Skip to content

Commit

Permalink
Rewrites ${revision} for dependencies
Browse files Browse the repository at this point in the history
Fixes #22
  • Loading branch information
Tijs-2 authored and jcgay committed Aug 15, 2020
1 parent 3b46319 commit e3e1433
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
<cloneClean>true</cloneClean>
<showVersion>true</showVersion>
<postBuildHookScript>verify</postBuildHookScript>
<setupIncludes>
<setupInclude>artifact-installer/pom.xml</setupInclude>
</setupIncludes>
</configuration>
<executions>
<execution>
Expand Down
1 change: 1 addition & 0 deletions src/it/artifact-installer/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals = install
15 changes: 15 additions & 0 deletions src/it/artifact-installer/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>fr.jcgay.maven.extension.urmf</groupId>
<artifactId>replace-revision-in-pom-dependencies</artifactId>
<version>1.0-SNAPSHOT</version>

<description>
artifact used as dependencies in ITs
</description>

</project>
8 changes: 8 additions & 0 deletions src/it/replace-revision-in-pom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>fr.jcgay.maven.extension.urmf</groupId>
<artifactId>replace-revision-in-pom-dependencies</artifactId>
<version>${revision}</version>
</dependency>
</dependencies>

</project>
1 change: 1 addition & 0 deletions src/it/replace-revision-in-pom/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ File pom = new File("$localRepositoryPath/fr/jcgay/maven/extension/urmf/replace-
def project = new XmlSlurper().parse(pom)
assert project.version == '1.0-SNAPSHOT'
assert project.dependencyManagement.dependencies[0].dependency.version == '1.0-SNAPSHOT'
assert project.dependencies[0].dependency.version == '1.0-SNAPSHOT'

return true
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ public Artifact transformArtifact(Artifact artifact) {
parent.setVersion(artifact.getBaseVersion());
}

if (pom.getDependencies() != null) {
for (Dependency dependency : pom.getDependencies()) {
if (isRevision(dependency.getVersion())) {
logger.debug("Filtering ${revision} in dependency " + dependency.getGroupId() + ":" + dependency.getArtifactId());
dependency.setVersion(artifact.getBaseVersion());
hasRevisionNumber = true;
}
}
}

if (pom.getDependencyManagement() != null && pom.getDependencyManagement().getDependencies() != null) {
for (Dependency dependency : pom.getDependencyManagement().getDependencies()) {
if (isRevision(dependency.getVersion())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class UniqueRevisionFilteringTest extends Specification {
<groupId>com.github.jcgay.example.version</groupId>
<artifactId>dep-mgmt-test</artifactId>
<version>\${revision}</version>
<dependencyManagement>
<dependencies>
<dependency>
Expand All @@ -189,4 +189,35 @@ class UniqueRevisionFilteringTest extends Specification {
project.version == '1.0-SNAPSHOT'
project.dependencyManagement.dependencies[0].dependency.version == '1.0-SNAPSHOT'
}

def 'updates versions in dependencies that are set to ${revision}'() {
given:
pom << """<?xml version="1.0" encoding="UTF-8"?>
<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>com.github.jcgay.example.version</groupId>
<artifactId>dep-mgmt-test</artifactId>
<version>\${revision}</version>
<dependencies>
<dependency>
<groupId>com.github.jcgay.example.version</groupId>
<artifactId>dep-mgmt-test-commons</artifactId>
<version>\${revision}</version>
</dependency>
</dependencies>
</project>
"""
def artifact = new SubArtifact(new DefaultArtifact('fr.jcgay.test', 'jar-id', 'jar', '1.0-SNAPSHOT'), null, 'pom', pom)

when:
def result = uniqueRevision.transformArtifact(artifact)

then:
def project = new XmlSlurper().parse(result.file)
project.version == '1.0-SNAPSHOT'
project.dependencies[0].dependency.version == '1.0-SNAPSHOT'
}
}

0 comments on commit e3e1433

Please sign in to comment.