Search in sources :

Example 46 with MavenXpp3Reader

use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project kie-wb-common by kiegroup.

the class MigrationToolTest method testNewPomStructure.

@Test
public void testNewPomStructure() throws IOException, XmlPullParserException {
    final File projectDir = getProjectDir(SPACE_B, PROJECT_B2), pom = new File(projectDir, "pom.xml");
    final MavenXpp3Reader reader = new MavenXpp3Reader();
    final Model model = reader.read(new FileInputStream(pom));
    assertThat(model.getVersion()).isEqualTo("1.2.3");
    assertThat(model.getDependencies()).hasSize(6);
    assertThat(model.getBuild().getPlugins()).hasSize(1);
    assertThat(model.getPackaging()).isEqualTo("kjar");
}
Also used : DataObjectFormModel(org.kie.workbench.common.forms.data.modeller.model.DataObjectFormModel) BusinessProcessFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.process.BusinessProcessFormModel) TaskFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.task.TaskFormModel) Model(org.apache.maven.model.Model) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 47 with MavenXpp3Reader

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

the class MavenUtils method mavenProjectRepositories.

/**
 * @return Collection of configured repositories for the Maven project.
 */
private static Collection<String> mavenProjectRepositories() throws Exception {
    String workDir = System.getProperty("user.dir");
    File prjPomFile = new File(workDir, "pom.xml");
    if (!prjPomFile.exists())
        return Collections.emptyList();
    Path outPath = Files.createTempFile("effective-pom", "");
    try {
        exec(buildMvnCommand() + " -f " + workDir + " help:effective-pom -Doutput=" + outPath.toAbsolutePath());
        Model model = new MavenXpp3Reader().read(new FileInputStream(outPath.toFile()));
        return F.transform(model.getRepositories(), RepositoryBase::getUrl);
    } finally {
        Files.deleteIfExists(outPath);
    }
}
Also used : Path(java.nio.file.Path) RepositoryBase(org.apache.maven.model.RepositoryBase) Model(org.apache.maven.model.Model) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 48 with MavenXpp3Reader

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

the class MavenPluginLocation method getPluginBundleVersion.

