summaryrefslogtreecommitdiffstats
path: root/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/EclipsePluginMojo.java
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2008-11-14 20:58:05 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2008-11-14 20:58:05 +0000
commit43fa7eb6d1d07b00bc1f57e9c269ae1da1f2675f (patch)
tree2d1ce23953735df15ad640ef7a91f6a27013ade4 /branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/EclipsePluginMojo.java
parent40991a80046e6f83f015083704c441f4387c6dc6 (diff)
Add explicit classpath entries for test/runtime scoped dependencies
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@714135 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/EclipsePluginMojo.java102
1 files changed, 97 insertions, 5 deletions
diff --git a/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/EclipsePluginMojo.java b/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/EclipsePluginMojo.java
index 5ed0ed3a48..c40020aee8 100644
--- a/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/EclipsePluginMojo.java
+++ b/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/EclipsePluginMojo.java
@@ -29,6 +29,8 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -236,11 +238,70 @@ public class EclipsePluginMojo extends AbstractMojo {
private static final String ATTR_SRC = "src";
/**
+ * Attribute value for kind: var
+ */
+ private static final String ATTR_VAR = "var";
+
+ /**
+ * Attribute value for kind: lib
+ */
+ private static final String ATTR_LIB = "lib";
+
+ /**
+ * Eclipse build path variable M2_REPO
+ */
+ private static final String M2_REPO = "M2_REPO";
+
+ /**
* Element for classpathentry.
*/
private static final String ELT_CLASSPATHENTRY = "classpathentry";
private static final String ELT_CLASSPATH = "classpath";
+ /**
+ * @parameter expression="${localRepository}"
+ * @required
+ * @readonly
+ */
+ private ArtifactRepository localRepository;
+
+ /**
+ * If the executed project is a reactor project, this will contains the full list of projects in the reactor.
+ *
+ * @parameter expression="${reactorProjects}"
+ * @required
+ * @readonly
+ */
+ protected List reactorProjects;
+
+ /**
+ * Utility method that locates a project producing the given artifact.
+ *
+ * @param artifact the artifact a project should produce.
+ * @return <code>true</code> if the artifact is produced by a reactor project.
+ */
+ private boolean isAvailableAsAReactorProject(Artifact artifact) {
+ if (reactorProjects != null) {
+ for (Iterator iter = reactorProjects.iterator(); iter.hasNext();) {
+ MavenProject reactorProject = (MavenProject)iter.next();
+
+ if (reactorProject.getGroupId().equals(artifact.getGroupId()) && reactorProject.getArtifactId()
+ .equals(artifact.getArtifactId())) {
+ if (reactorProject.getVersion().equals(artifact.getVersion())) {
+ return true;
+ } else {
+ getLog().info("Artifact " + artifact.getId()
+ + " already available as a reactor project, but with different version. Expected: "
+ + artifact.getVersion()
+ + ", found: "
+ + reactorProject.getVersion());
+ }
+ }
+ }
+ }
+ return false;
+ }
+
private static String getCanonicalPath(File file) throws MojoExecutionException {
try {
return file.getCanonicalPath();
@@ -289,7 +350,7 @@ public class EclipsePluginMojo extends AbstractMojo {
* @readonly
*/
private MavenProject project;
-
+
/**
* Skip the operation when true.
*
@@ -297,7 +358,6 @@ public class EclipsePluginMojo extends AbstractMojo {
*/
private boolean skip;
-
private EclipseSourceDir[] buildDirectoryList() throws MojoExecutionException {
File buildOutputDirectory = new File(project.getBuild().getOutputDirectory());
File basedir = project.getBasedir();
@@ -469,7 +529,7 @@ public class EclipsePluginMojo extends AbstractMojo {
List<EclipseSourceDir> specialSources = new ArrayList<EclipseSourceDir>();
// Map<String,List<EclipseSourceDir>>
- Map<String,List<EclipseSourceDir>> byOutputDir = new HashMap<String,List<EclipseSourceDir>>();
+ Map<String, List<EclipseSourceDir>> byOutputDir = new HashMap<String, List<EclipseSourceDir>>();
for (int j = 0; j < dirs.length; j++) {
EclipseSourceDir dir = dirs[j];
@@ -526,7 +586,7 @@ public class EclipsePluginMojo extends AbstractMojo {
writer.print(" <" + ELT_CLASSPATHENTRY);
- writer.print(" " + ATTR_KIND + "=\"src\"");
+ writer.print(" " + ATTR_KIND + "=\"" + ATTR_SRC + "\"");
writer.print(" " + ATTR_PATH + "=\"" + dir.getPath() + "\"");
if (!isSpecial && dir.getOutput() != null && !defaultOutput.equals(dir.getOutput())) {
@@ -551,7 +611,39 @@ public class EclipsePluginMojo extends AbstractMojo {
writer.println("/>");
}
- writer.println(" <classpathentry kind=\"output\" path=\"" + defaultOutput + "\"/>");
+
+ for (Object a : project.getArtifacts()) {
+ Artifact artifact = (Artifact)a;
+ if (Artifact.SCOPE_TEST.equals(artifact.getScope()) || Artifact.SCOPE_RUNTIME.equals(artifact.getScope())) {
+ if (getLog().isDebugEnabled()) {
+ getLog().debug("Adding explict classpath entry: " + artifact.toString());
+ }
+
+ String path = "", kind = "";
+ if (isAvailableAsAReactorProject(artifact)) {
+ path = "/" + artifact.getArtifactId();
+ kind = ATTR_SRC;
+ } else {
+ String fullPath = artifact.getFile().getPath();
+ String relativePath =
+ toRelativeAndFixSeparator(new File(localRepository.getBasedir()), new File(fullPath), false);
+
+ if (!new File(relativePath).isAbsolute()) {
+ path = M2_REPO + "/" + relativePath;
+ kind = ATTR_VAR;
+ } else {
+ path = relativePath;
+ kind = ATTR_LIB;
+ }
+ }
+ writer.print(" <" + ELT_CLASSPATHENTRY);
+
+ writer.print(" " + ATTR_KIND + "=\"" + kind + "\"");
+ writer.print(" " + ATTR_PATH + "=\"" + path + "\"");
+ writer.println("/>");
+ }
+ }
+ writer.println(" <classpathentry kind=\"" + ATTR_OUTPUT + "\" path=\"" + defaultOutput + "\"/>");
writer.println("</" + ELT_CLASSPATH + ">");
writer.close();
}