@contrast/contrast 1.0.4 → 1.0.7

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.
Files changed (115) hide show
  1. package/.prettierignore +0 -3
  2. package/dist/audit/autodetection/autoDetectLanguage.js +32 -0
  3. package/dist/audit/catalogueApplication/catalogueApplication.js +2 -11
  4. package/dist/audit/javaAnalysisEngine/parseMavenProjectFileContents.js +4 -2
  5. package/dist/audit/languageAnalysisEngine/checkForMultipleIdentifiedLanguages.js +2 -1
  6. package/dist/audit/languageAnalysisEngine/checkForMultipleIdentifiedProjectFiles.js +2 -1
  7. package/dist/audit/languageAnalysisEngine/checkIdentifiedLanguageHasProjectFile.js +2 -1
  8. package/dist/audit/languageAnalysisEngine/languageAnalysisFactory.js +6 -2
  9. package/dist/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +39 -1
  10. package/dist/audit/languageAnalysisEngine/report/commonReportingFunctions.js +69 -30
  11. package/dist/audit/languageAnalysisEngine/report/models/reportOutputModel.js +24 -0
  12. package/dist/audit/languageAnalysisEngine/report/models/reportSeverityModel.js +3 -1
  13. package/dist/audit/languageAnalysisEngine/report/models/severityCountModel.js +13 -0
  14. package/dist/audit/languageAnalysisEngine/report/reportingFeature.js +2 -2
  15. package/dist/audit/languageAnalysisEngine/report/utils/reportUtils.js +56 -45
  16. package/dist/audit/languageAnalysisEngine/sendSnapshot.js +65 -17
  17. package/dist/commands/audit/auditConfig.js +8 -2
  18. package/dist/commands/audit/auditController.js +9 -3
  19. package/dist/commands/audit/processAudit.js +1 -1
  20. package/dist/commands/scan/processScan.js +7 -4
  21. package/dist/commands/scan/sca/scaAnalysis.js +60 -0
  22. package/dist/common/HTTPClient.js +50 -16
  23. package/dist/common/errorHandling.js +11 -16
  24. package/dist/common/versionChecker.js +1 -1
  25. package/dist/constants/constants.js +24 -2
  26. package/dist/constants/locales.js +31 -36
  27. package/dist/constants.js +20 -0
  28. package/dist/lambda/analytics.js +11 -0
  29. package/dist/lambda/lambda.js +35 -4
  30. package/dist/lambda/types.js +13 -0
  31. package/dist/scaAnalysis/common/formatMessage.js +35 -0
  32. package/dist/scaAnalysis/common/treeUpload.js +29 -0
  33. package/dist/scaAnalysis/go/goAnalysis.js +17 -0
  34. package/dist/scaAnalysis/go/goParseDeps.js +158 -0
  35. package/dist/scaAnalysis/go/goReadDepFile.js +23 -0
  36. package/dist/scaAnalysis/java/analysis.js +105 -0
  37. package/dist/scaAnalysis/java/index.js +18 -0
  38. package/dist/scaAnalysis/java/javaBuildDepsParser.js +339 -0
  39. package/dist/scaAnalysis/python/analysis.js +41 -0
  40. package/dist/scaAnalysis/python/index.js +10 -0
  41. package/dist/scaAnalysis/ruby/analysis.js +226 -0
  42. package/dist/scaAnalysis/ruby/index.js +10 -0
  43. package/dist/scan/autoDetection.js +50 -1
  44. package/dist/scan/fileUtils.js +80 -1
  45. package/dist/scan/formatScanOutput.js +213 -0
  46. package/dist/scan/help.js +3 -1
  47. package/dist/scan/models/groupedResultsModel.js +2 -1
  48. package/dist/scan/models/scanResultsModel.js +3 -1
  49. package/dist/scan/populateProjectIdAndProjectName.js +2 -1
  50. package/dist/scan/scan.js +6 -99
  51. package/dist/scan/scanConfig.js +6 -1
  52. package/dist/scan/scanController.js +26 -7
  53. package/dist/scan/scanResults.js +20 -20
  54. package/dist/utils/commonApi.js +4 -1
  55. package/dist/utils/oraWrapper.js +5 -1
  56. package/package.json +12 -7
  57. package/src/audit/autodetection/autoDetectLanguage.ts +40 -0
  58. package/src/audit/catalogueApplication/catalogueApplication.js +3 -16
  59. package/src/audit/javaAnalysisEngine/parseMavenProjectFileContents.js +11 -8
  60. package/src/audit/languageAnalysisEngine/checkForMultipleIdentifiedLanguages.js +2 -1
  61. package/src/audit/languageAnalysisEngine/checkForMultipleIdentifiedProjectFiles.js +2 -1
  62. package/src/audit/languageAnalysisEngine/checkIdentifiedLanguageHasProjectFile.js +2 -1
  63. package/src/audit/languageAnalysisEngine/languageAnalysisFactory.js +17 -5
  64. package/src/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +76 -3
  65. package/src/audit/languageAnalysisEngine/report/commonReportingFunctions.ts +122 -40
  66. package/src/audit/languageAnalysisEngine/report/models/reportLibraryModel.ts +3 -3
  67. package/src/audit/languageAnalysisEngine/report/models/reportListModel.ts +15 -11
  68. package/src/audit/languageAnalysisEngine/report/models/reportOutputModel.ts +29 -0
  69. package/src/audit/languageAnalysisEngine/report/models/reportSeverityModel.ts +12 -3
  70. package/src/audit/languageAnalysisEngine/report/models/severityCountModel.ts +16 -0
  71. package/src/audit/languageAnalysisEngine/report/reportingFeature.ts +3 -3
  72. package/src/audit/languageAnalysisEngine/report/utils/reportUtils.ts +87 -65
  73. package/src/audit/languageAnalysisEngine/sendSnapshot.js +78 -25
  74. package/src/commands/audit/auditConfig.ts +12 -3
  75. package/src/commands/audit/auditController.ts +9 -3
  76. package/src/commands/audit/processAudit.ts +4 -1
  77. package/src/commands/scan/processScan.js +10 -4
  78. package/src/commands/scan/sca/scaAnalysis.js +83 -0
  79. package/src/common/HTTPClient.js +65 -25
  80. package/src/common/errorHandling.ts +14 -22
  81. package/src/common/versionChecker.ts +1 -1
  82. package/src/constants/constants.js +24 -2
  83. package/src/constants/locales.js +33 -50
  84. package/src/constants.js +22 -0
  85. package/src/lambda/analytics.ts +9 -0
  86. package/src/lambda/arn.ts +2 -1
  87. package/src/lambda/lambda.ts +37 -17
  88. package/src/lambda/types.ts +35 -0
  89. package/src/lambda/utils.ts +2 -7
  90. package/src/scaAnalysis/common/formatMessage.js +38 -0
  91. package/src/scaAnalysis/common/treeUpload.js +30 -0
  92. package/src/scaAnalysis/go/goAnalysis.js +19 -0
  93. package/src/scaAnalysis/go/goParseDeps.js +203 -0
  94. package/src/scaAnalysis/go/goReadDepFile.js +32 -0
  95. package/src/scaAnalysis/java/analysis.js +142 -0
  96. package/src/scaAnalysis/java/index.js +21 -0
  97. package/src/scaAnalysis/java/javaBuildDepsParser.js +404 -0
  98. package/src/scaAnalysis/python/analysis.js +48 -0
  99. package/src/scaAnalysis/python/index.js +11 -0
  100. package/src/scaAnalysis/ruby/analysis.js +282 -0
  101. package/src/scaAnalysis/ruby/index.js +11 -0
  102. package/src/scan/autoDetection.js +58 -1
  103. package/src/scan/fileUtils.js +99 -1
  104. package/src/scan/formatScanOutput.ts +249 -0
  105. package/src/scan/help.js +3 -1
  106. package/src/scan/models/groupedResultsModel.ts +7 -5
  107. package/src/scan/models/resultContentModel.ts +2 -2
  108. package/src/scan/models/scanResultsModel.ts +5 -2
  109. package/src/scan/populateProjectIdAndProjectName.js +3 -1
  110. package/src/scan/scan.ts +8 -136
  111. package/src/scan/scanConfig.js +5 -1
  112. package/src/scan/scanController.js +30 -10
  113. package/src/scan/scanResults.js +31 -18
  114. package/src/utils/commonApi.js +4 -1
  115. package/src/utils/oraWrapper.js +6 -1
