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 2019/05/10 20:00:16 UTC

[maven-release] branch failOnSnapshot created (now ffd0ff8)

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

rfscholte pushed a change to branch failOnSnapshot
in repository https://gitbox.apache.org/repos/asf/maven-release.git.


      at ffd0ff8  IT to ensure plugin fails on snapshots

This branch includes the following new commits:

     new ffd0ff8  IT to ensure plugin fails on snapshots

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-release] 01/01: IT to ensure plugin fails on snapshots

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch failOnSnapshot
in repository https://gitbox.apache.org/repos/asf/maven-release.git

commit ffd0ff8b978042dc27e71a1f43add5e54441d91f
Author: rfscholte <rf...@apache.org>
AuthorDate: Fri May 10 22:00:02 2019 +0200

    IT to ensure plugin fails on snapshots
---
 .../phase/CheckDependencySnapshotsPhase.java       |  2 +-
 .../release/phase/AbstractReleaseTestCase.java     | 24 +++++-
 maven-release-plugin/pom.xml                       | 26 +++++-
 .../it/mrm/repository/extension-1.0-SNAPSHOT.pom   | 30 +++++++
 maven-release-plugin/src/it/{ => mrm}/settings.xml |  9 ++
 .../prepare/fail-on-snapshots/invoker.properties   | 18 ++++
 .../it/projects/prepare/fail-on-snapshots/pom.xml  | 97 ++++++++++++++++++++++
 .../prepare/fail-on-snapshots/verify.groovy        | 32 +++++++
 .../maven/plugins/release/PrepareReleaseMojo.java  |  3 +-
 9 files changed, 236 insertions(+), 5 deletions(-)

diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckDependencySnapshotsPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckDependencySnapshotsPhase.java
index 37603d1..b19b446 100644
--- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckDependencySnapshotsPhase.java
+++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckDependencySnapshotsPhase.java
@@ -123,7 +123,7 @@ public class CheckDependencySnapshotsPhase
             }
         }
 
-        Set<Artifact> dependencyArtifacts = project.getArtifacts();
+        Set<Artifact> dependencyArtifacts = project.getDependencyArtifacts();
         usedSnapshotDependencies.addAll( checkDependencies( releaseDescriptor, artifactMap, dependencyArtifacts ) );
 
         //@todo check dependencyManagement
diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/AbstractReleaseTestCase.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/AbstractReleaseTestCase.java
index 2ddee24..989fad2 100644
--- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/AbstractReleaseTestCase.java
+++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/AbstractReleaseTestCase.java
@@ -1,6 +1,5 @@
 package org.apache.maven.shared.release.phase;
 
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -42,11 +41,13 @@ import java.util.Objects;
 
 import org.apache.commons.lang.SystemUtils;
 import org.apache.maven.artifact.ArtifactUtils;
+import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.DefaultArtifactRepository;
 import org.apache.maven.artifact.repository.MavenArtifactRepository;
 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
 import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
+import org.apache.maven.lifecycle.LifecycleExecutionException;
 import org.apache.maven.model.Profile;
 import org.apache.maven.model.Repository;
 import org.apache.maven.project.DefaultProjectBuildingRequest;
@@ -54,6 +55,7 @@ import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.ProjectBuilder;
 import org.apache.maven.project.ProjectBuildingRequest;
 import org.apache.maven.project.ProjectBuildingRequest.RepositoryMerging;
+import org.apache.maven.project.artifact.InvalidDependencyVersionException;
 import org.apache.maven.project.ProjectBuildingResult;
 import org.apache.maven.project.ProjectSorter;
 import org.apache.maven.repository.internal.MavenRepositorySystemSession;
@@ -82,6 +84,8 @@ public abstract class AbstractReleaseTestCase
     protected ProjectBuilder projectBuilder;
 
     protected ArtifactRepository localRepository;
+    
+    private ArtifactFactory artifactFactory;
 
     protected ReleasePhase phase;
 
@@ -92,6 +96,7 @@ public abstract class AbstractReleaseTestCase
         super.setUp();
 
         projectBuilder = lookup( ProjectBuilder.class );
+        artifactFactory = lookup( ArtifactFactory.class ); 
 
         ArtifactRepositoryLayout layout = lookup( ArtifactRepositoryLayout.class, "default" );
         String localRepoPath = getTestFile( "target/local-repository" ).getAbsolutePath().replace( '\\', '/' );
