Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add skip flags #385

Merged
merged 4 commits into from
Nov 29, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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`.
  • Loading branch information
korthout committed Nov 21, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 551d9a2fd65ca1f1236b8797b88524e6f75bc9bb
15 changes: 15 additions & 0 deletions src/main/java/org/codehaus/mojo/flatten/AbstractFlattenMojo.java
Original file line number Diff line number Diff line change
@@ -43,6 +43,12 @@ public abstract class AbstractFlattenMojo extends AbstractMojo {
@Parameter(property = "flattenedPomFilename", defaultValue = ".flattened-pom.xml")
private String flattenedPomFilename;

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

/**
* The constructor.
*/
@@ -71,4 +77,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();
}
16 changes: 16 additions & 0 deletions src/main/java/org/codehaus/mojo/flatten/CleanMojo.java
Original file line number Diff line number Diff line change
@@ -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
@@ -42,6 +43,12 @@
threadSafe = true)
public class CleanMojo extends AbstractFlattenMojo {

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

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

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

@Override
protected boolean shouldSkipGoal() {
return skipClean;
}
}
15 changes: 15 additions & 0 deletions src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java
Original file line number Diff line number Diff line change
@@ -364,6 +364,12 @@ 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.
*/
@Parameter(property = "flatten.flatten.skip", defaultValue = "false")
private boolean skipFlatten;

@Inject
private DirectDependenciesInheritanceAssembler inheritanceAssembler;

@@ -400,6 +406,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() + "...");

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

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

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