From de1ad50afc2590da2380c93b071ad1ca175342a3 Mon Sep 17 00:00:00 2001 From: Dror Ben-Gai Date: Mon, 9 Jan 2017 17:20:15 +0200 Subject: [PATCH] fix: adding the 'from' array to dependencies in maven (#157) * fix: adding the 'from' array to dependencies in maven * fix: ensure root module is in 'from' array for multi-module dependencies --- lib/module-info/maven/mvn-tree-parse.js | 18 +++++++++++------- test/acceptance/cli.acceptance.test.js | 22 +++++++++++++++++++--- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/lib/module-info/maven/mvn-tree-parse.js b/lib/module-info/maven/mvn-tree-parse.js index 0bb64737e17..1f93cf72e1d 100644 --- a/lib/module-info/maven/mvn-tree-parse.js +++ b/lib/module-info/maven/mvn-tree-parse.js @@ -17,14 +17,14 @@ function getRootProject(text) { var root = getProject(projects[0]); // Add any subsequent projects to the root as dependencies for (var i = 1; i < projects.length; i++) { - var project = getProject(projects[i]); + var project = getProject(projects[i], root); root.dependencies[project.name] = project; } root.packageFormatVersion = packageFormatVersion; return root; } -function getProject(projectDump) { +function getProject(projectDump, parent) { var lines = projectDump.split(newline); var identity = dequote(lines[0]); var deps = {}; @@ -36,22 +36,22 @@ function getProject(projectDump) { deps[source] = deps[source] || []; deps[source].push(target); } - return assemblePackage(identity, deps); + return assemblePackage(identity, deps, parent); } -function assemblePackage(source, projectDeps) { - var sourcePackage = createPackage(source); +function assemblePackage(source, projectDeps, parent) { + var sourcePackage = createPackage(source, parent); var sourceDeps = projectDeps[source]; if (sourceDeps) { for (var i = 0; i < sourceDeps.length; i++) { - var pkg = assemblePackage(sourceDeps[i], projectDeps); + var pkg = assemblePackage(sourceDeps[i], projectDeps, sourcePackage); sourcePackage.dependencies[pkg.name] = pkg; } } return sourcePackage; } -function createPackage(pkgStr) { +function createPackage(pkgStr, parent) { var range = getConstraint(pkgStr); if (range) { pkgStr = pkgStr.substring(0, pkgStr.indexOf(' ')); @@ -65,6 +65,10 @@ function createPackage(pkgStr) { name: parts[0] + ':' + parts[1], dependencies: {}, }; + var selfPkg = parts[0] + ':' + parts[1] + '@' + parts[3]; + result.from = parent ? + parent.from.concat(selfPkg) : + [selfPkg]; if (parts.length === 5) { result.scope = parts[4]; } diff --git a/test/acceptance/cli.acceptance.test.js b/test/acceptance/cli.acceptance.test.js index a4d8133e6a4..b961dab08c5 100644 --- a/test/acceptance/cli.acceptance.test.js +++ b/test/acceptance/cli.acceptance.test.js @@ -233,7 +233,7 @@ test('`monitor ruby-app`', function(t) { }); test('`monitor maven-app`', function(t) { - t.plan(5); + t.plan(8); chdirWorkspaces(); var proxiedCLI = proxyMavenExec('maven-app/mvn-dep-tree-stdout.txt'); return proxiedCLI.monitor('maven-app', {file: 'pom.xml'}).then(function() { @@ -242,14 +242,24 @@ test('`monitor maven-app`', function(t) { t.equal(req.method, 'PUT', 'makes PUT request'); t.match(req.url, '/monitor/maven', 'puts at correct url'); t.equal(pkg.artifactId, 'maven-app', 'specifies artifactId'); + t.equal(pkg.from[0], + 'com.mycompany.app:maven-app@1.0-SNAPSHOT', + 'specifies "from" path for root package'); t.ok(pkg.dependencies['junit:junit'], 'specifies dependency'); - t.equal(pkg.dependencies['junit:junit'].artifactId, 'junit', + t.equal(pkg.dependencies['junit:junit'].artifactId, + 'junit', 'specifies dependency artifactId'); + t.equal(pkg.dependencies['junit:junit'].from[0], + 'com.mycompany.app:maven-app@1.0-SNAPSHOT', + 'specifies "from" path for dependencies'); + t.equal(pkg.dependencies['junit:junit'].from[1], + 'junit:junit@3.8.2', + 'specifies "from" path for dependencies'); }); }); test('`monitor maven-multi-app`', function(t) { - t.plan(5); + t.plan(7); chdirWorkspaces(); var proxiedCLI = proxyMavenExec('maven-multi-app/mvn-dep-tree-stdout.txt'); return proxiedCLI.monitor('maven-multi-app', {file: 'pom.xml'}).then(function() { @@ -258,10 +268,16 @@ test('`monitor maven-multi-app`', function(t) { t.equal(req.method, 'PUT', 'makes PUT request'); t.match(req.url, '/monitor/maven', 'puts at correct url'); t.equal(pkg.artifactId, 'maven-multi-app', 'specifies artifactId'); + t.equal(pkg.from[0], + 'com.mycompany.app:maven-multi-app@1.0-SNAPSHOT', + 'specifies "from" path for root package'); t.ok(pkg.dependencies['com.mycompany.app:simple-child'], 'specifies dependency'); t.equal(pkg.dependencies['com.mycompany.app:simple-child'].artifactId, 'simple-child', 'specifies dependency artifactId'); + t.equal(pkg.dependencies['com.mycompany.app:simple-child'].from[0], + 'com.mycompany.app:maven-multi-app@1.0-SNAPSHOT', + 'specifies root module as first element of "from" path for dependencies'); }); });