diff --git a/.github/workflows/analysis.yml b/.github/workflows/analysis.yml index 2757ccd..868d506 100644 --- a/.github/workflows/analysis.yml +++ b/.github/workflows/analysis.yml @@ -13,7 +13,7 @@ jobs: uses: actions/setup-java@v3 with: distribution: "temurin" - java-version: "11" + java-version: "8" # Run static code analysis - name: Run spotbugs:check diff --git a/.github/workflows/frogbot-scan-and-fix.yml b/.github/workflows/frogbot-scan-and-fix.yml index 56f06e4..efdb64d 100644 --- a/.github/workflows/frogbot-scan-and-fix.yml +++ b/.github/workflows/frogbot-scan-and-fix.yml @@ -24,7 +24,7 @@ jobs: - name: Set up Java uses: actions/setup-java@v3 with: - java-version: "11" + java-version: "8" distribution: "adopt" - uses: jfrog/frogbot@v2 diff --git a/.github/workflows/frogbot-scan-pr.yml b/.github/workflows/frogbot-scan-pr.yml index fe92ca3..c40ff4e 100644 --- a/.github/workflows/frogbot-scan-pr.yml +++ b/.github/workflows/frogbot-scan-pr.yml @@ -20,7 +20,7 @@ jobs: - name: Set up Java uses: actions/setup-java@v3 with: - java-version: "11" + java-version: "8" distribution: "temurin" - uses: jfrog/frogbot@v2 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index db54456..dba87c4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: uses: actions/setup-java@v3 with: distribution: "temurin" - java-version: "11" + java-version: "8" # Install the plugin to allow running the integration tests - name: Install plugin diff --git a/.jfrog-pipelines/release/pipelines.release.yml b/.jfrog-pipelines/release/pipelines.release.yml index 37010b9..683208c 100644 --- a/.jfrog-pipelines/release/pipelines.release.yml +++ b/.jfrog-pipelines/release/pipelines.release.yml @@ -7,7 +7,7 @@ pipelines: auto: language: java versions: - - "11" + - "8" environmentVariables: readOnly: NEXT_VERSION: 0.0.0 diff --git a/.jfrog-pipelines/release/pipelines.snapshot.yml b/.jfrog-pipelines/release/pipelines.snapshot.yml index 9e65856..1c6d778 100644 --- a/.jfrog-pipelines/release/pipelines.snapshot.yml +++ b/.jfrog-pipelines/release/pipelines.snapshot.yml @@ -7,7 +7,7 @@ pipelines: auto: language: java versions: - - "11" + - "8" steps: - name: Snapshot type: Bash diff --git a/pom.xml b/pom.xml index a165e0e..2af258f 100644 --- a/pom.xml +++ b/pom.xml @@ -17,8 +17,8 @@ 3.6.3 UTF-8 - 11 - 11 + 8 + 8 2.15.2 true @@ -167,7 +167,7 @@ org.testng testng - 7.8.0 + 7.5.1 test diff --git a/src/main/java/com/jfrog/mavendeptree/MavenDependencyTree.java b/src/main/java/com/jfrog/mavendeptree/MavenDependencyTree.java index 0635d67..0cfd671 100644 --- a/src/main/java/com/jfrog/mavendeptree/MavenDependencyTree.java +++ b/src/main/java/com/jfrog/mavendeptree/MavenDependencyTree.java @@ -16,7 +16,6 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; -import java.nio.charset.StandardCharsets; import static com.jfrog.mavendeptree.Utils.createDependencyTree; import static com.jfrog.mavendeptree.Utils.writeResultsToFile; @@ -47,7 +46,7 @@ public class MavenDependencyTree extends AbstractMojo { @Override public void execute() throws MojoExecutionException { - try (FileWriter fileWriter = new FileWriter(depsTreeOutputFile, StandardCharsets.UTF_8, true)) { + try (FileWriter fileWriter = new FileWriter(depsTreeOutputFile, true)) { MavenDepTreeResults results = createDependencyTree(dependencyGraphBuilder, session, project); File resultsPath = writeResultsToFile(project, results); fileWriter.append(resultsPath.getAbsolutePath()).append(lineSeparator()); diff --git a/src/main/java/com/jfrog/mavendeptree/Utils.java b/src/main/java/com/jfrog/mavendeptree/Utils.java index a5783f3..182c3dc 100644 --- a/src/main/java/com/jfrog/mavendeptree/Utils.java +++ b/src/main/java/com/jfrog/mavendeptree/Utils.java @@ -19,7 +19,7 @@ import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Base64; import java.util.HashMap; import java.util.List; @@ -99,7 +99,7 @@ static void populateDependencyMap(DependencyNode node, Map depsTreeOutputFiles = runMavenDepTree("multi-module", testOutputDir); + List depsTreeOutputFiles = runMavenDepTree("multi-module", testOutputDir, pluginVersion); // Read output path assertEquals(depsTreeOutputFiles.size(), 4); @@ -81,7 +85,7 @@ public void testMavenArchetypeDependencyManagement() throws VerificationExceptio private void testMavenArchetype(String projectName) throws VerificationException, IOException { // Run Mojo - List depsTreeOutputFile = runMavenDepTree(projectName, testOutputDir); + List depsTreeOutputFile = runMavenDepTree(projectName, testOutputDir, pluginVersion); // Read output path assertEquals(depsTreeOutputFile.size(), 1); diff --git a/src/test/java/com/jfrog/mavendeptree/integration/MavenProjectTreeITest.java b/src/test/java/com/jfrog/mavendeptree/integration/MavenProjectTreeITest.java index 763d481..b760101 100644 --- a/src/test/java/com/jfrog/mavendeptree/integration/MavenProjectTreeITest.java +++ b/src/test/java/com/jfrog/mavendeptree/integration/MavenProjectTreeITest.java @@ -8,21 +8,22 @@ import org.testng.annotations.Test; import java.io.IOException; -import java.nio.file.Path; +import java.nio.file.Paths; import java.util.List; -import static com.jfrog.mavendeptree.integration.Utils.mapper; -import static com.jfrog.mavendeptree.integration.Utils.runMavenProjectTree; +import static com.jfrog.mavendeptree.integration.Utils.*; import static org.testng.Assert.*; /** * @author yahavi */ public class MavenProjectTreeITest { + private final String pluginVersion = getPluginVersion(); + @Test public void testMultiModule() throws VerificationException, IOException { // Run Mojo - List projectInfos = runMavenProjectTree("multi-module"); + List projectInfos = runMavenProjectTree("multi-module", pluginVersion); // Test output assertEquals(projectInfos.size(), 4); @@ -31,19 +32,19 @@ public void testMultiModule() throws VerificationException, IOException { switch (projectInfo.getGav()) { case "org.jfrog.test:multi:3.7-SNAPSHOT": assertEquals(projectInfo.getParentGav(), ""); - assertTrue(StringUtils.endsWith(projectInfo.getPomPath(), Path.of("multi-module", "pom.xml").toString())); + assertTrue(StringUtils.endsWith(projectInfo.getPomPath(), Paths.get("multi-module", "pom.xml").toString())); break; case "org.jfrog.test:multi1:3.7-SNAPSHOT": assertEquals(projectInfo.getParentGav(), "org.jfrog.test:multi:3.7-SNAPSHOT"); - assertTrue(StringUtils.endsWith(projectInfo.getPomPath(), Path.of("multi-module", "multi1", "pom.xml").toString())); + assertTrue(StringUtils.endsWith(projectInfo.getPomPath(), Paths.get("multi-module", "multi1", "pom.xml").toString())); break; case "org.jfrog.test:multi2:3.7-SNAPSHOT": assertEquals(projectInfo.getParentGav(), "org.jfrog.test:multi:3.7-SNAPSHOT"); - assertTrue(StringUtils.endsWith(projectInfo.getPomPath(), Path.of("multi-module", "multi2", "pom.xml").toString())); + assertTrue(StringUtils.endsWith(projectInfo.getPomPath(), Paths.get("multi-module", "multi2", "pom.xml").toString())); break; case "org.jfrog.test:multi3:3.7-SNAPSHOT": assertEquals(projectInfo.getParentGav(), "org.jfrog.test:multi:3.7-SNAPSHOT"); - assertTrue(StringUtils.endsWith(projectInfo.getPomPath(), Path.of("multi-module", "multi3", "pom.xml").toString())); + assertTrue(StringUtils.endsWith(projectInfo.getPomPath(), Paths.get("multi-module", "multi3", "pom.xml").toString())); break; default: fail("Unexpected GAV: " + projectInfo.getGav()); @@ -63,14 +64,14 @@ public void testMavenArchetypeDependencyManagement() throws VerificationExceptio private void testMavenArchetype(String projectName) throws VerificationException, IOException { // Run Mojo - List projectInfoJson = runMavenProjectTree(projectName); + List projectInfoJson = runMavenProjectTree(projectName, pluginVersion); // Test output assertEquals(projectInfoJson.size(), 1); ProjectInfo projectInfo = mapper.readValue(escapePathInWindows(projectInfoJson.get(0)), ProjectInfo.class); assertEquals(projectInfo.getGav(), "org.example:maven-archetype-simple:1.0-SNAPSHOT"); assertEquals(projectInfo.getParentGav(), ""); - assertTrue(StringUtils.endsWith(projectInfo.getPomPath(), Path.of(projectName, "pom.xml").toString())); + assertTrue(StringUtils.endsWith(projectInfo.getPomPath(), Paths.get(projectName, "pom.xml").toString())); } private static String escapePathInWindows(String path) { diff --git a/src/test/java/com/jfrog/mavendeptree/integration/Utils.java b/src/test/java/com/jfrog/mavendeptree/integration/Utils.java index 29aa0ff..387fd06 100644 --- a/src/test/java/com/jfrog/mavendeptree/integration/Utils.java +++ b/src/test/java/com/jfrog/mavendeptree/integration/Utils.java @@ -4,10 +4,14 @@ import com.google.common.collect.Lists; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.maven.it.VerificationException; import org.apache.maven.it.Verifier; import org.apache.maven.it.util.ResourceExtractor; +import org.w3c.dom.Document; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -16,6 +20,7 @@ import java.util.List; import static com.jfrog.mavendeptree.Utils.createMapper; +import static org.testng.Assert.fail; /** * @author yahavi @@ -23,16 +28,35 @@ public class Utils { static final ObjectMapper mapper = createMapper(); + /** + * Extract the plugin version from pom.xml + * + * @return the plugin version + */ + static String getPluginVersion() { + File pomFile = new File("pom.xml"); + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + try { + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + Document doc = dBuilder.parse(pomFile); + return doc.getElementsByTagName("version").item(0).getFirstChild().getNodeValue(); + } catch (Exception e) { + fail(ExceptionUtils.getRootCauseMessage(e)); + return ""; + } + } + /** * Run "tree" on a test project and return the path to the depsTreeOutputFile. * * @param projectName - The test project to run * @param testOutputDir - Output test directory + * @param pluginVersion - The plugin version * @return the content of the generated 'depsTreeOutputFile' file. * @throws IOException in case of any unexpected I/O error. * @throws VerificationException in case of any Maven Verifier error. */ - static List runMavenDepTree(String projectName, String testOutputDir) throws IOException, VerificationException { + static List runMavenDepTree(String projectName, String testOutputDir, String pluginVersion) throws IOException, VerificationException { Path depsTreeOutputFilePath = Paths.get(testOutputDir, "depsTreeOutputFile"); File testDir = ResourceExtractor.simpleExtractResources(Utils.class, "/integration/" + projectName); @@ -40,7 +64,7 @@ static List runMavenDepTree(String projectName, String testOutputDir) th if (StringUtils.equalsIgnoreCase(System.getProperty("debugITs"), "true")) { verifier.setEnvironmentVariable("MAVEN_OPTS", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"); } - verifier.executeGoals(Lists.newArrayList("clean", "com.jfrog:maven-dep-tree:tree", "-DdepsTreeOutputFile=" + depsTreeOutputFilePath)); + verifier.executeGoals(Lists.newArrayList("clean", "com.jfrog:maven-dep-tree:" + pluginVersion + ":tree", "-DdepsTreeOutputFile=" + depsTreeOutputFilePath)); verifier.verifyErrorFreeLog(); return FileUtils.readLines(depsTreeOutputFilePath.toFile(), StandardCharsets.UTF_8); } @@ -48,18 +72,19 @@ static List runMavenDepTree(String projectName, String testOutputDir) th /** * Run "tree" on a test project and return the path to the depsTreeOutputFile. * - * @param projectName - The test project to run + * @param projectName - The test project to run + * @param pluginVersion - The plugin version * @return the output. * @throws IOException in case of any unexpected I/O error. * @throws VerificationException in case of any Maven Verifier error. */ - static List runMavenProjectTree(String projectName) throws IOException, VerificationException { + static List runMavenProjectTree(String projectName, String pluginVersion) throws IOException, VerificationException { File testDir = ResourceExtractor.simpleExtractResources(Utils.class, "/integration/" + projectName); Verifier verifier = new Verifier(testDir.getAbsolutePath()); if (StringUtils.equalsIgnoreCase(System.getProperty("debugITs"), "true")) { verifier.setEnvironmentVariable("MAVEN_OPTS", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"); } - verifier.executeGoals(Lists.newArrayList("clean", "com.jfrog:maven-dep-tree:projects", "-q")); + verifier.executeGoals(Lists.newArrayList("clean", "com.jfrog:maven-dep-tree:" + pluginVersion + ":projects", "-q")); verifier.verifyErrorFreeLog(); return verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false); }