Search in sources :

Example 31 with MavenXpp3Reader

use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader 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 32 with MavenXpp3Reader

use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project BIMserver by opensourceBIM.

the class PluginManager method loadJavaProject.

public PluginBundle loadJavaProject(Path projectRoot, Path pomFile, Path pluginFolder, PluginDescriptor pluginDescriptor) throws PluginException, FileNotFoundException, IOException, XmlPullParserException {
    MavenXpp3Reader mavenreader = new MavenXpp3Reader();
    Model model = null;
    try (FileReader reader = new FileReader(pomFile.toFile())) {
        model = mavenreader.read(reader);
    }
    PluginBundleVersionIdentifier pluginBundleVersionIdentifier = new PluginBundleVersionIdentifier(model.getGroupId(), model.getArtifactId(), model.getVersion());
    if (pluginBundleIdentifierToPluginBundle.containsKey(pluginBundleVersionIdentifier.getPluginBundleIdentifier())) {
        throw new PluginException("Plugin " + pluginBundleVersionIdentifier.getPluginBundleIdentifier().getHumanReadable() + " already loaded (version " + pluginBundleIdentifierToPluginBundle.get(pluginBundleVersionIdentifier.getPluginBundleIdentifier()).getPluginBundleVersion().getVersion() + ")");
    }
    DelegatingClassLoader delegatingClassLoader = new DelegatingClassLoader(getClass().getClassLoader());
    PublicFindClassClassLoader previous = new PublicFindClassClassLoader(getClass().getClassLoader()) {

        @Override
        public Class<?> findClass(String name) throws ClassNotFoundException {
            return null;
        }

        @Override
        public URL findResource(String name) {
            return null;
        }

        @Override
        public void dumpStructure(int indent) {
        }
    };
    Set<org.bimserver.plugins.Dependency> bimServerDependencies = new HashSet<>();
    pluginBundleVersionIdentifier = new PluginBundleVersionIdentifier(new PluginBundleIdentifier(model.getGroupId(), model.getArtifactId()), model.getVersion());
    previous = loadDependencies(bimServerDependencies, model, previous);
    delegatingClassLoader.add(previous);
    // Path libFolder = projectRoot.resolve("lib");
    // loadDependencies(libFolder, delegatingClassLoader);
    EclipsePluginClassloader pluginClassloader = new EclipsePluginClassloader(delegatingClassLoader, projectRoot);
    // pluginClassloader.dumpStructure(0);
    ResourceLoader resourceLoader = new ResourceLoader() {

        @Override
        public InputStream load(String name) {
            try {
                return Files.newInputStream(pluginFolder.resolve(name));
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
    };
    SPluginBundle sPluginBundle = new SPluginBundle();
    sPluginBundle.setOrganization(model.getOrganization().getName());
    sPluginBundle.setName(model.getName());
    SPluginBundleVersion sPluginBundleVersion = createPluginBundleVersionFromMavenModel(model, true);
    Path icon = projectRoot.resolve("icon.png");
    if (Files.exists(icon)) {
        byte[] iconBytes = Files.readAllBytes(icon);
        sPluginBundleVersion.setIcon(iconBytes);
    }
    sPluginBundle.setInstalledVersion(sPluginBundleVersion);
    return loadPlugins(pluginBundleVersionIdentifier, resourceLoader, pluginClassloader, projectRoot.toUri(), projectRoot.resolve("target/classes").toString(), pluginDescriptor, PluginSourceType.ECLIPSE_PROJECT, bimServerDependencies, sPluginBundle, sPluginBundleVersion);
}
Also used : SPluginBundleVersion(org.bimserver.interfaces.objects.SPluginBundleVersion) Path(java.nio.file.Path) PluginException(org.bimserver.shared.exceptions.PluginException) PublicFindClassClassLoader(org.bimserver.plugins.classloaders.PublicFindClassClassLoader) SPluginBundle(org.bimserver.interfaces.objects.SPluginBundle) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) Dependency(org.eclipse.aether.graph.Dependency) IOException(java.io.IOException) DelegatingClassLoader(org.bimserver.plugins.classloaders.DelegatingClassLoader) Model(org.apache.maven.model.Model) FileReader(java.io.FileReader) EclipsePluginClassloader(org.bimserver.plugins.classloaders.EclipsePluginClassloader) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 33 with MavenXpp3Reader

use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project BIMserver by opensourceBIM.

the class PluginManager method install.

public PluginBundle install(MavenPluginBundle mavenPluginBundle, List<SPluginInformation> plugins, boolean strictDependencyChecking) throws Exception {
    PluginBundleVersionIdentifier pluginBundleVersionIdentifier = mavenPluginBundle.getPluginVersionIdentifier();
    MavenXpp3Reader mavenreader = new MavenXpp3Reader();
    Model model = null;
    try (InputStream pomInputStream = mavenPluginBundle.getPomInputStream()) {
        model = mavenreader.read(pomInputStream);
    }
    if (plugins == null) {
        try (JarInputStream jarInputStream = new JarInputStream(mavenPluginBundle.getJarInputStream())) {
            JarEntry nextJarEntry = jarInputStream.getNextJarEntry();
            while (nextJarEntry != null) {
                if (nextJarEntry.getName().equals("plugin/plugin.xml")) {
                    // Install all plugins
                    PluginDescriptor pluginDescriptor = getPluginDescriptor(new FakeClosingInputStream(jarInputStream));
                    plugins = new ArrayList<>();
                    processPluginDescriptor(pluginDescriptor, plugins);
                    for (SPluginInformation info : plugins) {
                        info.setInstallForAllUsers(true);
                        info.setInstallForNewUsers(true);
                    }
                    break;
                }
                nextJarEntry = jarInputStream.getNextJarEntry();
            }
        }
    }
    DelegatingClassLoader delegatingClassLoader = new DelegatingClassLoader(getClass().getClassLoader());
    for (org.apache.maven.model.Dependency dependency : model.getDependencies()) {
        if (dependency.getGroupId().equals("org.opensourcebim") && (dependency.getArtifactId().equals("shared") || dependency.getArtifactId().equals("pluginbase"))) {
        // TODO Skip, we should also check the version though
        } else {
            PluginBundleIdentifier pluginBundleIdentifier = new PluginBundleIdentifier(dependency.getGroupId(), dependency.getArtifactId());
            if (pluginBundleIdentifierToPluginBundle.containsKey(pluginBundleIdentifier)) {
                if (strictDependencyChecking) {
                    VersionRange versionRange = VersionRange.createFromVersion(dependency.getVersion());
                    // String version =
                    // pluginBundleIdentifierToPluginBundle.get(pluginBundleIdentifier).getPluginBundleVersion().getVersion();
                    ArtifactVersion artifactVersion = new DefaultArtifactVersion(mavenPluginBundle.getVersion());
                    if (versionRange.containsVersion(artifactVersion)) {
                    // OK
                    } else {
                        throw new Exception("Required dependency " + pluginBundleIdentifier + " is installed, but it's version (" + mavenPluginBundle.getVersion() + ") does not comply to the required version (" + dependency.getVersion() + ")");
                    }
                } else {
                    LOGGER.info("Skipping strict dependency checking for dependency " + dependency.getArtifactId());
                }
            } else {
                try {
                    MavenPluginLocation mavenPluginLocation = mavenPluginRepository.getPluginLocation(dependency.getGroupId(), dependency.getArtifactId());
                    Path depJarFile = mavenPluginLocation.getVersionJar(dependency.getVersion());
                    FileJarClassLoader jarClassLoader = new FileJarClassLoader(this, delegatingClassLoader, depJarFile);
                    jarClassLoaders.add(jarClassLoader);
                    delegatingClassLoader.add(jarClassLoader);
                } catch (Exception e) {
                    throw new Exception("Required dependency " + pluginBundleIdentifier + " is not installed");
                }
            }
        }
    }
    Path target = pluginsDir.resolve(pluginBundleVersionIdentifier.getFileName());
    if (Files.exists(target)) {
        throw new PluginException("This plugin has already been installed " + target.getFileName().toString());
    }
    Files.copy(mavenPluginBundle.getJarInputStream(), target);
    return loadPlugin(pluginBundleVersionIdentifier, target, mavenPluginBundle.getPluginBundle(), mavenPluginBundle.getPluginBundleVersion(), plugins, delegatingClassLoader);
}
Also used : Path(java.nio.file.Path) JarInputStream(java.util.jar.JarInputStream) FakeClosingInputStream(org.bimserver.utils.FakeClosingInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) JarInputStream(java.util.jar.JarInputStream) InputStream(java.io.InputStream) SPluginInformation(org.bimserver.interfaces.objects.SPluginInformation) PluginException(org.bimserver.shared.exceptions.PluginException) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) VersionRange(org.apache.maven.artifact.versioning.VersionRange) JarEntry(java.util.jar.JarEntry) DelegatingClassLoader(org.bimserver.plugins.classloaders.DelegatingClassLoader) 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) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) ArtifactVersion(org.apache.maven.artifact.versioning.ArtifactVersion) FileJarClassLoader(org.bimserver.plugins.classloaders.FileJarClassLoader) Model(org.apache.maven.model.Model) FakeClosingInputStream(org.bimserver.utils.FakeClosingInputStream)