public SPluginBundleVersion getPluginBundleVersion(String version) {
    try {
        Path pomFile = getVersionPom(version);
        MavenXpp3Reader mavenreader = new MavenXpp3Reader();
        Model model = null;
        try (FileReader fileReader = new FileReader(pomFile.toFile())) {
            model = mavenreader.read(fileReader);
        }
        SPluginBundleVersion sPluginBundleVersion = new SPluginBundleVersion();
        sPluginBundleVersion.setOrganization(model.getOrganization().getName());
        sPluginBundleVersion.setName(model.getName());
        sPluginBundleVersion.setType(SPluginBundleType.MAVEN);
        sPluginBundleVersion.setGroupId(groupId);
        sPluginBundleVersion.setArtifactId(artifactId);
        sPluginBundleVersion.setVersion(version);
        sPluginBundleVersion.setDescription(model.getDescription());
        // sPluginBundleVersion.setRepository(defaultrepository);
        sPluginBundleVersion.setMismatch(false);
        try {
            sPluginBundleVersion.setIcon(getVersionIcon(version));
        } catch (ArtifactResolutionException e) {
        // Not a problem
        }
        try {
            GregorianCalendar date = getVersionDate(version);
            // DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
            if (date != null) {
                sPluginBundleVersion.setDate(date.getTime());
            }
        } catch (ArtifactResolutionException e) {
        // Not a problem
        } catch (Exception e) {
            LOGGER.error("", e);
        }
        return sPluginBundleVersion;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (XmlPullParserException e) {
        e.printStackTrace();
    } catch (ArtifactResolutionException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : Path(java.nio.file.Path) SPluginBundleVersion(org.bimserver.interfaces.objects.SPluginBundleVersion) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) Model(org.apache.maven.model.Model) GregorianCalendar(java.util.GregorianCalendar) FileNotFoundException(java.io.FileNotFoundException) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) FileReader(java.io.FileReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) ParseException(java.text.ParseException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 49 with MavenXpp3Reader

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

the class MavenPluginLocation method getPluginBundle.

public SPluginBundle getPluginBundle(String version) {
    try {
        Artifact versionArtifact = new DefaultArtifact(groupId, artifactId, "pom", version);
        ArtifactRequest request = new ArtifactRequest();
        request.setArtifact(versionArtifact);
        ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
        File pomFile = resolveArtifact.getArtifact().getFile();
        MavenXpp3Reader mavenreader = new MavenXpp3Reader();
        Model model = null;
        try (FileReader fileReader = new FileReader(pomFile)) {
            model = mavenreader.read(fileReader);
        }
        SPluginBundle sPluginBundle = new SPluginBundle();
        sPluginBundle.setOrganization(model.getOrganization().getName());
        sPluginBundle.setName(model.getName());
        return sPluginBundle;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (XmlPullParserException e) {
        e.printStackTrace();
    } catch (ArtifactResolutionException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : SPluginBundle(org.bimserver.interfaces.objects.SPluginBundle) FileNotFoundException(java.io.FileNotFoundException) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) IOException(java.io.IOException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) Model(org.apache.maven.model.Model) FileReader(java.io.FileReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 50 with MavenXpp3Reader

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

the class MavenPluginLocation method getAllVersions.

@Override
public List<MavenPluginVersion> getAllVersions() {
    List<MavenPluginVersion> pluginVersions = new ArrayList<>();
    Artifact artifact = new DefaultArtifact(groupId, artifactId, null, "[0,)");
    VersionRangeRequest rangeRequest = new VersionRangeRequest();
    rangeRequest.setArtifact(artifact);
    rangeRequest.setRepositories(mavenPluginRepository.getRepositoriesAsList());
    // RemoteRepository centralRepo = newCentralRepository();
    try {
        VersionRangeResult rangeResult = mavenPluginRepository.getSystem().resolveVersionRange(mavenPluginRepository.getSession(), rangeRequest);
        List<Version> versions = rangeResult.getVersions();
        if (!versions.isEmpty()) {
            for (int i = versions.size() - 1; i >= Math.max(0, versions.size() - 3); i--) {
                Version version = versions.get(i);
                ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
                Artifact versionArtifact = new DefaultArtifact(groupId, artifactId, "pom", version.toString());
                descriptorRequest.setArtifact(versionArtifact);
                descriptorRequest.setRepositories(mavenPluginRepository.getRepositoriesAsList());
                MavenPluginVersion mavenPluginVersion = new MavenPluginVersion(versionArtifact, version);
                ArtifactDescriptorResult descriptorResult = mavenPluginRepository.getSystem().readArtifactDescriptor(mavenPluginRepository.getSession(), descriptorRequest);
                ArtifactRequest request = new ArtifactRequest();
                request.setArtifact(descriptorResult.getArtifact());
                request.setRepositories(mavenPluginRepository.getRepositoriesAsList());
                ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
                File pomFile = resolveArtifact.getArtifact().getFile();
                MavenXpp3Reader mavenreader = new MavenXpp3Reader();
                try (FileReader fileReader = new FileReader(pomFile)) {
                    Model model = mavenreader.read(fileReader);
                    mavenPluginVersion.setModel(model);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (XmlPullParserException e) {
                    e.printStackTrace();
                }
                for (org.eclipse.aether.graph.Dependency dependency : descriptorResult.getDependencies()) {
                    DefaultArtifactVersion artifactVersion = new DefaultArtifactVersion(dependency.getArtifact().getVersion());
                    mavenPluginVersion.addDependency(new MavenDependency(dependency.getArtifact(), artifactVersion));
                }
                pluginVersions.add(0, mavenPluginVersion);
            }
        }
    } catch (VersionRangeResolutionException e) {
        e.printStackTrace();
    } catch (ArtifactDescriptorException e) {
        e.printStackTrace();
    } catch (ArtifactResolutionException e) {
        e.printStackTrace();
    }
    return pluginVersions;
}
Also used : ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) Version(org.eclipse.aether.version.Version) SPluginBundleVersion(org.bimserver.interfaces.objects.SPluginBundleVersion) VersionRangeRequest(org.eclipse.aether.resolution.VersionRangeRequest) FileReader(java.io.FileReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) ArtifactDescriptorRequest(org.eclipse.aether.resolution.ArtifactDescriptorRequest) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) VersionRangeResult(org.eclipse.aether.resolution.VersionRangeResult) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) IOException(java.io.IOException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) Model(org.apache.maven.model.Model) ArtifactDescriptorResult(org.eclipse.aether.resolution.ArtifactDescriptorResult) File(java.io.File) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

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