@contrast/contrast 1.0.2 → 1.0.5
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/.prettierignore +4 -0
- package/README.md +24 -16
- package/dist/audit/autodetection/autoDetectLanguage.js +32 -0
- package/dist/audit/catalogueApplication/catalogueApplication.js +2 -11
- package/dist/audit/languageAnalysisEngine/{langugageAnalysisFactory.js → languageAnalysisFactory.js} +30 -13
- package/dist/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +25 -0
- package/dist/audit/languageAnalysisEngine/report/commonReportingFunctions.js +51 -237
- package/dist/audit/languageAnalysisEngine/report/models/reportLibraryModel.js +19 -0
- package/dist/audit/languageAnalysisEngine/report/models/reportListModel.js +24 -0
- package/dist/audit/languageAnalysisEngine/report/models/reportSeverityModel.js +10 -0
- package/dist/audit/languageAnalysisEngine/report/reportingFeature.js +24 -129
- package/dist/audit/languageAnalysisEngine/report/utils/reportUtils.js +85 -0
- package/dist/audit/languageAnalysisEngine/sendSnapshot.js +2 -14
- package/dist/commands/audit/auditConfig.js +8 -2
- package/dist/commands/audit/auditController.js +14 -5
- package/dist/commands/audit/saveFile.js +11 -0
- package/dist/commands/auth/auth.js +19 -1
- package/dist/commands/config/config.js +19 -8
- package/dist/commands/scan/processScan.js +13 -27
- package/dist/commands/scan/sca/scaAnalysis.js +44 -0
- package/dist/common/HTTPClient.js +29 -26
- package/dist/common/errorHandling.js +15 -39
- package/dist/common/versionChecker.js +32 -0
- package/dist/constants/constants.js +16 -2
- package/dist/constants/lambda.js +3 -1
- package/dist/constants/locales.js +58 -48
- package/dist/constants.js +59 -3
- package/dist/index.js +48 -30
- package/dist/lambda/help.js +22 -14
- package/dist/lambda/lambda.js +6 -0
- package/dist/sbom/generateSbom.js +20 -0
- package/dist/scaAnalysis/common/formatMessage.js +11 -0
- package/dist/scaAnalysis/common/treeUpload.js +30 -0
- package/dist/scaAnalysis/java/analysis.js +116 -0
- package/dist/scaAnalysis/java/index.js +18 -0
- package/dist/scaAnalysis/java/javaBuildDepsParser.js +326 -0
- package/dist/scan/autoDetection.js +46 -1
- package/dist/scan/fileUtils.js +73 -1
- package/dist/scan/formatScanOutput.js +212 -0
- package/dist/scan/help.js +6 -2
- package/dist/scan/models/groupedResultsModel.js +11 -0
- package/dist/scan/models/resultContentModel.js +2 -0
- package/dist/scan/models/scanResultsModel.js +11 -0
- package/dist/scan/populateProjectIdAndProjectName.js +1 -0
- package/dist/scan/saveResults.js +9 -10
- package/dist/scan/scan.js +26 -101
- package/dist/scan/scanConfig.js +20 -1
- package/dist/scan/scanController.js +8 -4
- package/dist/scan/scanResults.js +8 -17
- package/dist/utils/getConfig.js +3 -0
- package/dist/utils/requestUtils.js +1 -1
- package/dist/utils/saveFile.js +19 -0
- package/package.json +3 -2
- package/src/audit/autodetection/autoDetectLanguage.ts +40 -0
- package/src/audit/catalogueApplication/catalogueApplication.js +4 -16
- package/src/audit/languageAnalysisEngine/{langugageAnalysisFactory.js → languageAnalysisFactory.js} +41 -19
- package/src/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +71 -0
- package/src/audit/languageAnalysisEngine/report/commonReportingFunctions.ts +105 -0
- package/src/audit/languageAnalysisEngine/report/models/reportLibraryModel.ts +30 -0
- package/src/audit/languageAnalysisEngine/report/models/reportListModel.ts +32 -0
- package/src/audit/languageAnalysisEngine/report/models/reportSeverityModel.ts +9 -0
- package/src/audit/languageAnalysisEngine/report/reportingFeature.ts +56 -0
- package/src/audit/languageAnalysisEngine/report/utils/reportUtils.ts +110 -0
- package/src/audit/languageAnalysisEngine/sendSnapshot.js +2 -22
- package/src/commands/audit/auditConfig.ts +12 -3
- package/src/commands/audit/auditController.ts +21 -5
- package/src/commands/audit/processAudit.ts +3 -1
- package/src/commands/audit/saveFile.ts +6 -0
- package/src/commands/auth/auth.js +25 -1
- package/src/commands/config/config.js +22 -8
- package/src/commands/scan/processScan.js +15 -31
- package/src/commands/scan/sca/scaAnalysis.js +73 -0
- package/src/common/HTTPClient.js +42 -36
- package/src/common/errorHandling.ts +17 -48
- package/src/common/versionChecker.ts +41 -0
- package/src/constants/constants.js +17 -4
- package/src/constants/lambda.js +3 -1
- package/src/constants/locales.js +69 -63
- package/src/constants.js +66 -3
- package/src/index.ts +62 -36
- package/src/lambda/help.ts +22 -14
- package/src/lambda/lambda.ts +8 -0
- package/src/sbom/generateSbom.ts +17 -0
- package/src/scaAnalysis/common/formatMessage.js +10 -0
- package/src/scaAnalysis/common/treeUpload.js +34 -0
- package/src/scaAnalysis/java/analysis.js +159 -0
- package/src/scaAnalysis/java/index.js +21 -0
- package/src/scaAnalysis/java/javaBuildDepsParser.js +391 -0
- package/src/scan/autoDetection.js +54 -1
- package/src/scan/fileUtils.js +91 -1
- package/src/scan/formatScanOutput.ts +241 -0
- package/src/scan/help.js +6 -2
- package/src/scan/models/groupedResultsModel.ts +20 -0
- package/src/scan/models/resultContentModel.ts +86 -0
- package/src/scan/models/scanResultsModel.ts +52 -0
- package/src/scan/populateProjectIdAndProjectName.js +1 -0
- package/src/scan/saveResults.js +8 -9
- package/src/scan/scan.ts +62 -0
- package/src/scan/scanConfig.js +26 -1
- package/src/scan/scanController.js +12 -4
- package/src/scan/scanResults.js +19 -17
- package/src/utils/getConfig.ts +12 -0
- package/src/utils/requestUtils.js +1 -1
- package/src/utils/saveFile.js +19 -0
- package/dist/audit/languageAnalysisEngine/report/checkIgnoreDevDep.js +0 -17
- package/dist/audit/languageAnalysisEngine/report/newReportingFeature.js +0 -81
- package/dist/common/findLatestCLIVersion.js +0 -23
- package/src/audit/languageAnalysisEngine/report/checkIgnoreDevDep.js +0 -27
- package/src/audit/languageAnalysisEngine/report/commonReportingFunctions.js +0 -303
- package/src/audit/languageAnalysisEngine/report/newReportingFeature.js +0 -124
- package/src/audit/languageAnalysisEngine/report/reportingFeature.js +0 -190
- package/src/common/findLatestCLIVersion.ts +0 -27
- package/src/scan/scan.js +0 -167
package/src/index.ts
CHANGED
|
@@ -7,8 +7,11 @@ import constants from './constants'
|
|
|
7
7
|
import { APP_NAME, APP_VERSION } from './constants/constants'
|
|
8
8
|
import { processLambda } from './lambda/lambda'
|
|
9
9
|
import { localConfig } from './utils/getConfig'
|
|
10
|
-
import
|
|
11
|
-
|
|
10
|
+
import {
|
|
11
|
+
findLatestCLIVersion,
|
|
12
|
+
isCorrectNodeVersion
|
|
13
|
+
} from './common/versionChecker'
|
|
14
|
+
import { findCommandOnError } from './common/errorHandling'
|
|
12
15
|
|
|
13
16
|
const {
|
|
14
17
|
commandLineDefinitions: { mainUsageGuide, mainDefinition }
|
|
@@ -31,49 +34,72 @@ const getMainOption = () => {
|
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
const start = async () => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
if (await isCorrectNodeVersion(process.version)) {
|
|
38
|
+
const { mainOptions, argv: argvMain } = getMainOption()
|
|
39
|
+
const command =
|
|
40
|
+
mainOptions.command != undefined ? mainOptions.command.toLowerCase() : ''
|
|
41
|
+
if (
|
|
42
|
+
command === 'version' ||
|
|
43
|
+
argvMain.includes('--v') ||
|
|
44
|
+
argvMain.includes('--version')
|
|
45
|
+
) {
|
|
46
|
+
console.log(APP_VERSION)
|
|
47
|
+
await findLatestCLIVersion(config.get('updateMessageHidden') as boolean)
|
|
48
|
+
return
|
|
49
|
+
}
|
|
45
50
|
|
|
46
|
-
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
config.set('numOfRuns', config.get('numOfRuns') + 1)
|
|
47
53
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
if (config.get('numOfRuns') >= 5) {
|
|
56
|
+
await findLatestCLIVersion(config.get('updateMessageHidden') as boolean)
|
|
57
|
+
config.set('numOfRuns', 0)
|
|
58
|
+
}
|
|
51
59
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
60
|
+
if (command === 'config') {
|
|
61
|
+
return processConfig(argvMain, config)
|
|
62
|
+
}
|
|
55
63
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
64
|
+
if (command === 'auth') {
|
|
65
|
+
return await processAuth(argvMain, config)
|
|
66
|
+
}
|
|
59
67
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
68
|
+
if (command === 'lambda') {
|
|
69
|
+
return await processLambda(argvMain)
|
|
70
|
+
}
|
|
63
71
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
72
|
+
if (command === 'scan') {
|
|
73
|
+
return await processScan(argvMain)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (command === 'audit') {
|
|
77
|
+
return await processAudit(argvMain)
|
|
78
|
+
}
|
|
67
79
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
80
|
+
if (
|
|
81
|
+
command === 'help' ||
|
|
82
|
+
argvMain.includes('--help') ||
|
|
83
|
+
Object.keys(mainOptions).length === 0
|
|
84
|
+
) {
|
|
85
|
+
console.log(mainUsageGuide)
|
|
86
|
+
} else if (mainOptions._unknown !== undefined) {
|
|
87
|
+
const foundCommand = findCommandOnError(mainOptions._unknown)
|
|
88
|
+
|
|
89
|
+
foundCommand
|
|
90
|
+
? console.log(
|
|
91
|
+
`Unknown Command: Did you mean "${foundCommand}"? \nUse "${foundCommand} --help" for the full list of options`
|
|
92
|
+
)
|
|
93
|
+
: console.log(
|
|
94
|
+
`Unknown Command: ${command} \nUse --help for the full list`
|
|
95
|
+
)
|
|
96
|
+
} else {
|
|
97
|
+
console.log(`Unknown Command: ${command} \nUse --help for the full list`)
|
|
98
|
+
}
|
|
99
|
+
process.exit(9)
|
|
74
100
|
} else {
|
|
75
101
|
console.log(
|
|
76
|
-
'
|
|
102
|
+
'Contrast supports Node versions >=16.13.2 <17. Please use one of those versions.'
|
|
77
103
|
)
|
|
78
104
|
process.exit(9)
|
|
79
105
|
}
|
package/src/lambda/help.ts
CHANGED
|
@@ -8,7 +8,15 @@ const lambdaUsageGuide = commandLineUsage([
|
|
|
8
8
|
},
|
|
9
9
|
{
|
|
10
10
|
header: i18n.__('constantsPrerequisitesHeader'),
|
|
11
|
-
content: [
|
|
11
|
+
content: [
|
|
12
|
+
'{bold ' +
|
|
13
|
+
i18n.__('lambdaPrerequisitesContentLambdaLanguages') +
|
|
14
|
+
'}\n\n' +
|
|
15
|
+
'{bold ' +
|
|
16
|
+
i18n.__('lambdaPrerequisitesContentLambdaDescriptionTitle') +
|
|
17
|
+
'}' +
|
|
18
|
+
i18n.__('lambdaPrerequisitesContentLambdaDescription')
|
|
19
|
+
]
|
|
12
20
|
},
|
|
13
21
|
{
|
|
14
22
|
header: i18n.__('constantsUsage'),
|
|
@@ -18,49 +26,49 @@ const lambdaUsageGuide = commandLineUsage([
|
|
|
18
26
|
header: i18n.__('constantsOptions'),
|
|
19
27
|
content: [
|
|
20
28
|
{
|
|
21
|
-
name: i18n.__('lambdaFunctionNameOption'),
|
|
29
|
+
name: '{bold ' + i18n.__('lambdaFunctionNameOption') + '}',
|
|
22
30
|
summary: i18n.__('lambdaFunctionNameSummery')
|
|
23
31
|
},
|
|
24
32
|
{
|
|
25
|
-
name: i18n.__('lambdaListFunctionsOption'),
|
|
33
|
+
name: '{bold ' + i18n.__('lambdaListFunctionsOption') + '}',
|
|
26
34
|
summary: i18n.__('lambdaListFunctionsSummery')
|
|
27
35
|
},
|
|
28
36
|
{
|
|
29
|
-
name: i18n.__('lambdaEndpointOption'),
|
|
37
|
+
name: '{bold ' + i18n.__('lambdaEndpointOption') + '}',
|
|
30
38
|
summary:
|
|
31
|
-
'{
|
|
39
|
+
'{bold ' +
|
|
32
40
|
i18n.__('constantsOptional') +
|
|
33
41
|
'}: ' +
|
|
34
42
|
i18n.__('lambdaEndpointSummery')
|
|
35
43
|
},
|
|
36
44
|
{
|
|
37
|
-
name: i18n.__('lambdaRegionOption'),
|
|
45
|
+
name: '{bold ' + i18n.__('lambdaRegionOption') + '}',
|
|
38
46
|
summary:
|
|
39
|
-
'{
|
|
47
|
+
'{bold ' +
|
|
40
48
|
i18n.__('constantsOptional') +
|
|
41
49
|
'}: ' +
|
|
42
50
|
i18n.__('lambdaRegionSummery')
|
|
43
51
|
},
|
|
44
52
|
{
|
|
45
|
-
name: i18n.__('lambdaProfileOption'),
|
|
53
|
+
name: '{bold ' + i18n.__('lambdaProfileOption') + '}',
|
|
46
54
|
summary:
|
|
47
|
-
'{
|
|
55
|
+
'{bold ' +
|
|
48
56
|
i18n.__('constantsOptional') +
|
|
49
57
|
'}: ' +
|
|
50
58
|
i18n.__('lambdaProfileSummery')
|
|
51
59
|
},
|
|
52
60
|
{
|
|
53
|
-
name: i18n.__('lambdaJsonOption'),
|
|
61
|
+
name: '{bold ' + i18n.__('lambdaJsonOption') + '}',
|
|
54
62
|
summary:
|
|
55
|
-
'{
|
|
63
|
+
'{bold ' +
|
|
56
64
|
i18n.__('constantsOptional') +
|
|
57
65
|
'}: ' +
|
|
58
66
|
i18n.__('lambdaJsonSummery')
|
|
59
67
|
},
|
|
60
68
|
{
|
|
61
|
-
name: i18n.__('lambdaVerboseOption'),
|
|
69
|
+
name: '{bold ' + i18n.__('lambdaVerboseOption') + '}',
|
|
62
70
|
summary:
|
|
63
|
-
'{
|
|
71
|
+
'{bold ' +
|
|
64
72
|
i18n.__('constantsOptional') +
|
|
65
73
|
'}: ' +
|
|
66
74
|
i18n.__('lambdaVerbosSummery')
|
|
@@ -73,7 +81,7 @@ const lambdaUsageGuide = commandLineUsage([
|
|
|
73
81
|
]
|
|
74
82
|
},
|
|
75
83
|
{
|
|
76
|
-
content: '{underline https://www.contrastsecurity.com}'
|
|
84
|
+
content: '{underline https://www.contrastsecurity.com/developer/codesec}'
|
|
77
85
|
}
|
|
78
86
|
])
|
|
79
87
|
|
package/src/lambda/lambda.ts
CHANGED
|
@@ -12,6 +12,8 @@ import { requestScanFunctionPost } from './scanRequest'
|
|
|
12
12
|
import { getScanResults } from './scanResults'
|
|
13
13
|
import { printResults } from './utils'
|
|
14
14
|
import { getAllLambdas, printAvailableLambdas } from './lambdaUtils'
|
|
15
|
+
import { sleep } from '../utils/requestUtils'
|
|
16
|
+
import ora from '../utils/oraWrapper'
|
|
15
17
|
|
|
16
18
|
type LambdaOptions = {
|
|
17
19
|
functionName?: string
|
|
@@ -123,6 +125,12 @@ const actualProcessLambda = async (lambdaOptions: LambdaOptions) => {
|
|
|
123
125
|
})
|
|
124
126
|
}
|
|
125
127
|
|
|
128
|
+
// Wait to make sure we will have all the results
|
|
129
|
+
const startGetherResultsSpinner = ora.returnOra(i18n.__('gatherResults'))
|
|
130
|
+
ora.startSpinner(startGetherResultsSpinner)
|
|
131
|
+
await sleep(15 * 1000)
|
|
132
|
+
ora.succeedSpinner(startGetherResultsSpinner, 'Done gathering results')
|
|
133
|
+
|
|
126
134
|
const resultsResponse = await getScanResults(
|
|
127
135
|
auth,
|
|
128
136
|
params,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getHttpClient } from '../utils/commonApi'
|
|
2
|
+
|
|
3
|
+
export default function generateSbom(config: any) {
|
|
4
|
+
const client = getHttpClient(config)
|
|
5
|
+
return client
|
|
6
|
+
.getSbom(config)
|
|
7
|
+
.then((res: { statusCode: number; body: any }) => {
|
|
8
|
+
if (res.statusCode === 200) {
|
|
9
|
+
return res.body
|
|
10
|
+
} else {
|
|
11
|
+
console.log('Unable to retrieve Software Bill of Materials (SBOM)')
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
.catch((err: any) => {
|
|
15
|
+
console.log(err)
|
|
16
|
+
})
|
|
17
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const { getHttpClient } = require('../../utils/commonApi')
|
|
2
|
+
const { handleResponseErrors } = require('../../common/errorHandling')
|
|
3
|
+
const { APP_VERSION } = require('../../constants/constants')
|
|
4
|
+
|
|
5
|
+
const commonSendSnapShot = async (analysis, config) => {
|
|
6
|
+
const requestBody = {
|
|
7
|
+
appID: config.applicationId,
|
|
8
|
+
cliVersion: APP_VERSION,
|
|
9
|
+
snapshot: analysis
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//console.log(JSON.stringify(analysis))
|
|
13
|
+
|
|
14
|
+
//console.log(JSON.stringify(requestBody))
|
|
15
|
+
const client = getHttpClient(config)
|
|
16
|
+
return client
|
|
17
|
+
.sendSnapshot(requestBody, config)
|
|
18
|
+
.then(res => {
|
|
19
|
+
if (res.statusCode === 201) {
|
|
20
|
+
console.log('snapshot processed successfully')
|
|
21
|
+
return res.body
|
|
22
|
+
} else {
|
|
23
|
+
console.log(res.statusCode)
|
|
24
|
+
handleResponseErrors(res, 'snapshot')
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
.catch(err => {
|
|
28
|
+
console.log(err)
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = {
|
|
33
|
+
commonSendSnapShot
|
|
34
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
const child_process = require('child_process')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
const i18n = require('i18n')
|
|
4
|
+
const fs = require('fs')
|
|
5
|
+
|
|
6
|
+
const MAVEN = 'maven'
|
|
7
|
+
const GRADLE = 'gradle'
|
|
8
|
+
|
|
9
|
+
const determineProjectTypeAndCwd = (files, projectPath) => {
|
|
10
|
+
const projectData = {}
|
|
11
|
+
|
|
12
|
+
if (files[0].includes('pom.xml')) {
|
|
13
|
+
projectData.projectType = MAVEN
|
|
14
|
+
projectData.cwd = projectPath
|
|
15
|
+
? projectPath
|
|
16
|
+
: files[0].replace('pom.xml', '')
|
|
17
|
+
} else if (files[0].includes('build.gradle')) {
|
|
18
|
+
projectData.projectType = GRADLE
|
|
19
|
+
projectData.cwd = projectPath
|
|
20
|
+
? projectPath
|
|
21
|
+
: files[0].replace('pom.xml', '')
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return projectData
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const buildMaven = async (config, projectData, timeout) => {
|
|
28
|
+
let cmdStdout
|
|
29
|
+
let mvn_settings = ''
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
// Allow users to provide a custom location for their settings.xml
|
|
33
|
+
if (config.mavenSettingsPath) {
|
|
34
|
+
mvn_settings = ' -s ' + config.mavenSettingsPath
|
|
35
|
+
}
|
|
36
|
+
cmdStdout = child_process.execSync(
|
|
37
|
+
'mvn dependency:tree -B' + mvn_settings,
|
|
38
|
+
{
|
|
39
|
+
cwd: projectData.cwd,
|
|
40
|
+
timeout
|
|
41
|
+
}
|
|
42
|
+
)
|
|
43
|
+
// output.mvnDependancyTreeOutput = cmdStdout.toString()
|
|
44
|
+
// console.log(cmdStdout.toString())
|
|
45
|
+
return cmdStdout.toString()
|
|
46
|
+
} catch (err) {
|
|
47
|
+
try {
|
|
48
|
+
child_process.execSync('mvn --version', {
|
|
49
|
+
cwd: projectData.cwd,
|
|
50
|
+
timeout
|
|
51
|
+
})
|
|
52
|
+
throw new Error(
|
|
53
|
+
i18n.__('mavenDependencyTreeNonZero', projectData.cwd, `${err.message}`)
|
|
54
|
+
)
|
|
55
|
+
} catch (mvnErr) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
i18n.__('mavenNotInstalledError', projectData.cwd, `${mvnErr.message}`)
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const buildGradle = (config, projectData, timeout) => {
|
|
64
|
+
let cmdStdout
|
|
65
|
+
let output = {}
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
// path.sep is user here to either execute as "./gradlew" for UNIX/Linux/MacOS
|
|
69
|
+
// & ".\gradlew" for Windows
|
|
70
|
+
// Check if the user has specified a sub-project
|
|
71
|
+
if (config.subProject) {
|
|
72
|
+
cmdStdout = child_process.execSync(
|
|
73
|
+
'.' +
|
|
74
|
+
path.sep +
|
|
75
|
+
'gradlew :' +
|
|
76
|
+
config.subProject +
|
|
77
|
+
':dependencies --configuration runtimeClasspath',
|
|
78
|
+
{
|
|
79
|
+
cwd: projectData.cwd,
|
|
80
|
+
timeout
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
} else {
|
|
84
|
+
cmdStdout = child_process.execSync(
|
|
85
|
+
'.' +
|
|
86
|
+
path.sep +
|
|
87
|
+
'gradlew dependencies --configuration runtimeClasspath',
|
|
88
|
+
{
|
|
89
|
+
cwd: projectData.cwd,
|
|
90
|
+
timeout
|
|
91
|
+
}
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
if (
|
|
95
|
+
cmdStdout
|
|
96
|
+
.toString()
|
|
97
|
+
.includes(
|
|
98
|
+
"runtimeClasspath - Runtime classpath of source set 'main'.\n" +
|
|
99
|
+
'No dependencies'
|
|
100
|
+
)
|
|
101
|
+
) {
|
|
102
|
+
cmdStdout = child_process.execSync(
|
|
103
|
+
'.' + path.sep + 'gradlew dependencies',
|
|
104
|
+
{
|
|
105
|
+
cwd: projectData.cwd,
|
|
106
|
+
timeout
|
|
107
|
+
}
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
output.mvnDependancyTreeOutput = cmdStdout.toString()
|
|
111
|
+
return output
|
|
112
|
+
} catch (err) {
|
|
113
|
+
if (
|
|
114
|
+
fs.existsSync(projectData.cwd + 'gradlew') ||
|
|
115
|
+
fs.existsSync(projectData.cwd + 'gradlew.bat')
|
|
116
|
+
) {
|
|
117
|
+
throw new Error(
|
|
118
|
+
i18n.__(
|
|
119
|
+
'gradleDependencyTreeNonZero',
|
|
120
|
+
projectData.cwd,
|
|
121
|
+
`${err.message}`
|
|
122
|
+
)
|
|
123
|
+
)
|
|
124
|
+
} else {
|
|
125
|
+
throw new Error(
|
|
126
|
+
i18n.__('gradleWrapperUnavailable', projectData.cwd, `${err.message}`)
|
|
127
|
+
)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const getJavaBuildDeps = async (config, files) => {
|
|
133
|
+
const timeout = 960000
|
|
134
|
+
let output = {
|
|
135
|
+
mvnDependancyTreeOutput: undefined,
|
|
136
|
+
projectType: undefined
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
try {
|
|
140
|
+
const projectData = determineProjectTypeAndCwd(files, config.projectPath)
|
|
141
|
+
if (projectData.projectType === MAVEN) {
|
|
142
|
+
output.mvnDependancyTreeOutput = await buildMaven(
|
|
143
|
+
config,
|
|
144
|
+
projectData,
|
|
145
|
+
timeout
|
|
146
|
+
)
|
|
147
|
+
} else if (projectData.projectType === GRADLE) {
|
|
148
|
+
output.mvnDependancyTreeOutput = buildGradle(config, projectData, timeout)
|
|
149
|
+
}
|
|
150
|
+
output.projectType = projectData.projectType
|
|
151
|
+
return output
|
|
152
|
+
} catch (err) {
|
|
153
|
+
//
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
module.exports = {
|
|
158
|
+
getJavaBuildDeps
|
|
159
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const { getJavaBuildDeps } = require('./analysis')
|
|
2
|
+
const { parseBuildDeps } = require('./javaBuildDepsParser')
|
|
3
|
+
const { createJavaTSMessage } = require('../common/formatMessage')
|
|
4
|
+
|
|
5
|
+
const javaAnalysis = async (config, languageFiles) => {
|
|
6
|
+
languageFiles.java.forEach(file => {
|
|
7
|
+
file.replace('build.gradle.kts', 'build.gradle')
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
const javaDeps = await buildJavaTree(config, languageFiles.java)
|
|
11
|
+
return createJavaTSMessage(javaDeps)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const buildJavaTree = async (config, files) => {
|
|
15
|
+
const javaBuildDeps = await getJavaBuildDeps(config, files)
|
|
16
|
+
return parseBuildDeps(config, javaBuildDeps)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = {
|
|
20
|
+
javaAnalysis
|
|
21
|
+
}
|