Package org.apache.tools.ant

Examples of org.apache.tools.ant.AntClassLoader


     */
    private CatalogResolver getCatalogResolver() {

        if (catalogResolver == null) {

            AntClassLoader loader = null;

            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

    public boolean execute() throws BuildException {
        getRmic().log("Using WebLogic rmic", Project.MSG_VERBOSE);
        Commandline cmd = setupRmicCommand(new String[] {"-noexit"});

        AntClassLoader loader = null;
        try {
            // Create an instance of the rmic
            Class c = null;
            if (getRmic().getClasspath() == null) {
                c = Class.forName("weblogic.rmic");
            } else {
                loader
                    = getRmic().getProject().createClassLoader(getRmic().getClasspath());
                c = Class.forName("weblogic.rmic", true, loader);
            }
            Method doRmic = c.getMethod("main",
                                        new Class [] {String[].class});
            doRmic.invoke(null, new Object[] {cmd.getArguments()});
            return true;
        } catch (ClassNotFoundException ex) {
            throw new BuildException("Cannot use WebLogic rmic, as it is not "
                                     + "available.  A common solution is to "
                                     + "set the environment variable "
                                     + "CLASSPATH.", getRmic().getLocation());
        } catch (Exception ex) {
            if (ex instanceof BuildException) {
                throw (BuildException) ex;
            } else {
                throw new BuildException("Error starting WebLogic rmic: ", ex,
                                         getRmic().getLocation());
            }
        } finally {
            if (loader != null) {
                loader.cleanup();
            }
        }
    }
View Full Code Here

        classpathDependencies = null;
        Path checkPath = getCheckClassPath();
        if (checkPath != null) {
            // now determine which jars each class depends upon
            classpathDependencies = new Hashtable();
            AntClassLoader loader = getProject().createClassLoader(checkPath);

            Hashtable classpathFileCache = new Hashtable();
            Object nullFileMarker = new Object();
            for (Enumeration e = dependencyMap.keys(); e.hasMoreElements();) {
                String className = (String) e.nextElement();
                Vector dependencyList = (Vector) dependencyMap.get(className);
                Hashtable dependencies = new Hashtable();
                classpathDependencies.put(className, dependencies);
                Enumeration e2 = dependencyList.elements();
                while (e2.hasMoreElements()) {
                    String dependency = (String) e2.nextElement();
                    Object classpathFileObject
                        = classpathFileCache.get(dependency);
                    if (classpathFileObject == null) {
                        classpathFileObject = nullFileMarker;

                        if (!dependency.startsWith("java.")
                            && !dependency.startsWith("javax.")) {
                            URL classURL
                                = loader.getResource(dependency.replace('.', '/') + ".class");
                            if (classURL != null) {
                                if (classURL.getProtocol().equals("jar")) {
                                    String jarFilePath = classURL.getFile();
                                    if (jarFilePath.startsWith("file:")) {
                                        int classMarker = jarFilePath.indexOf('!');
View Full Code Here

    String getGenicClassName(Path classpath) {

        log("Looking for GenIC class in classpath: "
            + classpath.toString(), Project.MSG_VERBOSE);

        AntClassLoader cl = classpath.getProject().createClassLoader(classpath);

        try {
            cl.loadClass(JonasDeploymentTool.GENIC_CLASS);
            log("Found GenIC class '" + JonasDeploymentTool.GENIC_CLASS
                + "' in classpath.", Project.MSG_VERBOSE);
            return JonasDeploymentTool.GENIC_CLASS;

        } catch (ClassNotFoundException cnf1) {
            log("GenIC class '" + JonasDeploymentTool.GENIC_CLASS
                + "' not found in classpath.",
            Project.MSG_VERBOSE);
        }

        try {
            cl.loadClass(JonasDeploymentTool.OLD_GENIC_CLASS_1);
            log("Found GenIC class '" + JonasDeploymentTool.OLD_GENIC_CLASS_1
                + "' in classpath.", Project.MSG_VERBOSE);
            return JonasDeploymentTool.OLD_GENIC_CLASS_1;

        } catch (ClassNotFoundException cnf2) {
            log("GenIC class '" + JonasDeploymentTool.OLD_GENIC_CLASS_1
                + "' not found in classpath.",
            Project.MSG_VERBOSE);
        }

        try {
            cl.loadClass(JonasDeploymentTool.OLD_GENIC_CLASS_2);
            log("Found GenIC class '" + JonasDeploymentTool.OLD_GENIC_CLASS_2
                + "' in classpath.", Project.MSG_VERBOSE);
            return JonasDeploymentTool.OLD_GENIC_CLASS_2;

        } catch (ClassNotFoundException cnf3) {
View Full Code Here

        project.getProperty(null);
        ctrl.setMatcher(MockControl.ALWAYS_MATCHER);
        ctrl.setReturnValue("foo", 6);
        project.createClassLoader(null);
        ctrl.setMatcher(MockControl.ALWAYS_MATCHER);
        ctrl.setReturnValue(new AntClassLoader(new Echo().getClass().getClassLoader(), false));

        IncludeTask task = new IncludeTask();
        task.setProject(project);

        ctrl.replay();
View Full Code Here

        }
        forkedPathChecked = true;
        if (!cmd.haveClasspath()) {
            return;
        }
        AntClassLoader loader = null;
        try {
            loader =
                AntClassLoader.newAntClassLoader(null, getProject(),
                                                 cmd.createClasspath(getProject()),
                                                 true);
            String projectResourceName =
                LoaderUtils.classNameToResource(Project.class.getName());
            URL previous = null;
            try {
                for (Enumeration e = loader.getResources(projectResourceName);
                     e.hasMoreElements();) {
                    URL current = (URL) e.nextElement();
                    if (previous != null && !current.equals(previous)) {
                        log("WARNING: multiple versions of ant detected "
                            + "in path for junit "
                            + LINE_SEP + "         " + previous
                            + LINE_SEP + "     and " + current,
                            Project.MSG_WARN);
                        return;
                    }
                    previous = current;
                }
            } catch (Exception ex) {
                // Ignore exception
            }
        } finally {
            if (loader != null) {
                loader.cleanup();
            }
        }
    }
View Full Code Here

         *  Create a new Classloader for loading the Toolbox and the Velocity
         *  properties class.
         */
        if (classpath != null)
        {
            classLoader = new AntClassLoader(getProject(), classpath);
            dvsl.setClassLoader(classLoader);
        }

        /*
         * If the user gave us a velPropClass, we create an instance
View Full Code Here

             * This needs the ClassLoader we use to load the task have all the dependancyies set, hope that
             * is ok for now
             */
           
           
            AntClassLoader cl = new AntClassLoader(
                                    null,
                                    getProject(),
                                    classpath,
                                    false);
           
            Thread.currentThread().setContextClassLoader(cl);
            cl.addPathElement(output);
            System.out.println("path is "+cl.getClasspath());   

            Map commandLineOptions = this.fillOptionMap();
            CommandLineOptionParser parser =
                new CommandLineOptionParser(commandLineOptions);
            new CodeGenerationEngine(parser).generate();
View Full Code Here

     * @throws BuildException on error.
     */
    public void execute(Project project) throws BuildException {
        final String classname = javaCommand.getExecutable();

        AntClassLoader loader = null;
        try {
            if (sysProperties != null) {
                sysProperties.setSystem();
            }
            Class<?> target = null;
            try {
                if (classpath == null) {
                    target = Class.forName(classname);
                } else {
                    loader = project.createClassLoader(classpath);
                    loader.setParent(project.getCoreLoader());
                    loader.setParentFirst(false);
                    loader.addJavaLibraries();
                    loader.setIsolated(true);
                    loader.setThreadContextLoader();
                    loader.forceLoadClass(classname);
                    target = Class.forName(classname, true, loader);
                }
            } catch (ClassNotFoundException e) {
                throw new BuildException("Could not find " + classname + "."
                                         + " Make sure you have it in your"
                                         + " classpath");
            }
            main = target.getMethod("main", new Class[] {String[].class});
            if (main == null) {
                throw new BuildException("Could not find main() method in "
                                         + classname);
            }
            if ((main.getModifiers() & Modifier.STATIC) == 0) {
                throw new BuildException("main() method in " + classname
                    + " is not declared static");
            }
            if (timeout == null) {
                run();
            } else {
                thread = new Thread(this, "ExecuteJava");
                Task currentThreadTask
                    = project.getThreadTask(Thread.currentThread());
                // TODO is the following really necessary? it is in the same thread group...
                project.registerThreadTask(thread, currentThreadTask);
                // if we run into a timeout, the run-away thread shall not
                // make the VM run forever - if no timeout occurs, Ant's
                // main thread will still be there to let the new thread
                // finish
                thread.setDaemon(true);
                Watchdog w = new Watchdog(timeout.longValue());
                w.addTimeoutObserver(this);
                synchronized (this) {
                    thread.start();
                    w.start();
                    try {
                        wait();
                    } catch (InterruptedException e) {
                        // ignore
                    }
                    if (timedOut) {
                        project.log("Timeout: sub-process interrupted",
                                    Project.MSG_WARN);
                    } else {
                        thread = null;
                        w.stop();
                    }
                }
            }
            if (caught != null) {
                throw caught;
            }
        } catch (BuildException e) {
            throw e;
        } catch (SecurityException e) {
            throw e;
        } catch (ThreadDeath e) {
            // TODO could perhaps also call thread.stop(); not sure if anyone cares
            throw e;
        } catch (Throwable e) {
            throw new BuildException(e);
        } finally {
            if (loader != null) {
                loader.resetThreadContextLoader();
                loader.cleanup();
                loader = null;
            }
            if (sysProperties != null) {
                sysProperties.restoreSystem();
            }
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.