Search in sources :

Example 1 with PublicFindClassClassLoader

use of org.bimserver.plugins.classloaders.PublicFindClassClassLoader 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

FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Model (org.apache.maven.model.Model)1 MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)1 SPluginBundle (org.bimserver.interfaces.objects.SPluginBundle)1 SPluginBundleVersion (org.bimserver.interfaces.objects.SPluginBundleVersion)1 DelegatingClassLoader (org.bimserver.plugins.classloaders.DelegatingClassLoader)1 EclipsePluginClassloader (org.bimserver.plugins.classloaders.EclipsePluginClassloader)1 PublicFindClassClassLoader (org.bimserver.plugins.classloaders.PublicFindClassClassLoader)1 PluginException (org.bimserver.shared.exceptions.PluginException)1 Dependency (org.eclipse.aether.graph.Dependency)1