public URI getUri() { return definition.getUri(); }
private void buildCommonClassLoaderEnvironment(PhysicalClassLoaderDefinition definition) { URI uri = definition.getUri(); // Create an alias to the host classloader which contains all contribution artifacts in a non-isolated environment. // This simulates multiple classloaders ClassLoader hostClassLoader = classLoaderRegistry.getClassLoader(HOST_CONTRIBUTION); classLoaderRegistry.register(uri, hostClassLoader); }
/** * Resolves classpath urls. * * @param definition the physical classpath definition * @return the resolved classpath urls * @throws ClassLoaderBuilderException if an error occurs resolving a url */ private URL[] resolveClasspath(PhysicalClassLoaderDefinition definition) throws ClassLoaderBuilderException { URI uri = definition.getUri(); try { // resolve the remote contributions and cache them locally URL resolvedUrl = resolver.resolve(uri); // introspect and expand if necessary List<URL> classpath = new ArrayList<URL>(); List<Library> libraries = definition.getLibraries(); List<URL> archiveClasspath = classpathProcessorRegistry.process(resolvedUrl, libraries); classpath.addAll(archiveClasspath); return classpath.toArray(new URL[classpath.size()]); } catch (ResolutionException e) { throw new ClassLoaderBuilderException("Error resolving artifact: " + uri.toString(), e); } catch (IOException e) { throw new ClassLoaderBuilderException("Error processing: " + uri.toString(), e); } }
public void build(PhysicalClassLoaderDefinition definition) throws ClassLoaderBuilderException { URI uri = definition.getUri(); int count = tracker.increment(uri); ClassLoader classLoader = classLoaderRegistry.getClassLoader(uri); if (classLoader != null) { // The classloader was already loaded. The classloader will already be created if: it is the boot classloader; the environment is // single-VM as classloaders are shared between the contribution and runtime infrastructure; two composites are deployed individually // from the same contribution. for (PhysicalClassLoaderWireDefinition wireDefinition : definition.getWireDefinitions()) { URI target = wireDefinition.getTargetClassLoader(); classLoader = classLoaderRegistry.getClassLoader(target); tracker.incrementImported(classLoader); } notifyListenersBuild(count, classLoader); return; } if (info.supportsClassLoaderIsolation()) { buildIsolatedClassLoaderEnvironment(definition); } else { buildCommonClassLoaderEnvironment(definition); } notifyListenersBuild(count, classLoader); }
private void buildIsolatedClassLoaderEnvironment(PhysicalClassLoaderDefinition definition) throws ClassLoaderBuilderException { URI uri = definition.getUri(); // build the classloader using the locally cached resources ClassLoader hostClassLoader = classLoaderRegistry.getClassLoader(HOST_CONTRIBUTION); MultiParentClassLoader loader; if (definition.isProvisionArtifact()) { URL[] classpath = resolveClasspath(definition); loader = new MultiParentClassLoader(uri, classpath, hostClassLoader); setSysPathsField(loader); } else { loader = new MultiParentClassLoader(uri, hostClassLoader); } for (PhysicalClassLoaderWireDefinition wireDefinition : definition.getWireDefinitions()) { wireBuilder.build(loader, wireDefinition); URI target = wireDefinition.getTargetClassLoader(); ClassLoader classLoader = classLoaderRegistry.getClassLoader(target); tracker.incrementImported(classLoader); } classLoaderRegistry.register(uri, loader); }