tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r714135 - /tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/EclipsePluginMojo.java
Date Fri, 14 Nov 2008 20:58:05 GMT
Author: rfeng
Date: Fri Nov 14 12:58:05 2008
New Revision: 714135

URL: http://svn.apache.org/viewvc?rev=714135&view=rev
Log:
Add explicit classpath entries for test/runtime scoped dependencies

Modified:
    tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/EclipsePluginMojo.java

Modified: tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/EclipsePluginMojo.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/EclipsePluginMojo.java?rev=714135&r1=714134&r2=714135&view=diff
==============================================================================
--- tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/EclipsePluginMojo.java
(original)
+++ tuscany/branches/sca-equinox/tools/maven/maven-bundle-plugin/src/main/java/org/apache/tuscany/sca/tools/bundle/plugin/EclipsePluginMojo.java
Fri Nov 14 12:58:05 2008
@@ -29,6 +29,8 @@
 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 @@
     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 @@
      * @readonly
      */
     private MavenProject project;
-    
+
     /**
      * Skip the operation when true.
      * 
@@ -297,7 +358,6 @@
      */
     private boolean skip;
 
-
     private EclipseSourceDir[] buildDirectoryList() throws MojoExecutionException {
         File buildOutputDirectory = new File(project.getBuild().getOutputDirectory());
         File basedir = project.getBasedir();
@@ -469,7 +529,7 @@
         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 @@
 
             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 @@
 
             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();
     }



Mime
View raw message