Skip to content

Commit b5fbd23

Browse files
cstamasslawekjaranowski
authored andcommitted
[MINSTALL-179] Fix installAtEnd when module does not use m-install-p
1 parent 18052b3 commit b5fbd23

File tree

11 files changed

+272
-33
lines changed

11 files changed

+272
-33
lines changed

src/it/install-at-end-pass/module1/pom.xml

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,4 @@
2121
<version>1.0</version>
2222
</parent>
2323
<artifactId>module1</artifactId>
24-
25-
<build>
26-
<plugins>
27-
<plugin>
28-
<groupId>org.apache.maven.plugins</groupId>
29-
<artifactId>maven-enforcer-plugin</artifactId>
30-
<version>1.2</version>
31-
<executions>
32-
<execution>
33-
<id>enforce</id>
34-
<goals>
35-
<goal>enforce</goal>
36-
</goals>
37-
<configuration>
38-
<rules>
39-
<AlwaysPass/>
40-
</rules>
41-
</configuration>
42-
</execution>
43-
</executions>
44-
</plugin>
45-
</plugins>
46-
</build>
4724
</project>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
4+
license agreements. See the NOTICE file distributed with this work for additional
5+
information regarding copyright ownership. The ASF licenses this file to
6+
you under the Apache License, Version 2.0 (the "License"); you may not use
7+
this file except in compliance with the License. You may obtain a copy of
8+
the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
9+
by applicable law or agreed to in writing, software distributed under the
10+
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
11+
OF ANY KIND, either express or implied. See the License for the specific
12+
language governing permissions and limitations under the License. -->
13+
14+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
15+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
16+
<modelVersion>4.0.0</modelVersion>
17+
18+
<parent>
19+
<groupId>org.apache.maven.its.install.dae.pass</groupId>
20+
<artifactId>dae</artifactId>
21+
<version>1.0</version>
22+
</parent>
23+
<artifactId>module2</artifactId>
24+
25+
<build>
26+
<plugins>
27+
<plugin>
28+
<groupId>org.apache.maven.plugins</groupId>
29+
<artifactId>maven-install-plugin</artifactId>
30+
<executions>
31+
<execution>
32+
<id>default-install</id>
33+
<phase>none</phase>
34+
</execution>
35+
</executions>
36+
</plugin>
37+
</plugins>
38+
</build>
39+
</project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
4+
license agreements. See the NOTICE file distributed with this work for additional
5+
information regarding copyright ownership. The ASF licenses this file to
6+
you under the Apache License, Version 2.0 (the "License"); you may not use
7+
this file except in compliance with the License. You may obtain a copy of
8+
the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
9+
by applicable law or agreed to in writing, software distributed under the
10+
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
11+
OF ANY KIND, either express or implied. See the License for the specific
12+
language governing permissions and limitations under the License. -->
13+
14+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
15+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
16+
<modelVersion>4.0.0</modelVersion>
17+
18+
<parent>
19+
<groupId>org.apache.maven.its.install.dae.pass</groupId>
20+
<artifactId>dae</artifactId>
21+
<version>1.0</version>
22+
</parent>
23+
<artifactId>module3</artifactId>
24+
</project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
4+
license agreements. See the NOTICE file distributed with this work for additional
5+
information regarding copyright ownership. The ASF licenses this file to
6+
you under the Apache License, Version 2.0 (the "License"); you may not use
7+
this file except in compliance with the License. You may obtain a copy of
8+
the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
9+
by applicable law or agreed to in writing, software distributed under the
10+
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
11+
OF ANY KIND, either express or implied. See the License for the specific
12+
language governing permissions and limitations under the License. -->
13+
14+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
15+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
16+
<modelVersion>4.0.0</modelVersion>
17+
18+
<parent>
19+
<groupId>org.apache.maven.its.install.dae.pass</groupId>
20+
<artifactId>dae</artifactId>
21+
<version>1.0</version>
22+
</parent>
23+
<artifactId>module4</artifactId>
24+
25+
<!-- packaging without install plugin -->
26+
<packaging>without-install</packaging>
27+
28+
<build>
29+
<plugins>
30+
<plugin>
31+
<groupId>org.apache.maven.its.install.mock</groupId>
32+
<artifactId>mock-phase-maven-plugin</artifactId>
33+
<version>1.0</version>
34+
<extensions>true</extensions>
35+
</plugin>
36+
</plugins>
37+
</build>
38+
</project>

