Search in sources :

Example 16 with ResolutionCacheManager

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
            }
        }
    }
}
Also used : TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ResolutionCacheManager(org.apache.ivy.core.cache.ResolutionCacheManager) StreamSource(javax.xml.transform.stream.StreamSource) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) XSLTProcess(org.apache.tools.ant.taskdefs.XSLTProcess) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) BufferedInputStream(java.io.BufferedInputStream) FileOutputStream(java.io.FileOutputStream) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) TransformerException(javax.xml.transform.TransformerException)

Aggregations

File (java.io.File)16 ResolutionCacheManager (org.apache.ivy.core.cache.ResolutionCacheManager)16 XmlReportParser (org.apache.ivy.plugins.report.XmlReportParser)8 HashSet (java.util.HashSet)6 LinkedHashSet (java.util.LinkedHashSet)6 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)6 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)5 BuildException (org.apache.tools.ant.BuildException)5 IOException (java.io.IOException)4 FileOutputStream (java.io.FileOutputStream)3 URL (java.net.URL)3 ResolveReport (org.apache.ivy.core.report.ResolveReport)3 XmlReportOutputter (org.apache.ivy.plugins.report.XmlReportOutputter)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MalformedURLException (java.net.MalformedURLException)2 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Artifact (org.apache.ivy.core.module.descriptor.Artifact)2 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)2