Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added rewriting the ${revision} for dependencies and removing the par… #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ public Artifact transformArtifact(Artifact artifact) {
logger.debug("Filtering ${revision} in <parent><version> field");
hasRevisionNumber = true;
parent.setVersion(artifact.getBaseVersion());
parent.setRelativePath("");
}

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

if (pom.getDependencyManagement() != null && pom.getDependencyManagement().getDependencies() != null) {
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,62 @@ 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'
}

def 'replace the parent path with a default path'() {
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>
<parent>
<groupId>com.github.jcgay.example.version</groupId>
<artifactId>parent-pom</artifactId>
<version>\${revision}</version>
<relativePath>../blabla</relativePath>
</parent>

<artifactId>submodule-1</artifactId>
<version>\${revision}</version>
</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.parent.relativePath == ''
}
}