Skip to content

Commit ae487a7

Browse files
committed
Set project.originalModel after flattening
Based on the discussion in maven-shade-plugin#129 apache/maven-shade-plugin#129 (comment) It seems that the flatten plugin should update the `originalModel` property after we flatten the pom.
1 parent f02b2ad commit ae487a7

File tree

7 files changed

+168
-1
lines changed

7 files changed

+168
-1
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,11 @@ For publishing the site do the following:
4242
cd target/checkout
4343
mvn verify site site:stage scm-publish:publish-scm
4444
```
45+
46+
## Writing new test cases
47+
48+
- When developing new integration test cases an easy way to only run the scenario you are working on is to create a new
49+
directory (e.g. `src/it/new-case`) and put your new `pom.xml` and `verify.groovy` in that directory. Then update the
50+
`<projectsDirectory>` path of the `run-its` profile to point to the directory containing your single test case.
51+
- You can change the goal of the maven invoker plugin by creating a file `invoker.properties`.
52+
See the `flatten-shaded-drp` for an example.

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,9 @@
250250
<goal>${project.groupId}:${project.artifactId}:${project.version}:flatten -Drevision=1.2.3.4</goal>
251251
</goals>
252252
<projectsDirectory>src/it/projects</projectsDirectory>
253-
<postBuildHookScript>verify</postBuildHookScript>
254253
<preBuildHookScript>setup</preBuildHookScript>
254+
<postBuildHookScript>verify</postBuildHookScript>
255+
<streamLogsOnFailures>true</streamLogsOnFailures>
255256
</configuration>
256257
</plugin>
257258
<plugin>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invoker.goals=package
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.codehaus.mojo.flatten.its</groupId>
5+
<artifactId>flatten-shaded-drp</artifactId>
6+
<version>0.0.1${rev}-SNAPSHOT</version>
7+
8+
<properties>
9+
<flatten.its.version>3.2.1</flatten.its.version>
10+
<rev></rev>
11+
</properties>
12+
13+
<dependencies>
14+
<dependency>
15+
<groupId>com.google.guava</groupId>
16+
<artifactId>guava</artifactId>
17+
<version>16.0.1</version>
18+
</dependency>
19+
<dependency>
20+
<groupId>org.apache.maven</groupId>
21+
<artifactId>maven-archiver</artifactId>
22+
<version>2.5</version>
23+
</dependency>
24+
</dependencies>
25+
26+
<build>
27+
<defaultGoal>package</defaultGoal>
28+
29+
<plugins>
30+
<plugin>
31+
<groupId>org.codehaus.mojo</groupId>
32+
<artifactId>flatten-maven-plugin</artifactId>
33+
<configuration>
34+
<updatePomFile>true</updatePomFile>
35+
<flattenMode>ossrh</flattenMode>
36+
<embedBuildProfileDependencies>true</embedBuildProfileDependencies>
37+
</configuration>
38+
<executions>
39+
<execution>
40+
<id>flatten</id>
41+
<phase>prepare-package</phase>
42+
<goals>
43+
<goal>flatten</goal>
44+
</goals>
45+
</execution>
46+
</executions>
47+
</plugin>
48+
49+
<plugin>
50+
<groupId>org.apache.maven.plugins</groupId>
51+
<artifactId>maven-shade-plugin</artifactId>
52+
<version>3.3.0</version>
53+
<configuration>
54+
<minimizeJar>true</minimizeJar>
55+
<createDependencyReducedPom>true</createDependencyReducedPom>
56+
<artifactSet>
57+
<includes>
58+
<include>com.google.guava:*</include>
59+
</includes>
60+
</artifactSet>
61+
</configuration>
62+
<executions>
63+
<execution>
64+
<id>shade</id>
65+
<phase>package</phase>
66+
<goals>
67+
<goal>shade</goal>
68+
</goals>
69+
</execution>
70+
</executions>
71+
</plugin>
72+
</plugins>
73+
</build>
74+
75+
<!-- should be removed -->
76+
<profiles>
77+
<profile>
78+
<id>foo</id>
79+
<activation>
80+
<property>
81+
<name>willNotBeActive</name>
82+
</property>
83+
</activation>
84+
85+
<dependencies>
86+
<dependency>
87+
<groupId>org.codehaus.mojo.flatten.its</groupId>
88+
<artifactId>core</artifactId>
89+
<version>${flatten.its.version}</version>
90+
</dependency>
91+
</dependencies>
92+
</profile>
93+
</profiles>
94+
95+
<pluginRepositories>
96+
<pluginRepository>
97+
<id>no-one</id>
98+
<url>@repository.proxy.url@</url>
99+
</pluginRepository>
100+
</pluginRepositories>
101+
102+
103+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.example;
2+
3+
import java.util.List;
4+
import com.google.common.collect.ImmutableList;
5+
import org.apache.maven.archiver.MavenArchiver;
6+
7+
public class Main {
8+
public static void main(String[] args) {
9+
List<Object> l = ImmutableList.of();
10+
MavenArchiver a = new MavenArchiver();
11+
}
12+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
File originalPom = new File( basedir, 'pom.xml' )
20+
assert originalPom.exists()
21+
22+
def originalProject = new XmlSlurper().parse( originalPom )
23+
assert 1 == originalProject.dependencies.size()
24+
assert 2 == originalProject.dependencies.dependency.size()
25+
26+
File flattendPom = new File( basedir, 'dependency-reduced-pom.xml' )
27+
assert flattendPom.exists()
28+
29+
def flattendProject = new XmlSlurper().parse( flattendPom )
30+
assert 1 == flattendProject.dependencies.size()
31+
assert 1 == flattendProject.dependencies.dependency.size()
32+
33+
def archiver = flattendProject.dependencies.dependency.find {
34+
it.groupId == 'org.apache.maven' && it.artifactId == 'maven-archiver'
35+
}
36+
assert '2.5' == archiver.version.text()
37+
assert 'compile' == archiver.scope.text()
38+
39+
assert 0 == originalProject.build.size()
40+
assert 0 == originalProject.profiles.size()
41+
assert 0 == originalProject.pluginRepositories.size()

src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ public void execute()
396396
if ( isUpdatePomFile() )
397397
{
398398
this.project.setPomFile( flattenedPomFile );
399+
this.project.setOriginalModel( flattenedPom );
399400
}
400401
}
401402

0 commit comments

Comments
 (0)