maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hbout...@apache.org
Subject [maven-ant-plugin] 25/50: MANT-10: error with build.classpath in build.xml
Date Wed, 20 Dec 2017 09:26:43 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 112f204766f20a2e13acf5c158da5b7a2fdb30ec
Author: Vincent Siveton <vsiveton@apache.org>
AuthorDate: Sat Sep 23 18:04:04 2006 +0000

    MANT-10: error with build.classpath in build.xml
    
    o added <include name="*/.jar"/> if no dependencies exist
    o added a test case
    
    
    git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-ant-plugin@449282
13f79535-47bb-0310-9956-ffa450edef68
---
 .../apache/maven/plugin/ant/AntBuildWriter.java    |  32 +++--
 .../org/apache/maven/plugin/ant/AntMojoTest.java   |  32 ++++-
 .../ant/stubs/AntNoDepTestMavenProjectStub.java    | 156 +++++++++++++++++++++
 .../ant-nodep-test-plugin-config.xml               |  43 ++++++
 .../org/apache/maven/plugins/ant/test/App.java     |  13 ++
 .../ant-nodep-test/src/main/resources/main.txt     |   1 +
 6 files changed, 264 insertions(+), 13 deletions(-)

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 a728481..4821756 100644
--- a/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java
+++ b/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java
@@ -379,12 +379,20 @@ public class AntBuildWriter
         writer.addAttribute( "id", "build.classpath" );
         writer.startElement( "fileset" );
         writer.addAttribute( "dir", "${maven.repo.local}" );
-
-        for ( Iterator i = project.getCompileArtifacts().iterator(); i.hasNext(); )
+        if ( !project.getCompileArtifacts().isEmpty() )
+        {
+            for ( Iterator i = project.getCompileArtifacts().iterator(); i.hasNext(); )
+            {
+                Artifact artifact = (Artifact) i.next();
+                writer.startElement( "include" );
+                writer.addAttribute( "name", PathUtils.toRelative( localRepository, artifact.getFile().getPath()
) );
+                writer.endElement(); // include
+            }
+        }
+        else
         {
-            Artifact artifact = (Artifact) i.next();
             writer.startElement( "include" );
-            writer.addAttribute( "name", PathUtils.toRelative( localRepository, artifact.getFile().getPath()
) );
+            writer.addAttribute( "name", "*.jar" );
             writer.endElement(); // include
         }
         writer.endElement(); // fileset
@@ -394,12 +402,20 @@ public class AntBuildWriter
         writer.addAttribute( "id", "build.test.classpath" );
         writer.startElement( "fileset" );
         writer.addAttribute( "dir", "${maven.repo.local}" );
-
-        for ( Iterator i = project.getTestArtifacts().iterator(); i.hasNext(); )
+        if ( !project.getTestArtifacts().isEmpty() )
+        {
+            for ( Iterator i = project.getTestArtifacts().iterator(); i.hasNext(); )
+            {
+                Artifact artifact = (Artifact) i.next();
+                writer.startElement( "include" );
+                writer.addAttribute( "name", PathUtils.toRelative( localRepository, artifact.getFile().getPath()
) );
+                writer.endElement(); // include
+            }
+        }
+        else
         {
-            Artifact artifact = (Artifact) i.next();
             writer.startElement( "include" );
-            writer.addAttribute( "name", PathUtils.toRelative( localRepository, artifact.getFile().getPath()
) );
+            writer.addAttribute( "name", "*.jar" );
             writer.endElement(); // include
         }
         writer.endElement(); // fileset
diff --git a/src/test/java/org/apache/maven/plugin/ant/AntMojoTest.java b/src/test/java/org/apache/maven/plugin/ant/AntMojoTest.java
index 0e7a05e..b4f0a1b 100644
--- a/src/test/java/org/apache/maven/plugin/ant/AntMojoTest.java
+++ b/src/test/java/org/apache/maven/plugin/ant/AntMojoTest.java
@@ -51,18 +51,40 @@ public class AntMojoTest
     }
 
     /**
-     * Method to test Ant generation
+     * Method to test Default Ant generation
      *
      * @throws Exception
      */
