Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNAPSHOT from remote repos and added progress bar #31

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ module.exports = function(/*options, callback*/) {
var dependencyQueue = async.queue(processDependency, options.concurrency);
dependencyQueue.drain = complete;

var _cliProgress = require('cli-progress');
var progressBar = new _cliProgress.SingleBar({
format: 'Java Dependencies Loading [{bar}] {percentage}% || {value}/{total}',
barCompleteChar: '\u2588',
barIncompleteChar: '\u2591',
hideCursor: true,
clearOnComplete: false,
stopOnComplete: false
});

return go(callback);

/***************************************************************************************/
Expand All @@ -49,6 +59,7 @@ module.exports = function(/*options, callback*/) {
return callback(err);
}

progressBar.start(packageJson.java.totalDependencies != null ? packageJson.java.totalDependencies : 100, 0);
if (packageJson.java.repositories) {
options.repositories = options.repositories.concat(packageJson.java.repositories);
}
Expand All @@ -69,12 +80,11 @@ module.exports = function(/*options, callback*/) {
}
}



return packageJson.java.dependencies.forEach(function(d) {
dependencyQueuePush(Dependency.createFromObject(d, 'package.json'));
});
});
progressBar.stop();
}

function complete() {
Expand All @@ -99,6 +109,7 @@ module.exports = function(/*options, callback*/) {
dependencyArray = [dependency];
}
dependencyArray.forEach(function(d) {
progressBar.increment()
d.state = 'queued';

if (!d.groupId) {
Expand Down Expand Up @@ -207,7 +218,12 @@ module.exports = function(/*options, callback*/) {
});

function download(dependency, pomPath, callback) {
return downloadFile(dependency.getPomPath(), pomPath, dependency.reason, function(err, url) {
var dependencyPomPath = dependency.pomPath != null ? dependency.pomPath : dependency.getPomPath();
if (dependencyPomPath.endsWith('-SNAPSHOT.pom')) {
dependencyPomPath = dependencyPomPath.substring(0, dependencyPomPath.lastIndexOf('/') + 1) + 'maven-metadata.xml';
pomPath = pomPath.substring(0, pomPath.lastIndexOf(path.sep) + 1) + 'maven-metadata.xml';
}
return downloadFile(dependencyPomPath, pomPath, dependency.reason, function(err, url) {
if (err) {
return callback(err);
}
Expand All @@ -231,6 +247,11 @@ module.exports = function(/*options, callback*/) {
if (err) {
return callback(err);
}
if (dependency.pomPath.endsWith('maven-metadata.xml')) {
var snapshotVersion = xml.metadata.artifactId + '-' + xml.metadata.versioning["0"].snapshotVersions["0"].snapshotVersion["0"].value["0"];
dependency.pomPath = dependency.getPomPath().substring(0, dependency.getPomPath().lastIndexOf('/') + 1) + snapshotVersion + '.pom';
return download(dependency, path.resolve(options.localRepository, dependency.getPomPath()), callback);
}
dependency.pomXml = xml;
if (dependency.getParent()) {
var parentDep = dependency.getParent();
Expand All @@ -255,7 +276,12 @@ module.exports = function(/*options, callback*/) {
dependency.jarPath = jarPath;
return callback();
} else {
return downloadFile(dependency.getJarPath(), jarPath, dependency.reason, function(err, url) {
var dependencyJarPath = dependency.getJarPath();
if (dependency.version.endsWith('-SNAPSHOT')) {
var snapshotVersion = dependency.pomUrl.substring(dependency.pomUrl.lastIndexOf('/') + 1, dependency.pomUrl.lastIndexOf('.'));
dependencyJarPath = dependencyJarPath.substring(0, dependencyJarPath.lastIndexOf('/') + 1) + snapshotVersion + '.jar';
}
return downloadFile(dependencyJarPath, jarPath, dependency.reason, function(err, url) {
if (err) {
return callback(err);
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"async": "^0.9.0",
"mkdirp": "^0.5.0",
"request": "^2.37.0",
"xml2js": "^0.4.4"
"xml2js": "^0.4.4",
"cli-progress": "^3.0.0"
},
"devDependencies": {
"fs-extra": "^0.26.2",
Expand Down