-
Notifications
You must be signed in to change notification settings - Fork 19
Keep every Gradle module's dependencies when building the tree #190
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
Changes from all commits
c619a74
22818e9
10fc1f0
fcf3572
a8b3989
2f53600
cc7cce8
336efbd
3f61a89
9dd0303
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.jfrog.ide.common.deptree; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * The dependency tree of a single module of a multi-module project, as resolved by that module. | ||
| * | ||
| * @param rootId the module's root node ID | ||
| * @param nodes the nodes reachable from the module's root, by their component IDs | ||
| */ | ||
| public record DepTreeModule(String rootId, Map<String, DepTreeNode> nodes) { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| import com.jfrog.GradleDependencyNode; | ||
| import com.jfrog.ide.common.TestUtils; | ||
| import com.jfrog.ide.common.deptree.DepTree; | ||
| import com.jfrog.ide.common.deptree.DepTreeModule; | ||
| import com.jfrog.ide.common.deptree.DepTreeNode; | ||
| import org.apache.commons.io.FileUtils; | ||
| import org.jfrog.build.api.util.NullLog; | ||
|
|
@@ -80,6 +81,45 @@ public void gradleTreeBuilderUnresolvedTest(String projectPath) throws IOExcepti | |
| assertTrue(missing.getScopes().contains("testImplementation")); | ||
| } | ||
|
|
||
| /** | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One-row data provider plus javadoc that only returns
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The data provider is required. |
||
| * Data provider for a project whose modules resolve the same dependency with different transitive | ||
| * dependencies - 'modb' excludes 'commons-lang3' from 'commons-text', 'moda' doesn't. | ||
| * | ||
| * @return 'sharedDependency'. | ||
| */ | ||
| @DataProvider | ||
| private Object[][] gradleTreeBuilderSharedDependencyProvider() { | ||
| return new Object[][]{{"sharedDependency"}}; | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| @Test(dataProvider = "gradleTreeBuilderSharedDependencyProvider") | ||
| public void gradleTreeBuilderSharedDependencyTest(String projectPath) throws IOException { | ||
| final String COMMONS_TEXT = "org.apache.commons:commons-text:1.9"; | ||
| final String COMMONS_LANG3 = "org.apache.commons:commons-lang3:3.11"; | ||
| DepTree depTree = buildGradleDependencyTree(projectPath); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here the 3 isn't a coincidence: this fixture has exactly the root project plus |
||
|
|
||
| DepTreeNode commonsText = depTree.nodes().get(COMMONS_TEXT); | ||
| assertNotNull(commonsText, "Couldn't find node '" + COMMONS_TEXT + "'."); | ||
| assertTrue(commonsText.getChildren().contains(COMMONS_LANG3), | ||
| "The merged tree must keep the edge resolved by 'moda'"); | ||
|
|
||
| Map<String, DepTreeModule> modulesByRoot = new HashMap<>(); | ||
| depTree.modules().forEach(module -> modulesByRoot.put(module.rootId(), module)); | ||
| DepTreeModule moda = modulesByRoot.get("org.jfrog.test.gradle.shared:moda:1.0-SNAPSHOT"); | ||
| assertNotNull(moda, "Couldn't find the 'moda' module tree in " + modulesByRoot.keySet()); | ||
| DepTreeNode modaCommonsText = moda.nodes().get(COMMONS_TEXT); | ||
| assertNotNull(modaCommonsText, "Couldn't find '" + COMMONS_TEXT + "' in the 'moda' module tree."); | ||
| assertTrue(modaCommonsText.getChildren().contains(COMMONS_LANG3)); | ||
| assertTrue(modaCommonsText.getScopes().contains("implementation")); | ||
| DepTreeModule modb = modulesByRoot.get("org.jfrog.test.gradle.shared:modb:1.0-SNAPSHOT"); | ||
| assertNotNull(modb, "Couldn't find the 'modb' module tree in " + modulesByRoot.keySet()); | ||
| DepTreeNode modbCommonsText = modb.nodes().get(COMMONS_TEXT); | ||
| assertNotNull(modbCommonsText, "Couldn't find '" + COMMONS_TEXT + "' in the 'modb' module tree."); | ||
| assertFalse(modbCommonsText.getChildren().contains(COMMONS_LANG3), | ||
| "'modb' excludes commons-lang3, so its own tree must not contain the edge"); | ||
| } | ||
|
|
||
| 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()); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| allprojects { | ||
| group = 'org.jfrog.test.gradle.shared' | ||
| version = '1.0-SNAPSHOT' | ||
| repositories { | ||
| mavenCentral() | ||
| } | ||
| } | ||
|
|
||
| subprojects { | ||
| apply plugin: 'java' | ||
| } | ||
|
|
||
| project('moda') { | ||
| dependencies { | ||
| implementation 'org.apache.commons:commons-text:1.9' | ||
| } | ||
| } | ||
|
|
||
| project('modb') { | ||
| dependencies { | ||
| implementation('org.apache.commons:commons-text:1.9') { | ||
| exclude group: 'org.apache.commons', module: 'commons-lang3' | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| public class Moda { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| public class Modb { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| include "moda", "modb" |
Uh oh!
There was an error while loading. Please reload this page.