mirror of https://github.com/apache/maven.git
o Fixed MNG-772: applied Jesse McConnell's patch with minor style adjustments,
and did some more code cleanup. o Tracking with projects have been referenced in order to stop adding the same project twice if there's a dep on more than one artifact attachment from a project. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@239392 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0bb64a478b
commit
d6bd62e537
|
@ -33,7 +33,8 @@ import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -64,19 +65,15 @@ public class EclipseWriter
|
||||||
public void write( File outputDir, MavenProject project, MavenProject executedProject, List reactorProjects )
|
public void write( File outputDir, MavenProject project, MavenProject executedProject, List reactorProjects )
|
||||||
throws EclipsePluginException
|
throws EclipsePluginException
|
||||||
{
|
{
|
||||||
Map map = new HashMap();
|
|
||||||
|
|
||||||
assertNotEmpty( project.getGroupId(), "groupId" );
|
assertNotEmpty( project.getGroupId(), "groupId" );
|
||||||
|
|
||||||
assertNotEmpty( project.getArtifactId(), "artifactId" );
|
assertNotEmpty( project.getArtifactId(), "artifactId" );
|
||||||
|
|
||||||
map.put( "project.artifactId", project.getArtifactId() );
|
|
||||||
|
|
||||||
File projectBaseDir = project.getFile().getParentFile();
|
File projectBaseDir = project.getFile().getParentFile();
|
||||||
|
|
||||||
List referencedProjects = writeEclipseClasspath( projectBaseDir, outputDir, project, executedProject, map, reactorProjects );
|
Collection referencedProjects = writeEclipseClasspath( projectBaseDir, outputDir, project, executedProject, reactorProjects );
|
||||||
|
|
||||||
writeEclipseProject( projectBaseDir, outputDir, project, executedProject, referencedProjects, map );
|
writeEclipseProject( projectBaseDir, outputDir, project, executedProject, referencedProjects );
|
||||||
|
|
||||||
writeEclipseSettings( projectBaseDir, outputDir, project, executedProject );
|
writeEclipseSettings( projectBaseDir, outputDir, project, executedProject );
|
||||||
|
|
||||||
|
@ -104,31 +101,15 @@ public class EclipseWriter
|
||||||
{
|
{
|
||||||
Plugin plugin = (Plugin) it.next();
|
Plugin plugin = (Plugin) it.next();
|
||||||
|
|
||||||
if ( plugin.getArtifactId().equals("maven-compiler-plugin") )
|
if ( plugin.getArtifactId().equals( "maven-compiler-plugin" ) )
|
||||||
{
|
{
|
||||||
Xpp3Dom o = (Xpp3Dom) plugin.getConfiguration();
|
handleCompilerPlugin( plugin, coreSettings );
|
||||||
|
|
||||||
String source = o.getChild( "source" ).getValue();
|
|
||||||
|
|
||||||
String target = o.getChild( "target" ).getValue();
|
|
||||||
|
|
||||||
if ( !source.equals("1.3") )
|
|
||||||
{
|
|
||||||
coreSettings.put( "org.eclipse.jdt.core.compiler.source", source );
|
|
||||||
|
|
||||||
coreSettings.put( "org.eclipse.jdt.core.compiler.compliance", source );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !target.equals("1.2") )
|
|
||||||
{
|
|
||||||
coreSettings.put( "org.eclipse.jdt.core.compiler.codegen.targetPlatform", target );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// write the settings, if needed
|
// write the settings, if needed
|
||||||
|
|
||||||
if ( ! coreSettings.isEmpty() )
|
if ( !coreSettings.isEmpty() )
|
||||||
{
|
{
|
||||||
File settingsDir = new File( outputDir, "/.settings" );
|
File settingsDir = new File( outputDir, "/.settings" );
|
||||||
|
|
||||||
|
@ -163,7 +144,7 @@ public class EclipseWriter
|
||||||
// .project
|
// .project
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
protected void writeEclipseProject( File projectBaseDir, File basedir, MavenProject project, MavenProject executedProject, List referencedProjects, Map map )
|
protected void writeEclipseProject( File projectBaseDir, File basedir, MavenProject project, MavenProject executedProject, Collection referencedProjects )
|
||||||
throws EclipsePluginException
|
throws EclipsePluginException
|
||||||
{
|
{
|
||||||
FileWriter w;
|
FileWriter w;
|
||||||
|
@ -260,7 +241,7 @@ public class EclipseWriter
|
||||||
|
|
||||||
addResourceLinks( writer, projectBaseDir, basedir, executedProject.getBuild().getTestResources() );
|
addResourceLinks( writer, projectBaseDir, basedir, executedProject.getBuild().getTestResources() );
|
||||||
|
|
||||||
writer.endElement(); // linedResources
|
writer.endElement(); // linkedResources
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.endElement(); // projectDescription
|
writer.endElement(); // projectDescription
|
||||||
|
@ -272,7 +253,7 @@ public class EclipseWriter
|
||||||
// .classpath
|
// .classpath
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
protected List writeEclipseClasspath( File projectBaseDir, File basedir, MavenProject project, MavenProject executedProject, Map map, List reactorProjects )
|
protected Collection writeEclipseClasspath( File projectBaseDir, File basedir, MavenProject project, MavenProject executedProject, List reactorProjects )
|
||||||
throws EclipsePluginException
|
throws EclipsePluginException
|
||||||
{
|
{
|
||||||
FileWriter w;
|
FileWriter w;
|
||||||
|
@ -346,20 +327,15 @@ public class EclipseWriter
|
||||||
// The dependencies
|
// The dependencies
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
List referencedProjects = new ArrayList();
|
Collection referencedProjects = new HashSet();
|
||||||
|
|
||||||
Set artifacts = project.getArtifacts();
|
Set artifacts = project.getArtifacts();
|
||||||
|
|
||||||
for ( Iterator it = artifacts.iterator(); it.hasNext(); )
|
for ( Iterator it = artifacts.iterator(); it.hasNext(); )
|
||||||
{
|
{
|
||||||
Artifact artifact = (Artifact) it.next();
|
Artifact artifact = (Artifact) it.next();
|
||||||
|
|
||||||
MavenProject refProject = addDependency( writer, artifact, reactorProjects );
|
addDependency( writer, artifact, reactorProjects, referencedProjects );
|
||||||
|
|
||||||
if ( refProject != null )
|
|
||||||
{
|
|
||||||
referencedProjects.add( refProject );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.endElement();
|
writer.endElement();
|
||||||
|
@ -560,17 +536,24 @@ public class EclipseWriter
|
||||||
* @param reactorProjects
|
* @param reactorProjects
|
||||||
* @return null or the reactorProject providing this dependency
|
* @return null or the reactorProject providing this dependency
|
||||||
*/
|
*/
|
||||||
private MavenProject addDependency( XMLWriter writer, Artifact artifact, List reactorProjects )
|
private void addDependency( XMLWriter writer, Artifact artifact, List reactorProjects, Collection referencedProjects )
|
||||||
{
|
{
|
||||||
MavenProject reactorProject = findReactorProject( reactorProjects, artifact );
|
MavenProject reactorProject = findReactorProject( reactorProjects, artifact );
|
||||||
|
|
||||||
String path = null;
|
String path = null;
|
||||||
|
|
||||||
String kind = null;
|
String kind = null;
|
||||||
|
|
||||||
|
|
||||||
if (reactorProject != null)
|
if ( reactorProject != null )
|
||||||
{
|
{
|
||||||
|
// if there's a dependency on multiple artifact attachments of the
|
||||||
|
// same project, don't add it again.
|
||||||
|
|
||||||
|
if ( !markAddedOnce( reactorProject, referencedProjects ) )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
path = "/" + reactorProject.getArtifactId();
|
path = "/" + reactorProject.getArtifactId();
|
||||||
|
|
||||||
kind = "src";
|
kind = "src";
|
||||||
|
@ -583,7 +566,7 @@ public class EclipseWriter
|
||||||
{
|
{
|
||||||
log.error( "The artifacts path was null. Artifact id: " + artifact.getId() );
|
log.error( "The artifacts path was null. Artifact id: " + artifact.getId() );
|
||||||
|
|
||||||
return null;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
path = "M2_REPO/" + toRelative( localRepository, artifactPath.getPath() );
|
path = "M2_REPO/" + toRelative( localRepository, artifactPath.getPath() );
|
||||||
|
@ -598,10 +581,22 @@ public class EclipseWriter
|
||||||
writer.addAttribute( "path", path );
|
writer.addAttribute( "path", path );
|
||||||
|
|
||||||
writer.endElement();
|
writer.endElement();
|
||||||
|
|
||||||
return reactorProject;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean markAddedOnce( MavenProject project, Collection referencedProjects )
|
||||||
|
{
|
||||||
|
if ( referencedProjects.contains( project ) )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
referencedProjects.add( project );
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility method that locates a project producing the given artifact.
|
* Utility method that locates a project producing the given artifact.
|
||||||
*
|
*
|
||||||
|
@ -632,7 +627,7 @@ public class EclipseWriter
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void close( Writer closeable )
|
private static void close( Writer closeable )
|
||||||
{
|
{
|
||||||
if ( closeable == null )
|
if ( closeable == null )
|
||||||
{
|
{
|
||||||
|
@ -649,7 +644,7 @@ public class EclipseWriter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String toRelative( File basedir, String absolutePath )
|
private static String toRelative( File basedir, String absolutePath )
|
||||||
{
|
{
|
||||||
String relative;
|
String relative;
|
||||||
|
|
||||||
|
@ -667,7 +662,7 @@ public class EclipseWriter
|
||||||
return relative;
|
return relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertNotEmpty( String string, String elementName )
|
private static void assertNotEmpty( String string, String elementName )
|
||||||
throws EclipsePluginException
|
throws EclipsePluginException
|
||||||
{
|
{
|
||||||
if ( string == null )
|
if ( string == null )
|
||||||
|
@ -675,4 +670,39 @@ public class EclipseWriter
|
||||||
throw new EclipsePluginException( "Missing element from the project descriptor: '" + elementName + "'." );
|
throw new EclipsePluginException( "Missing element from the project descriptor: '" + elementName + "'." );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void handleCompilerPlugin( Plugin plugin, Properties coreSettings )
|
||||||
|
{
|
||||||
|
Xpp3Dom pluginConfig = (Xpp3Dom) plugin.getConfiguration();
|
||||||
|
|
||||||
|
String source = null;
|
||||||
|
|
||||||
|
Xpp3Dom sourceChild = pluginConfig.getChild( "source" );
|
||||||
|
|
||||||
|
if (sourceChild != null)
|
||||||
|
{
|
||||||
|
source = sourceChild.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
String target = null;
|
||||||
|
|
||||||
|
Xpp3Dom targetChild = pluginConfig.getChild( "target" );
|
||||||
|
|
||||||
|
if (targetChild != null)
|
||||||
|
{
|
||||||
|
target = targetChild.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( source != null && !source.equals( "1.3" ) )
|
||||||
|
{
|
||||||
|
coreSettings.put( "org.eclipse.jdt.core.compiler.source", source );
|
||||||
|
|
||||||
|
coreSettings.put( "org.eclipse.jdt.core.compiler.compliance", source );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( target != null && !target.equals( "1.2" ) )
|
||||||
|
{
|
||||||
|
coreSettings.put( "org.eclipse.jdt.core.compiler.codegen.targetPlatform", target );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue