Skip to content

Commit

Permalink
Add skip flags (#186)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
hgschmie and slawekjaranowski authored Nov 19, 2023
1 parent 2237441 commit b49b7e6
Show file tree
Hide file tree
Showing 17 changed files with 248 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/it/add-resource-skip/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals = -X generate-sources
invoker.buildResult = success
36 changes: 36 additions & 0 deletions src/it/add-resource-skip/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<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>build-helper</groupId>
<artifactId>integration-test</artifactId>
<version>1.0-SNAPSHOT</version>

<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>integration-test</id>
<phase>generate-sources</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${project.basedir}/not-existing</directory>
<targetPath>does-not-matter</targetPath>
</resource>
</resources>
<skipAddResource>true</skipAddResource>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
9 changes: 9 additions & 0 deletions src/it/add-resource-skip/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
File file = new File( basedir, "build.log" );
assert file.exists();

String text = file.getText("utf-8");

assert text.contains("skipAddResource = true");
assert text.contains("Skipping plugin execution!");

return true;
2 changes: 2 additions & 0 deletions src/it/add-source-skip/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals = -X generate-sources
invoker.buildResult = success
33 changes: 33 additions & 0 deletions src/it/add-source-skip/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<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>build-helper</groupId>
<artifactId>integration-test</artifactId>
<version>1.0-SNAPSHOT</version>

<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>integration-test</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.basedir}/not-existing</source>
</sources>
<skipAddSource>true</skipAddSource>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
9 changes: 9 additions & 0 deletions src/it/add-source-skip/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
File file = new File( basedir, "build.log" );
assert file.exists();

String text = file.getText("utf-8");

assert text.contains("skipAddSource = true");
assert text.contains("Skipping plugin execution!");

return true;
2 changes: 2 additions & 0 deletions src/it/add-test-resource-skip/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals = -X generate-sources
invoker.buildResult = success
36 changes: 36 additions & 0 deletions src/it/add-test-resource-skip/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<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>build-helper</groupId>
<artifactId>integration-test</artifactId>
<version>1.0-SNAPSHOT</version>

<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>integration-test</id>
<phase>generate-sources</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${project.basedir}/not-existing</directory>
<targetPath>does-not-matter</targetPath>
</resource>
</resources>
<skipAddTestResource>true</skipAddTestResource>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
9 changes: 9 additions & 0 deletions src/it/add-test-resource-skip/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
File file = new File( basedir, "build.log" );
assert file.exists();

String text = file.getText("utf-8");

assert text.contains("skipAddTestResource = true");
assert text.contains("Skipping plugin execution!");

return true;
2 changes: 2 additions & 0 deletions src/it/add-test-source-skip/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals = -X generate-sources
invoker.buildResult = success
33 changes: 33 additions & 0 deletions src/it/add-test-source-skip/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<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>build-helper</groupId>
<artifactId>integration-test</artifactId>
<version>1.0-SNAPSHOT</version>

<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>integration-test</id>
<phase>generate-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>${project.basedir}/not-existing</source>
</sources>
<skipAddTestSource>true</skipAddTestSource>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
9 changes: 9 additions & 0 deletions src/it/add-test-source-skip/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
File file = new File( basedir, "build.log" );
assert file.exists();

String text = file.getText("utf-8");

assert text.contains("skipAddTestSource = true");
assert text.contains("Skipping plugin execution!");

return true;
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ public abstract class AbstractAddResourceMojo extends AbstractMojo {
* Main plugin execution
*/
public void execute() {
if (isSkip()) {
if (getLog().isInfoEnabled()) {
getLog().info("Skipping plugin execution!");
}
return;
}

for (Resource resource : resources) {
// Check for relative paths in the resource configuration.
// http://maven.apache.org/plugin-developers/common-bugs.html#Resolving_Relative_Paths
Expand All @@ -64,6 +71,8 @@ public void execute() {
}
}

protected abstract boolean isSkip();

/**
* Add the resource to the project.
*
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/codehaus/mojo/buildhelper/AddResourceMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.maven.model.Resource;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

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

/**
* Skip plugin execution.
*
* @since 3.5.0
*/
@Parameter(property = "buildhelper.addresource.skip", defaultValue = "false")
private boolean skipAddResource;

public void addResource(Resource resource) {
getProject().addResource(resource);
if (getLog().isDebugEnabled()) {
getLog().debug("Added resource: " + resource.getDirectory());
}
}

protected boolean isSkip() {
return skipAddResource;
}
}
15 changes: 15 additions & 0 deletions src/main/java/org/codehaus/mojo/buildhelper/AddSourceMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,22 @@ public class AddSourceMojo extends AbstractMojo {
@Parameter(readonly = true, defaultValue = "${project}")
private MavenProject project;

/**
* Skip plugin execution.
*
* @since 3.5.0
*/
@Parameter(property = "buildhelper.addsource.skip", defaultValue = "false")
private boolean skipAddSource;

public void execute() {
if (skipAddSource) {
if (getLog().isInfoEnabled()) {
getLog().info("Skipping plugin execution!");
}
return;
}

for (File source : sources) {
this.project.addCompileSourceRoot(source.getAbsolutePath());
if (getLog().isInfoEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.maven.model.Resource;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

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

/**
* Skip plugin execution.
*
* @since 3.5.0
*/
@Parameter(property = "buildhelper.addtestresource.skip", defaultValue = "false")
private boolean skipAddTestResource;

/**
* Add the resource to the project.
*
Expand All @@ -48,4 +57,9 @@ public void addResource(Resource resource) {
getLog().debug("Added test resource: " + resource.getDirectory());
}
}

@Override
protected boolean isSkip() {
return skipAddTestResource;
}
}
15 changes: 15 additions & 0 deletions src/main/java/org/codehaus/mojo/buildhelper/AddTestSourceMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,22 @@ public class AddTestSourceMojo extends AbstractMojo {
@Parameter(readonly = true, defaultValue = "${project}")
private MavenProject project;

/**
* Skip plugin execution.
*
* @since 3.5.0
*/
@Parameter(property = "buildhelper.addtestsource.skip", defaultValue = "false")
private boolean skipAddTestSource;

public void execute() {
if (skipAddTestSource) {
if (getLog().isInfoEnabled()) {
getLog().info("Skipping plugin execution!");
}
return;
}

for (File source : sources) {
this.project.addTestCompileSourceRoot(source.getAbsolutePath());
if (getLog().isInfoEnabled()) {
Expand Down

0 comments on commit b49b7e6

Please sign in to comment.