Example usage for org.apache.maven.model.building ModelSource getInputStream

List of usage examples for org.apache.maven.model.building ModelSource getInputStream

Introduction

In this page you can find the example usage for org.apache.maven.model.building ModelSource getInputStream.

Prototype

InputStream getInputStream() throws IOException;

Source Link

Document

Gets a byte stream to the source contents.

Usage

From source file:org.sonatype.maven.polyglot.TeslaModelProcessor.java

License:Open Source License

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Model read(final Reader input, final Map<String, ?> options) throws IOException, ModelParseException {
    assert manager != null;
    ModelSource source = (ModelSource) options.get(ModelProcessor.SOURCE);
    if (("" + source).contains(".polyglot.")) {
        log.debug(source.getLocation());

        File pom = new File(source.getLocation());
        source = new FileModelSource(new File(pom.getPath().replaceFirst("[.]polyglot[.]", "")));

        ((Map) options).put(ModelProcessor.SOURCE, source);

        ModelReader reader = manager.getReaderFor(options);
        Model model = reader.read(source.getInputStream(), options);

        MavenXpp3Writer xmlWriter = new MavenXpp3Writer();
        StringWriter xml = new StringWriter();
        xmlWriter.write(xml, model);// w w  w  .  j a v  a2s  .  co  m

        FileUtils.fileWrite(pom, xml.toString());

        // dump pom if filename is given via the pom properties
        String dump = model.getProperties().getProperty("polyglot.dump.pom");
        if (dump == null) {
            // just nice to dump the pom.xml via commandline switch
            dump = System.getProperty("polyglot.dump.pom");
        }
        if (dump != null) {
            File dumpPom = new File(pom.getParentFile(), dump);
            if (!dumpPom.exists() || !FileUtils.fileRead(dumpPom).equals(xml.toString())) {
                dumpPom.setWritable(true);
                FileUtils.fileWrite(dumpPom, xml.toString());
                if ("true".equals(model.getProperties().getProperty("polyglot.dump.readonly"))) {
                    dumpPom.setReadOnly();
                }
            }
        }

        model.setPomFile(pom);
        return model;
    } else {
        ModelReader reader = manager.getReaderFor(options);
        return reader.read(input, options);
    }
}