You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kh...@apache.org on 2018/12/09 12:57:27 UTC
[maven-enforcer] 01/01: [MENFORCER-322] requireProfileIdsExist
triggers if profile is defined at parent o Fixed iterating over parent
poms. Added IT.
This is an automated email from the ASF dual-hosted git repository.
khmarbaise pushed a commit to branch MENFORCER-322
in repository https://gitbox.apache.org/repos/asf/maven-enforcer.git
commit 91066895050b9fbc41e7f79370b24d744eed10fa
Author: Gabriel Belingueres <be...@gmail.com>
AuthorDate: Sun Dec 9 00:46:08 2018 -0300
[MENFORCER-322] requireProfileIdsExist triggers if profile is defined at parent
o Fixed iterating over parent poms. Added IT.
---
.../plugins/enforcer/RequireProfileIdsExist.java | 27 ++++++---
.../MENFORCER-322-module/pom.xml | 65 ++++++++++++++++++++++
.../invoker.properties | 27 +++++++++
.../pom.xml | 63 +++++++++++++++++++++
.../verify.groovy | 22 ++++++++
5 files changed, 195 insertions(+), 9 deletions(-)
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 @@ import org.codehaus.plexus.util.StringUtils;
* 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 class RequireProfileIdsExist extends AbstractNonCacheableEnforcerRule
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 class RequireProfileIdsExist extends AbstractNonCacheableEnforcerRule
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" ) )