Package org.apache.tools.ant

Examples of org.apache.tools.ant.AntClassLoader


            try {
                Class<?> clazz = null;
                if (classpath == null) {
                    clazz = Class.forName(className);
                } else {
                    AntClassLoader al = pro.createClassLoader(classpath);
                    classLoadersToCleanUp.add(al);
                    clazz = Class.forName(className, true, al);
                }
                if (clazz != null) {
                    if (!FilterReader.class.isAssignableFrom(clazz)) {
View Full Code Here


     * @see <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=46752">
     *     https://issues.apache.org/bugzilla/show_bug.cgi?id=46752</a>
     */
    @Test
    public void testGetResources() throws IOException {
        AntClassLoader acl = new AntClassLoader5(new EmptyLoader(), null,
                                                 new Path(null), true);
        assertNull(acl.getResource("META-INF/MANIFEST.MF"));
        assertFalse(acl.getResources("META-INF/MANIFEST.MF").hasMoreElements());

        // double check using system classloader as parent
        acl = new AntClassLoader5(null, null, new Path(null), true);
        assertNotNull(acl.getResource("META-INF/MANIFEST.MF"));
        assertTrue(acl.getResources("META-INF/MANIFEST.MF").hasMoreElements());
    }
View Full Code Here

        assertTrue(acl.getResources("META-INF/MANIFEST.MF").hasMoreElements());
    }

    @Test
    public void testGetResourcesUsingFactory() throws IOException {
        AntClassLoader acl =
            AntClassLoader.newAntClassLoader(new EmptyLoader(), null,
                                             new Path(null), true);
        assertNull(acl.getResource("META-INF/MANIFEST.MF"));
        assertFalse(acl.getResources("META-INF/MANIFEST.MF").hasMoreElements());
    }
View Full Code Here

                log("Referenced object is not an AntClassLoader",
                        Project.MSG_ERR);
                return;
            }

            AntClassLoader acl = (AntClassLoader) obj;
            boolean existingLoader = acl != null;

            if (acl == null) {
                // Construct a new class loader
                Object parent = null;
                if (parentName != null) {
                    parent = getProject().getReference(parentName);
                    if (!(parent instanceof ClassLoader)) {
                        parent = null;
                    }
                }
                // TODO: allow user to request the system or no parent
                if (parent == null) {
                    parent = this.getClass().getClassLoader();
                }

                if (name == null) {
                    // The core loader must be reverse
                    //reverse=true;
                }
                getProject().log("Setting parent loader " + name + " "
                    + parent + " " + parentFirst, Project.MSG_DEBUG);

                // The param is "parentFirst"
                acl = AntClassLoader.newAntClassLoader((ClassLoader) parent,
                         getProject(), classpath, parentFirst);

                getProject().addReference(loaderName, acl);

                if (name == null) {
                    // This allows the core loader to load optional tasks
                    // without delegating
                    acl.addLoaderPackageRoot("org.apache.tools.ant.taskdefs.optional");
                    getProject().setCoreLoader(acl);
                }
            }

            if (existingLoader && classpath != null) {
                String[] list = classpath.list();
                for (int i = 0; i < list.length; i++) {
                    File f = new File(list[i]);
                    if (f.exists()) {
                        log("Adding to class loader " +  acl + " " + f.getAbsolutePath(),
                                Project.MSG_DEBUG);
                        acl.addPathElement(f.getAbsolutePath());
                    }
                }
            }

            // TODO add exceptions
View Full Code Here

                Class<?> c = null;
                if (classpath == null) {
                    c = Class.forName(classname);
                } else {
                    // Memory-Leak in line below
                    AntClassLoader al
                            = getProject().createClassLoader(classpath);
                    c = Class.forName(classname, true, al);
                }
                dynselector = c.asSubclass(FileSelector.class).newInstance();
                final Project p = getProject();
View Full Code Here

     */
    private CatalogResolver getCatalogResolver() {

        if (catalogResolver == null) {

            AntClassLoader loader = null;
            // Memory-Leak in line below
            loader = getProject().createClassLoader(Path.systemClasspath);

            try {
                Class<?> clazz = Class.forName(APACHE_RESOLVER, true, loader);
View Full Code Here

     */
    private InputSource classpathLookup(ResourceLocation matchingEntry) {

        InputSource source = null;

        AntClassLoader loader = null;
        Path cp = classpath;
        if (cp != null) {
            cp = classpath.concatSystemClasspath("ignore");
        } else {
            cp = (new Path(getProject())).concatSystemClasspath("last");
        }
        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);
        }
View Full Code Here

  private void setContextClassLoader() {
        if(classpath == null) {
            String cp = ((AntClassLoader) getClass().getClassLoader()).getClasspath();
            classpath = new Path(getProject(),cp);
        }
        AntClassLoader classloader = new AntClassLoader(getProject(),classpath,true);
        Thread.currentThread().setContextClassLoader(classloader);
    }
View Full Code Here

    public void execute() throws BuildException {
        if (taskClasspath==null || taskClasspath.size()==0) {
            throw new BuildException("no classpath given");
        }
        Project project = getProject();
        AntClassLoader loader = new AntClassLoader(makeRoot(),true);
        project.addReference(name,loader);
    }
View Full Code Here

        if (count > 0) {
            log("Generating " + count + " prox" + (count > 1 ? "ies" : "y")
                + " to " + _base, Project.MSG_INFO);

            Path classpath = getCompileClasspath();
            AntClassLoader loader = new AntClassLoader(project, classpath);

            for (int i = 0; i < count; ++i) {
                generate(generateList[i], loader);
            }
View Full Code Here

TOP

Related Classes of org.apache.tools.ant.AntClassLoader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.