From ba67cc31a0cfee8b000f95de31bfcd40f02ad711 Mon Sep 17 00:00:00 2001 From: Shaun Smith Date: Fri, 18 Aug 2017 22:32:36 +0100 Subject: [PATCH] feat: local jar support Opt-in with --jars or --localjars --- lib/index.js | 57 +++++++++++++++++++++------ lib/init.gradle | 17 ++++++++ package.json | 2 +- test/fixtures/no-wrapper/build.gradle | 2 +- 4 files changed, 64 insertions(+), 14 deletions(-) create mode 100644 lib/init.gradle diff --git a/lib/index.js b/lib/index.js index 8d88c48..b564d09 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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), @@ -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'; diff --git a/lib/init.gradle b/lib/init.gradle new file mode 100644 index 0000000..977ba7f --- /dev/null +++ b/lib/init.gradle @@ -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 + } + } + } + } +} diff --git a/package.json b/package.json index 7cdcd98..1b0bea2 100644 --- a/package.json +++ b/package.json @@ -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'`", diff --git a/test/fixtures/no-wrapper/build.gradle b/test/fixtures/no-wrapper/build.gradle index 0e71304..4ebc8bb 100644 --- a/test/fixtures/no-wrapper/build.gradle +++ b/test/fixtures/no-wrapper/build.gradle @@ -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'