snyk-gradle-plugin
Advanced tools
Comparing version 3.1.0 to 3.2.0
@@ -8,2 +8,3 @@ import { legacyCommon, legacyPlugin as api } from '@snyk/cli-interface'; | ||
declare type Options = api.InspectOptions & GradleInspectOptions; | ||
declare type VersionBuildInfo = api.VersionBuildInfo; | ||
export declare function inspect(root: string, targetFile: string, options?: api.SingleSubprojectInspectOptions & GradleInspectOptions): Promise<api.SinglePackageResult>; | ||
@@ -15,2 +16,3 @@ export declare function inspect(root: string, targetFile: string, options: api.MultiSubprojectInspectOptions & GradleInspectOptions): Promise<api.MultiProjectResult>; | ||
allSubProjectNames: string[]; | ||
versionBuildInfo: VersionBuildInfo; | ||
} | ||
@@ -27,2 +29,4 @@ interface ProjectsDict { | ||
declare function extractJsonFromScriptOutput(stdoutText: string): JsonDepsScriptResult; | ||
declare function getVersionBuildInfo(gradleVersionOutput: string): VersionBuildInfo | undefined; | ||
declare function toCamelCase(input: string): string; | ||
declare function buildArgs(root: string, targetFile: string | null, initGradlePath: string, options: Options): string[]; | ||
@@ -32,3 +36,5 @@ export declare const exportsForTests: { | ||
extractJsonFromScriptOutput: typeof extractJsonFromScriptOutput; | ||
getVersionBuildInfo: typeof getVersionBuildInfo; | ||
toCamelCase: typeof toCamelCase; | ||
}; | ||
export {}; |
@@ -71,2 +71,3 @@ "use strict"; | ||
gradleProjectName: depTreeAndDepRootNames.gradleProjectName, | ||
versionBuildInfo: depTreeAndDepRootNames.versionBuildInfo, | ||
}, | ||
@@ -113,2 +114,3 @@ }; | ||
gradleProjectName: meta.gradleProjectName, | ||
versionBuildInfo: allProjectDeps.versionBuildInfo, | ||
}; | ||
@@ -129,2 +131,3 @@ } | ||
gradleProjectName: defaultProject, | ||
versionBuildInfo: allProjectDeps.versionBuildInfo, | ||
}; | ||
@@ -167,2 +170,3 @@ }); | ||
gradleProjectName, | ||
versionBuildInfo: allProjectDeps.versionBuildInfo, | ||
}, | ||
@@ -223,2 +227,38 @@ depTree: { | ||
} | ||
// when running a project is making use of gradle wrapper, the first time we run `gradlew -v`, the download | ||
// process happens, cluttering the parsing of the gradle output. | ||
// will extract the needed data using a regex | ||
function cleanupVersionOutput(gradleVersionOutput) { | ||
const matchedData = gradleVersionOutput.match(/(--[\s\S]*?$)/g); | ||
if (matchedData) { | ||
return matchedData[0]; | ||
} | ||
debugLog('cannot parse gradle version output:' + gradleVersionOutput); | ||
return ''; | ||
} | ||
function getVersionBuildInfo(gradleVersionOutput) { | ||
try { | ||
const cleanedVersionOutput = cleanupVersionOutput(gradleVersionOutput); | ||
if (cleanedVersionOutput !== '') { | ||
const gradleOutputArray = cleanedVersionOutput.split(/\r\n|\r|\n/); | ||
// from first 3 new lines, we get the gradle version | ||
const gradleVersion = gradleOutputArray[1].split(' ')[1].trim(); | ||
const versionMetaInformation = gradleOutputArray.slice(4, gradleOutputArray.length); | ||
// from line 4 until the end we get multiple meta information such as Java, Groovy, Kotlin, etc. | ||
const metaBuildVersion = {}; | ||
// we want to remove all the new lines before processing each line from gradle -v output | ||
versionMetaInformation.map((value) => value.replace(/[\s\S](\r\n|\n|\r)/g, '')) | ||
.filter((value) => value && value.length > 0 && value.includes(': ')) | ||
.map((value) => value.split(/(.*): (.*)/)) | ||
.forEach((splitValue) => metaBuildVersion[toCamelCase(splitValue[1].trim())] = splitValue[2].trim()); | ||
return { | ||
gradleVersion, | ||
metaBuildVersion, | ||
}; | ||
} | ||
} | ||
catch (error) { | ||
debugLog('version build info not present, skipping ahead: ' + error); | ||
} | ||
} | ||
function getAllDeps(root, targetFile, options) { | ||
@@ -246,3 +286,8 @@ return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
} | ||
return extractJsonFromScriptOutput(stdoutText); | ||
const extractedJson = extractJsonFromScriptOutput(stdoutText); | ||
const versionBuildInfo = getVersionBuildInfo(gradleVersionOutput); | ||
if (versionBuildInfo) { | ||
extractedJson.versionBuildInfo = versionBuildInfo; | ||
} | ||
return extractedJson; | ||
} | ||
@@ -316,2 +361,8 @@ catch (error0) { | ||
} | ||
function toCamelCase(input) { | ||
input = input.toLowerCase().replace(/(?:(^.)|([-_\s]+.))/g, (match) => { | ||
return match.charAt(match.length - 1).toUpperCase(); | ||
}); | ||
return input.charAt(0).toLowerCase() + input.substring(1); | ||
} | ||
function getCommand(root, targetFile) { | ||
@@ -385,3 +436,5 @@ const isWinLocal = /^win/.test(os.platform()); // local check, can be stubbed in tests | ||
extractJsonFromScriptOutput, | ||
getVersionBuildInfo, | ||
toCamelCase, | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -43,3 +43,3 @@ { | ||
"dependencies": { | ||
"@snyk/cli-interface": "^2.1.0", | ||
"@snyk/cli-interface": "2.2.0", | ||
"@types/debug": "^4.1.4", | ||
@@ -52,3 +52,3 @@ "chalk": "^2.4.2", | ||
}, | ||
"version": "3.1.0" | ||
"version": "3.2.0" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54328
526
+ Added@snyk/cli-interface@2.2.0(transitive)
- Removed@snyk/cli-interface@2.14.0(transitive)
- Removed@snyk/dep-graph@2.9.0(transitive)
- Removed@types/graphlib@2.1.12(transitive)
- Removedevent-loop-spinner@2.3.2(transitive)
- Removedlodash.clone@4.5.0(transitive)
- Removedlodash.constant@3.0.0(transitive)
- Removedlodash.filter@4.6.0(transitive)
- Removedlodash.foreach@4.5.0(transitive)
- Removedlodash.isempty@4.4.0(transitive)
- Removedlodash.isequal@4.5.0(transitive)
- Removedlodash.isfunction@3.0.9(transitive)
- Removedlodash.isundefined@3.0.1(transitive)
- Removedlodash.map@4.6.0(transitive)
- Removedlodash.reduce@4.6.0(transitive)
- Removedlodash.size@4.2.0(transitive)
- Removedlodash.transform@4.6.0(transitive)
- Removedlodash.union@4.6.0(transitive)
- Removedlodash.values@4.3.0(transitive)
- Removedobject-hash@3.0.0(transitive)
- Removedpackageurl-js@1.2.0(transitive)
- Removedsemver@7.6.3(transitive)
- Removedtslib@2.8.0(transitive)
Updated@snyk/cli-interface@2.2.0