Search in sources :

Example 36 with XmlPullParserException

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

the class ResourceResolver method resolveBundleFromProject.

private static List<JavadocBundle> resolveBundleFromProject(SourceResolverConfig config, MavenProject project, Artifact artifact) throws IOException {
    List<JavadocBundle> bundles = new ArrayList<JavadocBundle>();
    List<String> classifiers = new ArrayList<String>();
    if (config.includeCompileSources()) {
        classifiers.add(AbstractJavadocMojo.JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER);
    }
    if (config.includeTestSources()) {
        classifiers.add(AbstractJavadocMojo.TEST_JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER);
    }
    for (String classifier : classifiers) {
        File optionsFile = new File(project.getBuild().getDirectory(), "javadoc-bundle-options/javadoc-options-" + classifier + ".xml");
        if (!optionsFile.exists()) {
            continue;
        }
        FileInputStream stream = null;
        try {
            stream = new FileInputStream(optionsFile);
            JavadocOptions options = new JavadocOptionsXpp3Reader().read(stream);
            stream.close();
            stream = null;
            bundles.add(new JavadocBundle(options, new File(project.getBasedir(), options.getJavadocResourcesDirectory())));
        } catch (XmlPullParserException e) {
            IOException error = new IOException("Failed to read javadoc options from: " + optionsFile + "\nReason: " + e.getMessage());
            error.initCause(e);
            throw error;
        } finally {
            close(stream);
        }
    }
    return bundles;
}
Also used : JavadocOptionsXpp3Reader(org.apache.maven.plugin.javadoc.options.io.xpp3.JavadocOptionsXpp3Reader) JavadocOptions(org.apache.maven.plugin.javadoc.options.JavadocOptions) ArrayList(java.util.ArrayList) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 37 with XmlPullParserException

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

the class SupplementalModelHelper method getSupplement.

protected static Model getSupplement(Log log, Xpp3Dom supplementModelXml) throws MojoExecutionException {
    MavenXpp3Reader modelReader = new MavenXpp3Reader();
    Model model = null;
    try {
        model = modelReader.read(new StringReader(supplementModelXml.toString()));
        String groupId = model.getGroupId();
        String artifactId = model.getArtifactId();
        if (groupId == null || "".equals(groupId.trim())) {
            throw new MojoExecutionException("Supplemental project XML requires that a <groupId> element be present.");
        }
        if (artifactId == null || "".equals(artifactId.trim())) {
            throw new MojoExecutionException("Supplemental project XML requires that a <artifactId> element be present.");
        }
    } catch (IOException e) {
        log.warn("Unable to read supplemental XML: " + e.getMessage(), e);
    } catch (XmlPullParserException e) {
        log.warn("Unable to parse supplemental XML: " + e.getMessage(), e);
    }
    return model;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) SupplementalDataModel(org.apache.maven.plugin.resources.remote.SupplementalDataModel) Model(org.apache.maven.model.Model) StringReader(java.io.StringReader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException)

Example 38 with XmlPullParserException

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

the class AbstractPmdViolationCheckMojo method executeCheck.

