Skip to content

Commit

Permalink
Build project with JDK 8
Browse files Browse the repository at this point in the history
  • Loading branch information
yahavi committed Nov 9, 2023
1 parent c77e174 commit fb9e3a5
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/frogbot-scan-and-fix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/frogbot-scan-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .jfrog-pipelines/release/pipelines.release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pipelines:
auto:
language: java
versions:
- "11"
- "8"
environmentVariables:
readOnly:
NEXT_VERSION: 0.0.0
Expand Down
2 changes: 1 addition & 1 deletion .jfrog-pipelines/release/pipelines.snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pipelines:
auto:
language: java
versions:
- "11"
- "8"
steps:
- name: Snapshot
type: Bash
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<properties>
<maven.min.version>3.6.3</maven.min.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<jackson.version>2.15.2</jackson.version>
<skipITs>true</skipITs>
</properties>
Expand Down Expand Up @@ -167,7 +167,7 @@
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.8.0</version>
<version>7.5.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/jfrog/mavendeptree/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -99,7 +99,7 @@ static void populateDependencyMap(DependencyNode node, Map<String, MavenDependen
* @throws IOException in case of any unexpected I/O error.
*/
static File writeResultsToFile(MavenProject project, MavenDepTreeResults results) throws IOException {
File targetDir = Path.of(project.getModel().getBuild().getDirectory(), "maven-dep-tree").toFile();
File targetDir = Paths.get(project.getModel().getBuild().getDirectory(), "maven-dep-tree").toFile();
FileUtils.forceMkdir(targetDir);
File resultsPath = targetDir.toPath().resolve(Base64.getEncoder().encodeToString(project.getName().getBytes(StandardCharsets.UTF_8))).toFile();
mapper.writeValue(resultsPath, results);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.testng.collections.Sets;
import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;
import java.util.Map;

import static com.jfrog.mavendeptree.Utils.createMapper;
import static com.jfrog.mavendeptree.integration.Utils.getPluginVersion;
import static com.jfrog.mavendeptree.integration.Utils.runMavenDepTree;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
Expand All @@ -25,6 +28,7 @@
* @author yahavi
*/
public class MavenDepTreeITest {
private final String pluginVersion = getPluginVersion();
ObjectMapper mapper = createMapper();
private String testOutputDir;

Expand All @@ -39,9 +43,9 @@ public void tearDown() throws IOException {
}

@Test
public void testMultiModule() throws VerificationException, IOException {
public void testMultiModule() throws VerificationException, IOException, ParserConfigurationException, SAXException {
// Run Mojo
List<String> depsTreeOutputFiles = runMavenDepTree("multi-module", testOutputDir);
List<String> depsTreeOutputFiles = runMavenDepTree("multi-module", testOutputDir, pluginVersion);

// Read output path
assertEquals(depsTreeOutputFiles.size(), 4);
Expand Down Expand Up @@ -81,7 +85,7 @@ public void testMavenArchetypeDependencyManagement() throws VerificationExceptio

private void testMavenArchetype(String projectName) throws VerificationException, IOException {
// Run Mojo
List<String> depsTreeOutputFile = runMavenDepTree(projectName, testOutputDir);
List<String> depsTreeOutputFile = runMavenDepTree(projectName, testOutputDir, pluginVersion);

// Read output path
assertEquals(depsTreeOutputFile.size(), 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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;
Expand All @@ -31,19 +31,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());
Expand All @@ -70,7 +70,7 @@ private void testMavenArchetype(String projectName) throws VerificationException
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) {
Expand Down
28 changes: 26 additions & 2 deletions src/test/java/com/jfrog/mavendeptree/integration/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,31 +20,51 @@
import java.util.List;

import static com.jfrog.mavendeptree.Utils.createMapper;
import static org.testng.Assert.fail;

/**
* @author yahavi
*/
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<String> runMavenDepTree(String projectName, String testOutputDir) throws IOException, VerificationException {
static List<String> runMavenDepTree(String projectName, String testOutputDir, String pluginVersion) throws IOException, VerificationException {
Path depsTreeOutputFilePath = Paths.get(testOutputDir, "depsTreeOutputFile");

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: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);
}
Expand Down

0 comments on commit fb9e3a5

Please sign in to comment.