Skip to content

Commit

Permalink
Import dependencies from pom file
Browse files Browse the repository at this point in the history
  • Loading branch information
Yu Zeng authored and zengyu714 committed Dec 30, 2021
1 parent 710ea2e commit d449ebc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 74 deletions.
88 changes: 15 additions & 73 deletions bin/kcl-bootstrap
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -14,74 +14,16 @@ var https = require('https');
var path = require('path');
var program = require('commander');
var spawn = require('child_process').spawn;
var convert = require('xml-js');
var url = require('url');
var util = require('util');

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

var MAVEN_PACKAGE_LIST = [
getMavenPackageInfo('software.amazon.kinesis', 'amazon-kinesis-client-multilang', '2.1.2'),
getMavenPackageInfo('software.amazon.kinesis', 'amazon-kinesis-client', '2.1.2'),
getMavenPackageInfo('software.amazon.awssdk', 'kinesis', '2.4.0'),
getMavenPackageInfo('software.amazon.awssdk', 'aws-cbor-protocol', '2.4.0'),
getMavenPackageInfo('com.fasterxml.jackson.dataformat', 'jackson-dataformat-cbor', '2.9.8'),
getMavenPackageInfo('software.amazon.awssdk', 'aws-json-protocol', '2.4.0'),
getMavenPackageInfo('software.amazon.awssdk', 'dynamodb', '2.4.0'),
getMavenPackageInfo('software.amazon.awssdk', 'cloudwatch', '2.4.0'),
getMavenPackageInfo('software.amazon.awssdk', 'netty-nio-client', '2.4.0'),
getMavenPackageInfo('io.netty', 'netty-codec-http', '4.1.32.Final'),
getMavenPackageInfo('io.netty', 'netty-codec-http2', '4.1.32.Final'),
getMavenPackageInfo('io.netty', 'netty-codec', '4.1.32.Final'),
getMavenPackageInfo('io.netty', 'netty-transport', '4.1.32.Final'),
getMavenPackageInfo('io.netty', 'netty-resolver', '4.1.32.Final'),
getMavenPackageInfo('io.netty', 'netty-common', '4.1.32.Final'),
getMavenPackageInfo('io.netty', 'netty-buffer', '4.1.32.Final'),
getMavenPackageInfo('io.netty', 'netty-handler', '4.1.32.Final'),
getMavenPackageInfo('io.netty', 'netty-transport-native-epoll', '4.1.32.Final'),
getMavenPackageInfo('io.netty', 'netty-transport-native-unix-common', '4.1.32.Final'),
getMavenPackageInfo('com.typesafe.netty', 'netty-reactive-streams-http', '2.0.0'),
getMavenPackageInfo('com.typesafe.netty', 'netty-reactive-streams', '2.0.0'),
getMavenPackageInfo('org.reactivestreams', 'reactive-streams', '1.0.2'),
getMavenPackageInfo('com.google.guava', 'guava', '26.0-jre'),
getMavenPackageInfo('com.google.code.findbugs', 'jsr305', '3.0.2'),
getMavenPackageInfo('org.checkerframework', 'checker-qual', '2.5.2'),
getMavenPackageInfo('com.google.errorprone', 'error_prone_annotations', '2.1.3'),
getMavenPackageInfo('com.google.j2objc', 'j2objc-annotations', '1.1'),
getMavenPackageInfo('org.codehaus.mojo', 'animal-sniffer-annotations', '1.14'),
getMavenPackageInfo('com.google.protobuf', 'protobuf-java', '2.6.1'),
getMavenPackageInfo('org.apache.commons', 'commons-lang3', '3.8.1'),
getMavenPackageInfo('org.slf4j', 'slf4j-api', '1.7.25'),
getMavenPackageInfo('io.reactivex.rxjava2', 'rxjava', '2.1.14'),
getMavenPackageInfo('software.amazon.awssdk', 'sts', '2.4.0'),
getMavenPackageInfo('software.amazon.awssdk', 'aws-query-protocol', '2.4.0'),
getMavenPackageInfo('software.amazon.awssdk', 'protocol-core', '2.4.0'),
getMavenPackageInfo('software.amazon.awssdk', 'profiles', '2.4.0'),
getMavenPackageInfo('software.amazon.awssdk', 'sdk-core', '2.4.0'),
getMavenPackageInfo('com.fasterxml.jackson.core', 'jackson-core', '2.9.8'),
getMavenPackageInfo('com.fasterxml.jackson.core', 'jackson-databind', '2.9.8'),
getMavenPackageInfo('software.amazon.awssdk', 'auth', '2.4.0'),
getMavenPackageInfo('software.amazon', 'flow', '1.7'),
getMavenPackageInfo('software.amazon.awssdk', 'http-client-spi', '2.4.0'),
getMavenPackageInfo('software.amazon.awssdk', 'regions', '2.4.0'),
getMavenPackageInfo('com.fasterxml.jackson.core', 'jackson-annotations', '2.9.0'),
getMavenPackageInfo('software.amazon.awssdk', 'annotations', '2.4.0'),
getMavenPackageInfo('software.amazon.awssdk', 'utils', '2.4.0'),
getMavenPackageInfo('software.amazon.awssdk', 'aws-core', '2.4.0'),
getMavenPackageInfo('software.amazon.awssdk', 'apache-client', '2.4.0'),
getMavenPackageInfo('org.apache.httpcomponents', 'httpclient', '4.5.6'),
getMavenPackageInfo('commons-codec', 'commons-codec', '1.10'),
getMavenPackageInfo('org.apache.httpcomponents', 'httpcore', '4.4.10'),
getMavenPackageInfo('com.amazonaws', 'aws-java-sdk-core', '1.11.477'),
getMavenPackageInfo('commons-logging', 'commons-logging', '1.1.3'),
getMavenPackageInfo('software.amazon.ion', 'ion-java', '1.0.2'),
getMavenPackageInfo('joda-time', 'joda-time', '2.8.1'),
getMavenPackageInfo('ch.qos.logback', 'logback-classic', '1.2.3'),
getMavenPackageInfo('ch.qos.logback', 'logback-core', '1.2.3'),
getMavenPackageInfo('com.beust', 'jcommander', '1.72'),
getMavenPackageInfo('commons-io', 'commons-io', '2.6'),
getMavenPackageInfo('org.apache.commons', 'commons-collections4', '4.2'),
getMavenPackageInfo('commons-beanutils', 'commons-beanutils', '1.9.3'),
getMavenPackageInfo('commons-collections', 'commons-collections', '3.2.2')
];
// Read Java dependencies from pom.xml
const MAVEN_PACKAGE_LIST = dependencyArray.map(dep => getMavenPackageInfo(dep.groupId._text, dep.artifactId._text, dep.version._text));

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

