Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ To build the code without running the tests, add to the "clean build" command th
We welcome community contribution through pull requests.

# Release Notes
The release notes are available [here](RELEASE.md#release-notes).
The release notes are available [here](https://github.com/jfrog/ide-plugins-common/releases).
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies {
implementation group: 'org.jfrog.buildinfo', name: 'build-info-extractor-go', version: buildInfoVersion
implementation group: 'org.jfrog.buildinfo', name: 'build-info-client', version: buildInfoVersion
implementation group: 'org.jfrog.buildinfo', name: 'build-info-api', version: buildInfoVersion
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.15.2'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.16.0'
implementation(group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.13') {
exclude group: 'commons-codec', module: 'commons-codec'
}
Expand All @@ -39,10 +39,10 @@ dependencies {
implementation group: 'com.jetbrains.qodana', name: 'qodana-sarif', version: '0.2.113'
implementation group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.14'
implementation group: 'org.apache.commons', name: 'commons-text', version: '1.10.0'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.11'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.18.0'
implementation group: 'com.google.guava', name: 'guava', version: '32.0.1-jre'
implementation group: 'commons-codec', name: 'commons-codec', version: '1.13'
implementation group: 'com.jfrog', name: 'gradle-dep-tree', version: '3.0.1'
implementation group: 'com.jfrog', name: 'gradle-dep-tree', version: '3.2.0'
implementation group: 'commons-io', name: 'commons-io', version: '2.20.0'
implementation(group: 'com.opencsv', name: 'opencsv', version: '5.11.1') {
exclude group: 'common-collections', module: 'commons-collections'
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/jfrog/ide/common/gradle/GradleDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void verifyGradleInstalled() throws IOException {
* @return list of files containing the dependency trees of the Gradle projects.
* @throws IOException in case of any I/O error.
*/
public List<File> generateDependenciesGraphAsJson(File workingDirectory, Log logger) throws IOException {
public List<File> generateDependenciesGraphAsJson(File workingDirectory, Path gradleUserHome, Log logger) throws IOException {
String encodedPath = Base64.getEncoder().encodeToString(workingDirectory.getName().getBytes(StandardCharsets.UTF_8));

// Create temp init script file
Expand All @@ -75,9 +75,10 @@ public List<File> generateDependenciesGraphAsJson(File workingDirectory, Log log
// Copy init script to the temp file
Files.copy(gradleInitScript, initScript, StandardCopyOption.REPLACE_EXISTING);

// Run "gradle generateDepTrees -q -I <path-to-init-script>" -Dcom.jfrog.depsTreeOutputFile=<path-to-output-file>
// Run "gradle generateDepTrees -q -I <path-to-init-script> -Dcom.jfrog.depsTreeOutputFile=<path-to-output-file> -Dgradle.user.home=<path-to-gradle-user-home>"
List<String> args = Lists.newArrayList("generateDepTrees", "-q", "-I", initScript.toString(),
"-Dcom.jfrog.depsTreeOutputFile=" + outputFile.toString());
"-Dcom.jfrog.depsTreeOutputFile=" + outputFile.toString(),
"-Dgradle.user.home=" + gradleUserHome.toString());
runCommand(workingDirectory, args, logger);
List<File> files = new ArrayList<>();
for (String line : Files.readAllLines(outputFile)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -27,11 +28,17 @@ public class GradleTreeBuilder {
private final GradleDriver gradleDriver;
private final Path projectDir;
private final String descriptorFilePath;
private final Path gradleUserHome;
private Path pluginLibDir;

public GradleTreeBuilder(Path projectDir, String descriptorFilePath, Map<String, String> env, String gradleExe) {
this(projectDir, descriptorFilePath, env, gradleExe, null);
}

public GradleTreeBuilder(Path projectDir, String descriptorFilePath, Map<String, String> env, String gradleExe, Path gradleUserHome) {
this.projectDir = projectDir;
this.descriptorFilePath = descriptorFilePath;
this.gradleUserHome = gradleUserHome != null ? gradleUserHome : Paths.get(System.getProperty("user.home"), ".gradle");
this.gradleDriver = new GradleDriver(gradleExe, env);
}

Expand All @@ -44,7 +51,7 @@ public GradleTreeBuilder(Path projectDir, String descriptorFilePath, Map<String,
*/
public DepTree buildTree(Log logger) throws IOException {
gradleDriver.verifyGradleInstalled();
List<File> gradleDependenciesFiles = gradleDriver.generateDependenciesGraphAsJson(projectDir.toFile(), logger);
List<File> gradleDependenciesFiles = gradleDriver.generateDependenciesGraphAsJson(projectDir.toFile(), gradleUserHome, logger);
return createDependencyTrees(gradleDependenciesFiles);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class ImpactPath {
private String name;
@JsonProperty()
private String version;
@JsonProperty()
private String id;

// empty constructor for deserialization
@SuppressWarnings("unused")
Expand All @@ -24,6 +26,13 @@ public ImpactPath(String dependencyName, String dependencyVersion) {
this.version = dependencyVersion;
}

@SuppressWarnings("unused")
public ImpactPath(String dependencyId, String dependencyName, String dependencyVersion) {
this.id = dependencyId;
this.name = dependencyName;
this.version = dependencyVersion;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,21 @@ public class GradleTreeBuilderTest {

private static final Path GRADLE_ROOT = Paths.get(".").toAbsolutePath().normalize().resolve(Paths.get("src", "test", "resources", "gradle"));
private File tempProject;
private File tempGradleUserHome;

@BeforeMethod
public void setUp(Object[] args) throws IOException {
tempProject = Files.createTempDirectory("ide-plugins-common-gradle").toFile();
tempProject.deleteOnExit();
FileUtils.copyDirectory(GRADLE_ROOT.resolve((String) args[0]).toFile(), tempProject);
tempGradleUserHome = Files.createTempDirectory("ide-plugins-common-gradle-user-home").toFile();
tempGradleUserHome.deleteOnExit();
}

@AfterMethod
public void tearDown() {
FileUtils.deleteQuietly(tempProject);
FileUtils.deleteQuietly(tempGradleUserHome);
}

@DataProvider
Expand Down Expand Up @@ -82,7 +86,7 @@ public void gradleTreeBuilderUnresolvedTest(String projectPath) throws IOExcepti

private DepTree buildGradleDependencyTree(String projectPath) throws IOException {
// Add path to gradle-dep-tree JAR to "pluginLibDir" environment variable, to be read in gradle-dep-tree.gradle init script
Map<String, String> env = new HashMap<>(System.getenv());
Map<String, String> env = new HashMap<>();
env.put("pluginLibDir", GradleDependencyNode.class.getProtectionDomain().getCodeSource().getLocation().getPath());

Path projectDir = tempProject.toPath();
Expand All @@ -91,7 +95,7 @@ private DepTree buildGradleDependencyTree(String projectPath) throws IOException
descriptorFileName += ".kts";
}
String descriptorFilePath = projectDir.resolve(descriptorFileName).toString();
GradleTreeBuilder gradleTreeBuilder = new GradleTreeBuilder(projectDir, descriptorFilePath, env, "");
GradleTreeBuilder gradleTreeBuilder = new GradleTreeBuilder(projectDir, descriptorFilePath, env, "", tempGradleUserHome.toPath());
DepTree depTree = gradleTreeBuilder.buildTree(new NullLog());
assertNotNull(depTree);

Expand Down
Loading