JSONObject projectInfo = new JSONObject();
if (isMavenProject()) {
try {
String pomXml = FileUtils.readToString(new FileSystemResource(new File(getMavenPomFilePath())));
SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
nsContext.bindNamespaceUri("mvn", "http://maven.apache.org/POM/4.0.0");
Document pomDoc = XMLUtils.parseMessagePayload(pomXml);
projectInfo.put("basePackage", XPathUtils.evaluateExpression(pomDoc, "/mvn:project/mvn:groupId", nsContext, XPathConstants.STRING));
projectInfo.put("name", XPathUtils.evaluateExpression(pomDoc, "/mvn:project/mvn:artifactId", nsContext, XPathConstants.STRING));
projectInfo.put("version", XPathUtils.evaluateExpression(pomDoc, "/mvn:project/mvn:properties/mvn:citrus.version", nsContext, XPathConstants.STRING));
projectInfo.put("description", XPathUtils.evaluateExpression(pomDoc, "/mvn:project/mvn:description", nsContext, XPathConstants.STRING));
} catch (IOException e) {
throw new CitrusAdminRuntimeException("Unable to open Maven pom.xml file", e);
}
} else if (isAntProject()) {
try {
String buildXml = FileUtils.readToString(new FileSystemResource(new File(getAntBuildFilePath())));
SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
Document buildDoc = XMLUtils.parseMessagePayload(buildXml);
projectInfo.put("name", XPathUtils.evaluateExpression(buildDoc, "/project/@name", nsContext, XPathConstants.STRING));
projectInfo.put("version", XPathUtils.evaluateExpression(buildDoc, "/project/property[@name='citrus.version']/@value", nsContext, XPathConstants.STRING));
projectInfo.put("description", XPathUtils.evaluateExpression(buildDoc, "/project/@description", nsContext, XPathConstants.STRING));