-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add configuration option to omit exclusions from flattened POMs
Introduces a new 'omitExclusions' configuration option that is false by default to maintain backwards compatible behaviour. When this new configuration option is explicitly set to true then this will result in the flattened POM omitting all exclusions stanzas from the dependency stanzas. Fixes #288
- Loading branch information
1 parent
9d08ece
commit bfd74cc
Showing
3 changed files
with
156 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/test/java/org/codehaus/mojo/flatten/FlattenMojoOmitExclusionsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package org.codehaus.mojo.flatten; | ||
|
||
import static org.junit.Assert.fail; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
|
||
import org.apache.maven.model.Model; | ||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; | ||
import org.apache.maven.plugin.testing.MojoRule; | ||
import org.apache.maven.project.MavenProject; | ||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; | ||
import org.junit.After; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Test case for the omitexclusions configuration option. | ||
*/ | ||
public class FlattenMojoOmitExclusionsTest { | ||
|
||
private static final String PATH = "src/test/resources/omit-exclusions/"; | ||
private static final String FLATTENED_POM = PATH + ".flattened-pom.xml"; | ||
|
||
@Rule public MojoRule rule = new MojoRule(); | ||
|
||
|
||
/** | ||
* Verify that when the omit exclusions configuration option is set then the | ||
* exclusions stanza of any dependencies is not copied into the flattened | ||
* POM. | ||
*/ | ||
@Test | ||
public void testOmitExclusions() throws Exception { | ||
// -- Given... | ||
// | ||
MavenProject project = rule.readMavenProject( new File( PATH ) ); | ||
FlattenMojo flattenMojo = (FlattenMojo) rule.lookupConfiguredMojo( project, "flatten" ); | ||
|
||
// -- When... | ||
// | ||
flattenMojo.execute(); | ||
|
||
// -- Then... | ||
// | ||
readPom( FLATTENED_POM ) | ||
.getDependencies() | ||
.stream() | ||
.filter(dep -> !dep.getExclusions().isEmpty()) | ||
.findAny() | ||
.ifPresent(dep -> fail("No exclusions should be present in flattened POM.")); | ||
} | ||
|
||
|
||
private static Model readPom(String pomFilePath) throws IOException, XmlPullParserException { | ||
try ( FileInputStream input = new FileInputStream( new File( pomFilePath ) ) ) { | ||
return new MavenXpp3Reader().read( input ); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* After test method. Removes flattened-pom.xml file which is created during test. | ||
* | ||
* @throws IOException if can't remove file. | ||
*/ | ||
@After | ||
public void removeFlattenedPom() throws IOException { | ||
File flattenedPom = new File( FLATTENED_POM ); | ||
if ( flattenedPom.exists() ) { | ||
if ( !flattenedPom.delete() ) { | ||
throw new IOException( "Can't delete " + flattenedPom ); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.codehaus.mojo.flatten.its</groupId> | ||
<!-- https://github.com/mojohaus/flatten-maven-plugin/issues/288 --> | ||
<artifactId>omit-exclusions</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<dependencies> | ||
<dependency> | ||
<groupId>groupA</groupId> | ||
<artifactId>artifactB</artifactId> | ||
<version>1</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>groupX</groupId> | ||
<artifactId>artifactY</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>group1</groupId> | ||
<artifactId>artifact2</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<defaultGoal>verify</defaultGoal> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>flatten-maven-plugin</artifactId> | ||
<configuration> | ||
<omitExclusions>true</omitExclusions> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |