org.apache.maven.api.settings.Proxy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of maven-api-settings Show documentation
Show all versions of maven-api-settings Show documentation
Maven 4 API - Immutable Settings model.
// =================== DO NOT EDIT THIS FILE ====================
// Generated by Modello Velocity from model.vm
// template, any modifications will be overwritten.
// ==============================================================
package org.apache.maven.api.settings;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Generated;
import org.apache.maven.api.annotations.Immutable;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.annotations.NotThreadSafe;
import org.apache.maven.api.annotations.ThreadSafe;
/**
* The {@code } element contains information required to a proxy settings.
*/
@Experimental
@Generated @ThreadSafe @Immutable
public class Proxy
extends IdentifiableBase
implements Serializable, InputLocationTracker
{
/**
* Whether this proxy configuration is the active one. Note: While the type of this field
* is {@code String} for technical reasons, the semantic type is actually {@code boolean}.
* @see #isActive()
*/
final String activeString;
/**
* The proxy protocol.
*/
final String protocol;
/**
* The proxy user.
*/
final String username;
/**
* The proxy password.
*/
final String password;
/**
* The proxy port. Note: While the type of this field is {@code String} for technical
* reasons, the semantic type is actually {@code int}.
* @see #getPort()
*/
final String portString;
/**
* The proxy host.
*/
final String host;
/**
* The list of non-proxied hosts (delimited by {@code |}).
*/
final String nonProxyHosts;
/**
* Constructor for this class, to be called from its subclasses and {@link Builder}.
* @see Builder#build()
*/
protected Proxy(Builder builder) {
super(builder);
this.activeString = builder.activeString != null ? builder.activeString : (builder.base != null ? builder.base.activeString : null);
this.protocol = builder.protocol != null ? builder.protocol : (builder.base != null ? builder.base.protocol : null);
this.username = builder.username != null ? builder.username : (builder.base != null ? builder.base.username : null);
this.password = builder.password != null ? builder.password : (builder.base != null ? builder.base.password : null);
this.portString = builder.portString != null ? builder.portString : (builder.base != null ? builder.base.portString : null);
this.host = builder.host != null ? builder.host : (builder.base != null ? builder.base.host : null);
this.nonProxyHosts = builder.nonProxyHosts != null ? builder.nonProxyHosts : (builder.base != null ? builder.base.nonProxyHosts : null);
}
/**
* Whether this proxy configuration is the active one. Note: While the type of this field
* is {@code String} for technical reasons, the semantic type is actually {@code boolean}.
* @see #isActive()
*
* @return a {@code String}
*/
public String getActiveString() {
return this.activeString;
}
/**
* The proxy protocol.
*
* @return a {@code String}
*/
public String getProtocol() {
return this.protocol;
}
/**
* The proxy user.
*
* @return a {@code String}
*/
public String getUsername() {
return this.username;
}
/**
* The proxy password.
*
* @return a {@code String}
*/
public String getPassword() {
return this.password;
}
/**
* The proxy port. Note: While the type of this field is {@code String} for technical
* reasons, the semantic type is actually {@code int}.
* @see #getPort()
*
* @return a {@code String}
*/
public String getPortString() {
return this.portString;
}
/**
* The proxy host.
*
* @return a {@code String}
*/
public String getHost() {
return this.host;
}
/**
* The list of non-proxied hosts (delimited by {@code |}).
*
* @return a {@code String}
*/
public String getNonProxyHosts() {
return this.nonProxyHosts;
}
/**
* Creates a new builder with this object as the basis.
*
* @return a {@code Builder}
*/
@Nonnull
public Builder with() {
return newBuilder(this);
}
/**
* Creates a new {@code Proxy} instance using the specified id.
*
* @param id the new {@code String} to use
* @return a {@code Proxy} with the specified id
*/
@Nonnull
public Proxy withId(String id) {
return newBuilder(this, true).id(id).build();
}
/**
* Creates a new {@code Proxy} instance using the specified activeString.
*
* @param activeString the new {@code String} to use
* @return a {@code Proxy} with the specified activeString
*/
@Nonnull
public Proxy withActiveString(String activeString) {
return newBuilder(this, true).activeString(activeString).build();
}
/**
* Creates a new {@code Proxy} instance using the specified protocol.
*
* @param protocol the new {@code String} to use
* @return a {@code Proxy} with the specified protocol
*/
@Nonnull
public Proxy withProtocol(String protocol) {
return newBuilder(this, true).protocol(protocol).build();
}
/**
* Creates a new {@code Proxy} instance using the specified username.
*
* @param username the new {@code String} to use
* @return a {@code Proxy} with the specified username
*/
@Nonnull
public Proxy withUsername(String username) {
return newBuilder(this, true).username(username).build();
}
/**
* Creates a new {@code Proxy} instance using the specified password.
*
* @param password the new {@code String} to use
* @return a {@code Proxy} with the specified password
*/
@Nonnull
public Proxy withPassword(String password) {
return newBuilder(this, true).password(password).build();
}
/**
* Creates a new {@code Proxy} instance using the specified portString.
*
* @param portString the new {@code String} to use
* @return a {@code Proxy} with the specified portString
*/
@Nonnull
public Proxy withPortString(String portString) {
return newBuilder(this, true).portString(portString).build();
}
/**
* Creates a new {@code Proxy} instance using the specified host.
*
* @param host the new {@code String} to use
* @return a {@code Proxy} with the specified host
*/
@Nonnull
public Proxy withHost(String host) {
return newBuilder(this, true).host(host).build();
}
/**
* Creates a new {@code Proxy} instance using the specified nonProxyHosts.
*
* @param nonProxyHosts the new {@code String} to use
* @return a {@code Proxy} with the specified nonProxyHosts
*/
@Nonnull
public Proxy withNonProxyHosts(String nonProxyHosts) {
return newBuilder(this, true).nonProxyHosts(nonProxyHosts).build();
}
/**
* Creates a new {@code Proxy} instance.
* Equivalent to {@code newInstance(true)}.
* @see #newInstance(boolean)
*
* @return a new {@code Proxy}
*/
@Nonnull
public static Proxy newInstance() {
return newInstance(true);
}
/**
* Creates a new {@code Proxy} instance using default values or not.
* Equivalent to {@code newBuilder(withDefaults).build()}.
*
* @param withDefaults the boolean indicating whether default values should be used
* @return a new {@code Proxy}
*/
@Nonnull
public static Proxy newInstance(boolean withDefaults) {
return newBuilder(withDefaults).build();
}
/**
* Creates a new {@code Proxy} builder instance.
* Equivalent to {@code newBuilder(true)}.
* @see #newBuilder(boolean)
*
* @return a new {@code Builder}
*/
@Nonnull
public static Builder newBuilder() {
return newBuilder(true);
}
/**
* Creates a new {@code Proxy} builder instance using default values or not.
*
* @param withDefaults the boolean indicating whether default values should be used
* @return a new {@code Builder}
*/
@Nonnull
public static Builder newBuilder(boolean withDefaults) {
return new Builder(withDefaults);
}
/**
* Creates a new {@code Proxy} builder instance using the specified object as a basis.
* Equivalent to {@code newBuilder(from, false)}.
*
* @param from the {@code Proxy} instance to use as a basis
* @return a new {@code Builder}
*/
@Nonnull
public static Builder newBuilder(Proxy from) {
return newBuilder(from, false);
}
/**
* Creates a new {@code Proxy} builder instance using the specified object as a basis.
*
* @param from the {@code Proxy} instance to use as a basis
* @param forceCopy the boolean indicating if a copy should be forced
* @return a new {@code Builder}
*/
@Nonnull
public static Builder newBuilder(Proxy from, boolean forceCopy) {
return new Builder(from, forceCopy);
}
/**
* Builder class used to create Proxy instances.
* @see #with()
* @see #newBuilder()
*/
@NotThreadSafe
public static class Builder
extends IdentifiableBase.Builder
{
Proxy base;
String activeString;
String protocol;
String username;
String password;
String portString;
String host;
String nonProxyHosts;
protected Builder(boolean withDefaults) {
super(withDefaults);
if (withDefaults) {
this.activeString = "true";
this.protocol = "http";
this.portString = "8080";
}
}
protected Builder(Proxy base, boolean forceCopy) {
super(base, forceCopy);
if (forceCopy) {
this.activeString = base.activeString;
this.protocol = base.protocol;
this.username = base.username;
this.password = base.password;
this.portString = base.portString;
this.host = base.host;
this.nonProxyHosts = base.nonProxyHosts;
this.locations = base.locations;
this.importedFrom = base.importedFrom;
} else {
this.base = base;
}
}
@Nonnull
public Builder id(String id) {
this.id = id;
return this;
}
@Nonnull
public Builder activeString(String activeString) {
this.activeString = activeString;
return this;
}
@Nonnull
public Builder protocol(String protocol) {
this.protocol = protocol;
return this;
}
@Nonnull
public Builder username(String username) {
this.username = username;
return this;
}
@Nonnull
public Builder password(String password) {
this.password = password;
return this;
}
@Nonnull
public Builder portString(String portString) {
this.portString = portString;
return this;
}
@Nonnull
public Builder host(String host) {
this.host = host;
return this;
}
@Nonnull
public Builder nonProxyHosts(String nonProxyHosts) {
this.nonProxyHosts = nonProxyHosts;
return this;
}
@Nonnull
public Builder location(Object key, InputLocation location) {
if (location != null) {
if (!(this.locations instanceof HashMap)) {
this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
}
this.locations.put(key, location);
}
return this;
}
@Nonnull
public Builder importedFrom(InputLocation importedFrom) {
this.importedFrom = importedFrom;
return this;
}
@Nonnull
public Proxy build() {
// this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
if (base != null
&& (id == null || id == base.id)
&& (activeString == null || activeString == base.activeString)
&& (protocol == null || protocol == base.protocol)
&& (username == null || username == base.username)
&& (password == null || password == base.password)
&& (portString == null || portString == base.portString)
&& (host == null || host == base.host)
&& (nonProxyHosts == null || nonProxyHosts == base.nonProxyHosts)
) {
return base;
}
return new Proxy(this);
}
}
/**
* Indicates if this proxy is active.
* To allow interpolation of this field, this method lazily parses
* the {@link #getActiveString()} value as a boolean and defaults to {@code true}
* if not set.
*
* @return a boolean indicating if this proxy is active
*/
public boolean isActive() {
return (getActiveString() != null) ? Boolean.parseBoolean(getActiveString()) : true;
}
/**
* Returns the port to use for this proxy.
* To allow interpolation of this field, this method lazily parses
* the {@link #getPortString()} value as an integer and defaults to {@code 8080}
* if not set.
*
* @return an integer indicating the port to use for this proxy
*/
public int getPort() {
return (getPortString() != null) ? Integer.parseInt(getPortString()) : 8080;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy