Skip to content

Commit d449ebc

Browse files
Yu Zengzengyu714
authored andcommitted
Import dependencies from pom file
1 parent 710ea2e commit d449ebc

File tree

2 files changed

+17
-74
lines changed

2 files changed

+17
-74
lines changed

bin/kcl-bootstrap

100755100644
Lines changed: 15 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -14,74 +14,16 @@ var https = require('https');
1414
var path = require('path');
1515
var program = require('commander');
1616
var spawn = require('child_process').spawn;
17+
var convert = require('xml-js');
1718
var url = require('url');
1819
var util = require('util');
1920

21+
const mavenFile = fs.readFileSync(path.join(__dirname, '..', 'pom.xml'), 'utf8');
22+
const mavenJson = JSON.parse(convert.xml2json(mavenFile, { compact: true }));
23+
const dependencyArray = mavenJson.project.dependencies.dependency
2024

21-
var MAVEN_PACKAGE_LIST = [
22-
getMavenPackageInfo('software.amazon.kinesis', 'amazon-kinesis-client-multilang', '2.1.2'),
23-
getMavenPackageInfo('software.amazon.kinesis', 'amazon-kinesis-client', '2.1.2'),
24-
getMavenPackageInfo('software.amazon.awssdk', 'kinesis', '2.4.0'),
25-
getMavenPackageInfo('software.amazon.awssdk', 'aws-cbor-protocol', '2.4.0'),
26-
getMavenPackageInfo('com.fasterxml.jackson.dataformat', 'jackson-dataformat-cbor', '2.9.8'),
27-
getMavenPackageInfo('software.amazon.awssdk', 'aws-json-protocol', '2.4.0'),
28-
getMavenPackageInfo('software.amazon.awssdk', 'dynamodb', '2.4.0'),
29-
getMavenPackageInfo('software.amazon.awssdk', 'cloudwatch', '2.4.0'),
30-
getMavenPackageInfo('software.amazon.awssdk', 'netty-nio-client', '2.4.0'),
31-
getMavenPackageInfo('io.netty', 'netty-codec-http', '4.1.32.Final'),
32-
getMavenPackageInfo('io.netty', 'netty-codec-http2', '4.1.32.Final'),
33-
getMavenPackageInfo('io.netty', 'netty-codec', '4.1.32.Final'),
34-
getMavenPackageInfo('io.netty', 'netty-transport', '4.1.32.Final'),
35-
getMavenPackageInfo('io.netty', 'netty-resolver', '4.1.32.Final'),
36-
getMavenPackageInfo('io.netty', 'netty-common', '4.1.32.Final'),
37-
getMavenPackageInfo('io.netty', 'netty-buffer', '4.1.32.Final'),
38-
getMavenPackageInfo('io.netty', 'netty-handler', '4.1.32.Final'),
39-
getMavenPackageInfo('io.netty', 'netty-transport-native-epoll', '4.1.32.Final'),
40-
getMavenPackageInfo('io.netty', 'netty-transport-native-unix-common', '4.1.32.Final'),
41-
getMavenPackageInfo('com.typesafe.netty', 'netty-reactive-streams-http', '2.0.0'),
42-
getMavenPackageInfo('com.typesafe.netty', 'netty-reactive-streams', '2.0.0'),
43-
getMavenPackageInfo('org.reactivestreams', 'reactive-streams', '1.0.2'),
44-
getMavenPackageInfo('com.google.guava', 'guava', '26.0-jre'),
45-
getMavenPackageInfo('com.google.code.findbugs', 'jsr305', '3.0.2'),
46-
getMavenPackageInfo('org.checkerframework', 'checker-qual', '2.5.2'),
47-
getMavenPackageInfo('com.google.errorprone', 'error_prone_annotations', '2.1.3'),
48-
getMavenPackageInfo('com.google.j2objc', 'j2objc-annotations', '1.1'),
49-
getMavenPackageInfo('org.codehaus.mojo', 'animal-sniffer-annotations', '1.14'),
50-
getMavenPackageInfo('com.google.protobuf', 'protobuf-java', '2.6.1'),
51-
getMavenPackageInfo('org.apache.commons', 'commons-lang3', '3.8.1'),
52-
getMavenPackageInfo('org.slf4j', 'slf4j-api', '1.7.25'),
53-
getMavenPackageInfo('io.reactivex.rxjava2', 'rxjava', '2.1.14'),
54-
getMavenPackageInfo('software.amazon.awssdk', 'sts', '2.4.0'),
55-
getMavenPackageInfo('software.amazon.awssdk', 'aws-query-protocol', '2.4.0'),
56-
getMavenPackageInfo('software.amazon.awssdk', 'protocol-core', '2.4.0'),
57-
getMavenPackageInfo('software.amazon.awssdk', 'profiles', '2.4.0'),
58-
getMavenPackageInfo('software.amazon.awssdk', 'sdk-core', '2.4.0'),
59-
getMavenPackageInfo('com.fasterxml.jackson.core', 'jackson-core', '2.9.8'),
60-
getMavenPackageInfo('com.fasterxml.jackson.core', 'jackson-databind', '2.9.8'),
61-
getMavenPackageInfo('software.amazon.awssdk', 'auth', '2.4.0'),
62-
getMavenPackageInfo('software.amazon', 'flow', '1.7'),
63-
getMavenPackageInfo('software.amazon.awssdk', 'http-client-spi', '2.4.0'),
64-
getMavenPackageInfo('software.amazon.awssdk', 'regions', '2.4.0'),
65-
getMavenPackageInfo('com.fasterxml.jackson.core', 'jackson-annotations', '2.9.0'),
66-
getMavenPackageInfo('software.amazon.awssdk', 'annotations', '2.4.0'),
67-
getMavenPackageInfo('software.amazon.awssdk', 'utils', '2.4.0'),
68-
getMavenPackageInfo('software.amazon.awssdk', 'aws-core', '2.4.0'),
69-
getMavenPackageInfo('software.amazon.awssdk', 'apache-client', '2.4.0'),
70-
getMavenPackageInfo('org.apache.httpcomponents', 'httpclient', '4.5.6'),
71-
getMavenPackageInfo('commons-codec', 'commons-codec', '1.10'),
72-
getMavenPackageInfo('org.apache.httpcomponents', 'httpcore', '4.4.10'),
73-
getMavenPackageInfo('com.amazonaws', 'aws-java-sdk-core', '1.11.477'),
74-
getMavenPackageInfo('commons-logging', 'commons-logging', '1.1.3'),
75-
getMavenPackageInfo('software.amazon.ion', 'ion-java', '1.0.2'),
76-
getMavenPackageInfo('joda-time', 'joda-time', '2.8.1'),
77-
getMavenPackageInfo('ch.qos.logback', 'logback-classic', '1.2.3'),
78-
getMavenPackageInfo('ch.qos.logback', 'logback-core', '1.2.3'),
79-
getMavenPackageInfo('com.beust', 'jcommander', '1.72'),
80-
getMavenPackageInfo('commons-io', 'commons-io', '2.6'),
81-
getMavenPackageInfo('org.apache.commons', 'commons-collections4', '4.2'),
82-
getMavenPackageInfo('commons-beanutils', 'commons-beanutils', '1.9.3'),
83-
getMavenPackageInfo('commons-collections', 'commons-collections', '3.2.2')
84-
];
25+
// Read Java dependencies from pom.xml
26+
const MAVEN_PACKAGE_LIST = dependencyArray.map(dep => getMavenPackageInfo(dep.groupId._text, dep.artifactId._text, dep.version._text));
8527

8628
var DEFAULT_JAR_PATH = path.resolve(path.join(__dirname, '..', 'lib', 'jars'));
8729
var MULTI_LANG_DAEMON_CLASS = 'software.amazon.kinesis.multilang.MultiLangDaemon';
@@ -90,7 +32,7 @@ var MAX_HTTP_REDIRECT_FOLLOW = 3;
9032

9133
function bootstrap() {
9234
var args = parseArguments();
93-
downloadMavenPackages(MAVEN_PACKAGE_LIST, args.jarPath, function(err) {
35+
downloadMavenPackages(MAVEN_PACKAGE_LIST, args.jarPath, function (err) {
9436
if (err) {
9537
errorExit(util.format('Unable to download MultiLangDaemon jar files from maven: %s', err));
9638
}
@@ -113,7 +55,7 @@ function parseArguments() {
11355

11456
var args = {
11557
'properties': program.properties,
116-
'logConfiguration': program.logConfiguration ? program.logConfiguration: null,
58+
'logConfiguration': program.logConfiguration ? program.logConfiguration : null,
11759
'java': (program.java ? program.java : (process.env.JAVA_HOME ? createJavaHomeExecutablePath() : null)),
11860
'jarPath': (program.jarPath ? program.jarPath : DEFAULT_JAR_PATH),
11961
'execute': program.execute
@@ -174,7 +116,7 @@ function downloadMavenPackages(mavenPackages, destinationDirectory, callback) {
174116
var remainingPackages = mavenPackages.length;
175117
var callbackInvoked = false;
176118

177-
var downloadMavenPackageCallback = function(err, filePath) {
119+
var downloadMavenPackageCallback = function (err, filePath) {
178120
remainingPackages = remainingPackages - 1;
179121
if (!callbackInvoked) {
180122
if (!err) {
@@ -188,13 +130,13 @@ function downloadMavenPackages(mavenPackages, destinationDirectory, callback) {
188130
}
189131
};
190132

191-
for (var i = 0 ; i < mavenPackages.length ; ++i) {
133+
for (var i = 0; i < mavenPackages.length; ++i) {
192134
downloadMavenPackage(mavenPackages[i], destinationDirectory, downloadMavenPackageCallback);
193135
}
194136
}
195137

196138
function downloadMavenPackage(mavenPackage, destinationDirectory, callback) {
197-
process.nextTick(function() {
139+
process.nextTick(function () {
198140
var mavenPackageUrlInfo = getMavenPackageUrlInfo(mavenPackage);
199141
var destinationFile = path.join(destinationDirectory, mavenPackageUrlInfo.fileName);
200142
if (fs.existsSync(destinationFile)) {
@@ -216,7 +158,7 @@ function httpDownloadFile(requestUrl, destinationFile, redirectCount, callback)
216158
path: url.parse(requestUrl).path,
217159
agent: false
218160
};
219-
var request = protocol.get(options, function(response) {
161+
var request = protocol.get(options, function (response) {
220162
// Non-2XX response.
221163
if (response.statusCode > 300) {
222164
if (response.statusCode > 300 && response.statusCode < 400 && response.headers.location) {
@@ -233,7 +175,7 @@ function httpDownloadFile(requestUrl, destinationFile, redirectCount, callback)
233175
response.pipe(destinationFileStream);
234176

235177
var callbackInvoked = false;
236-
var destinationFileStreamFinishCallback = function() {
178+
var destinationFileStreamFinishCallback = function () {
237179
if (callbackInvoked) {
238180
return;
239181
}
@@ -244,7 +186,7 @@ function httpDownloadFile(requestUrl, destinationFile, redirectCount, callback)
244186
// Older Node.js version may not support 'finish' event.
245187
destinationFileStream.on('close', destinationFileStreamFinishCallback);
246188
}
247-
}).on('error', function(err) {
189+
}).on('error', function (err) {
248190
fs.unlink(destinationFile);
249191
callback(err);
250192
});
@@ -285,7 +227,7 @@ function isDirectory(path) {
285227
function createDirectory(path) {
286228
try {
287229
fs.mkdirSync(path);
288-
} catch(e) {
230+
} catch (e) {
289231
if (e.code !== 'EEXIST') {
290232
throw e;
291233
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"doc": "grunt jsdoc"
2424
},
2525
"dependencies": {
26-
"commander": "~2.6.0"
26+
"commander": "~2.6.0",
27+
"xml-js": "^1.6.11"
2728
},
2829
"devDependencies": {
2930
"async": "^0.9.2",

0 commit comments

Comments
 (0)