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

Remove transformPom #520

Merged
merged 1 commit into from
Apr 11, 2023
Merged
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
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.