PR: MNG-549

Submitted by: Kenney Westerhof
make eclipse plugin reactor aware


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@225723 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-07-28 07:33:56 +00:00
parent bf7390cde7
commit f9eaca7ab0
2 changed files with 53 additions and 12 deletions

View File

@ -22,6 +22,7 @@ import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import java.io.File;
import java.util.List;
/**
* A Maven2 plugin which integrates the use of Maven2 with Eclipse.
@ -58,6 +59,13 @@ public class EclipsePlugin
*/
private ArtifactRepository localRepository;
/**
* @parameter expression="${reactorProjects}"
* @required
* @readonly
*/
private List reactorProjects;
public EclipsePlugin()
{
eclipseWriter = new EclipseWriter();
@ -97,7 +105,7 @@ public class EclipsePlugin
executedProject = project;
}
eclipseWriter.write( project, executedProject );
eclipseWriter.write( project, executedProject, reactorProjects );
}
catch ( EclipsePluginException e )
{

View File

@ -46,7 +46,7 @@ public class EclipseWriter
this.localRepository = localRepository;
}
public void write( MavenProject project, MavenProject executedProject )
public void write( MavenProject project, MavenProject executedProject, List reactorProjects )
throws EclipsePluginException
{
File basedir = project.getFile().getParentFile();
@ -61,7 +61,7 @@ public class EclipseWriter
writeEclipseProject( basedir, project, map );
writeEclipseClasspath( basedir, project, executedProject, map );
writeEclipseClasspath( basedir, project, executedProject, map, reactorProjects );
System.out.println( "Wrote Eclipse project for " + project.getArtifactId() + " to " + basedir.getAbsolutePath() );
}
@ -155,7 +155,7 @@ public class EclipseWriter
// .classpath
// ----------------------------------------------------------------------
protected void writeEclipseClasspath( File basedir, MavenProject project, MavenProject executedProject, Map map )
protected void writeEclipseClasspath( File basedir, MavenProject project, MavenProject executedProject, Map map, List reactorProjects )
throws EclipsePluginException
{
FileWriter w;
@ -235,7 +235,7 @@ public class EclipseWriter
{
Artifact artifact = (Artifact) it.next();
addDependency( writer, artifact );
addDependency( writer, artifact, reactorProjects );
}
writer.endElement();
@ -316,25 +316,58 @@ public class EclipseWriter
}
}
private void addDependency( XMLWriter writer, Artifact artifact )
private void addDependency( XMLWriter writer, Artifact artifact, List reactorProjects )
{
File path = artifact.getFile();
String path = getProjectPath( reactorProjects, artifact );
String kind = path == null ? "var" : "src";
// fall-through when no local project could be found in the reactor
if ( path == null )
{
System.err.println( "The artifacts path was null. Artifact id: " + artifact.getId() );
File artifactPath = artifact.getFile();
return;
if ( artifactPath == null )
{
System.err.println( "The artifacts path was null. Artifact id: " + artifact.getId() );
return;
}
path = "M2_REPO/" + toRelative( localRepository, artifactPath.getPath() );
}
writer.startElement( "classpathentry" );
writer.addAttribute( "kind", "var" );
writer.addAttribute( "kind", kind );
writer.addAttribute( "path", "M2_REPO/" + toRelative( localRepository, path.getPath() ) );
writer.addAttribute( "path", path );
writer.endElement();
}
private String getProjectPath( List reactorProjects, Artifact artifact )
{
if ( reactorProjects == null )
{
return null; // we're a single project
}
for (Iterator it = reactorProjects.iterator(); it.hasNext(); )
{
MavenProject project = (MavenProject) it.next();
if ( project.getGroupId().equals( artifact.getGroupId() )
&& project.getArtifactId().equals( artifact.getArtifactId() )
&& project.getVersion().equals( artifact.getVersion() )
)
{
return "/" + project.getArtifactId();
}
}
return null;
}
private void close( Writer closeable )
{