Skip to content

Commit

Permalink
Merge pull request #4 from nurun/master
Browse files Browse the repository at this point in the history
Fixes error related to reaching maximum string length
  • Loading branch information
cthorne66 authored Sep 16, 2016
2 parents 694c744 + 827ecb7 commit a3a65c3
Showing 1 changed file with 62 additions and 40 deletions.
102 changes: 62 additions & 40 deletions tasks/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ var createAndUploadArtifacts = function (options, done) {
save(createFile('latest-metadata.xml', options), pomDir, 'inner.xml');
save(createFile('pom.xml', options), pomDir, 'pom.xml');

var artifactData = fs.readFileSync(options.artifact, {encoding: 'binary'});
fs.writeFileSync(pomDir + '/artifact.' + options.packaging + '.md5', md5(artifactData));
fs.writeFileSync(pomDir + '/artifact.' + options.packaging + '.sha1', sha1(artifactData));

var upload = function (fileLocation, targetFile) {
var uploadArtifact = function (cb) {
Expand Down Expand Up @@ -114,56 +111,81 @@ var createAndUploadArtifacts = function (options, done) {
return uploadArtifact;
};

var uploads = {};

var groupIdAsPath = options.groupId.replace(/\./g, "/");
var groupArtifactPath = groupIdAsPath + '/' + options.artifactId;
var artifactStream = fs.createReadStream(options.artifact);
var md5Hash = crypto.createHash('md5');
var sha1Hash = crypto.createHash('sha1');

uploads[pomDir + "/outer.xml"] = groupArtifactPath + '/' + 'maven-metadata.xml';
uploads[pomDir + "/outer.xml.sha1"] = groupArtifactPath + '/' + 'maven-metadata.xml.sha1';
uploads[pomDir + "/outer.xml.md5"] = groupArtifactPath + '/' + 'maven-metadata.xml.md5';
artifactStream.on('data', function(chunk) {

var SNAPSHOT_VER = /.*SNAPSHOT$/i;
var binaryChunk = chunk.toString('binary');

var groupArtifactVersionPath = groupArtifactPath + '/' + options.version;
if (SNAPSHOT_VER.test(options.version)) {
uploads[pomDir + "/inner.xml"] = groupArtifactVersionPath + '/' + 'maven-metadata.xml';
uploads[pomDir + "/inner.xml.sha1"] = groupArtifactVersionPath + '/' + 'maven-metadata.xml.sha1';
uploads[pomDir + "/inner.xml.md5"] = groupArtifactVersionPath + '/' + 'maven-metadata.xml.md5';
}
md5Hash.update(binaryChunk);
sha1Hash.update(binaryChunk);
});

var remoteArtifactName = options.artifactId + '-' + options.version;
uploads[pomDir + "/pom.xml"] = groupArtifactVersionPath + '/' + remoteArtifactName + '.pom';
uploads[pomDir + "/pom.xml.sha1"] = groupArtifactVersionPath + '/' + remoteArtifactName + '.pom.sha1';
uploads[pomDir + "/pom.xml.md5"] = groupArtifactVersionPath + '/' + remoteArtifactName + '.pom.md5';
artifactStream.on('error', function(error) {
console.log(chalk.red(error));
done(error);
});

artifactStream.on('end', function() {

if(options.classifier) {
remoteArtifactName = remoteArtifactName + "-" + options.classifier;
}
uploads[options.artifact] = groupArtifactVersionPath + '/' + remoteArtifactName + '.' + options.packaging;
uploads[pomDir + "/artifact." + options.packaging + ".sha1"] = groupArtifactVersionPath + '/' + remoteArtifactName + '.' + options.packaging + '.sha1';
uploads[pomDir + "/artifact." + options.packaging + ".md5"] = groupArtifactVersionPath + '/' + remoteArtifactName + '.' + options.packaging + '.md5';
fs.writeFileSync(pomDir + '/artifact.' + options.packaging + '.md5', md5Hash.digest('hex'));
fs.writeFileSync(pomDir + '/artifact.' + options.packaging + '.sha1', sha1Hash.digest('hex'));

var uploads = {};

var groupIdAsPath = options.groupId.replace(/\./g, "/");
var groupArtifactPath = groupIdAsPath + '/' + options.artifactId;

var fns = [];
for (var u in uploads) {
if (uploads.hasOwnProperty(u)) {
fns.push(upload(u, uploads[u]));
uploads[pomDir + "/outer.xml"] = groupArtifactPath + '/' + 'maven-metadata.xml';
uploads[pomDir + "/outer.xml.sha1"] = groupArtifactPath + '/' + 'maven-metadata.xml.sha1';
uploads[pomDir + "/outer.xml.md5"] = groupArtifactPath + '/' + 'maven-metadata.xml.md5';

var SNAPSHOT_VER = /.*SNAPSHOT$/i;

var groupArtifactVersionPath = groupArtifactPath + '/' + options.version;
if (SNAPSHOT_VER.test(options.version)) {
uploads[pomDir + "/inner.xml"] = groupArtifactVersionPath + '/' + 'maven-metadata.xml';
uploads[pomDir + "/inner.xml.sha1"] = groupArtifactVersionPath + '/' + 'maven-metadata.xml.sha1';
uploads[pomDir + "/inner.xml.md5"] = groupArtifactVersionPath + '/' + 'maven-metadata.xml.md5';
}
}

var asyncFn = options.parallel ? async.parallel : async.series;
asyncFn(fns, function (err) {
if (!options.quiet) {
console.log(chalk.blue('-------------------------------------------\n'));
if (err) {
console.log(chalk.red('Artifact Upload failed\n' + String(err)));
} else {
console.log(chalk.green('Artifacts uploaded successfully'));
var remoteArtifactName = options.artifactId + '-' + options.version;
uploads[pomDir + "/pom.xml"] = groupArtifactVersionPath + '/' + remoteArtifactName + '.pom';
uploads[pomDir + "/pom.xml.sha1"] = groupArtifactVersionPath + '/' + remoteArtifactName + '.pom.sha1';
uploads[pomDir + "/pom.xml.md5"] = groupArtifactVersionPath + '/' + remoteArtifactName + '.pom.md5';


if(options.classifier) {
remoteArtifactName = remoteArtifactName + "-" + options.classifier;
}
uploads[options.artifact] = groupArtifactVersionPath + '/' + remoteArtifactName + '.' + options.packaging;
uploads[pomDir + "/artifact." + options.packaging + ".sha1"] = groupArtifactVersionPath + '/' + remoteArtifactName + '.' + options.packaging + '.sha1';
uploads[pomDir + "/artifact." + options.packaging + ".md5"] = groupArtifactVersionPath + '/' + remoteArtifactName + '.' + options.packaging + '.md5';


var fns = [];
for (var u in uploads) {
if (uploads.hasOwnProperty(u)) {
fns.push(upload(u, uploads[u]));
}
}
done(err);

var asyncFn = options.parallel ? async.parallel : async.series;
asyncFn(fns, function (err) {
if (!options.quiet) {
console.log(chalk.blue('-------------------------------------------\n'));
if (err) {
console.log(chalk.red('Artifact Upload failed\n' + String(err)));
} else {
console.log(chalk.green('Artifacts uploaded successfully'));
}
}
done(err);
});

});

};
Expand Down

0 comments on commit a3a65c3

Please sign in to comment.