Skip to content

Commit

Permalink
Fixes #145, #148 add codes to parse the <version> for the dependency …
Browse files Browse the repository at this point in the history
…in profile which is managed by <dependencyManagement> (#155)

* Fixes #145, #148 add codes to parse the <version> for the dependency in profile which is managed by <dependencyManagement>

* remove redundant code

* add empty line at the end of files

* remove profile-with-deps-inherit-parent-depMgmt-ci test

* consolidate two blocks of code change into createCleanPom method

* restore import change

* restore import change

* add test profile-with-deps-inherit-parent-depMgmt-flatten-dep-all-oss

* change test profile-with-deps-inherit-parent-depMgmt-flatten-dep-all-oss to profile-with-deps-inherit-parent-depMgmt-flatten-dep-all-oss-bom

* code style fix

* fix indents and licenses declaration in verify.groovy

* set scope as compile and optional as false if not specified

* fix scope and optional - code style

Co-authored-by: yangnuoyu <yangnuoyu@penguin>
  • Loading branch information
yangnuoyu and yangnuoyu committed Jun 5, 2020
1 parent 6b5779f commit b99ef48
Show file tree
Hide file tree
Showing 39 changed files with 1,137 additions and 14 deletions.
14 changes: 13 additions & 1 deletion src/it/projects/external-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,19 @@
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
</dependencies>
</dependencies>

<profiles>
<profile>
<id> test </id>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>


<dependencyManagement>
Expand Down
6 changes: 6 additions & 0 deletions src/it/projects/external-parent/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,9 @@ assert 1 == flattendProject.dependencies.size()
assert 1 == flattendProject.dependencies.dependency.size()
assert '4.0.5.RELEASE' == flattendProject.dependencies.dependency[0].version.text()

assert 1 == flattendProject.profiles.size()
assert 1 == flattendProject.profiles.profile.size()
assert 'test' == flattendProject.profiles.profile.id.text()
assert 1 == flattendProject.profiles.profile.dependencies.size()
assert 1 == flattendProject.profiles.profile.dependencies.dependency.size()
assert '1.1.0.RELEASE' == flattendProject.profiles.profile.dependencies.dependency.version.text()
25 changes: 25 additions & 0 deletions src/it/projects/fat-jar/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,38 @@
<!-- https://github.com/mojohaus/flatten-maven-plugin/issues/47 -->
<artifactId>fatjar-dependency-remove</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>parent-depMngt</artifactId>
<version>2</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>dep1</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>test</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
<profiles>
<profile>
<id> test2 </id>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>dep</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
<build>
<defaultGoal>verify</defaultGoal>
<plugins>
Expand Down
8 changes: 8 additions & 0 deletions src/it/projects/fat-jar/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@ assert flattendPom.exists()

def flattendProject = new XmlSlurper().parse( flattendPom )
assert 0 == flattendProject.dependencies.size()
assert 0 == flattendProject.dependencyManagement.size()
assert 1 == flattendProject.profiles.size()
assert 1 == flattendProject.profiles.profile.size()
assert 'test2' == flattendProject.profiles.profile.id.text()
assert 1 == flattendProject.profiles.profile.dependencies.size()
assert 1 == flattendProject.profiles.profile.dependencies.dependency.size()
assert 'dep' == flattendProject.profiles.profile.dependencies.dependency.artifactId.text()
assert '1.1' == flattendProject.profiles.profile.dependencies.dependency.version.text()
14 changes: 12 additions & 2 deletions src/it/projects/optional-elements-modeOss/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,15 @@
</scm>

<url>http://mojo.codehaus.org</url>

</project>
<profiles>
<profile>
<id>test</id>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>dep</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
7 changes: 7 additions & 0 deletions src/it/projects/optional-elements-modeOss/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,10 @@ assert 0 == flattendProject.reports.size()
assert 1 == flattendProject.scm.size()
assert 1 == flattendProject.url.size()

assert 1 == flattendProject.profiles.size()
assert 1 == flattendProject.profiles.profile.size()
assert 'test' == flattendProject.profiles.profile.id.text()
assert 1 == flattendProject.profiles.profile.dependencies.size()
assert 1 == flattendProject.profiles.profile.dependencies.dependency.size()
assert 'dep' == flattendProject.profiles.profile.dependencies.dependency.artifactId.text()
assert '1.1' == flattendProject.profiles.profile.dependencies.dependency.version.text()
14 changes: 12 additions & 2 deletions src/it/projects/optional-elements-modeOssrh/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,15 @@
</scm>

<url>http://mojo.codehaus.org</url>

</project>
<profiles>
<profile>
<id>test</id>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>dep</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
8 changes: 8 additions & 0 deletions src/it/projects/optional-elements-modeOssrh/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,11 @@ assert 0 == flattendProject.reports.size()
assert 1 == flattendProject.scm.size()
assert 1 == flattendProject.url.size()

assert 1 == flattendProject.profiles.size()
assert 1 == flattendProject.profiles.profile.size()
assert 'test' == flattendProject.profiles.profile.id.text()
assert 1 == flattendProject.profiles.profile.dependencies.size()
assert 1 == flattendProject.profiles.profile.dependencies.dependency.size()
assert 'dep' == flattendProject.profiles.profile.dependencies.dependency.artifactId.text()
assert '1.1' == flattendProject.profiles.profile.dependencies.dependency.version.text()

14 changes: 13 additions & 1 deletion src/it/projects/optional-elements-pomElements-legacy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,16 @@

<url>http://mojo.codehaus.org</url>

</project>
<profiles>
<profile>
<id>test</id>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>dep</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,11 @@ assert 0 == flattendProject.reports.size()
assert 1 == flattendProject.scm.size()
assert 1 == flattendProject.url.size()

assert 1 == flattendProject.profiles.size()
assert 1 == flattendProject.profiles.profile.size()
assert 'test' == flattendProject.profiles.profile.id.text()
assert 1 == flattendProject.profiles.profile.dependencies.size()
assert 1 == flattendProject.profiles.profile.dependencies.dependency.size()
assert 'dep' == flattendProject.profiles.profile.dependencies.dependency.artifactId.text()
assert '1.1' == flattendProject.profiles.profile.dependencies.dependency.version.text()

15 changes: 13 additions & 2 deletions src/it/projects/optional-elements-pomElements-suggested/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,16 @@
</configuration>
</plugin>
</plugins>
</build>
</project>
</build>
<profiles>
<profile>
<id>test</id>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>dep</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,11 @@ assert 0 == flattendProject.properties.size()
assert 0 == flattendProject.reporting.size()
assert 0 == flattendProject.reports.size()

assert 1 == flattendProject.profiles.size()
assert 1 == flattendProject.profiles.profile.size()
assert 'test' == flattendProject.profiles.profile.id.text()
assert 1 == flattendProject.profiles.profile.dependencies.size()
assert 1 == flattendProject.profiles.profile.dependencies.dependency.size()
assert 'dep' == flattendProject.profiles.profile.dependencies.dependency.artifactId.text()
assert '1.1' == flattendProject.profiles.profile.dependencies.dependency.version.text()

42 changes: 42 additions & 0 deletions src/it/projects/profile-with-deps-import/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<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.codehaus.mojo.flatten.its</groupId>
<artifactId>profile-with-deps-import</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>parent-depMngt</artifactId>
<version>2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<profiles>
<profile>
<id>test</id>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>dep</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
34 changes: 34 additions & 0 deletions src/it/projects/profile-with-deps-import/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.
*/
File originalPom = new File( basedir, 'pom.xml' )
assert originalPom.exists()

def originalProject = new XmlSlurper().parse( originalPom )
assert 0 == originalProject.dependencies.size()
assert 'test' == originalProject.profiles.profile.id.text()
assert 1 == originalProject.profiles.profile.dependencies.size()

File flattendPom = new File( basedir, '.flattened-pom.xml' )
assert flattendPom.exists()

def flattendProject = new XmlSlurper().parse( flattendPom )
assert 0 == flattendProject.dependencies.size()
assert 1 == flattendProject.profiles.profile.dependencies.size()
assert 'dep' == flattendProject.profiles.profile.dependencies.dependency.artifactId.text()
assert '1.1' == flattendProject.profiles.profile.dependencies.dependency.version.text()
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<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.codehaus.mojo.flatten.its</groupId>
<artifactId>profile-with-deps-inherit-parent-depMgmt-flatten-dep-all-active_parent</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>core</artifactId>
<version>3.2.1</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<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.codehaus.mojo.flatten.its</groupId>
<artifactId>profile-with-deps-inherit-parent-depMgmt-flatten-dep-all-active</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>profile-with-deps-inherit-parent-depMgmt-flatten-dep-all-active_parent</artifactId>
<version>0.1-SNAPSHOT</version>
<relativePath>parent</relativePath>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<configuration>
<flattenDependencyMode>all</flattenDependencyMode>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>test</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>core</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.
*/
File originalPom = new File( basedir, 'pom.xml' )
assert originalPom.exists()

def originalProject = new XmlSlurper().parse( originalPom )
assert 0 == originalProject.dependencies.size()
assert 'test' == originalProject.profiles.profile.id.text()
assert 1 == originalProject.profiles.profile.dependencies.size()

File flattendPom = new File( basedir, '.flattened-pom.xml' )
assert flattendPom.exists()

def flattendProject = new XmlSlurper().parse( flattendPom )
assert 2 == flattendProject.dependencies.dependency.size()
assert 'core' == flattendProject.dependencies.dependency[0].artifactId.text()
assert 1 == flattendProject.dependencies.dependency[0].exclusions.exclusion.size()
assert 'dep' == flattendProject.dependencies.dependency[1].artifactId.text()
assert 1 == flattendProject.profiles.profile.dependencies.dependency.size()
assert 'core' == flattendProject.profiles.profile.dependencies.dependency.artifactId.text()
assert '3.2.1' == flattendProject.profiles.profile.dependencies.dependency.version.text()
Loading

0 comments on commit b99ef48

Please sign in to comment.