Example usage for org.apache.maven.model.io ModelWriter write

List of usage examples for org.apache.maven.model.io ModelWriter write

Introduction

In this page you can find the example usage for org.apache.maven.model.io ModelWriter write.

Prototype

void write(OutputStream output, Map<String, Object> options, Model model) throws IOException;

Source Link

Document

Writes the supplied model to the specified byte stream.

Usage

From source file:org.ModelBuilderDemo.java

License:Open Source License

public static void main(String[] args) throws Exception {
    /*/*from w  ww.ja  va2  s  . c o m*/
     * setup the container and get us some interesting components
     */

    PlexusContainer container = new DefaultPlexusContainer();

    ModelBuilder modelBuilder = container.lookup(ModelBuilder.class);

    ModelWriter modelWriter = container.lookup(ModelWriter.class);

    /*
     * build some effective model
     */

    ModelSource modelSource = new UrlModelSource(
            ModelBuilderDemo.class.getResource("/repo/demo/dependency/1.0/pom.xml"));

    ModelBuildingRequest request = new DefaultModelBuildingRequest();

    request.setModelSource(modelSource);
    request.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
    request.setSystemProperties(System.getProperties());
    request.setModelResolver(new SimpleModelResolver());

    ModelBuildingResult result = modelBuilder.build(request);

    Model effectivePom = result.getEffectiveModel();

    StringWriter writer = new StringWriter();
    modelWriter.write(writer, null, effectivePom);
    System.out.println(writer.toString());
}

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

License:Apache License

public void translate(final File input, final Map<String, ?> inputOptions, final File output,
        final Map<String, ?> outputOptions) throws IOException, ModelParseException {
    assert input != null;
    assert output != null;

    ModelReader reader = manager.getReaderFor(inputOptions);
    Model model = reader.read(input, inputOptions);

    ModelWriter writer = manager.getWriterFor(outputOptions);
    writer.write(output, (Map<String, Object>) outputOptions, model);
}

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

License:Apache License

public void translate(final InputStream input, final Map<String, ?> inputOptions, final OutputStream output,
        final Map<String, ?> outputOptions) throws IOException, ModelParseException {
    assert input != null;
    assert output != null;

    ModelReader reader = manager.getReaderFor(inputOptions);
    Model model = reader.read(input, inputOptions);

    ModelWriter writer = manager.getWriterFor(outputOptions);
    writer.write(output, (Map<String, Object>) outputOptions, model);
}

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

License:Apache License

public void translate(final Reader input, final Map<String, ?> inputOptions, final Writer output,
        final Map<String, ?> outputOptions) throws IOException, ModelParseException {
    assert input != null;
    assert output != null;

    ModelReader reader = manager.getReaderFor(inputOptions);
    Model model = reader.read(input, inputOptions);

    ModelWriter writer = manager.getWriterFor(outputOptions);
    writer.write(output, (Map<String, Object>) outputOptions, model);
}

From source file:org.sonatype.maven.polyglot.ruby.AbstractInjectedTestCase.java

License:Open Source License

protected void assertRoundtrip(String pomName, boolean debug) throws Exception {
    File pom = new File(poms, pomName);
    MavenXpp3Reader xmlModelReader = new MavenXpp3Reader();
    Model xmlModel = xmlModelReader.read(new FileInputStream(pom));

    ////from w w w. j a  v a 2  s .c  o  m
    // Write out the Ruby POM
    //
    ModelWriter writer = new RubyModelWriter();
    StringWriter w = new StringWriter();
    writer.write(w, new HashMap<String, Object>(), xmlModel);

    if (debug) {
        // Let's take a look at see what's there
        System.out.println(w.toString());
    }

    //
    // Read in the Ruby POM
    //
    RubyModelReader rubyModelReader = new RubyModelReader();
    final PolyglotModelManager modelManager = new PolyglotModelManager() {
        {
            mappings = new ArrayList<Mapping>();
        }
    };
    modelManager.addMapping(new RubyMapping());
    rubyModelReader.executeManager = new ExecuteManagerImpl() {
        {
            log = new ConsoleLogger(Logger.LEVEL_INFO, "test");
            manager = modelManager;
        }
    };
    rubyModelReader.setupManager = new SetupClassRealm();

    StringReader reader = new StringReader(w.toString());
    Model rubyModel = rubyModelReader.read(reader, new HashMap<String, Object>());

    //
    // Test for fidelity
    //
    assertNotNull(rubyModel);

    assertModels(xmlModel, rubyModel, debug);
}

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

License:Open Source License

@SuppressWarnings({ "unchecked" })
public void translate(final File input, final Map<String, ?> inputOptions, final File output,
        final Map<String, ?> outputOptions) throws IOException, ModelParseException {
    assert input != null;
    assert output != null;

    ModelReader reader = manager.getReaderFor(inputOptions);
    Model model = reader.read(input, inputOptions);

    ModelWriter writer = manager.getWriterFor(outputOptions);
    writer.write(output, (Map<String, Object>) outputOptions, model);
}

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

License:Open Source License

@SuppressWarnings({ "unchecked" })
public void translate(final InputStream input, final Map<String, ?> inputOptions, final OutputStream output,
        final Map<String, ?> outputOptions) throws IOException, ModelParseException {
    assert input != null;
    assert output != null;

    ModelReader reader = manager.getReaderFor(inputOptions);
    Model model = reader.read(input, inputOptions);

    ModelWriter writer = manager.getWriterFor(outputOptions);
    writer.write(output, (Map<String, Object>) outputOptions, model);
}

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

License:Open Source License

@SuppressWarnings({ "unchecked" })
public void translate(final Reader input, final Map<String, ?> inputOptions, final Writer output,
        final Map<String, ?> outputOptions) throws IOException, ModelParseException {
    assert input != null;
    assert output != null;

    ModelReader reader = manager.getReaderFor(inputOptions);
    Model model = reader.read(input, inputOptions);

    ModelWriter writer = manager.getWriterFor(outputOptions);
    writer.write(output, (Map<String, Object>) outputOptions, model);
}