Example 34 with MavenXpp3Reader

use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader 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)

Example 35 with MavenXpp3Reader

use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project BIMserver by opensourceBIM.

the class PluginManager method extractPluginBundleVersionFromJar.

public SPluginBundleVersion extractPluginBundleVersionFromJar(Path jarFilePath, boolean isLocal) throws PluginException {
    String filename = jarFilePath.getFileName().toString();
    PluginBundleVersionIdentifier pluginBundleVersionIdentifier = PluginBundleVersionIdentifier.fromFileName(filename);
    PluginBundleIdentifier pluginBundleIdentifier = pluginBundleVersionIdentifier.getPluginBundleIdentifier();
    try (JarFile jarFile = new JarFile(jarFilePath.toFile())) {
        ZipEntry pomEntry = jarFile.getEntry("META-INF/maven/" + pluginBundleIdentifier.getGroupId() + "/" + pluginBundleIdentifier.getArtifactId() + "/" + "pom.xml");
        if (pomEntry == null) {
            throw new PluginException("No pom.xml found in JAR file " + jarFilePath.toString());
        }
        MavenXpp3Reader mavenreader = new MavenXpp3Reader();
        Model model = mavenreader.read(jarFile.getInputStream(pomEntry));
        SPluginBundleVersion sPluginBundleVersion = createPluginBundleVersionFromMavenModel(model, isLocal);
        return sPluginBundleVersion;
    } catch (IOException e) {
        throw new PluginException(e);
    } catch (XmlPullParserException e) {
        throw new PluginException(e);
    }
}
Also used : SPluginBundleVersion(org.bimserver.interfaces.objects.SPluginBundleVersion) ZipEntry(java.util.zip.ZipEntry) PluginException(org.bimserver.shared.exceptions.PluginException) Model(org.apache.maven.model.Model) 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

MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)65 Model (org.apache.maven.model.Model)59 IOException (java.io.IOException)39 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)33 FileReader (java.io.FileReader)27 File (java.io.File)18 FileNotFoundException (java.io.FileNotFoundException)17 Reader (java.io.Reader)15 Path (java.nio.file.Path)11 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 ArrayList (java.util.ArrayList)5 JarFile (java.util.jar.JarFile)5