/** */ protected Abstract2StageLocator(Option ... options) { try { this.classWorld = new ClassWorld(); this.realm = this.classWorld.newRealm(DEFAULT_REALM); } catch (DuplicateRealmException e) { // } }
/** Retrieve a <code>ClassRealmImpl</code> by its id. * * @param id The id. * * @return The matching class-realm. * * @throws NoSuchRealmException If the id does not correspond * to any known class-realm. */ DefaultClassRealm getRealmImpl(String id) throws NoSuchRealmException { return (DefaultClassRealm) getRealm( id ); }
public void disposeRealm( String id ) throws org.codehaus.plexus.classworlds.realm.NoSuchRealmException { try { world.disposeRealm( id ); } catch ( NoSuchRealmException e ) { throw new org.codehaus.plexus.classworlds.realm.NoSuchRealmException( this, e.getId() ); } }
public ClassWorld( String realmId, ClassLoader classLoader ) { this(); try { newRealm( realmId, classLoader ); } catch ( DuplicateRealmException e ) { // Will never happen as we are just creating the world. } }
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");
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; }
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());
/** * Called by the code in remoting to launch. * @throws org.codehaus.plexus.classworlds.realm.NoSuchRealmException */ public static int launch(String[] args) throws NoSuchMethodException, IllegalAccessException, NoSuchRealmException, InvocationTargetException, ClassNotFoundException { //ClassWorld world = ClassWorldAdapter.getInstance( launcher.getWorld() ); ClassWorld world = launcher.getWorld(); Set builtinRealms = new HashSet(world.getRealms()); try { launcher.launch(args); } finally { // delete all realms created by Maven // this is because Maven creates a child realm for each plugin it loads, // and the realm id doesn't include the version. // so unless we discard all the realms multiple invocations // that use different versions of the same plugin will fail to work correctly. Set all = new HashSet(world.getRealms()); all.removeAll(builtinRealms); for (Iterator itr = all.iterator(); itr.hasNext();) { ClassRealm cr = (ClassRealm) itr.next(); world.disposeRealm(cr.getId()); } } return launcher.getExitCode(); } }
public Collection getRealms() { Collection realms = world.getRealms(); Vector ret = new Vector(); Iterator it = realms.iterator(); while ( it.hasNext() ) { ClassRealm realm = (ClassRealm) it.next(); ret.add( ClassRealmReverseAdapter.getInstance( realm ) ); } return ret; } }
public ClassRealm newRealm( String id ) throws DuplicateRealmException { return newRealm( id, null ); }
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());
/** * Called by the code in remoting to launch. * @throws org.codehaus.plexus.classworlds.realm.NoSuchRealmException */ public static int launch(String[] args) throws NoSuchMethodException, IllegalAccessException, NoSuchRealmException, InvocationTargetException, ClassNotFoundException { //ClassWorld world = ClassWorldAdapter.getInstance( launcher.getWorld() ); ClassWorld world = launcher.getWorld(); Set builtinRealms = new HashSet(world.getRealms()); try { launcher.launch(args); } finally { // delete all realms created by Maven // this is because Maven creates a child realm for each plugin it loads, // and the realm id doesn't include the version. // so unless we discard all the realms multiple invocations // that use different versions of the same plugin will fail to work correctly. Set all = new HashSet(world.getRealms()); all.removeAll(builtinRealms); for (Iterator itr = all.iterator(); itr.hasNext();) { ClassRealm cr = (ClassRealm) itr.next(); world.disposeRealm(cr.getId()); } } return launcher.getExitCode(); } }
public Collection getRealms() { Collection realms = world.getRealms(); Vector ret = new Vector(); Iterator it = realms.iterator(); while ( it.hasNext() ) { ClassRealm realm = (ClassRealm) it.next(); ret.add( ClassRealmReverseAdapter.getInstance( realm ) ); } return ret; } }
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); } }
public ClassRealm createChildRealm( String id ) throws DuplicateRealmException { ClassRealm childRealm = getWorld().newRealm( id ); childRealm.setParent( this ); return childRealm; }
public void disposeRealm( String id ) throws org.codehaus.plexus.classworlds.realm.NoSuchRealmException { try { world.disposeRealm( id ); } catch ( NoSuchRealmException e ) { throw new org.codehaus.plexus.classworlds.realm.NoSuchRealmException( this, e.getId() ); } }
public Object run() { try { // Try to create a new ClassWorld object ClassPathManager.this.classWorld = new ClassWorld(); // Create a core realm (for internal and classpath://* plugins) try { ClassPathManager.this.classWorld.newRealm("core", getClass().getClassLoader()); } catch (DuplicateRealmException e) { e.printStackTrace(); } // Signal that we are okay. ClassPathManager.this.initializedProperly = true; } catch (SecurityException e) { ClassPathManager.this.logger.warning("Proper initialization failed due to security restrictions. Only classpath://xxx URIs will work. Sorry."); } return null; } });
/** * Adds a classpath location to this manager. * * @param location */ public void registerLocation(AbstractClassPathLocation location) { if (!this.initializedProperly) return; try { final ClassRealm newRealm = this.classWorld.newRealm(location.getRealm(), getClass().getClassLoader()); final URI[] classpathLocations = location.getClasspathLocations(); for (URI uri : classpathLocations) { newRealm.addConstituent(uri.toURL()); } } catch (DuplicateRealmException e) { // Happens for #classpath realms ... } catch (MalformedURLException e) { e.printStackTrace(); } }
/** * Retrieve the main entry realm. * * @return The main entry realm. * @throws NoSuchRealmException If the specified main entry realm does not exist. */ public ClassRealm getMainRealm() throws NoSuchRealmException { return getWorld().getRealm( getMainRealmName() ); }