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.
|
||||
]]></description>
|
||||
<fields>
|
||||
<field>
|
||||
<name>active</name>
|
||||
<field xml.tagName="active">
|
||||
<name>activeString</name>
|
||||
<version>1.0.0+</version>
|
||||
<required>false</required>
|
||||
<defaultValue>true</defaultValue>
|
||||
<description>
|
||||
<![CDATA[
|
||||
Whether this proxy configuration is the active one.
|
||||
]]>
|
||||
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()
|
||||
</description>
|
||||
<type>boolean</type>
|
||||
<type>String</type>
|
||||
</field>
|
||||
<field>
|
||||
<name>protocol</name>
|
||||
|
@ -502,15 +502,15 @@
|
|||
</description>
|
||||
<type>String</type>
|
||||
</field>
|
||||
<field>
|
||||
<name>port</name>
|
||||
<field xml.tagName="port">
|
||||
<name>portString</name>
|
||||
<version>1.0.0+</version>
|
||||
<description>
|
||||
<![CDATA[
|
||||
The proxy port.
|
||||
]]>
|
||||
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()
|
||||
</description>
|
||||
<type>int</type>
|
||||
<type>String</type>
|
||||
<defaultValue>8080</defaultValue>
|
||||
</field>
|
||||
<field>
|
||||
|
@ -535,6 +535,57 @@
|
|||
<type>String</type>
|
||||
</field>
|
||||
</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>
|
||||
<name>Server</name>
|
||||
|
|
|
@ -128,8 +128,6 @@ public class DefaultSettingsBuilder implements SettingsBuilder {
|
|||
|
||||
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
|
||||
String localRepository = userSettings.getLocalRepository();
|
||||
if (localRepository != null && localRepository.length() > 0) {
|
||||
|
@ -212,6 +210,8 @@ public class DefaultSettingsBuilder implements SettingsBuilder {
|
|||
return new Settings();
|
||||
}
|
||||
|
||||
settings = interpolate(settings, request, problems);
|
||||
|
||||
settingsValidator.validate(settings, isProjectSettings, problems);
|
||||
|
||||
if (isProjectSettings) {
|
||||
|
|
|
@ -195,6 +195,17 @@ public class DefaultSettingsValidator implements SettingsValidator {
|
|||
"must be unique but found duplicate proxy with id " + 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