mirror of https://github.com/apache/maven.git
[MNG-6401] Support interpolation of the proxy port in settings.xml (#1194)
Co-authored-by: Hervé Boutemy <hboutemy@apache.org> Co-authored-by: Michael Osipov <michaelo@apache.org>
This commit is contained in:
parent
421a23ad27
commit
c08b221264
|
@ -459,17 +459,17 @@
|
||||||
The <code><proxy></code> element contains informations required to a proxy settings.
|
The <code><proxy></code> element contains informations required to a proxy settings.
|
||||||
]]></description>
|
]]></description>
|
||||||
<fields>
|
<fields>
|
||||||
<field>
|
<field xml.tagName="active">
|
||||||
<name>active</name>
|
<name>activeString</name>
|
||||||
<version>1.0.0+</version>
|
<version>1.0.0+</version>
|
||||||
<required>false</required>
|
<required>false</required>
|
||||||
<defaultValue>true</defaultValue>
|
<defaultValue>true</defaultValue>
|
||||||
<description>
|
<description>
|
||||||
<![CDATA[
|
Whether this proxy configuration is the active one. Note: While the type of this field
|
||||||
Whether this proxy configuration is the active one.
|
is {@code String} for technical reasons, the semantic type is actually {@code boolean}.
|
||||||
]]>
|
@see #isActive()
|
||||||
</description>
|
</description>
|
||||||
<type>boolean</type>
|
<type>String</type>
|
||||||
</field>
|
</field>
|
||||||
<field>
|
<field>
|
||||||
<name>protocol</name>
|
<name>protocol</name>
|
||||||
|
@ -502,15 +502,15 @@
|
||||||
</description>
|
</description>
|
||||||
<type>String</type>
|
<type>String</type>
|
||||||
</field>
|
</field>
|
||||||
<field>
|
<field xml.tagName="port">
|
||||||
<name>port</name>
|
<name>portString</name>
|
||||||
<version>1.0.0+</version>
|
<version>1.0.0+</version>
|
||||||
<description>
|
<description>
|
||||||
<![CDATA[
|
The proxy port. Note: While the type of this field is {@code String} for technical
|
||||||
The proxy port.
|
reasons, the semantic type is actually {@code int}.
|
||||||
]]>
|
@see #getPort()
|
||||||
</description>
|
</description>
|
||||||
<type>int</type>
|
<type>String</type>
|
||||||
<defaultValue>8080</defaultValue>
|
<defaultValue>8080</defaultValue>
|
||||||
</field>
|
</field>
|
||||||
<field>
|
<field>
|
||||||
|
@ -535,6 +535,57 @@
|
||||||
<type>String</type>
|
<type>String</type>
|
||||||
</field>
|
</field>
|
||||||
</fields>
|
</fields>
|
||||||
|
<codeSegments>
|
||||||
|
<codeSegment>
|
||||||
|
<version>1.0.0/1.3.0</version>
|
||||||
|
<code>
|
||||||
|
public boolean isActive() {
|
||||||
|
return (getActiveString() != null) ? Boolean.parseBoolean(getActiveString()) : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActive(boolean active) {
|
||||||
|
setActiveString(String.valueOf(active));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPort() {
|
||||||
|
return (getPortString() != null) ? Integer.parseInt(getPortString()) : 8080;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPort(int port) {
|
||||||
|
setPortString(String.valueOf(port));
|
||||||
|
}
|
||||||
|
</code>
|
||||||
|
</codeSegment>
|
||||||
|
<codeSegment>
|
||||||
|
<version>2.0.0+</version>
|
||||||
|
<code>
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
</code>
|
||||||
|
</codeSegment>
|
||||||
|
</codeSegments>
|
||||||
</class>
|
</class>
|
||||||
<class>
|
<class>
|
||||||
<name>Server</name>
|
<name>Server</name>
|
||||||
|
|
|
@ -128,8 +128,6 @@ public class DefaultSettingsBuilder implements SettingsBuilder {
|
||||||
|
|
||||||
problems.setSource("");
|
problems.setSource("");
|
||||||
|
|
||||||
userSettings = interpolate(userSettings, request, problems);
|
|
||||||
|
|
||||||
// for the special case of a drive-relative Windows path, make sure it's absolute to save plugins from trouble
|
// for the special case of a drive-relative Windows path, make sure it's absolute to save plugins from trouble
|
||||||
String localRepository = userSettings.getLocalRepository();
|
String localRepository = userSettings.getLocalRepository();
|
||||||
if (localRepository != null && localRepository.length() > 0) {
|
if (localRepository != null && localRepository.length() > 0) {
|
||||||
|
@ -212,6 +210,8 @@ public class DefaultSettingsBuilder implements SettingsBuilder {
|
||||||
return new Settings();
|
return new Settings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
settings = interpolate(settings, request, problems);
|
||||||
|
|
||||||
settingsValidator.validate(settings, isProjectSettings, problems);
|
settingsValidator.validate(settings, isProjectSettings, problems);
|
||||||
|
|
||||||
if (isProjectSettings) {
|
if (isProjectSettings) {
|
||||||
|
|
|
@ -195,6 +195,17 @@ public class DefaultSettingsValidator implements SettingsValidator {
|
||||||
"must be unique but found duplicate proxy with id " + proxy.getId());
|
"must be unique but found duplicate proxy with id " + proxy.getId());
|
||||||
}
|
}
|
||||||
validateStringNotEmpty(problems, "proxies.proxy.host", proxy.getHost(), proxy.getId());
|
validateStringNotEmpty(problems, "proxies.proxy.host", proxy.getHost(), proxy.getId());
|
||||||
|
|
||||||
|
try {
|
||||||
|
Integer.parseInt(proxy.getPortString());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
addViolation(
|
||||||
|
problems,
|
||||||
|
Severity.ERROR,
|
||||||
|
"proxies.proxy[" + proxy.getId() + "].port",
|
||||||
|
null,
|
||||||
|
"must be a valid integer but found '" + proxy.getPortString() + "'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue