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
Show file tree
Hide file tree
Changes from 2 commits
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
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

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
Expand Up @@ -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")
slawekjaranowski marked this conversation as resolved.
Show resolved Hide resolved
private boolean skip;

/**
* The constructor.
*/
Expand Down Expand Up @@ -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
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,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.
*/
Expand All @@ -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()) {
Expand All @@ -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
Expand Up @@ -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;

Expand Down Expand Up @@ -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() + "...");

Expand All @@ -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.
*
Expand Down