Search in sources :

Example 11 with MavenXpp3Reader

use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project fabric8-maven-plugin by fabric8io.

the class BaseBoosterIT method updateSourceCode.

protected void updateSourceCode(Repository repository, String relativePomPath) throws XmlPullParserException, IOException {
    MavenXpp3Reader reader = new MavenXpp3Reader();
    String baseDir = repository.getWorkTree().getAbsolutePath();
    Model model = reader.read(new FileInputStream(new File(baseDir, relativePomPath)));
    Dependency dependency = new Dependency();
    dependency.setGroupId("org.apache.commons");
    dependency.setArtifactId("commons-lang3");
    dependency.setVersion("3.5");
    model.getDependencies().add(dependency);
    MavenXpp3Writer writer = new MavenXpp3Writer();
    writer.write(new FileOutputStream(new File(baseDir, relativePomPath)), model);
    model.getArtifactId();
}
Also used : MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) MavenXpp3Writer(org.apache.maven.model.io.xpp3.MavenXpp3Writer)

Example 12 with MavenXpp3Reader

use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project dkpro-tc by dkpro.

the class ModelVersionIO method getCurrentTcVersionFromJar.

default String getCurrentTcVersionFromJar() throws Exception {
    Class<?> contextClass = getClass();
    InputStream stream = contextClass.getResourceAsStream("/META-INF/maven/org.dkpro.tc/dkpro-tc-core/pom.xml");
    if (stream == null) {
        return null;
    }
    MavenXpp3Reader reader = new MavenXpp3Reader();
    Model model;
    try {
        model = reader.read(stream);
    } finally {
        IOUtils.closeQuietly(stream);
    }
    String version = model.getParent().getVersion();
    return version;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Model(org.apache.maven.model.Model) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader)

Example 13 with MavenXpp3Reader

use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project dkpro-tc by dkpro.

the class ModelVersionIO method getCurrentTcVersionFromWorkspace.

default String getCurrentTcVersionFromWorkspace() throws Exception {
    Class<?> contextClass = getClass();
    // Try to determine the location of the POM file belonging to the
    // context object
    URL url = contextClass.getResource(contextClass.getSimpleName() + ".class");
    String classPart = contextClass.getName().replace(".", "/") + ".class";
    String base = url.toString();
    base = base.substring(0, base.length() - classPart.length());
    base = base.substring(0, base.length() - "target/classes/".length());
    File pomFile = new File(new File(URI.create(base)), "pom.xml");
    MavenXpp3Reader reader = new MavenXpp3Reader();
    Model model;
    FileInputStream fis = null;
    try {
        fis = new FileInputStream(pomFile);
        model = reader.read(fis);
    } finally {
        IOUtils.closeQuietly(fis);
    }
    String version = model.getParent().getVersion();
    return version;
}
Also used : Model(org.apache.maven.model.Model) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) File(java.io.File) URL(java.net.URL) FileInputStream(java.io.FileInputStream)

Example 14 with MavenXpp3Reader

use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project ServiceStack.Java by ServiceStack.

the class EclipseMavenHelper method addMavenDependencyIfRequired.

public boolean addMavenDependencyIfRequired(IFile pomFile, String groupId, String packageId, String version) throws Exception {
    boolean dependencyAdded = false;
    MavenXpp3Reader reader = new MavenXpp3Reader();
    Model pomModel;
    try {
        pomModel = reader.read(new FileReader(new File(pomFile.getLocationURI())));
        final List<Dependency> dependencies = pomModel.getDependencies();
        boolean requiresPomDependency = true;
        for (Dependency dep : dependencies) {
            if (Objects.equals(dep.getGroupId(), groupId) && Objects.equals(dep.getArtifactId(), packageId)) {
                requiresPomDependency = false;
            }
        }
        String content;
        if (requiresPomDependency) {
            Dependency dependency = new Dependency();
            dependency.setGroupId(groupId);
            dependency.setArtifactId(packageId);
            dependency.setVersion(version);
            pomModel.addDependency(dependency);
            StringWriter strWriter = new StringWriter();
            new MavenXpp3Writer().write(strWriter, pomModel);
            content = strWriter.toString();
            InputStream stream = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));
            pomFile.setContents(stream, false, false, null);
            dependencyAdded = true;
        }
    } catch (IOException | XmlPullParserException e) {
        e.printStackTrace();
        throw new Exception("Unable to process pom.xml to add " + groupId + ":" + packageId + ":" + version);
    }
    return dependencyAdded;
}
Also used : MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) Dependency(org.apache.maven.model.Dependency) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) Model(org.apache.maven.model.Model) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IFile(org.eclipse.core.resources.IFile) MavenXpp3Writer(org.apache.maven.model.io.xpp3.MavenXpp3Writer)

Example 15 with MavenXpp3Reader

use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project ceylon by eclipse.

the class AetherResolverImpl method getDependencies.

@Override
public DependencyDescriptor getDependencies(File pomXml, String name, String version) throws IOException {
    MavenXpp3Reader reader = new MavenXpp3Reader();
    Model model;
    try (FileReader fileReader = new FileReader(pomXml)) {
        model = reader.read(fileReader);
    } catch (XmlPullParserException e) {
        throw new IOException(e);
    }
    return new ModelDependencyDescriptor(model);
}
Also used : Model(org.eclipse.ceylon.aether.apache.maven.model.Model) MavenXpp3Reader(org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader) FileReader(java.io.FileReader) XmlPullParserException(org.eclipse.ceylon.aether.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException)

Aggregations

MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)65 Model (org.apache.maven.model.Model)59 IOException (java.io.IOException)39 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)33 FileReader (java.io.FileReader)27 File (java.io.File)18 FileNotFoundException (java.io.FileNotFoundException)17 Reader (java.io.Reader)15 Path (java.nio.file.Path)11 PluginException (org.bimserver.shared.exceptions.PluginException)11 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)10 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)10 SPluginBundle (org.bimserver.interfaces.objects.SPluginBundle)9 ArtifactDescriptorException (org.eclipse.aether.resolution.ArtifactDescriptorException)9 DelegatingClassLoader (org.bimserver.plugins.classloaders.DelegatingClassLoader)8 InputStream (java.io.InputStream)7 FileInputStream (java.io.FileInputStream)6 DefaultArtifactVersion (org.apache.maven.artifact.versioning.DefaultArtifactVersion)6 ArrayList (java.util.ArrayList)5 JarFile (java.util.jar.JarFile)5