o coming close to something i can easily test

git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@759818 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-03-30 01:11:02 +00:00
parent 4f4b793d93
commit d22c870e02
22 changed files with 307 additions and 646 deletions

View File

@ -20,10 +20,6 @@
<artifactId>maven-core</artifactId>
<name>Maven Core</name>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-reporting-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
@ -49,14 +45,6 @@
<groupId>org.apache.maven</groupId>
<artifactId>maven-project-builder</artifactId>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-interactivity-api</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-interpolation</artifactId>
@ -69,22 +57,6 @@
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-classworlds</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-file</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>easymock</groupId>
<artifactId>easymock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-test-tools</artifactId>
<version>1.0-alpha-1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-annotations</artifactId>
@ -117,6 +89,17 @@
<groupId>commons-jxpath</groupId>
<artifactId>commons-jxpath</artifactId>
</dependency>
<!-- Testing -->
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-file</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>easymock</groupId>
<artifactId>easymock</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
@ -134,14 +117,6 @@
</models>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/testutils/**</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,37 +0,0 @@
package org.apache.maven;
import org.apache.maven.plugin.MojoFailureException;
/**
* Exception which occurs when an @aggregator plugin fails to execute. This
* exception is meant to wrap a {@link MojoFailureException}, and provide
* additional details about the mojo that failed, via {@link MojoBinding} and
* the root directory in which the build executes.
*
* @author jdcasey
*
*/
public class AggregatedBuildFailureException
extends BuildFailureException
{
private final String executionRootDirectory;
public AggregatedBuildFailureException( String executionRootDirectory,
MojoFailureException cause )
{
super( "Build in root directory: " + executionRootDirectory + " failed during execution of aggregator mojo.", cause );
this.executionRootDirectory = executionRootDirectory;
}
public MojoFailureException getMojoFailureException()
{
return (MojoFailureException) getCause();
}
public String getExecutionRootDirectory()
{
return executionRootDirectory;
}
}

View File

