some clean up of components and artifact repository factory

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@164181 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-04-22 07:16:09 +00:00
parent c98b557ac8
commit 7d6b029c43
9 changed files with 65 additions and 177 deletions

View File

@ -72,16 +72,10 @@ public class DefaultMaven
protected MavenProjectBuilder projectBuilder;
protected PluginManager pluginManager;
protected LifecycleExecutor lifecycleExecutor;
protected PlexusContainer container;
protected ArtifactRepositoryFactory artifactRepositoryFactory;
protected WagonManager wagonManager;
// ----------------------------------------------------------------------
// Project execution
// ----------------------------------------------------------------------
@ -301,7 +295,7 @@ public class DefaultMaven
protected MavenSession createSession( MavenExecutionRequest request, MavenProject project )
{
return new MavenSession( project, container, pluginManager, request.getSettings(),
return new MavenSession( project, container, request.getSettings(),
request.getLocalRepository(), request.getEventDispatcher(), request.getLog(),
request.getGoals() );
}

View File

@ -17,7 +17,6 @@ package org.apache.maven.artifact.repository;
*/
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.model.Repository;
/**
* @author jdcasey
@ -27,8 +26,9 @@ public interface ArtifactRepositoryFactory
public static final String ROLE = ArtifactRepositoryFactory.class.getName();
public ArtifactRepository createArtifactRepository( Repository modelRepository,
ArtifactRepositoryLayout repositoryLayout );
public ArtifactRepository createArtifactRepository( String id, String url,
ArtifactRepositoryLayout repositoryLayout,
String snapshotPolicy );
void setGlobalSnapshotPolicy( String snapshotPolicy );
}

View File

@ -17,10 +17,9 @@ package org.apache.maven.artifact.repository;
*/
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.model.Repository;
import org.apache.maven.settings.Settings;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.MavenSettingsBuilder;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings;
import org.apache.maven.wagon.authentication.AuthenticationInfo;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
@ -41,15 +40,13 @@ public class DefaultArtifactRepositoryFactory
// TODO: make this a store once object?
private MavenSettingsBuilder settingsBuilder;
public ArtifactRepository createArtifactRepository( Repository modelRepository,
ArtifactRepositoryLayout repositoryLayout )
public ArtifactRepository createArtifactRepository( String id, String url,
ArtifactRepositoryLayout repositoryLayout,
String snapshotPolicy )
{
AuthenticationInfo authInfo = null;
Server repoProfile = null;
String repoId = modelRepository.getId();
if ( repoId != null && repoId.length() > 0 )
if ( id != null && id.length() > 0 )
{
Settings settings = null;
try
@ -65,7 +62,21 @@ public class DefaultArtifactRepositoryFactory
getLogger().warn( "Error reading settings", e );
}
repoProfile = settings.getServer( modelRepository.getId() );
Server repoProfile = settings.getServer( id );
if ( repoProfile != null )
{
authInfo = new AuthenticationInfo();
authInfo.setUserName( repoProfile.getUsername() );
authInfo.setPassword( repoProfile.getPassword() );
authInfo.setPrivateKey( repoProfile.getPrivateKey() );
authInfo.setPassphrase( repoProfile.getPassphrase() );
}
}
else
{
@ -73,37 +84,24 @@ public class DefaultArtifactRepositoryFactory
if ( logger != null )
{
logger.warn( "Cannot associate authentication to repository with null id. The offending repository's URL is: " +
modelRepository.getUrl() );
url );
}
}
ArtifactRepository repo = null;
String snapshotPolicy = globalSnapshotPolicy;
if ( snapshotPolicy == null )
if ( globalSnapshotPolicy != null )
{
snapshotPolicy = modelRepository.getSnapshotPolicy();
snapshotPolicy = globalSnapshotPolicy;
}
if ( repoProfile != null )
if ( authInfo != null )
{
AuthenticationInfo authInfo = new AuthenticationInfo();
authInfo.setUserName( repoProfile.getUsername() );
authInfo.setPassword( repoProfile.getPassword() );
authInfo.setPrivateKey( repoProfile.getPrivateKey() );
authInfo.setPassphrase( repoProfile.getPassphrase() );
repo = new ArtifactRepository( modelRepository.getId(), modelRepository.getUrl(), authInfo,
repositoryLayout, snapshotPolicy );
repo = new ArtifactRepository( id, url, authInfo, repositoryLayout, snapshotPolicy );
}
else
{
repo = new ArtifactRepository( modelRepository.getId(), modelRepository.getUrl(), repositoryLayout,
snapshotPolicy );
repo = new ArtifactRepository( id, url, repositoryLayout, snapshotPolicy );
}
return repo;
@ -113,5 +111,4 @@ public class DefaultArtifactRepositoryFactory
{
this.globalSnapshotPolicy = snapshotPolicy;
}
}

