Skip to content

Commit

Permalink
Merge branch 'master' into feature/extended_interpolate
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeDemoulinGebit authored Nov 21, 2023
2 parents 7c2a8bf + a6d33fb commit 60967eb
Show file tree
Hide file tree
Showing 15 changed files with 228 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ jobs:
name: Verify
uses: apache/maven-gh-actions-shared/.github/workflows/maven-verify.yml@v3
with:
ff-maven: "3.9.1" # Maven version for fail-fast-build
maven-matrix: '[ "3.5.4", "3.8.8", "3.9.1" ]' # Maven versions matrix for verify builds
ff-maven: "3.9.5" # Maven version for fail-fast-build
maven-matrix: '[ "3.6.3", "3.8.8", "3.9.5" ]' # Maven versions matrix for verify builds
14 changes: 6 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
<parent>
<groupId>org.codehaus.mojo</groupId>
<artifactId>mojo-parent</artifactId>
<version>74</version>
<version>77</version>
</parent>

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

<name>Maven Flatten Plugin</name>
Expand Down Expand Up @@ -122,16 +122,14 @@
<scm>
<connection>scm:git:https://github.com/mojohaus/flatten-maven-plugin.git</connection>
<developerConnection>scm:git:ssh://[email protected]/mojohaus/flatten-maven-plugin.git</developerConnection>
<tag>1.5.0</tag>
<tag>1.4.1</tag>
<url>https://github.com/mojohaus/flatten-maven-plugin/tree/master</url>
</scm>

<properties>
<mavenVersion>3.5.4</mavenVersion>
<recommendedJavaBuildVersion>11</recommendedJavaBuildVersion>
<maven.compiler.target>${recommendedJavaBuildVersion}</maven.compiler.target>
<maven.compiler.source>${recommendedJavaBuildVersion}</maven.compiler.source>
<project.build.outputTimestamp>2023-05-09T19:54:01Z</project.build.outputTimestamp>
<project.build.outputTimestamp>2023-05-09T19:54:26Z</project.build.outputTimestamp>
</properties>

<!-- override versions of some transitive dependencies -->
Expand All @@ -140,7 +138,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
<version>2.14.0</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down Expand Up @@ -251,7 +249,7 @@
<dependency>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.inject</artifactId>
<version>0.3.5</version>
<version>0.9.0.M2</version>
</dependency>
</dependencies>
</plugin>
Expand Down
57 changes: 57 additions & 0 deletions src/it/mrm/settings-properties.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>mrm-maven-plugin</id>
<name>Mock Repository Manager</name>
<url>@repository.proxy.url@</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>it-repo</id>
<properties>
<testProperty>EXTERNAL-PROFILE-VALUE</testProperty>
</properties>
<repositories>
<repository>
<id>snapshots</id>
<url>@repository.proxy.url@</url>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>snapshots</id>
<url>@repository.proxy.url@</url>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
<updatePolicy>always</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>it-repo</activeProfile>
</activeProfiles>
</settings>
2 changes: 1 addition & 1 deletion src/it/projects/bom-flattenMode/bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.1-jre</version>
<version>32.0.0-jre</version>
</dependency>
<!-- Library with general utilities as well as I18N and exception support -->
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion src/it/projects/bom-pomElements/bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.1-jre</version>
<version>32.0.0-jre</version>
</dependency>
<!-- Library with general utilities as well as I18N and exception support -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.settingsFile = src/it/mrm/settings-properties.xml
invoker.profiles = !it-repo
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<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>profile-with-properties-active</artifactId>
<version>0.0.1-SNAPSHOT</version>

<properties>
<testProperty>DEFAULT_VALUE</testProperty>
</properties>

<licenses>
<license>
<name>${testProperty}</name>
</license>
</licenses>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.
*/
import groovy.xml.XmlSlurper

File originalPom = new File( basedir, 'pom.xml' )
assert originalPom.exists()

File flattenedPom = new File( basedir, '.flattened-pom.xml' )
assert flattenedPom.exists()

def flattenedProject = new XmlSlurper().parse( flattenedPom )
assert 'DEFAULT_VALUE' == flattenedProject.licenses.license.name.text()
assert 0 == flattenedProject.profiles.profile.size()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.settingsFile = src/it/mrm/settings-properties.xml
14 changes: 14 additions & 0 deletions src/it/projects/external-profile-with-properties-active/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<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>profile-with-properties-active</artifactId>
<version>0.0.1-SNAPSHOT</version>

<licenses>
<license>
<name>${testProperty}</name>
</license>
</licenses>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.
*/
import groovy.xml.XmlSlurper

File originalPom = new File( basedir, 'pom.xml' )
assert originalPom.exists()

File flattenedPom = new File( basedir, '.flattened-pom.xml' )
assert flattenedPom.exists()