@@ -20,6 +20,8 @@ const utils_1 = require("./utils");
20
20
  const lambdaUtils_1 = require("./lambdaUtils");
21
21
  const requestUtils_1 = require("../utils/requestUtils");
22
22
  const oraWrapper_1 = __importDefault(require("../utils/oraWrapper"));
23
+ const analytics_1 = require("./analytics");
24
+ const types_1 = require("./types");
23
25
  const failedStates = [
24
26
  'UNSUPPORTED',
25
27
  'EXCLUDED',
@@ -57,9 +59,19 @@ const getLambdaOptions = (argv) => {
57
59
  }
58
60
  };
59
61
  const processLambda = async (argv) => {
62
+ let errorMsg;
63
+ let scanInfo;
64
+ const commandSessionId = Date.now().toString(36);
60
65
  try {
61
66
  const lambdaOptions = getLambdaOptions(argv);
62
67
  const { help } = lambdaOptions;
68
+ const startCommandAnalytics = {
69
+ arguments: lambdaOptions,
70
+ sessionId: commandSessionId,
71
+ eventType: types_1.EventType.START
72
+ };
73
+ (0, analytics_1.postAnalytics)(startCommandAnalytics).catch((error) => {
74
+ });
63
75
  if (help) {
64
76
  return handleLambdaHelp();
65
77
  }
@@ -68,17 +80,35 @@ const processLambda = async (argv) => {
68
80
  await getAvailableFunctions(lambdaOptions);
69
81
  }
70
82
  else {
71
- await actualProcessLambda(lambdaOptions);
83
+ scanInfo = await actualProcessLambda(lambdaOptions);
72
84
  }
73
85
  }
74
86
  catch (error) {
75
87
  if (error instanceof cliError_1.CliError) {
76
- console.error(error.getErrorMessage());
88
+ errorMsg = error.getErrorMessage();
77
89
  }
78
90
  else if (error instanceof Error) {
79
- console.error(error.message);
91
+ errorMsg = error.message;
92
+ }
93
+ }
94
+ finally {
95
+ const endCommandAnalytics = {
96
+ sessionId: commandSessionId,
97
+ eventType: types_1.EventType.END,
98
+ status: errorMsg ? types_1.StatusType.FAILED : types_1.StatusType.SUCCESS
99
+ };
100
+ if (errorMsg) {
101
+ endCommandAnalytics.errorMsg = errorMsg;
102
+ console.error(errorMsg);
103
+ }
104
+ if (scanInfo) {
105
+ endCommandAnalytics.scanFunctionData = scanInfo;
106
+ }
107
+ await (0, analytics_1.postAnalytics)(endCommandAnalytics).catch((error) => {
108
+ });
109
+ if (errorMsg) {
110
+ process.exit(1);
80
111
  }
81
- process.exit(1);
82
112
  }
83
113
  };
