-
Notifications
You must be signed in to change notification settings - Fork 35
Yarn - Refactor the process of building impact graph #440
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
b22cc8f
:construction:
44d62da
:bug: - fixed issue regarding Yarn1 impact tree
08c2b58
:art:
cf4028a
:art:
d5021d1
:bulb:
35cfdf9
:white_check_mark: - YarnScannerTest.java was added.
ef87a64
checking if tearDown works after a failing test.
77d9351
:green_heart:
c211104
:truck: new resources for Yarn tests
df1237a
:truck: new resources for Yarn tests
a51787c
Merge remote-tracking branch 'upstream/master' into yarn1-take2
b1bd662
:loud_sound: improved logging structure with more info pops to the us…
f388391
:truck: a monorepo project was added to tests
39139ed
:white_check_mark: a Yarn monorepo test was added
139c601
:white_check_mark: a Yarn monorepo test was added
fe6ad01
:truck: removed unnecessary files for tests.
1e6f7ce
Merge branch 'jfrog:master' into yarn1-take2
noyshabtay 143b58b
Merge branch 'jfrog:master' into yarn1-take2
noyshabtay c3c7083
:see_no_evil:
f8070f9
:art: DepTree became a record class getRootNodeDescriptorFilePath add…
99e02ff
:art: DepTree became a record class getRootNodeDescriptorFilePath add…
bc6931b
:art: walkDepTree removed
0c0e109
:art:
51503ef
:art:
c8b5ed6
:technologist: walkdepTree changed to buildImpactGraph
9676d81
:arrow_up: Update ide-plugins-common dependency
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
src/test/java/com/jfrog/ide/idea/scan/YarnScannerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package com.jfrog.ide.idea.scan; | ||
|
||
import com.intellij.testFramework.HeavyPlatformTestCase; | ||
import com.intellij.util.ConcurrencyUtil; | ||
import com.jfrog.ide.common.deptree.DepTree; | ||
import com.jfrog.ide.common.nodes.DependencyNode; | ||
import com.jfrog.ide.common.nodes.FileTreeNode; | ||
import com.jfrog.ide.common.scan.GraphScanLogic; | ||
import org.apache.commons.io.FileUtils; | ||
import org.jetbrains.plugins.gradle.service.project.open.GradleProjectImportUtil; | ||
import org.jfrog.build.api.util.NullLog; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.*; | ||
import java.util.concurrent.ExecutorService; | ||
|
||
public class YarnScannerTest extends HeavyPlatformTestCase { | ||
private static final Path YARN_ROOT = Paths.get(".").toAbsolutePath().normalize().resolve(Paths.get("src", "test", "resources", "yarn")); | ||
private ExecutorService executorService; | ||
private String tempProjectDir; | ||
|
||
@Override | ||
protected void setUp() throws Exception { | ||
super.setUp(); | ||
tempProjectDir = createTempProjectDir("exampleYarnPackage"); | ||
executorService = ConcurrencyUtil.newSameThreadExecutorService(); | ||
} | ||
|
||
@Override | ||
protected void tearDown() throws Exception { | ||
try { | ||
executorService.shutdown(); | ||
} finally { | ||
// Ensure that tearDown gets executed even if an exception is thrown | ||
super.tearDown(); | ||
} | ||
} | ||
|
||
private String createTempProjectDir(String projectName) throws IOException { | ||
noyshabtay marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Using a virtual directory allows each test to have its own isolated workspace, preventing interference between tests. | ||
String tempProjectDir = getTempDir().createVirtualDir(projectName).toNioPath().toString(); | ||
FileUtils.copyDirectory(YARN_ROOT.resolve(projectName).toFile(), FileUtils.getFile(tempProjectDir)); | ||
return tempProjectDir; | ||
} | ||
|
||
public void testGetPackageNameToVersionsMap() { | ||
YarnScanner yarnScanner = new YarnScanner(getProject(), tempProjectDir, executorService, new GraphScanLogic(new NullLog())); | ||
Set<String> packages = new HashSet<>(Arrays.asList("package1:1.0.123", "package2:2.0.9", "package1:1.0.123", "package2:2.1.7")); | ||
Map<String, Set<String>> packageNameToVersions = yarnScanner.getPackageNameToVersionsMap(packages); | ||
|
||
assertEquals(2, packageNameToVersions.size()); | ||
assertTrue(packageNameToVersions.containsKey("package1")); | ||
assertTrue(packageNameToVersions.containsKey("package2")); | ||
assertFalse(packageNameToVersions.containsKey("package3")); | ||
|
||
assertEquals(new HashSet<>(List.of("1.0.123")), packageNameToVersions.get("package1")); | ||
assertEquals(new HashSet<>(Arrays.asList("2.0.9", "2.1.7")), packageNameToVersions.get("package2")); | ||
noyshabtay marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
public void testWalkDepTree() throws IOException { | ||
GradleProjectImportUtil.linkAndRefreshGradleProject(tempProjectDir, getProject()); | ||
noyshabtay marked this conversation as resolved.
Show resolved
Hide resolved
|
||
YarnScanner yarnScanner = new YarnScanner(getProject(), tempProjectDir, executorService, new GraphScanLogic(new NullLog())); | ||
|
||
// Sanity check - make sure the dependency tree is generated. | ||
DepTree depTree = yarnScanner.buildTree(); | ||
assertNotNull(depTree); | ||
assertEquals(depTree.getRootId(), "example-yarn-package:1.0.0"); | ||
|
||
// Test the walkDepTree method: | ||
// Init params | ||
String[] vulnerableDependencies = {"lodash:4.16.2", "tough-cookie:2.3.1"}; | ||
Map<String, DependencyNode> vulnerableDependenciesMap = new HashMap<>(); | ||
for (String vulnerableDependency : vulnerableDependencies) { | ||
DependencyNode dependencyNode = new DependencyNode(); | ||
dependencyNode.componentId(vulnerableDependency); | ||
// Insert a dummy node and remove it to init the children vector. | ||
dependencyNode.insert(new DependencyNode(), 0); | ||
noyshabtay marked this conversation as resolved.
Show resolved
Hide resolved
|
||
dependencyNode.remove(0); | ||
vulnerableDependenciesMap.put(vulnerableDependency, dependencyNode); | ||
} | ||
// Run the method | ||
List<FileTreeNode> fileTreeNodes = yarnScanner.walkDepTree(vulnerableDependenciesMap, depTree); | ||
// Check there is only one file tree node and it's package.json | ||
assertEquals(1, fileTreeNodes.size()); | ||
assertEquals("package.json", fileTreeNodes.get(0).getTitle()); | ||
|
||
// Check the impact graphs is attached to the package.json node. | ||
FileTreeNode packageJsonNode = fileTreeNodes.get(0); | ||
assertEquals(2, packageJsonNode.getChildren().size()); | ||
|
||
// Check the impact graph correctness. | ||
DependencyNode toughCookieDep = (DependencyNode) packageJsonNode.getChildren().get(0); | ||
DependencyNode lodashDep = (DependencyNode) packageJsonNode.getChildren().get(1); | ||
if (lodashDep.getComponentId().equals("tough-cookie:2.3.1")) { | ||
DependencyNode temp = lodashDep; | ||
lodashDep = toughCookieDep; | ||
toughCookieDep = temp; | ||
} | ||
|
||
// lodash:4.16.2 tests | ||
assertEquals("lodash:4.16.2", lodashDep.getComponentId()); | ||
assertFalse(lodashDep.isIndirect()); | ||
assertEquals(7, lodashDep.getImpactTree().getImpactPathsCount()); | ||
|
||
// tough-cookie:2.3.1 tests | ||
assertEquals("tough-cookie:2.3.1", toughCookieDep.getComponentId()); | ||
assertTrue(toughCookieDep.isIndirect()); | ||
assertEquals(2, toughCookieDep.getImpactTree().getImpactPathsCount()); | ||
|
||
noyshabtay marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ | ||
noyshabtay marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
BSD License | ||
noyshabtay marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
For Yarn software | ||
|
||
Copyright (c) 2016-present, Yarn Contributors. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.