Add cycle safety for transitive dependencies
This commit is contained in:
@@ -116,6 +116,25 @@ describe('depgraph', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('hadoop-tree', () => {
|
||||
let depGraph;
|
||||
beforeAll(() => {
|
||||
depGraph = parseDependencyJson(getTestDataFile("hadoop-tree"));
|
||||
});
|
||||
|
||||
it('should parse out the top level dependencies', () => {
|
||||
const mavenDependencies = new MavenDependencyGraph(depGraph);
|
||||
expect(mavenDependencies.getPackageCount()).to.equal(678);
|
||||
});
|
||||
|
||||
it('should be able to generate a manifest despite having a cycle', () => {
|
||||
const mavenDependencies = new MavenDependencyGraph(depGraph);
|
||||
const manifest = mavenDependencies.createManifest();
|
||||
|
||||
expect(manifest.name).to.equal('hadoop-main');
|
||||
expect(manifest.countDependencies()).to.equal(653);
|
||||
})
|
||||
});
|
||||
|
||||
describe('bs-parent-dep-tree', () => {
|
||||
|
||||
|
||||
+7
-2
@@ -85,13 +85,18 @@ export class MavenDependencyGraph {
|
||||
let scope = getDependencyScopeForMavenScope(artifact.scopes);
|
||||
manifest.addDirectDependency(depPackage, scope);
|
||||
|
||||
function addTransitiveDeps(dependencies) {
|
||||
function addTransitiveDeps(dependencies, seen: Set<string> = new Set()) {
|
||||
if (dependencies) {
|
||||
dependencies.forEach(transitiveDep => {
|
||||
if (seen.has(transitiveDep.packageURL.toString())) {
|
||||
// we're in a cycle! skip this one.
|
||||
return;
|
||||
}
|
||||
seen.add(transitiveDep.packageURL.toString());
|
||||
const transitiveDepArtifact = packageUrlToArtifact[transitiveDep.packageURL.toString()];
|
||||
const transitiveDepScope = getDependencyScopeForMavenScope(transitiveDepArtifact.scopes);
|
||||
manifest.addIndirectDependency(transitiveDep, transitiveDepScope);
|
||||
addTransitiveDeps(transitiveDep.dependencies);
|
||||
addTransitiveDeps(transitiveDep.dependencies, seen);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,12 +58,12 @@ export async function generateSnapshot(directory: string, mvnConfig?: MavenConfi
|
||||
? snapshotConfig.correlator
|
||||
: snapshot.job?.correlator;
|
||||
|
||||
const specifiedRef = getNonEmtptyValue(snapshotConfig?.ref);
|
||||
const specifiedRef = getNonEmptyValue(snapshotConfig?.ref);
|
||||
if (specifiedRef) {
|
||||
snapshot.ref = specifiedRef;
|
||||
}
|
||||
|
||||
const specifiedSha = getNonEmtptyValue(snapshot?.sha);
|
||||
const specifiedSha = getNonEmptyValue(snapshot?.sha);
|
||||
if (specifiedSha) {
|
||||
snapshot.sha = specifiedSha;
|
||||
}
|
||||
@@ -173,7 +173,7 @@ function getRepositoryRelativePath(file) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function getNonEmtptyValue(str?: string) {
|
||||
function getNonEmptyValue(str?: string) {
|
||||
if (str) {
|
||||
const trimmed = str.trim();
|
||||
if (trimmed.length > 0) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user