You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2020/05/27 14:25:15 UTC

[maven-enforcer] branch master updated: [MENFORCER-346] - RequireSnapshotVersion: Fix parent with CI Friendly Version (#57)

This is an automated email from the ASF dual-hosted git repository.

elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-enforcer.git


The following commit(s) were added to refs/heads/master by this push:
     new 9b1a09b  [MENFORCER-346] - RequireSnapshotVersion: Fix parent with CI Friendly Version (#57)
9b1a09b is described below

commit 9b1a09b76cdfc69938ddd81f70f4c745ac399dd7
Author: Falko Modler <fa...@users.noreply.github.com>
AuthorDate: Wed May 27 16:25:08 2020 +0200

    [MENFORCER-346] - RequireSnapshotVersion: Fix parent with CI Friendly Version (#57)
---
 .../plugins/enforcer/RequireSnapshotVersion.java   | 12 +++--
 .../invoker.properties                             | 19 +++++++
 .../module/pom.xml                                 | 33 ++++++++++++
 .../pom.xml                                        | 63 ++++++++++++++++++++++
 .../verify.groovy                                  | 21 ++++++++
 .../invoker.properties                             | 18 +++++++
 .../module/pom.xml                                 | 33 ++++++++++++
 .../pom.xml                                        | 63 ++++++++++++++++++++++
 8 files changed, 257 insertions(+), 5 deletions(-)

diff --git a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireSnapshotVersion.java b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireSnapshotVersion.java
index a7d9fd2..a631d2a 100644
--- a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireSnapshotVersion.java
+++ b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireSnapshotVersion.java
@@ -42,7 +42,7 @@ public class RequireSnapshotVersion
         throws EnforcerRuleException
     {
 
-        MavenProject project = getProject( helper );
+        MavenProject project = getProject( false, helper );
         Artifact artifact = project.getArtifact();
 
         if ( !artifact.isSnapshot() )
@@ -56,9 +56,10 @@ public class RequireSnapshotVersion
             sb.append( "This project cannot be a release:" ).append( artifact.getId() );
             throw new EnforcerRuleException( sb.toString() );
         }
-        if ( failWhenParentIsRelease )
+        if ( failWhenParentIsRelease && project.hasParent() )
         {
-            Artifact parentArtifact = project.getParentArtifact();
+            // project.getParentArtifact() does not work here if a "CI Friendly Version" is used (e.g. ${revision})
+            Artifact parentArtifact = getProject( true, helper ).getArtifact();
             if ( parentArtifact != null && !parentArtifact.isSnapshot() )
             {
                 throw new EnforcerRuleException( "Parent cannot be a release: " + parentArtifact.getId() );
@@ -67,12 +68,13 @@ public class RequireSnapshotVersion
 
     }
 
-    private MavenProject getProject( EnforcerRuleHelper helper )
+    private MavenProject getProject( boolean parent, EnforcerRuleHelper helper )
         throws EnforcerRuleException
     {
+        String expression = parent ? "${project.parent}" : "${project}";
         try
         {
-            return (MavenProject) helper.evaluate( "${project}" );
+            return (MavenProject) helper.evaluate( expression );
         }
         catch ( ExpressionEvaluationException eee )
         {
diff --git a/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure_parent-ci-friendly/invoker.properties b/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure_parent-ci-friendly/invoker.properties
new file mode 100644
index 0000000..4d90799
--- /dev/null
+++ b/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure_parent-ci-friendly/invoker.properties
@@ -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.maven.version = 3.5.0+
+invoker.buildResult = failure
diff --git a/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure_parent-ci-friendly/module/pom.xml b/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure_parent-ci-friendly/module/pom.xml
new file mode 100644
index 0000000..466827e
--- /dev/null
+++ b/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure_parent-ci-friendly/module/pom.xml
@@ -0,0 +1,33 @@
+<?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>
+
+  <parent>
+    <groupId>org.apache.maven.its.enforcer</groupId>
+    <artifactId>menforcer-346-parent</artifactId>
+    <version>${revision}</version>
+  </parent>
+
+  <artifactId>menforcer-346-module</artifactId>
+
+</project>
diff --git a/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure_parent-ci-friendly/pom.xml b/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure_parent-ci-friendly/pom.xml
new file mode 100644
index 0000000..2c01127
--- /dev/null
+++ b/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure_parent-ci-friendly/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.
+-->
+
+<project>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.enforcer</groupId>
+  <artifactId>menforcer-346-parent</artifactId>
+  <version>${revision}</version>
+  <packaging>pom</packaging>
+
+  <description>https://issues.apache.org/jira/browse/MENFORCER-346</description>
+
+  <properties>
+    <revision>1.0</revision>
+  </properties>
+
+  <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>
+                <requireSnapshotVersion/>
+              </rules>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <modules>
+    <module>module</module>
+  </modules>
+
+</project>
diff --git a/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure_parent-ci-friendly/verify.groovy b/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure_parent-ci-friendly/verify.groovy
new file mode 100644
index 0000000..039aef3
--- /dev/null
+++ b/maven-enforcer-plugin/src/it/projects/require-snapshot-version_failure_parent-ci-friendly/verify.groovy
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+File buildLog = new File( basedir, 'build.log' )
+assert buildLog.text.contains( 'This project cannot be a release:org.apache.maven.its.enforcer:menforcer-346-parent:pom:1.0' )
+ 
\ No newline at end of file
diff --git a/maven-enforcer-plugin/src/it/projects/require-snapshot-version_success_parent-ci-friendly/invoker.properties b/maven-enforcer-plugin/src/it/projects/require-snapshot-version_success_parent-ci-friendly/invoker.properties
new file mode 100644
index 0000000..425ce06
--- /dev/null
+++ b/maven-enforcer-plugin/src/it/projects/require-snapshot-version_success_parent-ci-friendly/invoker.properties
@@ -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.maven.version = 3.5.0+
diff --git a/maven-enforcer-plugin/src/it/projects/require-snapshot-version_success_parent-ci-friendly/module/pom.xml b/maven-enforcer-plugin/src/it/projects/require-snapshot-version_success_parent-ci-friendly/module/pom.xml
new file mode 100644
index 0000000..466827e
--- /dev/null
+++ b/maven-enforcer-plugin/src/it/projects/require-snapshot-version_success_parent-ci-friendly/module/pom.xml
@@ -0,0 +1,33 @@
+<?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>
+
+  <parent>
+    <groupId>org.apache.maven.its.enforcer</groupId>
+    <artifactId>menforcer-346-parent</artifactId>
+    <version>${revision}</version>
+  </parent>
+
+  <artifactId>menforcer-346-module</artifactId>
+
+</project>
diff --git a/maven-enforcer-plugin/src/it/projects/require-snapshot-version_success_parent-ci-friendly/pom.xml b/maven-enforcer-plugin/src/it/projects/require-snapshot-version_success_parent-ci-friendly/pom.xml
new file mode 100644
index 0000000..f9b1bd6
--- /dev/null
+++ b/maven-enforcer-plugin/src/it/projects/require-snapshot-version_success_parent-ci-friendly/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.
+-->
+
+<project>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.enforcer</groupId>
+  <artifactId>menforcer-346-parent</artifactId>
+  <version>${revision}</version>
+  <packaging>pom</packaging>
+
+  <description>https://issues.apache.org/jira/browse/MENFORCER-346</description>
+
+  <properties>
+    <revision>1.0-SNAPSHOT</revision>
+  </properties>
+
+  <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>
+                <requireSnapshotVersion/>
+              </rules>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <modules>
+    <module>module</module>
+  </modules>
+
+</project>