You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2009/04/13 15:23:40 UTC
svn commit: r764446 - in /maven/plugins/trunk/maven-ant-plugin: ./
src/it/clean-custom-files/ src/it/clean/
src/main/java/org/apache/maven/plugin/ant/
Author: bentmann
Date: Mon Apr 13 13:23:39 2009
New Revision: 764446
URL: http://svn.apache.org/viewvc?rev=764446&view=rev
Log:
[MANT-47] ant:clean should not delete build.xml
o Updated solution after dicussion on IRC
o Added ITs
Added:
maven/plugins/trunk/maven-ant-plugin/src/it/clean/
maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/
maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/invoker.properties (with props)
maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/pom.xml (with props)
maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/test.properties (with props)
maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/verify.bsh (with props)
maven/plugins/trunk/maven-ant-plugin/src/it/clean/invoker.properties (with props)
maven/plugins/trunk/maven-ant-plugin/src/it/clean/pom.xml (with props)
maven/plugins/trunk/maven-ant-plugin/src/it/clean/verify.bsh (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/AntCleanMojo.java
Modified: maven/plugins/trunk/maven-ant-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/pom.xml?rev=764446&r1=764445&r2=764446&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ant-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-ant-plugin/pom.xml Mon Apr 13 13:23:39 2009
@@ -100,16 +100,6 @@
<artifactId>xml-apis</artifactId>
<version>1.0.b2</version>
</dependency>
- <dependency>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-interactivity-api</artifactId>
- <version>1.0-alpha-5</version>
- </dependency>
- <dependency>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-interactivity-jline</artifactId>
- <version>1.0-alpha-5</version>
- </dependency>
<!-- test -->
<dependency>
Added: maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/invoker.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/invoker.properties?rev=764446&view=auto
==============================================================================
--- maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/invoker.properties (added)
+++ maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/invoker.properties Mon Apr 13 13:23:39 2009
@@ -0,0 +1 @@
+invoker.goals = clean ant:ant ant:clean
Propchange: maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/invoker.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/invoker.properties
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/pom.xml?rev=764446&view=auto
==============================================================================
--- maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/pom.xml (added)
+++ maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/pom.xml Mon Apr 13 13:23:39 2009
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.plugins.maven-ant-plugin.it</groupId>
+ <artifactId>clean-custom-files</artifactId>
+ <version>1.0-SNAPSHOT</version>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-ant-plugin</artifactId>
+ <version>@project.version@</version>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Propchange: maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/pom.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/test.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/test.properties?rev=764446&view=auto
==============================================================================
--- maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/test.properties (added)
+++ maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/test.properties Mon Apr 13 13:23:39 2009
@@ -0,0 +1 @@
+deleteCustomFiles = true
Propchange: maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/test.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/test.properties
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/verify.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/verify.bsh?rev=764446&view=auto
==============================================================================
--- maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/verify.bsh (added)
+++ maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/verify.bsh Mon Apr 13 13:23:39 2009
@@ -0,0 +1,14 @@
+import java.io.*;
+import java.util.*;
+import java.util.regex.*;
+
+import org.codehaus.plexus.util.*;
+
+File buildFile = new File( basedir, "build.xml" );
+System.out.println( "Checking for absence of " + buildFile );
+if ( buildFile.exists() )
+{
+ throw new IllegalStateException( "Custom build.xml was not deleted!" );
+}
+
+return true;
Propchange: maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/verify.bsh
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-ant-plugin/src/it/clean-custom-files/verify.bsh
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-ant-plugin/src/it/clean/invoker.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/it/clean/invoker.properties?rev=764446&view=auto
==============================================================================
--- maven/plugins/trunk/maven-ant-plugin/src/it/clean/invoker.properties (added)
+++ maven/plugins/trunk/maven-ant-plugin/src/it/clean/invoker.properties Mon Apr 13 13:23:39 2009
@@ -0,0 +1 @@
+invoker.goals = clean ant:ant ant:clean
Propchange: maven/plugins/trunk/maven-ant-plugin/src/it/clean/invoker.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-ant-plugin/src/it/clean/invoker.properties
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-ant-plugin/src/it/clean/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/it/clean/pom.xml?rev=764446&view=auto
==============================================================================
--- maven/plugins/trunk/maven-ant-plugin/src/it/clean/pom.xml (added)
+++ maven/plugins/trunk/maven-ant-plugin/src/it/clean/pom.xml Mon Apr 13 13:23:39 2009
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.plugins.maven-ant-plugin.it</groupId>
+ <artifactId>clean</artifactId>
+ <version>1.0-SNAPSHOT</version>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-ant-plugin</artifactId>
+ <version>@project.version@</version>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Propchange: maven/plugins/trunk/maven-ant-plugin/src/it/clean/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-ant-plugin/src/it/clean/pom.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-ant-plugin/src/it/clean/verify.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/it/clean/verify.bsh?rev=764446&view=auto
==============================================================================
--- maven/plugins/trunk/maven-ant-plugin/src/it/clean/verify.bsh (added)
+++ maven/plugins/trunk/maven-ant-plugin/src/it/clean/verify.bsh Mon Apr 13 13:23:39 2009
@@ -0,0 +1,14 @@
+import java.io.*;
+import java.util.*;
+import java.util.regex.*;
+
+import org.codehaus.plexus.util.*;
+
+File buildFile = new File( basedir, "build.xml" );
+System.out.println( "Checking for existence of " + buildFile );
+if ( !buildFile.isFile() )
+{
+ throw new IllegalStateException( "Custom build.xml was deleted!" );
+}
+
+return true;
Propchange: maven/plugins/trunk/maven-ant-plugin/src/it/clean/verify.bsh
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-ant-plugin/src/it/clean/verify.bsh
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: maven/plugins/trunk/maven-ant-plugin/src/main/java/org/apache/maven/plugin/ant/AntCleanMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ant-plugin/src/main/java/org/apache/maven/plugin/ant/AntCleanMojo.java?rev=764446&r1=764445&r2=764446&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ant-plugin/src/main/java/org/apache/maven/plugin/ant/AntCleanMojo.java (original)
+++ maven/plugins/trunk/maven-ant-plugin/src/main/java/org/apache/maven/plugin/ant/AntCleanMojo.java Mon Apr 13 13:23:39 2009
@@ -20,13 +20,10 @@
*/
import java.io.File;
-import java.io.IOException;
-import java.util.Locale;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
-import org.codehaus.plexus.components.interactivity.InputHandler;
/**
* Clean all Ant build files.
@@ -42,14 +39,6 @@
// Mojo components
// ----------------------------------------------------------------------
- /**
- * Input handler, needed for command line handling.
- *
- * @component
- * @since 2.1.1
- */
- private InputHandler inputHandler;
-
// ----------------------------------------------------------------------
// Mojo parameters
// ----------------------------------------------------------------------
@@ -66,26 +55,32 @@
/**
* Forcing the deletion of the custom <code>build.xml</code>.
*
- * @parameter expression="${force}"
- * @since 2.1.1
- */
- private boolean force;
-
- /**
- * The flag whether Maven is operating in interactive mode or in batch mode.
- *
- * @parameter default-value="${settings.interactiveMode}"
- * @required
- * @readonly
+ * @parameter expression="${deleteCustomFiles}" default-value="false"
* @since 2.1.1
*/
- private boolean interactiveMode;
+ private boolean deleteCustomFiles;
/** {@inheritDoc} */
public void execute()
throws MojoExecutionException
{
- deleteCustomBuild();
+ File buildXml = new File( project.getBasedir(), AntBuildWriter.DEFAULT_BUILD_FILENAME );
+ if ( buildXml.exists() )
+ {
+ if ( deleteCustomFiles )
+ {
+ if ( !buildXml.delete() )
+ {
+ throw new MojoExecutionException( "Cannot delete " + buildXml.getAbsolutePath() );
+ }
+ }
+ else if ( getLog().isInfoEnabled() )
+ {
+ getLog().info(
+ "Not deleting custom " + buildXml.getName()
+ + ", use -DdeleteCustomFiles=true to force its deletion" );
+ }
+ }
File mavenBuildXml = new File( project.getBasedir(), AntBuildWriter.DEFAULT_MAVEN_BUILD_FILENAME );
if ( mavenBuildXml.exists() && !mavenBuildXml.delete() )
@@ -101,98 +96,8 @@
}
getLog().info(
- "Deleted Ant project for " + project.getArtifactId() + " in "
+ "Deleted Ant build files for project " + project.getArtifactId() + " in "
+ project.getBasedir().getAbsolutePath() );
}
- /**
- * Deleting the <code>build.xml</code> depending the user interaction.
- *
- * @throws MojoExecutionException if any
- */
- private void deleteCustomBuild()
- throws MojoExecutionException
- {
- // add warranty msg
- if ( !preCheck() )
- {
- return;
- }
-
- File buildXml = new File( project.getBasedir(), AntBuildWriter.DEFAULT_BUILD_FILENAME );
- if ( buildXml.exists() && !buildXml.delete() )
- {
- throw new MojoExecutionException( "Cannot delete " + buildXml.getAbsolutePath() );
- }
- }
-
- /**
- * @return <code>true</code> if the user wants to proceed, <code>false</code> otherwise.
- * @throws MojoExecutionException if any
- */
- private boolean preCheck()
- throws MojoExecutionException
- {
- if ( force )
- {
- return true;
- }
-
- if ( !interactiveMode )
- {
- if ( getLog().isErrorEnabled() )
- {
- getLog().error(
- "Maven is not attempt to interact with the user for input. "
- + "Verify the <interactiveMode/> configuration in your settings." );
- }
- return false;
- }
-
- if ( getLog().isWarnEnabled() )
- {
- getLog().warn( "" );
- getLog().warn( " WARRANTY DISCLAIMER" );
- getLog().warn( "" );
- getLog().warn( "This Maven goal will delete your build.xml." );
- getLog().warn( "" );
- }
-
- while ( true )
- {
- if ( getLog().isInfoEnabled() )
- {
- getLog().info( "Are you sure to proceed? [Y]es [N]o" );
- }
-
- try
- {
- String userExpression = inputHandler.readLine();
- if ( userExpression == null || userExpression.toLowerCase( Locale.ENGLISH ).equalsIgnoreCase( "Y" )
- || userExpression.toLowerCase( Locale.ENGLISH ).equalsIgnoreCase( "Yes" ) )
- {
- if ( getLog().isInfoEnabled() )
- {
- getLog().info( "OK, let's proceed..." );
- }
- break;
- }
- if ( userExpression == null || userExpression.toLowerCase( Locale.ENGLISH ).equalsIgnoreCase( "N" )
- || userExpression.toLowerCase( Locale.ENGLISH ).equalsIgnoreCase( "No" ) )
- {
- if ( getLog().isInfoEnabled() )
- {
- getLog().info( "No changes on the build.xml occur." );
- }
- return false;
- }
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Unable to read from standard input.", e );
- }
- }
-
- return true;
- }
}