/** * Returns and initializes the classloader for this class. * @return the classloader */ public ClassLoader getClassLoader() { if (myClassLoader == null) { myClassLoader = (classpath == null) // the usual classloader ? getClass().getClassLoader() // additional use the provided classpath // Memory leak in line below : getProject().createClassLoader(classpath); } return myClassLoader; }
/** * Gets the Class object associated with the mapper implementation. * @return <code>Class</code>. * @throws ClassNotFoundException if the class cannot be found */ protected Class<? extends FileNameMapper> getImplementationClass() throws ClassNotFoundException { String cName = this.classname; if (type != null) { cName = type.getImplementation(); } ClassLoader loader = (classpath == null) ? getClass().getClassLoader() // Memory leak in line below : getProject().createClassLoader(classpath); return Class.forName(cName, true, loader).asSubclass(FileNameMapper.class); }
/** * If a custom classpath has been defined but no loader created * yet, create the classloader and set it as the context * classloader. */ private void setupLoader() { if (classpath != null && loader == null) { loader = getProject().createClassLoader(classpath); loader.setThreadContextLoader(); } }
/** * Returns a Classloader object which parses the passed in generic EjbJar classpath. * The loader is used to dynamically load classes from javax.ejb.* and the classes * being added to the jar. * @return a classloader. */ protected ClassLoader getClassLoaderForBuild() { if (classpathLoader != null) { return classpathLoader; } Path combinedClasspath = getCombinedClasspath(); // only generate a new ClassLoader if we have a classpath if (combinedClasspath == null) { classpathLoader = getClass().getClassLoader(); } else { // Memory leak in line below classpathLoader = getTask().getProject().createClassLoader(combinedClasspath); } return classpathLoader; }
/** * Gets a fresh, different, previously unused classloader that uses the * passed path as its classpath. * * <p>This method completely ignores the ant.reuse.loader magic * property and should be used with caution.</p> * @param p Ant Project where the handled components are living in. * @param path the classpath for this loader * @param reverseLoader if set to true this new loader will take * precedence over its parent (which is contra the regular * classloader behaviour) * @return The fresh, different, previously unused class loader. */ public static ClassLoader getUniqueClassLoaderForPath(Project p, Path path, boolean reverseLoader) { AntClassLoader acl = p.createClassLoader(path); if (reverseLoader) { acl.setParentFirst(false); acl.addJavaLibraries(); } return acl; }
/** * Based on the parameter passed in, this method creates the necessary * factory desired. * * The current mapping for compiler names are as follows: * <ul><li>jasper = jasper compiler (the default) * <li><i>a fully qualified classname</i> = the name of a jsp compiler * adapter * </ul> * * @param compilerType either the name of the desired compiler, or the * full classname of the compiler's adapter. * @param task a task to log through. * @return the compiler * @throws BuildException if the compiler type could not be resolved into * a compiler adapter. */ public static JspCompilerAdapter getCompiler(String compilerType, Task task) throws BuildException { return getCompiler(compilerType, task, // Memory-Leak in line below task.getProject().createClassLoader(null)); }
/** * @since Ant 1.6.2 */ private boolean isTomcat5x() { try (AntClassLoader l = getProject().createClassLoader(getClasspath())) { l.loadClass("org.apache.jasper.tagplugins.jstl.If"); return true; } catch (ClassNotFoundException e) { return false; } } }
readerLoader = getProject().createClassLoader(classpath); readerClass = Class.forName(readerClassName, true, readerLoader);
try { if (ignoreSystemClasses) { loader = getProject().createClassLoader(classpath); loader.setParentFirst(false); loader.addJavaLibraries();
= getProject().createClassLoader(classpath); c = Class.forName(classname, true, al);
if (classpath != null) { cleanup = true; cL = getProject().createClassLoader(classpath); } else { cL = this.getClass().getClassLoader();
try { if (ignoreSystemclasses) { loader = getProject().createClassLoader(classpath); loader.setParentFirst(false); loader.addJavaLibraries();
.createClassLoader(classpath));
.createClassLoader(classpath));
/** * Utility method to lookup a ResourceLocation in the classpath. * * @return An InputSource for reading the resource, or <code>null</code> * if the resource does not exist in the classpath or is not readable. */ private InputSource classpathLookup(ResourceLocation matchingEntry) { InputSource source = null; Path cp = classpath; if (cp != null) { cp = classpath.concatSystemClasspath("ignore"); } else { cp = (new Path(getProject())).concatSystemClasspath("last"); } AntClassLoader loader = getProject().createClassLoader(cp); // // for classpath lookup we ignore the base directory // InputStream is = loader.getResourceAsStream(matchingEntry.getLocation()); if (is != null) { source = new InputSource(is); URL entryURL = loader.getResource(matchingEntry.getLocation()); String sysid = entryURL.toExternalForm(); source.setSystemId(sysid); log("catalog entry matched a resource in the classpath: '" + sysid + "'", Project.MSG_DEBUG); } return source; }
} else { loader = getRmic().getProject().createClassLoader(getRmic().getClasspath()); c = Class.forName(WLRMIC_CLASSNAME, true, loader);
/** * Helper method invoked by isRebuildRequired to get a ClassLoader for a * Jar File passed to it. * * @param classjar java.io.File representing jar file to get classes from. * @return the classloader for the jarfile. * @throws IOException if there is a problem. */ protected ClassLoader getClassLoaderFromJar(File classjar) throws IOException { Path lookupPath = new Path(getTask().getProject()); lookupPath.setLocation(classjar); Path classpath = getCombinedClasspath(); if (classpath != null) { lookupPath.append(classpath); } return getTask().getProject().createClassLoader(lookupPath); } }
/** * Helper method invoked by isRebuildRequired to get a ClassLoader for a * Jar File passed to it. * * @param classjar java.io.File representing jar file to get classes from. * @return a classloader for the jar file. * @throws IOException if there is an error. */ protected ClassLoader getClassLoaderFromJar(File classjar) throws IOException { Path lookupPath = new Path(getTask().getProject()); lookupPath.setLocation(classjar); Path classpath = getCombinedClasspath(); if (classpath != null) { lookupPath.append(classpath); } return getTask().getProject().createClassLoader(lookupPath); } }
Path p = getClasspath().concatSystemClasspath("ignore"); if (parentFirst) { cl = getProject().createClassLoader(p); } else { cl = AntClassLoader.newAntClassLoader(getProject()
+ classpath.toString(), Project.MSG_VERBOSE); try (AntClassLoader cl = classpath.getProject().createClassLoader(classpath)) {