svn commit: r831567 - in /maven/plugins/trunk/maven-ant-plugin: ./ src/it/system-scope-dep/ src/main/java/org/apache/maven/plugin/ant/

View: New views
1 Messages — Rating Filter:   Alert me  

svn commit: r831567 - in /maven/plugins/trunk/maven-ant-plugin: ./ src/it/system-scope-dep/ src/main/java/org/apache/maven/plugin/ant/

by bentmann :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Author: bentmann
Date: Sat Oct 31 17:14:41 2009
New Revision: 831567

URL: http://svn.apache.org/viewvc?rev=831567&view=rev
Log:
[MANT-61] Classpath generation should honour system-scope.

Removed:
    maven/plugins/trunk/maven-ant-plugin/src/it/system-scope-dep/test.properties
Modified:
    maven/plugins/trunk/maven-ant-plugin/pom.xml
    maven/plugins/trunk/maven-ant-plugin/src/it/system-scope-dep/pom.xml
    maven/plugins/trunk/maven-ant-plugin/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java
    maven/plugins/trunk/maven-ant-plugin/src/main/java/org/apache/maven/plugin/ant/AntMojo.java

Modified: maven/plugins/trunk/maven-ant-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/pom.xml?rev=831567&r1=831566&r2=831567&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ant-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-ant-plugin/pom.xml Sat Oct 31 17:14:41 2009
@@ -81,6 +81,11 @@
       <version>${mavenVersion}</version>
     </dependency>
     <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-core</artifactId>
+      <version>${mavenVersion}</version>
+    </dependency>
+    <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-utils</artifactId>
       <version>1.5.8</version>

Modified: maven/plugins/trunk/maven-ant-plugin/src/it/system-scope-dep/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/it/system-scope-dep/pom.xml?rev=831567&r1=831566&r2=831567&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ant-plugin/src/it/system-scope-dep/pom.xml (original)
+++ maven/plugins/trunk/maven-ant-plugin/src/it/system-scope-dep/pom.xml Sat Oct 31 17:14:41 2009
@@ -8,18 +8,9 @@
 
   <properties>
     <build.compiler>extJavac</build.compiler>
+    <lib.dir>${basedir}/lib</lib.dir>
   </properties>
 
-  <dependencies>
-    <dependency>
-      <groupId>org.apache.maven.its.ant</groupId>
-      <artifactId>dep</artifactId>
-      <version>0.1</version>
-      <scope>system</scope>
-      <systemPath>${lib.dir}/system-scope-dep-0.1.jar</systemPath>
-    </dependency>
-  </dependencies>
-
   <build>
     <plugins>
       <plugin>
@@ -41,4 +32,23 @@
     </plugins>
   </build>
 
+  <profiles>
+    <profile>
+      <id>test</id>
+      <activation>
+        <property>
+          <name>!skip-it</name>
+        </property>
+      </activation>
+      <dependencies>
+        <dependency>
+          <groupId>org.apache.maven.its.ant</groupId>
+          <artifactId>dep</artifactId>
+          <version>0.1</version>
+          <scope>system</scope>
+          <systemPath>${lib.dir}/system-scope-dep-0.1.jar</systemPath>
+        </dependency>
+      </dependencies>
+    </profile>
+  </profiles>
 </project>

Modified: maven/plugins/trunk/maven-ant-plugin/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java?rev=831567&r1=831566&r2=831567&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ant-plugin/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java (original)
+++ maven/plugins/trunk/maven-ant-plugin/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java Sat Oct 31 17:14:41 2009
@@ -30,9 +30,12 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.SortedMap;
+import java.util.TreeMap;
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Profile;
 import org.apache.maven.model.Repository;
 import org.apache.maven.model.Resource;
 import org.apache.maven.project.MavenProject;
@@ -89,6 +92,8 @@
 
     private boolean overwrite;
 
