You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2017/12/20 09:28:52 UTC
[maven-ant-plugin] 11/18: [MANT-47] ant:clean should not delete
build.xml
This is an automated email from the ASF dual-hosted git repository.
hboutemy pushed a commit to annotated tag maven-ant-plugin-2.2
in repository https://gitbox.apache.org/repos/asf/maven-ant-plugin.git
commit 699f253239a18ed66675f716de9346a3b6f9dc5e
Author: Benjamin Bentmann <be...@apache.org>
AuthorDate: Mon Apr 13 13:23:39 2009 +0000
[MANT-47] ant:clean should not delete build.xml
o Updated solution after dicussion on IRC
o Added ITs
git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-ant-plugin@764446 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 10 --
src/it/clean-custom-files/invoker.properties | 1 +
src/it/clean-custom-files/pom.xml | 21 ++++
src/it/clean-custom-files/test.properties | 1 +
src/it/clean-custom-files/verify.bsh | 14 +++
src/it/clean/invoker.properties | 1 +
src/it/clean/pom.xml | 21 ++++
src/it/clean/verify.bsh | 14 +++
.../org/apache/maven/plugin/ant/AntCleanMojo.java | 135 +++------------------
9 files changed, 93 insertions(+), 125 deletions(-)
diff --git a/pom.xml b/pom.xml
index 59b05b7..d677ad2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -100,16 +100,6 @@ under the License.
<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>
diff --git a/src/it/clean-custom-files/invoker.properties b/src/it/clean-custom-files/invoker.properties
new file mode 100644
index 0000000..7f7a135
--- /dev/null
+++ b/src/it/clean-custom-files/invoker.properties
@@ -0,0 +1 @@
+invoker.goals = clean ant:ant ant:clean
diff --git a/src/it/clean-custom-files/pom.xml b/src/it/clean-custom-files/pom.xml
new file mode 100644
index 0000000..4b23a60
--- /dev/null
+++ b/src/it/clean-custom-files/pom.xml
@@ -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>
diff --git a/src/it/clean-custom-files/test.properties b/src/it/clean-custom-files/test.properties
new file mode 100644
index 0000000..bb54a0b
--- /dev/null
+++ b/src/it/clean-custom-files/test.properties
@@ -0,0 +1 @@
+deleteCustomFiles = true
diff --git a/src/it/clean-custom-files/verify.bsh b/src/it/clean-custom-files/verify.bsh
new file mode 100644
index 0000000..cc8855b
--- /dev/null
+++ b/src/it/clean-custom-files/verify.bsh
@@ -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;
diff --git a/src/it/clean/invoker.properties b/src/it/clean/invoker.properties
new file mode 100644
index 0000000..7f7a135
--- /dev/null
+++ b/src/it/clean/invoker.properties
@@ -0,0 +1 @@
+invoker.goals = clean ant:ant ant:clean
diff --git a/src/it/clean/pom.xml b/src/it/clean/pom.xml
new file mode 100644
index 0000000..65b0386
--- /dev/null
+++ b/src/it/clean/pom.xml
@@ -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>
diff --git a/src/it/clean/verify.bsh b/src/it/clean/verify.bsh
new file mode 100644
index 0000000..422dab6
--- /dev/null
+++ b/src/it/clean/verify.bsh
@@ -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;
diff --git a/src/main/java/org/apache/maven/plugin/ant/AntCleanMojo.java b/src/main/java/org/apache/maven/plugin/ant/AntCleanMojo.java
index ed29464..c55f356 100644
--- a/src/main/java/org/apache/maven/plugin/ant/AntCleanMojo.java
+++ b/src/main/java/org/apache/maven/plugin/ant/AntCleanMojo.java
@@ -20,13 +20,10 @@ package org.apache.maven.plugin.ant;
*/
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 @@ public class AntCleanMojo
// Mojo components
// ----------------------------------------------------------------------
- /**
- * Input handler, needed for command line handling.
- *
- * @component
- * @since 2.1.1
- */
- private InputHandler inputHandler;
-
// ----------------------------------------------------------------------
// Mojo parameters
// ----------------------------------------------------------------------
@@ -66,26 +55,32 @@ public class AntCleanMojo
/**
* 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 @@ public class AntCleanMojo
}
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;
- }
}
--
To stop receiving notification emails like this one, please contact
"commits@maven.apache.org" <co...@maven.apache.org>.