-    public void testWriter()
+    public void testDefaultProject()
         throws Exception
     {
-        File testPom = new File( getBasedir(), "src/test/resources/unit/ant-test/ant-test-plugin-config.xml"
);
+        invokeAntMojo( "ant-test" );
+    }
+
+    /**
+     * Method to test Project with no dependencies
+     *
+     * @throws Exception
+     */
+    public void testProjectWithNoDep()
+        throws Exception
+    {
+        invokeAntMojo( "ant-nodep-test" );
+    }
+
+    /**
+     * @param testPom
+     * @throws Exception
+     */
+    private void invokeAntMojo( String testProject )
+        throws Exception
+    {
+        File testPom = new File( getBasedir(),
+                                 "src/test/resources/unit/" + testProject + "/" + testProject
+ "-plugin-config.xml" );
         AntMojo mojo = (AntMojo) lookupMojo( "ant", testPom );
         mojo.execute();
 
-        File antBasedir = new File( getBasedir(), "target/test/unit/ant-test/" );
+        File antBasedir = new File( getBasedir(), "target/test/unit/" + testProject + "/"
);
         File antBuild = new File( antBasedir, AntBuildWriter.DEFAULT_BUILD_FILENAME );
         assertTrue( antBuild.exists() );
         File antProperties = new File( antBasedir, AntBuildWriter.DEFAULT_PROPERTIES_FILENAME
);
@@ -75,7 +97,7 @@ public class AntMojoTest
         assertTrue( new File( antBasedir, "target/ant-plugin-test.jar" ).exists() );
 
         Properties properties = new Properties();
-        properties.load( new FileInputStream( new File( getBasedir(), "target/test/unit/ant-test/build.properties"
) ) );
+        properties.load( new FileInputStream( new File( getBasedir(), "target/test/unit/"
+ testProject + "/build.properties" ) ) );
         String repo = properties.getProperty( "maven.repo.local" );
         assertTrue( repo.equals( new File( getBasedir(), "target/local-repo" ).getAbsolutePath()
) );
     }
