import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.functors.ProxyConnectorConfigurationOrderComparator;
import org.apache.maven.archiva.configuration.io.registry.ConfigurationRegistryReader;
import org.apache.maven.archiva.configuration.io.registry.ConfigurationRegistryWriter;
import org.codehaus.plexus.registry.Registry;
import org.codehaus.plexus.registry.RegistryException;
import org.codehaus.plexus.registry.RegistryListener;
-import org.codehaus.plexus.util.StringUtils;
import java.io.File;
import java.io.IOException;
registry.removeSubset( KEY + ".repositories" );
}
+
+ if ( !CollectionUtils.isEmpty( config.getRemoteRepositories() ) )
+ {
+ List<RemoteRepositoryConfiguration> remoteRepos = config.getRemoteRepositories();
+ for ( RemoteRepositoryConfiguration repo : remoteRepos )
+ {
+ // [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
+ if( StringUtils.isBlank( repo.getUsername() ) )
+ {
+ repo.setUsername( null );
+ }
+
+ if( StringUtils.isBlank( repo.getPassword() ) )
+ {
+ repo.setPassword( null );
+ }
+ }
+ }
if ( !config.getProxyConnectors().isEmpty() )
{
<name>Java.net Repository for Maven 2</name>
<url>https://maven2-repository.dev.java.net/nonav/repository</url>
<layout>default</layout>
+ <username></username>
+ <password></password>
</remoteRepository>
</remoteRepositories>
<sourceRepoId>internal</sourceRepoId>
<targetRepoId>central</targetRepoId>
<proxyId/>
- <snapshotsPolicy>disabled</snapshotsPolicy>
- <releasePolicy>never</releasePolicy>
- <failurePolicy>not-found</failurePolicy>
+ <policies>
+ <releases>ignored</releases>
+ <snapshots>disabled</snapshots>
+ <cache-failures>cached</cache-failures>
+ </policies>
</proxyConnector>
<proxyConnector>
<sourceRepoId>internal</sourceRepoId>
<targetRepoId>maven2-repository.dev.java.net</targetRepoId>
<proxyId/>
- <snapshotsPolicy>disabled</snapshotsPolicy>
- <releasePolicy>never</releasePolicy>
- <failurePolicy>not-found</failurePolicy>
+ <policies>
+ <releases>ignored</releases>
+ <snapshots>disabled</snapshots>
+ <cache-failures>cached</cache-failures>
+ </policies>
<whiteListPatterns>
<whiteListPattern>javax/**</whiteListPattern>
</whiteListPatterns>
assertEquals( "check cron expression", "0 0,20 0 * * ?", repository.getRefreshCronExpression() );
}
+
+ /**
+ * [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
+ */
+ public void testGetConfigurationFixEmptyRemoteRepoUsernamePassword()
+ throws Exception
+ {
+ ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup(
+ ArchivaConfiguration.class.getName(),
+ "test-configuration" );
+
+ Configuration configuration = archivaConfiguration.getConfiguration();
+ assertConfiguration( configuration );
+ assertEquals( "check remote repositories", 2, configuration.getRemoteRepositories().size() );
+
+ RemoteRepositoryConfiguration repository = (RemoteRepositoryConfiguration) configuration
+ .getRemoteRepositoriesAsMap().get( "maven2-repository.dev.java.net" );
+
+ assertEquals( "remote repository.url", "https://maven2-repository.dev.java.net/nonav/repository", repository.getUrl() );
+ assertEquals( "remote repository.name", "Java.net Repository for Maven 2", repository.getName() );
+ assertEquals( "remote repository.id", "maven2-repository.dev.java.net", repository.getId() );
+ assertEquals( "remote repository.layout", "default", repository.getLayout() );
+ assertNull( "remote repository.username == null", repository.getUsername() );
+ assertNull( "remote repository.password == null", repository.getPassword() );
+ }
}
AuthenticationInfo authInfo = null;
String username = remoteRepository.getRepository().getUsername();
String password = remoteRepository.getRepository().getPassword();
- if ( username != null && password != null )
+
+ if ( StringUtils.isNotBlank( username ) && StringUtils.isNotBlank( password ) )
{
- getLogger().debug(
- "Using username " + username + " to connect to remote repository "
+ getLogger().debug( "Using username " + username + " to connect to remote repository "
+ remoteRepository.getURL() );
authInfo = new AuthenticationInfo();
authInfo.setUserName( username );