src/it/install-at-end-pass/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ under the License.
7171

7272
<modules>
7373
<module>module1</module>
74+
<module>module2</module>
75+
<module>module3</module>
76+
<module>module4</module>
7477
</modules>
7578

7679
</project>

src/it/install-at-end-pass/verify.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919

2020
assert new File( basedir, "../../local-repo/org/apache/maven/its/install/dae/pass/dae/1.0/dae-1.0.pom" ).exists()
2121
assert new File( basedir, "../../local-repo/org/apache/maven/its/install/dae/pass/module1/1.0/module1-1.0.pom" ).exists()
22+
assert new File( basedir, "../../local-repo/org/apache/maven/its/install/dae/pass/module3/1.0/module3-1.0.pom" ).exists()
2223

2324
File buildLog = new File( basedir, 'build.log' )
2425
assert buildLog.exists()
2526
assert buildLog.text.contains( "[INFO] Deferring install for org.apache.maven.its.install.dae.pass:dae:1.0 at end" )
27+
assert buildLog.text.contains( "[INFO] Deferring install for org.apache.maven.its.install.dae.pass:module1:1.0 at end" )
28+
assert buildLog.text.contains( "[INFO] Deferring install for org.apache.maven.its.install.dae.pass:module3:1.0 at end" )
2629

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
invoker.goals = install
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
-->
21+
22+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
24+
<modelVersion>4.0.0</modelVersion>
25+
26+
<groupId>org.apache.maven.its.install.mock</groupId>
27+
<artifactId>mock-phase-maven-plugin</artifactId>
28+
<version>1.0</version>
29+
<packaging>maven-plugin</packaging>
30+
31+
<prerequisites>
32+
<maven>@mavenVersion@</maven>
33+
</prerequisites>
34+
35+
<description>plugin with Maven phase without m-install-p</description>
36+
37+
<build>
38+
<pluginManagement>
39+
<plugins>
40+
<plugin>
41+
<groupId>org.apache.maven.plugins</groupId>
42+
<artifactId>maven-install-plugin</artifactId>
43+
<version>@project.version@</version>
44+
</plugin>
45+
<plugin>
46+
<groupId>org.apache.maven.plugins</groupId>
47+
<artifactId>maven-plugin-plugin</artifactId>
48+
<version>3.6.4</version>
49+
<configuration>
50+
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
51+
</configuration>
52+
</plugin>
53+
</plugins>
54+
</pluginManagement>
55+
</build>
56+
57+
</project>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<!--
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
-->
21+
22+
<component-set>
23+
<components>
24+
<component>
25+
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
26+
<role-hint>without-install</role-hint>
27+
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
28+
<configuration>
29+
<lifecycles>
30+
<lifecycle>
31+
<id>default</id>
32+
<phases>
33+
<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
34+
</phases>
35+
</lifecycle>
36+
</lifecycles>
37+
</configuration>
38+
</component>
39+
</components>
40+
</component-set>

src/main/java/org/apache/maven/plugins/install/InstallMojo.java

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@
2020
*/
2121

2222
import java.io.File;
23+
import java.util.ArrayList;
2324
import java.util.List;
2425
import java.util.Map;
2526

2627
import org.apache.maven.RepositoryUtils;
2728
import org.apache.maven.execution.MavenSession;
29+
import org.apache.maven.model.Plugin;
30+
import org.apache.maven.model.PluginExecution;
2831
import org.apache.maven.plugin.AbstractMojo;
2932
import org.apache.maven.plugin.MojoExecutionException;
3033
import org.apache.maven.plugin.MojoFailureException;
@@ -134,9 +137,11 @@ public void execute()
134137
}
135138
}
136139

