Skip to content

Commit

Permalink
fix: adding the 'from' array to dependencies in maven (#157)
Browse files Browse the repository at this point in the history
* fix: adding the 'from' array to dependencies in maven

* fix: ensure root module is in 'from' array for multi-module dependencies
  • Loading branch information
deebugger authored and darscan committed Jan 9, 2017
1 parent dbcdc94 commit de1ad50
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
18 changes: 11 additions & 7 deletions lib/module-info/maven/mvn-tree-parse.js
Expand Up @@ -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 = {};
Expand All @@ -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(' '));
Expand All @@ -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];
}
Expand Down
22 changes: 19 additions & 3 deletions test/acceptance/cli.acceptance.test.js
Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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');
});
});

Expand Down

0 comments on commit de1ad50

Please sign in to comment.