def flattenedProject = new XmlSlurper().parse( flattenedPom )
assert 'EXTERNAL-PROFILE-VALUE' == flattenedProject.licenses.license.name.text()
assert 0 == flattenedProject.profiles.profile.size()
2 changes: 1 addition & 1 deletion src/it/projects/flatten-shaded-drp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.1-jre</version>
<version>32.0.0-jre</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/org/codehaus/mojo/flatten/FlattenDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,48 @@ public void setHandling(PomProperty<?> property, ElementHandling handling) {
this.name2handlingMap.put(property.getName(), handling);
}

/**
* @return {@link ElementHandling} for {@link Model#getArtifactId() artifactId}.
*/
public ElementHandling getArtifactId() {
return getHandling(PomProperty.ARTIFACT_ID);
}

/**
* @param artifactId the {@link #setArtifactId(ElementHandling) artifactId} to set.
*/
public void setArtifactId(ElementHandling artifactId) {
setHandling(PomProperty.ARTIFACT_ID, artifactId);
}

/**
* @return {@link ElementHandling} for {@link Model#getGroupId() groupId}.
*/
public ElementHandling getGroupId() {
return getHandling(PomProperty.GROUP_ID);
}

/**
* @param groupId the {@link #setGroupId(ElementHandling) groupId} to set.
*/
public void setGroupId(ElementHandling groupId) {
setHandling(PomProperty.GROUP_ID, groupId);
}

/**
* @return {@link ElementHandling} for {@link Model#getPackaging() packaging}.
*/
public ElementHandling getPackaging() {
return getHandling(PomProperty.PACKAGING);
}

/**
* @param packaging the {@link #setPackaging(ElementHandling) packaging} to set.
*/
public void setPackaging(ElementHandling packaging) {
setHandling(PomProperty.PACKAGING, packaging);
}

/**
* @return {@link ElementHandling} for {@link Model#getName() name}.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/codehaus/mojo/flatten/FlattenMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ public FlattenDescriptor getDescriptor() {
descriptor.setMailingLists(ElementHandling.interpolate);
descriptor.setModules(ElementHandling.interpolate);
descriptor.setName(ElementHandling.interpolate);
descriptor.setArtifactId(ElementHandling.interpolate);
descriptor.setGroupId(ElementHandling.interpolate);
descriptor.setPackaging(ElementHandling.interpolate);
descriptor.setOrganization(ElementHandling.interpolate);
descriptor.setParent(ElementHandling.resolve);
descriptor.setPluginManagement(ElementHandling.interpolate);
Expand Down
26 changes: 22 additions & 4 deletions src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Settings;
import org.codehaus.mojo.flatten.cifriendly.CiInterpolator;
import org.codehaus.mojo.flatten.extendedinterpolation.ExtendedModelInterpolator;
import org.codehaus.mojo.flatten.model.resolution.FlattenModelResolver;
Expand Down Expand Up @@ -191,6 +192,12 @@ public class FlattenMojo extends AbstractFlattenMojo {

private static final int INITIAL_POM_WRITER_SIZE = 4096;

/**
* The {@link Settings} used to get active profile properties.
*/
@Parameter(defaultValue = "${settings}", readonly = true, required = true)
private Settings settings;

/**
* The {@link MavenSession} used to get user properties.
*/
Expand Down Expand Up @@ -821,15 +828,26 @@ private ModelBuildingRequest createModelBuildingRequest(File pomFile) {
context,
project.getRemoteProjectRepositories(),
getReactorModelsFromSession());
Properties userProperties = this.session.getUserProperties();
List<String> activeProfiles = this.session.getRequest().getActiveProfiles();
Properties userAndActiveExternalProfilesProperties = new Properties();
userAndActiveExternalProfilesProperties.putAll(this.session.getUserProperties());
this.settings.getProfiles().stream()
.filter(p -> this.settings.getActiveProfiles().contains(p.getId())
&& !this.session.getRequest().getInactiveProfiles().contains(p.getId()))
.forEach(
activeProfile -> userAndActiveExternalProfilesProperties.putAll(activeProfile.getProperties()));

List<String> activeProfiles = Stream.concat(
this.session.getRequest().getActiveProfiles().stream(),
this.settings.getActiveProfiles().stream())
.collect(Collectors.toList());

return new DefaultModelBuildingRequest()
.setUserProperties(userProperties)
.setUserProperties(userAndActiveExternalProfilesProperties)
.setSystemProperties(System.getProperties())
.setPomFile(pomFile)
.setModelResolver(resolver)
.setActiveProfileIds(activeProfiles);
.setActiveProfileIds(activeProfiles)
.setInactiveProfileIds(this.session.getRequest().getInactiveProfiles());
}

private List<MavenProject> getReactorModelsFromSession() {
Expand Down

0 comments on commit 60967eb

Please sign in to comment.