@ -1,31 +1,24 @@
package org.apache.maven;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.Arrays;
import java.util.List;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
@ -34,9 +27,7 @@ import org.apache.maven.execution.DuplicateProjectException;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.ReactorManager;
import org.apache.maven.execution.RuntimeInformation;
import org.apache.maven.lifecycle.Lifecycle;
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.project.MavenProject;
@ -47,16 +38,12 @@ import org.apache.maven.reactor.MissingModuleException;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.Os;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.dag.CycleDetectedException;
/**
* @author Jason van Zyl
* @version $Id$
* @todo EventDispatcher should be a component as it is internal to maven.
*/
@Component(role = Maven.class)
public class DefaultMaven
@ -64,7 +51,7 @@ public class DefaultMaven
{
@Requirement
protected MavenProjectBuilder projectBuilder;
@Requirement
protected LifecycleExecutor lifecycleExecutor;
@ -74,14 +61,11 @@ public class DefaultMaven
@Requirement
protected RuntimeInformation runtimeInformation;
@Requirement
private Logger logger;
public List<String> getLifecyclePhases()
{
return lifecycleExecutor.getLifecyclePhases();
}
// ----------------------------------------------------------------------
// Project execution
// ----------------------------------------------------------------------
@ -92,28 +76,17 @@ public class DefaultMaven
public MavenExecutionResult execute( MavenExecutionRequest request )
{
request.setStartTime( new Date() );
MavenExecutionResult result = new DefaultMavenExecutionResult();
ReactorManager reactorManager = createReactorManager( request, result );
MavenSession session = createMavenSession( request, result );
if ( result.hasExceptions() )
if ( session.getReactorManager().hasMultipleProjects() )
{
return result;
}
//logger.info( "Reactor build order: " );
MavenSession session = createSession( request, reactorManager );
logger.info( "Scanning for projects..." );
if ( reactorManager.hasMultipleProjects() )
{
logger.info( "Reactor build order: " );
for( MavenProject project : reactorManager.getSortedProjects() )
for ( MavenProject project : session.getReactorManager().getSortedProjects() )
{
logger.info( " " + project.getName() );
//logger.info( " " + project.getName() );
}
}
@ -134,18 +107,21 @@ public class DefaultMaven
return result;
}
result.setTopologicallySortedProjects( reactorManager.getSortedProjects() );
result.setTopologicallySortedProjects( session.getReactorManager().getSortedProjects() );
result.setProject( reactorManager.getTopLevelProject() );
result.setProject( session.getReactorManager().getTopLevelProject() );
return result;
}
public ReactorManager createReactorManager( MavenExecutionRequest request, MavenExecutionResult result )
}
public MavenSession createMavenSession( MavenExecutionRequest request, MavenExecutionResult result )
{
List projects;
MavenSession session;
List<MavenProject> projects;
try
{
{
projects = getProjects( request );
if ( projects.isEmpty() )
@ -166,13 +142,11 @@ public class DefaultMaven
return null;
}
ReactorManager reactorManager;
try
{
reactorManager = new ReactorManager( projects, request.getReactorFailureBehavior() );
result.setReactorManager( reactorManager );
{
session = new MavenSession( container, request, projects );
result.setReactorManager( session.getReactorManager() );
}
catch ( CycleDetectedException e )
{
@ -191,205 +165,101 @@ public class DefaultMaven
return null;
}
return reactorManager;
}
protected List getProjects( MavenExecutionRequest request )
throws MavenExecutionException
{
List projects;
List files;
try
{
files = getProjectFiles( request );
}
catch ( IOException e )
{
throw new MavenExecutionException( "Error selecting project files for the reactor: " + e.getMessage(), e );
}
projects = collectProjects( files, request, !request.useReactor() );
return projects;
}
private List collectProjects( List files, MavenExecutionRequest request, boolean isRoot )
throws MavenExecutionException
{
List projects = new ArrayList( files.size() );
if ( !files.isEmpty() )
{
for ( Iterator iterator = files.iterator(); iterator.hasNext(); )
{
File file = (File) iterator.next();
MavenProject project;
try
{
project = projectBuilder.build( file, request.getProjectBuildingConfiguration() );
}
catch ( ProjectBuildingException e )
{
throw new MavenExecutionException( "Failed to build MavenProject instance for: " + file, file, e );
}
if ( isRoot )
{
project.setExecutionRoot( true );
}
if ( ( project.getPrerequisites() != null ) && ( project.getPrerequisites().getMaven() != null ) )
{
DefaultArtifactVersion version = new DefaultArtifactVersion( project.getPrerequisites().getMaven() );
if ( runtimeInformation.getApplicationInformation().getVersion().compareTo( version ) < 0 )
{
throw new MavenExecutionException(
"Unable to build project '" + file +
"; it requires Maven version " + version.toString(), file );
}
}
if ( ( project.getModules() != null ) && !project.getModules().isEmpty() && request.isRecursive() )
{
// TODO: Really should fail if it was not? What if it is aggregating - eg "ear"?
project.setPackaging( "pom" );
File basedir = file.getParentFile();
// Initial ordering is as declared in the modules section
List moduleFiles = new ArrayList( project.getModules().size() );
for ( Iterator i = project.getModules().iterator(); i.hasNext(); )
{
String name = (String) i.next();
if ( StringUtils.isEmpty( StringUtils.trim( name ) ) )
{
logger.warn( "Empty module detected. Please check you don't have any empty module definitions in your POM." );
continue;
}
File moduleFile = new File( basedir, name );
if ( !moduleFile.exists() )
{
throw new MissingModuleException( name, moduleFile, file );
}
else if ( moduleFile.isDirectory() )
{
moduleFile = new File( basedir, name + "/" + Maven.POMv4 );
}
if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
{
// we don't canonicalize on unix to avoid interfering with symlinks
try
{
moduleFile = moduleFile.getCanonicalFile();
}
catch ( IOException e )
{
throw new MavenExecutionException( "Unable to canonicalize file name " + moduleFile, e );
}
}
else
{
moduleFile = new File( moduleFile.toURI().normalize() );
}
moduleFiles.add( moduleFile );
}
List collectedProjects = collectProjects( moduleFiles, request, false );
projects.addAll( collectedProjects );
project.setCollectedProjects( collectedProjects );
}
projects.add( project );
}
}
return projects;
}
// ----------------------------------------------------------------------
// Methods used by all execution request handlers
// ----------------------------------------------------------------------
//!! We should probably have the execution request handler create the
// session as
// the session type would be specific to the request i.e. having a project
// or not.
protected MavenSession createSession( MavenExecutionRequest request, ReactorManager reactorManager )
{
MavenSession session = new MavenSession( container, request );
return session;
}
private List getProjectFiles( MavenExecutionRequest request )
throws IOException
protected List<MavenProject> getProjects( MavenExecutionRequest request )
throws MavenExecutionException
{
List files = Collections.EMPTY_LIST;
List<File> files = Arrays.asList( new File[] { new File( request.getPomFile() ) } );
File userDir = new File( request.getBaseDirectory() );
List<MavenProject> projects = collectProjects( files, request );
if ( request.useReactor() )
return projects;
}
private List<MavenProject> collectProjects( List<File> files, MavenExecutionRequest request )
throws MavenExecutionException
{
List<MavenProject> projects = new ArrayList<MavenProject>();
for ( File file : files )
{
String includes = System.getProperty( "maven.reactor.includes", "**/" + POMv4 );
MavenProject project;
String excludes = System.getProperty( "maven.reactor.excludes", POMv4 );
files = FileUtils.getFiles( userDir, includes, excludes );
// make sure there is consistent ordering on all platforms, rather than using the filesystem ordering
Collections.sort( files );
}
else if ( request.getPom() != null )
{
File projectFile = request.getPom().getAbsoluteFile();
if ( projectFile.exists() )
try
{
files = Collections.singletonList( projectFile );
project = projectBuilder.build( file, request.getProjectBuildingConfiguration() );
}
catch ( ProjectBuildingException e )
{
throw new MavenExecutionException( "Failed to build MavenProject instance for: " + file, file, e );
}
if ( ( project.getPrerequisites() != null ) && ( project.getPrerequisites().getMaven() != null ) )
{
DefaultArtifactVersion version = new DefaultArtifactVersion( project.getPrerequisites().getMaven() );
if ( runtimeInformation.getApplicationInformation().getVersion().compareTo( version ) < 0 )
{
throw new MavenExecutionException( "Unable to build project '" + file + "; it requires Maven version " + version.toString(), file );
}
}
if ( ( project.getModules() != null ) && !project.getModules().isEmpty() && request.isRecursive() )
{
File basedir = file.getParentFile();
List<File> moduleFiles = new ArrayList<File>();
for ( String name : project.getModules() )
{
if ( StringUtils.isEmpty( StringUtils.trim( name ) ) )
{
continue;
}
File moduleFile = new File( basedir, name );
if ( !moduleFile.exists() )
{
throw new MissingModuleException( name, moduleFile, file );
}
else if ( moduleFile.isDirectory() )
{
moduleFile = new File( basedir, name + "/" + Maven.POMv4 );
}
if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
{
// we don't canonicalize on unix to avoid interfering with symlinks
try
{
moduleFile = moduleFile.getCanonicalFile();
}
catch ( IOException e )
{
throw new MavenExecutionException( "Unable to canonicalize file name " + moduleFile, e );
}
}
else
{
moduleFile = new File( moduleFile.toURI().normalize() );
}
moduleFiles.add( moduleFile );
}
List<MavenProject> collectedProjects = collectProjects( moduleFiles, request );
projects.addAll( collectedProjects );
project.setCollectedProjects( collectedProjects );
}
}
else
{
File projectFile = new File( userDir, POMv4 );
if ( projectFile.exists() )
{
files = Collections.singletonList( projectFile );
}
projects.add( project );
}
return files;
}
// Lifecycle phases
public List<Lifecycle> getBuildLifecyclePhases()
{
// TODO Auto-generated method stub
return null;
}
public List<Lifecycle> getCleanLifecyclePhases()
{
// TODO Auto-generated method stub
return null;
}
public List<Lifecycle> getSiteLifecyclePhases()
{
// TODO Auto-generated method stub
return null;
return projects;
}
}

View File

@ -31,13 +31,9 @@ import org.apache.maven.execution.ReactorManager;
*/
public interface Maven
{
//jvz!! CLI pollution
String POMv4 = "pom.xml";
MavenExecutionResult execute( MavenExecutionRequest request );
//!!jvz This should not be exposed but is as a result of the buildProjectWithDependencies
ReactorManager createReactorManager( MavenExecutionRequest request, MavenExecutionResult result );
List getLifecyclePhases();
List<String> getLifecyclePhases();
}

View File

@ -1,20 +0,0 @@
package org.apache.maven;
/**
* Exception indicating that Maven has no instructions for what to execute. This
* happens when no goals are specified on the command line, and there is no
* defaultGoal specified in the POM itself.
*
* @author jdcasey
*
*/
public class NoGoalsSpecifiedException
extends BuildFailureException
{
public NoGoalsSpecifiedException( String message )
{
super( message );
}
}

View File

@ -31,7 +31,6 @@ import org.apache.maven.wagon.events.TransferListener;
/**
* @author Jason van Zyl
* @version $Id$
*/
public class DefaultMavenExecutionRequest
implements MavenExecutionRequest
@ -133,12 +132,10 @@ public class DefaultMavenExecutionRequest
copy.setGlobalSettingsFile( original.getGlobalSettingsFile() );
copy.setBaseDirectory( new File( original.getBaseDirectory() ) );
copy.setGoals( original.getGoals() );
copy.setUseReactor( original.useReactor() );
copy.setRecursive( original.isRecursive() );
copy.setPom( original.getPom() );
copy.setReactorFailureBehavior( original.getReactorFailureBehavior() );
copy.setProperties( original.getProperties() );
copy.setStartTime( original.getStartTime() );
copy.setShowErrors( original.isShowErrors() );
copy.setActiveProfiles( original.getActiveProfiles());
copy.setInactiveProfiles( original.getInactiveProfiles());

View File

@ -101,9 +101,6 @@ public interface MavenExecutionRequest
MavenExecutionRequest setReactorFailureBehavior( String failureBehavior );
String getReactorFailureBehavior();
MavenExecutionRequest setUseReactor( boolean useReactor );
boolean useReactor();
// Recursive (really to just process the top-level POM)
MavenExecutionRequest setRecursive( boolean recursive );
boolean isRecursive();

View File

@ -19,22 +19,15 @@ package org.apache.maven.execution;
* under the License.
*/
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilderConfiguration;
import org.apache.maven.reporting.MavenReport;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.util.dag.CycleDetectedException;
@ -125,11 +118,6 @@ public class MavenSession
return request.isProjectPresent();
}
public Date getStartTime()
{
return request.getStartTime();
}
public MavenExecutionRequest getRequest()
{
return request;
@ -140,9 +128,6 @@ public class MavenSession
this.currentProject = currentProject;
}
/**
* Return the current project for use in a mojo execution.
*/
public MavenProject getCurrentProject()
{
return currentProject;

View File

@ -29,6 +29,10 @@ import org.apache.maven.execution.ReactorManager;
import org.apache.maven.lifecycle.mapping.LifecycleMapping;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.PluginConfigurationException;
import org.apache.maven.plugin.PluginExecutionException;
import org.apache.maven.plugin.PluginLoaderException;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
@ -184,35 +188,30 @@ public class DefaultLifecycleExecutor
{
List<MojoDescriptor> lifecyclePlan = calculateLifecyclePlan( task, session );
for( MojoDescriptor md : lifecyclePlan )
for ( MojoDescriptor mojoDescriptor : lifecyclePlan )
{
System.out.println( md.getFullGoalName() );
}
/*
for ( MojoExecution mojoExecution : goals )
{
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
try
{
pluginManager.executeMojo( project, mojoExecution, session );
}
catch ( PluginManagerException e )
{
throw new LifecycleExecutionException( "Internal error in the plugin manager executing goal '" + mojoDescriptor.getId() + "': " + e.getMessage(), e );
}
catch ( MojoFailureException e )
{
throw new BuildFailureException( e.getMessage(), e );
}
catch ( PluginConfigurationException e )
{
throw new LifecycleExecutionException( e.getMessage(), e );
}
}
*/
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor );
try
{
pluginManager.executeMojo( project, mojoExecution, session );
}
catch ( MojoFailureException e )
{
// If the mojo actually screws up, like a compilation error
throw new LifecycleExecutionException( "Error executing goal.", e );
}
catch ( PluginExecutionException e )
{
// This looks like a duplicate
throw new LifecycleExecutionException( "Error executing goal.", e );
}
catch ( PluginConfigurationException e )
{
// If the mojo can't actually be configured
throw new LifecycleExecutionException( "Error executing goal.", e );
}
}
}
// 1. Find the lifecycle given the phase (default lifecycle when given install)

