Skip to content

Commit b49b7e6

Browse files
Add skip flags (#186)
* Add skip flags - build-helper:add-source - build-helper:add-test-source - build-helper:add-resource - build-helper:add-test-resource --------- Co-authored-by: Slawomir Jaranowski <[email protected]>
1 parent 2237441 commit b49b7e6

File tree

17 files changed

+248
-0
lines changed

17 files changed

+248
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
invoker.goals = -X generate-sources
2+
invoker.buildResult = success

src/it/add-resource-skip/pom.xml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<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">
2+
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>build-helper</groupId>
6+
<artifactId>integration-test</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
9+
<build>
10+
<plugins>
11+
<plugin>
12+
<groupId>@project.groupId@</groupId>
13+
<artifactId>@project.artifactId@</artifactId>
14+
<version>@project.version@</version>
15+
<executions>
16+
<execution>
17+
<id>integration-test</id>
18+
<phase>generate-sources</phase>
19+
<goals>
20+
<goal>add-resource</goal>
21+
</goals>
22+
<configuration>
23+
<resources>
24+
<resource>
25+
<directory>${project.basedir}/not-existing</directory>
26+
<targetPath>does-not-matter</targetPath>
27+
</resource>
28+
</resources>
29+
<skipAddResource>true</skipAddResource>
30+
</configuration>
31+
</execution>
32+
</executions>
33+
</plugin>
34+
</plugins>
35+
</build>
36+
</project>
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
File file = new File( basedir, "build.log" );
2+
assert file.exists();
3+
4+
String text = file.getText("utf-8");
5+
6+
assert text.contains("skipAddResource = true");
7+
assert text.contains("Skipping plugin execution!");
8+
9+
return true;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
invoker.goals = -X generate-sources
2+
invoker.buildResult = success

src/it/add-source-skip/pom.xml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<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">
2+
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>build-helper</groupId>
6+
<artifactId>integration-test</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
9+
<build>
10+
<plugins>
11+
<plugin>
12+
<groupId>@project.groupId@</groupId>
13+
<artifactId>@project.artifactId@</artifactId>
14+
<version>@project.version@</version>
15+
<executions>
16+
<execution>
17+
<id>integration-test</id>
18+
<phase>generate-sources</phase>
19+
<goals>
20+
<goal>add-source</goal>
21+
</goals>
22+
<configuration>
23+
<sources>
24+
<source>${project.basedir}/not-existing</source>
25+
</sources>
26+
<skipAddSource>true</skipAddSource>
27+
</configuration>
28+
</execution>
29+
</executions>
30+
</plugin>
31+
</plugins>
32+
</build>
33+
</project>

src/it/add-source-skip/verify.groovy

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
File file = new File( basedir, "build.log" );
2+
assert file.exists();
3+
4+
String text = file.getText("utf-8");
5+
6+
assert text.contains("skipAddSource = true");
7+
assert text.contains("Skipping plugin execution!");
8+
9+
return true;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
invoker.goals = -X generate-sources
2+
invoker.buildResult = success

src/it/add-test-resource-skip/pom.xml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<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">
2+
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>build-helper</groupId>
6+
<artifactId>integration-test</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
9+
<build>
10+
<plugins>
11+
<plugin>
12+
<groupId>@project.groupId@</groupId>
13+
<artifactId>@project.artifactId@</artifactId>
14+
<version>@project.version@</version>
15+
<executions>
16+
<execution>
17+
<id>integration-test</id>
18+
<phase>generate-sources</phase>
19+
<goals>
20+
<goal>add-test-resource</goal>
21+
</goals>
22+
<configuration>
23+
<resources>
24+
<resource>
25+
<directory>${project.basedir}/not-existing</directory>
26+
<targetPath>does-not-matter</targetPath>
27+
</resource>
28+
</resources>
29+
<skipAddTestResource>true</skipAddTestResource>
30+
</configuration>
31+
</execution>
32+
</executions>
33+
</plugin>
34+
</plugins>
35+
</build>
36+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
File file = new File( basedir, "build.log" );
2+
assert file.exists();
3+
4+
String text = file.getText("utf-8");
5+
6+
assert text.contains("skipAddTestResource = true");
7+
assert text.contains("Skipping plugin execution!");
8+
9+
return true;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
invoker.goals = -X generate-sources
2+
invoker.buildResult = success

src/it/add-test-source-skip/pom.xml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<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">
2+
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>build-helper</groupId>
6+
<artifactId>integration-test</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
9+
<build>
10+
<plugins>
11+
<plugin>
12+
<groupId>@project.groupId@</groupId>
13+
<artifactId>@project.artifactId@</artifactId>
14+
<version>@project.version@</version>
15+
<executions>
16+
<execution>
17+
<id>integration-test</id>
18+
<phase>generate-sources</phase>
19+
<goals>
20+
<goal>add-test-source</goal>
21+
</goals>
22+
<configuration>
23+
<sources>
24+
<source>${project.basedir}/not-existing</source>
25+
</sources>
26+
<skipAddTestSource>true</skipAddTestSource>
27+
</configuration>
28+
</execution>
29+
</executions>
30+
</plugin>
31+
</plugins>
32+
</build>
33+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
File file = new File( basedir, "build.log" );
2+
assert file.exists();
3+
4+
String text = file.getText("utf-8");
5+
6+
assert text.contains("skipAddTestSource = true");
7+
assert text.contains("Skipping plugin execution!");
8+
9+
return true;

src/main/java/org/codehaus/mojo/buildhelper/AbstractAddResourceMojo.java

+9
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ public abstract class AbstractAddResourceMojo extends AbstractMojo {
5151
* Main plugin execution
5252
*/
5353
public void execute() {
54+
if (isSkip()) {
55+
if (getLog().isInfoEnabled()) {
56+
getLog().info("Skipping plugin execution!");
57+
}
58+
return;
59+
}
60+
5461
for (Resource resource : resources) {
5562
// Check for relative paths in the resource configuration.
5663
// http://maven.apache.org/plugin-developers/common-bugs.html#Resolving_Relative_Paths
@@ -64,6 +71,8 @@ public void execute() {
6471
}
6572
}
6673

74+
protected abstract boolean isSkip();
75+
6776
/**
6877
* Add the resource to the project.
6978
*

src/main/java/org/codehaus/mojo/buildhelper/AddResourceMojo.java

+13
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.maven.model.Resource;
2828
import org.apache.maven.plugins.annotations.LifecyclePhase;
2929
import org.apache.maven.plugins.annotations.Mojo;
30+
import org.apache.maven.plugins.annotations.Parameter;
3031

3132
/**
3233
* Add more resource directories to the POM.
@@ -37,10 +38,22 @@
3738
@Mojo(name = "add-resource", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, threadSafe = true)
3839
public class AddResourceMojo extends AbstractAddResourceMojo {
3940

41+
/**
42+
* Skip plugin execution.
43+
*
44+
* @since 3.5.0
45+
*/
46+
@Parameter(property = "buildhelper.addresource.skip", defaultValue = "false")
47+
private boolean skipAddResource;
48+
4049
public void addResource(Resource resource) {
4150
getProject().addResource(resource);
4251
if (getLog().isDebugEnabled()) {
4352
getLog().debug("Added resource: " + resource.getDirectory());
4453
}
4554
}
55+
56+
protected boolean isSkip() {
57+
return skipAddResource;
58+
}
4659
}

src/main/java/org/codehaus/mojo/buildhelper/AddSourceMojo.java

+15
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,22 @@ public class AddSourceMojo extends AbstractMojo {
5454
@Parameter(readonly = true, defaultValue = "${project}")
5555
private MavenProject project;
5656

57+
/**
58+
* Skip plugin execution.
59+
*
60+
* @since 3.5.0
61+
*/
62+
@Parameter(property = "buildhelper.addsource.skip", defaultValue = "false")
63+
private boolean skipAddSource;
64+
5765
public void execute() {
66+
if (skipAddSource) {
67+
if (getLog().isInfoEnabled()) {
68+
getLog().info("Skipping plugin execution!");
69+
}
70+
return;
71+
}
72+
5873
for (File source : sources) {
5974
this.project.addCompileSourceRoot(source.getAbsolutePath());
6075
if (getLog().isInfoEnabled()) {

src/main/java/org/codehaus/mojo/buildhelper/AddTestResourceMojo.java

+14
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.maven.model.Resource;
2828
import org.apache.maven.plugins.annotations.LifecyclePhase;
2929
import org.apache.maven.plugins.annotations.Mojo;
30+
import org.apache.maven.plugins.annotations.Parameter;
3031

3132
/**
3233
* Add more test resource directories to the POM.
@@ -37,6 +38,14 @@
3738
@Mojo(name = "add-test-resource", defaultPhase = LifecyclePhase.GENERATE_TEST_RESOURCES, threadSafe = true)
3839
public class AddTestResourceMojo extends AbstractAddResourceMojo {
3940

41+
/**
42+
* Skip plugin execution.
43+
*
44+
* @since 3.5.0
45+
*/
46+
@Parameter(property = "buildhelper.addtestresource.skip", defaultValue = "false")
47+
private boolean skipAddTestResource;
48+
4049
/**
4150
* Add the resource to the project.
4251
*
@@ -48,4 +57,9 @@ public void addResource(Resource resource) {
4857
getLog().debug("Added test resource: " + resource.getDirectory());
4958
}
5059
}
60+
61+
@Override
62+
protected boolean isSkip() {
63+
return skipAddTestResource;
64+
}
5165
}

src/main/java/org/codehaus/mojo/buildhelper/AddTestSourceMojo.java

+15
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,22 @@ public class AddTestSourceMojo extends AbstractMojo {
5454
@Parameter(readonly = true, defaultValue = "${project}")
5555
private MavenProject project;
5656

57+
/**
58+
* Skip plugin execution.
59+
*
60+
* @since 3.5.0
61+
*/
62+
@Parameter(property = "buildhelper.addtestsource.skip", defaultValue = "false")
63+
private boolean skipAddTestSource;
64+
5765
public void execute() {
66+
if (skipAddTestSource) {
67+
if (getLog().isInfoEnabled()) {
68+
getLog().info("Skipping plugin execution!");
69+
}
70+
return;
71+
}
72+
5873
for (File source : sources) {
5974
this.project.addTestCompileSourceRoot(source.getAbsolutePath());
6075
if (getLog().isInfoEnabled()) {

0 commit comments

Comments
 (0)