View File

@ -56,9 +56,8 @@ public class ConsoleDownloadMonitor
long total = transferEvent.getResource().getContentLength();
complete += length;
// TODO [BP]: Sys.out may no longer be appropriate, but will \r work with getLogger()?
System.out.print(
( complete / 1024 ) + "/" + ( total == WagonConstants.UNKNOWN_LENGTH ? "?" : ( total / 1024 ) + "K" ) +
"\r" );
System.out.print( ( complete / 1024 ) + "/" +
( total == WagonConstants.UNKNOWN_LENGTH ? "?" : ( total / 1024 ) + "K" ) + "\r" );
}
public void transferCompleted( TransferEvent transferEvent )

View File

@ -32,7 +32,6 @@ import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.model.Model;
import org.apache.maven.model.Repository;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.monitor.event.DefaultEventDispatcher;
import org.apache.maven.monitor.event.DefaultEventMonitor;
@ -319,13 +318,16 @@ public class MavenCli
CommandLine commandLine )
throws ComponentLookupException
{
// TODO: release
// TODO: something in plexus to show all active hooks?
ArtifactRepositoryLayout repositoryLayout = (ArtifactRepositoryLayout) embedder.lookup(
ArtifactRepositoryLayout.ROLE, "default" );
ArtifactRepositoryFactory artifactRepositoryFactory = (ArtifactRepositoryFactory) embedder.lookup(
ArtifactRepositoryFactory.ROLE );
ArtifactRepository localRepository = getLocalRepository( settings, artifactRepositoryFactory, repositoryLayout );
String url = "file://" + settings.getActiveProfile().getLocalRepository();
ArtifactRepository localRepository = new ArtifactRepository( "local", url, repositoryLayout );
boolean snapshotPolicySet = false;
if ( commandLine.hasOption( CLIManager.OFFLINE ) )
@ -487,22 +489,4 @@ public class MavenCli
formatter.printHelp( "maven [options] [goal [goal2 [goal3] ...]]", "\nOptions:", options, "\n" );
}
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
protected static ArtifactRepository getLocalRepository( Settings settings, ArtifactRepositoryFactory repoFactory,
ArtifactRepositoryLayout repositoryLayout )
{
Profile profile = settings.getActiveProfile();
Repository repo = new Repository();
repo.setId( "local" );
repo.setUrl( "file://" + profile.getLocalRepository() );
return repoFactory.createArtifactRepository( repo, repositoryLayout );
}
}

View File

