-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmaven.js
43 lines (34 loc) · 1.01 KB
/
maven.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var fs = require('fs');
var cwd = process.cwd();
exports.isMavenProject = fs.existsSync(cwd + '/pom.xml');
if (exports.isMavenProject) {
var xmlParser = require('xml2js').parseString;
var pomXML = fs.readFileSync('pom.xml', "utf-8");
xmlParser(pomXML, function (err, parseResult) {
exports.pom = parseResult;
});
}
exports.getArtifactId = function() {
assertIsMavenProject();
return exports.pom.project.artifactId[0];
};
exports.getPackaging = function() {
assertIsMavenProject();
if (exports.pom.project.packaging) {
return exports.pom.project.packaging[0];
} else {
return 'jar';
}
};
exports.isHPI = function() {
return (exports.isMavenProject && exports.getPackaging() === 'hpi');
};
function assertIsMavenProject(preamble) {
if (!exports.isMavenProject) {
if (preamble) {
throw new Error(preamble + ' - This is not a maven project.');
} else {
throw new Error('This is not a maven project.');
}
}
}