Package org.apache.tools.ant

Examples of org.apache.tools.ant.AntClassLoader


        }
        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 && !urlEquals(current, 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


                                     getLocation());
        }

        File dest = getActualDestDir();

        AntClassLoader al = null;
        try {
            //bind to a compiler
            JspCompilerAdapter compiler =
                JspCompilerAdapterFactory
                .getCompiler(compilerName, this,
                             al = getProject().createClassLoader(compilerClasspath));

            //if we are a webapp, hand off to the compiler, which had
            //better handle it
            if (webApp != null) {
                doCompilation(compiler);
                return;
            }

            // make sure that we've got a srcdir
            if (src == null) {
                throw new BuildException("srcdir attribute must be set!",
                                         getLocation());
            }
            String [] list = src.list();
            if (list.length == 0) {
                throw new BuildException("srcdir attribute must be set!",
                                         getLocation());
            }


            // if the compiler does its own dependency stuff, we just
            // call it right now
            if (compiler.implementsOwnDependencyChecking()) {
                doCompilation(compiler);
                return;
            }

            //the remainder of this method is only for compilers that
            //need their dependency work done
            JspMangler mangler = compiler.createMangler();

            // scan source directories and dest directory to build up both copy
            // lists and compile lists
            resetFileLists();
            int filecount = 0;
            for (int i = 0; i < list.length; i++) {
                File srcDir = getProject().resolveFile(list[i]);
                if (!srcDir.exists()) {
                    throw new BuildException("srcdir \"" + srcDir.getPath()
                                             + "\" does not exist!",
                                             getLocation());
                }
                DirectoryScanner ds = this.getDirectoryScanner(srcDir);
                String[] files = ds.getIncludedFiles();
                filecount = files.length;
                scanDir(srcDir, dest, mangler, files);
            }

            // compile the source files

            log("compiling " + compileList.size() + " files",
                Project.MSG_VERBOSE);

            if (compileList.size() > 0) {

                log("Compiling " + compileList.size() + " source file"
                    + (compileList.size() == 1 ? "" : "s")
                    + " to "
                    + dest);
                doCompilation(compiler);

            } else {
                if (filecount == 0) {
                    log("there were no files to compile", Project.MSG_INFO);
                } else {
                    log("all files are up to date", Project.MSG_VERBOSE);
                }
            }
        } finally {
            if (al != null) {
                al.cleanup();
            }
        }
    }
View Full Code Here

                    rebuild = true;
                }
            }
            if (genericLoader != null
                && genericLoader instanceof AntClassLoader) {
                AntClassLoader loader = (AntClassLoader) genericLoader;
                loader.cleanup();
            }
        }

        return rebuild;
    }
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(WLRMIC_CLASSNAME);
            } else {
                loader
                    = getRmic().getProject().createClassLoader(getRmic().getClasspath());
                c = Class.forName(WLRMIC_CLASSNAME, 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(ERROR_NO_WLRMIC_ON_CLASSPATH, getRmic().getLocation());
        } catch (Exception ex) {
            if (ex instanceof BuildException) {
                throw (BuildException) ex;
            } else {
                throw new BuildException(ERROR_WLRMIC_FAILED, ex,
                                         getRmic().getLocation());
            }
        } finally {
            if (loader != null) {
                loader.cleanup();
            }
        }
    }
View Full Code Here

          ;
        }
        /* Now try to load the Jakara regexp jar from a specified classpath */
        try {
          log("Loading RegexpMatcher from " + regexpClasspath, Project.MSG_DEBUG);
          AntClassLoader loader = new AntClassLoader(getProject(), regexpClasspath);
          Class implClass = loader.findClass(DEFAULT_REGEXP_CLASS);
          return (RegexpMatcher) implClass.newInstance();
        } catch (Throwable t) {
          throw new BuildException(t);
        }
    }
