Skip to content

Commit

Permalink
Fixed an issue involving ProjectHelper and secure repositories.
Browse files Browse the repository at this point in the history
This ensures that the Furnace build succeeds when a settings.xml
file with passwords for mirrors or secured repositories used in
the tests, is present in the Maven home directory.
  • Loading branch information
VineetReynolds committed Nov 22, 2013
1 parent d47bb7e commit 4316782
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2013 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.jboss.forge.arquillian.maven;

import org.eclipse.aether.repository.Authentication;
import org.eclipse.aether.repository.AuthenticationSelector;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.util.repository.DefaultAuthenticationSelector;
import org.eclipse.aether.util.repository.DefaultMirrorSelector;

/**
* An {@link AuthenticationSelector} that resolves the Authentication info lazily at runtime. This selector determines
* whether a remote repository is mirrored and then returns the authentication info for the mirror. If no mirror exists,
* the authentication info for the remote repository is returned.
*/
final class LazyAuthenticationSelector implements AuthenticationSelector
{
private final DefaultMirrorSelector mirrorSelector;
private DefaultAuthenticationSelector defaultAuthSelector;

LazyAuthenticationSelector(DefaultMirrorSelector mirrorSelector)
{
this.mirrorSelector = mirrorSelector;
this.defaultAuthSelector = new DefaultAuthenticationSelector();
}

@Override
public Authentication getAuthentication(RemoteRepository repository)
{
RemoteRepository mirror = mirrorSelector.getMirror(repository);
if (mirror != null)
{
return defaultAuthSelector.getAuthentication(mirror);
}
return defaultAuthSelector.getAuthentication(repository);
}

public void add(String id, Authentication authentication)
{
defaultAuthSelector.add(id, authentication);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
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;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.graph.Dependency;
import org.eclipse.aether.repository.LocalRepository;
import org.eclipse.aether.util.repository.AuthenticationBuilder;
import org.eclipse.aether.util.repository.DefaultMirrorSelector;
import org.eclipse.aether.util.repository.DefaultProxySelector;
import org.jboss.forge.furnace.manager.maven.MavenContainer;
Expand Down Expand Up @@ -163,16 +165,26 @@ private ProjectBuildingRequest getBuildingRequest(PlexusContainer plexus)
localRepo));
repositorySession.setOffline(settings.isOffline());
List<Mirror> mirrors = executionRequest.getMirrors();
DefaultMirrorSelector mirrorSelector = new DefaultMirrorSelector();
if (mirrors != null)
{
DefaultMirrorSelector mirrorSelector = new DefaultMirrorSelector();
for (Mirror mirror : mirrors)
{
mirrorSelector.add(mirror.getId(), mirror.getUrl(), mirror.getLayout(), false, mirror.getMirrorOf(),
mirror.getMirrorOfLayouts());
}
repositorySession.setMirrorSelector(mirrorSelector);
}
repositorySession.setMirrorSelector(mirrorSelector);

LazyAuthenticationSelector authSelector = new LazyAuthenticationSelector(mirrorSelector);
for (Server server : settings.getServers())
{
authSelector.add(
server.getId(),
new AuthenticationBuilder().addUsername(server.getUsername()).addPassword(server.getPassword())
.addPrivateKey(server.getPrivateKey(), server.getPassphrase()).build());
}
repositorySession.setAuthenticationSelector(authSelector);

request.setRepositorySession(repositorySession);
request.setProcessPlugins(false);
Expand Down

0 comments on commit 4316782

Please sign in to comment.