Skip to content

Commit 100e329

Browse files
committed
added flag clean all to clean whole folder
1 parent 1d5ba2e commit 100e329

File tree

1 file changed

+25
-2
lines changed
  • jbbp-plugins/jbbp-maven/jbbp-maven-plugin/src/main/java/com/igormaznitsa/jbbp/plugin/mvn

1 file changed

+25
-2
lines changed

jbbp-plugins/jbbp-maven/jbbp-maven-plugin/src/main/java/com/igormaznitsa/jbbp/plugin/mvn/JBBPCleanMojo.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import com.igormaznitsa.jbbp.plugin.common.converters.JBBPScriptTranslator;
44
import com.igormaznitsa.jbbp.plugin.common.converters.Target;
5+
import org.apache.commons.io.FileUtils;
56
import org.apache.maven.plugin.MojoExecutionException;
67
import org.apache.maven.plugin.MojoFailureException;
78
import org.apache.maven.plugins.annotations.LifecyclePhase;
89
import org.apache.maven.plugins.annotations.Mojo;
10+
import org.apache.maven.plugins.annotations.Parameter;
911

1012
import java.io.File;
1113
import java.io.IOException;
@@ -19,8 +21,29 @@
1921
@Mojo(name = "clean", defaultPhase = LifecyclePhase.CLEAN, threadSafe = true)
2022
public class JBBPCleanMojo extends AbstractJBBPMojo {
2123

24+
/**
25+
* Clean whole target folder.
26+
*/
27+
@Parameter(alias = "cleanAll", defaultValue = "false")
28+
private boolean cleanAll;
29+
30+
2231
@Override
2332
public void executeMojo() throws MojoExecutionException, MojoFailureException {
33+
if (this.cleanAll) {
34+
getLog().debug("Clean whole folder : " + this.output);
35+
if (this.output.isDirectory()) {
36+
try {
37+
FileUtils.cleanDirectory(this.output);
38+
} catch (IOException ex) {
39+
throw new MojoExecutionException("Can't clean folder : " + this.output, ex);
40+
}
41+
} else {
42+
getLog().info("Can't find output folder : " + this.output);
43+
}
44+
return;
45+
}
46+
2447
final Set<File> scripts = findSources(this.output);
2548
if (checkSetNonEmptyWithLogging(scripts)) {
2649
int counter = 0;
@@ -36,8 +59,8 @@ public void executeMojo() throws MojoExecutionException, MojoFailureException {
3659
final Set<File> files;
3760
try {
3861
files = target.getTranslator().translate(parameters, true);
39-
}catch (IOException ex){
40-
throw new MojoExecutionException("Error during form file set",ex);
62+
} catch (IOException ex) {
63+
throw new MojoExecutionException("Error during form file set", ex);
4164
}
4265

4366
for (final File f : files) {

0 commit comments

Comments
 (0)