You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by vs...@apache.org on 2006/09/23 20:04:05 UTC

svn commit: r449282 - in /maven/plugins/trunk/maven-ant-plugin/src: main/java/org/apache/maven/plugin/ant/ test/java/org/apache/maven/plugin/ant/ test/java/org/apache/maven/plugin/ant/stubs/ test/resources/unit/ant-nodep-test/ test/resources/unit/ant-n...

Author: vsiveton
Date: Sat Sep 23 11:04:04 2006
New Revision: 449282

URL: http://svn.apache.org/viewvc?view=rev&rev=449282
Log:
MANT-10: error with build.classpath in build.xml

o added <include name="*/.jar"/> if no dependencies exist
o added a test case

Added:
    maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/stubs/AntNoDepTestMavenProjectStub.java   (with props)
    maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/
    maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/ant-nodep-test-plugin-config.xml   (with props)
    maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/src/
    maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/src/main/
    maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/src/main/java/
    maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/src/main/java/org/
    maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/src/main/java/org/apache/
    maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/src/main/java/org/apache/maven/
    maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/src/main/java/org/apache/maven/plugins/
    maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/src/main/java/org/apache/maven/plugins/ant/
    maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/src/main/java/org/apache/maven/plugins/ant/test/
    maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/src/main/java/org/apache/maven/plugins/ant/test/App.java   (with props)
    maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/src/main/resources/
    maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/src/main/resources/main.txt   (with props)
Modified:
    maven/plugins/trunk/maven-ant-plugin/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java
    maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/AntMojoTest.java

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?view=diff&rev=449282&r1=449281&r2=449282
==============================================================================
--- 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 Sep 23 11:04:04 2006
@@ -379,12 +379,20 @@
         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 @@
         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

Modified: maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/AntMojoTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/AntMojoTest.java?view=diff&rev=449282&r1=449281&r2=449282
==============================================================================
--- maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/AntMojoTest.java (original)
+++ maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/AntMojoTest.java Sat Sep 23 11:04:04 2006
@@ -51,18 +51,40 @@
     }
 
     /**
-     * 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 @@
         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() ) );
     }

Added: maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/stubs/AntNoDepTestMavenProjectStub.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/stubs/AntNoDepTestMavenProjectStub.java?view=auto&rev=449282
==============================================================================
--- maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/stubs/AntNoDepTestMavenProjectStub.java (added)
+++ maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/stubs/AntNoDepTestMavenProjectStub.java Sat Sep 23 11:04:04 2006
@@ -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 );
+    }
+}

Propchange: maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/stubs/AntNoDepTestMavenProjectStub.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/stubs/AntNoDepTestMavenProjectStub.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/ant-nodep-test-plugin-config.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/ant-nodep-test-plugin-config.xml?view=auto&rev=449282
==============================================================================
--- maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/ant-nodep-test-plugin-config.xml (added)
+++ maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/ant-nodep-test-plugin-config.xml Sat Sep 23 11:04:04 2006
@@ -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>

Propchange: maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/ant-nodep-test-plugin-config.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/ant-nodep-test-plugin-config.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/src/main/java/org/apache/maven/plugins/ant/test/App.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/src/main/java/org/apache/maven/plugins/ant/test/App.java?view=auto&rev=449282
==============================================================================
--- maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/src/main/java/org/apache/maven/plugins/ant/test/App.java (added)
+++ maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/src/main/java/org/apache/maven/plugins/ant/test/App.java Sat Sep 23 11:04:04 2006
@@ -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!" );
+    }
+}

Propchange: maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/src/main/java/org/apache/maven/plugins/ant/test/App.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/src/main/java/org/apache/maven/plugins/ant/test/App.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/src/main/resources/main.txt
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/src/main/resources/main.txt?view=auto&rev=449282
==============================================================================
--- maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/src/main/resources/main.txt (added)
+++ maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/src/main/resources/main.txt Sat Sep 23 11:04:04 2006
@@ -0,0 +1 @@
+Test resource for main
\ No newline at end of file

Propchange: maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/src/main/resources/main.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-nodep-test/src/main/resources/main.txt
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"