+    private Properties executionProperties;
+
     /**
      * @param project
      * @param artifactResolverWrapper
@@ -96,13 +101,14 @@
      * @param overwrite
      */
     public AntBuildWriter( MavenProject project, ArtifactResolverWrapper artifactResolverWrapper, Settings settings,
-                          boolean overwrite )
+                           boolean overwrite, Properties executionProperties )
     {
         this.project = project;
         this.artifactResolverWrapper = artifactResolverWrapper;
         this.localRepository = new File( artifactResolverWrapper.getLocalRepository().getBasedir() );
         this.settings = settings;
         this.overwrite = overwrite;
+        this.executionProperties = ( executionProperties != null ) ? executionProperties : new Properties();
     }
 
     /**
@@ -621,22 +627,55 @@
 
     private String getUninterpolatedSystemPath( Artifact artifact )
     {
+        String managementKey = artifact.getDependencyConflictId();
+
         for ( Iterator it = project.getOriginalModel().getDependencies().iterator(); it.hasNext(); )
         {
             Dependency dependency = (Dependency) it.next();
-            if ( artifact.getDependencyConflictId().equals( dependency.getManagementKey() ) )
+            if ( managementKey.equals( dependency.getManagementKey() ) )
             {
                 return dependency.getSystemPath();
             }
         }
 
+        for ( Iterator itp = project.getOriginalModel().getProfiles().iterator(); itp.hasNext(); )
+        {
+            Profile profile = (Profile) itp.next();
+            for ( Iterator it = profile.getDependencies().iterator(); it.hasNext(); )
+            {
+                Dependency dependency = (Dependency) it.next();
+                if ( managementKey.equals( dependency.getManagementKey() ) )
+                {
+                    return dependency.getSystemPath();
+                }
+            }
+        }
+
         String path = artifact.getFile().getAbsolutePath();
 
-        if ( path.startsWith( project.getBasedir().getAbsolutePath() + File.separator ) )
+        Properties props = new Properties();
+        props.putAll( project.getProperties() );
+        props.putAll( executionProperties );
+        props.remove( "user.dir" );
+        props.put( "basedir", project.getBasedir().getAbsolutePath() );
+
+        SortedMap candidateProperties = new TreeMap();
+        for ( Iterator it = props.keySet().iterator(); it.hasNext(); )
+        {
+            String key = (String) it.next();
+            String value = new File( props.getProperty( key ) ).getPath();
+            if ( path.startsWith( value ) && value.length() > 0 )
+            {
+                candidateProperties.put( value, key );
+            }
+        }
+        if ( !candidateProperties.isEmpty() )
         {
-            path = path.substring( project.getBasedir().getAbsolutePath().length() + 1 );
+            String value = candidateProperties.lastKey().toString();
+            String key = candidateProperties.get( value ).toString();
+            path = path.substring( value.length() );
             path = path.replace( '\\', '/' );
-            path = "${basedir}/" + path;
+            return "${" + key + "}" + path;
         }
 
         return path;

Modified: maven/plugins/trunk/maven-ant-plugin/src/main/java/org/apache/maven/plugin/ant/AntMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/main/java/org/apache/maven/plugin/ant/AntMojo.java?rev=831567&r1=831566&r2=831567&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ant-plugin/src/main/java/org/apache/maven/plugin/ant/AntMojo.java (original)
+++ maven/plugins/trunk/maven-ant-plugin/src/main/java/org/apache/maven/plugin/ant/AntMojo.java Sat Oct 31 17:14:41 2009
@@ -22,6 +22,7 @@
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
@@ -29,6 +30,7 @@
 
 import java.io.IOException;
 import java.util.List;
+import java.util.Properties;
 
 /**
  * Generate Ant build files.
@@ -106,6 +108,14 @@
      */
     private boolean overwrite;
 
+    /**
+     * The current Maven session.
+     *
+     * @parameter default-value="${session}"
+     * @readonly
+     */
+    private MavenSession session;
+
     /** {@inheritDoc} */
     public void execute()
         throws MojoExecutionException
@@ -114,7 +124,10 @@
                                                                                        localRepository,
                                                                                        remoteRepositories );
 
-        AntBuildWriter antBuildWriter = new AntBuildWriter( project, artifactResolverWrapper, settings, overwrite );
+        Properties executionProperties = ( session != null ) ? session.getExecutionProperties() : null;
+
+        AntBuildWriter antBuildWriter =
+            new AntBuildWriter( project, artifactResolverWrapper, settings, overwrite, executionProperties );
 
         try
         {