You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2017/09/25 22:02:31 UTC
svn commit: r1809668 - in /maven/enforcer/trunk:
enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/
enforcer-rules/src/site/apt/
maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_failure/
maven-enforcer-plugin/src/it/projects...
Author: rfscholte
Date: Mon Sep 25 22:02:30 2017
New Revision: 1809668
URL: http://svn.apache.org/viewvc?rev=1809668&view=rev
Log:
[MENFORCER-282] Add RequireProfileIdsExist to ensure al mentioned cmdline profiles exist
Added:
maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireProfileIdsExist.java
maven/enforcer/trunk/enforcer-rules/src/site/apt/requireProfileIdsExist.apt.vm
maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_failure/
maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_failure/invoker.properties
maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_failure/pom.xml
maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_failure/verify.groovy
maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_success/
maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_success/invoker.properties
maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_success/pom.xml
Modified:
maven/enforcer/trunk/enforcer-rules/src/site/apt/index.apt
Added: maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireProfileIdsExist.java
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireProfileIdsExist.java?rev=1809668&view=auto
==============================================================================
--- maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireProfileIdsExist.java (added)
+++ maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireProfileIdsExist.java Mon Sep 25 22:02:30 2017
@@ -0,0 +1,92 @@
+package org.apache.maven.plugins.enforcer;
+
+/*
+ * 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 java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * Ensure that all profiles mentioned on the commandline do exist.
+ *
+ * @author Robert Scholte
+ */
+public class RequireProfileIdsExist extends AbstractNonCacheableEnforcerRule
+{
+ @Override
+ public void execute( EnforcerRuleHelper helper )
+ throws EnforcerRuleException
+ {
+ 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() )
+ {
+ profileIds.remove( profile.getId() );
+
+ if ( profileIds.isEmpty() )
+ {
+ return;
+ }
+ }
+ }
+
+ for ( org.apache.maven.settings.Profile profile : session.getSettings().getProfiles() )
+ {
+ profileIds.remove( profile.getId() );
+
+ if ( profileIds.isEmpty() )
+ {
+ return;
+ }
+ }
+
+ StringBuilder sb = new StringBuilder();
+ if ( profileIds.size() > 1 )
+ {
+ sb.append( "The requested profiles don't exist: " );
+ }
+ else
+ {
+ sb.append( "The requested profile doesn't exist: " );
+ }
+ sb.append( StringUtils.join( profileIds.iterator(), ", " ) );
+
+ throw new EnforcerRuleException( sb.toString() );
+ }
+ catch ( ExpressionEvaluationException e )
+ {
+ throw new EnforcerRuleException( e.getMessage() );
+ }
+ }
+}
Modified: maven/enforcer/trunk/enforcer-rules/src/site/apt/index.apt
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/site/apt/index.apt?rev=1809668&r1=1809667&r2=1809668&view=diff
==============================================================================
--- maven/enforcer/trunk/enforcer-rules/src/site/apt/index.apt (original)
+++ maven/enforcer/trunk/enforcer-rules/src/site/apt/index.apt Mon Sep 25 22:02:30 2017
@@ -73,6 +73,8 @@ Built-In Rules
* {{{./requirePrerequisite.html}requirePrerequisite}} - enforces that prerequisites have been specified.
+ * {{{./requireProfileIdsExist.html}requireProfileIdsExist}} - enforces the existence of profiles specified on the commandline.
+
* {{{./requireProperty.html}requireProperty}} - enforces the existence and values of properties.
* {{{./requireReleaseDeps.html}requireReleaseDeps}} - enforces that no snapshots are included as dependencies.
Added: maven/enforcer/trunk/enforcer-rules/src/site/apt/requireProfileIdsExist.apt.vm
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/site/apt/requireProfileIdsExist.apt.vm?rev=1809668&view=auto
==============================================================================
--- maven/enforcer/trunk/enforcer-rules/src/site/apt/requireProfileIdsExist.apt.vm (added)
+++ maven/enforcer/trunk/enforcer-rules/src/site/apt/requireProfileIdsExist.apt.vm Mon Sep 25 22:02:30 2017
@@ -0,0 +1,61 @@
+ ~~ 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.
+
+ -----
+ Require Upper Bound Dependencies
+ -----
+ -----
+ 2017-09-25
+ -----
+
+ When running Maven with one or more unknown profile ids, Maven will give you a warning.
+ This rule will actually break the build for that reason.
+
+ Here is how a project should be setup to use this rule
+
+-----------------------------------------------------------------------------------
+<project>
+ ...
+ <build>
+ <plugins>
+ ...
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ <version>${project.version}</version>
+ <executions>
+ <execution>
+ <id>enforce</id>
+ <configuration>
+ <rules>
+ <requireProfileIdsExist/>
+ </rules>
+ </configuration>
+ <goals>
+ <goal>enforce</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ ...
+ </plugins>
+ </build>
+ ...
+</project>
+-----------------------------------------------------------------------------------
+
+
\ No newline at end of file
Added: maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_failure/invoker.properties
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_failure/invoker.properties?rev=1809668&view=auto
==============================================================================
--- maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_failure/invoker.properties (added)
+++ maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_failure/invoker.properties Mon Sep 25 22:02:30 2017
@@ -0,0 +1,19 @@
+# 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.
+
+invoker.buildResult=failure
+invoker.profiles = c
\ No newline at end of file
Added: maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_failure/pom.xml
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_failure/pom.xml?rev=1809668&view=auto
==============================================================================
--- maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_failure/pom.xml (added)
+++ maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_failure/pom.xml Mon Sep 25 22:02:30 2017
@@ -0,0 +1,60 @@
+<?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.
+-->
+
+<project>
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.enforcer</groupId>
+ <artifactId>test</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>a</id>
+ </profile>
+ <profile>
+ <id>b</id>
+ </profile>
+ </profiles>
+</project>
Added: maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_failure/verify.groovy
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_failure/verify.groovy?rev=1809668&view=auto
==============================================================================
--- maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_failure/verify.groovy (added)
+++ maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_failure/verify.groovy Mon Sep 25 22:02:30 2017
@@ -0,0 +1,20 @@
+/*
+ * 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: c" )
Added: maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_success/invoker.properties
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_success/invoker.properties?rev=1809668&view=auto
==============================================================================
--- maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_success/invoker.properties (added)
+++ maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_success/invoker.properties Mon Sep 25 22:02:30 2017
@@ -0,0 +1,18 @@
+# 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.
+
+invoker.profiles = a
\ No newline at end of file
Added: maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_success/pom.xml
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_success/pom.xml?rev=1809668&view=auto
==============================================================================
--- maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_success/pom.xml (added)
+++ maven/enforcer/trunk/maven-enforcer-plugin/src/it/projects/require-profile-ids-exist_success/pom.xml Mon Sep 25 22:02:30 2017
@@ -0,0 +1,60 @@
+<?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.
+-->
+
+<project>
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.enforcer</groupId>
+ <artifactId>test</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>a</id>
+ </profile>
+ <profile>
+ <id>b</id>
+ </profile>
+ </profiles>
+</project>