use of org.apache.ivy.core.cache.ResolutionCacheManager in project ant-ivy by apache.
the class IvyReport method genStyled.
private void genStyled(String[] confs, File style, String ext) throws IOException {
ResolutionCacheManager cacheMgr = getIvyInstance().getResolutionCacheManager();
// process the report with xslt to generate dot file
File out;
if (todir != null) {
out = todir;
} else {
out = getProject().getBaseDir();
}
InputStream xsltStream = null;
try {
// create stream to stylesheet
xsltStream = new BufferedInputStream(new FileInputStream(style));
Source xsltSource = new StreamSource(xsltStream, JAXPUtils.getSystemId(style));
// create transformer
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(xsltSource);
// add standard parameters
transformer.setParameter("confs", conf);
transformer.setParameter("extension", xslext);
// add the provided XSLT parameters
for (XSLTProcess.Param param : params) {
transformer.setParameter(param.getName(), param.getExpression());
}
// create the report
for (String config : confs) {
File reportFile = cacheMgr.getConfigurationResolveReportInCache(resolveId, config);
File outFile = new File(out, getOutputPattern(config, ext));
log("Processing " + reportFile + " to " + outFile);
// make sure the output directory exist
File outFileDir = outFile.getParentFile();
if (!outFileDir.exists()) {
if (!outFileDir.mkdirs()) {
throw new BuildException("Unable to create directory: " + outFileDir.getAbsolutePath());
}
}
InputStream inStream = null;
OutputStream outStream = null;
try {
inStream = new BufferedInputStream(new FileInputStream(reportFile));
outStream = new BufferedOutputStream(new FileOutputStream(outFile));
StreamResult res = new StreamResult(outStream);
Source src = new StreamSource(inStream, JAXPUtils.getSystemId(style));
transformer.transform(src, res);
} catch (TransformerException e) {
throw new BuildException(e);
} finally {
if (inStream != null) {
try {
inStream.close();
} catch (IOException e) {
// ignore
}
}
if (outStream != null) {
try {
outStream.close();
} catch (IOException e) {
// ignore
}
}
}
}
} catch (TransformerConfigurationException e) {
throw new BuildException(e);
} finally {
if (xsltStream != null) {
try {
xsltStream.close();
} catch (IOException e) {
// ignore
}
}
}
}
Aggregations