View File

@ -1,6 +1,6 @@
package org.apache.maven;
package org.apache.maven.lifecycle;
import org.apache.maven.lifecycle.TaskValidationResult;
import org.apache.maven.BuildFailureException;
/**
* Exception which occurs when a task or goal is specified on the command line

View File

@ -1,6 +1,5 @@
package org.apache.maven.lifecycle;
import org.apache.maven.InvalidTaskException;
import org.apache.maven.plugin.InvalidPluginException;
import org.apache.maven.plugin.PluginLoaderException;

View File

@ -29,7 +29,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
//TODO: all of this needs to be translated into the RepositorySystem or removed.
import org.apache.maven.ArtifactFilterManager;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
@ -48,7 +47,6 @@ import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
// end
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.RuntimeInformation;
import org.apache.maven.model.Dependency;
@ -59,7 +57,6 @@ import org.apache.maven.monitor.logging.DefaultLog;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
import org.apache.maven.project.DuplicateArtifactAttachmentException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
@ -69,7 +66,6 @@ import org.apache.maven.project.builder.PomInterpolatorTag;
import org.apache.maven.project.builder.PomTransformer;
import org.apache.maven.project.builder.ProjectUri;
import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.reporting.MavenReport;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.repository.VersionNotFoundException;
import org.apache.maven.shared.model.InterpolatorProperty;
@ -107,8 +103,6 @@ public class DefaultPluginManager
@Requirement
protected PlexusContainer container;
protected PluginDescriptorBuilder pluginDescriptorBuilder;
@Requirement
protected ArtifactFilterManager coreArtifactFilterManager;
@ -136,11 +130,6 @@ public class DefaultPluginManager
private Map<String,org.apache.maven.model.Plugin> pluginDefinitionsByPrefix = new HashMap<String,org.apache.maven.model.Plugin>();
public DefaultPluginManager()
{
pluginDescriptorBuilder = new PluginDescriptorBuilder();
}
// This should be template method code for allowing subclasses to assist in contributing search/hint information
public Plugin findPluginForPrefix( String prefix, MavenProject project, MavenSession session )
{
@ -151,18 +140,20 @@ public class DefaultPluginManager
throws PluginLoaderException
{
PluginDescriptor pluginDescriptor = pluginCollector.getPluginDescriptor( plugin );
if ( pluginDescriptor != null )
// There are cases where plugins are discovered but not actually populated. These are edge cases where you are working in the IDE on
// Maven itself so this speaks to a problem we have with the system not starting entirely clean.
if ( pluginDescriptor != null && pluginDescriptor.getClassRealm() != null )
{
return pluginDescriptor;
}
try
{
{
resolvePluginVersion( plugin, project, session );
addPlugin( plugin, project, session );
pluginDescriptor = pluginCollector.getPluginDescriptor( plugin );
project.addPlugin( plugin );
@ -194,9 +185,6 @@ public class DefaultPluginManager
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
}
// We need to load different
private Map<String,ClassRealm> pluginRealms = new HashMap<String,ClassRealm>();
private String pluginKey( Plugin plugin )
{
@ -205,9 +193,7 @@ public class DefaultPluginManager
protected void addPlugin( Plugin plugin, MavenProject project, MavenSession session )
throws ArtifactNotFoundException, ArtifactResolutionException, PluginManagerException, InvalidPluginException, PluginVersionResolutionException
{
logger.debug( "Resolving plugin artifact " + plugin.getKey() + " from " + project.getRemoteArtifactRepositories() );
{
ArtifactRepository localRepository = session.getLocalRepository();
MavenProject pluginProject = buildPluginProject( plugin, localRepository, project.getRemoteArtifactRepositories() );
@ -224,94 +210,43 @@ public class DefaultPluginManager
ArtifactResolutionResult result = repositorySystem.resolve( request );
resolutionErrorHandler.throwErrors( request, result );
// ----------------------------------------------------------------------------
// Get the dependencies for the Plugin
// ----------------------------------------------------------------------------
resolutionErrorHandler.throwErrors( request, result );
// the only Plugin instance which will have dependencies is the one specified in the project.
// We need to look for a Plugin instance there, in case the instance we're using didn't come from
// the project.
// Trying to cache the version of the plugin for a project?
Plugin projectPlugin = project.getPlugin( plugin.getKey() );
ClassRealm pluginRealm = container.createChildRealm( pluginKey( plugin ) );
if ( projectPlugin == null )
Set<Artifact> pluginArtifacts = getPluginArtifacts( pluginArtifact, plugin, project, session.getLocalRepository() );
for ( Artifact a : pluginArtifacts )
{
projectPlugin = plugin;
}
else if ( projectPlugin.getVersion() == null || Artifact.RELEASE_VERSION.equals( projectPlugin.getVersion() ) )
{
projectPlugin.setVersion( plugin.getVersion() );
}
// associate the realm with the descriptor
ClassRealm pluginRealm = pluginRealms.get( pluginKey( plugin ) );
if ( pluginRealm == null )
{
pluginRealm = container.createChildRealm( pluginKey( plugin ) );
Set<Artifact> pluginArtifacts = getPluginArtifacts( pluginArtifact, projectPlugin, project, session.getLocalRepository() );
for( Artifact a : pluginArtifacts )
{
try
{
pluginRealm.addURL( a.getFile().toURI().toURL() );
}
catch ( MalformedURLException e )
{
// Not going to happen
}
}
try
{
logger.debug( "Discovering components in realm: " + pluginRealm );
container.discoverComponents( pluginRealm );
pluginRealm.addURL( a.getFile().toURI().toURL() );
}
catch ( PlexusConfigurationException e )
catch ( MalformedURLException e )
{
throw new PluginContainerException( plugin, pluginRealm, "Error scanning plugin realm for components.", e );
// Not going to happen
}
catch ( ComponentRepositoryException e )
{
throw new PluginContainerException( plugin, pluginRealm, "Error scanning plugin realm for components.", e );
}
// ----------------------------------------------------------------------------
// The PluginCollector will now know about the plugin we are trying to load
// ----------------------------------------------------------------------------
logger.debug( "Checking for plugin descriptor for: " + projectPlugin.getKey() + " with version: " + projectPlugin.getVersion() + " in collector: " + pluginCollector );
PluginDescriptor pluginDescriptor = pluginCollector.getPluginDescriptor( projectPlugin );
if ( pluginDescriptor == null )
{
if ( ( pluginRealm != null ) && logger.isDebugEnabled() )
{
logger.debug( "Plugin Realm: " );
pluginRealm.display();
}
logger.debug( "Removing invalid plugin realm." );
throw new PluginManagerException( projectPlugin, "The plugin descriptor for the plugin " + projectPlugin.getKey() + " was not found. Should have been in realm: " + pluginRealm
+ " Please verify that the plugin JAR " + pluginArtifact.getFile() + " is intact.", project );
}
pluginDescriptor.setPluginArtifact( pluginArtifact );
// Make sure it's just the plugin artifacts
pluginDescriptor.setArtifacts( new ArrayList<Artifact>( pluginArtifacts ) );
pluginDescriptor.setClassRealm( pluginRealm );
pluginRealms.put( pluginKey( plugin ), pluginRealm );
}
try
{
logger.debug( "Discovering components in realm: " + pluginRealm );
container.discoverComponents( pluginRealm );
}
catch ( PlexusConfigurationException e )
{
throw new PluginContainerException( plugin, pluginRealm, "Error scanning plugin realm for components.", e );
}
catch ( ComponentRepositoryException e )
{
throw new PluginContainerException( plugin, pluginRealm, "Error scanning plugin realm for components.", e );
}
PluginDescriptor pluginDescriptor = pluginCollector.getPluginDescriptor( plugin );
pluginDescriptor.setPluginArtifact( pluginArtifact );
pluginDescriptor.setArtifacts( new ArrayList<Artifact>( pluginArtifacts ) );
pluginDescriptor.setClassRealm( pluginRealm );
}
// plugin artifact
@ -563,12 +498,8 @@ public class DefaultPluginManager
{
mojo = getConfiguredMojo( session, dom, project, false, mojoExecution );
//dispatcher.dispatchStart( event, goalExecId );
pluginRealm = pluginDescriptor.getClassRealm();
logger.debug( "Setting context classloader for plugin to: " + pluginRealm.getId() + " (instance is: " + pluginRealm + ")" );
Thread.currentThread().setContextClassLoader( pluginRealm );
// NOTE: DuplicateArtifactAttachmentException is currently unchecked, so be careful removing this try/catch!
@ -627,7 +558,6 @@ public class DefaultPluginManager
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
ClassRealm pluginRealm = pluginDescriptor.getClassRealm();
System.out.println( "XXX Looking for class realm " + pluginDescriptor.getArtifactId() + ":" + pluginDescriptor.getVersion() );
// We are forcing the use of the plugin realm for all lookups that might occur during
// the lifecycle that is part of the lookup. Here we are specifically trying to keep
@ -652,15 +582,6 @@ public class DefaultPluginManager
+ pluginDescriptor.getPluginLookupKey() + "'", e );
}
if ( mojo != null )
{
logger.debug( "Looked up - " + mojo + " - " + mojo.getClass().getClassLoader() );
}
else
{
logger.warn( "No luck." );
}
if ( mojo instanceof ContextEnabled )
{
Map<String,Object> pluginContext = session.getPluginContext( pluginDescriptor, project );
@ -775,7 +696,7 @@ public class DefaultPluginManager
private PlexusConfiguration extractMojoConfiguration( PlexusConfiguration mergedConfiguration, MojoDescriptor mojoDescriptor )
{
Map parameterMap = mojoDescriptor.getParameterMap();
Map<String,Parameter> parameterMap = mojoDescriptor.getParameterMap();
PlexusConfiguration[] mergedChildren = mergedConfiguration.getChildren();
@ -1288,10 +1209,8 @@ public class DefaultPluginManager
if ( project.getBuildPlugins() != null )
{
for ( Iterator it = project.getBuildPlugins().iterator(); it.hasNext() && ( version == null ); )
for ( Plugin p : project.getBuildPlugins() )
{
Plugin p = (Plugin) it.next();
if ( groupId.equals( p.getGroupId() ) && artifactId.equals( p.getArtifactId() ) )
{
version = p.getVersion();
@ -1538,6 +1457,10 @@ public class DefaultPluginManager
public MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, MavenSession session )
throws PluginLoaderException
{
return loadPlugin( plugin, session.getCurrentProject(), session ).getMojo( goal );
PluginDescriptor pluginDescriptor = loadPlugin( plugin, session.getCurrentProject(), session );
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal );
return mojoDescriptor;
}
}

View File

@ -54,11 +54,11 @@ public class MavenPluginCollector
PluginDescriptor pluginDescriptor = (PluginDescriptor) componentSetDescriptor;
String key = constructPluginKey( pluginDescriptor );
if ( !pluginsInProcess.contains( key ) )
{
pluginsInProcess.add( key );
pluginDescriptors.put( key, pluginDescriptor );
}
}

View File

@ -39,10 +39,6 @@ public class MojoExecution
private Xpp3Dom configuration;
private List forkedExecutions = new ArrayList();
private List reports;
public MojoExecution( MojoDescriptor mojoDescriptor )
{
this.mojoDescriptor = mojoDescriptor;
@ -79,26 +75,6 @@ public class MojoExecution
return configuration;
}
public void addMojoExecution( MojoExecution execution )
{
forkedExecutions.add( execution );
}
public void setReports( List reports )
{
this.reports = reports;
}
public List getReports()
{
return reports;
}
public List getForkedExecutions()
{
return forkedExecutions;
}
public void setConfiguration( Xpp3Dom configuration )
{
this.configuration = configuration;

View File

@ -66,28 +66,37 @@ public abstract class AbstractCoreMavenComponentTest
containerConfiguration.addComponentDiscoveryListener( new MavenPluginCollector() );
}
// - remove the event monitor, just default or get rid of it
// layer the creation of a project builder configuration with a request, but this will need to be
// a Maven subclass because we don't want to couple maven to the project builder which we need to
// separate.
protected MavenSession createMavenSession( File pom )
protected MavenExecutionRequest createMavenExecutionRequest( File pom )
throws Exception
{
ArtifactRepository localRepository = repositorySystem.createDefaultLocalRepository();
ArtifactRepository remoteRepository = repositorySystem.createDefaultRemoteRepository();
MavenExecutionRequest request = new DefaultMavenExecutionRequest()
.setPom( pom )
.setProjectPresent( true )
.setPluginGroups( Arrays.asList( new String[] { "org.apache.maven.plugins" } ) )
.setLocalRepository( localRepository )
.setRemoteRepositories( Arrays.asList( remoteRepository ) )
.setGoals( Arrays.asList( new String[] { "package" } ) )
.setProperties( new Properties() );
.setProperties( new Properties() );
return request;
}
// layer the creation of a project builder configuration with a request, but this will need to be
// a Maven subclass because we don't want to couple maven to the project builder which we need to
// separate.
protected MavenSession createMavenSession( File pom )
throws Exception
{
MavenExecutionRequest request = createMavenExecutionRequest( pom );
ProjectBuilderConfiguration configuration = new DefaultProjectBuilderConfiguration()
.setLocalRepository( localRepository )
.setRemoteRepositories( Arrays.asList( remoteRepository ) );
.setLocalRepository( request.getLocalRepository() )
.setRemoteRepositories( request.getRemoteRepositories() );
// We just need to use the configuration, and get the POM from that.
MavenProject project = projectBuilder.build( pom, configuration );
MavenSession session = new MavenSession( getContainer(), request, project );

View File

@ -0,0 +1,38 @@
package org.apache.maven;
import java.io.File;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
import org.codehaus.plexus.component.annotations.Requirement;
public class MavenTest
extends AbstractCoreMavenComponentTest
{
@Requirement
private Maven maven;
protected void setUp()
throws Exception
{
super.setUp();
maven = lookup( Maven.class );
}
protected String getProjectsDirectory()
{
return "src/test/projects/lifecycle-executor";
}
// -----------------------------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------------------------
public void testMaven()
throws Exception
{
File pom = getProject( "project-with-additional-lifecycle-elements" );
MavenExecutionRequest request = createMavenExecutionRequest( pom );
MavenExecutionResult result = maven.execute( request );
}
}

View File

@ -25,6 +25,43 @@ public class PluginManagerTest
return "src/test/projects/lifecycle-executor";
}
public void testPluginLoading()
throws Exception
{
MavenSession session = createMavenSession( getProject( "project-with-inheritance" ) );
Plugin plugin = new Plugin();
plugin.setGroupId( "org.codehaus.plexus" );
plugin.setArtifactId( "plexus-component-metadata" );
plugin.setVersion( "1.0-beta-3.0.6" );
PluginDescriptor pluginDescriptor = pluginManager.loadPlugin( plugin, session.getCurrentProject(), session );
assertNotNull( pluginDescriptor );
assertNotNull( pluginDescriptor.getClassRealm() );
}
public void testMojoDescriptorRetrieval()
throws Exception
{
MavenSession session = createMavenSession( getProject( "project-with-inheritance" ) );
String goal = "generate-metadata";
Plugin plugin = new Plugin();
plugin.setGroupId( "org.codehaus.plexus" );
plugin.setArtifactId( "plexus-component-metadata" );
plugin.setVersion( "1.0-beta-3.0.6" );
MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( plugin, goal, session );
assertNotNull( mojoDescriptor );
assertEquals( "generate-metadata", mojoDescriptor.getGoal() );
assertNotNull( mojoDescriptor.getRealm() );
mojoDescriptor.getRealm().display();
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
assertNotNull( pluginDescriptor );
assertEquals( "org.codehaus.plexus", pluginDescriptor.getGroupId() );
assertEquals( "plexus-component-metadata", pluginDescriptor.getArtifactId() );
assertEquals( "1.0-beta-3.0.6", pluginDescriptor.getVersion() );
assertNotNull( pluginDescriptor.getClassRealm() );
}
// -----------------------------------------------------------------------------------------------
// Tests which exercise the lifecycle executor when it is dealing with individual goals.
// -----------------------------------------------------------------------------------------------

View File

@ -23,7 +23,6 @@ package org.apache.maven.plugin;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@ -345,7 +344,6 @@ public class PluginParameterExpressionEvaluatorTest
{
MavenExecutionRequest request = new DefaultMavenExecutionRequest()
.setProperties( new Properties() )
.setStartTime( new Date() )
.setGoals( Collections.EMPTY_LIST )
.setBaseDirectory( new File( "" ) )
.setLocalRepository( repo );

View File

@ -229,7 +229,6 @@ public final class CLIRequestUtils
.setUserProperties( userProperties ) // optional
.setReactorFailureBehavior( reactorFailureBehaviour ) // default: fail fast
.setRecursive( recursive ) // default: true
.setUseReactor( useReactor ) // default: false
.setShowErrors( showErrors ) // default: false
.setInteractiveMode( interactive ) // default: true
.setOffline( offline ) // default: false

View File

@ -23,7 +23,6 @@ import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.Arrays;
import java.util.List;
import org.apache.maven.Maven;
@ -34,7 +33,6 @@ import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.ReactorManager;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
@ -64,7 +62,6 @@ import org.codehaus.plexus.MutablePlexusContainer;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.PlexusContainerException;
import org.codehaus.plexus.classworlds.ClassWorld;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.logging.LoggerManager;
import org.codehaus.plexus.util.IOUtil;
@ -116,8 +113,6 @@ public class MavenEmbedder
private ClassWorld classWorld;
private ClassRealm realm;
private MavenEmbedderLogger logger;
private boolean activateSystemManager;
@ -329,12 +324,16 @@ public class MavenEmbedder
return result.addException( e );
}
//TODO: need to check for circularity problems here even though this is purely downloading and for IDEs they will take care of circularity problems.
/*
ReactorManager reactorManager = maven.createReactorManager( request, result );
if ( result.hasExceptions() )
{
return result;
}
*/
MavenProjectBuildingResult projectBuildingResult;
@ -347,6 +346,7 @@ public class MavenEmbedder
return result.addException( e );
}
/*
if ( reactorManager.hasMultipleProjects() )
{
result.setProject( projectBuildingResult.getProject() );
@ -359,6 +359,7 @@ public class MavenEmbedder
result.setTopologicallySortedProjects( Arrays.asList( new MavenProject[]{ projectBuildingResult.getProject()} ) );
}
*/
result.setArtifactResolutionResult( projectBuildingResult.getArtifactResolutionResult() );
@ -605,7 +606,7 @@ public class MavenEmbedder
return container;
}
public List getLifecyclePhases()
public List<String> getLifecyclePhases()
{
return maven.getLifecyclePhases();
}