protected void executeCheck(final String filename, final String tagName, final String key, final int failurePriority) throws MojoFailureException, MojoExecutionException {
    if (aggregate && !project.isExecutionRoot()) {
        return;
    }
    if ("pom".equals(project.getPackaging()) && !aggregate) {
        return;
    }
    excludeFromFile.loadExcludeFromFailuresData(excludeFromFailureFile);
    final File outputFile = new File(targetDirectory, filename);
    if (outputFile.exists()) {
        try {
            final ViolationDetails<D> violations = getViolations(outputFile, failurePriority);
            final List<D> failures = violations.getFailureDetails();
            final List<D> warnings = violations.getWarningDetails();
            if (verbose) {
                printErrors(failures, warnings);
            }
            final int failureCount = failures.size();
            final int warningCount = warnings.size();
            final String message = getMessage(failureCount, warningCount, key, outputFile);
            getLog().debug("PMD failureCount: " + failureCount + ", warningCount: " + warningCount);
            if (failureCount > 0 && isFailOnViolation()) {
                throw new MojoFailureException(message);
            }
            this.getLog().info(message);
        } catch (final IOException e) {
            throw new MojoExecutionException("Unable to read PMD results xml: " + outputFile.getAbsolutePath(), e);
        } catch (final XmlPullParserException e) {
            throw new MojoExecutionException("Unable to read PMD results xml: " + outputFile.getAbsolutePath(), e);
        }
    } else {
        throw new MojoFailureException("Unable to perform check, " + "unable to find " + outputFile);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) File(java.io.File)

Example 39 with XmlPullParserException

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

the class PluginManager method loadPluginsFromEclipseProject.

public PluginBundle loadPluginsFromEclipseProject(Path projectRoot) throws PluginException {
    try {
        if (!Files.isDirectory(projectRoot)) {
            throw new PluginException("No directory: " + projectRoot.toString());
        }
        final Path pluginFolder = projectRoot.resolve("plugin");
        if (!Files.isDirectory(pluginFolder)) {
            throw new PluginException("No 'plugin' directory found in " + projectRoot.toString());
        }
        Path pluginFile = pluginFolder.resolve("plugin.xml");
        if (!Files.exists(pluginFile)) {
            throw new PluginException("No 'plugin.xml' found in " + pluginFolder.toString());
        }
        PluginDescriptor pluginDescriptor = getPluginDescriptor(Files.newInputStream(pluginFile));
        Path pomFile = projectRoot.resolve("pom.xml");
        if (!Files.exists(pomFile)) {
            throw new PluginException("No pom.xml found in " + projectRoot);
        }
        // Path packageFile = projectRoot.resolve("package.json");
        // if (Files.exists(packageFile)) {
        // return loadJavaScriptProject(projectRoot, packageFile,
        // pluginFolder, pluginDescriptor);
        // } else if (Files.exists(pomFile)) {
        PluginBundle pluginBundle = loadJavaProject(projectRoot, pomFile, pluginFolder, pluginDescriptor);
        // } else {
        // throw new PluginException("No pom.xml or package.json found in "
        // + projectRoot.toString());
        // }
        List<SPluginInformation> plugins = new ArrayList<>();
        processPluginDescriptor(pluginDescriptor, plugins);
        for (SPluginInformation sPluginInformation : plugins) {
            if (sPluginInformation.isEnabled()) {
                // For local plugins, we assume to install for all users
                sPluginInformation.setInstallForAllUsers(true);
                sPluginInformation.setInstallForNewUsers(true);
                PluginContext pluginContext = pluginBundle.getPluginContext(sPluginInformation.getIdentifier());
                if (pluginContext == null) {
                    throw new PluginException("No plugin context found for " + sPluginInformation.getIdentifier());
                }
                pluginContext.getPlugin().init(pluginContext);
            }
        }
        try {
            long pluginBundleVersionId = pluginChangeListener.pluginBundleInstalled(pluginBundle);
            for (SPluginInformation sPluginInformation : plugins) {
                if (sPluginInformation.isEnabled()) {
                    PluginContext pluginContext = pluginBundle.getPluginContext(sPluginInformation.getIdentifier());
                    pluginChangeListener.pluginInstalled(pluginBundleVersionId, pluginContext, sPluginInformation);
                }
            }
        } catch (Exception e) {
            LOGGER.error("", e);
            throw new PluginException(e);
        }
        return pluginBundle;
    } catch (JAXBException e) {
        throw new PluginException(e);
    } catch (FileNotFoundException e) {
        throw new PluginException(e);
    } catch (IOException e) {
        throw new PluginException(e);
    } catch (XmlPullParserException e) {
        throw new PluginException(e);
    }
}
Also used : Path(java.nio.file.Path) PluginException(org.bimserver.shared.exceptions.PluginException) SPluginInformation(org.bimserver.interfaces.objects.SPluginInformation) JAXBException(javax.xml.bind.JAXBException) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) 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) SPluginBundle(org.bimserver.interfaces.objects.SPluginBundle) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException)

Example 40 with XmlPullParserException

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

the class PluginManager method extractPluginBundleFromJar.

// public void loadAllPluginsFromDirectoryOfJars(Path directory) throws
// PluginException, IOException {
// LOGGER.debug("Loading all plugins from " + directory.toString());
// if (!Files.isDirectory(directory)) {
// throw new PluginException("No directory: " + directory.toString());
// }
// for (Path file : PathUtils.list(directory)) {
// if (file.getFileName().toString().toLowerCase().endsWith(".jar")) {
// try {
// PluginBundleVersionIdentifier pluginBundleVersionIdentifier =
// PluginBundleVersionIdentifier.fromFileName(file.getFileName().toString());
// 
// loadPluginsFromJar(pluginBundleVersionIdentifier, file,
// extractPluginBundleFromJar(file),
// extractPluginBundleVersionFromJar(file));
// } catch (PluginException e) {
// LOGGER.error("", e);
// }
// }
// }
// }
public SPluginBundle extractPluginBundleFromJar(Path jarFilePath) throws PluginException {
    String filename = jarFilePath.getFileName().toString();
    PluginBundleVersionIdentifier pluginBundleVersionIdentifier = PluginBundleVersionIdentifier.fromFileName(filename);
    try (JarFile jarFile = new JarFile(jarFilePath.toFile())) {
        String pomLocation = "META-INF/maven/" + pluginBundleVersionIdentifier.getPluginBundleIdentifier().getGroupId() + "/" + pluginBundleVersionIdentifier.getPluginBundleIdentifier().getArtifactId() + "/" + "pom.xml";
        ZipEntry pomEntry = jarFile.getEntry(pomLocation);
        if (pomEntry == null) {
            throw new PluginException("No pom.xml found in JAR file " + jarFilePath.toString() + ", " + pomLocation);
        }
        MavenXpp3Reader mavenreader = new MavenXpp3Reader();
        Model model = mavenreader.read(jarFile.getInputStream(pomEntry));
        SPluginBundle sPluginBundle = new SPluginBundle();
        sPluginBundle.setOrganization(model.getOrganization().getName());
        sPluginBundle.setName(model.getName());
        return sPluginBundle;
    } catch (IOException e) {
        throw new PluginException(e);
    } catch (XmlPullParserException e) {
        throw new PluginException(e);
    }
}
Also used : ZipEntry(java.util.zip.ZipEntry) PluginException(org.bimserver.shared.exceptions.PluginException) Model(org.apache.maven.model.Model) SPluginBundle(org.bimserver.interfaces.objects.SPluginBundle) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) JarFile(java.util.jar.JarFile)

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