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 @@ private void resolve( Artifact artifact, List remoteRepositories, ArtifactReposi
boolean force )
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

View File

@ -30,6 +30,7 @@
* Description of an artifact.
*
* @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
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
it0042: Test that the reactor can establish the artifact location of known projects for dependencies
-------------------------------------------------------------------------------
- generated sources

View File

@ -1,3 +1,4 @@
it0042
it0041
it0040
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 @@ private void resolveTransitiveDependencies( MavenSession context, ArtifactResolv
// check this with yourkit as a hot spot.
try
{
project.setDependencyArtifacts( MavenProject.createArtifacts( artifactFactory, project.getDependencies() ) );
project.setDependencyArtifacts( project.createArtifacts( artifactFactory ) );
}
catch ( InvalidVersionSpecificationException e )
{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -154,8 +154,7 @@ public MavenProject buildWithDependencies( File projectDescriptor, ArtifactRepos
try
{
project.setDependencyArtifacts(
MavenProject.createArtifacts( artifactFactory, project.getDependencies() ) );
project.setDependencyArtifacts( project.createArtifacts( artifactFactory ) );
}
catch ( InvalidVersionSpecificationException e )
{
@ -474,7 +473,6 @@ private MavenProject processProjectLogic( String pomLocation, MavenProject proje
// 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(),
project.getVersion(), project.getPackaging() );
project.setArtifact( projectArtifact );
project.setPluginArtifactRepositories( ProjectUtils.buildArtifactRepositories( model.getPluginRepositories(),

View File

@ -52,11 +52,13 @@
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.HashSet;
/**
* 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 projectReferences = new HashMap();
public MavenProject( Model model )
{
this.model = model;
@ -329,12 +333,21 @@ public List getCompileClasspathElements()
// TODO: let the scope handler deal with this
if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() ) )
{
File file = a.getFile();
if ( file == null )
String refId = getProjectReferenceId( a.getGroupId(), a.getArtifactId() );
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 List getBuildExtensions()
/**
* @todo the lazy initialisation of this makes me uneasy.
*/
public static Set createArtifacts( ArtifactFactory artifactFactory, List dependencies )
public Set createArtifacts( ArtifactFactory artifactFactory )
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 @@
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Extension;
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.DAG;
import org.codehaus.plexus.util.dag.TopologicalSorter;
@ -64,7 +65,7 @@ public static List getSortedProjects( List projects )
{
MavenProject project = (MavenProject) i.next();
String id = getProjectId( project );
String id = getId( project.getGroupId(), project.getArtifactId() );
dag.addVertex( id );
@ -75,16 +76,18 @@ public static List getSortedProjects( List projects )
{
MavenProject project = (MavenProject) i.next();
String id = getProjectId( project );
String id = getId( project.getGroupId(), project.getArtifactId() );
for ( Iterator j = project.getDependencies().iterator(); j.hasNext(); )
{
Dependency dependency = (Dependency) j.next();
String dependencyId = getDependencyId( dependency );
String dependencyId = getId( dependency.getGroupId(), dependency.getArtifactId() );
if ( dag.getVertex( dependencyId ) != null )
{
project.addProjectReference( (MavenProject) projectMap.get( dependencyId ) );
dag.addEdge( id, dependencyId );
}
}
@ -92,7 +95,7 @@ public static List getSortedProjects( List projects )
MavenProject parent = project.getParent();
if ( parent != null )
{
String parentId = getProjectId( parent );
String parentId = getId( parent.getGroupId(), parent.getArtifactId() );
if ( dag.getVertex( parentId ) != null )
{
dag.addEdge( id, parentId );
@ -105,7 +108,7 @@ public static List getSortedProjects( List projects )
for ( Iterator j = buildPlugins.iterator(); j.hasNext(); )
{
Plugin plugin = (Plugin) j.next();
String pluginId = getPluginId( plugin );
String pluginId = getId( plugin.getGroupId(), plugin.getArtifactId() );
if ( dag.getVertex( pluginId ) != null )
{
dag.addEdge( id, pluginId );
@ -118,8 +121,8 @@ public static List getSortedProjects( List projects )
{
for ( Iterator j = reportPlugins.iterator(); j.hasNext(); )
{
Plugin plugin = (Plugin) j.next();
String pluginId = getPluginId( plugin );
ReportPlugin plugin = (ReportPlugin) j.next();
String pluginId = getId( plugin.getGroupId(), plugin.getArtifactId() );
if ( dag.getVertex( pluginId ) != null )
{
dag.addEdge( id, pluginId );
@ -130,7 +133,7 @@ public static List getSortedProjects( List projects )
for ( Iterator j = project.getBuildExtensions().iterator(); j.hasNext(); )
{
Extension extension = (Extension) j.next();
String extensionId = getExtensionId( extension );
String extensionId = getId( extension.getGroupId(), extension.getArtifactId() );
if ( dag.getVertex( extensionId ) != null )
{
dag.addEdge( id, extensionId );
@ -150,23 +153,8 @@ public static List getSortedProjects( List projects )
return sortedProjects;
}
private static String getExtensionId( Extension extension )
private static String getId( String groupId, String artifactId )
{
return extension.getGroupId() + ":" + extension.getArtifactId();
}
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();
return groupId + ":" + artifactId;
}
}