84
114
  exports.processLambda = processLambda;
@@ -127,6 +157,7 @@ const actualProcessLambda = async (lambdaOptions) => {
127
157
  if (results?.length) {
128
158
  (0, utils_1.printResults)(results);
129
159
  }
160
+ return { functionArn, scanId };
130
161
  };
131
162
  const validateRequiredLambdaParams = (options) => {
132
163
  if (options._unknown?.length) {
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EventType = exports.StatusType = void 0;
4
+ var StatusType;
5
+ (function (StatusType) {
6
+ StatusType["FAILED"] = "failed";
7
+ StatusType["SUCCESS"] = "success";
8
+ })(StatusType = exports.StatusType || (exports.StatusType = {}));
9
+ var EventType;
10
+ (function (EventType) {
11
+ EventType["START"] = "start_command_session";
12
+ EventType["END"] = "end_command_session";
13
+ })(EventType = exports.EventType || (exports.EventType = {}));
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ const createJavaTSMessage = javaTree => {
3
+ return {
4
+ java: {
5
+ mavenDependencyTrees: javaTree
6
+ }
7
+ };
8
+ };
9
+ const createGoTSMessage = goTree => {
10
+ return {
11
+ go: {
12
+ goDependencyTrees: goTree
13
+ }
14
+ };
15
+ };
16
+ const createRubyTSMessage = rubyTree => {
17
+ return {
18
+ ruby: {
19
+ rubyDependencyTrees: rubyTree
20
+ }
21
+ };
22
+ };
23
+ const createPythonTSMessage = pythonTree => {
24
+ return {
25
+ python: {
26
+ pythonDependencyTrees: pythonTree
27
+ }
28
+ };
29
+ };
30
+ module.exports = {
31
+ createJavaTSMessage,
32
+ createGoTSMessage,
33
+ createRubyTSMessage,
34
+ createPythonTSMessage
35
+ };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ const { getHttpClient } = require('../../utils/commonApi');
3
+ const { APP_VERSION } = require('../../constants/constants');
4
+ const commonSendSnapShot = async (analysis, config) => {
5
+ const requestBody = {
6
+ appID: config.applicationId,
7
+ cliVersion: APP_VERSION,
8
+ snapshot: analysis
9
+ };
10
+ const client = getHttpClient(config);
11
+ return client
12
+ .sendSnapshot(requestBody, config)
13
+ .then(res => {
14
+ if (res.statusCode === 201) {
15
+ console.log('dependencies processed successfully');
16
+ return res.body;
17
+ }
18
+ else {
19
+ console.log(res.statusCode);
20
+ console.log('error processing dependencies');
21
+ }
22
+ })
23
+ .catch(err => {
24
+ console.log(err);
25
+ });
26
+ };
27
+ module.exports = {
28
+ commonSendSnapShot
29
+ };
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ const { createGoTSMessage } = require('../common/formatMessage');
3
+ const goReadDepFile = require('./goReadDepFile');
4
+ const goParseDeps = require('./goParseDeps');
5
+ const goAnalysis = (config, languageFiles) => {
6
+ try {
7
+ const rawGoDependencies = goReadDepFile.getGoDependencies(config);
8
+ const parsedGoDependencies = goParseDeps.parseGoDependencies(rawGoDependencies);
9
+ return createGoTSMessage(parsedGoDependencies);
10
+ }
11
+ catch (e) {
12
+ console.log(e.message.toString());
13
+ }
14
+ };
15
+ module.exports = {
16
+ goAnalysis
17
+ };
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ const crypto = require('crypto');
3
+ const parseGoDependencies = goDeps => {
4
+ return parseGo(goDeps);
5
+ };
6
+ const parseGo = modGraphOutput => {
7
+ let splitLines = splitAllLinesIntoArray(modGraphOutput);
8
+ const directDepNames = getDirectDepNames(splitLines);
9
+ const uniqueTransitiveDepNames = getAllUniqueTransitiveDepNames(splitLines, directDepNames);
10
+ let rootNodes = createRootNodes(splitLines);
11
+ createTransitiveDeps(uniqueTransitiveDepNames, splitLines, rootNodes);
12
+ return rootNodes;
13
+ };
14
+ const splitAllLinesIntoArray = modGraphOutput => {
15
+ return modGraphOutput.split(/\r\n|\r|\n/);
16
+ };
17
+ const getAllDepsOfADepAsEdge = (dep, deps) => {
18
+ let edges = {};
19
+ const depRows = deps.filter(line => {
20
+ return line.startsWith(dep);
21
+ });
22
+ depRows.forEach(dep => {
23
+ const edgeName = dep.split(' ')[1];
24
+ edges[edgeName] = edgeName;
25
+ });
26
+ return edges;
27
+ };
28
+ const getAllDepsOfADepAsName = (dep, deps) => {
29
+ let edges = [];
30
+ const depRows = deps.filter(line => {
31
+ return line.startsWith(dep);
32
+ });
33
+ depRows.forEach(dep => {
34
+ const edgeName = dep.split(' ')[1];
35
+ edges.push(edgeName);
36
+ });
37
+ return edges;
38
+ };
39
+ const createRootNodes = deps => {
40
+ let rootDep = {};
41
+ const rootDeps = getRootDeps(deps);
42
+ const edges = rootDeps.map(dep => {
43
+ return dep.split(' ')[1];
44
+ });
45
+ rootDep[rootDeps[0].split(' ')[0]] = {};
46
+ edges.forEach(edge => {
47
+ const splitEdge = edge.split('@');
48
+ const splitGroupName = splitEdge[0].split('/');
49
+ const name = splitGroupName.pop();
50
+ const lastSlash = splitEdge[0].lastIndexOf('/');
51
+ let group = splitEdge[0].substring(0, lastSlash);
52
+ const hash = getHash(splitEdge[0]);
53
+ group = checkGroupExists(group, name);
54
+ const edgesOfDep = getAllDepsOfADepAsEdge(edge, deps);
55
+ rootDep[rootDeps[0].split(' ')[0]][edge] = {
56
+ artifactID: name,
57
+ group: group,
58
+ version: splitEdge[1],
59
+ scope: '"compile',
60
+ type: 'direct',
61
+ hash: hash,
62
+ edges: edgesOfDep
63
+ };
64
+ });
65
+ return rootDep;
66
+ };
67
+ const getRootDeps = deps => {
68
+ const rootDeps = deps.filter(dep => {
69
+ const parentDep = dep.split(' ')[0];
70
+ if (parentDep.split('@v').length === 1) {
71
+ return dep;
72
+ }
73
+ });
74
+ return rootDeps;
75
+ };
76
+ const getHash = library => {
77
+ let shaSum = crypto.createHash('sha1');
78
+ shaSum.update(library);
79
+ return shaSum.digest('hex');
80
+ };
81
+ const getDirectDepNames = deps => {
82
+ const directDepNames = [];
83
+ deps.forEach(dep => {
84
+ const parentDep = dep.split(' ')[0];
85
+ if (parentDep.split('@v').length === 1) {
86
+ dep.split(' ')[1] !== undefined
87
+ ? directDepNames.push(dep.split(' ')[1])
88
+ : null;
89
+ }
90
+ });
91
+ return directDepNames;
92
+ };
93
+ const getAllUniqueTransitiveDepNames = (deps, directDepNames) => {
94
+ let uniqueDeps = [];
95
+ deps.forEach(dep => {
96
+ const parentDep = dep.split(' ')[0];
97
+ if (parentDep.split('@v').length !== 1) {
98
+ if (!directDepNames.includes(parentDep)) {
99
+ if (!uniqueDeps.includes(parentDep)) {
100
+ parentDep.length > 1 ? uniqueDeps.push(parentDep) : null;
101
+ }
102
+ }
103
+ }
104
+ });
105
+ return uniqueDeps;
106
+ };
107
+ const checkGroupExists = (group, name) => {
108
+ if (group === null || group === '') {
109
+ return name;
110
+ }
111
+ return group;
112
+ };
113
+ const createTransitiveDeps = (transitiveDeps, splitLines, rootNodes) => {
114
+ transitiveDeps.forEach(dep => {
115
+ const splitEdge = dep.split('@');
116
+ const splitGroupName = splitEdge[0].split('/');
117
+ const name = splitGroupName.pop();
118
+ const lastSlash = splitEdge[0].lastIndexOf('/');
119
+ let group = splitEdge[0].substring(0, lastSlash);
120
+ const hash = getHash(splitEdge[0]);
121
+ group = checkGroupExists(group, name);
122
+ const transitiveDep = {
123
+ artifactID: name,
124
+ group: group,
125
+ version: splitEdge[1],
126
+ scope: 'compile',
127
+ type: 'transitive',
128
+ hash: hash,
129
+ edges: {}
130
+ };
131
+ const edges = getAllDepsOfADepAsEdge(dep, splitLines);
132
+ transitiveDep.edges = edges;
133
+ const edgesAsName = getAllDepsOfADepAsName(dep, splitLines);
134
+ edgesAsName.forEach(dep => {
135
+ const splitEdge = dep.split('@');
136
+ const splitGroupName = splitEdge[0].split('/');
137
+ const name = splitGroupName.pop();
138
+ const lastSlash = splitEdge[0].lastIndexOf('/');
139
+ let group = splitEdge[0].substring(0, lastSlash);
140
+ const hash = getHash(splitEdge[0]);
141
+ group = checkGroupExists(group, name);
142
+ const transitiveDep = {
143
+ artifactID: name,
144
+ group: group,
145
+ version: splitEdge[1],
146
+ scope: 'compile',
147
+ type: 'transitive',
148
+ hash: hash,
149
+ edges: {}
150
+ };
151
+ rootNodes[Object.keys(rootNodes)[0]][dep] = transitiveDep;
152
+ });
153
+ rootNodes[Object.keys(rootNodes)[0]][dep] = transitiveDep;
154
+ });
155
+ };
156
+ module.exports = {
157
+ parseGoDependencies
158
+ };
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ const child_process = require('child_process');
3
+ const i18n = require('i18n');
4
+ const getGoDependencies = config => {
5
+ let cmdStdout;
6
+ let cwd = config.projectPath
7
+ ? config.projectPath.replace('go.mod', '')
8
+ : process.cwd();
9
+ try {
10
+ cmdStdout = child_process.execSync('go mod graph', { cwd });
11
+ return cmdStdout.toString();
12
+ }
13
+ catch (err) {
14
+ if (err.message === 'spawnSync /bin/sh ENOENT') {
15
+ err.message =
16
+ '\n\n*************** No transitive dependencies ***************\n\nWe are unable to build a dependency tree view from your repository as there were no transitive dependencies found.';
17
+ }
18
+ console.log(i18n.__('goReadProjectFile', cwd, `${err.message ? err.message : ''}`));
19
+ }
20
+ };
21
+ module.exports = {
22
+ getGoDependencies
23
+ };
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ const child_process = require('child_process');
3
+ const path = require('path');
4
+ const i18n = require('i18n');
5
+ const fs = require('fs');
6
+ const MAVEN = 'maven';
7
+ const GRADLE = 'gradle';
8
+ const determineProjectTypeAndCwd = (files, projectPath) => {
9
+ const projectData = {};
10
+ if (files[0].includes('pom.xml')) {
11
+ projectData.projectType = MAVEN;
12
+ }
13
+ else if (files[0].includes('build.gradle')) {
14
+ projectData.projectType = GRADLE;
15
+ }
16
+ projectData.cwd = projectPath
17
+ ? projectPath.replace('pom.xml', '').replace('build.gradle', '')
18
+ : projectPath;
19
+ return projectData;
20
+ };
21
+ const buildMaven = (config, projectData, timeout) => {
22
+ let cmdStdout;
23
+ let mvn_settings = '';
24
+ try {
25
+ if (config.mavenSettingsPath) {
26
+ mvn_settings = ' -s ' + config.mavenSettingsPath;
27
+ }
28
+ cmdStdout = child_process.execSync('mvn dependency:tree -B' + mvn_settings, {
29
+ cwd: projectData.cwd,
30
+ timeout
31
+ });
32
+ return cmdStdout.toString();
33
+ }
34
+ catch (err) {
35
+ throw new Error(i18n.__('mavenDependencyTreeNonZero', projectData.cwd, `${err.message}`));
36
+ }
37
+ };
38
+ const buildGradle = (config, projectData, timeout) => {
39
+ let cmdStdout;
40
+ let output = {};
41
+ try {
42
+ if (config.subProject) {
43
+ cmdStdout = child_process.execSync('.' +
44
+ path.sep +
45
+ 'gradlew :' +
46
+ config.subProject +
47
+ ':dependencies --configuration runtimeClasspath', {
48
+ cwd: projectData.cwd,
49
+ timeout
50
+ });
51
+ }
52
+ else {
53
+ cmdStdout = child_process.execSync('.' +
54
+ path.sep +
55
+ 'gradlew dependencies --configuration runtimeClasspath', {
56
+ cwd: projectData.cwd,
57
+ timeout
58
+ });
59
+ }
60
+ if (cmdStdout
61
+ .toString()
62
+ .includes("runtimeClasspath - Runtime classpath of source set 'main'.\n" +
63
+ 'No dependencies')) {
64
+ cmdStdout = child_process.execSync('.' + path.sep + 'gradlew dependencies', {
65
+ cwd: projectData.cwd,
66
+ timeout
67
+ });
68
+ }
69
+ output = cmdStdout.toString();
70
+ return output;
71
+ }
72
+ catch (err) {
73
+ if (fs.existsSync(projectData.cwd + 'gradlew') ||
74
+ fs.existsSync(projectData.cwd + 'gradlew.bat')) {
75
+ throw new Error(i18n.__('gradleDependencyTreeNonZero', projectData.cwd, `${err.message}`));
76
+ }
77
+ else {
78
+ throw new Error(i18n.__('gradleWrapperUnavailable', projectData.cwd, `${err.message}`));
79
+ }
80
+ }
81
+ };
82
+ const getJavaBuildDeps = (config, files) => {
83
+ const timeout = 960000;
84
+ let output = {
85
+ mvnDependancyTreeOutput: undefined,
86
+ projectType: undefined
87
+ };
88
+ try {
89
+ const projectData = determineProjectTypeAndCwd(files, config.projectPath);
90
+ if (projectData.projectType === MAVEN) {
91
+ output.mvnDependancyTreeOutput = buildMaven(config, projectData, timeout);
92
+ }
93
+ else if (projectData.projectType === GRADLE) {
94
+ output.mvnDependancyTreeOutput = buildGradle(config, projectData, timeout);
95
+ }
96
+ output.projectType = projectData.projectType;
97
+ return output;
98
+ }
99
+ catch (err) {
100
+ console.log(err.message.toString());
101
+ }
102
+ };
103
+ module.exports = {
104
+ getJavaBuildDeps
105
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ const analysis = require('./analysis');
3
+ const { parseBuildDeps } = require('./javaBuildDepsParser');
4
+ const { createJavaTSMessage } = require('../common/formatMessage');
5
+ const javaAnalysis = (config, languageFiles) => {
6
+ languageFiles.JAVA.forEach(file => {
7
+ file.replace('build.gradle.kts', 'build.gradle');
8
+ });
9
+ const javaDeps = buildJavaTree(config, languageFiles.JAVA);
10
+ return createJavaTSMessage(javaDeps);
11
+ };
12
+ const buildJavaTree = (config, files) => {
13
+ const javaBuildDeps = analysis.getJavaBuildDeps(config, files);
14
+ return parseBuildDeps(config, javaBuildDeps);
15
+ };
16
+ module.exports = {
17
+ javaAnalysis
18
+ };