Example usage for org.apache.maven.model.io ModelReader read

List of usage examples for org.apache.maven.model.io ModelReader read

Introduction

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

Prototype

Model read(InputStream input, Map<String, ?> options) throws IOException, ModelParseException;

Source Link

Document

Reads the model from the specified byte stream.

Usage

From source file:io.github.jeddict.jcode.util.POMManager.java

License:Apache License

@Override
public POMManager copy(String... inputResources) {
    Map<String, ?> properties = Collections.singletonMap(ModelReader.IS_STRICT, false);
    ModelReader reader = EmbedderFactory.getProjectEmbedder().lookupComponent(ModelReader.class);
    for (String inputResource : inputResources) {
        try {/*from  w  w  w  .  ja v  a  2 s .c om*/
            //source
            sourceModels.add(reader.read(FileUtil.loadResource(inputResource), properties));
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
    return this;
}

From source file:io.github.jeddict.jcode.util.POMManager.java

License:Apache License

@Override
public POMManager copy(Reader... inputResources) {
    Map<String, ?> properties = Collections.singletonMap(ModelReader.IS_STRICT, false);
    ModelReader reader = EmbedderFactory.getProjectEmbedder().lookupComponent(ModelReader.class);
    for (Reader inputResource : inputResources) {
        try {/*from   w  ww  .  j a v a 2 s  .c o  m*/
            //source
            sourceModels.add(reader.read(inputResource, properties));
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
    return this;
}

From source file:net.officefloor.maven.classpath.ClassPathFactoryImpl.java

License:Open Source License

/**
 * Obtains the {@link Model} (POM) from the archive.
 * //from w  w  w  . j  av  a  2 s  .  c om
 * @param archiveFile
 *            Archive {@link File}.
 * @return {@link Model}.
 * @throws Exception
 *             If fails to obtain the POM {@link Model}.
 */
private Model getArchivePom(File archiveFile) throws Exception {

    // Attempt to open archive file
    ZipFile archive = null;
    try {
        archive = new ZipFile(archiveFile, ZipFile.OPEN_READ);
    } catch (Exception ex) {
        return null; // Not archive
    }

    // Obtain the pom.xml file from within the archive
    ZipEntry pomEntry = null;
    for (Enumeration<? extends ZipEntry> iterator = archive.entries(); iterator.hasMoreElements();) {
        ZipEntry entry = iterator.nextElement();

        // Ensure pom.xml within the META-INF/maven location
        String name = entry.getName();
        if (name.startsWith("META-INF/maven/") && (name.endsWith("/pom.xml"))) {
            // Found the POM
            pomEntry = entry;
            break; // entry found
        }
    }
    if (pomEntry == null) {
        archive.close(); // ensure close archive
        return null; // no pom.xml
    }

    // Obtain model for POM
    ModelReader reader = this.plexusContainer.lookup(ModelReader.class);
    InputStream pomContents = archive.getInputStream(pomEntry);
    Model pomModel = reader.read(pomContents, null);
    pomContents.close();

    // Close the archive
    archive.close();

    // Return the POM model
    return pomModel;
}

From source file:org.apache.karaf.tooling.semantic.UnitHelp.java

License:Apache License

/**
 * Resolve maven URI into maven project.
 * <p>/*from  w ww  .j av  a  2s.c o m*/
 * Provides only model and artifact.
 */
public static MavenProject newProject(String mavenURI) throws Exception {

    final Artifact artifact = newArtifact(mavenURI);

    final File input = artifact.getFile();

    final ModelReader reader = new DefaultModelReader();

    final Model model = reader.read(input, null);

    final MavenProject project = new MavenProject(model);

    project.setArtifact(RepositoryUtils.toArtifact(artifact));

    return project;

}

From source file:org.netbeans.jcode.core.util.POMManager.java

License:Apache License

public POMManager(String inputResource, Project project) {
    try {//from ww  w  . j a v  a 2  s .c  om
        this.project = project;
        operations = new ArrayList<>();
        InputStream pomStream = FileUtil.loadResource(inputResource);
        ModelReader reader = EmbedderFactory.getProjectEmbedder().lookupComponent(ModelReader.class);
        model = reader.read(pomStream, Collections.singletonMap(ModelReader.IS_STRICT, false));
        pomFileObject = org.openide.filesystems.FileUtil
                .toFileObject(project.getLookup().lookup(NbMavenProjectImpl.class).getPOMFile());
        //            org.netbeans.modules.xml.xam.ModelSource source = Utilities.createModelSource(pomFileObject);
        //            pomModel = POMModelFactory.getDefault().createFreshModel(source);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }

}

From source file:org.sonatype.maven.polyglot.plugin.ExecuteMojo.java

License:Open Source License

protected Model modelFromNativePom(Log log) throws MojoExecutionException, MojoFailureException {
    Map<String, ModelSource> options = new HashMap<String, ModelSource>();
    options.put(ModelProcessor.SOURCE, new FileModelSource(nativePom));

    assert modelManager != null;
    try {/*w  w  w. j  a v a  2  s.  c  om*/
        ModelReader reader = modelManager.getReaderFor(options);
        if (reader == null) {
            throw new MojoExecutionException("no model reader found for " + nativePom);
        }
        if (log.isDebugEnabled()) {
            log.debug("Parsing native pom " + nativePom);
        }
        return reader.read(nativePom, options);
    } catch (IOException e) {
        throw new MojoFailureException("error parsing " + nativePom, e);
    }
}

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

License:Apache License

public Model read(final Reader input, final Map<String, ?> options) throws IOException, ModelParseException {
    assert manager != null;
    ModelReader reader = manager.getReaderFor(options);
    return reader.read(input, options);
}

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);
}