Skip to content

Commit

Permalink
[MINSTALL-179] Fix installAtEnd when module does not use m-install-p
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas authored and slawekjaranowski committed Oct 28, 2022
1 parent 18052b3 commit b5fbd23
Show file tree
Hide file tree
Showing 11 changed files with 272 additions and 33 deletions.
23 changes: 0 additions & 23 deletions src/it/install-at-end-pass/module1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
39 changes: 39 additions & 0 deletions src/it/install-at-end-pass/module2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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>

<parent>
<groupId>org.apache.maven.its.install.dae.pass</groupId>
<artifactId>dae</artifactId>
<version>1.0</version>
</parent>
<artifactId>module2</artifactId>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>default-install</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
24 changes: 24 additions & 0 deletions src/it/install-at-end-pass/module3/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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>

<parent>
<groupId>org.apache.maven.its.install.dae.pass</groupId>
<artifactId>dae</artifactId>
<version>1.0</version>
</parent>
<artifactId>module3</artifactId>
</project>
38 changes: 38 additions & 0 deletions src/it/install-at-end-pass/module4/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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>

<parent>
<groupId>org.apache.maven.its.install.dae.pass</groupId>
<artifactId>dae</artifactId>
<version>1.0</version>
</parent>
<artifactId>module4</artifactId>

<!-- packaging without install plugin -->
<packaging>without-install</packaging>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.install.mock</groupId>
<artifactId>mock-phase-maven-plugin</artifactId>
<version>1.0</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
3 changes: 3 additions & 0 deletions src/it/install-at-end-pass/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ under the License.

<modules>
<module>module1</module>
<module>module2</module>
<module>module3</module>
<module>module4</module>
</modules>

</project>
3 changes: 3 additions & 0 deletions src/it/install-at-end-pass/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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" )

18 changes: 18 additions & 0 deletions src/it/setup-mock-phase-maven-plugin/invoker.properties
Original file line number Diff line number Diff line change
@@ -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
57 changes: 57 additions & 0 deletions src/it/setup-mock-phase-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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>
43 changes: 39 additions & 4 deletions src/main/java/org/apache/maven/plugins/install/InstallMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
*/

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;
Expand Down Expand Up @@ -134,9 +137,11 @@ public void execute()
}
}

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 )
Expand All @@ -147,9 +152,9 @@ public void execute()
}
}

private boolean allProjectsMarked()
private boolean allProjectsMarked( List<MavenProject> allProjectsUsingPlugin )
{
for ( MavenProject reactorProject : reactorProjects )
for ( MavenProject reactorProject : allProjectsUsingPlugin )
{
if ( !hasState( reactorProject ) )
{
Expand All @@ -159,6 +164,36 @@ private boolean allProjectsMarked()
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
* 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;
Expand All @@ -31,8 +27,9 @@
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;
Expand All @@ -48,10 +45,13 @@
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:aramirez@apache.org">Allan Ramirez</a>
*/

public class InstallMojoTest
extends AbstractMojoTestCase
{
Expand Down Expand Up @@ -381,5 +381,10 @@ private void updateMavenProject( MavenProject project )
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 );
}
}

0 comments on commit b5fbd23

Please sign in to comment.