This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-install-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new b5fbd23 [MINSTALL-179] Fix installAtEnd when module does not use
m-install-p
b5fbd23 is described below
commit b5fbd2340e3f3d87746bfcb95eca48fa3f043bc0
Author: Tamas Cservenak <[email protected]>
AuthorDate: Thu Oct 20 09:21:32 2022 +0200
[MINSTALL-179] Fix installAtEnd when module does not use m-install-p
---
src/it/install-at-end-pass/module1/pom.xml | 23 ---------
.../{module1 => module2}/pom.xml | 16 ++----
.../{module1 => module3}/pom.xml | 25 +---------
.../{module1 => module4}/pom.xml | 25 +++-------
src/it/install-at-end-pass/pom.xml | 3 ++
src/it/install-at-end-pass/verify.groovy | 3 ++
.../invoker.properties | 18 +++++++
src/it/setup-mock-phase-maven-plugin/pom.xml | 57 ++++++++++++++++++++++
.../main/resources/META-INF/plexus/components.xml | 40 +++++++++++++++
.../apache/maven/plugins/install/InstallMojo.java | 43 ++++++++++++++--
.../maven/plugins/install/InstallMojoTest.java | 17 ++++---
11 files changed, 184 insertions(+), 86 deletions(-)
diff --git a/src/it/install-at-end-pass/module1/pom.xml
b/src/it/install-at-end-pass/module1/pom.xml
index 904addf..31279ce 100644
--- a/src/it/install-at-end-pass/module1/pom.xml
+++ b/src/it/install-at-end-pass/module1/pom.xml
@@ -21,27 +21,4 @@
<version>1.0</version>
</parent>
<artifactId>module1</artifactId>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-enforcer-plugin</artifactId>
- <version>1.2</version>
- <executions>
- <execution>
- <id>enforce</id>
- <goals>
- <goal>enforce</goal>
- </goals>
- <configuration>
- <rules>
- <AlwaysPass/>
- </rules>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
</project>
diff --git a/src/it/install-at-end-pass/module1/pom.xml
b/src/it/install-at-end-pass/module2/pom.xml
similarity index 80%
copy from src/it/install-at-end-pass/module1/pom.xml
copy to src/it/install-at-end-pass/module2/pom.xml
index 904addf..f78eb0d 100644
--- a/src/it/install-at-end-pass/module1/pom.xml
+++ b/src/it/install-at-end-pass/module2/pom.xml
@@ -20,25 +20,17 @@
<artifactId>dae</artifactId>
<version>1.0</version>
</parent>
- <artifactId>module1</artifactId>
+ <artifactId>module2</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-enforcer-plugin</artifactId>
- <version>1.2</version>
+ <artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
- <id>enforce</id>
- <goals>
- <goal>enforce</goal>
- </goals>
- <configuration>
- <rules>
- <AlwaysPass/>
- </rules>
- </configuration>
+ <id>default-install</id>
+ <phase>none</phase>
</execution>
</executions>
</plugin>
diff --git a/src/it/install-at-end-pass/module1/pom.xml
b/src/it/install-at-end-pass/module3/pom.xml
similarity index 67%
copy from src/it/install-at-end-pass/module1/pom.xml
copy to src/it/install-at-end-pass/module3/pom.xml
index 904addf..2d346db 100644
--- a/src/it/install-at-end-pass/module1/pom.xml
+++ b/src/it/install-at-end-pass/module3/pom.xml
@@ -20,28 +20,5 @@
<artifactId>dae</artifactId>
<version>1.0</version>
</parent>
- <artifactId>module1</artifactId>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-enforcer-plugin</artifactId>
- <version>1.2</version>
- <executions>
- <execution>
- <id>enforce</id>
- <goals>
- <goal>enforce</goal>
- </goals>
- <configuration>
- <rules>
- <AlwaysPass/>
- </rules>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
+ <artifactId>module3</artifactId>
</project>
diff --git a/src/it/install-at-end-pass/module1/pom.xml
b/src/it/install-at-end-pass/module4/pom.xml
similarity index 72%
copy from src/it/install-at-end-pass/module1/pom.xml
copy to src/it/install-at-end-pass/module4/pom.xml
index 904addf..cb4ca5f 100644
--- a/src/it/install-at-end-pass/module1/pom.xml
+++ b/src/it/install-at-end-pass/module4/pom.xml
@@ -20,27 +20,18 @@
<artifactId>dae</artifactId>
<version>1.0</version>
</parent>
- <artifactId>module1</artifactId>
+ <artifactId>module4</artifactId>
+
+ <!-- packaging without install plugin -->
+ <packaging>without-install</packaging>
<build>
<plugins>
<plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-enforcer-plugin</artifactId>
- <version>1.2</version>
- <executions>
- <execution>
- <id>enforce</id>
- <goals>
- <goal>enforce</goal>
- </goals>
- <configuration>
- <rules>
- <AlwaysPass/>
- </rules>
- </configuration>
- </execution>
- </executions>
+ <groupId>org.apache.maven.its.install.mock</groupId>
+ <artifactId>mock-phase-maven-plugin</artifactId>
+ <version>1.0</version>
+ <extensions>true</extensions>
</plugin>
</plugins>
</build>
diff --git a/src/it/install-at-end-pass/pom.xml
b/src/it/install-at-end-pass/pom.xml
index 39d1e6d..5149bb7 100644
--- a/src/it/install-at-end-pass/pom.xml
+++ b/src/it/install-at-end-pass/pom.xml
@@ -71,6 +71,9 @@ under the License.
<modules>
<module>module1</module>
+ <module>module2</module>
+ <module>module3</module>
+ <module>module4</module>
</modules>
</project>
diff --git a/src/it/install-at-end-pass/verify.groovy
b/src/it/install-at-end-pass/verify.groovy
index f1b7e51..2d4ea4b 100644
--- a/src/it/install-at-end-pass/verify.groovy
+++ b/src/it/install-at-end-pass/verify.groovy
@@ -19,8 +19,11 @@
assert new File( basedir,
"../../local-repo/org/apache/maven/its/install/dae/pass/dae/1.0/dae-1.0.pom"
).exists()
assert new File( basedir,
"../../local-repo/org/apache/maven/its/install/dae/pass/module1/1.0/module1-1.0.pom"
).exists()
+assert new File( basedir,
"../../local-repo/org/apache/maven/its/install/dae/pass/module3/1.0/module3-1.0.pom"
).exists()
File buildLog = new File( basedir, 'build.log' )
assert buildLog.exists()
assert buildLog.text.contains( "[INFO] Deferring install for
org.apache.maven.its.install.dae.pass:dae:1.0 at end" )
+assert buildLog.text.contains( "[INFO] Deferring install for
org.apache.maven.its.install.dae.pass:module1:1.0 at end" )
+assert buildLog.text.contains( "[INFO] Deferring install for
org.apache.maven.its.install.dae.pass:module3:1.0 at end" )
diff --git a/src/it/setup-mock-phase-maven-plugin/invoker.properties
b/src/it/setup-mock-phase-maven-plugin/invoker.properties
new file mode 100644
index 0000000..d5d6ca5
--- /dev/null
+++ b/src/it/setup-mock-phase-maven-plugin/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.goals = install
diff --git a/src/it/setup-mock-phase-maven-plugin/pom.xml
b/src/it/setup-mock-phase-maven-plugin/pom.xml
new file mode 100644
index 0000000..d0d5595
--- /dev/null
+++ b/src/it/setup-mock-phase-maven-plugin/pom.xml
@@ -0,0 +1,57 @@
+<?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>org.apache.maven.its.install.mock</groupId>
+ <artifactId>mock-phase-maven-plugin</artifactId>
+ <version>1.0</version>
+ <packaging>maven-plugin</packaging>
+
+ <prerequisites>
+ <maven>@mavenVersion@</maven>
+ </prerequisites>
+
+ <description>plugin with Maven phase without m-install-p</description>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <version>@project.version@</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <version>3.6.4</version>
+ <configuration>
+ <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+</project>
diff --git
a/src/it/setup-mock-phase-maven-plugin/src/main/resources/META-INF/plexus/components.xml
b/src/it/setup-mock-phase-maven-plugin/src/main/resources/META-INF/plexus/components.xml
new file mode 100644
index 0000000..55eb892
--- /dev/null
+++
b/src/it/setup-mock-phase-maven-plugin/src/main/resources/META-INF/plexus/components.xml
@@ -0,0 +1,40 @@
+<?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.
+-->
+
+<component-set>
+ <components>
+ <component>
+ <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
+ <role-hint>without-install</role-hint>
+
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
+ <configuration>
+ <lifecycles>
+ <lifecycle>
+ <id>default</id>
+ <phases>
+
<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
+ </phases>
+ </lifecycle>
+ </lifecycles>
+ </configuration>
+ </component>
+ </components>
+</component-set>
diff --git a/src/main/java/org/apache/maven/plugins/install/InstallMojo.java
b/src/main/java/org/apache/maven/plugins/install/InstallMojo.java
index a6c694b..5f06261 100644
--- a/src/main/java/org/apache/maven/plugins/install/InstallMojo.java
+++ b/src/main/java/org/apache/maven/plugins/install/InstallMojo.java
@@ -20,11 +20,14 @@ package org.apache.maven.plugins.install;
*/
import java.io.File;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.maven.RepositoryUtils;
import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.PluginExecution;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -134,9 +137,11 @@ public class InstallMojo
}
}
- if ( allProjectsMarked() )
+ List<MavenProject> allProjectsUsingPlugin =
getAllProjectsUsingPlugin();
+
+ if ( allProjectsMarked( allProjectsUsingPlugin ) )
{
- for ( MavenProject reactorProject : reactorProjects )
+ for ( MavenProject reactorProject : allProjectsUsingPlugin )
{
State state = getState( reactorProject );
if ( state == State.TO_BE_INSTALLED )
@@ -147,9 +152,9 @@ public class InstallMojo
}
}
- private boolean allProjectsMarked()
+ private boolean allProjectsMarked( List<MavenProject>
allProjectsUsingPlugin )
{
- for ( MavenProject reactorProject : reactorProjects )
+ for ( MavenProject reactorProject : allProjectsUsingPlugin )
{
if ( !hasState( reactorProject ) )
{
@@ -159,6 +164,36 @@ public class InstallMojo
return true;
}
+ private List<MavenProject> getAllProjectsUsingPlugin()
+ {
+ ArrayList<MavenProject> result = new ArrayList<>();
+ for ( MavenProject reactorProject : reactorProjects )
+ {
+ if ( hasExecution( reactorProject.getPlugin(
"org.apache.maven.plugins:maven-install-plugin" ) ) )
+ {
+ result.add( reactorProject );
+ }
+ }
+ return result;
+ }
+
+ private boolean hasExecution( Plugin plugin )
+ {
+ if ( plugin == null )
+ {
+ return false;
+ }
+
+ for ( PluginExecution execution : plugin.getExecutions() )
+ {
+ if ( !execution.getGoals().isEmpty() && !"none".equalsIgnoreCase(
execution.getPhase() ) )
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
private void installProject( MavenProject project ) throws
MojoExecutionException, MojoFailureException
{
try
diff --git
a/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java
b/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java
index 57fe471..04c26e2 100644
--- a/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java
@@ -19,10 +19,6 @@ package org.apache.maven.plugins.install;
* under the License.
*/
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
import java.io.File;
import java.util.Collections;
import java.util.List;
@@ -31,8 +27,9 @@ import java.util.concurrent.ConcurrentHashMap;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.Build;
+import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
@@ -48,10 +45,13 @@ import
org.eclipse.aether.internal.impl.EnhancedLocalRepositoryManagerFactory;
import org.eclipse.aether.repository.LocalRepository;
import org.eclipse.aether.repository.NoLocalRepositoryManagerException;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
/**
* @author <a href="mailto:[email protected]">Allan Ramirez</a>
*/
-
public class InstallMojoTest
extends AbstractMojoTestCase
{
@@ -381,5 +381,10 @@ public class InstallMojoTest
project.setGroupId( project.getArtifact().getGroupId() );
project.setArtifactId( project.getArtifact().getArtifactId() );
project.setVersion( project.getArtifact().getVersion() );
+
+ Plugin plugin = new Plugin();
+ plugin.setArtifactId( "maven-install-plugin" );
+ project.setBuild( new Build() );
+ project.getBuild().addPlugin( plugin );
}
}