From 1b03bbe13d65a5907a24d68732f822f0dd5a27c2 Mon Sep 17 00:00:00 2001 From: Michael Gokhman Date: Sun, 7 Oct 2018 11:37:40 +0300 Subject: [PATCH] feat: option to specify sub-project in multi-project build --- lib/index.js | 20 ++++++-- test/fixtures/multi-project/build.gradle | 0 test/fixtures/multi-project/settings.gradle | 5 ++ .../multi-project/subproj/build.gradle | 49 +++++++++++++++++++ test/system/plugin.test.js | 24 +++++++++ 5 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 test/fixtures/multi-project/build.gradle create mode 100644 test/fixtures/multi-project/settings.gradle create mode 100644 test/fixtures/multi-project/subproj/build.gradle diff --git a/lib/index.js b/lib/index.js index 4a9468a..aa587a5 100644 --- a/lib/index.js +++ b/lib/index.js @@ -19,8 +19,9 @@ function inspect(root, targetFile, options) { options = {dev: false}; } var command = getCommand(root, targetFile); - var args = buildArgs(root, targetFile, options.args); - return getPackage(root, command, args) + var subProject = options['gradle-sub-project']; + var args = buildArgs(root, targetFile, options.args, subProject); + return getPackage(root, command, args, subProject) .then(function (pkg) { // opt-in with `jars` or `localjars` flag if (options.jars || options.localjars) { @@ -53,10 +54,13 @@ function inspect(root, targetFile, options) { }); } -function getPackage(root, command, args) { +function getPackage(root, command, args, subProject) { return subProcess.execute(command, args, {cwd: root}) .then(function (result) { var packageName = path.basename(root); + if (subProject) { + packageName += '/' + subProject; + } var packageVersion = '0.0.0'; var depTree = depParser.parse(result); return { @@ -97,8 +101,14 @@ function getCommand(root, targetFile) { return 'gradle'; } -function buildArgs(root, targetFile, gradleArgs) { - var args = ['dependencies', '-q']; +function buildArgs(root, targetFile, gradleArgs, subProject) { + var args = []; + if (subProject) { + args.push(subProject + ':dependencies'); + } else { + args.push('dependencies'); + } + args.push('-q'); if (targetFile) { if (!fs.existsSync(path.resolve(root, targetFile))) { throw new Error('File not found: ' + targetFile); diff --git a/test/fixtures/multi-project/build.gradle b/test/fixtures/multi-project/build.gradle new file mode 100644 index 0000000..e69de29 diff --git a/test/fixtures/multi-project/settings.gradle b/test/fixtures/multi-project/settings.gradle new file mode 100644 index 0000000..90289e8 --- /dev/null +++ b/test/fixtures/multi-project/settings.gradle @@ -0,0 +1,5 @@ +rootProject.name = 'root-proj' + +include 'subproj' + + diff --git a/test/fixtures/multi-project/subproj/build.gradle b/test/fixtures/multi-project/subproj/build.gradle new file mode 100644 index 0000000..4ebc8bb --- /dev/null +++ b/test/fixtures/multi-project/subproj/build.gradle @@ -0,0 +1,49 @@ +apply plugin: 'java' +apply plugin: 'maven' + +group = 'com.github.jitpack' + +sourceCompatibility = 1.8 // java 8 +targetCompatibility = 1.8 + +repositories { + mavenCentral() +} + +dependencies { + compile 'com.google.guava:guava:18.0' + 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' +} + +task sourcesJar(type: Jar, dependsOn: classes) { + classifier = 'sources' + from sourceSets.main.allSource +} + +task javadocJar(type: Jar, dependsOn: javadoc) { + classifier = 'javadoc' + from javadoc.destinationDir +} + +artifacts { + archives sourcesJar + archives javadocJar +} + +// To specify a license in the pom: +install { + repositories.mavenInstaller { + pom.project { + licenses { + license { + name 'The Apache Software License, Version 2.0' + url 'http://www.apache.org/licenses/LICENSE-2.0.txt' + distribution 'repo' + } + } + } + } +} diff --git a/test/system/plugin.test.js b/test/system/plugin.test.js index 0cbb1fb..25abbd3 100644 --- a/test/system/plugin.test.js +++ b/test/system/plugin.test.js @@ -137,6 +137,30 @@ test('darwin with wrapper in root', function (t) { }); }); +test('only sub-project has deps', function (t) { + t.plan(2); + const options = { + 'gradle-sub-project': 'subproj', + }; + return plugin.inspect('.', + path.join(__dirname, '..', 'fixtures', 'multi-project', 'build.gradle'), + options) + .then(function (result) { + t.match(result.package.name, '/subproj', + 'sub project name is included in the root pkg name'); + + t.equal(result.package + .dependencies['com.android.tools.build:builder'] + .dependencies['com.android.tools:sdklib'] + .dependencies['com.android.tools:repository'] + .dependencies['com.android.tools:common'] + .dependencies['com.android.tools:annotations'].version, + '25.3.0', + 'correct version found'); + }) + .catch(t.fail); +}); + function stubPlatform(platform, t) { sinon.stub(os, 'platform') .callsFake(function () {