Skip to content

Commit

Permalink
Remove transformPom (#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed Apr 11, 2023
1 parent df344cd commit 2e05ec6
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 331 deletions.
38 changes: 0 additions & 38 deletions src/main/java/org/jenkins/tools/test/model/MavenPom.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
Expand Down Expand Up @@ -85,43 +84,6 @@ private MavenPom(File rootDir, String pomFileName) {
this.pomFileName = pomFileName;
}

public void transformPom(Dependency coreCoordinates) throws PomTransformationException {
File pom = new File(rootDir.getAbsolutePath() + "/" + pomFileName);
File backupPom = new File(rootDir.getAbsolutePath() + "/" + pomFileName + ".backup");
try {
Files.move(pom.toPath(), backupPom.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new UncheckedIOException(e);
}

Document doc;
try {
doc = new SAXReader().read(backupPom);
} catch (DocumentException x) {
throw new PomTransformationException("Failed to parse pom.xml", x);
}

Element parent = doc.getRootElement().element("parent");
if (parent != null) {
Element groupIdElem = parent.element(GROUP_ID_ELEMENT);
if (groupIdElem != null) {
groupIdElem.setText(coreCoordinates.getGroupId());
}

Element artifactIdElem = parent.element(ARTIFACT_ID_ELEMENT);
if (artifactIdElem != null) {
artifactIdElem.setText(coreCoordinates.getArtifactId());
}

Element versionIdElem = parent.element(VERSION_ELEMENT);
if (versionIdElem != null) {
versionIdElem.setText(coreCoordinates.getVersion());
}
}

writeDocument(pom, doc);
}

/** Removes the dependency if it exists. */
public void removeDependency(@NonNull String groupId, @NonNull String artifactId)
throws PomTransformationException {
Expand Down
17 changes: 0 additions & 17 deletions src/test/java/org/jenkins/tools/test/model/MavenPomTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.List;
import java.util.Map;
import org.apache.commons.io.FileUtils;
import org.apache.maven.model.Dependency;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.jvnet.hudson.test.Issue;
Expand Down Expand Up @@ -160,22 +159,6 @@ void addDependenciesWithTestsClassifier(@TempDir File prj) throws Exception {
assertResourceEqualsXmlFile("credentials-binding-pom-after.xml", pom);
}

@Issue("https://github.com/jenkinsci/plugin-compat-tester/pull/287")
@Test
void transformPOMwithSpecialCharacters(@TempDir File folder) throws Exception {
File pomFile = createPomFileFromResource(folder, "demo-plugin-pom-before.xml");

Dependency coreCoordinates = new Dependency();
coreCoordinates.setGroupId("org.jenkins-ci.plugins");
coreCoordinates.setArtifactId("plugin");
coreCoordinates.setVersion("2.235.1");

MavenPom mavenPom = new MavenPom(pomFile.getParentFile());
mavenPom.transformPom(coreCoordinates);

assertResourceEqualsXmlFile("demo-plugin-pom-after.xml", pomFile);
}

@Test
void doNotDuplicateDependenciesWhoseVersionsAreProperties(@TempDir File folder) throws Exception {
File pomFile = createPomFileFromResource(folder, "demo-plugin-properties-pom-before.xml");
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 2e05ec6

Please sign in to comment.