Skip to content

Commit

Permalink
Merge pull request #5 from snyk/feat/hack-jars
Browse files Browse the repository at this point in the history
feat: local jar support
  • Loading branch information
darscan authored Aug 18, 2017
2 parents 10da9bc + ba67cc3 commit a3d2bfb
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 14 deletions.
57 changes: 45 additions & 12 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,30 @@ module.exports = {

function inspect(root, targetFile, options) {
if (!options) { options = { dev: false }; }
return getPackage(root, targetFile, options)
.then(function (pkg) {
// opt-in with `jars` or `localjars` flag
if (options.jars || options.localjars) {
return getJarList(root, targetFile, options)
.then(function (jars) {
if (jars && jars.length) { pkg.jars = jars; }
return pkg;
});
}
return pkg;
})
.then(function (pkg) {
return {
plugin: {
name: 'bundled:gradle',
runtime: 'unknown',
},
package: pkg,
};
});
}

function getPackage(root, targetFile, options) {
return subProcess.execute(
getCommand(root, targetFile),
buildArgs(root, targetFile, options.args),
Expand All @@ -21,23 +44,33 @@ function inspect(root, targetFile, options) {
var packageVersion = '0.0.0';
var from = packageName + '@' + packageVersion;
var depTree = parse(result, from);

return {
plugin: {
name: 'bundled:gradle',
runtime: 'unknown',
},
package: {
dependencies: depTree,
name: packageName,
version: packageVersion,
packageFormatVersion: packageFormatVersion,
from: [from],
},
dependencies: depTree,
name: packageName,
version: packageVersion,
packageFormatVersion: packageFormatVersion,
from: [from],
};
});
}

function getJarList(root, targetFile, options) {
var args = buildArgs(root, targetFile, options.args);
args.shift(); // remove `dependencies` arg
args.push('-I ' + path.join(__dirname, 'init.gradle'));
args.push(options.jars ? 'listAllJars' : 'listLocalJars');
return subProcess.execute(
getCommand(root, targetFile),
args,
{ cwd: root })
.then(function (result) {
if (result && result.length) {
return result.split('\n').filter(Boolean);
}
return [];
});
}

function getCommand(root, targetFile) {
var isWin = /^win/.test(os.platform());
var wrapperScript = isWin ? 'gradlew.bat' : './gradlew';
Expand Down
17 changes: 17 additions & 0 deletions lib/init.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
allprojects {
task listAllJars {
doLast {
configurations.compile.each { File file -> println file.name }
}
}
task listLocalJars {
doLast {
def userDir = System.getProperty("user.dir")
configurations.compile.each {
if (it.absolutePath.contains(userDir)) {
println it.name
}
}
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"test": "test"
},
"scripts": {
"test": "npm run lint && npm run test-functional",
"test": "npm run lint && npm run test-functional && npm run test-system",
"lint": "jscs `find ./lib -name '*.js'` -v && jscs `find ./test -name '*.js'` -v",
"test-functional": "tap `find ./test/functional -name '*.test.js'`",
"test-system": "tap --timeout=300 `find ./test/system -name '*.test.js'`",
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/no-wrapper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repositories {

dependencies {
compile 'com.google.guava:guava:18.0'
compile 'batik:batik-dom:1.6999999'
compile 'batik:batik-dom:1.6'
compile 'commons-discovery:commons-discovery:0.2'
compile 'axis:axis:1.3'
compile 'com.android.tools.build:builder:2.3.0'
Expand Down

0 comments on commit a3d2bfb

Please sign in to comment.