Skip to content

Commit

Permalink
Add skip flags (#385)
Browse files Browse the repository at this point in the history
* Add skip flags

This introduces 3 flags:
- `flatten.skip`: skips the entire plugin regardless of goal
- `flatten.clean.skip`: skips the clean goal
- `flatten.flatten.skip`: skips the flatten goal

This means the user has control over what parts are skipped, and the
flags are descriptive. The `flatten.` prefix is in line with other
parameters like `flatten.mode` and `flatten.dependency.mode`.

* Test skip flags

This adds 3 ITs for the skip flags:
- to verify `skip` -> should not create/remove flattened pom
- to verify `skipFlatten` -> should not create flattened pom
- to verify `skipClean` -> should not remove flattened pom

* Prepare for 1.6.0 release

* Annotate skip flags as since 1.6.0

This is the release in which they'll be first available.
  • Loading branch information
korthout authored Nov 29, 2023
1 parent 2eb7e13 commit 8bb80b3
Show file tree
Hide file tree
Showing 12 changed files with 248 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</parent>

<artifactId>flatten-maven-plugin</artifactId>
<version>1.5.1-SNAPSHOT</version>
<version>1.6.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<name>Maven Flatten Plugin</name>
Expand Down
16 changes: 16 additions & 0 deletions src/it/projects/clean-skip/.flattened-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>resolve-properties</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>dep</artifactId>
<version>1.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
29 changes: 29 additions & 0 deletions src/it/projects/clean-skip/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>flatten-skip</artifactId>
<version>0.0.1-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>dep</artifactId>
<version>1.1</version>
</dependency>
</dependencies>

<build>
<defaultGoal>verify</defaultGoal>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<skipClean>true</skipClean>
</configuration>
</plugin>
</plugins>
</build>
</project>
24 changes: 24 additions & 0 deletions src/it/projects/clean-skip/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

// Clean mojo is skipped so we should expect flattened pom to still exist
File flattendPom = new File( basedir, '.flattened-pom.xml' )
assert flattendPom.exists()


29 changes: 29 additions & 0 deletions src/it/projects/flatten-skip/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>flatten-skip</artifactId>
<version>0.0.1-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>dep</artifactId>
<version>1.1</version>
</dependency>
</dependencies>

<build>
<defaultGoal>verify</defaultGoal>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
24 changes: 24 additions & 0 deletions src/it/projects/flatten-skip/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

// Flatten mojo is skipped so we should expect no flattened pom
File flattendPom = new File( basedir, '.flattened-pom.xml' )
assert !flattendPom.exists()


16 changes: 16 additions & 0 deletions src/it/projects/skip/.flattened-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>resolve-properties</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>dep</artifactId>
<version>1.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
29 changes: 29 additions & 0 deletions src/it/projects/skip/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>flatten-skip</artifactId>
<version>0.0.1-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>dep</artifactId>
<version>1.1</version>
</dependency>
</dependencies>

<build>
<defaultGoal>verify</defaultGoal>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
28 changes: 28 additions & 0 deletions src/it/projects/skip/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

// Flatten plugin is skipped so we should expect that the flattened
// pom is not removed by the clean mojo, and not newly created by the
// flatten mojo, i.e. it is left unchanged. We can check this by
// asserting it was last modified before starting to run this test
File flattendPom = new File( basedir, '.flattened-pom.xml' )
assert flattendPom.exists()
long now = System.currentTimeMillis()
assert now - flattendPom.lastModified() > 20*1000

17 changes: 17 additions & 0 deletions src/main/java/org/codehaus/mojo/flatten/AbstractFlattenMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ public abstract class AbstractFlattenMojo extends AbstractMojo {
@Parameter(property = "flattenedPomFilename", defaultValue = ".flattened-pom.xml")
private String flattenedPomFilename;

/**
* If {@code true} the plugin will be skipped.
*
* @since 1.6.0
*/
@Parameter(property = "flatten.skip", defaultValue = "false")
private boolean skip;

/**
* The constructor.
*/
Expand Down Expand Up @@ -71,4 +79,13 @@ public File getOutputDirectory() {
protected File getFlattenedPomFile() {
return new File(getOutputDirectory(), getFlattenedPomFilename());
}

protected boolean shouldSkip() {
if (skip) {
return true;
}
return shouldSkipGoal();
}

protected abstract boolean shouldSkipGoal();
}
18 changes: 18 additions & 0 deletions src/main/java/org/codehaus/mojo/flatten/CleanMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

/**
* This MOJO realizes the goal <code>flatten:clean</code> that deletes any files created by
Expand All @@ -42,6 +43,14 @@
threadSafe = true)
public class CleanMojo extends AbstractFlattenMojo {

/**
* If {@code true} the clean goal will be skipped.
*
* @since 1.6.0
*/
@Parameter(property = "flatten.clean.skip", defaultValue = "false")
private boolean skipClean;

/**
* The constructor.
*/
Expand All @@ -53,6 +62,10 @@ public CleanMojo() {
* {@inheritDoc}
*/
public void execute() throws MojoExecutionException, MojoFailureException {
if (shouldSkip()) {
getLog().info("Clean skipped.");
return;
}

File flattenedPomFile = getFlattenedPomFile();
if (flattenedPomFile.isFile()) {
Expand All @@ -63,4 +76,9 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
}
}

@Override
protected boolean shouldSkipGoal() {
return skipClean;
}
}
17 changes: 17 additions & 0 deletions src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,14 @@ public class FlattenMojo extends AbstractFlattenMojo {
@Parameter(property = "flatten.dependency.keepComments", required = false, defaultValue = "false")
private boolean keepCommentsInPom;

/**
* If {@code true} the flatten goal will be skipped.
*
* @since 1.6.0
*/
@Parameter(property = "flatten.flatten.skip", defaultValue = "false")
private boolean skipFlatten;

@Inject
private DirectDependenciesInheritanceAssembler inheritanceAssembler;

Expand Down Expand Up @@ -400,6 +408,10 @@ public FlattenMojo() {
*/
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (shouldSkip()) {
getLog().info("Flatten skipped.");
return;
}

getLog().info("Generating flattened POM of project " + this.project.getId() + "...");

Expand All @@ -422,6 +434,11 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
}

@Override
protected boolean shouldSkipGoal() {
return skipFlatten;
}

/**
* This method extracts the XML header comment if available.
*
Expand Down

0 comments on commit 8bb80b3

Please sign in to comment.