View Full Code Here

                //
                // I think there is no real need for creating an additional
                // AntClassLoader
                // CocoonTask was already loaded via an AntClassLoader by Ant
                //
                AntClassLoader antClassLoader = new AntClassLoader(this.project, this.cocoonClasspath, false);

                log("Using Class Loader having classpath " + String.valueOf(this.cocoonClasspath), Project.MSG_INFO);
                classLoader = antClassLoader;
            } else {
                classLoader = this.getClass().getClassLoader();
View Full Code Here

    }
   
    public void execute(CommandlineJava command) throws BuildException {
        final String classname = command.getJavaCommand().getExecutable();

        AntClassLoader loader = null;
        try {
            if (command.getSystemProperties() != null) {
                command.getSystemProperties().setSystem();
            }

            final Class[] param = {Class.forName("org.w3c.dom.Document"), Class.forName("java.lang.String")};
            Class target = null;
            if (command.getClasspath() == null) {
                target = Class.forName(classname);
            } else {
                loader = new AntClassLoader(getProject().getCoreLoader(), getProject(),
                                            command.getClasspath(), false);
                loader.setIsolated(true);
                loader.setThreadContextLoader();
                target = loader.forceLoadClass(classname);
                Class.forName(classname, true, loader);
            }
            Method method = target.getMethod("process", param);
            if (method == null) {
                throw new BuildException("Could not find process() method in "
                                         + classname);
            }

            run(method);

            if (caught != null) {
                throw caught;
            }

        } catch (ClassNotFoundException e) {
            throw new BuildException("Could not find " + classname + "."
                                     + " Make sure you have it in your"
                                     + " classpath");
        } catch (SecurityException e) {
            throw e;
        } catch (Throwable e) {
            throw new BuildException(e);
        } finally {
            if (loader != null) {
                loader.resetThreadContextLoader();
                loader.cleanup();
            }
            if (command.getSystemProperties() != null) {
                command.getSystemProperties().restoreSystem();
            }
        }
View Full Code Here

  private boolean failOnMissingClasses = true;
  private boolean ignoreEmptyFileset = false;
   
  @Override
  public void execute() throws BuildException {
    AntClassLoader antLoader = null;
    try {
      final ClassLoader loader;
      if (classpath != null) {
        classpath.setProject(getProject());
        loader = antLoader = getProject().createClassLoader(ClassLoader.getSystemClassLoader(), classpath);
        antLoader.setParentFirst(true); // use default classloader delegation
      } else {
        loader = ClassLoader.getSystemClassLoader();
      }
      classFiles.setProject(getProject());
      apiSignatures.setProject(getProject());
     
      final Checker checker = new Checker(loader, internalRuntimeForbidden, failOnMissingClasses, true) {
        @Override
        protected void logError(String msg) {
          log(msg, Project.MSG_ERR);
        }
       
        @Override
        protected void logWarn(String msg) {
          // ANT has no real log levels printed, so prefix with "WARNING":
          log("WARNING: " + msg, Project.MSG_WARN);
        }
       
        @Override
        protected void logInfo(String msg) {
          log(msg, Project.MSG_INFO);
        }
      };
     
      if (!checker.isSupportedJDK) {
        final String msg = String.format(Locale.ENGLISH,
          "Your Java runtime (%s %s) is not supported by <%s/>. Please run the checks with a supported JDK!",
          System.getProperty("java.runtime.name"), System.getProperty("java.runtime.version"), getTaskName());
        if (failOnUnsupportedJava) {
          throw new BuildException(msg);
        } else {
          log("WARNING: " + msg, Project.MSG_WARN);
          return;
        }
      }
     
      try {
        for (BundledSignaturesType bs : bundledSignatures) {
          final String name = bs.getName();
          if (name == null) {
            throw new BuildException("<bundledSignatures/> must have the mandatory attribute 'name' referring to a bundled signatures file.");
          }
          log("Reading bundled API signatures: " + name, Project.MSG_INFO);
          checker.parseBundledSignatures(name, null);
        }
       
        @SuppressWarnings("unchecked")
        final Iterator<Resource> iter = (Iterator<Resource>) apiSignatures.iterator();
        while (iter.hasNext()) {
          final Resource r = iter.next();
          if (r instanceof StringResource) {
            final String s = ((StringResource) r).getValue();
            if (s != null && s.trim().length() > 0) {
              log("Reading inline API signatures...", Project.MSG_INFO);
              checker.parseSignaturesString(s);
            }
          } else {
            log("Reading API signatures: " + r, Project.MSG_INFO);
            checker.parseSignaturesFile(r.getInputStream());
          }
        }
      } catch (IOException ioe) {
        throw new BuildException("IO problem while reading files with API signatures: " + ioe);
      } catch (ParseException pe) {
        throw new BuildException("Parsing signatures failed: " + pe.getMessage());
      }
       
      if (checker.hasNoSignatures()) {
        throw new BuildException("No API signatures found; use signaturesFile=, <signaturesFileSet/>, <bundledSignatures/> or inner text to define those!");
      }

      log("Loading classes to check...", Project.MSG_INFO);
      try {
        @SuppressWarnings("unchecked")
        final Iterator<Resource> iter = (Iterator<Resource>) classFiles.iterator();
        boolean foundClass = false;
        while (iter.hasNext()) {
          final Resource r = iter.next();
          final String name = r.getName();
          if (restrictClassFilename && name != null && !name.endsWith(".class")) {
            continue;
          }
          checker.addClassToCheck(r.getInputStream());
          foundClass = true;
        }
        if (!foundClass) {
          if (ignoreEmptyFileset) {
            log("There is no <fileset/> or other resource collection given, or the collection does not contain any class files to check.", Project.MSG_WARN);
            log("Scanned 0 class files.", Project.MSG_INFO);
            return;
          } else {
            throw new BuildException("There is no <fileset/> or other resource collection given, or the collection does not contain any class files to check.");
          }
        }
      } catch (IOException ioe) {
        throw new BuildException("Failed to load one of the given class files: " + ioe);
      }

      log("Scanning for API signatures and dependencies...", Project.MSG_INFO);
      try {
        checker.run();
      } catch (ForbiddenApiException fae) {
        throw new BuildException(fae.getMessage());
      }
    } finally {
      if (antLoader != null) antLoader.cleanup();
    }
  }
View Full Code Here


    protected GroovyClassLoader buildClassLoaderFor() {
        ClassLoader parent = getIncludeantruntime()
                ? getClass().getClassLoader()
                : new AntClassLoader(new RootLoader(new URL[0], null), getProject(), getClasspath());
        if (parent instanceof AntClassLoader) {
            AntClassLoader antLoader = (AntClassLoader) parent;
            String[] pathElm = antLoader.getClasspath().split(File.pathSeparator);
            List<String> classpath = configuration.getClasspath();
            /*
             * Iterate over the classpath provided to groovyc, and add any missing path
             * entries to the AntClassLoader.  This is a workaround, since for some reason
             * 'directory' classpath entries were not added to the AntClassLoader' classpath.
             */
            for (String cpEntry : classpath) {
                boolean found = false;
                for (String path : pathElm) {
                    if (cpEntry.equals(path)) {
                        found = true;
                        break;
                    }
                }
                /*
                 * fix for GROOVY-2284
                 * seems like AntClassLoader doesn't check if the file
                 * may not exist in the classpath yet
                 */
                if (!found && new File(cpEntry).exists())
                    antLoader.addPathElement(cpEntry);
            }
        }

        GroovyClassLoader loader = new GroovyClassLoader(parent, configuration);
        // in command line we don't need to do script lookups
View Full Code Here

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

        /*
         * If the user gave us a velPropClass, we create an instance
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.