Search in sources :

Example 6 with SPluginBundle

use of org.bimserver.interfaces.objects.SPluginBundle in project BIMserver by opensourceBIM.

the class PluginBundleDatabaseAction method processMavenPluginLocation.

public SPluginBundle processMavenPluginLocation(MavenPluginLocation mavenPluginLocation, boolean strictVersionChecking, ArtifactVersion bimserverVersion) {
    SPluginBundle pluginBundle = new SPluginBundle();
    boolean usefulBundle = false;
    for (PluginVersion pluginVersion : mavenPluginLocation.getAllVersions()) {
        if (pluginVersion instanceof MavenPluginVersion) {
            SPluginBundleVersion sPluginBundleVersion = new SPluginBundleVersion();
            boolean useful = true;
            MavenPluginVersion mavenPluginVersion = (MavenPluginVersion) pluginVersion;
            for (MavenDependency mavenDependency : mavenPluginVersion.getDependencies()) {
                if (mavenDependency.getArtifact().getGroupId().equals("org.opensourcebim")) {
                    String artifactId = mavenDependency.getArtifact().getArtifactId();
                    // for the plugin, it's version has to be ok
                    if (artifactId.equals("shared") || artifactId.equals("pluginbase")) {
                        VersionRange versionRange = VersionRange.createFromVersion(mavenDependency.getArtifact().getVersion());
                        if (bimserverVersion != null && versionRange.containsVersion(bimserverVersion)) {
                        } else {
                            sPluginBundleVersion.setMismatch(true);
                            if (strictVersionChecking) {
                                useful = false;
                                LOGGER.info("Skipping version " + mavenPluginVersion.getArtifact().getVersion() + " or artifact " + mavenPluginVersion.getArtifact().getArtifactId());
                            }
                        }
                    }
                }
            }
            if (useful) {
                usefulBundle = true;
                sPluginBundleVersion.setName(mavenPluginVersion.getModel().getName());
                sPluginBundleVersion.setOrganization(mavenPluginVersion.getModel().getOrganization().getName());
                sPluginBundleVersion.setArtifactId(mavenPluginLocation.getArtifactId());
                sPluginBundleVersion.setGroupId(mavenPluginLocation.getGroupId());
                try {
                    sPluginBundleVersion.setRepository(mavenPluginLocation.getRepository(mavenPluginVersion.getVersion().toString()));
                } catch (ArtifactResolutionException e) {
                    LOGGER.error("", e);
                }
                sPluginBundleVersion.setType(SPluginBundleType.MAVEN);
                sPluginBundleVersion.setVersion(mavenPluginVersion.getVersion().toString());
                sPluginBundleVersion.setDescription(mavenPluginVersion.getModel().getDescription());
                pluginBundle.setName(mavenPluginVersion.getModel().getName());
                pluginBundle.setOrganization(mavenPluginVersion.getModel().getOrganization().getName());
                pluginBundle.setLatestVersion(sPluginBundleVersion);
                pluginBundle.getAvailableVersions().add(sPluginBundleVersion);
                try {
                    sPluginBundleVersion.setIcon(mavenPluginLocation.getVersionIcon(mavenPluginVersion.getVersion().toString()));
                } catch (ArtifactResolutionException e) {
                // This is not important
                } catch (IOException e) {
                    LOGGER.error("", e);
                }
                try {
                    GregorianCalendar date = mavenPluginLocation.getVersionDate(mavenPluginVersion.getVersion().toString());
                    if (date != null) {
                        sPluginBundleVersion.setDate(date.getTime());
                    }
                // byte[] bytes = Files.readAllBytes(date);
                // Properties properties = new Properties();
                // properties.load(new ByteArrayInputStream(bytes));
                // String buildDateString = properties.getProperty("build.date");
                // 
                // DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
                // try {
                // } catch (ParseException e) {
                // LOGGER.error("Invalid date format for plugin " + mavenPluginVersion.getModel().getName() + ": '" + buildDateString + "'");
                // }
                } catch (ArtifactResolutionException e) {
                // Not a problem
                } catch (Exception e) {
                    LOGGER.error("", e);
                }
            }
        }
    }
    if (usefulBundle) {
        return pluginBundle;
    }
    return null;
}
Also used : SPluginBundleVersion(org.bimserver.interfaces.objects.SPluginBundleVersion) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) MavenPluginVersion(org.bimserver.plugins.MavenPluginVersion) PluginVersion(org.bimserver.plugins.PluginVersion) MavenPluginVersion(org.bimserver.plugins.MavenPluginVersion) SPluginBundle(org.bimserver.interfaces.objects.SPluginBundle) GregorianCalendar(java.util.GregorianCalendar) VersionRange(org.apache.maven.artifact.versioning.VersionRange) IOException(java.io.IOException) IOException(java.io.IOException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) MavenDependency(org.bimserver.plugins.MavenDependency)