@@ -207,7 +212,22 @@ public abstract class AbstractReleaseTestCase
         List<MavenProject> resolvedProjects = new ArrayList<>( reactorProjects.size() );
         for ( MavenProject project  : reactorProjects )
         {
-            resolvedProjects.add( projectBuilder.build( project.getFile(), buildingRequest ).getProject() );
+            MavenProject resolvedProject = projectBuilder.build( project.getFile(), buildingRequest ).getProject();
+            
+            // from LifecycleDependencyResolver
+            if ( project.getDependencyArtifacts() == null )
+            {
+                try
+                {
+                    resolvedProject.setDependencyArtifacts( resolvedProject.createArtifacts( artifactFactory, null, null ) );
+                }
+                catch ( InvalidDependencyVersionException e )
+                {
+                    throw new LifecycleExecutionException( e );
+                }
+            }
+            
+            resolvedProjects.add( resolvedProject );
         }
         return resolvedProjects;
     }
diff --git a/maven-release-plugin/pom.xml b/maven-release-plugin/pom.xml
index 72702bf..acc6f7c 100644
--- a/maven-release-plugin/pom.xml
+++ b/maven-release-plugin/pom.xml
@@ -198,7 +198,10 @@
               <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
               <postBuildHookScript>verify</postBuildHookScript>
               <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
-              <settingsFile>src/it/settings.xml</settingsFile>
+              <settingsFile>src/it/mrm/settings.xml</settingsFile>
+              <filterProperties>
+                <mrm.repository.url>${mrm.repository.url}</mrm.repository.url>
+              </filterProperties>
               <debug>true</debug>
               <ignoreFailures>${maven.it.failure.ignore}</ignoreFailures>
               <setupIncludes>
@@ -223,6 +226,27 @@
               </properties>
             </configuration>
           </plugin>
+          <plugin>
+            <groupId>org.codehaus.mojo</groupId>
+            <artifactId>mrm-maven-plugin</artifactId>
+            <version>1.2.0</version>
+            <executions>
+              <execution>
+                <goals>
+                  <goal>start</goal>
+                  <goal>stop</goal>
+                </goals>
+              </execution>
+            </executions>
+            <configuration>
+              <repositories>
+                <mockRepo>
+                  <source>src/it/mrm/repository</source>
+                </mockRepo>
+                <proxyRepo/>
+              </repositories>
+            </configuration>
+          </plugin>
         </plugins>
       </build>
     </profile>
diff --git a/maven-release-plugin/src/it/mrm/repository/extension-1.0-SNAPSHOT.pom b/maven-release-plugin/src/it/mrm/repository/extension-1.0-SNAPSHOT.pom
new file mode 100644
index 0000000..3c5f169
--- /dev/null
+++ b/maven-release-plugin/src/it/mrm/repository/extension-1.0-SNAPSHOT.pom
@@ -0,0 +1,30 @@
+<?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 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>test</groupId>
+  <artifactId>extension</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+</project>
diff --git a/maven-release-plugin/src/it/settings.xml b/maven-release-plugin/src/it/mrm/settings.xml
similarity index 91%
rename from maven-release-plugin/src/it/settings.xml
rename to maven-release-plugin/src/it/mrm/settings.xml
index 1851c77..4b3caf1 100644
--- a/maven-release-plugin/src/it/settings.xml
+++ b/maven-release-plugin/src/it/mrm/settings.xml
@@ -20,6 +20,15 @@
 <settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
   
+  <mirrors>
+    <mirror>
+      <id>mrm-maven-plugin</id>
+      <name>Mock Repository Manager</name>
+      <url>@mrm.repository.url@</url>
+      <mirrorOf>*</mirrorOf>
+    </mirror>
+  </mirrors>
+  
   <servers>
     <server>
       <id>it-server</id>
