Skip to content

Flatten maven plugin 1.1.x #102

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
<artifactId>flatten-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<name>Maven Flatten Plugin</name>
<version>1.2.0-SNAPSHOT</version>
<!-- Custom patch to org.codehaus.mojo:flatten-maven-plugin:1.1.0
For more details please see "git diff flatten-maven-plugin-1.1.0 flatten-maven-plugin-1.1.x"
or visit https://github.com/nruzic/flatten-maven-plugin -->
<version>1.1.0.2</version>
<description>Plugin to generate flattened POM (reduced and resolved information required for consumers of maven repositories) and to use (install, sign, deploy) it instead of original pom.xml.</description>
<inceptionYear>2014</inceptionYear>
<prerequisites>
Expand Down
19 changes: 19 additions & 0 deletions src/it/projects/complete-multimodule-parent-pom-cifriendly/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<artifactId>flatten-maven-plugin</artifactId>
<configuration>
<flattenMode>resolveCiFriendliesOnly</flattenMode>
<!-- Use this instead to fix interpolation bug
<flattenMode>version</flattenMode>-->
</configuration>
</plugin>
</plugins>
Expand Down Expand Up @@ -100,6 +102,8 @@
<revision>1.2.3.0</revision>

<key>value</key>
<repoHost>foo</repoHost>
<repoPath>bar</repoPath>
</properties>

<reporting>
Expand All @@ -114,4 +118,19 @@

<url>http://mojo.codehaus.org</url>

<profiles>
<profile>
<id>cifriendly-profile-bug</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>myrepo</id>
<name>myrepo</name>
<url>https://${repoHost}/${repoPath}</url>
</repository>
</repositories>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,6 @@ assert 'org.codehaus.mojo.flatten.its' == flattendChildWithParentProject.groupId
assert 'multimodule-module-with-parent-cifriendly' == flattendChildWithParentProject.artifactId.text()
assert '1.2.3.4' == flattendChildWithParentProject.version.text()
assert '1.2.3.4' == flattendChildWithParentProject.parent.version.text()

// CiFriendly interpolation bug
assert 'https://${repoHost}/${repoPath}' == flattendProject.profiles.profile[0].repositories.repository[0].url.text()
5 changes: 4 additions & 1 deletion src/main/java/org/codehaus/mojo/flatten/ElementHandling.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public enum ElementHandling
keep,

/** Remove the element entirely so it will not be present in flattened POM. */
remove
remove,

/** Take the element untouched from the original POM. Fix for {@link #keep} */
keepRaw

}
16 changes: 16 additions & 0 deletions src/main/java/org/codehaus/mojo/flatten/FlattenDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,22 @@ public void setIssueManagement( ElementHandling issueManagement )
setHandling( PomProperty.ISSUE_MANAGEMENT, issueManagement );
}

/**
* @return {@link ElementHandling} for {@link Model#getLicenses() licenses}.
*/
public ElementHandling getLicenses()
{
return getHandling( PomProperty.LICENSES );
}

/**
* @param licenses the {@link #getLicenses() licenses} to set.
*/
public void setLicenses( ElementHandling licenses )
{
setHandling( PomProperty.LICENSES, licenses );
}

/**
* @return {@link ElementHandling} for {@link Model#getCiManagement() ciManagement}.
*/
Expand Down
34 changes: 33 additions & 1 deletion src/main/java/org/codehaus/mojo/flatten/FlattenMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ public enum FlattenMode
/** Only resolves variables revision, sha1 and changelist. Keeps everything else.
* See <a href="https://maven.apache.org/maven-ci-friendly.html">Maven CI Friendly</a> for further details.
*/
resolveCiFriendliesOnly;
resolveCiFriendliesOnly,

/**
* Fix for {@link #resolveCiFriendliesOnly}
*/
version;

