public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } ProvisionClassloaderCommand that = (ProvisionClassloaderCommand) o; return !(definition != null ? !definition.equals(that.definition) : that.definition != null); }
public URI getUri() { return definition.getUri(); }
public int hashCode() { return (definition != null ? definition.hashCode() : 0); } }
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); }
/** * 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); } }
private PhysicalClassLoaderDefinition createClassLoaderDefinition(Contribution contribution) { URI uri = contribution.getUri(); if (Names.BOOT_CONTRIBUTION.equals(uri) || Names.HOST_CONTRIBUTION.equals(uri)) { return null; } boolean provisionArtifact = contribution.getLocation() != null; // don't provision synthetic artifacts; List<Library> libraries = contribution.getManifest().getLibraries(); PhysicalClassLoaderDefinition definition = new PhysicalClassLoaderDefinition(uri, libraries, provisionArtifact); List<ContributionWire<?, ?>> contributionWires = contribution.getWires(); for (ContributionWire<?, ?> wire : contributionWires) { ClassLoaderWireGenerator generator = generators.get(wire.getClass()); if (generator == null) { // not all contribution wires resolve resources through classloaders, so skip if one is not found continue; } PhysicalClassLoaderWireDefinition wireDefinition = generator.generate(wire); definition.add(wireDefinition); } return definition; }
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 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); }