diff --git a/src/test/java/org/apache/maven/plugin/ant/stubs/AntNoDepTestMavenProjectStub.java
b/src/test/java/org/apache/maven/plugin/ant/stubs/AntNoDepTestMavenProjectStub.java
new file mode 100644
index 0000000..89cf820
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugin/ant/stubs/AntNoDepTestMavenProjectStub.java
@@ -0,0 +1,156 @@
+package org.apache.maven.plugin.ant.stubs;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import java.io.File;
+import java.io.FileReader;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.handler.DefaultArtifactHandler;
+import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.model.Build;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Repository;
+import org.apache.maven.model.Resource;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+import org.codehaus.plexus.PlexusTestCase;
+
+/**
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ */
+public class AntNoDepTestMavenProjectStub
+    extends MavenProjectStub
+{
+    private Build build;
+
+    /**
+     * Default
+     */
+    public AntNoDepTestMavenProjectStub()
+    {
+        File antTestDir = new File( PlexusTestCase.getBasedir() + "/src/test/resources/unit/ant-nodep-test/"
);
+
+        MavenXpp3Reader pomReader = new MavenXpp3Reader();
+        Model model = null;
+
+        try
+        {
+            model = pomReader.read( new FileReader( new File( antTestDir, "ant-nodep-test-plugin-config.xml"
) ) );
+            setModel( model );
+        }
+        catch ( Exception e )
+        {
+            throw new RuntimeException( e );
+        }
+
+        setGroupId( model.getGroupId() );
+        setArtifactId( model.getArtifactId() );
+        setVersion( model.getVersion() );
+        setName( model.getName() );
+        setUrl( model.getUrl() );
+        setPackaging( model.getPackaging() );
+
+        build = new Build();
+        Resource resource = new Resource();
+
+        build.setFinalName( model.getArtifactId() );
+        build.setDirectory( getBasedir().getAbsolutePath() + "/target" );
+
+        build.setSourceDirectory( antTestDir + "/src/main/java" );
+        resource.setDirectory( antTestDir + "/src/main/resources" );
+        build.setResources( Collections.singletonList( resource ) );
+        build.setOutputDirectory( getBasedir().getAbsolutePath() + "/target/classes" );
+        build.setTestOutputDirectory( getBasedir().getAbsolutePath() + "/target/test-classes"
);
+
+        setBuild( build );
+    }
+
+    /**
+     * @see org.apache.maven.project.MavenProject#getBuild()
+     */
+    public Build getBuild()
+    {
+        return build;
+    }
+
+    /**
+     * @see org.apache.maven.project.MavenProject#getBasedir()
+     */
+    public File getBasedir()
+    {
+        File basedir = new File( PlexusTestCase.getBasedir(), "/target/test/unit/ant-nodep-test/"
);
+
+        if ( !basedir.exists() )
+        {
+            basedir.mkdirs();
+        }
+
+        return basedir;
+    }
+
+    /**
+     * @see org.apache.maven.project.MavenProject#getCompileSourceRoots()
+     */
+    public List getCompileSourceRoots()
+    {
+        File src = new File( PlexusTestCase.getBasedir() + "/src/test/resources/unit/ant-nodep-test/src/main/java"
);
+        return Collections.singletonList( src.getAbsolutePath() );
+    }
+
+    /**
+     * @see org.apache.maven.project.MavenProject#getTestCompileSourceRoots()
+     */
+    public List getTestCompileSourceRoots()
+    {
+        File test = new File( PlexusTestCase.getBasedir() + "/src/test/resources/unit/ant-nodep-test/src/test/java"
);
+        return Collections.singletonList( test.getAbsolutePath() );
+    }
+
+    /**
+     * @see org.apache.maven.project.MavenProject#getCompileArtifacts()
+     */
+    public List getCompileArtifacts()
+    {
+        return Collections.EMPTY_LIST;
+    }
+
+    /**
+     * @see org.apache.maven.project.MavenProject#getTestArtifacts()
+     */
+    public List getTestArtifacts()
+    {
+        return Collections.EMPTY_LIST;
+    }
+
+    /**
+     * @see org.apache.maven.project.MavenProject#getRepositories()
+     */
+    public List getRepositories()
+    {
+        Repository repo = new Repository();
+        repo.setId( "central" );
+        repo.setName( "central" );
+        repo.setUrl( "http://repo1.maven.org/maven2" );
+
+        return Collections.singletonList( repo );
+    }
+}
diff --git a/src/test/resources/unit/ant-nodep-test/ant-nodep-test-plugin-config.xml b/src/test/resources/unit/ant-nodep-test/ant-nodep-test-plugin-config.xml
new file mode 100644
index 0000000..4ef207b
--- /dev/null
+++ b/src/test/resources/unit/ant-nodep-test/ant-nodep-test-plugin-config.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  ~ Copyright 2006 The Apache Software Foundation.
+  ~
+  ~ Licensed 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.
+  -->
+
+<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>ant-plugin.test</groupId>
+  <artifactId>ant-plugin-test</artifactId>
+  <packaging>jar</packaging>
+  <version>1.0-SNAPSHOT</version>
+  <inceptionYear>2006</inceptionYear>
+  <name>Maven Ant Plugin Test</name>
+  <url>http://maven.apache.org</url>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-ant-plugin</artifactId>
+        <configuration>
+          <project implementation="org.apache.maven.plugin.ant.stubs.AntNoDepTestMavenProjectStub"/>
+          <settings implementation="org.apache.maven.plugin.ant.stubs.SettingsStub"/>
+          <localRepository>${localRepository}</localRepository>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/src/test/resources/unit/ant-nodep-test/src/main/java/org/apache/maven/plugins/ant/test/App.java
b/src/test/resources/unit/ant-nodep-test/src/main/java/org/apache/maven/plugins/ant/test/App.java
new file mode 100644
index 0000000..6dd2044
--- /dev/null
+++ b/src/test/resources/unit/ant-nodep-test/src/main/java/org/apache/maven/plugins/ant/test/App.java
@@ -0,0 +1,13 @@
+package org.apache.maven.plugins.ant.test;
+
+/**
+ * Hello world!
+ *
+ */
+public class App
+{
+    public static void main( String[] args )
+    {
+        System.out.println( "Hello World!" );
+    }
+}
diff --git a/src/test/resources/unit/ant-nodep-test/src/main/resources/main.txt b/src/test/resources/unit/ant-nodep-test/src/main/resources/main.txt
new file mode 100644
index 0000000..0aef8b1
--- /dev/null
+++ b/src/test/resources/unit/ant-nodep-test/src/main/resources/main.txt
@@ -0,0 +1 @@
+Test resource for main
\ No newline at end of file

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

Mime
View raw message