/**
* @return the {@link FlattenDescriptor} defined by this {@link FlattenMode}.
Expand Down Expand Up @@ -147,6 +151,34 @@ public FlattenDescriptor getDescriptor()
descriptor.setUrl( ElementHandling.interpolate );
descriptor.setVersion( ElementHandling.resolve );
break;
case version:
descriptor.setBuild(ElementHandling.keepRaw);
descriptor.setCiManagement(ElementHandling.keepRaw);
descriptor.setContributors(ElementHandling.keepRaw);
descriptor.setDependencies(ElementHandling.keepRaw);
descriptor.setDependencyManagement(ElementHandling.keepRaw);
descriptor.setDescription(ElementHandling.keepRaw);
descriptor.setDevelopers(ElementHandling.keepRaw);
descriptor.setDistributionManagement(ElementHandling.keepRaw);
descriptor.setInceptionYear(ElementHandling.keepRaw);
descriptor.setIssueManagement(ElementHandling.keepRaw);
descriptor.setLicenses(ElementHandling.keepRaw);
descriptor.setMailingLists(ElementHandling.keepRaw);
descriptor.setModules(ElementHandling.keepRaw);
descriptor.setName(ElementHandling.keepRaw);
descriptor.setOrganization(ElementHandling.keepRaw);
descriptor.setParent(ElementHandling.resolve);
descriptor.setPluginManagement(ElementHandling.keepRaw);
descriptor.setPluginRepositories(ElementHandling.keepRaw);
descriptor.setPrerequisites(ElementHandling.keepRaw);
descriptor.setProfiles(ElementHandling.keepRaw);
descriptor.setProperties(ElementHandling.keepRaw);
descriptor.setReporting(ElementHandling.keepRaw);
descriptor.setRepositories(ElementHandling.keepRaw);
descriptor.setScm(ElementHandling.keepRaw);
descriptor.setUrl(ElementHandling.keepRaw);
descriptor.setVersion(ElementHandling.resolve);
break;
case clean:
// nothing to do...
break;
Expand Down
25 changes: 23 additions & 2 deletions src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.maven.model.building.ModelBuildingResult;
import org.apache.maven.model.building.ModelProblemCollector;
import org.apache.maven.model.interpolation.ModelInterpolator;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.model.profile.ProfileActivationContext;
import org.apache.maven.model.profile.ProfileInjector;
Expand All @@ -57,6 +58,7 @@
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.ext.DefaultHandler2;
Expand All @@ -65,6 +67,7 @@
import javax.xml.parsers.SAXParserFactory;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
Expand Down Expand Up @@ -486,6 +489,7 @@ protected Model createFlattenedPom( File pomFile )
Model originalPom = this.project.getOriginalModel();
Model resolvedPom = this.project.getModel();
Model interpolatedPom = createResolvedPom( buildingRequest );
Model rawPom = getRawPom(pomFile);

// copy the configured additional POM elements...

Expand All @@ -494,7 +498,7 @@ protected Model createFlattenedPom( File pomFile )
if ( property.isElement() )
{
Model sourceModel = getSourceModel( descriptor, property, effectivePom, originalPom, resolvedPom,
interpolatedPom, cleanPom );
interpolatedPom, cleanPom, rawPom );
if ( sourceModel == null )
{
if ( property.isRequired() )
Expand All @@ -513,6 +517,20 @@ protected Model createFlattenedPom( File pomFile )
return flattenedPom;
}

private Model getRawPom(File pomFile) throws MojoExecutionException
{
MavenXpp3Reader reader = new MavenXpp3Reader();
Model rawPom = null;
try
{
rawPom = reader.read(new FileReader(pomFile));
}
catch(IOException | XmlPullParserException e) {
throw new MojoExecutionException("Error reading raw model.", e);
}
return rawPom;
}

private Model createResolvedPom( ModelBuildingRequest buildingRequest )
{
LoggingModelProblemCollector problems = new LoggingModelProblemCollector( getLog() );
Expand Down Expand Up @@ -593,7 +611,8 @@ protected Model createCleanPom( Model effectivePom )
}

private Model getSourceModel( FlattenDescriptor descriptor, PomProperty<?> property, Model effectivePom,
Model originalPom, Model resolvedPom, Model interpolatedPom, Model cleanPom )
Model originalPom, Model resolvedPom, Model interpolatedPom, Model cleanPom,
Model rawPom )
{

ElementHandling handling = descriptor.getHandling( property );
Expand All @@ -613,6 +632,8 @@ private Model getSourceModel( FlattenDescriptor descriptor, PomProperty<?> prope
return cleanPom;
case remove:
return null;
case keepRaw:
return rawPom;
default:
throw new IllegalStateException( handling.toString() );
}
Expand Down