Skip to content

Instantly share code, notes, and snippets.

@sebersole
Created October 11, 2010 22:51
Show Gist options
  • Save sebersole/621371 to your computer and use it in GitHub Desktop.
Save sebersole/621371 to your computer and use it in GitHub Desktop.
public class Authenticator extends DefaultTask {
public static final String USER = "JBOSS_NEXUS_USERNAME";
public static final String PASS = "JBOSS_NEXUS_PASSWORD";
private Set<RemoteRepository> nexusRepositories = new HashSet<RemoteRepository>();
void addRepository(RemoteRepository remoteRepository) {
nexusRepositories.add( remoteRepository );
}
@TaskAction
public void configureNexusAuthentication() {
Authentication authentication = null;
if ( getProject().hasProperty( USER ) ) {
authentication = new Authentication();
authentication.setUserName( (String) getProject().getProperties().get( USER ) );
}
if ( getProject().hasProperty( PASS ) ) {
if ( authentication == null ) {
authentication = new Authentication();
authentication.setPassword( (String) getProject().getProperties().get( PASS ) );
}
}
if ( authentication != null ) {
for ( RemoteRepository remoteRepository : nexusRepositories ) {
remoteRepository.addAuthentication( authentication );
}
}
else {
if ( ! nexusRepositories.isEmpty() ) {
getLogger().warn( "Unable to locate JBoss Nexus username/password; upload will most likely fail" );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment