Search in sources :

Example 1 with XmlPullParserException

use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project maven-plugins by apache.

the class ResourceResolver method resolveBundlesFromArtifacts.

private List<JavadocBundle> resolveBundlesFromArtifacts(final SourceResolverConfig config, final List<Artifact> artifacts) throws IOException {
    final List<Artifact> toResolve = new ArrayList<Artifact>(artifacts.size());
    for (final Artifact artifact : artifacts) {
        if (config.filter() != null && !new ArtifactIncludeFilterTransformer().transform(config.filter()).include(artifact)) {
            continue;
        }
        if (config.includeCompileSources()) {
            toResolve.add(createResourceArtifact(artifact, AbstractJavadocMojo.JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER, config));
        }
        if (config.includeTestSources()) {
            toResolve.add(createResourceArtifact(artifact, AbstractJavadocMojo.TEST_JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER, config));
        }
    }
    List<String> dirs = null;
    try {
        dirs = resolveAndUnpack(toResolve, config, RESOURCE_VALID_CLASSIFIERS, false);
    } catch (ArtifactResolutionException e) {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug(e.getMessage(), e);
        }
    } catch (ArtifactNotFoundException e) {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug(e.getMessage(), e);
        }
    }
    List<JavadocBundle> result = new ArrayList<JavadocBundle>();
    if (dirs != null) {
        for (String d : dirs) {
            File dir = new File(d);
            File resources = new File(dir, ResourcesBundleMojo.RESOURCES_DIR_PATH);
            JavadocOptions options = null;
            File javadocOptions = new File(dir, ResourcesBundleMojo.BUNDLE_OPTIONS_PATH);
            if (javadocOptions.exists()) {
                FileInputStream reader = null;
                try {
                    reader = new FileInputStream(javadocOptions);
                    options = new JavadocOptionsXpp3Reader().read(reader);
                } catch (XmlPullParserException e) {
                    IOException error = new IOException("Failed to parse javadoc options: " + e.getMessage());
                    error.initCause(e);
                    throw error;
                } finally {
                    close(reader);
                }
            }
            result.add(new JavadocBundle(options, resources));
        }
    }
    return result;
}
Also used : ArtifactIncludeFilterTransformer(org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) FileInputStream(java.io.FileInputStream) JavadocOptionsXpp3Reader(org.apache.maven.plugin.javadoc.options.io.xpp3.JavadocOptionsXpp3Reader) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) JavadocOptions(org.apache.maven.plugin.javadoc.options.JavadocOptions) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) File(java.io.File)

Example 2 with XmlPullParserException

use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project BIMserver by opensourceBIM.

the class PluginManager method loadDependencies.

private PublicFindClassClassLoader loadDependencies(Set<org.bimserver.plugins.Dependency> bimServerDependencies, Model model, PublicFindClassClassLoader previous) throws FileNotFoundException, IOException {
    List<org.apache.maven.model.Dependency> dependencies = model.getDependencies();
    Iterator<org.apache.maven.model.Dependency> it = dependencies.iterator();
    Path workspaceDir = Paths.get("..");
    bimServerDependencies.add(new org.bimserver.plugins.Dependency(workspaceDir.resolve("PluginBase/target/classes")));
    bimServerDependencies.add(new org.bimserver.plugins.Dependency(workspaceDir.resolve("Shared/target/classes")));
    while (it.hasNext()) {
        org.apache.maven.model.Dependency depend = it.next();
        try {
            if (depend.getGroupId().equals("org.opensourcebim") && (depend.getArtifactId().equals("shared") || depend.getArtifactId().equals("pluginbase"))) {
                // TODO we might want to check the version though
                continue;
            }
            if (depend.isOptional() || "test".equals(depend.getScope())) {
                continue;
            }
            Dependency dependency2 = new Dependency(new DefaultArtifact(depend.getGroupId() + ":" + depend.getArtifactId() + ":jar:" + depend.getVersion()), "compile");
            DelegatingClassLoader depDelLoader = new DelegatingClassLoader(previous);
            if (!dependency2.getArtifact().isSnapshot()) {
                if (dependency2.getArtifact().getFile() != null) {
                    bimServerDependencies.add(new org.bimserver.plugins.Dependency(dependency2.getArtifact().getFile().toPath()));
                    loadDependencies(dependency2.getArtifact().getFile().toPath(), depDelLoader);
                } else {
                    ArtifactRequest request = new ArtifactRequest();
                    request.setArtifact(dependency2.getArtifact());
                    request.setRepositories(mavenPluginRepository.getRepositories());
                    try {
                        ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
                        if (resolveArtifact.getArtifact().getFile() != null) {
                            bimServerDependencies.add(new org.bimserver.plugins.Dependency(resolveArtifact.getArtifact().getFile().toPath()));
                            loadDependencies(resolveArtifact.getArtifact().getFile().toPath(), depDelLoader);
                        } else {
                        // TODO error?
                        }
                    } catch (ArtifactResolutionException e) {
                        e.printStackTrace();
                    }
                }
            } else {
                // Snapshot projects linked in Eclipse
                ArtifactRequest request = new ArtifactRequest();
                if ((!"test".equals(dependency2.getScope()) && !dependency2.getArtifact().isSnapshot())) {
                    request.setArtifact(dependency2.getArtifact());
                    request.setRepositories(mavenPluginRepository.getLocalRepositories());
                    try {
                        ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
                        if (resolveArtifact.getArtifact().getFile() != null) {
                            bimServerDependencies.add(new org.bimserver.plugins.Dependency(resolveArtifact.getArtifact().getFile().toPath()));
                            loadDependencies(resolveArtifact.getArtifact().getFile().toPath(), depDelLoader);
                        } else {
                        // TODO error?
                        }
                    } catch (Exception e) {
                        LOGGER.info(dependency2.getArtifact().toString());
                        e.printStackTrace();
                    }
                // bimServerDependencies.add(new
                // org.bimserver.plugins.Dependency(resolveArtifact.getArtifact().getFile().toPath()));
                }
            }
            ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
            descriptorRequest.setArtifact(dependency2.getArtifact());
            descriptorRequest.setRepositories(mavenPluginRepository.getRepositories());
            ArtifactDescriptorResult descriptorResult = mavenPluginRepository.getSystem().readArtifactDescriptor(mavenPluginRepository.getSession(), descriptorRequest);
            CollectRequest collectRequest = new CollectRequest();
            collectRequest.setRootArtifact(descriptorResult.getArtifact());
            collectRequest.setDependencies(descriptorResult.getDependencies());
            collectRequest.setManagedDependencies(descriptorResult.getManagedDependencies());
            collectRequest.setRepositories(descriptorResult.getRepositories());
            DependencyNode node = mavenPluginRepository.getSystem().collectDependencies(mavenPluginRepository.getSession(), collectRequest).getRoot();
            DependencyRequest dependencyRequest = new DependencyRequest();
            dependencyRequest.setRoot(node);
            CollectResult collectResult = mavenPluginRepository.getSystem().collectDependencies(mavenPluginRepository.getSession(), collectRequest);
            PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
            // collectResult.getRoot().accept(new
            // ConsoleDependencyGraphDumper());
            collectResult.getRoot().accept(nlg);
            try {
                mavenPluginRepository.getSystem().resolveDependencies(mavenPluginRepository.getSession(), dependencyRequest);
            } catch (DependencyResolutionException e) {
            // Ignore
            }
            for (DependencyNode dependencyNode : nlg.getNodes()) {
                ArtifactRequest newRequest = new ArtifactRequest(dependencyNode);
                newRequest.setRepositories(mavenPluginRepository.getRepositories());
                ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), newRequest);
                Artifact artifact = resolveArtifact.getArtifact();
                Path jarFile = Paths.get(artifact.getFile().getAbsolutePath());
                loadDependencies(jarFile, depDelLoader);
                Artifact versionArtifact = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), "pom", artifact.getVersion());
                ArtifactRequest request = new ArtifactRequest();
                request.setArtifact(versionArtifact);
                request.setRepositories(mavenPluginRepository.getRepositories());
                // try {
                // ArtifactResult resolveArtifact =
                // mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(),
                // request);
                // File depPomFile =
                // resolveArtifact.getArtifact().getFile();
                // if (depPomFile != null) {
                // MavenXpp3Reader mavenreader = new MavenXpp3Reader();
                // Model depModel = null;
                // try (FileReader reader = new FileReader(depPomFile)) {
                // try {
                // depModel = mavenreader.read(reader);
                // } catch (XmlPullParserException e) {
                // e.printStackTrace();
                // }
                // }
                // previous = loadDependencies(bimServerDependencies,
                // depModel, previous);
                // } else {
                // LOGGER.info("Artifact not found " + versionArtifact);
                // }
                // } catch (ArtifactResolutionException e1) {
                // LOGGER.error(e1.getMessage());
                // }
                // EclipsePluginClassloader depLoader = new
                // EclipsePluginClassloader(depDelLoader, projectRoot);
                bimServerDependencies.add(new org.bimserver.plugins.Dependency(jarFile));
            }
            previous = depDelLoader;
        } catch (DependencyCollectionException e) {
            e.printStackTrace();
        } catch (ArtifactDescriptorException e2) {
            e2.printStackTrace();
        } catch (ArtifactResolutionException e) {
            e.printStackTrace();
        }
    }
    return previous;
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DependencyNode(org.eclipse.aether.graph.DependencyNode) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) ArtifactDescriptorRequest(org.eclipse.aether.resolution.ArtifactDescriptorRequest) Path(java.nio.file.Path) DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) CollectResult(org.eclipse.aether.collection.CollectResult) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) DelegatingClassLoader(org.bimserver.plugins.classloaders.DelegatingClassLoader) PreorderNodeListGenerator(org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator) ObjectIDMException(org.bimserver.plugins.objectidms.ObjectIDMException) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) ServiceException(org.bimserver.shared.exceptions.ServiceException) IOException(java.io.IOException) PluginException(org.bimserver.shared.exceptions.PluginException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) UserException(org.bimserver.shared.exceptions.UserException) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) ArtifactDescriptorResult(org.eclipse.aether.resolution.ArtifactDescriptorResult) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 3 with XmlPullParserException

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

the class PomHelper method readPom.

public static MavenProject readPom(File pomFile) throws MojoExecutionException {
    Reader reader = null;
    try {
        reader = new FileReader(pomFile);
        MavenXpp3Reader modelReader = new MavenXpp3Reader();
        return new MavenProject(modelReader.read(reader));
    } catch (FileNotFoundException e) {
        throw new MojoExecutionException("Error reading specified POM file: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new MojoExecutionException("Error reading specified POM file: " + e.getMessage(), e);
    } catch (XmlPullParserException e) {
        throw new MojoExecutionException("Error reading specified POM file: " + e.getMessage(), e);
    } finally {
        IOUtil.close(reader);
    }
}
Also used : MavenProject(org.apache.maven.project.MavenProject) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) Reader(java.io.Reader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) FileReader(java.io.FileReader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException)

Example 4 with XmlPullParserException

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

the class AttachPartialBundleListMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    final BundleList initializedBundleList;
    if (bundleListFile.exists()) {
        try {
            initializedBundleList = readBundleList(bundleListFile);
        } catch (IOException e) {
            throw new MojoExecutionException("Unable to read bundle list file", e);
        } catch (XmlPullParserException e) {
            throw new MojoExecutionException("Unable to read bundle list file", e);
        }
    } else {
        throw new MojoFailureException(String.format("Bundle list file %s does not exist.", bundleListFile.getAbsolutePath()));
    }
    interpolateProperties(initializedBundleList, this.project, this.mavenSession);
    final BundleListXpp3Writer writer = new BundleListXpp3Writer();
    try {
        this.bundleListOutput.getParentFile().mkdirs();
        writer.write(new FileWriter(bundleListOutput), initializedBundleList);
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to write bundle list", e);
    }
    // if this project is a partial bundle list, it's the main artifact
    if (project.getPackaging().equals(PARTIAL)) {
        project.getArtifact().setFile(bundleListOutput);
    } else {
        // otherwise attach it as an additional artifact
        projectHelper.attachArtifact(project, TYPE, CLASSIFIER, bundleListOutput);
    }
    this.getLog().info("Attaching bundle list configuration");
    try {
        this.attachConfigurations();
    } catch (final IOException ioe) {
        throw new MojoExecutionException("Unable to attach configuration.", ioe);
    } catch (final ArchiverException ioe) {
        throw new MojoExecutionException("Unable to attach configuration.", ioe);
    }
}
Also used : BundleListXpp3Writer(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.io.xpp3.BundleListXpp3Writer) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) BundleListUtils.readBundleList(org.apache.sling.maven.projectsupport.BundleListUtils.readBundleList) BundleList(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) FileWriter(java.io.FileWriter) MojoFailureException(org.apache.maven.plugin.MojoFailureException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException)

Example 5 with XmlPullParserException

use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project maven-scm by apache.

the class ClearCaseUtil method readSettings.

public static Settings readSettings() {
    File settingsFile = new File(settingsDirectory, CLEARCASE_SETTINGS_FILENAME);
    if (!settingsFile.exists()) {
        File scmGlobalDir = new File(System.getProperty("maven.home"), "conf");
        settingsFile = new File(scmGlobalDir, CLEARCASE_SETTINGS_FILENAME);
    }
    if (settingsFile.exists()) {
        ClearcaseXpp3Reader reader = new ClearcaseXpp3Reader();
        try {
            return reader.read(ReaderFactory.newXmlReader(settingsFile));
        } catch (FileNotFoundException e) {
        // nop
        } catch (IOException e) {
        // nop
        } catch (XmlPullParserException e) {
            String message = settingsFile.getAbsolutePath() + " isn't well formed. SKIPPED." + e.getMessage();
            System.out.println(message);
        }
    }
    return new Settings();
}
Also used : ClearcaseXpp3Reader(org.apache.maven.scm.providers.clearcase.settings.io.xpp3.ClearcaseXpp3Reader) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) File(java.io.File) Settings(org.apache.maven.scm.providers.clearcase.settings.Settings)

Aggregations

XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)76 IOException (java.io.IOException)70 File (java.io.File)37 Model (org.apache.maven.model.Model)31 MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)29 Reader (java.io.Reader)20 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)19 FileNotFoundException (java.io.FileNotFoundException)18 FileReader (java.io.FileReader)15 FileInputStream (java.io.FileInputStream)12 ArrayList (java.util.ArrayList)12 InputStream (java.io.InputStream)10 StringReader (java.io.StringReader)10 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)8 Artifact (org.eclipse.aether.artifact.Artifact)6 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)6 Path (java.nio.file.Path)5 HashMap (java.util.HashMap)5 MojoFailureException (org.apache.maven.plugin.MojoFailureException)5 IllegalCharsetNameException (java.nio.charset.IllegalCharsetNameException)4