View File

@ -80,8 +80,6 @@ public class DefaultMavenExecutionRequestPopulator
{
executionProperties( request, configuration );
pom( request, configuration );
settings( request, configuration );
localRepository( request, configuration );
@ -252,38 +250,6 @@ public class DefaultMavenExecutionRequestPopulator
request.setRemoteRepositories( repositorySystem.getMirrors( request.getRemoteRepositories() ) );
}
// ------------------------------------------------------------------------
// POM
// ------------------------------------------------------------------------
private void pom( MavenExecutionRequest request, Configuration configuration )
{
// ------------------------------------------------------------------------
// POM
//
// If we are not given a specific POM file, but passed a base directory
// then we will use a release POM in the directory provide, or and then
// look for the standard POM.
// ------------------------------------------------------------------------
if ( ( request.getPom() != null ) && ( request.getPom().getParentFile() != null ) )
{
request.setBaseDirectory( request.getPom().getParentFile() );
}
else if ( ( request.getPom() == null ) && ( request.getBaseDirectory() != null ) )
{
// Look for a release POM
File pom = new File( request.getBaseDirectory(), Maven.POMv4 );
request.setPom( pom );
}
// TODO: Is this correct?
else if ( request.getBaseDirectory() == null )
{
request.setBaseDirectory( new File( System.getProperty( "user.dir" ) ) );
}
}
// ------------------------------------------------------------------------
// Settings
// ------------------------------------------------------------------------

