diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java index 8ab8fcd06b..ec100c8fe1 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -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() ); } diff --git a/maven-core/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java b/maven-core/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java index 255573d281..f696a56a35 100644 --- a/maven-core/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java +++ b/maven-core/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java @@ -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 ); } \ No newline at end of file diff --git a/maven-core/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java b/maven-core/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java index dad5036186..8efe8e1187 100644 --- a/maven-core/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java +++ b/maven-core/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java @@ -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; } - -} \ No newline at end of file +} diff --git a/maven-core/src/main/java/org/apache/maven/cli/ConsoleDownloadMonitor.java b/maven-core/src/main/java/org/apache/maven/cli/ConsoleDownloadMonitor.java index b33cc5c501..492e9310c0 100644 --- a/maven-core/src/main/java/org/apache/maven/cli/ConsoleDownloadMonitor.java +++ b/maven-core/src/main/java/org/apache/maven/cli/ConsoleDownloadMonitor.java @@ -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 ) diff --git a/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java index 340ffa6ccc..248f6f504f 100644 --- a/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java @@ -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 ); - } } \ No newline at end of file diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java b/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java index 0c6a6052c7..8bf42605c2 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java @@ -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 Jason van Zyl @@ -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(); diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index 4b14d0dd4c..7fcb67b979 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -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 ) diff --git a/maven-core/src/main/resources/META-INF/plexus/components.xml b/maven-core/src/main/resources/META-INF/plexus/components.xml index 5b8e124b9f..f0d5635f21 100644 --- a/maven-core/src/main/resources/META-INF/plexus/components.xml +++ b/maven-core/src/main/resources/META-INF/plexus/components.xml @@ -12,18 +12,12 @@ org.codehaus.plexus.i18n.I18N - - org.apache.maven.plugin.PluginManager - org.apache.maven.project.MavenProjectBuilder org.apache.maven.lifecycle.LifecycleExecutor - - org.apache.maven.artifact.repository.ArtifactRepositoryFactory - - - org.apache.maven.artifact.repository.ArtifactRepositoryFactory - org.apache.maven.artifact.repository.DefaultArtifactRepositoryFactory - - - org.apache.maven.settings.MavenSettingsBuilder - - -