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/21 14:24:16 UTC
svn commit: r448530 - in /maven/plugins/trunk/maven-ant-plugin: ./
src/main/java/org/apache/maven/plugin/ant/ src/test/ src/test/java/
src/test/java/org/ src/test/java/org/apache/
src/test/java/org/apache/maven/ src/test/java/org/apache/maven/plugin/ s...
Author: vsiveton
Date: Thu Sep 21 05:24:14 2006
New Revision: 448530
URL: http://svn.apache.org/viewvc?view=rev&rev=448530
Log:
MANT-5: Add line breaks between <target> elements in build.xml
o Handle this in the AntBuildWriter
o Improved the build.xml renderer:
- added an header (with "do not edit")
- wrap long element tags
o Updated pom.xml:
- added license
- bumped dependencies
- added ant, maven-plugin-testing-harness for test scope
o Added test cases
Added:
maven/plugins/trunk/maven-ant-plugin/src/main/java/org/apache/maven/plugin/ant/AntBuildWriterUtil.java (with props)
maven/plugins/trunk/maven-ant-plugin/src/test/
maven/plugins/trunk/maven-ant-plugin/src/test/java/
maven/plugins/trunk/maven-ant-plugin/src/test/java/org/
maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/
maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/
maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/
maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/
maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/AntBuildWriterUtilTest.java (with props)
maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/AntMojoTest.java (with props)
maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/AntWrapper.java (with props)
maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/stubs/
maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/stubs/AntTestMavenProjectStub.java (with props)
maven/plugins/trunk/maven-ant-plugin/src/test/resources/
maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/
maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/
maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/ant-test-plugin-config.xml (with props)
maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/src/
maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/src/main/
maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/src/main/java/
maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/src/main/java/org/
maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/src/main/java/org/apache/
maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/src/main/java/org/apache/maven/
maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/src/main/java/org/apache/maven/plugins/
maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/src/main/java/org/apache/maven/plugins/ant/
maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/src/main/java/org/apache/maven/plugins/ant/test/
maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-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-test/src/test/
maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/src/test/java/
maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/src/test/java/org/
maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/src/test/java/org/apache/
maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/src/test/java/org/apache/maven/
maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/src/test/java/org/apache/maven/plugins/
maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/src/test/java/org/apache/maven/plugins/ant/
maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/src/test/java/org/apache/maven/plugins/ant/test/
maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/src/test/java/org/apache/maven/plugins/ant/test/AppTest.java (with props)
Modified:
maven/plugins/trunk/maven-ant-plugin/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?view=diff&rev=448530&r1=448529&r2=448530
==============================================================================
--- maven/plugins/trunk/maven-ant-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-ant-plugin/pom.xml Thu Sep 21 05:24:14 2006
@@ -1,8 +1,28 @@
-<project>
+<?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">
<parent>
<artifactId>maven-plugins</artifactId>
<groupId>org.apache.maven.plugins</groupId>
- <version>1</version>
+ <version>4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-ant-plugin</artifactId>
@@ -13,66 +33,39 @@
<system>jira</system>
<url>http://jira.codehaus.org/browse/MANT</url>
</issueManagement>
- <mailingLists>
- <!-- duplication from maven-plugins pom - temporary until they inherit properly -->
- <mailingList>
- <name>Maven User List</name>
- <subscribe>users-subscribe@maven.apache.org</subscribe>
- <unsubscribe>users-unsubscribe@maven.apache.org</unsubscribe>
- <post>users@maven.apache.org</post>
- <archive>http://mail-archives.apache.org/mod_mbox/maven-users</archive>
- <otherArchives>
- <otherArchive>http://www.mail-archive.com/users@maven.apache.org/</otherArchive>
- <otherArchive>http://www.nabble.com/Maven---Users-f178.html</otherArchive>
- </otherArchives>
- </mailingList>
- <mailingList>
- <name>Maven Developer List</name>
- <subscribe>dev-subscribe@maven.apache.org</subscribe>
- <unsubscribe>dev-unsubscribe@maven.apache.org</unsubscribe>
- <post>dev@maven.apache.org</post>
- <archive>http://mail-archives.apache.org/mod_mbox/maven-dev</archive>
- </mailingList>
- <mailingList>
- <name>Maven Commits List</name>
- <subscribe>commits-subscribe@maven.apache.org</subscribe>
- <unsubscribe>commits-unsubscribe@maven.apache.org</unsubscribe>
- <post>commits@maven.apache.org</post>
- <archive>http://mail-archives.apache.org/mod_mbox/maven-dev</archive>
- </mailingList>
- <!-- duplication from maven-parent pom - temporary until they inherit properly -->
- <mailingList>
- <name>Maven Announcements List</name>
- <post>announce@maven.apache.org</post>
- <subscribe>announce-subscribe@maven.apache.org</subscribe>
- <unsubscribe>announce-unsubscribe@maven.apache.org</unsubscribe>
- <archive>http://mail-archives.apache.org/mod_mbox/maven-announce/</archive>
- </mailingList>
- <mailingList>
- <name>Maven Issues List</name>
- <post>issues@maven.apache.org</post>
- <subscribe>issues-subscribe@maven.apache.org</subscribe>
- <unsubscribe>issues-unsubscribe@maven.apache.org</unsubscribe>
- <archive>http://mail-archives.apache.org/mod_mbox/maven-issues/</archive>
- </mailingList>
- <mailingList>
- <name>Maven Notifications List</name>
- <post>notifications@maven.apache.org</post>
- <subscribe>notifications-subscribe@maven.apache.org</subscribe>
- <unsubscribe>notifications-unsubscribe@maven.apache.org</unsubscribe>
- <archive>http://mail-archives.apache.org/mod_mbox/maven-notifications/</archive>
- </mailingList>
- </mailingLists>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
- <version>2.0</version>
+ <version>2.0.4</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
- <version>2.0</version>
+ <version>2.0.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-plugin-testing-harness</artifactId>
+ <version>1.0-beta-2-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>ant</groupId>
+ <artifactId>ant</artifactId>
+ <version>1.6.5</version>
+ </dependency>
+ <dependency>
+ <groupId>ant</groupId>
+ <artifactId>ant-junit</artifactId>
+ <version>1.6.5</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>ant</groupId>
+ <artifactId>ant-nodeps</artifactId>
+ <version>1.6.5</version>
+ <scope>test</scope>
</dependency>
</dependencies>
</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?view=diff&rev=448530&r1=448529&r2=448530
==============================================================================
--- 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 Thu Sep 21 05:24:14 2006
@@ -1,7 +1,7 @@
package org.apache.maven.plugin.ant;
/*
- * Copyright 2001-2005 The Apache Software Foundation.
+ * Copyright 2001-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.
@@ -16,32 +16,50 @@
* limitations under the License.
*/
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.model.Repository;
-import org.apache.maven.model.Resource;
-import org.apache.maven.project.MavenProject;
-import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
-import org.codehaus.plexus.util.xml.XMLWriter;
-
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Date;
import java.util.Iterator;
import java.util.List;
+import java.util.Locale;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.model.Repository;
+import org.apache.maven.model.Resource;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.wagon.PathUtils;
+import org.apache.tools.ant.Main;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
+import org.codehaus.plexus.util.xml.XMLWriter;
/**
+ * Write an <code>build.xml<code> for <a href="http://ant.apache.org">Ant</a> 1.6.2 or above.
+ *
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
* @version $Id$
*/
public class AntBuildWriter
{
+ /**
+ * The default line indenter
+ */
+ protected final static int DEFAULT_INDENTATION_SIZE = 2;
+
private MavenProject project;
private File localRepository;
+ /**
+ * @param project
+ * @param localRepository
+ */
public AntBuildWriter( MavenProject project, File localRepository )
{
this.project = project;
@@ -55,33 +73,76 @@
protected void writeBuildXml()
throws IOException
{
- FileWriter w;
-
// TODO: parameter
- w = new FileWriter( new File( project.getBasedir(), "build.xml" ) );
+ FileWriter w = new FileWriter( new File( project.getBasedir(), Main.DEFAULT_BUILD_FILENAME ) );
+
+ XMLWriter writer = new PrettyPrintXMLWriter( w, StringUtils.repeat( " ", DEFAULT_INDENTATION_SIZE ), "UTF-8",
+ null );
- XMLWriter writer = new PrettyPrintXMLWriter( w );
+ // ----------------------------------------------------------------------
+ // <!-- comments -->
+ // ----------------------------------------------------------------------
+
+ writeHeader( writer );
+
+ // ----------------------------------------------------------------------
+ // <project/>
+ // ----------------------------------------------------------------------
writer.startElement( "project" );
writer.addAttribute( "name", project.getArtifactId() );
writer.addAttribute( "default", "jar" );
writer.addAttribute( "basedir", "." );
+ AntBuildWriterUtil.writeLineBreak( writer );
+
+ // ----------------------------------------------------------------------
+ // <property/>
+ // ----------------------------------------------------------------------
+
writeProperties( writer );
+ // ----------------------------------------------------------------------
+ // <path/>
+ // ----------------------------------------------------------------------
+
writeBuildPathDefinition( writer );
+ // ----------------------------------------------------------------------
+ // <target name="clean" />
+ // ----------------------------------------------------------------------
+
writeCleanTarget( writer );
+
+ // ----------------------------------------------------------------------
+ // <target name="compile" />
+ // ----------------------------------------------------------------------
+
List compileSourceRoots = removeEmptyCompileSourceRoots( project.getCompileSourceRoots() );
writeCompileTarget( writer, compileSourceRoots );
+ // ----------------------------------------------------------------------
+ // <target name="jar" />
+ // ----------------------------------------------------------------------
// TODO: what if type is not JAR?
writeJarTarget( writer );
+ // ----------------------------------------------------------------------
+ // <target name="compile-tests" />
+ // ----------------------------------------------------------------------
+
List testCompileSourceRoots = removeEmptyCompileSourceRoots( project.getTestCompileSourceRoots() );
writeCompileTestsTarget( writer, testCompileSourceRoots );
+
+ // ----------------------------------------------------------------------
+ // <target name="test" />
+ // ----------------------------------------------------------------------
+
writeTestTargets( writer, testCompileSourceRoots );
+ // ----------------------------------------------------------------------
+ // <target name="get-deps" />
+ // ----------------------------------------------------------------------
writeGetDepsTarget( writer );
writer.endElement(); // project
@@ -91,25 +152,31 @@
private void writeCompileTestsTarget( XMLWriter writer, List testCompileSourceRoots )
{
+ AntBuildWriterUtil.writeCommentText( writer, "Test-compilation target", 1 );
+
writer.startElement( "target" );
writer.addAttribute( "name", "compile-tests" );
- writer.addAttribute( "depends", "junit-present, compile" );
- writer.addAttribute( "description", "Compile the test code" );
- writer.addAttribute( "if", "junit.present" );
+ AntBuildWriterUtil.addWrapAttribute( writer, "target", "depends", "junit-present, compile", 2 );
+ AntBuildWriterUtil.addWrapAttribute( writer, "target", "description", "Compile the test code", 2 );
+ AntBuildWriterUtil.addWrapAttribute( writer, "target", "if", "junit.present", 2 );
- writeCompileTasks( writer, project.getBasedir(), "${maven.test.output}", testCompileSourceRoots,
- project.getBuild().getTestResources(), "${maven.build.output}" );
+ writeCompileTasks( writer, project.getBasedir(), "${maven.test.output}", testCompileSourceRoots, project
+ .getBuild().getTestResources(), "${maven.build.output}" );
writer.endElement(); // target
+
+ AntBuildWriterUtil.writeLineBreak( writer );
}
private void writeTestTargets( XMLWriter writer, List testCompileSourceRoots )
{
+ AntBuildWriterUtil.writeCommentText( writer, "Run all tests", 1 );
+
writer.startElement( "target" );
writer.addAttribute( "name", "test" );
- writer.addAttribute( "depends", "junit-present, compile-tests" );
- writer.addAttribute( "if", "junit.present" );
- writer.addAttribute( "description", "Run the test cases" );
+ AntBuildWriterUtil.addWrapAttribute( writer, "target", "depends", "junit-present, compile-tests", 2 );
+ AntBuildWriterUtil.addWrapAttribute( writer, "target", "if", "junit.present", 2 );
+ AntBuildWriterUtil.addWrapAttribute( writer, "target", "description", "Run the test cases", 2 );
if ( !testCompileSourceRoots.isEmpty() )
{
@@ -156,14 +223,14 @@
{
writer.startElement( "fileset" );
String testSrcDir = (String) i.next();
- writer.addAttribute( "dir", toRelative( project.getBasedir(), testSrcDir ) );
-/* TODO: need to get these from the test plugin somehow?
- UnitTest unitTest = project.getBuild().getUnitTest();
- writeIncludesExcludes( writer, unitTest.getIncludes(), unitTest.getExcludes() );
- // TODO: m1 allows additional test exclusions via maven.ant.excludeTests
-*/
- writeIncludesExcludes( writer, Collections.singletonList( "**/*Test.java" ),
- Collections.singletonList( "**/*Abstract*Test.java" ) );
+ writer.addAttribute( "dir", PathUtils.toRelative( project.getBasedir(), testSrcDir ) );
+ /* TODO: need to get these from the test plugin somehow?
+ UnitTest unitTest = project.getBuild().getUnitTest();
+ writeIncludesExcludes( writer, unitTest.getIncludes(), unitTest.getExcludes() );
+ // TODO: m1 allows additional test exclusions via maven.ant.excludeTests
+ */
+ writeIncludesExcludes( writer, Collections.singletonList( "**/*Test.java" ), Collections
+ .singletonList( "**/*Abstract*Test.java" ) );
writer.endElement(); // fileset
}
writer.endElement(); // batchtest
@@ -172,6 +239,8 @@
}
writer.endElement(); // target
+ AntBuildWriterUtil.writeLineBreak( writer, 2, 1 );
+
writer.startElement( "target" );
writer.addAttribute( "name", "test-junit-present" );
@@ -182,13 +251,15 @@
writer.endElement(); // target
+ AntBuildWriterUtil.writeLineBreak( writer, 2, 1 );
+
writer.startElement( "target" );
writer.addAttribute( "name", "junit-present" );
- writer.addAttribute( "depends", "test-junit-present" );
- writer.addAttribute( "unless", "junit.present" );
+ AntBuildWriterUtil.addWrapAttribute( writer, "target", "depends", "test-junit-present", 2 );
+ AntBuildWriterUtil.addWrapAttribute( writer, "target", "unless", "junit.present", 2 );
writer.startElement( "echo" );
- writer.writeText( "================================= WARNING ================================" );
+ writer.writeText( StringUtils.repeat( "=", 35 ) + " WARNING " + StringUtils.repeat( "=", 35 ) );
writer.endElement(); // echo
writer.startElement( "echo" );
@@ -196,30 +267,38 @@
writer.endElement(); // echo
writer.startElement( "echo" );
- writer.writeText( "==========================================================================" );
+ writer.writeText( StringUtils.repeat( "=", 79 ) );
writer.endElement(); // echo
writer.endElement(); // target
+
+ AntBuildWriterUtil.writeLineBreak( writer );
}
private void writeJarTarget( XMLWriter writer )
{
+ AntBuildWriterUtil.writeCommentText( writer, "Creation target", 1 );
+
writer.startElement( "target" );
writer.addAttribute( "name", "jar" );
writer.addAttribute( "depends", "compile,test" );
- writer.addAttribute( "description", "Clean the JAR" );
+ writer.addAttribute( "description", "Create the JAR" );
writer.startElement( "jar" );
writer.addAttribute( "jarfile", "${maven.build.directory}/${maven.build.final.name}.jar" );
- writer.addAttribute( "basedir", "${maven.build.output}" );
- writer.addAttribute( "excludes", "**/package.html" );
+ AntBuildWriterUtil.addWrapAttribute( writer, "jar", "basedir", "${maven.build.output}", 3 );
+ AntBuildWriterUtil.addWrapAttribute( writer, "jar", "excludes", "**/package.html", 3 );
writer.endElement(); // jar
writer.endElement(); // target
+
+ AntBuildWriterUtil.writeLineBreak( writer );
}
private void writeCleanTarget( XMLWriter writer )
{
+ AntBuildWriterUtil.writeCommentText( writer, "Cleaning up target", 1 );
+
writer.startElement( "target" );
writer.addAttribute( "name", "clean" );
writer.addAttribute( "description", "Clean the output directory" );
@@ -229,23 +308,29 @@
writer.endElement(); // delete
writer.endElement(); // target
+
+ AntBuildWriterUtil.writeLineBreak( writer );
}
private void writeCompileTarget( XMLWriter writer, List compileSourceRoots )
{
+ AntBuildWriterUtil.writeCommentText( writer, "Compilation target", 1 );
+
writer.startElement( "target" );
writer.addAttribute( "name", "compile" );
writer.addAttribute( "depends", "get-deps" );
writer.addAttribute( "description", "Compile the code" );
- writeCompileTasks( writer, project.getBasedir(), "${maven.build.output}", compileSourceRoots,
- project.getBuild().getResources(), null );
+ writeCompileTasks( writer, project.getBasedir(), "${maven.build.output}", compileSourceRoots, project
+ .getBuild().getResources(), null );
writer.endElement(); // target
+
+ AntBuildWriterUtil.writeLineBreak( writer );
}
private static void writeCompileTasks( XMLWriter writer, File basedir, String outputDirectory,
- List compileSourceRoots, List resources, String additionalClassesDirectory )
+ List compileSourceRoots, List resources, String additionalClassesDirectory )
{
writer.startElement( "mkdir" );
writer.addAttribute( "dir", outputDirectory );
@@ -255,10 +340,10 @@
{
writer.startElement( "javac" );
writer.addAttribute( "destdir", outputDirectory );
- writer.addAttribute( "excludes", "**/package.html" );
- writer.addAttribute( "debug", "true" ); // TODO: use compiler setting
- writer.addAttribute( "deprecation", "true" ); // TODO: use compiler setting
- writer.addAttribute( "optimize", "false" ); // TODO: use compiler setting
+ AntBuildWriterUtil.addWrapAttribute( writer, "javac", "excludes", "**/package.html", 3 );
+ AntBuildWriterUtil.addWrapAttribute( writer, "javac", "debug", "true", 3 ); // TODO: use compiler setting
+ AntBuildWriterUtil.addWrapAttribute( writer, "javac", "deprecation", "true", 3 ); // TODO: use compiler setting
+ AntBuildWriterUtil.addWrapAttribute( writer, "javac", "optimize", "false", 3 ); // TODO: use compiler setting
for ( Iterator i = compileSourceRoots.iterator(); i.hasNext(); )
{
@@ -266,7 +351,7 @@
writer.startElement( "src" );
writer.startElement( "pathelement" );
- writer.addAttribute( "location", toRelative( basedir, srcDir ) );
+ writer.addAttribute( "location", PathUtils.toRelative( basedir, srcDir ) );
writer.endElement(); // pathelement
writer.endElement(); // src
}
@@ -313,7 +398,7 @@
writer.addAttribute( "todir", outputDir );
writer.startElement( "fileset" );
- writer.addAttribute( "dir", toRelative( basedir, resource.getDirectory() ) );
+ writer.addAttribute( "dir", PathUtils.toRelative( basedir, resource.getDirectory() ) );
writeIncludesExcludes( writer, resource.getIncludes(), resource.getExcludes() );
@@ -362,6 +447,8 @@
private void writeGetDepsTarget( XMLWriter writer )
{
+ AntBuildWriterUtil.writeCommentText( writer, "Download dependencies target", 1 );
+
writer.startElement( "target" );
writer.addAttribute( "name", "test-offline" );
@@ -372,13 +459,15 @@
writer.addAttribute( "arg2", "only" );
writer.endElement(); // equals
writer.endElement(); // condition
-
writer.endElement(); // target
+
+ AntBuildWriterUtil.writeLineBreak( writer, 2, 1 );
+
writer.startElement( "target" );
writer.addAttribute( "name", "get-deps" );
- writer.addAttribute( "depends", "test-offline" );
- writer.addAttribute( "description", "Download all dependencies" );
- writer.addAttribute( "unless", "maven.mode.offline" ); // TODO: check, and differs from m1
+ AntBuildWriterUtil.addWrapAttribute( writer, "target", "depends", "test-offline", 2 );
+ AntBuildWriterUtil.addWrapAttribute( writer, "target", "description", "Download all dependencies", 2 );
+ AntBuildWriterUtil.addWrapAttribute( writer, "target", "unless", "maven.mode.offline", 2 ); // TODO: check, and differs from m1
writer.startElement( "mkdir" );
writer.addAttribute( "dir", "${maven.repo.local}" );
@@ -391,13 +480,13 @@
Artifact artifact = (Artifact) i.next();
// TODO: should the artifacthandler be used instead?
- String path = toRelative( localRepository, artifact.getFile().getPath() );
+ String path = PathUtils.toRelative( localRepository, artifact.getFile().getPath() );
File parentDirs = new File( path ).getParentFile();
if ( parentDirs != null )
{
writer.startElement( "mkdir" );
- writer.addAttribute( "dir", parentDirs.getAbsolutePath() );
+ writer.addAttribute( "dir", "${maven.repo.local}/" + parentDirs.getPath() );
writer.endElement(); // mkdir
}
@@ -407,18 +496,22 @@
writer.startElement( "get" );
writer.addAttribute( "src", repository.getUrl() + "/" + path );
- writer.addAttribute( "dest", "${maven.repo.local}/" + path );
- writer.addAttribute( "usetimestamp", "true" );
- writer.addAttribute( "ignoreerrors", "true" );
+ AntBuildWriterUtil.addWrapAttribute( writer, "get", "dest", "${maven.repo.local}/" + path, 3 );
+ AntBuildWriterUtil.addWrapAttribute( writer, "get", "usetimestamp", "true", 3 );
+ AntBuildWriterUtil.addWrapAttribute( writer, "get", "ignoreerrors", "true", 3 );
writer.endElement(); // get
}
}
writer.endElement(); // target
+
+ AntBuildWriterUtil.writeLineBreak( writer );
}
private void writeBuildPathDefinition( XMLWriter writer )
{
+ AntBuildWriterUtil.writeCommentText( writer, "Defining classpaths", 1 );
+
writer.startElement( "path" );
writer.addAttribute( "id", "build.classpath" );
writer.startElement( "fileset" );
@@ -427,29 +520,34 @@
{
Artifact artifact = (Artifact) i.next();
writer.startElement( "include" );
- writer.addAttribute( "name", toRelative( localRepository, artifact.getFile().getPath() ) );
+ writer.addAttribute( "name", PathUtils.toRelative( localRepository, artifact.getFile().getPath() ) );
writer.endElement(); // include
}
writer.endElement(); // fileset
writer.endElement(); // path
+
+ AntBuildWriterUtil.writeLineBreak( writer );
}
private void writeProperties( XMLWriter writer )
{
// TODO: optional in m1
// TODO: USD properties
+ AntBuildWriterUtil.writeCommentText( writer, "Build environnement properties", 1 );
+
writer.startElement( "property" );
writer.addAttribute( "file", "${user.home}/.m2/maven.properties" );
writer.endElement(); // property
writer.startElement( "property" );
writer.addAttribute( "name", "maven.build.output" );
- writer.addAttribute( "value", toRelative( project.getBasedir(), project.getBuild().getOutputDirectory() ) );
+ writer.addAttribute( "value", PathUtils.toRelative( project.getBasedir(), project.getBuild()
+ .getOutputDirectory() ) );
writer.endElement(); // property
writer.startElement( "property" );
writer.addAttribute( "name", "maven.build.directory" );
- writer.addAttribute( "value", toRelative( project.getBasedir(), project.getBuild().getDirectory() ) );
+ writer.addAttribute( "value", PathUtils.toRelative( project.getBasedir(), project.getBuild().getDirectory() ) );
writer.endElement(); // property
writer.startElement( "property" );
@@ -465,7 +563,8 @@
writer.startElement( "property" );
writer.addAttribute( "name", "maven.test.output" );
- writer.addAttribute( "value", toRelative( project.getBasedir(), project.getBuild().getTestOutputDirectory() ) );
+ writer.addAttribute( "value", PathUtils.toRelative( project.getBasedir(), project.getBuild()
+ .getTestOutputDirectory() ) );
writer.endElement(); // property
writer.startElement( "property" );
@@ -473,32 +572,45 @@
writer.addAttribute( "value", "${user.home}/.m2/repository" );
writer.endElement(); // property
-/* TODO: offline setting
- writer.startElement( "property" );
- writer.addAttribute( "name", "maven.mode.offline" );
- writer.addAttribute( "value", project.getBuild().getOutput() );
- writer.endElement(); // property
-*/
- }
-
- // TODO: move to plexus-utils or use something appropriate from there (eclipse plugin too)
- private static String toRelative( File basedir, String absolutePath )
- {
- String relative;
+ /* TODO: offline setting
+ writer.startElement( "property" );
+ writer.addAttribute( "name", "maven.mode.offline" );
+ writer.addAttribute( "value", project.getBuild().getOutput() );
+ writer.endElement(); // property
+ */
+
+ AntBuildWriterUtil.writeLineBreak( writer );
+ }
+
+ /**
+ * Write comment in the file header
+ *
+ * @param writer
+ */
+ private static void writeHeader( XMLWriter writer )
+ {
+ AntBuildWriterUtil.writeLineBreak( writer );
+
+ AntBuildWriterUtil.writeCommentLineBreak( writer );
+ AntBuildWriterUtil.writeComment( writer, "Ant build file (http://ant.apache.org/) for Ant 1.6.2 or above." );
+ AntBuildWriterUtil.writeCommentLineBreak( writer );
+
+ AntBuildWriterUtil.writeLineBreak( writer );
+
+ AntBuildWriterUtil.writeCommentLineBreak( writer );
+ AntBuildWriterUtil.writeComment( writer, StringUtils.repeat( "=", 21 ) + " - DO NOT EDIT THIS FILE! - "
+ + StringUtils.repeat( "=", 21 ) );
+ AntBuildWriterUtil.writeCommentLineBreak( writer );
+ AntBuildWriterUtil.writeComment( writer, " " );
+ AntBuildWriterUtil.writeComment( writer, "Any modifications will be overwritten." );
+ AntBuildWriterUtil.writeComment( writer, " " );
+ DateFormat dateFormat = DateFormat.getDateTimeInstance( DateFormat.SHORT, DateFormat.SHORT, Locale.US );
+ AntBuildWriterUtil.writeComment( writer, "Generated by Maven Ant Plugin on "
+ + dateFormat.format( new Date( System.currentTimeMillis() ) ) );
+ AntBuildWriterUtil.writeComment( writer, "See: http://maven.apache.org/plugins/maven-ant-plugin/" );
+ AntBuildWriterUtil.writeComment( writer, " " );
+ AntBuildWriterUtil.writeCommentLineBreak( writer );
- absolutePath = absolutePath.replace( '\\', '/' );
- String basedirPath = basedir.getAbsolutePath().replace( '\\', '/' );
-
- if ( absolutePath.startsWith( basedirPath ) )
- {
- relative = absolutePath.substring( basedirPath.length() + 1 );
- }
- else
- {
- relative = absolutePath;
- }
-
- return relative;
+ AntBuildWriterUtil.writeLineBreak( writer );
}
-
}
Added: maven/plugins/trunk/maven-ant-plugin/src/main/java/org/apache/maven/plugin/ant/AntBuildWriterUtil.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/main/java/org/apache/maven/plugin/ant/AntBuildWriterUtil.java?view=auto&rev=448530
==============================================================================
--- maven/plugins/trunk/maven-ant-plugin/src/main/java/org/apache/maven/plugin/ant/AntBuildWriterUtil.java (added)
+++ maven/plugins/trunk/maven-ant-plugin/src/main/java/org/apache/maven/plugin/ant/AntBuildWriterUtil.java Thu Sep 21 05:24:14 2006
@@ -0,0 +1,187 @@
+package org.apache.maven.plugin.ant;
+
+/*
+ * 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 org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.xml.XMLWriter;
+
+/**
+ * Utility class for the <code>AntBuildWriter</code> class.
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ */
+public class AntBuildWriterUtil
+{
+ /**
+ * Convenience method to write one CRLF
+ *
+ * @param writer
+ */
+ public static void writeLineBreak( XMLWriter writer )
+ {
+ writeLineBreak( writer, 1 );
+ }
+
+ /**
+ * Convenience method to repeat <code>CRLF</code>
+ *
+ * @param writer
+ * @param repeat
+ */
+ public static void writeLineBreak( XMLWriter writer, int repeat )
+ {
+ for ( int i = 0; i < repeat; i++ )
+ {
+ writer.writeMarkup( "\n" );
+ }
+ }
+
+ /**
+ * Convenience method to repeat <code>CRLF</code> and to indent the writer
+ *
+ * @param writer
+ * @param repeat
+ * @param indent
+ */
+ public static void writeLineBreak( XMLWriter writer, int repeat, int indent )
+ {
+ writeLineBreak( writer, repeat );
+
+ if ( indent < 0 )
+ {
+ indent = 0;
+ }
+
+ writer.writeText( StringUtils.repeat( " ", indent * AntBuildWriter.DEFAULT_INDENTATION_SIZE ) );
+ }
+
+ /**
+ * Convenience method to write XML comment line break. Its size is 80.
+ *
+ * @param writer
+ */
+ public static void writeCommentLineBreak( XMLWriter writer )
+ {
+ writer.writeMarkup( "<!-- " + StringUtils.repeat( "=", 70 ) + " -->\n" );
+ }
+
+ /**
+ * Convenience method to write XML comment line. The <code>comment</code> is splitted to have a size of 80.
+ *
+ * @param writer
+ * @param comment
+ */
+ public static void writeComment( XMLWriter writer, String comment )
+ {
+ if ( comment == null )
+ {
+ comment = "null";
+ }
+
+ String[] words = StringUtils.split( comment, " " );
+
+ StringBuffer line = new StringBuffer( "<!-- " );
+ for ( int i = 0; i < words.length; i++ )
+ {
+ String[] sentences = StringUtils.split( words[i], "\n" );
+ if ( sentences.length > 1 )
+ {
+ for ( int j = 0; j < sentences.length - 1; j++ )
+ {
+ line.append( sentences[j] ).append( ' ' );
+ line.append( StringUtils.repeat( " ", 76 - line.length() ) ).append( "-->" ).append( '\n' );
+ writer.writeMarkup( line.toString() );
+ line = new StringBuffer( "<!-- " );
+ }
+ line.append( sentences[sentences.length - 1] ).append( ' ' );
+ }
+ else
+ {
+ StringBuffer sentenceTmp = new StringBuffer( line.toString() );
+ sentenceTmp.append( words[i] ).append( ' ' );
+ if ( sentenceTmp.length() > 76 )
+ {
+ line.append( StringUtils.repeat( " ", 76 - line.length() ) ).append( "-->" ).append( '\n' );
+ writer.writeMarkup( line.toString() );
+ line = new StringBuffer( "<!-- " );
+ line.append( words[i] ).append( ' ' );
+ }
+ else
+ {
+ line.append( words[i] ).append( ' ' );
+ }
+ }
+ }
+ if ( line.length() <= 76 )
+ {
+ line.append( StringUtils.repeat( " ", 76 - line.length() ) ).append( "-->" ).append( '\n' );
+ }
+ writer.writeMarkup( line.toString() );
+ }
+
+ /**
+ * Convenience method to write XML comment between two comment line break. The XML comment block is also indented.
+ *
+ * @param writer
+ * @param comment
+ * @param indent
+ */
+ public static void writeCommentText( XMLWriter writer, String comment, int indent )
+ {
+ if ( indent < 0 )
+ {
+ indent = 0;
+ }
+
+ writeLineBreak( writer, 1 );
+
+ writer.writeMarkup( StringUtils.repeat( " ", indent * AntBuildWriter.DEFAULT_INDENTATION_SIZE ) );
+ writeCommentLineBreak( writer );
+
+ writer.writeMarkup( StringUtils.repeat( " ", indent * AntBuildWriter.DEFAULT_INDENTATION_SIZE ) );
+ writeComment( writer, " " + comment );
+
+ writer.writeMarkup( StringUtils.repeat( " ", indent * AntBuildWriter.DEFAULT_INDENTATION_SIZE ) );
+ writeCommentLineBreak( writer );
+
+ writeLineBreak( writer, 1, indent );
+ }
+
+ /**
+ * Convenience method to wrap long element tags for a given attribute.
+ *
+ * @param writer
+ * @param tag
+ * @param name
+ * @param value
+ * @param indent
+ */
+ public static void addWrapAttribute( XMLWriter writer, String tag, String name, String value, int indent )
+ {
+ if ( indent < 0 )
+ {
+ writer.addAttribute( name, value );
+ }
+ else
+ {
+ writer.addAttribute( "\n"
+ + StringUtils.repeat( " ", ( StringUtils.isEmpty( tag ) ? 0 : tag.length() ) + indent
+ * AntBuildWriter.DEFAULT_INDENTATION_SIZE ) + name, value );
+ }
+ }
+}
Propchange: maven/plugins/trunk/maven-ant-plugin/src/main/java/org/apache/maven/plugin/ant/AntBuildWriterUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-ant-plugin/src/main/java/org/apache/maven/plugin/ant/AntBuildWriterUtil.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
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?view=diff&rev=448530&r1=448529&r2=448530
==============================================================================
--- 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 Thu Sep 21 05:24:14 2006
@@ -1,7 +1,7 @@
package org.apache.maven.plugin.ant;
/*
- * Copyright 2001-2005 The Apache Software Foundation.
+ * Copyright 2001-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.
@@ -25,7 +25,7 @@
import java.io.IOException;
/**
- * A Maven2 plugin to generate an Ant build file.
+ * Generate an Ant build file.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
@@ -52,6 +52,9 @@
*/
private ArtifactRepository localRepository;
+ /**
+ * @see org.apache.maven.plugin.Mojo#execute()
+ */
public void execute()
throws MojoExecutionException
{
Added: maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/AntBuildWriterUtilTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/AntBuildWriterUtilTest.java?view=auto&rev=448530
==============================================================================
--- maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/AntBuildWriterUtilTest.java (added)
+++ maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/AntBuildWriterUtilTest.java Thu Sep 21 05:24:14 2006
@@ -0,0 +1,78 @@
+package org.apache.maven.plugin.ant;
+
+/*
+ * 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.StringWriter;
+
+import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
+import org.codehaus.plexus.util.xml.XMLWriter;
+
+import junit.framework.TestCase;
+
+/**
+ * Test cases for 'org.apache.maven.plugin.ant.AntBuildWriterUtil'
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ */
+public class AntBuildWriterUtilTest
+ extends TestCase
+{
+ /**
+ * Test method for 'org.apache.maven.plugin.ant.AntBuildWriterUtil.writeComment(XMLWriter, String)'
+ */
+ public void testWriteCommentNull()
+ {
+ StringWriter s = new StringWriter();
+ XMLWriter writer = new PrettyPrintXMLWriter( s );
+ AntBuildWriterUtil.writeComment( writer, null );
+ StringBuffer sb = new StringBuffer();
+ sb.append( "<!-- null -->" ).append( '\n' );
+ assertTrue( s.toString().equals( sb.toString() ) );
+ }
+
+ /**
+ * Test method for 'org.apache.maven.plugin.ant.AntBuildWriterUtil.writeComment(XMLWriter, String)'
+ */
+ public void testWriteCommentShort()
+ {
+ StringWriter s = new StringWriter();
+ XMLWriter writer = new PrettyPrintXMLWriter( s );
+ AntBuildWriterUtil.writeComment( writer, "This is a short text");
+ StringBuffer sb = new StringBuffer();
+ sb.append( "<!-- This is a short text -->" ).append( '\n' );
+ assertTrue( s.toString().equals( sb.toString() ) );
+ }
+
+ /**
+ * Test method for 'org.apache.maven.plugin.ant.AntBuildWriterUtil.writeComment(XMLWriter, String)'
+ */
+ public void testWriteCommentLong()
+ {
+ StringWriter s = new StringWriter();
+ XMLWriter writer = new PrettyPrintXMLWriter( s );
+ AntBuildWriterUtil.writeComment( writer, "Maven is a software project management and comprehension tool. " +
+ "Based on the concept of a project object model (POM), Maven can manage a project's build, reporting " +
+ "and documentation from a central piece of information." );
+ StringBuffer sb = new StringBuffer();
+ sb.append( "<!-- Maven is a software project management and comprehension tool. Based -->" ).append( '\n' );
+ sb.append( "<!-- on the concept of a project object model (POM), Maven can manage a -->" ).append( '\n' );
+ sb.append( "<!-- project's build, reporting and documentation from a central piece of -->" ).append( '\n' );
+ sb.append( "<!-- information. -->" ).append( '\n' );
+ assertTrue( s.toString().equals( sb.toString() ) );
+ }
+}
Propchange: maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/AntBuildWriterUtilTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/AntBuildWriterUtilTest.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: 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=auto&rev=448530
==============================================================================
--- maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/AntMojoTest.java (added)
+++ maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/AntMojoTest.java Thu Sep 21 05:24:14 2006
@@ -0,0 +1,74 @@
+package org.apache.maven.plugin.ant;
+
+/*
+ * 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 org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.apache.tools.ant.Main;
+
+/**
+ * Class to test Ant plugin
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ */
+public class AntMojoTest
+ extends AbstractMojoTestCase
+{
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp()
+ throws Exception
+ {
+ // required for mojo lookups to work
+ super.setUp();
+ }
+
+ /**
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown()
+ throws Exception
+ {
+ // nop
+ }
+
+ /**
+ * Method to test Ant generation
+ *
+ * @throws Exception
+ */
+ public void testWriter()
+ throws Exception
+ {
+ File testPom = new File( getBasedir(), "src/test/resources/unit/ant-test/ant-test-plugin-config.xml" );
+ AntMojo mojo = (AntMojo) lookupMojo( "ant", testPom );
+ mojo.execute();
+
+ File antBasedir = new File( getBasedir(), "target/test/unit/ant-test/" );
+ File antBuild = new File( antBasedir, Main.DEFAULT_BUILD_FILENAME );
+ assertTrue( antBuild.exists() );
+
+ AntWrapper.invoke( antBuild );
+
+ assertTrue( new File( antBasedir, "target" ).exists() );
+ assertTrue( new File( antBasedir, "target/classes" ).exists() );
+ assertTrue( new File( antBasedir, "target/ant-plugin-test.jar" ).exists() );
+ }
+}
Propchange: maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/AntMojoTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/AntMojoTest.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/AntWrapper.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/AntWrapper.java?view=auto&rev=448530
==============================================================================
--- maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/AntWrapper.java (added)
+++ maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/AntWrapper.java Thu Sep 21 05:24:14 2006
@@ -0,0 +1,108 @@
+package org.apache.maven.plugin.ant;
+
+/*
+ * 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.OutputStream;
+import java.io.PrintStream;
+import java.util.Properties;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.ExitException;
+import org.apache.tools.ant.Main;
+import org.apache.tools.ant.util.optional.NoExitSecurityManager;
+import org.codehaus.plexus.util.StringOutputStream;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * Wrap <code>Ant</code> call.
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ */
+public class AntWrapper
+{
+ /**
+ * Invoke <code>Ant</code> for the default target of a given build file.
+ *
+ * @param antBuild an <code>Ant build</code> file
+ * @throws IllegalArgumentException if any
+ * @throws BuildException if any
+ */
+ public static void invoke( File antBuild )
+ throws BuildException, IllegalArgumentException
+ {
+ if ( !antBuild.exists() )
+ {
+ throw new IllegalArgumentException( "antBuild should exist" );
+ }
+ if ( !antBuild.isFile() )
+ {
+ throw new IllegalArgumentException( "antBuild should be a file" );
+ }
+
+ // ----------------------------------------------------------------------
+ // NB: By using org.apache.tools.ant.launch.Launcher, we have:
+ // java.lang.ClassCastException
+ // at org.apache.tools.ant.launch.Launcher.run(Launcher.java:245)
+ // So, using org.apache.tools.ant.Main#main()
+ // ----------------------------------------------------------------------
+
+ Properties oldSystemProperties = System.getProperties();
+
+ System.setProperty( "basedir", antBuild.getParentFile().getAbsolutePath() );
+
+ SecurityManager oldSm = System.getSecurityManager();
+ System.setSecurityManager( new NoExitSecurityManager() );
+
+ PrintStream oldErr = System.err;
+ OutputStream errOS = new StringOutputStream();
+ PrintStream err = new PrintStream( errOS );
+ System.setErr( err );
+
+ PrintStream oldOut = System.out;
+ OutputStream outOS = new StringOutputStream();
+ PrintStream out = new PrintStream( outOS );
+ System.setOut( out );
+
+ // ----------------------------------------------------------------------
+ // To prevent Javac exception i.e. "Unable to find a javac compiler"
+ // Ant can use the same command line arguments as the javac of the current VM
+ // ----------------------------------------------------------------------
+ System.setProperty( "build.compiler", "extJavac" );
+
+ try
+ {
+ Main.main( new String[] { "-f", antBuild.getAbsolutePath() } );
+ }
+ catch ( ExitException e )
+ {
+ if ( StringUtils.isNotEmpty( errOS.toString() ) )
+ {
+ throw new BuildException( "Error in the Ant build file. \n= Ant output =\n" + outOS.toString() + "\n"
+ + errOS.toString() );
+ }
+ }
+ finally
+ {
+ System.setSecurityManager( oldSm );
+ System.setErr( oldErr );
+ System.setOut( oldOut );
+ System.setProperties( oldSystemProperties );
+ }
+ }
+}
Propchange: maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/AntWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/AntWrapper.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/stubs/AntTestMavenProjectStub.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/stubs/AntTestMavenProjectStub.java?view=auto&rev=448530
==============================================================================
--- maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/stubs/AntTestMavenProjectStub.java (added)
+++ maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/stubs/AntTestMavenProjectStub.java Thu Sep 21 05:24:14 2006
@@ -0,0 +1,145 @@
+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 java.util.Set;
+
+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.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 AntTestMavenProjectStub
+ extends MavenProjectStub
+{
+ private Build build;
+
+ /**
+ * Default
+ */
+ public AntTestMavenProjectStub()
+ {
+ MavenXpp3Reader pomReader = new MavenXpp3Reader();
+ Model model = null;
+
+ try
+ {
+ model = pomReader.read( new FileReader( new File( PlexusTestCase.getBasedir()
+ + "/src/test/resources/unit/ant-test/ant-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();
+ build.setFinalName( model.getArtifactId() );
+ build.setDirectory( getBasedir().getAbsolutePath() + "/target" );
+ 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-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-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-test/src/test/java" );
+ return Collections.singletonList( test.getAbsolutePath() );
+ }
+
+ /**
+ * @see org.apache.maven.project.MavenProject#getArtifacts()
+ */
+ public Set getArtifacts()
+ {
+ Artifact junit = new DefaultArtifact( "junit", "junit", VersionRange.createFromVersion( "3.8.1" ),
+ Artifact.SCOPE_TEST, "jar", null, new DefaultArtifactHandler( "jar" ),
+ false );
+ junit.setFile( new File( "junit/junit/3.8.1/junit-3.8.1.jar" ) );
+
+ return Collections.singleton( junit );
+ }
+
+ /**
+ * @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/AntTestMavenProjectStub.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-ant-plugin/src/test/java/org/apache/maven/plugin/ant/stubs/AntTestMavenProjectStub.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/ant-test-plugin-config.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/ant-test-plugin-config.xml?view=auto&rev=448530
==============================================================================
--- maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/ant-test-plugin-config.xml (added)
+++ maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/ant-test-plugin-config.xml Thu Sep 21 05:24:14 2006
@@ -0,0 +1,50 @@
+<?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>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-ant-plugin</artifactId>
+ <configuration>
+ <project implementation="org.apache.maven.plugin.ant.stubs.AntTestMavenProjectStub"/>
+ <localRepository>${localRepository}</localRepository>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Propchange: maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/ant-test-plugin-config.xml
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-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-test/src/main/java/org/apache/maven/plugins/ant/test/App.java?view=auto&rev=448530
==============================================================================
--- maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/src/main/java/org/apache/maven/plugins/ant/test/App.java (added)
+++ maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/src/main/java/org/apache/maven/plugins/ant/test/App.java Thu Sep 21 05:24:14 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-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-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-test/src/test/java/org/apache/maven/plugins/ant/test/AppTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/src/test/java/org/apache/maven/plugins/ant/test/AppTest.java?view=auto&rev=448530
==============================================================================
--- maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/src/test/java/org/apache/maven/plugins/ant/test/AppTest.java (added)
+++ maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/src/test/java/org/apache/maven/plugins/ant/test/AppTest.java Thu Sep 21 05:24:14 2006
@@ -0,0 +1,38 @@
+package org.apache.maven.plugins.ant.test;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest
+ extends TestCase
+{
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public AppTest( String testName )
+ {
+ super( testName );
+ }
+
+ /**
+ * @return the suite of tests being tested
+ */
+ public static Test suite()
+ {
+ return new TestSuite( AppTest.class );
+ }
+
+ /**
+ * Rigourous Test :-)
+ */
+ public void testApp()
+ {
+ assertTrue( true );
+ }
+}
Propchange: maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/src/test/java/org/apache/maven/plugins/ant/test/AppTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-ant-plugin/src/test/resources/unit/ant-test/src/test/java/org/apache/maven/plugins/ant/test/AppTest.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"