1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
'use strict';
var path = require('path');
export class Dependency {
reason: string;
groupId: string;
artifactId: string;
version: string;
state: string;
pomPath: string;
pomXml: any;
jarPath: string;
complete: boolean;
toString() {
return this.groupId + ':' + this.artifactId + ':' + this.version;
}
getGroupPath() {
return this.groupId.replace(/\./g, '/');
}
getArtifactPath() {
return path.join(this.getGroupPath(), this.artifactId);
}
getVersionPath() {
if (!this.version) {
throw new Error('version not found for ' + this.toString());
}
return path.join(this.getArtifactPath(), this.version);
}
getPomPath() {
return path.join(this.getVersionPath(), this.getPomFileName());
}
getJarPath() {
return path.join(this.getVersionPath(), this.getJarFileName());
}
getJarFileName() {
return this.artifactId + '-' + this.version + '.jar';
}
getPomFileName() {
return this.artifactId + '-' + this.version + '.pom';
}
getPackaging() {
if (!this.pomXml) {
throw new Error('Could not find pomXml for dependency: ' + this.toString());
}
if (this.pomXml.project && this.pomXml.project.packaging) {
return this.pomXml.project.packaging[0];
} else {
return 'jar';
}
}
getParent() {
if (!this.pomXml || !this.pomXml.project) {
throw new Error("Invalid dependency state. Missing pomXml. " + this);
}
if (this.pomXml.project.parent) {
var p = this.pomXml.project.parent[0];
return Dependency.createFromXmlObject(p, this.reason);
}
return null;
}
getDependencies() {
if (
this.pomXml.project
&& this.pomXml.project.dependencies
&& this.pomXml.project.dependencies[0]
&& this.pomXml.project.dependencies[0].dependency) {
var reason = this.reason;
if (reason) {
reason += '/';
}
reason += this.toString();
var dependencies = this.pomXml.project.dependencies[0].dependency;
return dependencies.map(function (d) {
return Dependency.createFromXmlObject(d, reason);
});
}
return [];
}
getDependencyManagementDependencies() {
if (
this.pomXml.project
&& this.pomXml.project.dependencyManagement
&& this.pomXml.project.dependencyManagement[0]
&& this.pomXml.project.dependencyManagement[0].dependencies
&& this.pomXml.project.dependencyManagement[0].dependencies[0]
&& this.pomXml.project.dependencyManagement[0].dependencies[0].dependency) {
var reason = this.reason;
if (reason) {
reason += '/';
}
reason += this.toString();
var dependencies = this.pomXml.project.dependencyManagement[0].dependencies[0].dependency;
return dependencies.map(function (d) {
return Dependency.createFromXmlObject(d, reason);
});
}
return [];
}
markCompleted() {
this.complete = true;
}
// this is a hack to wait for in flight dependencies to complete
waitUntilComplete(callback) {
callback = callback || function () { };
var me = this;
var count = 0;
var wait = setInterval(function () {
if (me.complete) {
clearInterval(wait);
if (!callback) {
return false;
}
var cb = callback;
callback = null;
return cb();
}
count++;
if (count > 100) {
console.log('waiting for ' + me.toString() + ' [state: ' + me.state + ']');
count = 0;
}
return false;
}, 10);
}
static createFromObject(obj, reason) {
var result = new Dependency();
result.reason = reason;
Object.keys(obj).forEach(function(k) {
result[k] = obj[k];
});
return result;
}
static createFromXmlObject(xml, reason) {
return Dependency.createFromObject({
groupId: xml.groupId[0],
artifactId: xml.artifactId[0],
version: xml.version ? xml.version[0] : null,
scope: xml.scope ? xml.scope[0] : 'compile',
optional: xml.optional ? (xml.optional[0] == 'true') : false
}, reason);
}
}
|