[
https://issues.apache.org/jira/browse/MENFORCER-322?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16717707#comment-16717707
]
ASF GitHub Bot commented on MENFORCER-322:
------------------------------------------
khmarbaise closed pull request #46: [MENFORCER-322] - requireProfileIdsExist
triggers if profile is defined at parent
URL: https://github.com/apache/maven-enforcer/pull/46
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireProfileIdsExist.java
b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireProfileIdsExist.java
index 770f644..d595497 100644
---
a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireProfileIdsExist.java
+++
b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireProfileIdsExist.java
@@ -33,6 +33,7 @@
* Ensure that all profiles mentioned on the commandline do exist.
*
* @author Robert Scholte
+ * @author Gabriel Belingueres
*/
public class RequireProfileIdsExist extends AbstractNonCacheableEnforcerRule
{
@@ -43,24 +44,32 @@ public void execute( EnforcerRuleHelper helper )
try
{
MavenSession session = (MavenSession) helper.evaluate(
"${session}" );
-
+
List<String> profileIds = new ArrayList<String>();
profileIds.addAll(
session.getProjectBuildingRequest().getActiveProfileIds() );
profileIds.addAll(
session.getProjectBuildingRequest().getInactiveProfileIds() );
-
+
for ( MavenProject project : session.getProjects() )
{
- for ( org.apache.maven.model.Profile profile :
project.getModel().getProfiles() )
+ // iterate over all parents
+ MavenProject currentProject = project;
+ do
{
- profileIds.remove( profile.getId() );
-
- if ( profileIds.isEmpty() )
+ for ( org.apache.maven.model.Profile profile :
currentProject.getModel().getProfiles() )
{
- return;
+ profileIds.remove( profile.getId() );
+
+ if ( profileIds.isEmpty() )
+ {
+ return;
+ }
}
+
+ currentProject = currentProject.getParent();
}
+ while ( currentProject != null );
}
-
+
for ( org.apache.maven.settings.Profile profile :
session.getSettings().getProfiles() )
{
profileIds.remove( profile.getId() );
@@ -81,7 +90,7 @@ public void execute( EnforcerRuleHelper helper )
sb.append( "The requested profile doesn't exist: " );
}
sb.append( StringUtils.join( profileIds.iterator(), ", " ) );
-
+
throw new EnforcerRuleException( sb.toString() );
}
catch ( ExpressionEvaluationException e )
diff --git
a/maven-enforcer-plugin/src/it/projects/require-profile-id-exist_defined_in_parent/MENFORCER-322-module/pom.xml
b/maven-enforcer-plugin/src/it/projects/require-profile-id-exist_defined_in_parent/MENFORCER-322-module/pom.xml
new file mode 100644
index 0000000..a0540d5
--- /dev/null
+++
b/maven-enforcer-plugin/src/it/projects/require-profile-id-exist_defined_in_parent/MENFORCER-322-module/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<!-- MENFORCER-322 -->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.its.enforcer</groupId>
+ <artifactId>test</artifactId>
+ <version>1.0</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <groupId>org.apache.maven.its.enforcer</groupId>
+ <artifactId>menforcer-322-module</artifactId>
+ <version>1.0</version>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ <version>@project.version@</version>
+ <executions>
+ <execution>
+ <id>test</id>
+ <goals>
+ <goal>enforce</goal>
+ </goals>
+ <configuration>
+ <rules>
+ <RequireProfileIdsExist/>
+ </rules>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>b</id>
+ </profile>
+ </profiles>
+</project>
diff --git
a/maven-enforcer-plugin/src/it/projects/require-profile-id-exist_defined_in_parent/invoker.properties
b/maven-enforcer-plugin/src/it/projects/require-profile-id-exist_defined_in_parent/invoker.properties
new file mode 100644
index 0000000..8d46b16
--- /dev/null
+++
b/maven-enforcer-plugin/src/it/projects/require-profile-id-exist_defined_in_parent/invoker.properties
@@ -0,0 +1,27 @@
+# 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.
+
+# MENFORCER-322
+
+# test building the top level project
+invoker.goals.1 = clean compile
+invoker.profiles.1 = a,b
+
+# test building the module
+invoker.project.2 = MENFORCER-322-module
+invoker.goals.2 = clean compile
+invoker.profiles.2 = a,b
diff --git
a/maven-enforcer-plugin/src/it/projects/require-profile-id-exist_defined_in_parent/pom.xml
b/maven-enforcer-plugin/src/it/projects/require-profile-id-exist_defined_in_parent/pom.xml
new file mode 100644
index 0000000..21adc5c
--- /dev/null
+++
b/maven-enforcer-plugin/src/it/projects/require-profile-id-exist_defined_in_parent/pom.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<!-- MENFORCER-322 -->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.enforcer</groupId>
+ <artifactId>test</artifactId>
+ <version>1.0</version>
+ <packaging>pom</packaging>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ <version>@project.version@</version>
+ <executions>
+ <execution>
+ <id>test</id>
+ <goals>
+ <goal>enforce</goal>
+ </goals>
+ <configuration>
+ <rules>
+ <RequireProfileIdsExist/>
+ </rules>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <modules>
+ <module>MENFORCER-322-module</module>
+ </modules>
+
+ <profiles>
+ <profile>
+ <id>a</id>
+ </profile>
+ </profiles>
+</project>
diff --git
a/maven-enforcer-plugin/src/it/projects/require-profile-id-exist_defined_in_parent/verify.groovy
b/maven-enforcer-plugin/src/it/projects/require-profile-id-exist_defined_in_parent/verify.groovy
new file mode 100644
index 0000000..4e58239
--- /dev/null
+++
b/maven-enforcer-plugin/src/it/projects/require-profile-id-exist_defined_in_parent/verify.groovy
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+def buildLog = new File( basedir, 'build.log' )
+assert !( buildLog.text.contains( "The requested profile doesn't exist: a" ) )
+assert !( buildLog.text.contains( "The requested profile doesn't exist: b" ) )
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> requireProfileIdsExist triggers if profile is defined at parent
> ---------------------------------------------------------------
>
> Key: MENFORCER-322
> URL: https://issues.apache.org/jira/browse/MENFORCER-322
> Project: Maven Enforcer Plugin
> Issue Type: Bug
> Components: Standard Rules
> Affects Versions: 3.0.0-M2
> Reporter: Andre Schulz
> Assignee: Karl Heinz Marbaise
> Priority: Major
> Fix For: 3.0.0
>
>
> If a profile is defined at a parent POM the maven-enforcer-plugin fails the
> build if requireProfileIdsExist is used.
> Transitive profiles should be also respected, since they are used during
> build.
> Example:
> profile from parent: RUN
> profile from self: DEV
> build parameters: -P RUN,DEV
> {code:java}
> [WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireProfileIdsExist
> faile
> d with message:
> The requested profile doesn't exist: RUN
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)