/** * Creates a fresh object instance of the specified classname. * * <p>This uses the userDefinedLoader to load the specified class, * and then makes an instance using the default no-argument constructor.</p> * * @param className the full qualified class name to load. * @param userDefinedLoader the classloader to use. * @return The fresh object instance * @throws BuildException when loading or instantiation failed. */ public static Object newInstance(String className, ClassLoader userDefinedLoader) { return newInstance(className, userDefinedLoader, Object.class); }
/** * Convenience overloaded version of {@link * #getClassLoaderForPath(Project, Reference, boolean)}. * * <p>Assumes the logical 'false' for the reverseLoader.</p> * * @param p the project * @param ref the reference * @return The class loader */ public static ClassLoader getClassLoaderForPath(Project p, Reference ref) { return getClassLoaderForPath(p, ref, false); }
private ClasspathUtils.Delegate getDelegate() { if (cpDelegate == null) { cpDelegate = ClasspathUtils.getDelegate(this); } return cpDelegate; } }
/** * Convenience overloaded version of {@link * #getClassLoaderForPath(Project, Path, String, boolean, boolean)}. * * <p>Sets value for 'reuseLoader' to true if the magic property * has been set.</p> * * @param p the project * @param path the path * @param loaderId the loader id string * @param reverseLoader if set to true this new loader will take * precedence over its parent (which is contra the regular * classloader behaviour) * @return The class loader */ public static ClassLoader getClassLoaderForPath( Project p, Path path, String loaderId, boolean reverseLoader) { return getClassLoaderForPath(p, path, loaderId, reverseLoader, isMagicPropertySet(p)); }
cl = getUniqueClassLoaderForPath(p, path, reverseLoader); if (loaderId != null && reuseLoader) { p.addReference(loaderId, cl);
/** * Create an instance of a matcher from a classname. * * @param className a <code>String</code> value * @return a <code>RegexpMatcher</code> value * @exception BuildException if an error occurs */ protected RegexpMatcher createInstance(String className) throws BuildException { return ClasspathUtils.newInstance(className, RegexpMatcherFactory.class.getClassLoader(), RegexpMatcher.class); }
/** * Convenience overloaded version of {@link * #getClassLoaderForPath(Project, Path, String, boolean)}. * * <p>Assumes the logical 'false' for the reverseLoader.</p> * * @param p current Ant project * @param path the path * @param loaderId the loader id string * @return The class loader */ public static ClassLoader getClassLoaderForPath(Project p, Path path, String loaderId) { return getClassLoaderForPath(p, path, loaderId, false); }
private ClasspathUtils.Delegate getClassPathDelegate() { if (cpDelegate == null) { if (projectComponent == null) { throw new IllegalStateException("Can't access classpath without a project component"); } cpDelegate = ClasspathUtils.getDelegate(projectComponent); } return cpDelegate; }
/** * Wrapper over RegexpMatcherFactory.createInstance that ensures that * we are dealing with a Regexp implementation. * @param classname the name of the class to use. * @return the instance. * @throws BuildException if there is a problem. * @since 1.3 * * @see RegexpMatcherFactory#createInstance(String) */ protected Regexp createRegexpInstance(String classname) throws BuildException { return ClasspathUtils.newInstance(classname, RegexpFactory.class.getClassLoader(), Regexp.class); }
/** * Convenience overloaded version of {@link #getClassLoaderForPath(Project, Path, * String, boolean)}. * * <p>Delegates to the other one after extracting the referenced * Path from the Project. This checks also that the passed * Reference is pointing to a Path all right.</p> * @param p current Ant project * @param ref Reference to Path structure * @param reverseLoader if set to true this new loader will take * precedence over its parent (which is contra the regular * classloader behaviour) * @return The class loader */ public static ClassLoader getClassLoaderForPath( Project p, Reference ref, boolean reverseLoader) { String pathId = ref.getRefId(); Object path = p.getReference(pathId); if (!(path instanceof Path)) { throw new BuildException( "The specified classpathref %s does not reference a Path.", pathId); } String loaderId = MagicNames.REFID_CLASSPATH_LOADER_PREFIX + pathId; return getClassLoaderForPath(p, (Path) path, loaderId, reverseLoader); }
/** * Tries to resolve the given classname into a javah adapter. * Throws a fit if it can't. * * @param className The fully qualified classname to be created. * @param loader the classloader to use * @throws BuildException This is the fit that is thrown if className * isn't an instance of JavahAdapter. */ private static JavahAdapter resolveClassName(String className, ClassLoader loader) throws BuildException { return ClasspathUtils.newInstance(className, loader != null ? loader : JavahAdapterFactory.class.getClassLoader(), JavahAdapter.class); } }
/** * Finds or creates the classloader for this object. * @return The class loader. */ public ClassLoader getClassLoader() { return getClassLoaderForPath(getContextProject(), classpath, getClassLoadId(), reverseLoader, loaderId != null || isMagicPropertySet(getContextProject())); }
/** * Tries to resolve the given classname into a rmic adapter. * Throws a fit if it can't. * * @param className The fully qualified classname to be created. * @param loader the classloader to use * @throws BuildException This is the fit that is thrown if className * isn't an instance of RmicAdapter. */ private static RmicAdapter resolveClassName(String className, ClassLoader loader) throws BuildException { return ClasspathUtils.newInstance(className, loader != null ? loader : RmicAdapterFactory.class.getClassLoader(), RmicAdapter.class); } }
} else if ("classloaderforpath".equalsIgnoreCase(name)) { this.value = ClasspathUtils.getClassLoaderForPath(getProject(), new Reference(getProject(), value));
/** * Tries to resolve the given classname into a native2ascii adapter. * Throws a fit if it can't. * * @param className The fully qualified classname to be created. * @param loader the classloader to use * @throws BuildException This is the fit that is thrown if className * isn't an instance of Native2AsciiAdapter. */ private static Native2AsciiAdapter resolveClassName(String className, ClassLoader loader) throws BuildException { return ClasspathUtils.newInstance(className, loader != null ? loader : Native2AsciiAdapterFactory.class.getClassLoader(), Native2AsciiAdapter.class); }
/** Configures the classpath which we'll use to load service classes. */ public void setClasspathref (Reference pathref) { _cloader = ClasspathUtils.getClassLoaderForPath(getProject(), pathref); // set the parent of the classloader to be the classloader used to load this task, rather // than the classloader used to load Ant, so that we have access to Narya classes like // TransportHint ((AntClassLoader)_cloader).setParent(getClass().getClassLoader()); }
/** * Tries to resolve the given classname into a compiler adapter. * Throws a fit if it can't. * * @param className The fully qualified classname to be created. * @param loader the classloader to use * @throws BuildException This is the fit that is thrown if className * isn't an instance of CompilerAdapter. */ private static CompilerAdapter resolveClassName(String className, ClassLoader loader) throws BuildException { return ClasspathUtils.newInstance(className, loader != null ? loader : CompilerAdapterFactory.class.getClassLoader(), CompilerAdapter.class); }
/** Configures the classpath which we'll use to load service classes. */ public void setClasspath (Path path) { _cloader = ClasspathUtils.getClassLoaderForPath(getProject(), path, "narya"); // set the parent of the classloader to be the classloader used to load this task, rather // than the classloader used to load Ant, so that we have access to Narya classes like // TransportHint ((AntClassLoader)_cloader).setParent(getClass().getClassLoader()); }
/** * Helper method obtaining a fresh instance of the class specified * in the @classname and using the specified classpath. * * @return the fresh instantiated object. */ public Object newInstance() { return ClasspathUtils.newInstance(this.className, getClassLoader()); }
/** * Adds the listeners specified in the command line arguments, * along with the default listener, to the specified project. * * @param project The project to add listeners to. * Must not be <code>null</code>. */ protected void addBuildListeners(final Project project) { // Add the default listener project.addBuildListener(createLogger()); final int count = listeners.size(); for (int i = 0; i < count; i++) { final String className = listeners.elementAt(i); final BuildListener listener = ClasspathUtils.newInstance(className, Main.class.getClassLoader(), BuildListener.class); project.setProjectReference(listener); project.addBuildListener(listener); } }