Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AntCleanMojo |
|
| 12.0;12 |
1 | package org.apache.maven.plugin.ant; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import java.io.File; | |
23 | ||
24 | import org.apache.maven.plugin.AbstractMojo; | |
25 | import org.apache.maven.plugin.MojoExecutionException; | |
26 | import org.apache.maven.project.MavenProject; | |
27 | ||
28 | /** | |
29 | * Clean all Ant build files. | |
30 | * | |
31 | * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a> | |
32 | * @version $Id: AntCleanMojo.java 764451 2009-04-13 13:29:52Z bentmann $ | |
33 | * @goal clean | |
34 | */ | |
35 | 0 | public class AntCleanMojo |
36 | extends AbstractMojo | |
37 | { | |
38 | // ---------------------------------------------------------------------- | |
39 | // Mojo components | |
40 | // ---------------------------------------------------------------------- | |
41 | ||
42 | // ---------------------------------------------------------------------- | |
43 | // Mojo parameters | |
44 | // ---------------------------------------------------------------------- | |
45 | ||
46 | /** | |
47 | * The working project. | |
48 | * | |
49 | * @parameter default-value="${project}" | |
50 | * @required | |
51 | * @readonly | |
52 | */ | |
53 | private MavenProject project; | |
54 | ||
55 | /** | |
56 | * Forcing the deletion of the custom <code>build.xml</code>. | |
57 | * | |
58 | * @parameter expression="${deleteCustomFiles}" default-value="false" | |
59 | * @since 2.2 | |
60 | */ | |
61 | private boolean deleteCustomFiles; | |
62 | ||
63 | /** {@inheritDoc} */ | |
64 | public void execute() | |
65 | throws MojoExecutionException | |
66 | { | |
67 | 0 | File buildXml = new File( project.getBasedir(), AntBuildWriter.DEFAULT_BUILD_FILENAME ); |
68 | 0 | if ( buildXml.exists() ) |
69 | { | |
70 | 0 | if ( deleteCustomFiles ) |
71 | { | |
72 | 0 | if ( !buildXml.delete() ) |
73 | { | |
74 | 0 | throw new MojoExecutionException( "Cannot delete " + buildXml.getAbsolutePath() ); |
75 | } | |
76 | } | |
77 | 0 | else if ( getLog().isInfoEnabled() ) |
78 | { | |
79 | 0 | getLog().info( |
80 | "Not deleting custom " + buildXml.getName() | |
81 | + ", use -DdeleteCustomFiles=true to force its deletion" ); | |
82 | } | |
83 | } | |
84 | ||
85 | 0 | File mavenBuildXml = new File( project.getBasedir(), AntBuildWriter.DEFAULT_MAVEN_BUILD_FILENAME ); |
86 | 0 | if ( mavenBuildXml.exists() && !mavenBuildXml.delete() ) |
87 | { | |
88 | 0 | throw new MojoExecutionException( "Cannot delete " + mavenBuildXml.getAbsolutePath() ); |
89 | } | |
90 | ||
91 | 0 | File mavenBuildProperties = |
92 | new File( project.getBasedir(), AntBuildWriter.DEFAULT_MAVEN_PROPERTIES_FILENAME ); | |
93 | 0 | if ( mavenBuildProperties.exists() && !mavenBuildProperties.delete() ) |
94 | { | |
95 | 0 | throw new MojoExecutionException( "Cannot delete " + mavenBuildProperties.getAbsolutePath() ); |
96 | } | |
97 | ||
98 | 0 | getLog().info( |
99 | "Deleted Ant build files for project " + project.getArtifactId() + " in " | |
100 | + project.getBasedir().getAbsolutePath() ); | |
101 | 0 | } |
102 | ||
103 | } |