You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2017/12/20 09:29:09 UTC

[maven-ant-plugin] 09/14: [MANT-61] Classpath generation should honour system-scope

This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a commit to annotated tag maven-ant-plugin-2.3
in repository https://gitbox.apache.org/repos/asf/maven-ant-plugin.git

commit 8fc5ec8a777bc8ff5f0c22b67eca9962b6c6c87d
Author: Benjamin Bentmann <be...@apache.org>
AuthorDate: Sun Oct 25 22:38:35 2009 +0000

    [MANT-61] Classpath generation should honour system-scope
    
    git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-ant-plugin@829673 13f79535-47bb-0310-9956-ffa450edef68
---
 .../system-scope-dep/lib/system-scope-dep-0.1.jar  | Bin 0 -> 4294 bytes
 src/it/system-scope-dep/pom.xml                    |  44 +++++++++++
 .../src/main/java/DefaultComponent.java            |  24 ++++++
 src/it/system-scope-dep/test.properties            |   1 +
 .../apache/maven/plugin/ant/AntBuildWriter.java    |  84 ++++++++++++---------
 5 files changed, 117 insertions(+), 36 deletions(-)

diff --git a/src/it/system-scope-dep/lib/system-scope-dep-0.1.jar b/src/it/system-scope-dep/lib/system-scope-dep-0.1.jar
new file mode 100644
index 0000000..4aa61e0
Binary files /dev/null and b/src/it/system-scope-dep/lib/system-scope-dep-0.1.jar differ
diff --git a/src/it/system-scope-dep/pom.xml b/src/it/system-scope-dep/pom.xml
new file mode 100644
index 0000000..56d2eb8
--- /dev/null
+++ b/src/it/system-scope-dep/pom.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.ant</groupId>
+  <artifactId>system-scope-dep</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <properties>
+    <build.compiler>extJavac</build.compiler>
+  </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>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-ant-plugin</artifactId>
+        <version>@project.version@</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-antrun-plugin</artifactId>
+        <version>1.1</version>
+        <configuration>
+          <tasks>
+            <property name="lib.dir" location="${lib.dir}" />
+            <ant dir="${basedir}" antfile="${basedir}/build.xml" target="compile" />
+          </tasks>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/src/it/system-scope-dep/src/main/java/DefaultComponent.java b/src/it/system-scope-dep/src/main/java/DefaultComponent.java
new file mode 100644
index 0000000..84ac87e
--- /dev/null
+++ b/src/it/system-scope-dep/src/main/java/DefaultComponent.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// requires the system-scope dependency for compilation
+public class DefaultComponent
+    implements Component
+{
+}
diff --git a/src/it/system-scope-dep/test.properties b/src/it/system-scope-dep/test.properties
new file mode 100644
index 0000000..cf15e82
--- /dev/null
+++ b/src/it/system-scope-dep/test.properties
@@ -0,0 +1 @@
+lib.dir = ${basedir}/lib
diff --git a/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java b/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java
index 9bf35da..97b5d92 100644
--- a/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java
+++ b/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java
@@ -32,6 +32,7 @@ import java.util.Map;
 import java.util.Properties;
 
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.model.Dependency;
 import org.apache.maven.model.Repository;
 import org.apache.maven.model.Resource;
 import org.apache.maven.project.MavenProject;
@@ -583,55 +584,62 @@ public class AntBuildWriter
 
         XmlWriterUtil.writeCommentText( writer, "Defining classpaths", 1 );
 
+        writeBuildPathDefinition( writer, "build.classpath", project.getCompileArtifacts() );
+
+        writeBuildPathDefinition( writer, "build.test.classpath", project.getTestArtifacts() );
+
+        XmlWriterUtil.writeLineBreak( writer );
+    }
+
+    private void writeBuildPathDefinition( XMLWriter writer, String id, List artifacts )
+    {
         writer.startElement( "path" );
-        writer.addAttribute( "id", "build.classpath" );
-        writer.startElement( "fileset" );
-        writer.addAttribute( "dir", "${maven.repo.local}" );
-        if ( !project.getCompileArtifacts().isEmpty() )
+        writer.addAttribute( "id", id );
+
+        for ( Iterator i = artifacts.iterator(); i.hasNext(); )
         {
-            for ( Iterator i = project.getCompileArtifacts().iterator(); i.hasNext(); )
+            Artifact artifact = (Artifact) i.next();
+
+            writer.startElement( "pathelement" );
+
+            String path;
+            if ( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) )
             {
-                Artifact artifact = (Artifact) i.next();
-                String path = artifactResolverWrapper.getLocalArtifactPath( artifact );
-                writer.startElement( "include" );
-                writer.addAttribute( "name", path );
-                writer.endElement(); // include
+                path = getUninterpolatedSystemPath( artifact );
             }
+            else
+            {
+                path = "${maven.repo.local}/" + artifactResolverWrapper.getLocalArtifactPath( artifact );
+            }
+            writer.addAttribute( "location", path );
+
+            writer.endElement(); // pathelement
         }
-        else
-        {
-            writer.startElement( "include" );
-            writer.addAttribute( "name", "*.jar" );
-            writer.endElement(); // include
-        }
-        writer.endElement(); // fileset
+
         writer.endElement(); // path
+    }
 
-        writer.startElement( "path" );
-        writer.addAttribute( "id", "build.test.classpath" );
-        writer.startElement( "fileset" );
-        writer.addAttribute( "dir", "${maven.repo.local}" );
-        if ( !project.getTestArtifacts().isEmpty() )
+    private String getUninterpolatedSystemPath( Artifact artifact )
+    {
+        for ( Iterator it = project.getOriginalModel().getDependencies().iterator(); it.hasNext(); )
         {
-            for ( Iterator i = project.getTestArtifacts().iterator(); i.hasNext(); )
+            Dependency dependency = (Dependency) it.next();
+            if ( artifact.getDependencyConflictId().equals( dependency.getManagementKey() ) )
             {
-                Artifact artifact = (Artifact) i.next();
-                String path = artifactResolverWrapper.getLocalArtifactPath( artifact );
-                writer.startElement( "include" );
-                writer.addAttribute( "name", path );
-                writer.endElement(); // include
+                return dependency.getSystemPath();
             }
         }
-        else
+
+        String path = artifact.getFile().getAbsolutePath();
+
+        if ( path.startsWith( project.getBasedir().getAbsolutePath() + File.separator ) )
         {
-            writer.startElement( "include" );
-            writer.addAttribute( "name", "*.jar" );
-            writer.endElement(); // include
+            path = path.substring( project.getBasedir().getAbsolutePath().length() + 1 );
+            path = path.replace( '\\', '/' );
+            path = "${basedir}/" + path;
         }
-        writer.endElement(); // fileset
-        writer.endElement(); // path
 
-        XmlWriterUtil.writeLineBreak( writer );
+        return path;
     }
 
     /**
@@ -1262,7 +1270,11 @@ public class AntBuildWriter
         {
             Artifact artifact = (Artifact) i.next();
 
-            // TODO: should the artifacthandler be used instead?
+            if ( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) )
+            {
+                continue;
+            }
+
             String path = artifactResolverWrapper.getLocalArtifactPath( artifact );
 
             if ( !new File( path ).exists() )

-- 
To stop receiving notification emails like this one, please contact
"commits@maven.apache.org" <co...@maven.apache.org>.