Search in sources :

Example 56 with XmlPullParserException

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

the class PluginBundleManager 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 = null;
        try (InputStream newInputStream = Files.newInputStream(pluginFile)) {
            pluginDescriptor = pluginManager.getPluginDescriptor(newInputStream);
        }
        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, false);
        // } else {
        // throw new PluginException("No pom.xml or package.json found in "
        // + projectRoot.toString());
        // }
        List<SPluginInformation> plugins = new ArrayList<>();
        pluginManager.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());
                }
            }
        }
        try {
            long pluginBundleVersionId = pluginManager.pluginBundleInstalled(pluginBundle);
            for (SPluginInformation sPluginInformation : plugins) {
                if (sPluginInformation.isEnabled()) {
                    PluginContext pluginContext = pluginBundle.getPluginContext(sPluginInformation.getIdentifier());
                    // PluginConfiguration pluginConfiguration = PluginConfiguration.fromDefaults(pluginContext.getPlugin().getSystemSettingsDefinition());
                    // pluginContext.initialize(pluginConfiguration);
                    pluginManager.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) FakeClosingInputStream(org.bimserver.utils.FakeClosingInputStream) JarInputStream(java.util.jar.JarInputStream) InputStream(java.io.InputStream) PluginException(org.bimserver.shared.exceptions.PluginException) SPluginInformation(org.bimserver.interfaces.objects.SPluginInformation) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) PluginException(org.bimserver.shared.exceptions.PluginException) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) UserException(org.bimserver.shared.exceptions.UserException) InvalidVersionSpecificationException(org.apache.maven.artifact.versioning.InvalidVersionSpecificationException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) IOException(java.io.IOException) SPluginBundle(org.bimserver.interfaces.objects.SPluginBundle) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException)

Example 57 with XmlPullParserException

use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project indy by Commonjava.

the class ArchetypeCatalogMerger method merge.

public byte[] merge(final Collection<Transfer> sources, final Group group, final String path) {
    final ArchetypeCatalog master = new ArchetypeCatalog();
    final ArchetypeCatalogXpp3Reader reader = new ArchetypeCatalogXpp3Reader();
    final FileReader fr = null;
    boolean merged = false;
    final Set<String> seen = new HashSet<String>();
    for (final Transfer src : sources) {
        try (InputStream stream = src.openInputStream()) {
            final ArchetypeCatalog catalog = reader.read(stream, false);
            for (final Archetype arch : catalog.getArchetypes()) {
                final String key = arch.getGroupId() + ":" + arch.getArtifactId() + ":" + arch.getVersion();
                if (seen.add(key)) {
                    master.addArchetype(arch);
                }
            }
            merged = true;
        } catch (final IOException e) {
            final StoreKey key = getKey(src);
            logger.error(String.format("Cannot read archetype catalog: %s from artifact-store: %s. Reason: %s", src.getPath(), key, e.getMessage()), e);
        } catch (final XmlPullParserException e) {
            final StoreKey key = getKey(src);
            logger.error(String.format("Cannot parse archetype catalog: %s from artifact-store: %s. Reason: %s", src.getPath(), key, e.getMessage()), e);
        } finally {
            closeQuietly(fr);
        }
    }
    if (merged) {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {
            new ArchetypeCatalogXpp3Writer().write(baos, master);
            return baos.toByteArray();
        } catch (final IOException e) {
            logger.error(String.format("Cannot write consolidated archetype catalog: %s to: %s. Reason: %s", path, group.getKey(), e.getMessage()), e);
        }
    }
    return null;
}
Also used : Archetype(org.apache.maven.archetype.catalog.Archetype) InputStream(java.io.InputStream) ArchetypeCatalogXpp3Writer(org.apache.maven.archetype.catalog.io.xpp3.ArchetypeCatalogXpp3Writer) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StoreKey(org.commonjava.indy.model.core.StoreKey) ArchetypeCatalogXpp3Reader(org.apache.maven.archetype.catalog.io.xpp3.ArchetypeCatalogXpp3Reader) Transfer(org.commonjava.maven.galley.model.Transfer) FileReader(java.io.FileReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) ArchetypeCatalog(org.apache.maven.archetype.catalog.ArchetypeCatalog) HashSet(java.util.HashSet)

Example 58 with XmlPullParserException

use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project build-info by JFrogDev.

the class ProjectReader method readModel.

/**
 * @return Construct a Maven {@link Model} from the pom.
 */
private Model readModel(File pom) throws IOException {
    MavenXpp3Reader reader = new MavenXpp3Reader();
    StringReader stringReader = null;
    try {
        stringReader = new StringReader(Files.toString(pom, Charset.forName("UTF-8")));
        return reader.read(stringReader);
    } catch (XmlPullParserException e) {
        throw new IOException(e);
    } finally {
        IOUtils.closeQuietly(stringReader);
    }
}
Also used : 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 59 with XmlPullParserException

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

the class VssCommandLineUtils method readSettings.

public static Settings readSettings() {
    Settings settings = null;
    File settingsFile = getScmConfFile();
    if (settingsFile.exists()) {
        VssXpp3Reader reader = new VssXpp3Reader();
        try {
            settings = 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.err.println(message);
        }
    }
    // override settings with command line options
    String vssDirectory = System.getProperty("vssDirectory");
    if (StringUtils.isNotEmpty(vssDirectory)) {
        if (settings == null) {
            settings = new Settings();
        }
        settings.setVssDirectory(vssDirectory);
    }
    return settings;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) VssXpp3Reader(org.apache.maven.scm.providers.vss.settings.io.xpp3.VssXpp3Reader) File(java.io.File) Settings(org.apache.maven.scm.providers.vss.settings.Settings)

Example 60 with XmlPullParserException

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

the class LocalScmMetadataUtils method readMetadata.

/**
 * Reads metadata file from given directory.
 *
 * @param dir The directory that should contain the metadata file
 * @return LocalScmMetadata or <tt>null</tt> in case of problems
 */
public LocalScmMetadata readMetadata(File dir) {
    File metadataFile = new File(dir, FILENAME);
    if (!metadataFile.exists()) {
        return null;
    }
    LocalScmMetadata result = null;
    Reader reader = null;
    try {
        reader = ReaderFactory.newXmlReader(metadataFile);
        result = new LocalScmMetadataXpp3Reader().read(reader);
    } catch (XmlPullParserException e) {
        if (logger.isWarnEnabled()) {
            logger.warn("Could not interpret .maven-scm-local - ignoring", e);
        }
        return null;
    } catch (IOException e) {
        if (logger.isWarnEnabled()) {
            logger.warn("Could not Read .maven-scm-local - ignoring", e);
        }
    } finally {
        IOUtil.close(reader);
    }
    return result;
}
Also used : LocalScmMetadataXpp3Reader(org.apache.maven.scm.provider.local.metadata.io.xpp3.LocalScmMetadataXpp3Reader) Reader(java.io.Reader) LocalScmMetadataXpp3Reader(org.apache.maven.scm.provider.local.metadata.io.xpp3.LocalScmMetadataXpp3Reader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) File(java.io.File)

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