Adding more complete support for the maven coordinate system with respect to PackageURLs so as to properly disambiguate to types and calssifiers, as reported in #19
This commit is contained in:
Vendored
+18
-1
@@ -134,9 +134,26 @@ function parseDependencyJson(file, isMultiModule = false) {
|
|||||||
}
|
}
|
||||||
exports.parseDependencyJson = parseDependencyJson;
|
exports.parseDependencyJson = parseDependencyJson;
|
||||||
function artifactToPackageURL(artifact) {
|
function artifactToPackageURL(artifact) {
|
||||||
return new packageurl_js_1.PackageURL('maven', artifact.groupId, artifact.artifactId, artifact.version, undefined, undefined);
|
const qualifiers = getArtifactQualifiers(artifact);
|
||||||
|
return new packageurl_js_1.PackageURL('maven', artifact.groupId, artifact.artifactId, artifact.version, qualifiers, undefined);
|
||||||
}
|
}
|
||||||
exports.artifactToPackageURL = artifactToPackageURL;
|
exports.artifactToPackageURL = artifactToPackageURL;
|
||||||
|
function getArtifactQualifiers(artifact) {
|
||||||
|
let qualifiers = undefined;
|
||||||
|
if (artifact.types && artifact.types.length > 0) {
|
||||||
|
if (!qualifiers) {
|
||||||
|
qualifiers = {};
|
||||||
|
}
|
||||||
|
qualifiers['type'] = artifact.types[0];
|
||||||
|
}
|
||||||
|
if (artifact.classifiers && artifact.classifiers.length > 0) {
|
||||||
|
if (!qualifiers) {
|
||||||
|
qualifiers = {};
|
||||||
|
}
|
||||||
|
qualifiers['classifier'] = artifact.classifiers[0];
|
||||||
|
}
|
||||||
|
return qualifiers;
|
||||||
|
}
|
||||||
function getDependencyScopeForMavenScope(mavenScopes) {
|
function getDependencyScopeForMavenScope(mavenScopes) {
|
||||||
// Once the API scopes are improved and expanded we should be able to perform better mapping here from Maven to cater for
|
// Once the API scopes are improved and expanded we should be able to perform better mapping here from Maven to cater for
|
||||||
// provided, runtime, compile, test, system, etc... in the future.
|
// provided, runtime, compile, test, system, etc... in the future.
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+45
-45
@@ -40,41 +40,41 @@ describe('depgraph', () => {
|
|||||||
|
|
||||||
const names = topLevelDependencies.map(pkg => pkg.packageID());
|
const names = topLevelDependencies.map(pkg => pkg.packageID());
|
||||||
expect(names).to.have.members([
|
expect(names).to.have.members([
|
||||||
"pkg:maven/org.apache.maven/[email protected]",
|
"pkg:maven/org.apache.maven/[email protected]?type=jar",
|
||||||
"pkg:maven/org.apache.maven/[email protected]",
|
"pkg:maven/org.apache.maven/[email protected]?type=jar",
|
||||||
"pkg:maven/org.apache.maven/[email protected]",
|
"pkg:maven/org.apache.maven/[email protected]?type=jar",
|
||||||
"pkg:maven/org.apache.maven/[email protected]",
|
"pkg:maven/org.apache.maven/[email protected]?type=jar",
|
||||||
"pkg:maven/org.apache.maven/[email protected]",
|
"pkg:maven/org.apache.maven/[email protected]?type=jar",
|
||||||
"pkg:maven/org.apache.maven/[email protected]",
|
"pkg:maven/org.apache.maven/[email protected]?type=jar",
|
||||||
"pkg:maven/org.apache.maven/[email protected]",
|
"pkg:maven/org.apache.maven/[email protected]?type=jar",
|
||||||
"pkg:maven/org.apache.maven.reporting/[email protected]",
|
"pkg:maven/org.apache.maven.reporting/[email protected]?type=jar",
|
||||||
"pkg:maven/commons-io/[email protected]",
|
"pkg:maven/commons-io/[email protected]?type=jar",
|
||||||
"pkg:maven/org.codehaus.plexus/[email protected]",
|
"pkg:maven/org.codehaus.plexus/[email protected]?type=jar",
|
||||||
"pkg:maven/org.codehaus.plexus/[email protected]",
|
"pkg:maven/org.codehaus.plexus/[email protected]?type=jar",
|
||||||
"pkg:maven/org.codehaus.plexus/[email protected]",
|
"pkg:maven/org.codehaus.plexus/[email protected]?type=jar",
|
||||||
"pkg:maven/org.apache.maven.shared/[email protected]",
|
"pkg:maven/org.apache.maven.shared/[email protected]?type=jar",
|
||||||
"pkg:maven/org.apache.maven.shared/[email protected]",
|
"pkg:maven/org.apache.maven.shared/[email protected]?type=jar",
|
||||||
"pkg:maven/org.apache.maven.shared/[email protected]",
|
"pkg:maven/org.apache.maven.shared/[email protected]?type=jar",
|
||||||
"pkg:maven/org.apache.maven.shared/[email protected]",
|
"pkg:maven/org.apache.maven.shared/[email protected]?type=jar",
|
||||||
"pkg:maven/org.apache.maven.shared/[email protected]",
|
"pkg:maven/org.apache.maven.shared/[email protected]?type=jar",
|
||||||
"pkg:maven/org.apache.commons/[email protected]",
|
"pkg:maven/org.apache.commons/[email protected]?type=jar",
|
||||||
"pkg:maven/org.apache.commons/[email protected]",
|
"pkg:maven/org.apache.commons/[email protected]?type=jar",
|
||||||
"pkg:maven/org.apache.maven.plugin-tools/[email protected]",
|
"pkg:maven/org.apache.maven.plugin-tools/[email protected]?type=jar",
|
||||||
"pkg:maven/org.eclipse.aether/[email protected]",
|
"pkg:maven/org.eclipse.aether/[email protected]?type=jar",
|
||||||
"pkg:maven/org.eclipse.aether/[email protected]",
|
"pkg:maven/org.eclipse.aether/[email protected]?type=jar",
|
||||||
"pkg:maven/org.eclipse.aether/[email protected]",
|
"pkg:maven/org.eclipse.aether/[email protected]?type=jar",
|
||||||
"pkg:maven/org.apache.maven.wagon/[email protected]",
|
"pkg:maven/org.apache.maven.wagon/[email protected]?type=jar",
|
||||||
"pkg:maven/junit/[email protected]",
|
"pkg:maven/junit/[email protected]?type=jar",
|
||||||
"pkg:maven/org.apache.maven.plugin-testing/[email protected]",
|
"pkg:maven/org.apache.maven.plugin-testing/[email protected]?type=jar",
|
||||||
"pkg:maven/org.apache.maven.plugin-testing/[email protected]",
|
"pkg:maven/org.apache.maven.plugin-testing/[email protected]?type=jar",
|
||||||
"pkg:maven/org.mockito/[email protected]",
|
"pkg:maven/org.mockito/[email protected]?type=jar",
|
||||||
"pkg:maven/org.codehaus.plexus/[email protected]",
|
"pkg:maven/org.codehaus.plexus/[email protected]?type=jar",
|
||||||
"pkg:maven/org.apache.maven/[email protected]",
|
"pkg:maven/org.apache.maven/[email protected]?type=jar",
|
||||||
"pkg:maven/org.eclipse.jetty/[email protected]",
|
"pkg:maven/org.eclipse.jetty/[email protected]?type=jar",
|
||||||
"pkg:maven/org.eclipse.jetty/[email protected]",
|
"pkg:maven/org.eclipse.jetty/[email protected]?type=jar",
|
||||||
"pkg:maven/org.eclipse.jetty/[email protected]",
|
"pkg:maven/org.eclipse.jetty/[email protected]?type=jar",
|
||||||
"pkg:maven/org.slf4j/[email protected]",
|
"pkg:maven/org.slf4j/[email protected]?type=jar",
|
||||||
"pkg:maven/commons-beanutils/[email protected]"
|
"pkg:maven/commons-beanutils/[email protected]?type=jar"
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -104,13 +104,13 @@ describe('depgraph', () => {
|
|||||||
|
|
||||||
const names = topLevelDependencies.map(pkg => pkg.packageID());
|
const names = topLevelDependencies.map(pkg => pkg.packageID());
|
||||||
expect(names).to.have.members([
|
expect(names).to.have.members([
|
||||||
"pkg:maven/org.eclipse.jetty/[email protected]",
|
"pkg:maven/org.eclipse.jetty/[email protected]?type=jar",
|
||||||
"pkg:maven/org.eclipse.jetty/[email protected]",
|
"pkg:maven/org.eclipse.jetty/[email protected]?type=jar",
|
||||||
"pkg:maven/org.thymeleaf/[email protected]",
|
"pkg:maven/org.thymeleaf/[email protected]?type=jar",
|
||||||
"pkg:maven/org.json/json@20210307",
|
"pkg:maven/org.json/json@20210307?type=jar",
|
||||||
"pkg:maven/org.xerial/[email protected]",
|
"pkg:maven/org.xerial/[email protected]?type=jar",
|
||||||
"pkg:maven/org.apache.logging.log4j/[email protected]",
|
"pkg:maven/org.apache.logging.log4j/[email protected]?type=jar",
|
||||||
"pkg:maven/junit/[email protected]"
|
"pkg:maven/junit/[email protected]?type=jar"
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -132,9 +132,9 @@ describe('depgraph', () => {
|
|||||||
|
|
||||||
const topLevelNames = topLevelDependencies.map(pkg => pkg.packageID());
|
const topLevelNames = topLevelDependencies.map(pkg => pkg.packageID());
|
||||||
expect(topLevelNames).to.have.members([
|
expect(topLevelNames).to.have.members([
|
||||||
"pkg:maven/org.eclipse.jetty/[email protected]",
|
"pkg:maven/org.eclipse.jetty/[email protected]?type=jar",
|
||||||
"pkg:maven/com.github.octodemo/[email protected]",
|
"pkg:maven/com.github.octodemo/[email protected]?type=jar",
|
||||||
"pkg:maven/junit/[email protected]"
|
"pkg:maven/junit/[email protected]?type=jar"
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+23
-1
@@ -19,6 +19,7 @@ export type DepgraphArtifact = {
|
|||||||
optional?: boolean,
|
optional?: boolean,
|
||||||
scopes?: string[],
|
scopes?: string[],
|
||||||
types?: string[],
|
types?: string[],
|
||||||
|
classifiers?: string[],
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DepgraphDependency = {
|
export type DepgraphDependency = {
|
||||||
@@ -186,16 +187,37 @@ export function parseDependencyJson(file: string, isMultiModule: boolean = false
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function artifactToPackageURL(artifact: DepgraphArtifact): PackageURL {
|
export function artifactToPackageURL(artifact: DepgraphArtifact): PackageURL {
|
||||||
|
const qualifiers = getArtifactQualifiers(artifact);
|
||||||
return new PackageURL(
|
return new PackageURL(
|
||||||
'maven',
|
'maven',
|
||||||
artifact.groupId,
|
artifact.groupId,
|
||||||
artifact.artifactId,
|
artifact.artifactId,
|
||||||
artifact.version,
|
artifact.version,
|
||||||
undefined,
|
qualifiers,
|
||||||
undefined
|
undefined
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getArtifactQualifiers(artifact: DepgraphArtifact): { [key: string]: string; } | undefined {
|
||||||
|
let qualifiers: { [key: string]: string; } | undefined = undefined;
|
||||||
|
|
||||||
|
if (artifact.types && artifact.types.length > 0) {
|
||||||
|
if (!qualifiers) {
|
||||||
|
qualifiers = {};
|
||||||
|
}
|
||||||
|
qualifiers['type'] = artifact.types[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (artifact.classifiers && artifact.classifiers.length > 0) {
|
||||||
|
if (!qualifiers) {
|
||||||
|
qualifiers = {};
|
||||||
|
}
|
||||||
|
qualifiers['classifier'] = artifact.classifiers[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
return qualifiers;
|
||||||
|
}
|
||||||
|
|
||||||
function getDependencyScopeForMavenScope(mavenScopes: string[] | undefined | null): DependencyScope {
|
function getDependencyScopeForMavenScope(mavenScopes: string[] | undefined | null): DependencyScope {
|
||||||
// Once the API scopes are improved and expanded we should be able to perform better mapping here from Maven to cater for
|
// Once the API scopes are improved and expanded we should be able to perform better mapping here from Maven to cater for
|
||||||
// provided, runtime, compile, test, system, etc... in the future.
|
// provided, runtime, compile, test, system, etc... in the future.
|
||||||
|
|||||||
@@ -51,5 +51,14 @@ describe('snapshot-generator', () => {
|
|||||||
expect(snapshot.detector.version).toBe(version);
|
expect(snapshot.detector.version).toBe(version);
|
||||||
expect(snapshot.manifests['maven-wrapper-test'].countDependencies()).toBe(0);
|
expect(snapshot.manifests['maven-wrapper-test'].countDependencies()).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should generate a snapshot for an artifact with classifiers project', async () => {
|
||||||
|
const projectDir = getMavenProjectDirectory('artifact-with-classifiers');
|
||||||
|
const snapshot = await generateSnapshot(projectDir);
|
||||||
|
|
||||||
|
expect(snapshot.manifests['artifact-with-classifiers']).toBeDefined();
|
||||||
|
expect(snapshot.detector.version).toBe(version);
|
||||||
|
expect(snapshot.manifests['artifact-with-classifiers'].countDependencies()).toBe(7);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.github.octodemo</groupId>
|
||||||
|
<artifactId>artifact-with-classifiers</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- dependency triggering Maximum call stack size exceeded due to not propery processing the classifiers -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.netty</groupId>
|
||||||
|
<artifactId>netty-tcnative-boringssl-static</artifactId>
|
||||||
|
<version>2.0.54.Final</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
Reference in New Issue
Block a user