Return-Path: Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 30786 invoked from network); 3 Feb 2000 23:11:00 -0000 Received: from postfix3.free.fr (postfix@212.27.32.22) by locus.apache.org with SMTP; 3 Feb 2000 23:11:00 -0000 Received: from slawek (unknown [213.228.47.157]) by postfix3.free.fr (Postfix) with SMTP id EDF4286CE1; Fri, 4 Feb 2000 00:10:53 +0100 (CET) Message-ID: <000d01bf6e9c$1d57a560$9d2fe4d5@zachcial> From: "Slawek Zachcial" To: "Slawek (HP)" , Subject: Javadoc problems : some findings Date: Fri, 4 Feb 2000 00:11:21 +0100 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_000A_01BF6EA4.5DBFB540" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.00.2314.1300 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 This is a multi-part message in MIME format. ------=_NextPart_000_000A_01BF6EA4.5DBFB540 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hello "ANT-ers" ! I got ANT from http://jakarta.apache.org/from-cvs/jakarta-tools and tried to use Javadoc2 task (jakarta-tools_20000203111218.tar.gz). For me this task does simply noting. So I looked a little bit at it and that's what I found: 1. Javadoc2's getFiles function constructs incorrectly "cwd" local variable. 2. File names instead of File objects are put on the list in this function. 3. JavaReader class is not able to skip comments like /** some_comments_here **/. 4. In Java's run function, InvocationTargetException's target exception can be other than "Exit not allowed" exception, ex: java.security.AccessControlException: access denied java.lang.RuntimePermission setContextClassLoader) 5. There are security problems with the usage of com.sun.tools.javadoc.Main class (as the one above). To make it work that's what I added to java.policy: permission java.lang.RuntimePermission "setContextClassLoader"; permission java.util.PropertyPermission "user.language", "write"; 6. But still javadoc tries to exit with System.exit which causes the handled "Exit not allowed" exception. Maybe the security issues can be resolved by AntSecurityManager ? I attach modified Javadoc2.java and Java.java. Lines to remove are commented with '//--' and added lines have at the end '//++'. Can anyone look at the changes and incorporate them if it's OK? Regards, Slawek PS. I'm using JDK 1.2.2 and JDK 1.3 beta on Windows NT ------=_NextPart_000_000A_01BF6EA4.5DBFB540 Content-Type: application/octet-stream; name="Javadoc2.java" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="Javadoc2.java" /*=0A= * The Apache Software License, Version 1.1=0A= *=0A= * Copyright (c) 1999 The Apache Software Foundation. All rights =0A= * reserved.=0A= *=0A= * Redistribution and use in source and binary forms, with or without=0A= * modification, are permitted provided that the following conditions=0A= * are met:=0A= *=0A= * 1. Redistributions of source code must retain the above copyright=0A= * notice, this list of conditions and the following disclaimer. =0A= *=0A= * 2. Redistributions in binary form must reproduce the above copyright=0A= * notice, this list of conditions and the following disclaimer in=0A= * the documentation and/or other materials provided with the=0A= * distribution.=0A= *=0A= * 3. The end-user documentation included with the redistribution, if=0A= * any, must include the following acknowlegement: =0A= * "This product includes software developed by the =0A= * Apache Software Foundation (http://www.apache.org/)."=0A= * Alternately, this acknowlegement may appear in the software itself,=0A= * if and wherever such third-party acknowlegements normally appear.=0A= *=0A= * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software=0A= * Foundation" must not be used to endorse or promote products derived=0A= * from this software without prior written permission. For written =0A= * permission, please contact apache@apache.org.=0A= *=0A= * 5. Products derived from this software may not be called "Apache"=0A= * nor may "Apache" appear in their names without prior written=0A= * permission of the Apache Group.=0A= *=0A= * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED=0A= * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES=0A= * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE=0A= * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR=0A= * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,=0A= * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT=0A= * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF=0A= * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND=0A= * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,=0A= * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT=0A= * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF=0A= * SUCH DAMAGE.=0A= * = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= *=0A= * This software consists of voluntary contributions made by many=0A= * individuals on behalf of the Apache Software Foundation. For more=0A= * information on the Apache Software Foundation, please see=0A= * .=0A= */=0A= =0A= package org.apache.tools.ant.taskdefs;=0A= =0A= import org.apache.tools.ant.*;=0A= =0A= import java.io.*;=0A= import java.util.*;=0A= =0A= /**=0A= * This Task makes it easy to generate javadocs for a collection of = source code.=0A= *=0A= * Current known limitations are:=0A= * - multiple source path breaks operation=0A= * - patterns must be of the form "xxx.*", every other pattern doesn't = work.=0A= * - the java comment-stripper reader is horribly slow=0A= * - stupid javadoc calls System.exit() and breaks Ant execution=0A= * (two solutions: security manager and decompilation for better = hooks)=0A= * - there is no control on arguments sanity since they are left=0A= * to the javadoc implementation.=0A= *=0A= * @author Jon S. Stevens jon@clearink.com=0A= * @author Stefano Mazzocchi stefano@apache.org=0A= */=0A= public class Javadoc2 extends Java {=0A= =0A= private String sourcePath =3D null;=0A= private File destDir =3D null;=0A= private File overviewFile =3D null;=0A= private String sourceFiles =3D null;=0A= private String packageNames =3D null;=0A= private boolean pub =3D false;=0A= private boolean prot =3D false;=0A= private boolean pack =3D false;=0A= private boolean priv =3D false;=0A= private boolean author =3D true;=0A= private boolean version =3D true;=0A= private String doclet =3D null;=0A= private File docletpath =3D null;=0A= private boolean old =3D false;=0A= private String classpath =3D null;=0A= private String bootclasspath =3D null;=0A= private String extdirs =3D null;=0A= private boolean verbose =3D false;=0A= private String locale =3D null;=0A= private String encoding =3D null;=0A= private boolean use =3D false;=0A= private boolean splitindex =3D false;=0A= private String windowtitle =3D null;=0A= private String doctitle =3D null;=0A= private String header =3D null;=0A= private String footer =3D null;=0A= private String bottom =3D null;=0A= private String link =3D null;=0A= private String linkoffline =3D null;=0A= private String group =3D null;=0A= private boolean nodeprecated =3D false;=0A= private boolean nodeprecatedlist =3D false;=0A= private boolean notree =3D false;=0A= private boolean noindex =3D false;=0A= private boolean nohelp =3D false;=0A= private boolean nonavbar =3D false;=0A= private File stylesheetfile =3D null;=0A= private File helpfile =3D null;=0A= private String docencoding =3D null;=0A= =0A= private Vector compileList =3D new Vector();=0A= =0A= public void setSourcepath(String src) {=0A= sourcePath =3D project.translatePath(src);=0A= }=0A= public void setDestdir(String src) {=0A= destDir =3D project.resolveFile(src);=0A= }=0A= public void setSourcefiles(String src) {=0A= sourceFiles =3D src;=0A= }=0A= public void setPackagenames(String src) {=0A= packageNames =3D src;=0A= }=0A= public void setOverview(String src) {=0A= overviewFile =3D project.resolveFile(src);=0A= }=0A= public void setPublic(String src) {=0A= pub =3D new Boolean(src).booleanValue();=0A= }=0A= public void setProtected(String src) {=0A= prot =3D new Boolean(src).booleanValue();=0A= }=0A= public void setPackage(String src) {=0A= pack =3D new Boolean(src).booleanValue();=0A= }=0A= public void setPrivate(String src) {=0A= priv =3D new Boolean(src).booleanValue();=0A= }=0A= public void setDoclet(String src) {=0A= doclet =3D src;=0A= }=0A= public void setDocletPath(String src) {=0A= docletpath =3D project.resolveFile(src);=0A= }=0A= public void setOld(String src) {=0A= old =3D new Boolean(src).booleanValue();=0A= }=0A= public void setClasspath(String src) {=0A= classpath =3D Project.translatePath(src);=0A= }=0A= public void setBootclasspath(String src) {=0A= bootclasspath =3D Project.translatePath(src);=0A= }=0A= public void setExtdirs(String src) {=0A= extdirs =3D src;=0A= }=0A= public void setVerbose(String src) {=0A= verbose =3D new Boolean(src).booleanValue();=0A= }=0A= public void setLocale(String src) {=0A= locale =3D src;=0A= }=0A= public void setEncoding(String src) {=0A= encoding =3D src;=0A= }=0A= public void setVersion(String src) {=0A= version =3D new Boolean(src).booleanValue();=0A= }=0A= public void setUse(String src) {=0A= use =3D new Boolean(src).booleanValue();=0A= }=0A= public void setAuthor(String src) {=0A= author =3D new Boolean(src).booleanValue();=0A= }=0A= public void setSplitindex(String src) {=0A= splitindex =3D new Boolean(src).booleanValue();=0A= }=0A= public void setWindowtitle(String src) {=0A= windowtitle =3D src;=0A= }=0A= public void setDoctitle(String src) {=0A= doctitle =3D src;=0A= }=0A= public void setHeader(String src) {=0A= header =3D src;=0A= }=0A= public void setFooter(String src) {=0A= footer =3D src;=0A= }=0A= public void setBottom(String src) {=0A= bottom =3D src;=0A= }=0A= public void setLink(String src) {=0A= link =3D src;=0A= }=0A= public void setLinkoffline(String src) {=0A= linkoffline =3D src;=0A= }=0A= public void setGroup(String src) {=0A= group =3D src;=0A= }=0A= public void setNodeprecated(String src) {=0A= nodeprecated =3D new Boolean(src).booleanValue();=0A= }=0A= public void setNodeprecatedlist(String src) {=0A= nodeprecatedlist =3D new Boolean(src).booleanValue();=0A= }=0A= public void setNotree(String src) {=0A= notree =3D new Boolean(src).booleanValue();=0A= }=0A= public void setNoindex(String src) {=0A= noindex =3D new Boolean(src).booleanValue();=0A= }=0A= public void setNohelp(String src) {=0A= nohelp =3D new Boolean(src).booleanValue();=0A= }=0A= public void setNonavbar(String src) {=0A= nonavbar =3D new Boolean(src).booleanValue();=0A= }=0A= public void setStylesheetfile(String src) {=0A= stylesheetfile =3D project.resolveFile(src);=0A= }=0A= public void setDocencoding(String src) {=0A= docencoding =3D src;=0A= }=0A= =0A= public void execute() throws BuildException {=0A= if (sourcePath =3D=3D null && destDir =3D=3D null ) {=0A= String msg =3D "sourcePath and destDir attributes must be = set!";=0A= throw new BuildException(msg);=0A= }=0A= =0A= project.log("Generating Javadoc", project.MSG_INFO);=0A= =0A= Vector argList =3D new Vector();=0A= =0A= if (overviewFile !=3D null) {=0A= argList.addElement("-overview");=0A= argList.addElement(overviewFile.getAbsolutePath());=0A= }=0A= if (pub)=0A= argList.addElement ("-public");=0A= if (prot)=0A= argList.addElement ("-protected");=0A= if (pack)=0A= argList.addElement ("-package");=0A= if (priv)=0A= argList.addElement ("-private");=0A= if (old)=0A= argList.addElement ("-1.1");=0A= if (verbose)=0A= argList.addElement ("-verbose");=0A= if (version)=0A= argList.addElement ("-version");=0A= if (use)=0A= argList.addElement ("-use");=0A= if (author)=0A= argList.addElement ("-author");=0A= if (splitindex)=0A= argList.addElement ("-splitindex");=0A= if (nodeprecated)=0A= argList.addElement ("-nodeprecated");=0A= if (nodeprecatedlist)=0A= argList.addElement ("-nodeprecatedlist");=0A= if (notree)=0A= argList.addElement ("-notree");=0A= if (noindex)=0A= argList.addElement ("-noindex");=0A= if (nohelp)=0A= argList.addElement ("-nohelp");=0A= if (nonavbar)=0A= argList.addElement ("-nonavbar");=0A= =0A= if (doclet !=3D null) {=0A= argList.addElement("-doclet");=0A= argList.addElement(doclet);=0A= }=0A= argList.addElement("-classpath");=0A= if (classpath !=3D null) {=0A= argList.addElement(classpath);=0A= } else {=0A= argList.addElement(System.getProperty("java.class.path"));=0A= }=0A= if (bootclasspath !=3D null) {=0A= argList.addElement("-bootclasspath");=0A= argList.addElement(bootclasspath);=0A= }=0A= if (extdirs !=3D null) {=0A= argList.addElement("-extdirs");=0A= argList.addElement(extdirs);=0A= }=0A= if (locale !=3D null) {=0A= argList.addElement("-locale");=0A= argList.addElement(locale);=0A= }=0A= if (encoding !=3D null) {=0A= argList.addElement("-encoding");=0A= argList.addElement(encoding);=0A= }=0A= if (windowtitle !=3D null) {=0A= argList.addElement("-windowtitle");=0A= argList.addElement(windowtitle);=0A= }=0A= if (doctitle !=3D null) {=0A= argList.addElement("-doctitle");=0A= argList.addElement(doctitle);=0A= }=0A= if (header !=3D null) {=0A= argList.addElement("-header");=0A= argList.addElement(header);=0A= }=0A= if (footer !=3D null) {=0A= argList.addElement("-footer");=0A= argList.addElement(footer);=0A= }=0A= if (bottom !=3D null) {=0A= argList.addElement("-bottom");=0A= argList.addElement(bottom);=0A= }=0A= if (link !=3D null) {=0A= argList.addElement("-link");=0A= argList.addElement(link);=0A= }=0A= if (linkoffline !=3D null) {=0A= argList.addElement("-linkoffline");=0A= argList.addElement(linkoffline);=0A= }=0A= if (group !=3D null) {=0A= argList.addElement("-group");=0A= argList.addElement(group);=0A= }=0A= if (stylesheetfile !=3D null) {=0A= argList.addElement("-stylesheetfile");=0A= argList.addElement(stylesheetfile.getAbsolutePath());=0A= }=0A= if (helpfile !=3D null) {=0A= argList.addElement("-helpfile");=0A= argList.addElement(helpfile.getAbsolutePath());=0A= }=0A= if (docencoding !=3D null) {=0A= argList.addElement("-docencoding");=0A= argList.addElement(docencoding);=0A= }=0A= if (destDir !=3D null) {=0A= argList.addElement("-d");=0A= argList.addElement(destDir.getAbsolutePath());=0A= }=0A= if (sourcePath !=3D null) {=0A= argList.addElement("-sourcepath");=0A= argList.addElement(sourcePath);=0A= }=0A= =0A= if ((packageNames !=3D null) && (packageNames.length() > 0)) {=0A= Vector packages =3D new Vector();=0A= StringTokenizer tok =3D new StringTokenizer(packageNames, = ",", false);=0A= while (tok.hasMoreTokens()) {=0A= String name =3D tok.nextToken().trim();=0A= if (name.endsWith(".*")) {=0A= packages.addElement(name);=0A= } else {=0A= argList.addElement(name);=0A= }=0A= }=0A= if (packages.size() > 0) {=0A= evaluatePackages(sourcePath, packages, argList);=0A= }=0A= }=0A= =0A= if ((sourceFiles !=3D null) && (sourceFiles.length() > 0)) {=0A= StringTokenizer tok =3D new StringTokenizer(sourceFiles, = ",", false);=0A= while (tok.hasMoreTokens()) {=0A= argList.addElement(tok.nextToken().trim());=0A= }=0A= }=0A= project.log("Javadoc args: " + argList.toString(), "javadoc", = project.MSG_VERBOSE);=0A= =0A= project.log("Javadoc execution", project.MSG_INFO);=0A= =0A= run("com.sun.tools.javadoc.Main", argList);=0A= }=0A= =0A= /**=0A= * Given a source path, a list of package patterns, fill the given = list=0A= * with the packages found in that path subdirs matching one of the = given=0A= * patterns.=0A= */=0A= private void evaluatePackages(String source, Vector packages, Vector = list) {=0A= project.log("Parsing source files for packages (will take a = while)", project.MSG_INFO);=0A= =0A= Hashtable map =3D mapClasses(new File(source));=0A= =0A= Enumeration e =3D map.keys();=0A= while (e.hasMoreElements()) {=0A= String pack =3D (String) e.nextElement();=0A= for (int i =3D 0; i < packages.size(); i++) {=0A= if (matches(pack, (String) packages.elementAt(i))) {=0A= list.addElement(pack);=0A= break;=0A= }=0A= }=0A= }=0A= }=0A= =0A= /**=0A= * Implements the pattern matching. For now it's only able to=0A= * guarantee that "aaa.bbb.ccc" matches "aaa.*" and "aaa.bbb.*"=0A= * FIXME: this code needs much improvement.=0A= */=0A= private boolean matches(String string, String pattern) {=0A= return string.startsWith(pattern.substring(0, pattern.length() - = 2));=0A= }=0A= =0A= /**=0A= * Returns an hashtable of packages linked to the last parsed=0A= * file in that package. This map is use to return a list of unique=0A= * packages as map keys.=0A= */=0A= private Hashtable mapClasses(File path) {=0A= Hashtable map =3D new Hashtable();=0A= =0A= Vector files =3D new Vector();=0A= getFiles(path, files);=0A= =0A= Enumeration e =3D files.elements();=0A= while (e.hasMoreElements()) {=0A= File file =3D (File) e.nextElement();=0A= String packageName =3D getPackageName(file);=0A= if (packageName !=3D null) map.put(packageName, file);=0A= }=0A= =0A= return map;=0A= }=0A= =0A= /**=0A= * Fills the given vector with files under the given path filtered=0A= * by the given file filter.=0A= */=0A= private void getFiles(File path, Vector list) {=0A= if (!path.exists()) {=0A= throw new BuildException("Path " + path + " does not = exist.");=0A= }=0A= =0A= String[] files =3D path.list();=0A= //-- String cwd =3D path.getName() + = System.getProperty("path.separator");=0A= String cwd =3D path.getPath() + = System.getProperty("file.separator");//++=0A= =0A= if (files !=3D null) {=0A= int count =3D 0;=0A= for (int i =3D 0; i < files.length; i++) {=0A= File file =3D new File(cwd + files[i]);=0A= if (file.isDirectory()) { =0A= getFiles(file, list);=0A= } else if (files[i].endsWith(".java")) {=0A= count++;=0A= //-- list.addElement(files[i]);=0A= list.addElement(file);//++=0A= }=0A= }=0A= if (count > 0) {=0A= project.log("found " + count + " source files in " + = path, "javadoc", project.MSG_VERBOSE);=0A= }=0A= } else {=0A= throw new BuildException("Error occurred during " + path + " = evaluation.");=0A= }=0A= }=0A= =0A= =0A= =0A= /**=0A= * Return the package name of the given java source file.=0A= * This method performs valid java parsing to figure out the package.=0A= */=0A= private String getPackageName(File file) {=0A= String name =3D null;=0A= =0A= try {=0A= BufferedReader reader =3D new BufferedReader(new = JavaReader(new FileReader(file)));=0A= String line;=0A= while (true) {=0A= line =3D reader.readLine();=0A= if (line =3D=3D null) {=0A= project.log("Could not evaluate package for " + = file, "javadoc", project.MSG_WARN);=0A= return null;=0A= }=0A= if (line.trim().startsWith("package ")) {=0A= name =3D line.substring(8, line.indexOf(";")).trim();=0A= break;=0A= }=0A= }=0A= reader.close();=0A= } catch (Exception e) {=0A= project.log("Exception " + e + " parsing " + file, = "javadoc", project.MSG_WARN);=0A= return null;=0A= }=0A= =0A= project.log(file + " --> " + name, "javadoc", = project.MSG_VERBOSE);=0A= =0A= return name;=0A= }=0A= =0A= /**=0A= * This is a java comment stripper reader that filters comments out=0A= * for more significant java parsing.=0A= */=0A= class JavaReader extends FilterReader {=0A= =0A= public JavaReader(Reader in) {=0A= super(in);=0A= }=0A= =0A= public int read() throws IOException {=0A= int c =3D in.read();=0A= if (c =3D=3D '/') {=0A= c =3D in.read();=0A= if (c =3D=3D '*') {=0A= c =3D in.read(); //++=0A= while (true) {=0A= //-- c =3D in.read();=0A= if (c =3D=3D '*') {=0A= c =3D in.read();=0A= if (c =3D=3D '/') {=0A= c =3D in.read();=0A= break;=0A= }=0A= }=0A= else { //++=0A= c =3D in.read(); //++=0A= } //++=0A= }=0A= }=0A= }=0A= return c; =0A= }=0A= =0A= =0A= /**=0A= * FIXME: this method is the one called by BuffereReader and it = should=0A= * use char[] based methods instead of relying on single char = ones=0A= * to speed up execution. Please, make this faster.=0A= */=0A= public int read(char cbuf[], int off, int len) throws = IOException {=0A= for (int i =3D 0; i < len; i++) {=0A= int c =3D read();=0A= if (c =3D=3D -1) {=0A= if (i =3D=3D 0) {=0A= return -1;=0A= } else {=0A= return i;=0A= }=0A= }=0A= cbuf[off + i] =3D (char) c;=0A= }=0A= return len;=0A= }=0A= =0A= public long skip(long n) throws IOException {=0A= for (long i =3D 0; i < n; i++) {=0A= if (in.read() =3D=3D -1) return i;=0A= }=0A= return n;=0A= }=0A= }=0A= }=0A= ------=_NextPart_000_000A_01BF6EA4.5DBFB540 Content-Type: application/octet-stream; name="Java.java" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="Java.java" /*=0A= * The Apache Software License, Version 1.1=0A= *=0A= * Copyright (c) 1999 The Apache Software Foundation. All rights =0A= * reserved.=0A= *=0A= * Redistribution and use in source and binary forms, with or without=0A= * modification, are permitted provided that the following conditions=0A= * are met:=0A= *=0A= * 1. Redistributions of source code must retain the above copyright=0A= * notice, this list of conditions and the following disclaimer. =0A= *=0A= * 2. Redistributions in binary form must reproduce the above copyright=0A= * notice, this list of conditions and the following disclaimer in=0A= * the documentation and/or other materials provided with the=0A= * distribution.=0A= *=0A= * 3. The end-user documentation included with the redistribution, if=0A= * any, must include the following acknowlegement: =0A= * "This product includes software developed by the =0A= * Apache Software Foundation (http://www.apache.org/)."=0A= * Alternately, this acknowlegement may appear in the software itself,=0A= * if and wherever such third-party acknowlegements normally appear.=0A= *=0A= * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software=0A= * Foundation" must not be used to endorse or promote products derived=0A= * from this software without prior written permission. For written =0A= * permission, please contact apache@apache.org.=0A= *=0A= * 5. Products derived from this software may not be called "Apache"=0A= * nor may "Apache" appear in their names without prior written=0A= * permission of the Apache Group.=0A= *=0A= * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED=0A= * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES=0A= * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE=0A= * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR=0A= * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,=0A= * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT=0A= * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF=0A= * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND=0A= * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,=0A= * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT=0A= * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF=0A= * SUCH DAMAGE.=0A= * = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= *=0A= * This software consists of voluntary contributions made by many=0A= * individuals on behalf of the Apache Software Foundation. For more=0A= * information on the Apache Software Foundation, please see=0A= * .=0A= */=0A= =0A= package org.apache.tools.ant.taskdefs;=0A= =0A= import org.apache.tools.ant.*;=0A= import java.lang.reflect.*;=0A= import java.util.*;=0A= =0A= /**=0A= * This task acts as a loader for java applications but allows to use = the same JVM =0A= * for the called application thus resulting in much faster operation.=0A= *=0A= * @author Stefano Mazzocchi stefano@apache.org=0A= */=0A= public class Java extends Task {=0A= =0A= private String classname =3D null;=0A= private String args =3D null;=0A= =0A= /**=0A= * Do the execution.=0A= */=0A= public void execute() throws BuildException {=0A= =0A= project.log("Calling " + classname, "java", project.MSG_VERBOSE);=0A= =0A= if (classname =3D=3D null) {=0A= throw new BuildException("Class name must not be null.");=0A= }=0A= =0A= Vector argList =3D tokenize(args);=0A= =0A= project.log("Java args: " + argList.toString(), "java", = project.MSG_VERBOSE);=0A= =0A= run(classname, argList);=0A= }=0A= =0A= /**=0A= * Set the source file.=0A= */=0A= public void setClass(String s) {=0A= this.classname =3D s;=0A= }=0A= =0A= /**=0A= * Set the destination file.=0A= */=0A= public void setArgs(String s) {=0A= this.args =3D s;=0A= }=0A= =0A= /**=0A= * Executes the given classname with the given arguments as it=0A= * was a command line application.=0A= */=0A= protected void run(String classname, Vector args) throws = BuildException {=0A= try {=0A= Class[] param =3D { Class.forName("[Ljava.lang.String;") };=0A= Class c =3D Class.forName(classname);=0A= Method main =3D c.getMethod("main", param);=0A= Object[] a =3D { array(args) };=0A= main.invoke(null, a);=0A= } catch (NullPointerException e) {=0A= throw new BuildException("Could not find main() method in " = + classname);=0A= } catch (ClassNotFoundException e) {=0A= throw new BuildException("Could not find " + classname + ". = Make sure you have it in your classpath");=0A= } catch (InvocationTargetException e) {=0A= /* =0A= //--=0A= Throwable t =3D e.getTargetException();=0A= if (!(t instanceof SecurityException)) {=0A= throw new BuildException(t.toString());=0A= }=0A= // else ignore because the security exception is thrown=0A= // if the invoked application tried to call System.exit()=0A= */=0A= throw new = BuildException(e.getTargetException().toString());//++=0A= } catch (Exception e) {=0A= throw new BuildException(e.toString());=0A= }=0A= }=0A= =0A= /**=0A= * Transforms an argument string into a vector of strings.=0A= */=0A= protected Vector tokenize(String args) {=0A= Vector v =3D new Vector();=0A= StringTokenizer t =3D new StringTokenizer(args, " ");=0A= =0A= while (t.hasMoreTokens()) {=0A= v.addElement(t.nextToken());=0A= }=0A= =0A= return v;=0A= }=0A= =0A= /**=0A= * Transforms a vector of strings into an array.=0A= */=0A= protected String[] array(Vector v) {=0A= String[] s =3D new String[v.size()];=0A= Enumeration e =3D v.elements();=0A= =0A= for (int i =3D 0; e.hasMoreElements(); i++) {=0A= s[i] =3D (String) e.nextElement();=0A= }=0A= =0A= return s;=0A= }=0A= }=0A= ------=_NextPart_000_000A_01BF6EA4.5DBFB540--