View File

@ -19,27 +19,17 @@ package org.apache.maven.plugin.descriptor;
* under the License.
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.plugin.lifecycle.Lifecycle;
import org.apache.maven.plugin.lifecycle.LifecycleConfiguration;
import org.apache.maven.plugin.lifecycle.io.xpp3.LifecycleMappingsXpp3Reader;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
/**
* @author Jason van Zyl
*/
@ -60,8 +50,6 @@ public class PluginDescriptor
private List artifacts;
private Map lifecycleMappings;
private ClassRealm classRealm;
// calculated on-demand.
@ -266,9 +254,11 @@ public class PluginDescriptor
// changes above not being propogated to the map
MojoDescriptor mojoDescriptor = null;
for ( Iterator i = getMojos().iterator(); i.hasNext() && mojoDescriptor == null; )
{
MojoDescriptor desc = (MojoDescriptor) i.next();
if ( goal.equals( desc.getGoal() ) )
{
mojoDescriptor = desc;
@ -277,43 +267,6 @@ public class PluginDescriptor
return mojoDescriptor;
}
public Lifecycle getLifecycleMapping( String lifecycle )
throws IOException, XmlPullParserException
{
if ( lifecycleMappings == null )
{
LifecycleMappingsXpp3Reader reader = new LifecycleMappingsXpp3Reader();
InputStreamReader r = null;
LifecycleConfiguration config;
try
{
InputStream resourceAsStream = classRealm.getResourceAsStream( "/META-INF/maven/lifecycle.xml" );
if ( resourceAsStream == null )
{
throw new FileNotFoundException( "Unable to find /META-INF/maven/lifecycle.xml in the plugin" );
}
r = new InputStreamReader( resourceAsStream );
config = reader.read( r, true );
}
finally
{
IOUtil.close( r );
}
Map map = new HashMap();
for ( Iterator i = config.getLifecycles().iterator(); i.hasNext(); )
{
Lifecycle l = (Lifecycle) i.next();
map.put( l.getId(), l );
}
lifecycleMappings = map;
}
return (Lifecycle) lifecycleMappings.get( lifecycle );
}
public void setClassRealm( ClassRealm classRealm )
{
this.classRealm = classRealm;