Search in sources :

Example 46 with XmlPullParserException

use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project liferay-ide by liferay.

the class LiferayMavenLegacyProjectUpdater method _hasDependency.

private boolean _hasDependency(IProject project, String groupId, String artifactId) {
    boolean retVal = false;
    IFile iFile = project.getFile("pom.xml");
    File pomFile = iFile.getLocation().toFile();
    MavenXpp3Reader mavenReader = new MavenXpp3Reader();
    try (FileReader reader = new FileReader(pomFile.getAbsolutePath())) {
        Model model = mavenReader.read(reader);
        List<Dependency> dependencies = model.getDependencies();
        for (Dependency dependency : dependencies) {
            if (groupId.equals(dependency.getGroupId()) && artifactId.equals(dependency.getArtifactId())) {
                retVal = true;
                break;
            }
        }
    } catch (FileNotFoundException fnfe) {
    } catch (IOException ioe) {
    } catch (XmlPullParserException xppe) {
    }
    return retVal;
}
Also used : IFile(org.eclipse.core.resources.IFile) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Model(org.apache.maven.model.Model) FileNotFoundException(java.io.FileNotFoundException) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) FileReader(java.io.FileReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) Dependency(org.apache.maven.model.Dependency) IOException(java.io.IOException) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 47 with XmlPullParserException

use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project archiva by apache.

the class Maven2RepositoryStorage method applyServerSideRelocation.

@Override
public void applyServerSideRelocation(ManagedRepositoryContent managedRepository, ArtifactReference artifact) throws ProxyDownloadException {
    if ("pom".equals(artifact.getType())) {
        return;
    }
    // Build the artifact POM reference
    ArtifactReference pomReference = new ArtifactReference();
    pomReference.setGroupId(artifact.getGroupId());
    pomReference.setArtifactId(artifact.getArtifactId());
    pomReference.setVersion(artifact.getVersion());
    pomReference.setType("pom");
    RepositoryProxyConnectors connectors = applicationContext.getBean("repositoryProxyConnectors#default", RepositoryProxyConnectors.class);
    // Get the artifact POM from proxied repositories if needed
    connectors.fetchFromProxies(managedRepository, pomReference);
    // Open and read the POM from the managed repo
    Path pom = managedRepository.toFile(pomReference);
    if (!Files.exists(pom)) {
        return;
    }
    try {
        // MavenXpp3Reader leaves the file open, so we need to close it ourselves.
        Model model = null;
        try (Reader reader = Files.newBufferedReader(pom, Charset.defaultCharset())) {
            model = MAVEN_XPP_3_READER.read(reader);
        }
        DistributionManagement dist = model.getDistributionManagement();
        if (dist != null) {
            Relocation relocation = dist.getRelocation();
            if (relocation != null) {
                // artifact is relocated : update the repositoryPath
                if (relocation.getGroupId() != null) {
                    artifact.setGroupId(relocation.getGroupId());
                }
                if (relocation.getArtifactId() != null) {
                    artifact.setArtifactId(relocation.getArtifactId());
                }
                if (relocation.getVersion() != null) {
                    artifact.setVersion(relocation.getVersion());
                }
            }
        }
    } catch (IOException e) {
    // Unable to read POM : ignore.
    } catch (XmlPullParserException e) {
    // Invalid POM : ignore
    }
}
Also used : Path(java.nio.file.Path) Model(org.apache.maven.model.Model) Reader(java.io.Reader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) MavenMetadataReader(org.apache.archiva.maven2.metadata.MavenMetadataReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) RepositoryProxyConnectors(org.apache.archiva.proxy.model.RepositoryProxyConnectors) IOException(java.io.IOException) DistributionManagement(org.apache.maven.model.DistributionManagement) ArtifactReference(org.apache.archiva.model.ArtifactReference) Relocation(org.apache.maven.model.Relocation)

Example 48 with XmlPullParserException

use of org.codehaus.plexus.util.xml.pull.XmlPullParserException 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 49 with XmlPullParserException

use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project kie-wb-common by kiegroup.

the class PomEditorTest method testDefault.

private void testDefault(String prj) {
    path = Paths.get("file://" + currentDir + prj + "pom.xml");
    pathCopy = Paths.get("file://" + currentDir + prj + "copy_pom.xml");
    Files.copy(path, pathCopy);
    try {
        Model original = editor.getModel(path);
        assertThat(original.getBuild().getPlugins().size()).isEqualTo(1);
        ;
        Model modelUpdated = editor.updatePomWithoutWrite(path);
        assertThat(modelUpdated.getPackaging()).isEqualToIgnoringCase("kjar");
        assertThat(modelUpdated).isNotNull();
        assertThat(modelUpdated.getBuild().getPlugins()).hasSize(1);
        List<Dependency> deps = modelUpdated.getDependencies();
        for (Dependency dep : deps) {
            assertThat(dep.getVersion()).isNotNull();
        }
    } catch (IOException ioex) {
        logger.error(ioex.getMessage(), ioex);
        throw new AssertionError(ioex.getMessage());
    } catch (XmlPullParserException xmlEx) {
        logger.error(xmlEx.getMessage(), xmlEx);
        throw new AssertionError(xmlEx.getMessage());
    }
}
Also used : Model(org.apache.maven.model.Model) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) Dependency(org.apache.maven.model.Dependency) IOException(java.io.IOException)

Example 50 with XmlPullParserException

use of org.codehaus.plexus.util.xml.pull.XmlPullParserException 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)

Aggregations

XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)79 IOException (java.io.IOException)73 File (java.io.File)37 Model (org.apache.maven.model.Model)32 MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)30 FileNotFoundException (java.io.FileNotFoundException)20 Reader (java.io.Reader)20 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)19 FileReader (java.io.FileReader)15 FileInputStream (java.io.FileInputStream)12 ArrayList (java.util.ArrayList)12 InputStream (java.io.InputStream)11 StringReader (java.io.StringReader)10 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)10 Path (java.nio.file.Path)7 Artifact (org.eclipse.aether.artifact.Artifact)7 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)7 PluginException (org.bimserver.shared.exceptions.PluginException)6 ArtifactDescriptorException (org.eclipse.aether.resolution.ArtifactDescriptorException)6 HashMap (java.util.HashMap)5