Example 7 with SPluginBundle

use of org.bimserver.interfaces.objects.SPluginBundle in project BIMserver by opensourceBIM.

the class GetPluginBundle method execute.

@Override
public SPluginBundle execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
    if (bimServer.getVersionChecker() != null && bimServer.getVersionChecker().getLocalVersion() != null) {
        bimserverVersion = new DefaultArtifactVersion(bimServer.getVersionChecker().getLocalVersion().getFullString());
    }
    MavenPluginLocation pluginLocation = bimServer.getMavenPluginRepository().getPluginLocation(repository, groupId, artifactId);
    PluginBundle pluginBundle = bimServer.getPluginManager().getPluginBundle(pluginLocation.getPluginIdentifier());
    // Skipping all plugin bundles that already have an installed version
    if (pluginBundle == null) {
        SPluginBundle sPluginBundle = processPluginLocation(pluginLocation, false, bimserverVersion);
        if (sPluginBundle != null) {
            return sPluginBundle;
        }
    }
    throw new UserException("Plugin bundle already installed " + groupId + "." + artifactId);
}
Also used : PluginBundle(org.bimserver.plugins.PluginBundle) SPluginBundle(org.bimserver.interfaces.objects.SPluginBundle) MavenPluginLocation(org.bimserver.plugins.MavenPluginLocation) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) SPluginBundle(org.bimserver.interfaces.objects.SPluginBundle) UserException(org.bimserver.shared.exceptions.UserException)

Example 8 with SPluginBundle

use of org.bimserver.interfaces.objects.SPluginBundle in project BIMserver by opensourceBIM.

the class PluginManager method loadPlugin.