function bootstrap() {
var args = parseArguments();
downloadMavenPackages(MAVEN_PACKAGE_LIST, args.jarPath, function(err) {
downloadMavenPackages(MAVEN_PACKAGE_LIST, args.jarPath, function (err) {
if (err) {
errorExit(util.format('Unable to download MultiLangDaemon jar files from maven: %s', err));
}
Expand All @@ -113,7 +55,7 @@ function parseArguments() {

var args = {
'properties': program.properties,
'logConfiguration': program.logConfiguration ? program.logConfiguration: null,
'logConfiguration': program.logConfiguration ? program.logConfiguration : null,
'java': (program.java ? program.java : (process.env.JAVA_HOME ? createJavaHomeExecutablePath() : null)),
'jarPath': (program.jarPath ? program.jarPath : DEFAULT_JAR_PATH),
'execute': program.execute
Expand Down Expand Up @@ -174,7 +116,7 @@ function downloadMavenPackages(mavenPackages, destinationDirectory, callback) {
var remainingPackages = mavenPackages.length;
var callbackInvoked = false;

var downloadMavenPackageCallback = function(err, filePath) {
var downloadMavenPackageCallback = function (err, filePath) {
remainingPackages = remainingPackages - 1;
if (!callbackInvoked) {
if (!err) {
Expand All @@ -188,13 +130,13 @@ function downloadMavenPackages(mavenPackages, destinationDirectory, callback) {
}
};

for (var i = 0 ; i < mavenPackages.length ; ++i) {
for (var i = 0; i < mavenPackages.length; ++i) {
downloadMavenPackage(mavenPackages[i], destinationDirectory, downloadMavenPackageCallback);
}
}

function downloadMavenPackage(mavenPackage, destinationDirectory, callback) {
process.nextTick(function() {
process.nextTick(function () {
var mavenPackageUrlInfo = getMavenPackageUrlInfo(mavenPackage);
var destinationFile = path.join(destinationDirectory, mavenPackageUrlInfo.fileName);
if (fs.existsSync(destinationFile)) {
Expand All @@ -216,7 +158,7 @@ function httpDownloadFile(requestUrl, destinationFile, redirectCount, callback)
path: url.parse(requestUrl).path,
agent: false
};
var request = protocol.get(options, function(response) {
var request = protocol.get(options, function (response) {
// Non-2XX response.
if (response.statusCode > 300) {
if (response.statusCode > 300 && response.statusCode < 400 && response.headers.location) {
Expand All @@ -233,7 +175,7 @@ function httpDownloadFile(requestUrl, destinationFile, redirectCount, callback)
response.pipe(destinationFileStream);

var callbackInvoked = false;
var destinationFileStreamFinishCallback = function() {
var destinationFileStreamFinishCallback = function () {
if (callbackInvoked) {
return;
}
Expand All @@ -244,7 +186,7 @@ function httpDownloadFile(requestUrl, destinationFile, redirectCount, callback)
// Older Node.js version may not support 'finish' event.
destinationFileStream.on('close', destinationFileStreamFinishCallback);
}
}).on('error', function(err) {
}).on('error', function (err) {
fs.unlink(destinationFile);
callback(err);
});
Expand Down Expand Up @@ -285,7 +227,7 @@ function isDirectory(path) {
function createDirectory(path) {
try {
fs.mkdirSync(path);
} catch(e) {
} catch (e) {
if (e.code !== 'EEXIST') {
throw e;
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"doc": "grunt jsdoc"
},
"dependencies": {
"commander": "~2.6.0"
"commander": "~2.6.0",
"xml-js": "^1.6.11"
},
"devDependencies": {
"async": "^0.9.2",
Expand Down

0 comments on commit d449ebc

Please sign in to comment.