diff --git a/maven-release-plugin/src/it/projects/prepare/fail-on-snapshots/invoker.properties b/maven-release-plugin/src/it/projects/prepare/fail-on-snapshots/invoker.properties
new file mode 100644
index 0000000..c19c711
--- /dev/null
+++ b/maven-release-plugin/src/it/projects/prepare/fail-on-snapshots/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.buildResult = failure
\ No newline at end of file
diff --git a/maven-release-plugin/src/it/projects/prepare/fail-on-snapshots/pom.xml b/maven-release-plugin/src/it/projects/prepare/fail-on-snapshots/pom.xml
new file mode 100644
index 0000000..317f36a
--- /dev/null
+++ b/maven-release-plugin/src/it/projects/prepare/fail-on-snapshots/pom.xml
@@ -0,0 +1,97 @@
+<?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 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/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.release.its</groupId>
+  <artifactId>fail-on-snapshot</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <scm>
+    <connection>scm:dummy|nul</connection>
+    <developerConnection>scm:dummy|nul</developerConnection>
+  </scm>
+
+  <build>
+    <extensions>
+      <extension>
+        <groupId>test</groupId>
+        <artifactId>extension</artifactId>
+        <version>1.0-SNAPSHOT</version>
+      </extension>      
+    </extensions>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-release-plugin</artifactId>
+        <version>@project.version@</version>
+        <configuration>
+          <arguments>-Dflag -Dfoo=bar</arguments>
+          <mavenExecutorId>invoker</mavenExecutorId>
+          <goals>validate</goals>
+          <preparationGoals>validate</preparationGoals>
+          <completionGoals>verify</completionGoals>
+        </configuration>
+        <dependencies>
+          <dependency>
+            <groupId>org.apache.maven.its.release</groupId>
+            <artifactId>maven-scm-provider-dummy</artifactId>
+            <version>1.0</version>
+          </dependency>
+        </dependencies>
+      </plugin>
+      <plugin>
+        <groupId>test</groupId>
+        <artifactId>plugin</artifactId>
+        <version>1.0-SNAPSHOT</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-install-plugin</artifactId>
+        <version>3.0.0</version>
+      </plugin>
+    </plugins>
+  </build>
+
+  <dependencies>
+    <dependency>
+      <groupId>test</groupId>
+      <artifactId>dependency</artifactId>
+      <version>1.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>test</groupId>
+      <artifactId>dependency.test</artifactId>
+      <version>1.0-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  
+  <reporting>
+    <plugins>
+      <plugin>
+        <groupId>test</groupId>
+        <artifactId>report</artifactId>
+        <version>1.0-SNAPSHOT</version>
+      </plugin>
+    </plugins>
+  </reporting>
+</project>
diff --git a/maven-release-plugin/src/it/projects/prepare/fail-on-snapshots/verify.groovy b/maven-release-plugin/src/it/projects/prepare/fail-on-snapshots/verify.groovy
new file mode 100644
index 0000000..7bc9f5f
--- /dev/null
+++ b/maven-release-plugin/src/it/projects/prepare/fail-on-snapshots/verify.groovy
@@ -0,0 +1,32 @@
+
+/*
+ * 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')
+def nonReleased = buildLog.readLines()
+                          .dropWhile{ !it.endsWith("Can't release project due to non released dependencies :") }
+                          .drop(1)
+                          .collect{ (it - '[ERROR]').trim() }
+                          .takeWhile{ !it.startsWith("in project 'fail-on-snapshot'") } as Set
+
+assert nonReleased == ['test:dependency:jar:1.0-SNAPSHOT:compile',
+                       'test:dependency.test:jar:1.0-SNAPSHOT:test',
+                       'test:extension:jar:1.0-SNAPSHOT',
+                       'test:plugin:maven-plugin:1.0-SNAPSHOT:runtime',                                 
+                       'test:report:maven-plugin:1.0-SNAPSHOT:runtime'] as Set
\ No newline at end of file
diff --git a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareReleaseMojo.java b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareReleaseMojo.java
index 196f727..11c0fd3 100644
--- a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareReleaseMojo.java
+++ b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareReleaseMojo.java
@@ -25,6 +25,7 @@ import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.plugins.annotations.ResolutionScope;
 import org.apache.maven.shared.release.ReleaseExecutionException;
 import org.apache.maven.shared.release.ReleaseFailureException;
 import org.apache.maven.shared.release.ReleasePrepareRequest;
@@ -44,7 +45,7 @@ import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder;
  * @version $Id$
  * @todo [!] check how this works with version ranges
  */
-@Mojo( name = "prepare", aggregator = true )
+@Mojo( name = "prepare", aggregator = true, requiresDependencyCollection = ResolutionScope.TEST )
 public class PrepareReleaseMojo
     extends AbstractScmReleaseMojo
 {