137-
if ( allProjectsMarked() )
140+
List<MavenProject> allProjectsUsingPlugin = getAllProjectsUsingPlugin();
141+
142+
if ( allProjectsMarked( allProjectsUsingPlugin ) )
138143
{
139-
for ( MavenProject reactorProject : reactorProjects )
144+
for ( MavenProject reactorProject : allProjectsUsingPlugin )
140145
{
141146
State state = getState( reactorProject );
142147
if ( state == State.TO_BE_INSTALLED )
@@ -147,9 +152,9 @@ public void execute()
147152
}
148153
}
149154

150-
private boolean allProjectsMarked()
155+
private boolean allProjectsMarked( List<MavenProject> allProjectsUsingPlugin )
151156
{
152-
for ( MavenProject reactorProject : reactorProjects )
157+
for ( MavenProject reactorProject : allProjectsUsingPlugin )
153158
{
154159
if ( !hasState( reactorProject ) )
155160
{
@@ -159,6 +164,36 @@ private boolean allProjectsMarked()
159164
return true;
160165
}
161166

167+
private List<MavenProject> getAllProjectsUsingPlugin()
168+
{
169+
ArrayList<MavenProject> result = new ArrayList<>();
170+
for ( MavenProject reactorProject : reactorProjects )
171+
{
172+
if ( hasExecution( reactorProject.getPlugin( "org.apache.maven.plugins:maven-install-plugin" ) ) )
173+
{
174+
result.add( reactorProject );
175+
}
176+
}
177+
return result;
178+
}
179+
180+
private boolean hasExecution( Plugin plugin )
181+
{
182+
if ( plugin == null )
183+
{
184+
return false;
185+
}
186+
187+
for ( PluginExecution execution : plugin.getExecutions() )
188+
{
189+
if ( !execution.getGoals().isEmpty() && !"none".equalsIgnoreCase( execution.getPhase() ) )
190+
{
191+
return true;
192+
}
193+
}
194+
return false;
195+
}
196+
162197
private void installProject( MavenProject project ) throws MojoExecutionException, MojoFailureException
163198
{
164199
try

src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919
* under the License.
2020
*/
2121

22-
import static org.mockito.ArgumentMatchers.any;
23-
import static org.mockito.Mockito.mock;
24-
import static org.mockito.Mockito.when;
25-
2622
import java.io.File;
2723
import java.util.Collections;
2824
import java.util.List;
@@ -31,8 +27,9 @@
3127
import org.apache.maven.artifact.Artifact;
3228
import org.apache.maven.artifact.metadata.ArtifactMetadata;
3329
import org.apache.maven.execution.MavenSession;
30+
import org.apache.maven.model.Build;
31+
import org.apache.maven.model.Plugin;
3432
import org.apache.maven.plugin.AbstractMojo;
35-
import org.apache.maven.plugin.MojoExecutionException;
3633
import org.apache.maven.plugin.MojoFailureException;
3734
import org.apache.maven.plugin.descriptor.PluginDescriptor;
3835
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
@@ -48,10 +45,13 @@
4845
import org.eclipse.aether.repository.LocalRepository;
4946
import org.eclipse.aether.repository.NoLocalRepositoryManagerException;
5047

48+
import static org.mockito.ArgumentMatchers.any;
49+
import static org.mockito.Mockito.mock;
50+
import static org.mockito.Mockito.when;
51+
5152
/**
5253
* @author <a href="mailto:aramirez@apache.org">Allan Ramirez</a>
5354
*/
54-
5555
public class InstallMojoTest
5656
extends AbstractMojoTestCase
5757
{
@@ -381,5 +381,10 @@ private void updateMavenProject( MavenProject project )
381381
project.setGroupId( project.getArtifact().getGroupId() );
382382
project.setArtifactId( project.getArtifact().getArtifactId() );
383383
project.setVersion( project.getArtifact().getVersion() );
384+
385+
Plugin plugin = new Plugin();
386+
plugin.setArtifactId( "maven-install-plugin" );
387+
project.setBuild( new Build() );
388+
project.getBuild().addPlugin( plugin );
384389
}
385390
}

0 commit comments

Comments
 (0)