PR: MNG-249

make compile and package reactor aware



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@225731 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-07-28 09:32:32 +00:00
parent f9eaca7ab0
commit 9a86709abd
21 changed files with 176 additions and 49 deletions

View File

@ -73,7 +73,8 @@ public class DefaultArtifactResolver
boolean force ) boolean force )
throws ArtifactResolutionException throws ArtifactResolutionException
{ {
if ( artifact != null ) // skip artifacts with a file - they are already resolved
if ( artifact != null && artifact.getFile() == null )
{ {
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Check for the existence of the artifact in the specified local // Check for the existence of the artifact in the specified local

View File

@ -30,6 +30,7 @@ import java.util.regex.Pattern;
* Description of an artifact. * Description of an artifact.
* *
* @todo do we really need an interface here? * @todo do we really need an interface here?
* @todo get rid of the multiple states we can have (project, parent, etc artifacts, file == null, snapshot, etc) - construct subclasses and use accordingly?
*/ */
public interface Artifact public interface Artifact
extends Comparable extends Comparable

View File

@ -120,6 +120,8 @@ it0040: Test the use of a packaging from a plugin
it0041: Test the use of a new type from a plugin it0041: Test the use of a new type from a plugin
it0042: Test that the reactor can establish the artifact location of known projects for dependencies
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
- generated sources - generated sources

View File

@ -1,3 +1,4 @@
it0042
it0041 it0041
it0040 it0040
it0039 it0039

View File

@ -0,0 +1,3 @@
test-component-a/target/test-component-a-0.1.jar
test-component-b/target/test-component-b-0.1.war
test-component-b/target/test-component-b-0.1.war!/WEB-INF/lib/test-component-a-0.1.jar

View File

@ -0,0 +1,2 @@
compile
package

View File

@ -0,0 +1,13 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test-components</artifactId>
<version>0.1</version>
<name>Test Components</name>
<packaging>pom</packaging>
<modules>
<module>test-component-a</module>
<module>test-component-b</module>
</modules>
</project>

View File

@ -0,0 +1,14 @@
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>test-components</artifactId>
<groupId>test</groupId>
<version>0.1</version>
</parent>
<groupId>test</groupId>
<artifactId>test-component-a</artifactId>
<version>0.1</version>
<name>Test Component A</name>
<packaging>jar</packaging>
</project>

View File

@ -0,0 +1,3 @@
public class A {
}

View File

@ -0,0 +1,22 @@
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>test-components</artifactId>
<groupId>test</groupId>
<version>0.1</version>
</parent>
<groupId>test</groupId>
<artifactId>test-component-b</artifactId>
<version>0.1</version>
<name>Test Component B</name>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>test</groupId>
<artifactId>test-component-a</artifactId>
<version>0.1</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,5 @@
public class B
extends A
{
}

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app >
</web-app>

View File

@ -1051,7 +1051,7 @@ public class DefaultPluginManager
// check this with yourkit as a hot spot. // check this with yourkit as a hot spot.
try try
{ {
project.setDependencyArtifacts( MavenProject.createArtifacts( artifactFactory, project.getDependencies() ) ); project.setDependencyArtifacts( project.createArtifacts( artifactFactory ) );
} }
catch ( InvalidVersionSpecificationException e ) catch ( InvalidVersionSpecificationException e )
{ {

View File

@ -22,5 +22,10 @@
<artifactId>plexus-compiler-javac</artifactId> <artifactId>plexus-compiler-javac</artifactId>
<version>1.4</version> <version>1.4</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>2.0-beta-1-SNAPSHOT</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -79,7 +79,7 @@ public abstract class AbstractCompilerMojo
protected abstract List getCompileSourceRoots(); protected abstract List getCompileSourceRoots();
protected abstract String getOutputDirectory(); protected abstract File getOutputDirectory();
public void execute() public void execute()
throws MojoExecutionException throws MojoExecutionException
@ -97,7 +97,7 @@ public abstract class AbstractCompilerMojo
CompilerConfiguration compilerConfiguration = new CompilerConfiguration(); CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
compilerConfiguration.setOutputLocation( getOutputDirectory() ); compilerConfiguration.setOutputLocation( getOutputDirectory().getAbsolutePath() );
compilerConfiguration.setClasspathEntries( getClasspathElements() ); compilerConfiguration.setClasspathEntries( getClasspathElements() );
compilerConfiguration.setSourceLocations( compileSourceRoots ); compilerConfiguration.setSourceLocations( compileSourceRoots );
@ -131,7 +131,7 @@ public abstract class AbstractCompilerMojo
compilerConfiguration.setDebug( debug ); compilerConfiguration.setDebug( debug );
List messages = null; List messages;
try try
{ {
messages = compiler.compile( compilerConfiguration ); messages = compiler.compile( compilerConfiguration );
@ -169,8 +169,6 @@ public abstract class AbstractCompilerMojo
scanner.addSourceMapping( mapping ); scanner.addSourceMapping( mapping );
File outDir = new File( getOutputDirectory() );
Set staleSources = new HashSet(); Set staleSources = new HashSet();
for ( Iterator it = getCompileSourceRoots().iterator(); it.hasNext(); ) for ( Iterator it = getCompileSourceRoots().iterator(); it.hasNext(); )
@ -186,7 +184,7 @@ public abstract class AbstractCompilerMojo
try try
{ {
staleSources.addAll( scanner.getIncludedSources( rootFile, outDir ) ); staleSources.addAll( scanner.getIncludedSources( rootFile, getOutputDirectory() ) );
} }
catch ( InclusionScanException e ) catch ( InclusionScanException e )
{ {

View File

@ -14,7 +14,10 @@ package org.apache.maven.plugin;
* the License. * the License.
*/ */
import org.apache.maven.artifact.Artifact;
import java.util.List; import java.util.List;
import java.io.File;
/** /**
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a> * @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
@ -34,21 +37,29 @@ public class CompilerMojo
* @readonly * @readonly
*/ */
private List compileSourceRoots; private List compileSourceRoots;
/** /**
* @parameter expression="${project.compileClasspathElements}" * @parameter expression="${project.compileClasspathElements}"
* @required * @required
* @readonly * @readonly
*/ */
private List classpathElements; private List classpathElements;
/** /**
* @parameter expression="${project.build.outputDirectory}" * @parameter expression="${project.build.outputDirectory}"
* @required * @required
* @readonly * @readonly
*/ */
private String outputDirectory; private File outputDirectory;
/**
* @parameter expression="${project.artifact}"
* @required
* @readonly
* @todo this is an export variable, really
*/
private Artifact projectArtifact;
protected List getCompileSourceRoots() protected List getCompileSourceRoots()
{ {
return compileSourceRoots; return compileSourceRoots;
@ -59,9 +70,16 @@ public class CompilerMojo
return classpathElements; return classpathElements;
} }
protected String getOutputDirectory() protected File getOutputDirectory()
{ {
return outputDirectory; return outputDirectory;
} }
public void execute()
throws MojoExecutionException
{
super.execute();
projectArtifact.setFile( outputDirectory );
}
} }

View File

@ -1,6 +1,7 @@
package org.apache.maven.plugin; package org.apache.maven.plugin;
import java.util.List; import java.util.List;
import java.io.File;
/* /*
* Copyright 2001-2005 The Apache Software Foundation. * Copyright 2001-2005 The Apache Software Foundation.
@ -48,7 +49,7 @@ public class TestCompilerMojo
* @required * @required
* @readonly * @readonly
*/ */
private String outputDirectory; private File outputDirectory;
protected List getCompileSourceRoots() protected List getCompileSourceRoots()
{ {
@ -60,7 +61,7 @@ public class TestCompilerMojo
return classpathElements; return classpathElements;
} }
protected String getOutputDirectory() protected File getOutputDirectory()
{ {
return outputDirectory; return outputDirectory;
} }

View File

@ -98,6 +98,8 @@ public class JarMojo
} }
archiver.createArchive( project, archive ); archiver.createArchive( project, archive );
project.getArtifact().setFile( jarFile );
} }
catch ( Exception e ) catch ( Exception e )
{ {

View File

@ -154,8 +154,7 @@ public class DefaultMavenProjectBuilder
try try
{ {
project.setDependencyArtifacts( project.setDependencyArtifacts( project.createArtifacts( artifactFactory ) );
MavenProject.createArtifacts( artifactFactory, project.getDependencies() ) );
} }
catch ( InvalidVersionSpecificationException e ) catch ( InvalidVersionSpecificationException e )
{ {
@ -474,7 +473,6 @@ public class DefaultMavenProjectBuilder
// TODO: maybe not strictly correct, while we should enfore that packaging has a type handler of the same id, we don't // TODO: maybe not strictly correct, while we should enfore that packaging has a type handler of the same id, we don't
Artifact projectArtifact = artifactFactory.createBuildArtifact( project.getGroupId(), project.getArtifactId(), Artifact projectArtifact = artifactFactory.createBuildArtifact( project.getGroupId(), project.getArtifactId(),
project.getVersion(), project.getPackaging() ); project.getVersion(), project.getPackaging() );
project.setArtifact( projectArtifact ); project.setArtifact( projectArtifact );
project.setPluginArtifactRepositories( ProjectUtils.buildArtifactRepositories( model.getPluginRepositories(), project.setPluginArtifactRepositories( ProjectUtils.buildArtifactRepositories( model.getPluginRepositories(),

View File

@ -52,11 +52,13 @@ import java.io.IOException;
import java.io.Writer; import java.io.Writer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.HashSet;
/** /**
* The concern of the project is provide runtime values based on the model. <p/> * The concern of the project is provide runtime values based on the model. <p/>
@ -124,6 +126,8 @@ public class MavenProject
private Map reportArtifactMap; private Map reportArtifactMap;
private Map projectReferences = new HashMap();
public MavenProject( Model model ) public MavenProject( Model model )
{ {
this.model = model; this.model = model;
@ -329,12 +333,21 @@ public class MavenProject
// TODO: let the scope handler deal with this // TODO: let the scope handler deal with this
if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() ) ) if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() ) )
{ {
File file = a.getFile(); String refId = getProjectReferenceId( a.getGroupId(), a.getArtifactId() );
if ( file == null ) MavenProject project = (MavenProject) projectReferences.get( refId );
if ( project != null )
{ {
throw new DependencyResolutionRequiredException( a ); list.add( project.getBuild().getOutputDirectory() );
}
else
{
File file = a.getFile();
if ( file == null )
{
throw new DependencyResolutionRequiredException( a );
}
list.add( file.getPath() );
} }
list.add( file.getPath() );
} }
} }
} }
@ -1217,9 +1230,41 @@ public class MavenProject
/** /**
* @todo the lazy initialisation of this makes me uneasy. * @todo the lazy initialisation of this makes me uneasy.
*/ */
public static Set createArtifacts( ArtifactFactory artifactFactory, List dependencies ) public Set createArtifacts( ArtifactFactory artifactFactory )
throws InvalidVersionSpecificationException throws InvalidVersionSpecificationException
{ {
return MavenMetadataSource.createArtifacts( artifactFactory, dependencies, null, null ); Set artifacts = new HashSet( getDependencies().size() );
List list = new ArrayList( getDependencies().size() );
for ( Iterator i = getDependencies().iterator(); i.hasNext(); )
{
Dependency dependency = (Dependency) i.next();
String refId = getProjectReferenceId( dependency.getGroupId(), dependency.getArtifactId() );
MavenProject project = (MavenProject) projectReferences.get( refId );
if ( project != null && project.getArtifact() != null )
{
// TODO: actually these need to be funnelled through the same process and the artifacts cloned somehow
project.getArtifact().setScope( dependency.getScope() );
artifacts.add( project.getArtifact() );
}
else
{
list.add( dependency );
}
}
artifacts.addAll( MavenMetadataSource.createArtifacts( artifactFactory, list, null, null ) );
return artifacts;
}
public void addProjectReference( MavenProject project )
{
projectReferences.put( getProjectReferenceId( project.getGroupId(), project.getArtifactId() ), project );
}
private static String getProjectReferenceId( String groupId, String artifactId )
{
return groupId + ":" + artifactId;
} }
} }

View File

@ -19,6 +19,7 @@ package org.apache.maven.project;
import org.apache.maven.model.Dependency; import org.apache.maven.model.Dependency;
import org.apache.maven.model.Extension; import org.apache.maven.model.Extension;
import org.apache.maven.model.Plugin; import org.apache.maven.model.Plugin;
import org.apache.maven.model.ReportPlugin;
import org.codehaus.plexus.util.dag.CycleDetectedException; import org.codehaus.plexus.util.dag.CycleDetectedException;
import org.codehaus.plexus.util.dag.DAG; import org.codehaus.plexus.util.dag.DAG;
import org.codehaus.plexus.util.dag.TopologicalSorter; import org.codehaus.plexus.util.dag.TopologicalSorter;
@ -64,7 +65,7 @@ public class ProjectSorter
{ {
MavenProject project = (MavenProject) i.next(); MavenProject project = (MavenProject) i.next();
String id = getProjectId( project ); String id = getId( project.getGroupId(), project.getArtifactId() );
dag.addVertex( id ); dag.addVertex( id );
@ -75,16 +76,18 @@ public class ProjectSorter
{ {
MavenProject project = (MavenProject) i.next(); MavenProject project = (MavenProject) i.next();
String id = getProjectId( project ); String id = getId( project.getGroupId(), project.getArtifactId() );
for ( Iterator j = project.getDependencies().iterator(); j.hasNext(); ) for ( Iterator j = project.getDependencies().iterator(); j.hasNext(); )
{ {
Dependency dependency = (Dependency) j.next(); Dependency dependency = (Dependency) j.next();
String dependencyId = getDependencyId( dependency ); String dependencyId = getId( dependency.getGroupId(), dependency.getArtifactId() );
if ( dag.getVertex( dependencyId ) != null ) if ( dag.getVertex( dependencyId ) != null )
{ {
project.addProjectReference( (MavenProject) projectMap.get( dependencyId ) );
dag.addEdge( id, dependencyId ); dag.addEdge( id, dependencyId );
} }
} }
@ -92,7 +95,7 @@ public class ProjectSorter
MavenProject parent = project.getParent(); MavenProject parent = project.getParent();
if ( parent != null ) if ( parent != null )
{ {
String parentId = getProjectId( parent ); String parentId = getId( parent.getGroupId(), parent.getArtifactId() );
if ( dag.getVertex( parentId ) != null ) if ( dag.getVertex( parentId ) != null )
{ {
dag.addEdge( id, parentId ); dag.addEdge( id, parentId );
@ -105,7 +108,7 @@ public class ProjectSorter
for ( Iterator j = buildPlugins.iterator(); j.hasNext(); ) for ( Iterator j = buildPlugins.iterator(); j.hasNext(); )
{ {
Plugin plugin = (Plugin) j.next(); Plugin plugin = (Plugin) j.next();
String pluginId = getPluginId( plugin ); String pluginId = getId( plugin.getGroupId(), plugin.getArtifactId() );
if ( dag.getVertex( pluginId ) != null ) if ( dag.getVertex( pluginId ) != null )
{ {
dag.addEdge( id, pluginId ); dag.addEdge( id, pluginId );
@ -118,8 +121,8 @@ public class ProjectSorter
{ {
for ( Iterator j = reportPlugins.iterator(); j.hasNext(); ) for ( Iterator j = reportPlugins.iterator(); j.hasNext(); )
{ {
Plugin plugin = (Plugin) j.next(); ReportPlugin plugin = (ReportPlugin) j.next();
String pluginId = getPluginId( plugin ); String pluginId = getId( plugin.getGroupId(), plugin.getArtifactId() );
if ( dag.getVertex( pluginId ) != null ) if ( dag.getVertex( pluginId ) != null )
{ {
dag.addEdge( id, pluginId ); dag.addEdge( id, pluginId );
@ -130,7 +133,7 @@ public class ProjectSorter
for ( Iterator j = project.getBuildExtensions().iterator(); j.hasNext(); ) for ( Iterator j = project.getBuildExtensions().iterator(); j.hasNext(); )
{ {
Extension extension = (Extension) j.next(); Extension extension = (Extension) j.next();
String extensionId = getExtensionId( extension ); String extensionId = getId( extension.getGroupId(), extension.getArtifactId() );
if ( dag.getVertex( extensionId ) != null ) if ( dag.getVertex( extensionId ) != null )
{ {
dag.addEdge( id, extensionId ); dag.addEdge( id, extensionId );
@ -150,23 +153,8 @@ public class ProjectSorter
return sortedProjects; return sortedProjects;
} }
private static String getExtensionId( Extension extension ) private static String getId( String groupId, String artifactId )
{ {
return extension.getGroupId() + ":" + extension.getArtifactId(); return groupId + ":" + artifactId;
}
private static String getPluginId( Plugin plugin )
{
return plugin.getGroupId() + ":" + plugin.getArtifactId();
}
private static String getDependencyId( Dependency dependency )
{
return dependency.getGroupId() + ":" + dependency.getArtifactId();
}
private static String getProjectId( MavenProject project )
{
return project.getGroupId() + ":" + project.getArtifactId();
} }
} }