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:27:35 UTC

[maven-ant-plugin] 26/48: [MANT-4] Generated ANT contains hardcoded "get" tasks that look at the "C:\" drive etc... when using a local repository

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

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

commit d60798d504818181d13b948d4450bf3f6a65a652
Author: Benjamin Bentmann <be...@apache.org>
AuthorDate: Sat Mar 22 01:19:37 2008 +0000

    [MANT-4] Generated ANT contains hardcoded "get" tasks that look at the "C:\" drive etc... when using a local repository
    
    git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-ant-plugin@639932 13f79535-47bb-0310-9956-ffa450edef68
---
 src/it/file-repo-it/goals.txt                      |  2 +
 src/it/file-repo-it/pom.xml                        | 62 ++++++++++++++++++++++
 src/it/file-repo-it/verify.bsh                     | 38 +++++++++++++
 .../apache/maven/plugin/ant/AntBuildWriter.java    | 38 ++++++++++---
 4 files changed, 133 insertions(+), 7 deletions(-)

diff --git a/src/it/file-repo-it/goals.txt b/src/it/file-repo-it/goals.txt
new file mode 100644
index 0000000..16cd63b
--- /dev/null
+++ b/src/it/file-repo-it/goals.txt
@@ -0,0 +1,2 @@
+ant:ant
+initialize
diff --git a/src/it/file-repo-it/pom.xml b/src/it/file-repo-it/pom.xml
new file mode 100644
index 0000000..fe639c9
--- /dev/null
+++ b/src/it/file-repo-it/pom.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.maven-ant-plugin.it</groupId>
+  <artifactId>file-repo-it</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-ant-plugin</artifactId>
+        <version>@pom.version@</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-antrun-plugin</artifactId>
+        <version>1.1</version>
+        <executions>
+          <execution>
+            <phase>initialize</phase>
+            <configuration>
+              <tasks>
+                <ant dir="${basedir}" antfile="${basedir}/build.xml" target="help" />
+              </tasks>
+            </configuration>
+            <goals>
+              <goal>run</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.2</version>
+    </dependency>
+  </dependencies>
+
+  <repositories>
+    <repository>
+      <id>repo0</id>
+      <url>file://localhost/${basedir}</url>
+    </repository>
+    <repository>
+      <id>repo1</id>
+      <url>file://${basedir}/repo1</url>
+    </repository>
+    <repository>
+      <id>repo2</id>
+      <url>file://${basedir}/repo2/</url>
+    </repository>
+  </repositories>
+
+</project>
diff --git a/src/it/file-repo-it/verify.bsh b/src/it/file-repo-it/verify.bsh
new file mode 100644
index 0000000..803ca53
--- /dev/null
+++ b/src/it/file-repo-it/verify.bsh
@@ -0,0 +1,38 @@
+import java.io.*;
+import java.util.*;
+import java.util.regex.*;
+import org.codehaus.plexus.util.*;
+
+try
+{
+    File buildFile = new File( basedir, "maven-build.xml" );
+    String xml = FileUtils.fileRead( buildFile, "UTF-8" );
+
+    Matcher m0 = Pattern.compile( "<copy\\s+file\\s*=\\s*\\Q\"junit/junit/3.8.2/junit-3.8.2.jar\"\\E" ).matcher( xml );
+    if ( !m0.find() )
+    {
+        System.err.println( "Build script does not contain <copy> for local artifacts from repo0." );
+        return false;
+    }
+
+    Matcher m1 = Pattern.compile( "<copy\\s+file\\s*=\\s*\\Q\"repo1/junit/junit/3.8.2/junit-3.8.2.jar\"\\E" ).matcher( xml );
+    if ( !m1.find() )
+    {
+        System.err.println( "Build script does not contain <copy> for local artifacts from repo1." );
+        return false;
+    }
+
+    Matcher m2 = Pattern.compile( "<copy\\s+file\\s*=\\s*\\Q\"repo2/junit/junit/3.8.2/junit-3.8.2.jar\"\\E" ).matcher( xml );
+    if ( !m2.find() )
+    {
+        System.err.println( "Build script does not contain <copy> for local artifacts from repo2." );
+        return false;
+    }
+}
+catch( Throwable t )
+{
+    t.printStackTrace();
+    return false;
+}
+
+return true;
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 a81e456..6d1164b 100644
--- a/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java
+++ b/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java
@@ -1144,6 +1144,8 @@ public class AntBuildWriter
         writer.addAttribute( "dir", "${maven.repo.local}" );
         writer.endElement(); // mkdir
 
+        String basedir = project.getBasedir().getAbsolutePath();
+
         // TODO: proxy - probably better to use wagon!
         for ( Iterator i = project.getTestArtifacts().iterator(); i.hasNext(); )
         {
@@ -1166,13 +1168,35 @@ public class AntBuildWriter
                 for ( Iterator j = project.getRepositories().iterator(); j.hasNext(); )
                 {
                     Repository repository = (Repository) j.next();
-
-                    writer.startElement( "get" );
-                    writer.addAttribute( "src", repository.getUrl() + "/" + path );
-                    AntBuildWriterUtil.addWrapAttribute( writer, "get", "dest", "${maven.repo.local}/" + path, 3 );
-                    AntBuildWriterUtil.addWrapAttribute( writer, "get", "usetimestamp", "false", 3 );
-                    AntBuildWriterUtil.addWrapAttribute( writer, "get", "ignoreerrors", "true", 3 );
-                    writer.endElement(); // get
+                    String url = repository.getUrl();
+
+                    if ( url.regionMatches( true, 0, "file:", 0, 5 ) && url.indexOf( basedir ) > 0 )
+                    {
+                        url = url.substring( url.indexOf( basedir ) + basedir.length() );
+                        if ( url.startsWith( "/" ) )
+                        {
+                            url = url.substring( 1 );
+                        }
+                        if ( !url.endsWith( "/" ) && url.length() > 0 )
+                        {
+                            url += '/';
+                        }
+
+                        writer.startElement( "copy" );
+                        writer.addAttribute( "file", url + path );
+                        AntBuildWriterUtil.addWrapAttribute( writer, "copy", "tofile", "${maven.repo.local}/" + path, 3 );
+                        AntBuildWriterUtil.addWrapAttribute( writer, "copy", "failonerror", "false", 3 );
+                        writer.endElement(); // copy
+                    }
+                    else
+                    {
+                        writer.startElement( "get" );
+                        writer.addAttribute( "src", url + '/' + path );
+                        AntBuildWriterUtil.addWrapAttribute( writer, "get", "dest", "${maven.repo.local}/" + path, 3 );
+                        AntBuildWriterUtil.addWrapAttribute( writer, "get", "usetimestamp", "false", 3 );
+                        AntBuildWriterUtil.addWrapAttribute( writer, "get", "ignoreerrors", "true", 3 );
+                        writer.endElement(); // get
+                    }
                 }
             }
         }

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