@contrast/contrast 1.0.0 → 1.0.3
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 +3 -0
- package/README.md +115 -78
- package/dist/audit/AnalysisEngine.js +37 -0
- package/dist/audit/catalogueApplication/catalogueApplication.js +36 -0
- package/dist/audit/dotnetAnalysisEngine/index.js +25 -0
- package/dist/audit/dotnetAnalysisEngine/parseLockFileContents.js +35 -0
- package/dist/audit/dotnetAnalysisEngine/parseProjectFileContents.js +15 -0
- package/dist/audit/dotnetAnalysisEngine/readLockFileContents.js +18 -0
- package/dist/audit/dotnetAnalysisEngine/readProjectFileContents.js +14 -0
- package/dist/audit/dotnetAnalysisEngine/sanitizer.js +9 -0
- package/dist/audit/goAnalysisEngine/index.js +17 -0
- package/dist/audit/goAnalysisEngine/parseProjectFileContents.js +164 -0
- package/dist/audit/goAnalysisEngine/readProjectFileContents.js +21 -0
- package/dist/audit/goAnalysisEngine/sanitizer.js +5 -0
- package/dist/audit/javaAnalysisEngine/index.js +34 -0
- package/dist/audit/javaAnalysisEngine/parseMavenProjectFileContents.js +153 -0
- package/dist/audit/javaAnalysisEngine/parseProjectFileContents.js +353 -0
- package/dist/audit/javaAnalysisEngine/readProjectFileContents.js +98 -0
- package/dist/audit/javaAnalysisEngine/sanitizer.js +5 -0
- package/dist/audit/languageAnalysisEngine/checkForMultipleIdentifiedLanguages.js +24 -0
- package/dist/audit/languageAnalysisEngine/checkForMultipleIdentifiedProjectFiles.js +24 -0
- package/dist/audit/languageAnalysisEngine/checkIdentifiedLanguageHasLockFile.js +35 -0
- package/dist/audit/languageAnalysisEngine/checkIdentifiedLanguageHasProjectFile.js +23 -0
- package/dist/audit/languageAnalysisEngine/commonApi.js +18 -0
- package/dist/audit/languageAnalysisEngine/constants.js +20 -0
- package/dist/audit/languageAnalysisEngine/filterProjectPath.js +20 -0
- package/dist/audit/languageAnalysisEngine/getIdentifiedLanguageInfo.js +25 -0
- package/dist/audit/languageAnalysisEngine/getProjectRootFilenames.js +39 -0
- package/dist/audit/languageAnalysisEngine/index.js +39 -0
- package/dist/audit/languageAnalysisEngine/langugageAnalysisFactory.js +95 -0
- package/dist/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +121 -0
- package/dist/audit/languageAnalysisEngine/report/checkIgnoreDevDep.js +17 -0
- package/dist/audit/languageAnalysisEngine/report/commonReportingFunctions.js +257 -0
- package/dist/audit/languageAnalysisEngine/report/newReportingFeature.js +81 -0
- package/dist/audit/languageAnalysisEngine/report/reportingFeature.js +133 -0
- package/dist/audit/languageAnalysisEngine/sendSnapshot.js +41 -0
- package/dist/audit/languageAnalysisEngine/util/capabilities.js +11 -0
- package/dist/audit/languageAnalysisEngine/util/generalAPI.js +39 -0
- package/dist/audit/languageAnalysisEngine/util/requestUtils.js +14 -0
- package/dist/audit/nodeAnalysisEngine/handleNPMLockFileV2.js +40 -0
- package/dist/audit/nodeAnalysisEngine/index.js +31 -0
- package/dist/audit/nodeAnalysisEngine/parseNPMLockFileContents.js +18 -0
- package/dist/audit/nodeAnalysisEngine/parseYarn2LockFileContents.js +51 -0
- package/dist/audit/nodeAnalysisEngine/parseYarnLockFileContents.js +18 -0
- package/dist/audit/nodeAnalysisEngine/readNPMLockFileContents.js +17 -0
- package/dist/audit/nodeAnalysisEngine/readProjectFileContents.js +14 -0
- package/dist/audit/nodeAnalysisEngine/readYarnLockFileContents.js +24 -0
- package/dist/audit/nodeAnalysisEngine/sanitizer.js +9 -0
- package/dist/audit/phpAnalysisEngine/index.js +23 -0
- package/dist/audit/phpAnalysisEngine/parseLockFileContents.js +52 -0
- package/dist/audit/phpAnalysisEngine/readLockFileContents.js +13 -0
- package/dist/audit/phpAnalysisEngine/readProjectFileContents.js +16 -0
- package/dist/audit/phpAnalysisEngine/sanitizer.js +5 -0
- package/dist/audit/pythonAnalysisEngine/index.js +25 -0
- package/dist/audit/pythonAnalysisEngine/parsePipfileLockContents.js +17 -0
- package/dist/audit/pythonAnalysisEngine/parseProjectFileContents.js +21 -0
- package/dist/audit/pythonAnalysisEngine/readPipfileLockFileContents.js +13 -0
- package/dist/audit/pythonAnalysisEngine/readPythonProjectFileContents.js +14 -0
- package/dist/audit/pythonAnalysisEngine/sanitizer.js +7 -0
- package/dist/audit/rubyAnalysisEngine/index.js +25 -0
- package/dist/audit/rubyAnalysisEngine/parseGemfileLockContents.js +176 -0
- package/dist/audit/rubyAnalysisEngine/parsedGemfile.js +22 -0
- package/dist/audit/rubyAnalysisEngine/readGemfileContents.js +14 -0
- package/dist/audit/rubyAnalysisEngine/readGemfileLockContents.js +14 -0
- package/dist/audit/rubyAnalysisEngine/sanitizer.js +6 -0
- package/dist/commands/audit/auditConfig.js +25 -0
- package/dist/commands/audit/auditController.js +31 -0
- package/dist/commands/audit/help.js +52 -0
- package/dist/commands/audit/processAudit.js +18 -0
- package/dist/commands/audit/saveFile.js +11 -0
- package/dist/commands/auth/auth.js +20 -2
- package/dist/commands/config/config.js +19 -8
- package/dist/commands/scan/processScan.js +9 -13
- package/dist/common/HTTPClient.js +112 -13
- package/dist/common/errorHandling.js +65 -1
- package/dist/common/versionChecker.js +30 -0
- package/dist/constants/constants.js +4 -2
- package/dist/constants/lambda.js +32 -4
- package/dist/constants/locales.js +60 -21
- package/dist/constants.js +181 -21
- package/dist/index.js +50 -23
- package/dist/lambda/aws.js +14 -11
- package/dist/lambda/help.js +4 -0
- package/dist/lambda/lambda.js +50 -27
- package/dist/lambda/lambdaUtils.js +72 -0
- package/dist/lambda/logUtils.js +11 -1
- package/dist/lambda/scanDetailCompletion.js +4 -4
- package/dist/lambda/scanRequest.js +11 -5
- package/dist/lambda/utils.js +110 -53
- package/dist/sbom/generateSbom.js +20 -0
- package/dist/scan/autoDetection.js +0 -32
- package/dist/scan/fileUtils.js +1 -1
- package/dist/scan/help.js +14 -40
- package/dist/scan/populateProjectIdAndProjectName.js +5 -0
- package/dist/scan/saveResults.js +14 -0
- package/dist/scan/scan.js +105 -40
- package/dist/scan/scanConfig.js +39 -0
- package/dist/scan/scanController.js +19 -16
- package/dist/scan/scanResults.js +24 -16
- package/dist/utils/commonApi.js +3 -3
- package/dist/utils/paramsUtil/commandlineParams.js +1 -20
- package/dist/utils/paramsUtil/paramHandler.js +3 -6
- package/dist/utils/parsedCLIOptions.js +14 -8
- package/dist/utils/requestUtils.js +1 -1
- package/dist/utils/saveFile.js +19 -0
- package/package.json +26 -21
- package/src/audit/AnalysisEngine.js +103 -0
- package/src/audit/catalogueApplication/catalogueApplication.js +42 -0
- package/src/audit/dotnetAnalysisEngine/index.js +26 -0
- package/src/audit/dotnetAnalysisEngine/parseLockFileContents.js +47 -0
- package/src/audit/dotnetAnalysisEngine/parseProjectFileContents.js +29 -0
- package/src/audit/dotnetAnalysisEngine/readLockFileContents.js +30 -0
- package/src/audit/dotnetAnalysisEngine/readProjectFileContents.js +26 -0
- package/src/audit/dotnetAnalysisEngine/sanitizer.js +11 -0
- package/src/audit/goAnalysisEngine/index.js +18 -0
- package/src/audit/goAnalysisEngine/parseProjectFileContents.js +209 -0
- package/src/audit/goAnalysisEngine/readProjectFileContents.js +31 -0
- package/src/audit/goAnalysisEngine/sanitizer.js +7 -0
- package/src/audit/javaAnalysisEngine/index.js +41 -0
- package/src/audit/javaAnalysisEngine/parseMavenProjectFileContents.js +222 -0
- package/src/audit/javaAnalysisEngine/parseProjectFileContents.js +420 -0
- package/src/audit/javaAnalysisEngine/readProjectFileContents.js +141 -0
- package/src/audit/javaAnalysisEngine/sanitizer.js +6 -0
- package/src/audit/languageAnalysisEngine/checkForMultipleIdentifiedLanguages.js +35 -0
- package/src/audit/languageAnalysisEngine/checkForMultipleIdentifiedProjectFiles.js +41 -0
- package/src/audit/languageAnalysisEngine/checkIdentifiedLanguageHasLockFile.js +54 -0
- package/src/audit/languageAnalysisEngine/checkIdentifiedLanguageHasProjectFile.js +32 -0
- package/src/audit/languageAnalysisEngine/commonApi.js +20 -0
- package/src/audit/languageAnalysisEngine/constants.js +23 -0
- package/src/audit/languageAnalysisEngine/filterProjectPath.js +21 -0
- package/src/audit/languageAnalysisEngine/getIdentifiedLanguageInfo.js +41 -0
- package/src/audit/languageAnalysisEngine/getProjectRootFilenames.js +72 -0
- package/src/audit/languageAnalysisEngine/index.js +45 -0
- package/src/audit/languageAnalysisEngine/langugageAnalysisFactory.js +126 -0
- package/src/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +177 -0
- package/src/audit/languageAnalysisEngine/report/checkIgnoreDevDep.js +27 -0
- package/src/audit/languageAnalysisEngine/report/commonReportingFunctions.js +303 -0
- package/src/audit/languageAnalysisEngine/report/newReportingFeature.js +124 -0
- package/src/audit/languageAnalysisEngine/report/reportingFeature.js +190 -0
- package/src/audit/languageAnalysisEngine/sendSnapshot.js +51 -0
- package/src/audit/languageAnalysisEngine/util/capabilities.js +12 -0
- package/src/audit/languageAnalysisEngine/util/generalAPI.js +43 -0
- package/src/audit/languageAnalysisEngine/util/requestUtils.js +17 -0
- package/src/audit/nodeAnalysisEngine/handleNPMLockFileV2.js +49 -0
- package/src/audit/nodeAnalysisEngine/index.js +35 -0
- package/src/audit/nodeAnalysisEngine/parseNPMLockFileContents.js +20 -0
- package/src/audit/nodeAnalysisEngine/parseYarn2LockFileContents.js +63 -0
- package/src/audit/nodeAnalysisEngine/parseYarnLockFileContents.js +26 -0
- package/src/audit/nodeAnalysisEngine/readNPMLockFileContents.js +23 -0
- package/src/audit/nodeAnalysisEngine/readProjectFileContents.js +27 -0
- package/src/audit/nodeAnalysisEngine/readYarnLockFileContents.js +36 -0
- package/src/audit/nodeAnalysisEngine/sanitizer.js +11 -0
- package/src/audit/phpAnalysisEngine/index.js +27 -0
- package/src/audit/phpAnalysisEngine/parseLockFileContents.js +60 -0
- package/src/audit/phpAnalysisEngine/readLockFileContents.js +14 -0
- package/src/audit/phpAnalysisEngine/readProjectFileContents.js +25 -0
- package/src/audit/phpAnalysisEngine/sanitizer.js +4 -0
- package/src/audit/pythonAnalysisEngine/index.js +55 -0
- package/src/audit/pythonAnalysisEngine/parsePipfileLockContents.js +23 -0
- package/src/audit/pythonAnalysisEngine/parseProjectFileContents.js +33 -0
- package/src/audit/pythonAnalysisEngine/readPipfileLockFileContents.js +16 -0
- package/src/audit/pythonAnalysisEngine/readPythonProjectFileContents.js +22 -0
- package/src/audit/pythonAnalysisEngine/sanitizer.js +9 -0
- package/src/audit/rubyAnalysisEngine/index.js +30 -0
- package/src/audit/rubyAnalysisEngine/parseGemfileLockContents.js +215 -0
- package/src/audit/rubyAnalysisEngine/parsedGemfile.js +39 -0
- package/src/audit/rubyAnalysisEngine/readGemfileContents.js +18 -0
- package/src/audit/rubyAnalysisEngine/readGemfileLockContents.js +17 -0
- package/src/audit/rubyAnalysisEngine/sanitizer.js +8 -0
- package/src/commands/audit/auditConfig.ts +30 -0
- package/src/commands/audit/auditController.ts +31 -0
- package/src/commands/audit/help.ts +48 -0
- package/src/commands/audit/processAudit.ts +18 -0
- package/src/commands/audit/saveFile.ts +6 -0
- package/src/commands/auth/auth.js +26 -2
- package/src/commands/config/config.js +22 -8
- package/src/commands/scan/processScan.js +9 -13
- package/src/common/HTTPClient.js +149 -14
- package/src/common/errorHandling.ts +85 -2
- package/src/common/versionChecker.ts +39 -0
- package/src/constants/constants.js +5 -4
- package/src/constants/lambda.js +45 -4
- package/src/constants/locales.js +76 -26
- package/src/constants.js +204 -23
- package/src/index.ts +67 -27
- package/src/lambda/aws.ts +13 -12
- package/src/lambda/help.ts +4 -0
- package/src/lambda/lambda.ts +53 -34
- package/src/lambda/lambdaUtils.ts +111 -0
- package/src/lambda/logUtils.ts +19 -1
- package/src/lambda/scanDetailCompletion.ts +4 -4
- package/src/lambda/scanRequest.ts +13 -11
- package/src/lambda/utils.ts +149 -81
- package/src/sbom/generateSbom.ts +17 -0
- package/src/scan/autoDetection.js +0 -29
- package/src/scan/fileUtils.js +1 -1
- package/src/scan/help.js +14 -45
- package/src/scan/populateProjectIdAndProjectName.js +5 -0
- package/src/scan/saveResults.js +14 -0
- package/src/scan/scan.js +127 -58
- package/src/scan/scanConfig.js +54 -0
- package/src/scan/scanController.js +22 -15
- package/src/scan/scanResults.js +32 -19
- package/src/utils/commonApi.js +2 -3
- package/src/utils/getConfig.ts +2 -0
- package/src/utils/paramsUtil/commandlineParams.js +1 -26
- package/src/utils/paramsUtil/paramHandler.js +3 -7
- package/src/utils/parsedCLIOptions.js +11 -9
- package/src/utils/requestUtils.js +1 -1
- package/src/utils/saveFile.js +19 -0
- package/dist/lambda/scanDetail.js +0 -30
- package/dist/scan/fileFinder.js +0 -15
- package/dist/utils/paramsUtil/yamlParams.js +0 -6
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
const i18n = require('i18n')
|
|
2
|
+
|
|
3
|
+
module.exports = exports = ({ language: { projectFilePath }, java }, next) => {
|
|
4
|
+
const { mvnDependancyTreeOutput } = java
|
|
5
|
+
|
|
6
|
+
if (projectFilePath.endsWith('pom.xml')) {
|
|
7
|
+
try {
|
|
8
|
+
java.mavenDependencyTrees = parseMvn(mvnDependancyTreeOutput)
|
|
9
|
+
next()
|
|
10
|
+
} catch (err) {
|
|
11
|
+
next(new Error(i18n.__('javaParseProjectFile') + `${err.message}`))
|
|
12
|
+
return
|
|
13
|
+
}
|
|
14
|
+
} else {
|
|
15
|
+
// Go to gradle project
|
|
16
|
+
next()
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const hasVersion = key => {
|
|
21
|
+
var regex = RegExp('[0-9].[0-9]')
|
|
22
|
+
return regex.test(key)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const formatKeyName = value => {
|
|
26
|
+
let tempArr = value.split(':')
|
|
27
|
+
let versionIndex = undefined
|
|
28
|
+
for (let i = 0; i < tempArr.length; i++) {
|
|
29
|
+
if (hasVersion(tempArr[i])) {
|
|
30
|
+
versionIndex = i
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return tempArr[0] + '/' + tempArr[1] + '@' + tempArr[versionIndex]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const shaveConsoleOutputUntilItFindsFirsDigraphMention = mvnDependancyTreeOutput => {
|
|
38
|
+
//shaves of the console output until it reaches the first digraph
|
|
39
|
+
return mvnDependancyTreeOutput.substring(
|
|
40
|
+
mvnDependancyTreeOutput.indexOf('digraph')
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const getDigraphObjInfo = editedOutput => {
|
|
45
|
+
//turns the output into an array of digraph information
|
|
46
|
+
// which looks like
|
|
47
|
+
// ' "com.contrastsecurity:teamserver-model:jar:local" {\n
|
|
48
|
+
// \n [INFO] "com.contrastsecurity:teamserver-model:jar:local" -> "junit:junit:jar:4.12:test" ;\n
|
|
49
|
+
// \n [INFO] "junit:junit:jar:4.12:test" -> "org.hamcrest:hamcrest-core:jar:1.3:test" ;\n
|
|
50
|
+
// [INFO] }' ]
|
|
51
|
+
let digraphObj = editedOutput.split('digraph')
|
|
52
|
+
|
|
53
|
+
return digraphObj.filter(v => v != '')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const createDigraphObjKey = element => {
|
|
57
|
+
// parse the digraph to turn into an object key
|
|
58
|
+
let formatObjKey = element.substring(0, element.indexOf('{'))
|
|
59
|
+
formatObjKey = formatObjKey.replace(/"/g, '')
|
|
60
|
+
formatObjKey = formatObjKey.replace('{', '')
|
|
61
|
+
formatObjKey = formatObjKey.trim()
|
|
62
|
+
|
|
63
|
+
return formatObjKey
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const turnDigraphDependanciesIntoArrOfInnerDep = digraphObj => {
|
|
67
|
+
// takes:
|
|
68
|
+
// "com.contrastsecurity:teamserver-model:jar:local" {
|
|
69
|
+
// [INFO] "com.contrastsecurity:teamserver-model:jar:local" -> "org.springframework:spring-core:jar:5.1.9.RELEASE:compile" ;
|
|
70
|
+
// [INFO] "com.contrastsecurity:teamserver-model:jar:local" -> "junit:junit:jar:4.12:test" ;
|
|
71
|
+
// [INFO] "org.springframework:spring-core:jar:5.1.9.RELEASE:compile" -> "org.springframework:spring-jcl:jar:5.1.9.RELEASE:compile" ;
|
|
72
|
+
// [INFO] "junit:junit:jar:4.12:test" -> "org.hamcrest:hamcrest-core:jar:1.3:test" ;
|
|
73
|
+
// [INFO] }
|
|
74
|
+
|
|
75
|
+
// and turns it into
|
|
76
|
+
// [ '"com.contrastsecurity:teamserver-model:jar:local" -> "org.springframework:spring-core:jar:5.1.9.RELEASE:compile"',
|
|
77
|
+
// '"com.contrastsecurity:teamserver-model:jar:local" -> "junit:junit:jar:4.12:test"',
|
|
78
|
+
// '"org.springframework:spring-core:jar:5.1.9.RELEASE:compile" -> "org.springframework:spring-jcl:jar:5.1.9.RELEASE:compile"',
|
|
79
|
+
// '"junit:junit:jar:4.12:test" -> "org.hamcrest:hamcrest-core:jar:1.3:test"',
|
|
80
|
+
// '' ]
|
|
81
|
+
|
|
82
|
+
let depRow = digraphObj.substring(
|
|
83
|
+
digraphObj.indexOf('{'),
|
|
84
|
+
digraphObj.indexOf('}') + 1
|
|
85
|
+
)
|
|
86
|
+
depRow = depRow.replace(/\[INFO\]/g, '')
|
|
87
|
+
depRow = depRow.replace(/\n/g, '')
|
|
88
|
+
depRow = depRow.replace(/\{/g, '')
|
|
89
|
+
depRow = depRow.replace(/\}/g, '')
|
|
90
|
+
depRow = depRow.replace(/\"/g, '') // eslint-disable-line
|
|
91
|
+
|
|
92
|
+
return depRow.split(';').map(s => s.trim())
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const createOuterDependanciesAndType = (digraphObjKey, arrOfInnerDep) => {
|
|
96
|
+
let leftKey
|
|
97
|
+
let rightKey
|
|
98
|
+
let newDepNode
|
|
99
|
+
const list = []
|
|
100
|
+
|
|
101
|
+
arrOfInnerDep.forEach(element => {
|
|
102
|
+
leftKey = element.substring(0, element.indexOf(' -'))
|
|
103
|
+
rightKey = element.substring(element.indexOf('>') + 2)
|
|
104
|
+
|
|
105
|
+
// if the digraph and the leftKey are the same and the left has a version
|
|
106
|
+
// then “edgeType” is direct
|
|
107
|
+
if (leftKey === digraphObjKey) {
|
|
108
|
+
if (hasVersion(rightKey)) {
|
|
109
|
+
let rightKeyArr = rightKey.split(':')
|
|
110
|
+
newDepNode = {
|
|
111
|
+
[rightKey]: {
|
|
112
|
+
group: rightKeyArr[0],
|
|
113
|
+
artifactID: rightKeyArr[1],
|
|
114
|
+
packaging: rightKeyArr[2],
|
|
115
|
+
version: rightKeyArr[3],
|
|
116
|
+
scope: rightKeyArr[4],
|
|
117
|
+
type: 'direct',
|
|
118
|
+
parent: leftKey,
|
|
119
|
+
edges: {}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
list.push(newDepNode)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// if right and left both have versions and left doesn't match digraph name
|
|
126
|
+
// then “type” is transitive
|
|
127
|
+
if (
|
|
128
|
+
hasVersion(leftKey) &&
|
|
129
|
+
hasVersion(rightKey) &&
|
|
130
|
+
!(leftKey === digraphObjKey)
|
|
131
|
+
) {
|
|
132
|
+
let rightKeyArr = rightKey.split(':')
|
|
133
|
+
newDepNode = {
|
|
134
|
+
[rightKey]: {
|
|
135
|
+
group: rightKeyArr[0],
|
|
136
|
+
artifactID: rightKeyArr[1],
|
|
137
|
+
packaging: rightKeyArr[2],
|
|
138
|
+
version: rightKeyArr[3],
|
|
139
|
+
scope: rightKeyArr[4],
|
|
140
|
+
type: 'transitive',
|
|
141
|
+
parent: leftKey,
|
|
142
|
+
edges: {}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
list.push(newDepNode)
|
|
146
|
+
}
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
return list
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const createEdges = (digraphObjKey, listOuterDep) => {
|
|
153
|
+
listOuterDep.forEach(element => {
|
|
154
|
+
const key = Object.keys(element).toString()
|
|
155
|
+
|
|
156
|
+
const childParentRef = element[key].parent
|
|
157
|
+
|
|
158
|
+
if (childParentRef !== digraphObjKey) {
|
|
159
|
+
listOuterDep.forEach(i => {
|
|
160
|
+
let parentKey = Object.keys(i).toString()
|
|
161
|
+
if (childParentRef === parentKey) {
|
|
162
|
+
i[parentKey].edges[formatKeyName(key)] = formatKeyName(key)
|
|
163
|
+
}
|
|
164
|
+
})
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
return listOuterDep
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const extractFromArrAndFinalParse = listWithEdges => {
|
|
171
|
+
let finalObj = {}
|
|
172
|
+
listWithEdges.forEach(element => {
|
|
173
|
+
const key = Object.keys(element).toString()
|
|
174
|
+
|
|
175
|
+
const parsedKey = formatKeyName(key)
|
|
176
|
+
|
|
177
|
+
delete element[key].parent
|
|
178
|
+
|
|
179
|
+
finalObj[parsedKey] = element[key]
|
|
180
|
+
})
|
|
181
|
+
return finalObj
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const dependancyValueCreationOrganiser = (digraphObjKey, digraph) => {
|
|
185
|
+
const arrOfInnerDep = turnDigraphDependanciesIntoArrOfInnerDep(digraph)
|
|
186
|
+
const listOuterDep = createOuterDependanciesAndType(
|
|
187
|
+
digraphObjKey,
|
|
188
|
+
arrOfInnerDep
|
|
189
|
+
)
|
|
190
|
+
const listWithEdges = createEdges(digraphObjKey, listOuterDep)
|
|
191
|
+
const finishDepObj = extractFromArrAndFinalParse(listWithEdges)
|
|
192
|
+
|
|
193
|
+
return finishDepObj
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const parseMvn = mvnDependancyTreeOutput => {
|
|
197
|
+
let parsedDepObj = {}
|
|
198
|
+
let editedOutput = shaveConsoleOutputUntilItFindsFirsDigraphMention(
|
|
199
|
+
mvnDependancyTreeOutput
|
|
200
|
+
)
|
|
201
|
+
let digraphObjArray = getDigraphObjInfo(editedOutput)
|
|
202
|
+
|
|
203
|
+
digraphObjArray.forEach(digraph => {
|
|
204
|
+
const digraphObjKey = createDigraphObjKey(digraph)
|
|
205
|
+
parsedDepObj[digraphObjKey] = dependancyValueCreationOrganiser(
|
|
206
|
+
digraphObjKey,
|
|
207
|
+
digraph
|
|
208
|
+
)
|
|
209
|
+
})
|
|
210
|
+
return parsedDepObj
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// testing purposes
|
|
214
|
+
exports.shaveConsoleOutputUntilItFindsFirsDigraphMention = shaveConsoleOutputUntilItFindsFirsDigraphMention
|
|
215
|
+
exports.getDigraphObjInfo = getDigraphObjInfo
|
|
216
|
+
exports.createDigraphObjKey = createDigraphObjKey
|
|
217
|
+
exports.turnDigraphDependanciesIntoArrOfInnerDep = turnDigraphDependanciesIntoArrOfInnerDep
|
|
218
|
+
exports.hasVersion = hasVersion
|
|
219
|
+
exports.formatKeyName = formatKeyName
|
|
220
|
+
exports.createOuterDependanciesAndType = createOuterDependanciesAndType
|
|
221
|
+
exports.extractFromArrAndFinalParse = extractFromArrAndFinalParse
|
|
222
|
+
exports.createEdges = createEdges
|
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
const i18n = require('i18n')
|
|
2
|
+
let projectType = ''
|
|
3
|
+
const StringBuilder = require('string-builder')
|
|
4
|
+
let sb = new StringBuilder()
|
|
5
|
+
|
|
6
|
+
module.exports = exports = (
|
|
7
|
+
{ language: { projectFilePath }, java },
|
|
8
|
+
next,
|
|
9
|
+
config
|
|
10
|
+
) => {
|
|
11
|
+
const { mvnDependancyTreeOutput } = java
|
|
12
|
+
if (
|
|
13
|
+
projectFilePath.endsWith('build.gradle') ||
|
|
14
|
+
projectFilePath.endsWith('pom.xml')
|
|
15
|
+
) {
|
|
16
|
+
if (projectFilePath.endsWith('build.gradle')) {
|
|
17
|
+
projectType = 'Gradle'
|
|
18
|
+
} else {
|
|
19
|
+
projectType = 'Maven'
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
java.mavenDependencyTrees = parseGradle(mvnDependancyTreeOutput, config)
|
|
23
|
+
next()
|
|
24
|
+
} catch (err) {
|
|
25
|
+
next(new Error(i18n.__('javaParseProjectFile') + `${err.message}`))
|
|
26
|
+
return
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
next()
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const preParser = shavedOutput => {
|
|
34
|
+
let obj = []
|
|
35
|
+
for (let dep in shavedOutput) {
|
|
36
|
+
obj.push(
|
|
37
|
+
shavedOutput[dep]
|
|
38
|
+
.replace('+-', '+---')
|
|
39
|
+
.replace('[INFO]', '')
|
|
40
|
+
.replace('\\-', '\\---')
|
|
41
|
+
.replace(':jar:', ':')
|
|
42
|
+
.replace(':test', '')
|
|
43
|
+
.replace(':compile', '')
|
|
44
|
+
.replace(' +', '+')
|
|
45
|
+
.replace(' |', '|')
|
|
46
|
+
.replace(' \\', '\\')
|
|
47
|
+
.replace(':runtime', '')
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let depTree = []
|
|
52
|
+
for (let x in obj) {
|
|
53
|
+
let nodeLevel = computeRelationToLastElement(obj[x])
|
|
54
|
+
|
|
55
|
+
let notLastLevel =
|
|
56
|
+
obj[x].startsWith('|') ||
|
|
57
|
+
obj[x].startsWith('+') ||
|
|
58
|
+
obj[x].startsWith('\\')
|
|
59
|
+
|
|
60
|
+
if (notLastLevel) {
|
|
61
|
+
if (nodeLevel === 0) {
|
|
62
|
+
depTree.push(obj[x])
|
|
63
|
+
} else {
|
|
64
|
+
let level = computeLevel(nodeLevel)
|
|
65
|
+
let validatedLevel = addIndentation(nodeLevel === 2 ? 5 : level, obj[x])
|
|
66
|
+
depTree.push(validatedLevel)
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
let level = computeLevel(nodeLevel)
|
|
70
|
+
let validatedLevel = addIndentation(nodeLevel === 3 ? 5 : level, obj[x])
|
|
71
|
+
depTree.push(validatedLevel)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return depTree
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const shaveOutput = gradleDependencyTreeOutput => {
|
|
79
|
+
let shavedOutput = gradleDependencyTreeOutput.split('\n')
|
|
80
|
+
|
|
81
|
+
if (projectType === 'Maven') {
|
|
82
|
+
shavedOutput = preParser(shavedOutput)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
let obj = []
|
|
86
|
+
for (let key in shavedOutput) {
|
|
87
|
+
if (shavedOutput[key].includes('project :')) {
|
|
88
|
+
//skip
|
|
89
|
+
} else if (
|
|
90
|
+
shavedOutput[key].includes('+---') ||
|
|
91
|
+
shavedOutput[key].includes('\\---')
|
|
92
|
+
) {
|
|
93
|
+
obj.push(shavedOutput[key])
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return obj
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const computeIndentation = element => {
|
|
100
|
+
let hasPlus = element.includes('+')
|
|
101
|
+
let hasSlash = element.includes('\\')
|
|
102
|
+
if (hasPlus) {
|
|
103
|
+
return element.substring(element.indexOf('+'))
|
|
104
|
+
}
|
|
105
|
+
if (hasSlash) {
|
|
106
|
+
return element.substring(element.indexOf('\\'))
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const computeLevel = nodeLevel => {
|
|
111
|
+
let num = [5, 8, 11, 14, 17, 20]
|
|
112
|
+
for (let z in num) {
|
|
113
|
+
if (num[z] === nodeLevel) {
|
|
114
|
+
let n = parseInt(z)
|
|
115
|
+
return 5 * (n + 2)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const addIndentation = (number, str) => {
|
|
121
|
+
str = computeIndentation(str)
|
|
122
|
+
sb.clear() // need to clear so each dep doesn't append to the string
|
|
123
|
+
for (let j = 0; j < number; j++) {
|
|
124
|
+
sb.append(' ')
|
|
125
|
+
}
|
|
126
|
+
sb.append(str)
|
|
127
|
+
return sb.toString()
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const computeRelationToLastElement = element => {
|
|
131
|
+
let hasPlus = element.includes('+---')
|
|
132
|
+
let hasSlash = element.includes('\\---')
|
|
133
|
+
if (hasPlus) {
|
|
134
|
+
return element.split('+---')[0].length
|
|
135
|
+
}
|
|
136
|
+
if (hasSlash) {
|
|
137
|
+
return element.split('\\---')[0].length
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const stripElement = element => {
|
|
142
|
+
return element
|
|
143
|
+
.replace(/[|]/g, '')
|
|
144
|
+
.replace('+---', '')
|
|
145
|
+
.replace('\\---', '')
|
|
146
|
+
.replace(/[' ']/g, '')
|
|
147
|
+
.replace('(c)', '')
|
|
148
|
+
.replace('->', '@')
|
|
149
|
+
.replace('(*)', '')
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const checkVersion = element => {
|
|
153
|
+
let version = element.split(':')
|
|
154
|
+
return version[version.length - 1]
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const createElement = (element, isRoot) => {
|
|
158
|
+
let tree
|
|
159
|
+
let cleanElement = stripElement(element)
|
|
160
|
+
let splitGroupName = cleanElement.split(':')
|
|
161
|
+
|
|
162
|
+
let validateVersion = false
|
|
163
|
+
if (!element.includes('->')) {
|
|
164
|
+
validateVersion = true
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
tree = {
|
|
168
|
+
artifactID: splitGroupName[1],
|
|
169
|
+
group: splitGroupName[0],
|
|
170
|
+
version: validateVersion
|
|
171
|
+
? checkVersion(cleanElement)
|
|
172
|
+
: splitGroupName[splitGroupName.length - 1],
|
|
173
|
+
scope: 'compile',
|
|
174
|
+
type: isRoot ? 'direct' : 'transitive',
|
|
175
|
+
edges: {}
|
|
176
|
+
}
|
|
177
|
+
return tree
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const getElementHeader = element => {
|
|
181
|
+
let elementHeader = stripElement(element)
|
|
182
|
+
elementHeader = elementHeader.replace(':', '/')
|
|
183
|
+
elementHeader = elementHeader.replace(':', '@')
|
|
184
|
+
|
|
185
|
+
return elementHeader
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const buildElement = (element, rootElement, parentOfCurrent, tree, isRoot) => {
|
|
189
|
+
let childElement = createElement(element, isRoot)
|
|
190
|
+
let elementHeader = getElementHeader(element)
|
|
191
|
+
let levelsArray = [rootElement, parentOfCurrent]
|
|
192
|
+
const treeNode = getNestedObject(tree, levelsArray)
|
|
193
|
+
const rootNode = getNestedObject(tree, [rootElement])
|
|
194
|
+
|
|
195
|
+
// eslint-disable-next-line
|
|
196
|
+
if (!rootNode.hasOwnProperty(elementHeader)) {
|
|
197
|
+
tree[rootElement][elementHeader] = childElement
|
|
198
|
+
}
|
|
199
|
+
treeNode.edges[elementHeader] = elementHeader
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const hasChildren = (nextNodeLevel, nodeLevel) => {
|
|
203
|
+
if (nextNodeLevel > nodeLevel) {
|
|
204
|
+
return true
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const lastChild = (nextNodeLevel, nodeLevel) => {
|
|
209
|
+
if (nextNodeLevel < nodeLevel) {
|
|
210
|
+
return true
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const calculateLevels = (nextNodeLevel, nodeLevel) => {
|
|
215
|
+
return (nodeLevel - nextNodeLevel) / 5
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const buildTree = shavedOutput => {
|
|
219
|
+
let tree = {}
|
|
220
|
+
let rootElement
|
|
221
|
+
let levelNodes = []
|
|
222
|
+
|
|
223
|
+
shavedOutput.forEach((element, index) => {
|
|
224
|
+
if (index === 0) {
|
|
225
|
+
// console.log(element, index)
|
|
226
|
+
let cleanElement = stripElement(element)
|
|
227
|
+
let elementHeader = getElementHeader(cleanElement)
|
|
228
|
+
let splitElement = element.split(' ')
|
|
229
|
+
let splitGroupName = splitElement[1].split(':')
|
|
230
|
+
|
|
231
|
+
let validateVersion = false
|
|
232
|
+
if (!element.includes('->')) {
|
|
233
|
+
validateVersion = true
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
tree[splitGroupName[0]] = {}
|
|
237
|
+
tree[splitGroupName[0]][elementHeader] = {
|
|
238
|
+
artifactID: splitGroupName[1],
|
|
239
|
+
group: splitGroupName[0],
|
|
240
|
+
version: validateVersion
|
|
241
|
+
? checkVersion(cleanElement)
|
|
242
|
+
: splitElement[splitElement.length - 1],
|
|
243
|
+
scope: 'compile',
|
|
244
|
+
type: 'direct',
|
|
245
|
+
edges: {}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
rootElement = splitGroupName[0]
|
|
249
|
+
levelNodes.push(elementHeader)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (shavedOutput.length - 1 === index) {
|
|
253
|
+
// console.log(element, index)
|
|
254
|
+
const parentOfCurrent = levelNodes[levelNodes.length - 1]
|
|
255
|
+
let nodeLevel = computeRelationToLastElement(element)
|
|
256
|
+
|
|
257
|
+
let validateVersion = false
|
|
258
|
+
if (!element.includes('->')) {
|
|
259
|
+
validateVersion = true
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (nodeLevel === 0) {
|
|
263
|
+
let cleanElement = stripElement(element)
|
|
264
|
+
let elementHeader = getElementHeader(cleanElement)
|
|
265
|
+
let splitElement = element.split(' ')
|
|
266
|
+
let splitGroupName = splitElement[1].split(':')
|
|
267
|
+
tree[rootElement][elementHeader] = {
|
|
268
|
+
artifactID: splitGroupName[1],
|
|
269
|
+
group: splitGroupName[0],
|
|
270
|
+
version: validateVersion
|
|
271
|
+
? checkVersion(cleanElement)
|
|
272
|
+
: splitElement[splitElement.length - 1],
|
|
273
|
+
scope: 'compile',
|
|
274
|
+
type: 'direct',
|
|
275
|
+
edges: {}
|
|
276
|
+
}
|
|
277
|
+
} else {
|
|
278
|
+
buildElement(element, rootElement, parentOfCurrent, tree)
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (index >= 1 && index < shavedOutput.length - 1) {
|
|
283
|
+
let nodeLevel = computeRelationToLastElement(element)
|
|
284
|
+
let nextNodeLevel = computeRelationToLastElement(shavedOutput[index + 1])
|
|
285
|
+
const parentOfCurrent = levelNodes[levelNodes.length - 1]
|
|
286
|
+
|
|
287
|
+
let isRoot = false
|
|
288
|
+
if (nodeLevel === 0) {
|
|
289
|
+
isRoot = true
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// useful for debugging
|
|
293
|
+
// console.log(
|
|
294
|
+
// element,
|
|
295
|
+
// index,
|
|
296
|
+
// 'nodeLevel:',
|
|
297
|
+
// nodeLevel,
|
|
298
|
+
// 'nextNodeLevel:',
|
|
299
|
+
// nextNodeLevel,
|
|
300
|
+
// 'parentofCurrent:',
|
|
301
|
+
// parentOfCurrent
|
|
302
|
+
// )
|
|
303
|
+
|
|
304
|
+
if (isRoot) {
|
|
305
|
+
let cleanElement = stripElement(element)
|
|
306
|
+
let elementHeader = getElementHeader(cleanElement)
|
|
307
|
+
let splitElement = element.split(' ')
|
|
308
|
+
let splitGroupName = splitElement[1].split(':')
|
|
309
|
+
|
|
310
|
+
let validateVersion = false
|
|
311
|
+
if (!element.includes('->')) {
|
|
312
|
+
validateVersion = true
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
tree[rootElement][elementHeader] = {
|
|
316
|
+
artifactID: splitGroupName[1],
|
|
317
|
+
group: splitGroupName[0],
|
|
318
|
+
version: validateVersion
|
|
319
|
+
? checkVersion(cleanElement)
|
|
320
|
+
: splitElement[splitElement.length - 1],
|
|
321
|
+
scope: 'compile',
|
|
322
|
+
type: 'direct',
|
|
323
|
+
edges: {}
|
|
324
|
+
}
|
|
325
|
+
levelNodes.push(elementHeader)
|
|
326
|
+
return
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
let elementHeader = getElementHeader(element)
|
|
330
|
+
buildElement(element, rootElement, parentOfCurrent, tree, isRoot)
|
|
331
|
+
|
|
332
|
+
if (hasChildren(nextNodeLevel, nodeLevel)) {
|
|
333
|
+
buildElement(element, rootElement, parentOfCurrent, tree, isRoot)
|
|
334
|
+
levelNodes.push(elementHeader)
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (lastChild(nextNodeLevel, nodeLevel)) {
|
|
338
|
+
let levelDifference = calculateLevels(nextNodeLevel, nodeLevel)
|
|
339
|
+
if (levelDifference === 0) {
|
|
340
|
+
levelNodes.pop()
|
|
341
|
+
} else {
|
|
342
|
+
let i
|
|
343
|
+
for (i = 0; i < levelDifference; i++) {
|
|
344
|
+
levelNodes.pop()
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
})
|
|
350
|
+
|
|
351
|
+
return tree
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const getNestedObject = (nestedObj, pathArr) => {
|
|
355
|
+
return pathArr.reduce(
|
|
356
|
+
(obj, key) => (obj && obj[key] !== 'undefined' ? obj[key] : undefined),
|
|
357
|
+
nestedObj
|
|
358
|
+
)
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// emit any "+--- project :" within the tree
|
|
362
|
+
const parseSubProject = shavedOutput => {
|
|
363
|
+
let obj = []
|
|
364
|
+
for (let key in shavedOutput) {
|
|
365
|
+
if (!shavedOutput[key].includes('project')) {
|
|
366
|
+
obj.push(shavedOutput[key])
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return obj
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const validateIndentation = shavedOutput => {
|
|
373
|
+
let validatedTree = []
|
|
374
|
+
shavedOutput.forEach((element, index) => {
|
|
375
|
+
let nextNodeLevel
|
|
376
|
+
let nodeLevel = computeRelationToLastElement(element)
|
|
377
|
+
if (shavedOutput[index + 1] !== undefined) {
|
|
378
|
+
nextNodeLevel = computeRelationToLastElement(shavedOutput[index + 1])
|
|
379
|
+
}
|
|
380
|
+
if (index === 0) {
|
|
381
|
+
validatedTree.push(shavedOutput[index])
|
|
382
|
+
validatedTree.push(shavedOutput[index + 1])
|
|
383
|
+
} else if (nextNodeLevel > nodeLevel + 5) {
|
|
384
|
+
return
|
|
385
|
+
} else {
|
|
386
|
+
validatedTree.push(shavedOutput[index + 1])
|
|
387
|
+
}
|
|
388
|
+
})
|
|
389
|
+
validatedTree.pop()
|
|
390
|
+
return validatedTree
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
const parseGradle = (gradleDependencyTreeOutput, config) => {
|
|
394
|
+
let shavedOutput = shaveOutput(gradleDependencyTreeOutput)
|
|
395
|
+
|
|
396
|
+
if (config.subProject) {
|
|
397
|
+
let subProject = parseSubProject(shavedOutput)
|
|
398
|
+
let validatedOutput = validateIndentation(subProject)
|
|
399
|
+
return buildTree(validatedOutput)
|
|
400
|
+
} else {
|
|
401
|
+
let validatedOutput = validateIndentation(shavedOutput)
|
|
402
|
+
return buildTree(validatedOutput)
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
exports.shaveOutput = shaveOutput
|
|
407
|
+
exports.validateIndentation = validateIndentation
|
|
408
|
+
exports.stripElement = stripElement
|
|
409
|
+
exports.getElementHeader = getElementHeader
|
|
410
|
+
exports.createElement = createElement
|
|
411
|
+
exports.parseGradle = parseGradle
|
|
412
|
+
exports.computeRelationToLastElement = computeRelationToLastElement
|
|
413
|
+
exports.hasChildren = hasChildren
|
|
414
|
+
exports.lastChild = lastChild
|
|
415
|
+
exports.calculateLevels = calculateLevels
|
|
416
|
+
exports.buildElement = buildElement
|
|
417
|
+
exports.checkVersion = checkVersion
|
|
418
|
+
exports.computeIndentation = computeIndentation
|
|
419
|
+
exports.computeLevel = computeLevel
|
|
420
|
+
exports.addIndentation = addIndentation
|