public void configureComponent(Object component, PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator, ClassRealm containerRealm, ConfigurationListener listener) throws ComponentConfigurationException { addProjectDependenciesToClassRealm(expressionEvaluator, containerRealm); converterLookup.registerConverter(new ClassRealmConverter(containerRealm)); ObjectWithFieldsConverter converter = new ObjectWithFieldsConverter(); converter.processConfiguration(converterLookup, component, containerRealm.getClassLoader(), configuration, expressionEvaluator, listener); }
private void addProjectDependenciesToClassRealm(ExpressionEvaluator expressionEvaluator, ClassRealm containerRealm) throws ComponentConfigurationException { List<String> runtimeClasspathElements; try { // noinspection unchecked runtimeClasspathElements = (List<String>) expressionEvaluator .evaluate("${project.runtimeClasspathElements}"); } catch (ExpressionEvaluationException e) { throw new ComponentConfigurationException( "There was a problem evaluating: ${project.runtimeClasspathElements}", e); } // Add the project dependencies to the ClassRealm final URL[] urls = buildURLs(runtimeClasspathElements); for (URL url : urls) { containerRealm.addConstituent(url); } }
public Class loadClass( String name ) throws ClassNotFoundException { return realm.loadClass( name ); }
public static void extendPluginClasspath(List<String> elements) throws MojoExecutionException { ClassWorld world = new ClassWorld(); try { ClassRealm realm = world.newRealm("maven", Thread.currentThread().getContextClassLoader()); for (String element : elements) { File elementFile = new File(element); realm.addConstituent(elementFile.toURI().toURL()); } Thread.currentThread().setContextClassLoader(realm.getClassLoader()); } catch (Exception ex) { throw new MojoExecutionException(ex.toString(), ex); } }
remoting.setParent(launcher.getWorld().getRealm("plexus.core.maven")); remoting.addConstituent(remotingJar.toURI().toURL()); Class remotingLauncher = remoting.loadClass("hudson.remoting.Launcher"); remotingLauncher.getMethod("main",new Class[]{InputStream.class,OutputStream.class}).invoke(null, new Object[]{
private ScriptFactory createScriptFactory() throws MojoExecutionException { try classRealm.getWorld().disposeRealm("jruby-all"); ClassRealm realm = classRealm.getWorld().newRealm("jruby-all"); for (String path : getProjectClasspath()) { realm.addConstituent(new File(path).toURI().toURL()); Class<?> clazz = realm.loadClass("org.jruby.runtime.Constants"); if ( jrubyVerbose ){ String version = clazz.getField( "VERSION" ).get(clazz).toString();
public Object newInstance( ComponentDescriptor componentDescriptor, ClassRealm classRealm, PlexusContainer container ) throws ComponentInstantiationException { ClassLoader currentContextLoader = Thread.currentThread().getContextClassLoader(); try { ClassLoader cl = classRealm.getClassLoader(); Class loader = classRealm.loadClass("clojure.plexus.factory.ClojureLoader"); Method m = loader.getDeclaredMethod("instantiate",String.class); Thread.currentThread().setContextClassLoader(cl); Object obj=m.invoke(loader,componentDescriptor.getImplementation()); return obj; } catch ( Exception e ) { classRealm.display(); throw new ComponentInstantiationException( "Failed to extract Clojure component for: " + componentDescriptor.getHumanReadableKey(), e ); } finally { Thread.currentThread() .setContextClassLoader(currentContextLoader); } }
URL scriptLocation = containerRealm.getResource( impl ); for ( int i = 0; i < containerRealm.getConstituents().length; i++ ) URL constituent = containerRealm.getConstituents()[i]; buf.append( "\n [" + i + "] " + constituent ); Thread.currentThread().setContextClassLoader( containerRealm.getClassLoader() ); result = interp.eval( reader ); Thread.currentThread().setContextClassLoader( oldClassLoader ); containerRealm.display(); containerRealm.display(); throw new ComponentInstantiationException( "Cannot build component for: " + componentDescriptor.getComponentKey() +
private ClassRealmReverseAdapter( ClassRealm oldRealm ) { super( ClassWorldReverseAdapter.getInstance( oldRealm.getWorld() ), oldRealm.getId(), oldRealm.getClassLoader() ); this.realm = oldRealm; }
type = containerRealm.loadClass( implementation ); containerRealm.getClassLoader(), expressionEvaluator );
ClassRealm jruby; try { jruby = classRealm.getWorld().getRealm("jruby"); jruby = classRealm.getWorld().newRealm("jruby"); if(jrubyJar != null){ jruby.addConstituent(jrubyJar.toURI().toURL()); jruby.getWorld().disposeRealm("pom"); newClassRealm = jruby.createChildRealm("pom"); for (final String classpath : classpathElements) { if (!classpath.contains("jruby-complete") || factory.jrubyJar == null) { newClassRealm.addConstituent(new File(classpath).toURI() .toURL());
curRealm.importFrom( relamName, importSpec ); curRealm.addConstituent( file.toURL() ); curRealm.addConstituent( new URL( constituent ) );
private static synchronized ClassRealm getOrCreateClassRealm(final ClassRealm classRealm, final File jrubyJar) throws MalformedURLException, ScriptException { ClassRealm jruby; try { jruby = classRealm.getWorld().getRealm("jruby"); } catch (final NoSuchRealmException e) { try { jruby = classRealm.getWorld().newRealm("jruby"); if(jrubyJar != null){ jruby.addConstituent(jrubyJar.toURI().toURL()); } } catch (final DuplicateRealmException ee) { throw new ScriptException("could not setup classrealm for jruby", ee); } } return jruby; }
realm.addConstituent( uri.toURL() ); getLog().debug( "Added to realm : " + uri ); try(InputStream is = realm.getResourceAsStream( resourceName );)
workflowRealm = containerRealm.createChildRealm("plugin.fornax.oaw.workflow"); Resource resource = (Resource) resources.get(i); File directory = resolvePath(new File(resource.getDirectory())); workflowRealm.addConstituent(toURL(directory, true)); if (getLog().isDebugEnabled()) { getLog().debug("Added resource to classpath: " + toURL(directory, true)); workflowRealm.addConstituent(artifactUrl); if (getLog().isDebugEnabled()) { final boolean resolved = !artifact.getFile().toURI().toURL().equals(artifactUrl);
public URL getResource( String name ) { return realm.getResource( name ); }
protected URL getScriptLocation( ComponentDescriptor componentDescriptor, ClassRealm classRealm ) { String impl = componentDescriptor.getImplementation(); if ( !impl.startsWith( "/" ) ) { impl = "/" + impl; } URL scriptLocation = classRealm.getResource( impl ); if(scriptLocation == null) { System.out.println("Cannot find: " + impl + " in classpath:"); for ( int i = 0; i < classRealm.getConstituents().length; i++ ) { URL constituent = classRealm.getConstituents()[i]; System.out.println("[" + i + "] " + constituent); } } return scriptLocation; }
public InputStream getResourceAsStream( String name ) { return realm.getResourceAsStream( name ); }
public String getId() { return realm.getId(); }
private void showUrls( ClassRealm classRealm ) { System.out.println( "this realm = " + classRealm.getId() ); URL[] urls = classRealm.getConstituents(); for ( int i = 0; i < urls.length; i++ ) { System.out.println( "urls[" + i + "] = " + urls[i] ); } System.out.println( "Number of imports: " + imports.size() ); for ( Iterator i = imports.iterator(); i.hasNext(); ) { System.out.println( "import: " + i.next() ); } } }