@ -25,13 +25,9 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.util.dag.CycleDetectedException;
import org.codehaus.plexus.util.dag.DAG;
import org.codehaus.plexus.util.dag.TopologicalSorter;
import org.codehaus.plexus.util.dag.Vertex;
import java.util.List;
import java.util.Map;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
@ -45,32 +41,22 @@ public class MavenSession
private ArtifactRepository localRepository;
private PluginManager pluginManager;
private DAG dag;
private List goals;
private Map preGoalMappings;
private Map postGoalMappings;
private EventDispatcher eventDispatcher;
private Log log;
// TODO: make this the central one, get rid of build settings...
private final Settings settings;
public MavenSession( MavenProject project, PlexusContainer container, PluginManager pluginManager,
Settings settings, ArtifactRepository localRepository, EventDispatcher eventDispatcher,
Log log, List goals )
public MavenSession( MavenProject project, PlexusContainer container, Settings settings,
ArtifactRepository localRepository, EventDispatcher eventDispatcher, Log log, List goals )
{
this.project = project;
this.container = container;
this.pluginManager = pluginManager;
this.settings = settings;
this.localRepository = localRepository;
@ -79,8 +65,6 @@ public class MavenSession
this.log = log;
this.dag = new DAG();
this.goals = goals;
}
@ -89,11 +73,6 @@ public class MavenSession
return container;
}
public PluginManager getPluginManager()
{
return pluginManager;
}
public MavenProject getProject()
{
return project;
@ -118,12 +97,14 @@ public class MavenSession
//
// ----------------------------------------------------------------------
public Object lookup( String role ) throws ComponentLookupException
public Object lookup( String role )
throws ComponentLookupException
{
return container.lookup( role );
}
public Object lookup( String role, String roleHint ) throws ComponentLookupException
public Object lookup( String role, String roleHint )
throws ComponentLookupException
{
return container.lookup( role, roleHint );
}
@ -143,29 +124,6 @@ public class MavenSession
return settings;
}
public void addImpliedExecution( String goal, String implied ) throws CycleDetectedException
{
dag.addEdge( goal, implied );
}
public void addSingleExecution( String goal )
{
dag.addVertex( goal );
}
public List getExecutionChain( String goal )
{
Vertex vertex = dag.getVertex( goal );
List sorted = TopologicalSorter.sort( vertex );
int goalIndex = sorted.indexOf( goal );
List chainToHere = sorted.subList( 0, goalIndex + 1 );
return chainToHere;
}
public List getPluginRepositories()
{
return project.getPluginArtifactRepositories();

View File

@ -26,11 +26,11 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.model.Build;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.model.Repository;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.project.inheritance.ModelInheritanceAssembler;
import org.apache.maven.project.injection.ModelDefaultsInjector;
@ -59,12 +59,12 @@ import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.HashSet;
/**
* @version $Id: DefaultMavenProjectBuilder.java,v 1.37 2005/03/08 01:55:22
@ -84,6 +84,7 @@ public class DefaultMavenProjectBuilder
private ModelValidator validator;
// TODO: make it a component
private MavenXpp3Reader modelReader;
private PathTranslator pathTranslator;
@ -92,7 +93,6 @@ public class DefaultMavenProjectBuilder
private ModelInterpolator modelInterpolator;
// TODO: comes from Maven CORE
private ArtifactRepositoryFactory artifactRepositoryFactory;
private final Map modelCache = new HashMap();
@ -242,13 +242,12 @@ public class DefaultMavenProjectBuilder
project = new MavenProject( model );
project.setPluginArtifactRepositories( buildPluginRepositories( model.getPluginRepositories() ) );
project.setPluginArtifactRepositories( buildArtifactRepositories( model.getPluginRepositories() ) );
DistributionManagement dm = model.getDistributionManagement();
if ( dm != null )
{
project.setDistributionManagementArtifactRepository( buildDistributionManagementRepository(
dm.getRepository() ) );
project.setDistributionManagementArtifactRepository( buildArtifactRepository( dm.getRepository() ) );
}
project.setParent( parentProject );
@ -348,10 +347,7 @@ public class DefaultMavenProjectBuilder
{
Repository mavenRepo = (Repository) i.next();
ArtifactRepositoryLayout remoteRepoLayout = getRepositoryLayout( mavenRepo );
ArtifactRepository artifactRepo = artifactRepositoryFactory.createArtifactRepository( mavenRepo,
remoteRepoLayout );
ArtifactRepository artifactRepo = buildArtifactRepository( mavenRepo );
if ( !repos.contains( artifactRepo ) )
{
@ -361,27 +357,6 @@ public class DefaultMavenProjectBuilder
return repos;
}
private List buildPluginRepositories( List pluginRepositories )
throws ProjectBuildingException
{
List remotePluginRepositories = new ArrayList();
for ( Iterator it = pluginRepositories.iterator(); it.hasNext(); )
{
Repository mavenRepo = (Repository) it.next();
ArtifactRepositoryLayout repositoryLayout = getRepositoryLayout( mavenRepo );
ArtifactRepository pluginRepository = artifactRepositoryFactory.createArtifactRepository( mavenRepo,
repositoryLayout );
remotePluginRepositories.add( pluginRepository );
}
return remotePluginRepositories;
}
private ArtifactRepositoryLayout getRepositoryLayout( Repository mavenRepo )
throws ProjectBuildingException
{
@ -400,20 +375,21 @@ public class DefaultMavenProjectBuilder
return repositoryLayout;
}
private ArtifactRepository buildDistributionManagementRepository( Repository dmRepo )
private ArtifactRepository buildArtifactRepository( Repository repo )
throws ProjectBuildingException
{
if ( dmRepo == null )
if ( repo != null )
{
String id = repo.getId();
String url = repo.getUrl();
ArtifactRepositoryLayout layout = getRepositoryLayout( repo );
String snapshotPolicy = repo.getSnapshotPolicy();
return artifactRepositoryFactory.createArtifactRepository( id, url, layout, snapshotPolicy );
}
else
{
return null;
}
ArtifactRepositoryLayout repositoryLayout = getRepositoryLayout( dmRepo );
ArtifactRepository dmArtifactRepository = artifactRepositoryFactory.createArtifactRepository( dmRepo,
repositoryLayout );
return dmArtifactRepository;
}
private Model readModel( File file )

View File

@ -12,18 +12,12 @@
<requirement>
<role>org.codehaus.plexus.i18n.I18N</role>
</requirement>
<requirement>
<role>org.apache.maven.plugin.PluginManager</role>
</requirement>
<requirement>
<role>org.apache.maven.project.MavenProjectBuilder</role>
</requirement>
<requirement>
<role>org.apache.maven.lifecycle.LifecycleExecutor</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
</requirement>
</requirements>
</component>
<!--
@ -233,20 +227,6 @@
<role>org.apache.maven.project.path.PathTranslator</role>
<implementation>org.apache.maven.project.path.DefaultPathTranslator</implementation>
</component>
<!-- ********************* FIXME *******************************************
| NOTE: This is also declared in plexus.xml for maven. We currently need it
| in both places, for systems that don't use maven's plexus.xml. This will
| become unnecessary when multiple plexus.xml files are allowed in plexus.
-->
<component>
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
<implementation>org.apache.maven.artifact.repository.DefaultArtifactRepositoryFactory</implementation>
<requirements>
<requirement>
<role>org.apache.maven.settings.MavenSettingsBuilder</role>
</requirement>
</requirements>
</component>
<!-- ********************* FIXME *******************************************
| NOTE: This is also declared in plexus.xml for maven. We currently need it
| in both places, for systems that don't use maven's plexus.xml. This will

View File

@ -74,7 +74,7 @@ public class PluginParameterExpressionEvaluatorTest
MavenProject project = new MavenProject( model );
project.setFile( new File( "pom.xml" ).getCanonicalFile() );
MavenSession session = new MavenSession( project, container, mgr, new Settings(), repo,
MavenSession session = new MavenSession( project, container, new Settings(), repo,
new DefaultEventDispatcher(), new DefaultLog( container.getLogger() ),
Collections.EMPTY_LIST );
@ -99,7 +99,7 @@ public class PluginParameterExpressionEvaluatorTest
PlexusContainer container = getContainer();
MavenSession session = new MavenSession( null, // don't need a project for this test.
container, mgr, new Settings(), repo,
container, new Settings(), repo,
new DefaultEventDispatcher(), new DefaultLog( container.getLogger() ),
Collections.EMPTY_LIST );
@ -120,7 +120,7 @@ public class PluginParameterExpressionEvaluatorTest
PlexusContainer container = getContainer();
MavenSession session = new MavenSession( null, // don't need a project for this test.
container, mgr, new Settings(), repo,
container, new Settings(), repo,
new DefaultEventDispatcher(), new DefaultLog( container.getLogger() ),
Collections.EMPTY_LIST );