mirror of
https://github.com/apache/maven.git
synced 2025-02-21 01:15:42 +00:00
[MNG-5794] Warn about Proxies with duplicate id, but different protocols
Patch contributed by Thomas Meyer, verified by Robert Scholte
This commit is contained in:
parent
da98af988d
commit
874eaef725
@ -39,6 +39,12 @@ under the License.
|
||||
<tag>HEAD</tag>
|
||||
</scm>
|
||||
|
||||
<contributors>
|
||||
<contributor>
|
||||
<name>Thomas Meyer</name>
|
||||
</contributor>
|
||||
</contributors>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
|
@ -26,6 +26,7 @@
|
||||
import org.apache.maven.settings.Mirror;
|
||||
import org.apache.maven.settings.Profile;
|
||||
import org.apache.maven.settings.Repository;
|
||||
import org.apache.maven.settings.Proxy;
|
||||
import org.apache.maven.settings.Server;
|
||||
import org.apache.maven.settings.Settings;
|
||||
import org.apache.maven.settings.building.SettingsProblem.Severity;
|
||||
@ -141,6 +142,23 @@ else if ( !pluginGroup.matches( ID_REGEX ) )
|
||||
+ "pluginRepositories.pluginRepository" );
|
||||
}
|
||||
}
|
||||
|
||||
List<Proxy> proxies = settings.getProxies();
|
||||
|
||||
if ( proxies != null )
|
||||
{
|
||||
Set<String> proxyIds = new HashSet<String>();
|
||||
|
||||
for ( Proxy proxy : proxies )
|
||||
{
|
||||
if ( !proxyIds.add( proxy.getId() ) )
|
||||
{
|
||||
addViolation( problems, Severity.WARNING, "proxies.proxy.id", null,
|
||||
"must be unique but found duplicate proxy with id " + proxy.getId() );
|
||||
}
|
||||
validateStringNotEmpty( problems, "proxies.proxy.host", proxy.getHost(), proxy.getId() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void validateRepositories( SettingsProblemCollector problems, List<Repository> repositories, String prefix )
|
||||
@ -189,7 +207,7 @@ private void validateRepositories( SettingsProblemCollector problems, List<Repos
|
||||
* <li><code>string.length > 0</code>
|
||||
* </ul>
|
||||
*/
|
||||
private boolean validateStringNotEmpty( SettingsProblemCollector problems, String fieldName, String string,
|
||||
private static boolean validateStringNotEmpty( SettingsProblemCollector problems, String fieldName, String string,
|
||||
String sourceHint )
|
||||
{
|
||||
if ( !validateNotNull( problems, fieldName, string, sourceHint ) )
|
||||
@ -214,7 +232,7 @@ private boolean validateStringNotEmpty( SettingsProblemCollector problems, Strin
|
||||
* <li><code>string != null</code>
|
||||
* </ul>
|
||||
*/
|
||||
private boolean validateNotNull( SettingsProblemCollector problems, String fieldName, Object object,
|
||||
private static boolean validateNotNull( SettingsProblemCollector problems, String fieldName, Object object,
|
||||
String sourceHint )
|
||||
{
|
||||
if ( object != null )
|
||||
@ -227,7 +245,7 @@ private boolean validateNotNull( SettingsProblemCollector problems, String field
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean validateBannedCharacters( SettingsProblemCollector problems, String fieldName, Severity severity,
|
||||
private static boolean validateBannedCharacters( SettingsProblemCollector problems, String fieldName, Severity severity,
|
||||
String string, String sourceHint, String banned )
|
||||
{
|
||||
if ( string != null )
|
||||
@ -247,7 +265,7 @@ private boolean validateBannedCharacters( SettingsProblemCollector problems, Str
|
||||
return true;
|
||||
}
|
||||
|
||||
private void addViolation( SettingsProblemCollector problems, Severity severity, String fieldName,
|
||||
private static void addViolation( SettingsProblemCollector problems, Severity severity, String fieldName,
|
||||
String sourceHint, String message )
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder( 256 );
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
import org.apache.maven.settings.Mirror;
|
||||
import org.apache.maven.settings.Profile;
|
||||
import org.apache.maven.settings.Proxy;
|
||||
import org.apache.maven.settings.Repository;
|
||||
import org.apache.maven.settings.Server;
|
||||
import org.apache.maven.settings.Settings;
|
||||
@ -195,6 +196,38 @@ public void testValidateUniqueRepositoryId()
|
||||
+ " but found duplicate repository with id test" );
|
||||
}
|
||||
|
||||
public void testValidateUniqueProxyId()
|
||||
throws Exception
|
||||
{
|
||||
Settings settings = new Settings();
|
||||
Proxy proxy = new Proxy();
|
||||
String id = null;
|
||||
proxy.setId( id );
|
||||
proxy.setHost("www.example.com");
|
||||
settings.addProxy( proxy );
|
||||
settings.addProxy( proxy );
|
||||
|
||||
SimpleProblemCollector problems = new SimpleProblemCollector();
|
||||
validator.validate( settings, problems );
|
||||
assertEquals( 1, problems.messages.size() );
|
||||
assertContains( problems.messages.get( 0 ), "'proxies.proxy.id' must be unique"
|
||||
+ " but found duplicate proxy with id " + id );
|
||||
|
||||
}
|
||||
|
||||
public void testValidateProxy()
|
||||
throws Exception
|
||||
{
|
||||
Settings settings = new Settings();
|
||||
Proxy proxy1 = new Proxy();
|
||||
settings.addProxy( proxy1 );
|
||||
|
||||
SimpleProblemCollector problems = new SimpleProblemCollector();
|
||||
validator.validate( settings, problems );
|
||||
assertEquals( 1, problems.messages.size() );
|
||||
assertContains( problems.messages.get( 0 ), "'proxies.proxy.host' for default is missing" );
|
||||
}
|
||||
|
||||
private static class SimpleProblemCollector
|
||||
implements SettingsProblemCollector
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user