Example usage for org.apache.commons.jelly XMLOutput close

List of usage examples for org.apache.commons.jelly XMLOutput close

Introduction

In this page you can find the example usage for org.apache.commons.jelly XMLOutput close.

Prototype

public void close() throws IOException 

Source Link

Document

Provides a useful hook that implementations can use to close the underlying OutputStream or Writer

Usage

From source file:com.viltgroup.xcp.jenkins.maven.XcpMavenSettings.java

public static void generateFile(String workspacePath, String xcpDesignerPath, String localRepositoryPath,
        FilePath generatedFilePath) {/*from w w w.  ja  v  a  2  s  .co m*/
    XMLOutput output = null;
    try {
        // create directories if needed
        generatedFilePath.getParent().mkdirs();

        // prepare output writer
        output = XMLOutput.createXMLOutput(generatedFilePath.write());

        // load jelly template
        String templateLocation = String.format("/%s/template.jelly",
                XcpMavenSettings.class.getName().replace('.', '/'));
        URL templateURL = XcpMavenSettings.class.getResource(templateLocation);

        // generate settings.xml from template
        Jelly jelly = new Jelly();
        jelly.setUrl(templateURL);
        Script script = jelly.compileScript();
        // add xCP Designer path to the jelly context
        JellyContext context = new JellyContext();
        context.setVariable("workspacePath", OSPathHacks.processFilePath(workspacePath));
        context.setVariable("xcpDesignerPath", xcpDesignerPath);
        context.setVariable("xcpDesignerMavenPath",
                String.format("%s/maven", OSPathHacks.processFilePath(xcpDesignerPath)));
        context.setVariable("localRepositoryPath", OSPathHacks.processFilePath(localRepositoryPath));
        script.run(context, output);
        output.flush();
    } catch (IOException e) {
        throw new RuntimeException("Error generating xCP settings.xml file.", e);
    } catch (JellyTagException e) {
        throw new RuntimeException("Error generating xCP settings.xml file.", e);
    } catch (JellyException e) {
        throw new RuntimeException("Error generating xCP settings.xml file.", e);
    } catch (InterruptedException e) {
        throw new RuntimeException("Error generating xCP settings.xml file.", e);
    } finally {
        if (output != null)
            try {
                output.close();
            } catch (IOException e) {
            }
    }
}