Skip to content

Instantly share code, notes, and snippets.

@daicham daicham/mkmvndeps.js
Last active Dec 2, 2015

Embed
What would you like to do?
A script for searching artifact information from jar file list that created by fciv ( maven.org, bintray)
var http = require('http');
var fs = require('fs');
var js2xmlparser = require('js2xmlparser');
var search_url = 'http://search.maven.org/solrsearch/select?rows=20&wt=json&q=1:';
// コマンドライン引数チェック
if (process.argv.length != 3) {
log("Usage `node mkmvn path/to/jar_list`");
log("jar_list is required fciv output format");
return -1;
}
var jar_list_path = process.argv[2];
// ファイル読み込み
fs.readFile(jar_list_path, function(err, data) {
if (err) { log(err); throw err; }
var artifacts = parseData(data);
artifacts.forEach(function(artifact) {
var url = search_url + artifact.sha1;
log("Searching... " + url);
http.get(url, function(res) {
res.setEncoding('UTF-8');
var body = '';
res.on('data', function(chunk) {
body += chunk;
});
res.on('end', function() {
var ret = JSON.parse(body);
if (ret.response.numFound > 0) {
log(artifact.name + " is found " + ret.response.numFound + " artifact(s).");
var dep = parseResponse(ret.response.docs[0]);
out(dep);
} else {
log(artifact.name + " is not found.");
}
});
}).on('error', function(e) {
log(e);
});
});
});
function parseData(data) {
return data.toString()
.split('\n')
.filter(function(line) {
return line.length > 0 && line.indexOf('//') == -1; //空行,コメント無視
})
.map(function(line) {
var pair = line.split(" ");
return { "name": pair[1], "sha1": pair[0] };
});
}
function parseResponse(json) {
var options = {
'declaration': {
'include': false
}
};
var data = {
"groupId": json.g,
"artifactId": json.a,
"version": json.v
};
return js2xmlparser("dependency", data, options);
}
function log(log) {
console.error(log);
}
function out(out) {
console.log(out);
}
var http = require('https');
var fs = require('fs');
var js2xmlparser = require('js2xmlparser');
var search_url = 'https://api.bintray.com/search/file?sha1='
// コマンドライン引数チェック
if (process.argv.length != 3) {
log("Usage `node mkmvn path/to/jar_list`");
log("jar_list is required fciv output format");
return -1;
}
var jar_list_path = process.argv[2];
// ファイル読み込み
fs.readFile(jar_list_path, function(err, data) {
if (err) { log(err); throw err; }
var artifacts = parseData(data);
artifacts.forEach(function(artifact) {
var url = search_url + artifact.sha1;
log("Searching... " + url);
http.get(url, function(res) {
res.setEncoding('UTF-8');
var body = '';
res.on('data', function(chunk) {
body += chunk;
});
res.on('end', function() {
var ret = JSON.parse(body);
if (ret.length> 0) {
log(artifact.name + " is found " + ret.length + " artifact(s).");
var dep = parseResponse(ret[0]);
out(dep);
} else {
log(artifact.name + " is not found.");
}
});
}).on('error', function(e) {
log(e);
});
});
});
function parseData(data) {
return data.toString()
.split('\n')
.filter(function(line) {
return line.length > 0 && line.indexOf('//') == -1; //空行,コメント無視
})
.map(function(line) {
var pair = line.split(" ");
return { "name": pair[1], "sha1": pair[0] };
});
}
function parseResponse(json) {
var options = {
'declaration': {
'include': false
}
};
var data = {
"groupId": json.package.split(":")[0],
"artifactId": json.package.split(":")[1],
"version": json.version
};
return js2xmlparser("dependency", data, options);
}
function log(log) {
console.error(log);
}
function out(out) {
console.log(out);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.