public PluginBundle loadPlugin(PluginBundleVersionIdentifier pluginBundleVersionIdentifier, Path target, SPluginBundle sPluginBundle, SPluginBundleVersion pluginBundleVersion, List<SPluginInformation> plugins, ClassLoader parentClassLoader) throws Exception {
    PluginBundle pluginBundle = null;
    // Stage 1, load all plugins from the JAR file and initialize them
    try {
        pluginBundle = loadPluginsFromJar(pluginBundleVersionIdentifier, target, sPluginBundle, pluginBundleVersion, parentClassLoader);
        if (plugins.isEmpty()) {
            LOGGER.warn("No plugins given to install for bundle " + sPluginBundle.getName());
        }
        for (SPluginInformation sPluginInformation : plugins) {
            if (sPluginInformation.isEnabled()) {
                PluginContext pluginContext = pluginBundle.getPluginContext(sPluginInformation.getIdentifier());
                if (pluginContext == null) {
                    LOGGER.info("No plugin context found for " + sPluginInformation.getIdentifier());
                } else {
                    pluginContext.getPlugin().init(pluginContext);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        if (pluginBundle != null) {
            pluginBundle.close();
        }
        pluginBundleVersionIdentifierToPluginBundle.remove(pluginBundleVersionIdentifier);
        pluginBundleIdentifierToPluginBundle.remove(pluginBundleVersionIdentifier.getPluginBundleIdentifier());
        Files.delete(target);
        LOGGER.error("", e);
        throw e;
    }
    // uninstalled
    try {
        long pluginBundleVersionId = pluginChangeListener.pluginBundleInstalled(pluginBundle);
        for (SPluginInformation sPluginInformation : plugins) {
            if (sPluginInformation.isEnabled()) {
                PluginContext pluginContext = pluginBundle.getPluginContext(sPluginInformation.getIdentifier());
                pluginChangeListener.pluginInstalled(pluginBundleVersionId, pluginContext, sPluginInformation);
            }
        }
        return pluginBundle;
    } catch (Exception e) {
        uninstall(pluginBundleVersionIdentifier);
        LOGGER.error("", e);
        throw e;
    }
}
Also used : SPluginBundle(org.bimserver.interfaces.objects.SPluginBundle) SPluginInformation(org.bimserver.interfaces.objects.SPluginInformation) 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)

Example 9 with SPluginBundle

use of org.bimserver.interfaces.objects.SPluginBundle in project BIMserver by opensourceBIM.

the class PluginManager method uninstall.

// public PluginBundle install(PluginBundleVersionIdentifier
// pluginBundleVersionIdentifier, SPluginBundle sPluginBundle,
// SPluginBundleVersion pluginBundleVersion, List<SPluginInformation>
// plugins, boolean strictDependencyChecking) throws Exception {
// MavenXpp3Reader mavenreader = new MavenXpp3Reader();
// Model model = mavenreader.read(new FileReader(pomFile.toFile()));
// 
// 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(version);
// if (versionRange.containsVersion(artifactVersion)) {
// // OK
// } else {
// throw new Exception("Required dependency " + pluginBundleIdentifier + "
// is installed, but it's version (" + version + ") 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);
// 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(jarFile, target);
// 
// return loadPlugin(pluginBundleVersionIdentifier, target, sPluginBundle,
// pluginBundleVersion, plugins, delegatingClassLoader);
// }
public void uninstall(PluginBundleVersionIdentifier pluginBundleVersionIdentifier) {
    PluginBundle pluginBundle = pluginBundleVersionIdentifierToPluginBundle.get(pluginBundleVersionIdentifier);
    if (pluginBundle == null) {
        return;
    }
    try {
        pluginBundle.close();
        pluginBundleVersionIdentifierToPluginBundle.remove(pluginBundleVersionIdentifier);
        pluginBundleIdentifierToPluginBundle.remove(pluginBundleVersionIdentifier.getPluginBundleIdentifier());
        pluginBundleIdentifierToCurrentPluginBundleVersionIdentifier.remove(pluginBundleVersionIdentifier.getPluginBundleIdentifier());
        for (PluginContext pluginContext : pluginBundle) {
            Set<PluginContext> set = implementations.get(pluginContext.getPluginInterface());
            set.remove(pluginContext);
        }
        Path target = pluginsDir.resolve(pluginBundleVersionIdentifier.getFileName());
        Files.delete(target);
        for (PluginContext pluginContext : pluginBundle) {
            pluginChangeListener.pluginUninstalled(pluginContext);
        }
        pluginChangeListener.pluginBundleUninstalled(pluginBundle);
    } catch (IOException e) {
        LOGGER.error("", e);
    }
}
Also used : SPluginBundle(org.bimserver.interfaces.objects.SPluginBundle) Path(java.nio.file.Path) IOException(java.io.IOException)

Example 10 with SPluginBundle

use of org.bimserver.interfaces.objects.SPluginBundle 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)

Aggregations

SPluginBundle (org.bimserver.interfaces.objects.SPluginBundle)14 IOException (java.io.IOException)8 PluginException (org.bimserver.shared.exceptions.PluginException)6 Model (org.apache.maven.model.Model)5 MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)5 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)5 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)5 FileNotFoundException (java.io.FileNotFoundException)4 Path (java.nio.file.Path)4 DefaultArtifactVersion (org.apache.maven.artifact.versioning.DefaultArtifactVersion)4 SPluginBundleVersion (org.bimserver.interfaces.objects.SPluginBundleVersion)4 UserException (org.bimserver.shared.exceptions.UserException)4 FileReader (java.io.FileReader)3 FileSystemNotFoundException (java.nio.file.FileSystemNotFoundException)3 JAXBException (javax.xml.bind.JAXBException)3 PluginBundle (org.bimserver.plugins.PluginBundle)3 DelegatingClassLoader (org.bimserver.plugins.classloaders.DelegatingClassLoader)3 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)3 ObjectIDMException (org.bimserver.plugins.objectidms.ObjectIDMException)3 ArrayList (java.util.ArrayList)2