Search in sources :

Example 46 with MavenXpp3Reader

use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project drools by kiegroup.

the class StaticMethodTestHelper method getProjectVersion.

static String getProjectVersion() {
    URL codeLocUrl = StaticMethodTestHelper.class.getProtectionDomain().getCodeSource().getLocation();
    String projVersionStr = null;
    String codeLocStr = null;
    try {
        codeLocStr = codeLocUrl.toURI().toString();
        if (codeLocStr.endsWith(".jar")) {
            Matcher jarLocMatcher = jarLocRegex.matcher(codeLocStr);
            assertTrue("Regex for code (jar) location did not match location!", jarLocMatcher.matches() && jarLocMatcher.groupCount() >= 2);
            projVersionStr = jarLocMatcher.group(1);
        } else {
            codeLocStr = codeLocStr.replace("target/classes/", "pom.xml");
            File pomFile = new File(new URI(codeLocStr));
            assertTrue(codeLocStr + " does not exist!", pomFile.exists());
            Reader reader = null;
            try {
                reader = new FileReader(pomFile);
                MavenXpp3Reader xpp3Reader = new MavenXpp3Reader();
                Model model = xpp3Reader.read(reader);
                projVersionStr = model.getVersion();
                if (projVersionStr == null) {
                    projVersionStr = model.getParent().getVersion();
                }
                String projectName = model.getGroupId() + ":" + model.getArtifactId();
                assertNotNull("Unable to resolve project version for " + projectName, projVersionStr);
            } catch (FileNotFoundException fnfe) {
                throw new RuntimeException("Unable to open " + pomFile.getAbsolutePath(), fnfe);
            } catch (IOException ioe) {
                throw new RuntimeException("Unable to read " + codeLocStr, ioe);
            } catch (XmlPullParserException xppe) {
                throw new RuntimeException("Unable to parse " + codeLocStr, xppe);
            } finally {
                try {
                    if (reader != null) {
                        reader.close();
                    }
                } catch (IOException e) {
                // no-op
                }
            }
        }
    } catch (URISyntaxException urise) {
        throw new RuntimeException("Invalid URL: " + codeLocStr, urise);
    }
    return projVersionStr;
}
Also used : Matcher(java.util.regex.Matcher) FileNotFoundException(java.io.FileNotFoundException) Reader(java.io.Reader) FileReader(java.io.FileReader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URL(java.net.URL) Model(org.apache.maven.model.Model) FileReader(java.io.FileReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) File(java.io.File)

Example 47 with MavenXpp3Reader

use of org.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 48 with MavenXpp3Reader

use of org.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 49 with MavenXpp3Reader

use of org.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 50 with MavenXpp3Reader

use of org.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)

Aggregations

MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)66 Model (org.apache.maven.model.Model)61 IOException (java.io.IOException)40 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)34 FileReader (java.io.FileReader)28 File (java.io.File)18 FileNotFoundException (java.io.FileNotFoundException)17 Reader (java.io.Reader)15 Path (java.nio.file.Path)12 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 MavenXpp3Writer (org.apache.maven.model.io.xpp3.MavenXpp3Writer)6 StringReader (java.io.StringReader)5