forked from mojohaus/flatten-maven-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes mojohaus#181: Support dependency ordering
- Loading branch information
Showing
5 changed files
with
136 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<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>flatten-dependency-all-simple</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.codehaus.mojo.flatten.its</groupId> | ||
<artifactId>dep</artifactId> | ||
<version>1.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.codehaus.mojo.flatten.its</groupId> | ||
<artifactId>test</artifactId> | ||
<version>2.0</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<defaultGoal>verify</defaultGoal> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>flatten-maven-plugin</artifactId> | ||
<configuration> | ||
<orderDependencies>true</orderDependencies> | ||
<flattenDependencyMode>all</flattenDependencyMode> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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 flattendPom = new File( basedir, '.flattened-pom.xml' ) | ||
assert flattendPom.exists() | ||
|
||
def flattendProject = new XmlSlurper().parse( flattendPom ) | ||
assert 1 == flattendProject.dependencies.size() | ||
assert 2 == flattendProject.dependencies.dependency.size() | ||
|
||
assert "dep" == flattendProject.dependencies.dependency[0].artifactId.text() | ||
assert "test" == flattendProject.dependencies.dependency[1].artifactId.text() | ||
|
||
|
23 changes: 23 additions & 0 deletions
23
src/main/java/org/codehaus/mojo/flatten/DependencyComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.codehaus.mojo.flatten; | ||
|
||
import org.apache.maven.model.Dependency; | ||
|
||
import java.util.Comparator; | ||
|
||
/** | ||
* Orders a {@link Dependency} through its groupId and artifactId. | ||
*/ | ||
public class DependencyComparator implements Comparator<Dependency> | ||
{ | ||
@Override | ||
public int compare( Dependency o1, Dependency o2 ) | ||
{ | ||
int c = o1.getGroupId().compareTo( o2.getGroupId() ); | ||
if ( c == 0 ) | ||
{ | ||
// Same groupId | ||
c = o1.getArtifactId().compareTo( o2.getArtifactId() ); | ||
} | ||
return c; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/test/java/org/codehaus/mojo/flatten/DependencyComparatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.codehaus.mojo.flatten; | ||
|
||
import org.apache.maven.model.Dependency; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class DependencyComparatorTest | ||
{ | ||
private final DependencyComparator comparator = new DependencyComparator(); | ||
|
||
@Test | ||
public void shouldOrder() | ||
{ | ||
List<Dependency> dependencies = new ArrayList<>(); | ||
dependencies.add( createDependency( "g", "b", "1" ) ); | ||
dependencies.add( createDependency( "g", "a", "1" ) ); | ||
dependencies.add( createDependency( "g", "c", "1" ) ); | ||
Collections.sort( dependencies, comparator ); | ||
assertThat( dependencies ).usingComparatorForType( comparator, Dependency.class ).containsExactly( | ||
createDependency( "g", "a", "1" ), | ||
createDependency( "g", "b", "1" ), | ||
createDependency( "g", "c", "1" ) ); | ||
} | ||
|
||
private Dependency createDependency( String groupId, String artifactId, String version ) | ||
{ | ||
Dependency dependency = new Dependency(); | ||
dependency.setGroupId( groupId ); | ||
dependency.setArtifactId( artifactId ); | ||
dependency.setVersion( version ); | ||
return dependency; | ||
} | ||
} |