scanoss 0.2.14 → 0.2.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scanoss",
3
- "version": "0.2.14",
3
+ "version": "0.2.18",
4
4
  "description": "The SCANOSS JS package provides a simple, easy to consume module for interacting with SCANOSS APIs/Engine.",
5
5
  "main": "build/main/index.js",
6
6
  "typings": "build/main/index.d.ts",
@@ -15,7 +15,7 @@ function CLIErrorHandler(e: Error) {
15
15
 
16
16
  async function main() {
17
17
  program
18
- .version("0.2.14")
18
+ .version("0.2.17")
19
19
  .description('The SCANOSS JS package provides a simple, easy to consume module for interacting with SCANOSS APIs/Engine.')
20
20
 
21
21
  program
@@ -4,6 +4,7 @@ import fs from "fs";
4
4
  import { IDependencyResponse, IFile, IDependency } from "./DependencyTypes";
5
5
  import { FileListDependency } from "./parsers/types";
6
6
  import { generateDependenciesPurls } from "./PurlGenerator";
7
+ import { PackageURL } from "packageurl-js";
7
8
 
8
9
  export class Dependency {
9
10
 
@@ -31,16 +32,15 @@ export class Dependency {
31
32
  private adapterToDependencyResponse (dependencies: FileListDependency): IDependencyResponse {
32
33
  const results = <IDependencyResponse>{files: []};
33
34
 
34
-
35
-
36
-
37
35
  for (const dependency of dependencies.files){
38
36
  let depArr: Array<IDependency> = [];
39
37
  for (const purl of dependency.purls) {
38
+ const pkg = PackageURL.fromString(purl.purl);
39
+
40
40
  depArr.push({
41
41
  component: null,
42
42
  purl: purl.purl,
43
- version: null,
43
+ version: pkg.version,
44
44
  licenses: [{name: null}]
45
45
  });
46
46
  }
@@ -11,7 +11,7 @@ const PURL_TYPE = 'maven';
11
11
  // and https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
12
12
  const MANIFEST_FILE = 'pom.xml';
13
13
  export function pomParser(fileContent: string, filePath: string): FileDependency {
14
-
14
+
15
15
  // If the file is not a python manifest file, return an empty results
16
16
  const results: FileDependency = {file: filePath, purls: []};
17
17
  if(path.basename(filePath) != MANIFEST_FILE)
@@ -19,30 +19,40 @@ export function pomParser(fileContent: string, filePath: string): FileDependency
19
19
 
20
20
  const dependencies = fileContent.match(/<dependency>((?:.|\n)*?)<\/dependency>/gm);
21
21
  if(dependencies) {
22
- // TODO: classifier are not supported yet
23
- dependencies.forEach(dependency => {
24
- // Extract groupId. It's the purl namespace
25
- const groupId = dependency.match(/<groupId>([^<]*)<\/groupId>/);
26
- const namespace = groupId ? groupId[1] : '';
27
-
28
- // Extract artifact id. It's the purl name
29
- const artifactId = dependency.match(/<artifactId>([^<]*)<\/artifactId>/);
30
- const name = artifactId ? artifactId[1] : '';
31
-
32
- const versionReg = dependency.match(/<version>([^<]*)<\/version>/);
33
- const version = versionReg ? versionReg[1] : '';
34
-
35
-
36
- let purlQualifiers;
37
- const type = dependency.match(/<type>([^<]*)<\/type>/);
38
- if(type) {
39
- purlQualifiers = {};
40
- purlQualifiers['type'] = type[1]
41
- }
42
-
43
- const purlString = new PackageURL(PURL_TYPE, namespace, name, version, purlQualifiers, undefined).toString();
44
- results.purls.push({purl: purlString});
45
- });
22
+
23
+ // TODO: classifier are not supported yet
24
+ dependencies.forEach(dependency => {
25
+ // Extract groupId. It's the purl namespace
26
+ const groupId = dependency.match(/<groupId>([^<]*)<\/groupId>/);
27
+ const namespace = groupId ? groupId[1] : '';
28
+
29
+ // Extract artifact id. It's the purl name
30
+ const artifactId = dependency.match(/<artifactId>([^<]*)<\/artifactId>/);
31
+ const name = artifactId ? artifactId[1] : '';
32
+
33
+ const versionReg = dependency.match(/<version>([^<]*)<\/version>/);
34
+ let version = versionReg ? versionReg[1] : '';
35
+
36
+ const ver = version.match(/\${(.*?)}/);
37
+ if(ver && ver.length >= 1) {
38
+ if(ver[1] === 'project.version') { // TODO: Add support for project.version
39
+ version = undefined;
40
+ } else {
41
+ const res = fileContent.match(new RegExp(`<${ver[1]}>([^<]*)<\/${ver[1]}>`));
42
+ version = res.length >= 1 ? res[1] : '';
43
+ }
44
+ }
45
+
46
+ let purlQualifiers;
47
+ const type = dependency.match(/<type>([^<]*)<\/type>/);
48
+ if(type) {
49
+ purlQualifiers = {};
50
+ purlQualifiers['type'] = type[1]
51
+ }
52
+
53
+ const purlString = new PackageURL(PURL_TYPE, namespace, name, version, purlQualifiers, undefined).toString();
54
+ results.purls.push({purl: purlString});
55
+ });
46
56
  }
47
57
  return results;
48
- }
58
+ }
@@ -272,8 +272,8 @@ export class Scanner extends EventEmitter {
272
272
  this.init();
273
273
  this.createOutputFiles();
274
274
  this.scannerInput = scannerInput;
275
- // If some jobs have no files to scan, we return
276
- if (this.scannerInput.some((input) => !input.fileList.length)){
275
+
276
+ if (!this.isValidInput(scannerInput)) {
277
277
  this.finishScan();
278
278
  return this.finishPromise;
279
279
  }
@@ -283,6 +283,29 @@ export class Scanner extends EventEmitter {
283
283
  }
284
284
 
285
285
 
286
+ private isValidInput(scannerInput: Array<ScannerInput>): boolean {
287
+ if (!scannerInput) {
288
+ this.reportLog('[ SCANNER ]: No input provided', 'warning');
289
+ return false;
290
+ }
291
+
292
+ if (!Array.isArray(scannerInput)) {
293
+ this.reportLog('[ SCANNER ]: Input must be an array','warning');
294
+ return false;
295
+ }
296
+
297
+ if (!scannerInput.length) {
298
+ this.reportLog('[ SCANNER ]: Input array is empty', 'warning');
299
+ return false;
300
+ }
301
+
302
+ if (scannerInput.some((input) => !input.fileList.length)) {
303
+ this.reportLog('[ SCANNER ]: Input array contains an element with no file list','warning');
304
+ return false;
305
+ }
306
+
307
+ return true;
308
+ }
286
309
 
287
310
 
288
311
  getScannerId() {