diff --git a/src/main/org/apache/tools/ant/RuntimeConfigurable.java b/src/main/org/apache/tools/ant/RuntimeConfigurable.java index 6e7153a98..15ddddd09 100644 --- a/src/main/org/apache/tools/ant/RuntimeConfigurable.java +++ b/src/main/org/apache/tools/ant/RuntimeConfigurable.java @@ -132,14 +132,14 @@ public class RuntimeConfigurable { public String getElementTag() { return elementTag; } - - + + /** * Configure the wrapped element and all children. */ public void maybeConfigure(Project p) throws BuildException { - String id = null; - + String id = null; + if (attributes != null) { ProjectHelper.configure(wrappedObject, attributes, p); id = attributes.getValue("id"); diff --git a/src/main/org/apache/tools/ant/taskdefs/Deltree.java b/src/main/org/apache/tools/ant/taskdefs/Deltree.java index 4bee0e686..c1295ce9c 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Deltree.java +++ b/src/main/org/apache/tools/ant/taskdefs/Deltree.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -9,7 +9,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -17,15 +17,15 @@ * distribution. * * 3. The end-user documentation included with the redistribution, if - * any, must include the following acknowlegement: - * "This product includes software developed by the + * any, must include the following acknowlegement: + * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived - * from this software without prior written permission. For written + * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" @@ -72,28 +72,28 @@ public class Deltree extends Task { private File dir; public void setDir(File dir) { - this.dir = dir; + this.dir = dir; } - + public void execute() throws BuildException { log("DEPRECATED - The deltree task is deprecated. Use delete instead."); if (dir == null) { throw new BuildException("dir attribute must be set!", location); - } + } - if (dir.exists()) { - if (!dir.isDirectory()) { - if (!dir.delete()) { - throw new BuildException("Unable to delete directory " + if (dir.exists()) { + if (!dir.isDirectory()) { + if (!dir.delete()) { + throw new BuildException("Unable to delete directory " + dir.getAbsolutePath(), location); - } - return; - // String msg = "Given dir: " + dir.getAbsolutePath() + - // " is not a dir"; - // throw new BuildException(msg); - } + } + return; + // String msg = "Given dir: " + dir.getAbsolutePath() + + // " is not a dir"; + // throw new BuildException(msg); + } log("Deleting: " + dir.getAbsolutePath()); @@ -105,31 +105,31 @@ public class Deltree extends Task { } } } - + private void removeDir(File dir) throws IOException { // check to make sure that the given dir isn't a symlink // the comparison of absolute path and canonical path // catches this - - // if (dir.getCanonicalPath().equals(dir.getAbsolutePath())) { - // (costin) It will not work if /home/costin is symlink to /da0/home/costin ( taz - // for example ) - String[] list = dir.list(); - for (int i = 0; i < list.length; i++) { - String s = list[i]; - File f = new File(dir, s); - if (f.isDirectory()) { - removeDir(f); - } else { - if (!f.delete()) { - throw new BuildException("Unable to delete file " + f.getAbsolutePath()); - } - } - } + + // if (dir.getCanonicalPath().equals(dir.getAbsolutePath())) { + // (costin) It will not work if /home/costin is symlink to /da0/home/costin ( taz + // for example ) + String[] list = dir.list(); + for (int i = 0; i < list.length; i++) { + String s = list[i]; + File f = new File(dir, s); + if (f.isDirectory()) { + removeDir(f); + } else { + if (!f.delete()) { + throw new BuildException("Unable to delete file " + f.getAbsolutePath()); + } + } + } if (!dir.delete()) { - throw new BuildException("Unable to delete directory " + dir.getAbsolutePath()); - } + throw new BuildException("Unable to delete directory " + dir.getAbsolutePath()); + } } } diff --git a/src/main/org/apache/tools/ant/taskdefs/ExecTask.java b/src/main/org/apache/tools/ant/taskdefs/ExecTask.java index 4b4813942..d29973ebb 100644 --- a/src/main/org/apache/tools/ant/taskdefs/ExecTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/ExecTask.java @@ -75,7 +75,7 @@ import java.io.FileNotFoundException; * @author rubys@us.ibm.com * @author thomas.haas@softwired-inc.com * @author Stefan Bodewig - * @author Mariusz Nowostawski + * @author Mariusz Nowostawski */ public class ExecTask extends Task { @@ -95,7 +95,7 @@ public class ExecTask extends Task { /** Controls whether the VM (1.3 and above) is used to execute the command */ private boolean vmLauncher = true; - + /** * Timeout in milliseconds after which the process will be killed. */ @@ -146,7 +146,7 @@ public class ExecTask extends Task { * the process */ public void setOutputproperty(String outputprop) { - this.outputprop = outputprop; + this.outputprop = outputprop; } /** @@ -195,10 +195,10 @@ public class ExecTask extends Task { throw new BuildException("no executable specified", location); } if (dir != null && !dir.exists()) { - throw new BuildException("The directory you specified does not exist"); + throw new BuildException("The directory you specified does not exist"); } if (dir != null && !dir.isDirectory()) { - throw new BuildException("The directory you specified is not a directory"); + throw new BuildException("The directory you specified is not a directory"); } } @@ -224,7 +224,7 @@ public class ExecTask extends Task { public void setVMLauncher(boolean vmLauncher) { this.vmLauncher = vmLauncher; } - + /** * Create an Execute instance with the correct working directory set. */ @@ -233,7 +233,7 @@ public class ExecTask extends Task { if (dir == null) dir = project.getBaseDir(); // show the command log(cmdl.toString(), Project.MSG_VERBOSE); - + Execute exe = new Execute(createHandler(), createWatchdog()); exe.setAntRun(project); exe.setWorkingDirectory(dir); @@ -265,7 +265,7 @@ public class ExecTask extends Task { } } if (baos != null) { - BufferedReader in = + BufferedReader in = new BufferedReader(new StringReader(baos.toString())); String line = null; StringBuffer val = new StringBuffer(); @@ -278,7 +278,7 @@ public class ExecTask extends Task { project.setProperty(outputprop, val.toString()); } } - + /** * Run the command using the given Execute instance. This may be overidden by subclasses */ @@ -309,10 +309,10 @@ public class ExecTask extends Task { throw new BuildException("Cannot write to "+out, ioe, location); } } else if (outputprop != null) { - // try { - baos = new ByteArrayOutputStream(); - log("Output redirected to ByteArray", Project.MSG_VERBOSE); - return new PumpStreamHandler(baos); + // try { + baos = new ByteArrayOutputStream(); + log("Output redirected to ByteArray", Project.MSG_VERBOSE); + return new PumpStreamHandler(baos); } else { return new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN); diff --git a/src/main/org/apache/tools/ant/taskdefs/Get.java b/src/main/org/apache/tools/ant/taskdefs/Get.java index 0cfc0bbb6..e8d4c85b7 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Get.java +++ b/src/main/org/apache/tools/ant/taskdefs/Get.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -9,7 +9,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -17,15 +17,15 @@ * distribution. * * 3. The end-user documentation included with the redistribution, if - * any, must include the following acknowlegement: - * "This product includes software developed by the + * any, must include the following acknowlegement: + * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived - * from this software without prior written permission. For written + * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" @@ -67,9 +67,9 @@ import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; /** - * Get a particular file from a URL source. - * Options include verbose reporting, timestamp based fetches and controlling - * actions on failures. NB: access through a firewall only works if the whole + * Get a particular file from a URL source. + * Options include verbose reporting, timestamp based fetches and controlling + * actions on failures. NB: access through a firewall only works if the whole * Java runtime is correctly configured. * * @author costin@dnt.ro @@ -84,7 +84,7 @@ public class Get extends Task { private String uname = null; private String pword = null; - + /** * Does the work. * @@ -99,12 +99,12 @@ public class Get extends Task { throw new BuildException("dest attribute is required", location); } - if (dest.exists() && dest.isDirectory()) { + if (dest.exists() && dest.isDirectory()) { throw new BuildException("The specified destination is a directory", location); } - if (dest.exists() && !dest.canWrite()) { + if (dest.exists() && !dest.canWrite()) { throw new BuildException("Can't write to " + dest.getAbsolutePath(), location); } @@ -123,10 +123,10 @@ public class Get extends Task { Date t=new Date(timestamp); log("local file date : "+t.toString()); } - + hasTimestamp=true; } - + //set up the URL connection URLConnection connection=source.openConnection(); //modify the headers @@ -134,24 +134,23 @@ public class Get extends Task { if(useTimestamp && hasTimestamp) { connection.setIfModifiedSince(timestamp); } - // prepare Java 1.1 style credentials - if (uname != null || pword != null) { - String up = uname + ":" + pword; - String encoding; - // check to see if sun's Base64 encoder is available. - try { - sun.misc.BASE64Encoder encoder = - (sun.misc.BASE64Encoder) Class.forName("sun.misc.BASE64Encoder").newInstance(); - encoding = encoder.encode (up.getBytes()); - - } - catch (Exception ex) { // sun's base64 encoder isn't available - Base64Converter encoder = new Base64Converter(); - encoding = encoder.encode(up.getBytes()); - } - connection.setRequestProperty ("Authorization", "Basic " + encoding); - - } + // prepare Java 1.1 style credentials + if (uname != null || pword != null) { + String up = uname + ":" + pword; + String encoding; + // check to see if sun's Base64 encoder is available. + try { + sun.misc.BASE64Encoder encoder = + (sun.misc.BASE64Encoder) Class.forName("sun.misc.BASE64Encoder").newInstance(); + encoding = encoder.encode (up.getBytes()); + + } + catch (Exception ex) { // sun's base64 encoder isn't available + Base64Converter encoder = new Base64Converter(); + encoding = encoder.encode(up.getBytes()); + } + connection.setRequestProperty ("Authorization", "Basic " + encoding); + } //connect to the remote site (may take some time) connection.connect(); @@ -160,23 +159,23 @@ public class Get extends Task { HttpURLConnection httpConnection=(HttpURLConnection)connection; if(httpConnection.getResponseCode()==HttpURLConnection.HTTP_NOT_MODIFIED) { //not modified so no file download. just return instead - //and trace out something so the user doesn't think that the + //and trace out something so the user doesn't think that the //download happened when it didnt log("Not modified - so not downloaded"); - return; + return; } - // test for 401 result (HTTP only) + // test for 401 result (HTTP only) if(httpConnection.getResponseCode()==HttpURLConnection.HTTP_UNAUTHORIZED) { log("Not authorized - check " + dest + " for details"); - return; + return; } } //REVISIT: at this point even non HTTP connections may support the if-modified-since //behaviour -we just check the date of the content and skip the write if it is not - //newer. Some protocols (FTP) dont include dates, of course. - + //newer. Some protocols (FTP) dont include dates, of course. + FileOutputStream fos = new FileOutputStream(dest); InputStream is=null; @@ -190,15 +189,15 @@ public class Get extends Task { } if( is==null ) { log( "Can't get " + source + " to " + dest); - if(ignoreErrors) + if(ignoreErrors) return; throw new BuildException( "Can't get " + source + " to " + dest, location); } - + byte[] buffer = new byte[100 * 1024]; int length; - + while ((length = is.read(buffer)) >= 0) { fos.write(buffer, 0, length); if (verbose) System.out.print("."); @@ -206,8 +205,8 @@ public class Get extends Task { if(verbose) System.out.println(); fos.close(); is.close(); - - //if (and only if) the use file time option is set, then the + + //if (and only if) the use file time option is set, then the //saved file now has its timestamp set to that of the downloaded file if(useTimestamp) { long remoteTimestamp=connection.getLastModified(); @@ -219,18 +218,15 @@ public class Get extends Task { if(remoteTimestamp!=0) touchFile(dest,remoteTimestamp); } - - - } catch (IOException ioe) { log("Error getting " + source + " to " + dest ); - if(ignoreErrors) + if(ignoreErrors) return; throw new BuildException(ioe, location); } } - - /** + + /** * set the timestamp of a named file to a specified time. * * @param filename @@ -240,7 +236,7 @@ public class Get extends Task { *@exception BuildException Thrown in unrecoverable error. Likely *this comes from file access failures. */ - protected boolean touchFile(File file, long timemillis) + protected boolean touchFile(File file, long timemillis) throws BuildException { if (project.getJavaVersion() != Project.JAVA_1_1) { @@ -252,11 +248,11 @@ public class Get extends Task { touch.setMillis(timemillis); touch.touch(); return true; - + } else { return false; } - } + } /** * Set the URL. @@ -300,13 +296,13 @@ public class Get extends Task { *

In this situation, the if-modified-since header is set so that the file is * only fetched if it is newer than the local file (or there is no local file) * This flag is only valid on HTTP connections, it is ignored in other cases. - * When the flag is set, the local copy of the downloaded file will also - * have its timestamp set to the remote file time. + * When the flag is set, the local copy of the downloaded file will also + * have its timestamp set to the remote file time. *
* Note that remote files of date 1/1/1970 (GMT) are treated as 'no timestamp', and * web servers often serve files with a timestamp in the future by replacing their timestamp - * with that of the current time. Also, inter-computer clock differences can cause no end of - * grief. + * with that of the current time. Also, inter-computer clock differences can cause no end of + * grief. * @param v "true" to enable file time fetching */ public void setUseTimestamp(boolean v) { @@ -334,95 +330,92 @@ public class Get extends Task { this.pword = p; } - /********************************************************************* - * BASE 64 encoding of a String or an array of bytes. - * - * Based on RFC 1421. - * - * @author - * Unknown - * @author - * Gautam Guliani - *********************************************************************/ - - class Base64Converter - { - - public final char [ ] alphabet = { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 0 to 7 - 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', // 8 to 15 - 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', // 16 to 23 - 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', // 24 to 31 - 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', // 32 to 39 - 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', // 40 to 47 - 'w', 'x', 'y', 'z', '0', '1', '2', '3', // 48 to 55 - '4', '5', '6', '7', '8', '9', '+', '/' }; // 56 to 63 - - - public String encode ( String s ) - { - return encode ( s.getBytes ( ) ); - } - - public String encode ( byte [ ] octetString ) - { - int bits24; - int bits6; - - char [ ] out - = new char [ ( ( octetString.length - 1 ) / 3 + 1 ) * 4 ]; - - int outIndex = 0; - int i = 0; - - while ( ( i + 3 ) <= octetString.length ) { - // store the octets - bits24=( octetString [ i++ ] & 0xFF ) << 16; - bits24 |=( octetString [ i++ ] & 0xFF ) << 8; - - bits6=( bits24 & 0x00FC0000 )>> 18; - out [ outIndex++ ] = alphabet [ bits6 ]; - bits6 = ( bits24 & 0x0003F000 ) >> 12; - out [ outIndex++ ] = alphabet [ bits6 ]; - bits6 = ( bits24 & 0x00000FC0 ) >> 6; - out [ outIndex++ ] = alphabet [ bits6 ]; - bits6 = ( bits24 & 0x0000003F ); - out [ outIndex++ ] = alphabet [ bits6 ]; - } - - if ( octetString.length - i == 2 ) - { - // store the octets - bits24 = ( octetString [ i ] & 0xFF ) << 16; - bits24 |=( octetString [ i + 1 ] & 0xFF ) << 8; - bits6=( bits24 & 0x00FC0000 )>> 18; - out [ outIndex++ ] = alphabet [ bits6 ]; - bits6 = ( bits24 & 0x0003F000 ) >> 12; - out [ outIndex++ ] = alphabet [ bits6 ]; - bits6 = ( bits24 & 0x00000FC0 ) >> 6; - out [ outIndex++ ] = alphabet [ bits6 ]; - - // padding - out [ outIndex++ ] = '='; - } - else if ( octetString.length - i == 1 ) - { - // store the octets - bits24 = ( octetString [ i ] & 0xFF ) << 16; - bits6=( bits24 & 0x00FC0000 )>> 18; - out [ outIndex++ ] = alphabet [ bits6 ]; - bits6 = ( bits24 & 0x0003F000 ) >> 12; - out [ outIndex++ ] = alphabet [ bits6 ]; - - // padding - out [ outIndex++ ] = '='; - out [ outIndex++ ] = '='; - } - - return new String ( out ); - } + /********************************************************************* + * BASE 64 encoding of a String or an array of bytes. + * + * Based on RFC 1421. + * + * @author + * Unknown + * @author + * Gautam Guliani + *********************************************************************/ + + class Base64Converter + { + + public final char [ ] alphabet = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 0 to 7 + 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', // 8 to 15 + 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', // 16 to 23 + 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', // 24 to 31 + 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', // 32 to 39 + 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', // 40 to 47 + 'w', 'x', 'y', 'z', '0', '1', '2', '3', // 48 to 55 + '4', '5', '6', '7', '8', '9', '+', '/' }; // 56 to 63 + + + public String encode ( String s ) + { + return encode ( s.getBytes ( ) ); + } - } + public String encode ( byte [ ] octetString ) + { + int bits24; + int bits6; + + char [ ] out + = new char [ ( ( octetString.length - 1 ) / 3 + 1 ) * 4 ]; + + int outIndex = 0; + int i = 0; + + while ( ( i + 3 ) <= octetString.length ) { + // store the octets + bits24=( octetString [ i++ ] & 0xFF ) << 16; + bits24 |=( octetString [ i++ ] & 0xFF ) << 8; + + bits6=( bits24 & 0x00FC0000 )>> 18; + out [ outIndex++ ] = alphabet [ bits6 ]; + bits6 = ( bits24 & 0x0003F000 ) >> 12; + out [ outIndex++ ] = alphabet [ bits6 ]; + bits6 = ( bits24 & 0x00000FC0 ) >> 6; + out [ outIndex++ ] = alphabet [ bits6 ]; + bits6 = ( bits24 & 0x0000003F ); + out [ outIndex++ ] = alphabet [ bits6 ]; + } + if ( octetString.length - i == 2 ) + { + // store the octets + bits24 = ( octetString [ i ] & 0xFF ) << 16; + bits24 |=( octetString [ i + 1 ] & 0xFF ) << 8; + bits6=( bits24 & 0x00FC0000 )>> 18; + out [ outIndex++ ] = alphabet [ bits6 ]; + bits6 = ( bits24 & 0x0003F000 ) >> 12; + out [ outIndex++ ] = alphabet [ bits6 ]; + bits6 = ( bits24 & 0x00000FC0 ) >> 6; + out [ outIndex++ ] = alphabet [ bits6 ]; + + // padding + out [ outIndex++ ] = '='; + } + else if ( octetString.length - i == 1 ) + { + // store the octets + bits24 = ( octetString [ i ] & 0xFF ) << 16; + bits6=( bits24 & 0x00FC0000 )>> 18; + out [ outIndex++ ] = alphabet [ bits6 ]; + bits6 = ( bits24 & 0x0003F000 ) >> 12; + out [ outIndex++ ] = alphabet [ bits6 ]; + + // padding + out [ outIndex++ ] = '='; + out [ outIndex++ ] = '='; + } + return new String ( out ); + } + } } diff --git a/src/main/org/apache/tools/ant/taskdefs/Javac.java b/src/main/org/apache/tools/ant/taskdefs/Javac.java index 881cf9a4c..df51a5a4b 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Javac.java +++ b/src/main/org/apache/tools/ant/taskdefs/Javac.java @@ -134,7 +134,7 @@ public class Javac extends MatchingTask { private String source; private String debugLevel; - + /** * Get the value of debugLevel. * @return value of debugLevel. @@ -158,7 +158,7 @@ public class Javac extends MatchingTask { public String getSource() { return source; } - + /** * Set the value of source. * @param v Value to assign to source. @@ -500,7 +500,7 @@ public class Javac extends MatchingTask { * Is this a forked invocation of JDK's javac? */ public boolean isForkedJavac() { - return !"false".equals(fork) || + return !"false".equals(fork) || "extJavac".equals(project.getProperty("build.compiler")); } @@ -534,7 +534,7 @@ public class Javac extends MatchingTask { * Adds an implementation specific command line argument. */ public ImplementationSpecificArgument createCompilerArg() { - ImplementationSpecificArgument arg = + ImplementationSpecificArgument arg = new ImplementationSpecificArgument(); implementationSpecificArgs.addElement(arg); return arg; @@ -546,10 +546,10 @@ public class Javac extends MatchingTask { */ public String[] getCurrentCompilerArgs() { Vector args = new Vector(); - for (Enumeration enum = implementationSpecificArgs.elements(); + for (Enumeration enum = implementationSpecificArgs.elements(); enum.hasMoreElements(); ) { - String[] curr = + String[] curr = ((ImplementationSpecificArgument) enum.nextElement()).getParts(); for (int i=0; i 0) { String pkgDir = packageDirs[i].replace('/','.').replace('\\','.'); if (!addedPackages.contains(pkgDir)) { @@ -1095,7 +1095,7 @@ public class Javadoc extends Task { } } } catch (IOException ioex) { - throw new BuildException("Error creating temporary file", + throw new BuildException("Error creating temporary file", ioex, location); } finally { if (packageListWriter != null) { @@ -1133,7 +1133,7 @@ public class Javadoc extends Task { } } - + protected void logFlush() { if (queuedLine != null) { super.processLine(queuedLine, Project.MSG_VERBOSE); @@ -1146,15 +1146,15 @@ public class Javadoc extends Task { * Convenience method to expand properties. */ protected String expand(String content) { - return ProjectHelper.replaceProperties(project, content, + return ProjectHelper.replaceProperties(project, content, project.getProperties()); } private String getJavadocExecutableName() { - // This is the most common extension case - exe for windows and OS/2, + // This is the most common extension case - exe for windows and OS/2, // nothing for *nix. - String extension = Os.isFamily("dos") ? ".exe" : ""; + String extension = Os.isFamily("dos") ? ".exe" : ""; // Look for javadoc in the java.home/../bin directory. Unfortunately // on Windows java.home doesn't always refer to the correct location, diff --git a/src/main/org/apache/tools/ant/taskdefs/Mkdir.java b/src/main/org/apache/tools/ant/taskdefs/Mkdir.java index 3df7059e5..f685c2fb9 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Mkdir.java +++ b/src/main/org/apache/tools/ant/taskdefs/Mkdir.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -9,7 +9,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -17,15 +17,15 @@ * distribution. * * 3. The end-user documentation included with the redistribution, if - * any, must include the following acknowlegement: - * "This product includes software developed by the + * any, must include the following acknowlegement: + * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived - * from this software without prior written permission. For written + * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" @@ -50,7 +50,7 @@ * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . - */ + */ package org.apache.tools.ant.taskdefs; @@ -68,7 +68,7 @@ import java.io.File; public class Mkdir extends Task { private File dir; - + public void execute() throws BuildException { if (dir == null) { throw new BuildException("dir attribute is required", location); @@ -77,19 +77,19 @@ public class Mkdir extends Task { if (dir.isFile()) { throw new BuildException("Unable to create directory as a file already exists with that name: " + dir.getAbsolutePath()); } - + if (!dir.exists()) { - boolean result = dir.mkdirs(); - if (result == false) { - String msg = "Directory " + dir.getAbsolutePath() + " creation was not " + - "successful for an unknown reason"; - throw new BuildException(msg, location); - } - log("Created dir: " + dir.getAbsolutePath()); - } + boolean result = dir.mkdirs(); + if (result == false) { + String msg = "Directory " + dir.getAbsolutePath() + " creation was not " + + "successful for an unknown reason"; + throw new BuildException(msg, location); + } + log("Created dir: " + dir.getAbsolutePath()); + } } public void setDir(File dir) { - this.dir = dir; + this.dir = dir; } } diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/Kjc.java b/src/main/org/apache/tools/ant/taskdefs/compilers/Kjc.java index 1947b30ff..8a9fb535c 100644 --- a/src/main/org/apache/tools/ant/taskdefs/compilers/Kjc.java +++ b/src/main/org/apache/tools/ant/taskdefs/compilers/Kjc.java @@ -80,9 +80,9 @@ public class Kjc extends DefaultCompilerAdapter { Class c = Class.forName("at.dms.kjc.Main"); // Call the compile() method - Method compile = c.getMethod("compile", + Method compile = c.getMethod("compile", new Class [] { String [].class }); - Boolean ok = (Boolean)compile.invoke(null, + Boolean ok = (Boolean)compile.invoke(null, new Object[] {cmd.getArguments()}); return ok.booleanValue(); } @@ -105,8 +105,8 @@ public class Kjc extends DefaultCompilerAdapter { */ protected Commandline setupKjcCommand() { Commandline cmd = new Commandline(); - - // generate classpath, because kjc does't support sourcepath. + + // generate classpath, because kjc does't support sourcepath. Path classpath = getCompileClasspath(); if (deprecation == true) { @@ -118,26 +118,26 @@ public class Kjc extends DefaultCompilerAdapter { cmd.createArgument().setFile(destDir); } - // generate the clsspath + // generate the clsspath cmd.createArgument().setValue("-classpath"); - Path cp = new Path(project); + Path cp = new Path(project); - // kjc don't have bootclasspath option. - if (bootclasspath != null) { + // kjc don't have bootclasspath option. + if (bootclasspath != null) { cp.append(bootclasspath); - } + } - if (extdirs != null) { + if (extdirs != null) { cp.addExtdirs(extdirs); - } + } - cp.append(classpath); - cp.append(src); + cp.append(classpath); + cp.append(src); - cmd.createArgument().setPath(cp); + cmd.createArgument().setPath(cp); - // kjc-1.5A doesn't support -encoding option now. + // kjc-1.5A doesn't support -encoding option now. // but it will be supported near the feature. if (encoding != null) { cmd.createArgument().setValue("-encoding"); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbJar.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbJar.java index db9e89b5f..72077a143 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbJar.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbJar.java @@ -89,7 +89,7 @@ import org.apache.tools.ant.types.FileSet; *

* *

Functionality is currently provided for standard EJB1.1 jars and Weblogic - * 5.1 jars. The weblogic deployment descriptors, used in constructing the + * 5.1 jars. The weblogic deployment descriptors, used in constructing the * Weblogic jar, are located based on a simple naming convention. The name of the * standard deployment descriptor is taken upto the first instance of a String, * specified by the attribute baseNameTerminator, and then the regular Weblogic @@ -106,23 +106,23 @@ import org.apache.tools.ant.types.FileSet; * @author Tim Fennell */ public class EjbJar extends MatchingTask { - + public static class DTDLocation { private String publicId = null; private String location = null; - + public void setPublicId(String publicId) { this.publicId = publicId; } - + public void setLocation(String location) { this.location = location; } - + public String getPublicId() { return publicId; } - + public String getLocation() { return location; } @@ -138,7 +138,7 @@ public class EjbJar extends MatchingTask { /** Stores a handle to the directory under which to search for deployment descriptors */ public File descriptorDir; - + /** Instance variable that marks the end of the 'basename' */ public String baseNameTerminator = "-"; @@ -150,28 +150,28 @@ public class EjbJar extends MatchingTask { * of a flat directory as the destination for the jar files. */ public boolean flatDestDir = false; - + /** * The classpath to use when loading classes */ public Path classpath; - + /** * A Fileset of support classes */ public List supportFileSets = new ArrayList(); - + /** * The list of configured DTD locations */ public ArrayList dtdLocations = new ArrayList(); - + /** * The naming scheme used to determine the generated jar name * from the descriptor information */ public NamingScheme namingScheme; - + /** * The Manifest file */ @@ -196,7 +196,7 @@ public class EjbJar extends MatchingTask { deployment descriptor tools are provided. Normally each deployment tool will specify the desitination dir itself. */ private File destDir; - + /** Instance variable that stores the suffix for the generated jarfile. */ private String genericJarSuffix = "-generic.jar"; @@ -235,7 +235,7 @@ public class EjbJar extends MatchingTask { /** * Create a nested element used to configure a deployment tool for iPlanet - * Application Server. + * Application Server. * * @return the deployment tool instance to be configured. */ @@ -279,7 +279,7 @@ public class EjbJar extends MatchingTask { * * This classpath is used to locate the super classes and interfaces * of the classes that will make up the EJB jar. - * + * * @return the path to be configured. */ public Path createClasspath() { @@ -296,7 +296,7 @@ public class EjbJar extends MatchingTask { public DTDLocation createDTD() { DTDLocation dtdLocation = new DTDLocation(); config.dtdLocations.add(dtdLocation); - + return dtdLocation; } @@ -310,7 +310,7 @@ public class EjbJar extends MatchingTask { config.supportFileSets.add(supportFileSet); return supportFileSet; } - + /** * Set the Manifest file to use when jarring. @@ -327,7 +327,7 @@ public class EjbJar extends MatchingTask { /** * Set the srcdir attribute. The source directory is the directory that contains - * the classes that will be added to the EJB jar. Typically this will include the + * the classes that will be added to the EJB jar. Typically this will include the * home and remote interfaces and the bean class. * * @param inDir the source directory. @@ -342,7 +342,7 @@ public class EjbJar extends MatchingTask { * The descriptor directory contains the EJB deployment descriptors. These are XML * files that declare the properties of a bean in a particular deployment scenario. Such * properties include, for example, the transactional nature of the bean and the security - * access control to the bean's methods. + * access control to the bean's methods. * * @param inDir the directory containing the deployment descriptors. */ @@ -352,8 +352,8 @@ public class EjbJar extends MatchingTask { /** * Set the base name of the EJB jar that is to be created if it is not to be - * determined from the name of the deployment descriptor files. - * + * determined from the name of the deployment descriptor files. + * * @param inValue the basename that will be used when writing the jar file containing * the EJB */ @@ -364,9 +364,9 @@ public class EjbJar extends MatchingTask { config.namingScheme.setValue(NamingScheme.BASEJARNAME); } else if (!config.namingScheme.getValue().equals(NamingScheme.BASEJARNAME)) { - throw new BuildException("The basejarname attribute is not compatible with the " + + throw new BuildException("The basejarname attribute is not compatible with the " + config.namingScheme.getValue() + " naming scheme"); - } + } } /** @@ -379,22 +379,22 @@ public class EjbJar extends MatchingTask { config.namingScheme = namingScheme; if (!config.namingScheme.getValue().equals(NamingScheme.BASEJARNAME) && config.baseJarName != null) { - throw new BuildException("The basejarname attribute is not compatible with the " + + throw new BuildException("The basejarname attribute is not compatible with the " + config.namingScheme.getValue() + " naming scheme"); - } + } } - + /** * Set the destination directory. - * + * * The EJB jar files will be written into this directory. The jar files that exist in - * this directory are also used when determining if the contents of the jar file + * this directory are also used when determining if the contents of the jar file * have changed. * * Note that this parameter is only used if no deployment tools are specified. Typically * each deployment tool will specify its own destination directory. - * + * * @param inFile the destination directory. */ public void setDestdir(File inDir) { @@ -402,7 +402,7 @@ public class EjbJar extends MatchingTask { } /** - * Set the classpath to use when resolving classes for inclusion in the jar. + * Set the classpath to use when resolving classes for inclusion in the jar. * * @param classpath the classpath to use. */ @@ -413,26 +413,26 @@ public class EjbJar extends MatchingTask { /** * Set the flat dest dir flag. * - * This flag controls whether the destination jars are written out in the - * destination directory with the same hierarchal structure from which - * the deployment descriptors have been read. If this is set to true the + * This flag controls whether the destination jars are written out in the + * destination directory with the same hierarchal structure from which + * the deployment descriptors have been read. If this is set to true the * generated EJB jars are written into the root of the destination directory, * otherwise they are written out in the same relative position as the deployment * descriptors in the descriptor directory. - * + * * @param inValue the new value of the flatdestdir flag. */ public void setFlatdestdir(boolean inValue) { config.flatDestDir = inValue; } - + /** * Set the suffix for the generated jar file. * When generic jars are generated, they have a suffix which is appended to the * the bean name to create the name of the jar file. Note that this suffix includes - * the extension fo te jar file and should therefore end with an appropriate + * the extension fo te jar file and should therefore end with an appropriate * extension such as .jar or .ear - * + * * @param inString the string to use as the suffix. */ public void setGenericjarsuffix(String inString) { @@ -443,7 +443,7 @@ public class EjbJar extends MatchingTask { * Set the baseNameTerminator. * * The basename terminator is the string which terminates the bean name. The convention - * used by this task is that bean descriptors are named as the BeanName with some suffix. + * used by this task is that bean descriptors are named as the BeanName with some suffix. * The baseNameTerminator string separates the bean name and the suffix and is used to * determine the bean name. * @@ -468,19 +468,19 @@ public class EjbJar extends MatchingTask { } else if (config.namingScheme.getValue().equals(NamingScheme.BASEJARNAME) && config.baseJarName == null) { - throw new BuildException("The basejarname attribute must be specified " + + throw new BuildException("The basejarname attribute must be specified " + "with the basejarname naming scheme"); } - } + } /** * Invoked by Ant after the task is prepared, when it is ready to execute - * this task. + * this task. * - * This will configure all of the nested deployment tools to allow them to - * process the jar. If no deployment tools have been configured a generic + * This will configure all of the nested deployment tools to allow them to + * process the jar. If no deployment tools have been configured a generic * tool is created to handle the jar. - * + * * A parser is configured and then each descriptor found is passed to all * the deployment tool elements for processing. * @@ -490,7 +490,7 @@ public class EjbJar extends MatchingTask { */ public void execute() throws BuildException { validateConfig(); - + if (deploymentTools.size() == 0) { GenericDeploymentTool genericTool = new GenericDeploymentTool(); genericTool.setTask(this); @@ -498,27 +498,27 @@ public class EjbJar extends MatchingTask { genericTool.setGenericJarSuffix(genericJarSuffix); deploymentTools.add(genericTool); } - + for (Iterator i = deploymentTools.iterator(); i.hasNext(); ) { EJBDeploymentTool tool = (EJBDeploymentTool)i.next(); tool.configure(config); tool.validateConfigured(); } - + try { // Create the parser using whatever parser the system dictates SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); saxParserFactory.setValidating(true); SAXParser saxParser = saxParserFactory.newSAXParser(); - - + + DirectoryScanner ds = getDirectoryScanner(config.descriptorDir); ds.scan(); String[] files = ds.getIncludedFiles(); - + log(files.length + " deployment descriptors located.", Project.MSG_VERBOSE); - + // Loop through the files. Each file represents one deployment // descriptor, and hence one bean in our model. for (int index = 0; index < files.length; ++index) { @@ -527,7 +527,7 @@ public class EjbJar extends MatchingTask { EJBDeploymentTool tool = (EJBDeploymentTool)i.next(); tool.processDescriptor(files[index], saxParser); } - } + } } catch (SAXException se) { String msg = "SAXException while creating parser." diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java index a58c108f1..e8c17dec7 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java @@ -80,23 +80,23 @@ import org.xml.sax.InputSource; import org.xml.sax.AttributeList; /** - * Utility class to compile EJB stubs and skeletons for the iPlanet Application + * Utility class to compile EJB stubs and skeletons for the iPlanet Application * Server (iAS). The class will read a standard EJB descriptor (as well as an - * EJB descriptor specific to iPlanet Application Server) to identify one or - * more EJBs to process. It will search for EJB "source" classes (the remote + * EJB descriptor specific to iPlanet Application Server) to identify one or + * more EJBs to process. It will search for EJB "source" classes (the remote * interface, home interface, and EJB implementation class) and the EJB stubs - * and skeletons in the specified destination directory. Only if the stubs and + * and skeletons in the specified destination directory. Only if the stubs and * skeletons cannot be found or if they're out of date will the iPlanet * Application Server ejbc utility be run. *

* Because this class (and it's assorted inner classes) may be bundled into the - * iPlanet Application Server distribution at some point (and removed from the - * Ant distribution), the class has been written to be independent of all - * Ant-specific classes. It is also for this reason (and to avoid cluttering - * the Apache Ant source files) that this utility has been packaged into a + * iPlanet Application Server distribution at some point (and removed from the + * Ant distribution), the class has been written to be independent of all + * Ant-specific classes. It is also for this reason (and to avoid cluttering + * the Apache Ant source files) that this utility has been packaged into a * single source file. *

- * For more information on Ant Tasks for iPlanet Application Server, see the + * For more information on Ant Tasks for iPlanet Application Server, see the * IPlanetDeploymentTool and IPlanetEjbcTask classes. * * @see IPlanetDeploymentTool @@ -105,692 +105,692 @@ import org.xml.sax.AttributeList; */ public class IPlanetEjbc { - /* Constants used for the "beantype" attribute */ - private final static String ENTITY_BEAN = "entity"; - private final static String STATELESS_SESSION = "stateless"; - private final static String STATEFUL_SESSION = "stateful"; - - /* Filenames of the standard EJB descriptor and the iAS-specific descriptor */ - private File stdDescriptor; - private File iasDescriptor; - - /* - * Directory where "source" EJB files are stored and where stubs and - * skeletons will also be written. - */ - private File destDirectory; - - /* Classpath used when the iAS ejbc is called */ - private String classpath; - private String[] classpathElements; - - /* Options passed to the iAS ejbc */ - private boolean retainSource = false; - private boolean debugOutput = false; - - /* iAS installation directory (used if ejbc isn't on user's PATH) */ - private File iasHomeDir; - - /* Parser and handler used to process both EJB descriptor files */ - private SAXParser parser; - private EjbcHandler handler = new EjbcHandler(); - - /* - * This Hashtable maintains a list of EJB class files processed by the ejbc - * utility (both "source" class files as well as stubs and skeletons). The - * key for the Hashtable is a String representing the path to the class file - * (relative to the destination directory). The value for the Hashtable is - * a File object which reference the actual class file. - */ - private Hashtable ejbFiles = new Hashtable(); - - /* Value of the display-name element read from the standard EJB descriptor */ - private String displayName; - - /** - * Constructs an instance which may be used to process EJB descriptors and - * generate EJB stubs and skeletons, if needed. - * - * @param stdDescriptor File referencing a standard EJB descriptor. - * @param iasDescriptor File referencing an iAS-specific EJB descriptor. - * @param destDirectory File referencing the base directory where both - * EJB "source" files are found and where stubs and - * skeletons will be written. - * @param classpath String representation of the classpath to be used - * by the iAS ejbc utility. - * @param parser SAXParser to be used to process both of the EJB - * descriptors. - */ - public IPlanetEjbc(File stdDescriptor, - File iasDescriptor, - File destDirectory, - String classpath, - SAXParser parser) { - this.stdDescriptor = stdDescriptor; - this.iasDescriptor = iasDescriptor; - this.destDirectory = destDirectory; - this.classpath = classpath; - this.parser = parser; - - /* - * Parse the classpath into it's individual elements and store the - * results in the "classpathElements" instance variable. - */ - List elements = new ArrayList(); - if (classpath != null) { - StringTokenizer st = new StringTokenizer(classpath, - File.pathSeparator); - while (st.hasMoreTokens()) { - elements.add(st.nextToken()); - } - classpathElements - = (String[])elements.toArray(new String[elements.size()]); - } - } + /* Constants used for the "beantype" attribute */ + private final static String ENTITY_BEAN = "entity"; + private final static String STATELESS_SESSION = "stateless"; + private final static String STATEFUL_SESSION = "stateful"; + + /* Filenames of the standard EJB descriptor and the iAS-specific descriptor */ + private File stdDescriptor; + private File iasDescriptor; + + /* + * Directory where "source" EJB files are stored and where stubs and + * skeletons will also be written. + */ + private File destDirectory; + + /* Classpath used when the iAS ejbc is called */ + private String classpath; + private String[] classpathElements; + + /* Options passed to the iAS ejbc */ + private boolean retainSource = false; + private boolean debugOutput = false; + + /* iAS installation directory (used if ejbc isn't on user's PATH) */ + private File iasHomeDir; + + /* Parser and handler used to process both EJB descriptor files */ + private SAXParser parser; + private EjbcHandler handler = new EjbcHandler(); + + /* + * This Hashtable maintains a list of EJB class files processed by the ejbc + * utility (both "source" class files as well as stubs and skeletons). The + * key for the Hashtable is a String representing the path to the class file + * (relative to the destination directory). The value for the Hashtable is + * a File object which reference the actual class file. + */ + private Hashtable ejbFiles = new Hashtable(); + + /* Value of the display-name element read from the standard EJB descriptor */ + private String displayName; + + /** + * Constructs an instance which may be used to process EJB descriptors and + * generate EJB stubs and skeletons, if needed. + * + * @param stdDescriptor File referencing a standard EJB descriptor. + * @param iasDescriptor File referencing an iAS-specific EJB descriptor. + * @param destDirectory File referencing the base directory where both + * EJB "source" files are found and where stubs and + * skeletons will be written. + * @param classpath String representation of the classpath to be used + * by the iAS ejbc utility. + * @param parser SAXParser to be used to process both of the EJB + * descriptors. + */ + public IPlanetEjbc(File stdDescriptor, + File iasDescriptor, + File destDirectory, + String classpath, + SAXParser parser) { + this.stdDescriptor = stdDescriptor; + this.iasDescriptor = iasDescriptor; + this.destDirectory = destDirectory; + this.classpath = classpath; + this.parser = parser; + + /* + * Parse the classpath into it's individual elements and store the + * results in the "classpathElements" instance variable. + */ + List elements = new ArrayList(); + if (classpath != null) { + StringTokenizer st = new StringTokenizer(classpath, + File.pathSeparator); + while (st.hasMoreTokens()) { + elements.add(st.nextToken()); + } + classpathElements + = (String[])elements.toArray(new String[elements.size()]); + } + } /** - * Sets whether or not the Java source files which are generated by the - * ejbc process should be retained or automatically deleted. - * - * @param retainsource A boolean indicating if the Java source files for - * the stubs and skeletons should be retained. + * Sets whether or not the Java source files which are generated by the + * ejbc process should be retained or automatically deleted. + * + * @param retainsource A boolean indicating if the Java source files for + * the stubs and skeletons should be retained. */ - public void setRetainSource(boolean retainSource) { - this.retainSource = retainSource; - } + public void setRetainSource(boolean retainSource) { + this.retainSource = retainSource; + } /** * Sets whether or not debugging output will be generated when ejbc is - * executed. - * - * @param debugOutput A boolean indicating if debugging output should be - * generated + * executed. + * + * @param debugOutput A boolean indicating if debugging output should be + * generated */ - public void setDebugOutput(boolean debugOutput) { - this.debugOutput = debugOutput; - } + public void setDebugOutput(boolean debugOutput) { + this.debugOutput = debugOutput; + } /** * Registers the location of a local DTD file or resource. By registering - * a local DTD, EJB descriptors can be parsed even when the remote servers - * which contain the "public" DTDs cannot be accessed. + * a local DTD, EJB descriptors can be parsed even when the remote servers + * which contain the "public" DTDs cannot be accessed. * * @param publicID The public DTD identifier found in an XML document. - * @param location The file or resource name for the appropriate DTD stored - * on the local machine. + * @param location The file or resource name for the appropriate DTD stored + * on the local machine. */ - public void registerDTD(String publicID, String location) { - handler.registerDTD(publicID, location); - } + public void registerDTD(String publicID, String location) { + handler.registerDTD(publicID, location); + } /** * Setter method used to store the "home" directory of the user's iAS - * installation. The directory specified should typically be - * [install-location]/iplanet/ias6/ias. - * + * installation. The directory specified should typically be + * [install-location]/iplanet/ias6/ias. + * * @param iashome The home directory for the user's iAS installation. */ - public void setIasHomeDir(File iasHomeDir) { - this.iasHomeDir = iasHomeDir; - } - - /** - * Returns a Hashtable which contains a list of EJB class files processed by - * the ejbc utility (both "source" class files as well as stubs and - * skeletons). The key for the Hashtable is a String representing the path - * to the class file (relative to the destination directory). The value for - * the Hashtable is a File object which reference the actual class file. - * - * @return The list of EJB files processed by the ejbc utility. - */ - public Hashtable getEjbFiles() { - return ejbFiles; - } - - /** - * Returns the display-name element read from the standard EJB descriptor. - * - * @return The EJB-JAR display name. - */ - public String getDisplayName() { - return displayName; - } - - /** - * Returns the list of CMP descriptors referenced in the EJB descriptors. - * - * @return An array of CMP descriptors. - */ - public String[] getCmpDescriptors() { - List returnList = new ArrayList(); - - EjbInfo[] ejbs = handler.getEjbs(); - - for (int i = 0; i < ejbs.length ; i++) { - List descriptors = (List) ejbs[i].getCmpDescriptors(); - returnList.addAll(descriptors); - } - - return (String[]) returnList.toArray(new String[returnList.size()]); - } - - /** - * Main application method for the iPlanet Application Server ejbc utility. - * If the application is run with no commandline arguments, a usage - * statement is printed for the user. - * - * @param args The commandline arguments passed to the application. - */ - public static void main(String[] args) { - File stdDescriptor; - File iasDescriptor; - File destDirectory = null; - String classpath = null; - SAXParser parser = null; - boolean debug = false; - boolean retainSource = false; - IPlanetEjbc ejbc; - - if ((args.length < 2) || (args.length > 8)) { - usage(); - return; - } - - stdDescriptor = new File(args[args.length - 2]); - iasDescriptor = new File(args[args.length - 1]); - - for (int i = 0; i < args.length - 2; i++) { - if (args[i].equals("-classpath")) { - classpath = args[++i]; - } else if (args[i].equals("-d")) { - destDirectory = new File(args[++i]); - } else if (args[i].equals("-debug")) { - debug = true; - } else if (args[i].equals("-keepsource")) { - retainSource = true; - } else { - usage(); - return; - } - } - - /* If the -classpath flag isn't specified, use the system classpath */ - if (classpath == null) { - Properties props = System.getProperties(); - classpath = props.getProperty("java.class.path"); - } - - /* - * If the -d flag isn't specified, use the working directory as the - * destination directory - */ - if (destDirectory == null) { - Properties props = System.getProperties(); - destDirectory = new File(props.getProperty("user.dir")); - } - - /* Construct a SAXParser used to process the descriptors */ - SAXParserFactory parserFactory = SAXParserFactory.newInstance(); - parserFactory.setValidating(true); - try { - parser = parserFactory.newSAXParser(); - } catch (Exception e) { - // SAXException or ParserConfigurationException may be thrown - System.out.println("An exception was generated while trying to "); - System.out.println("create a new SAXParser."); - e.printStackTrace(); - return; - } - - /* Build and populate an instance of the ejbc utility */ - ejbc = new IPlanetEjbc(stdDescriptor, iasDescriptor, destDirectory, - classpath, parser); - ejbc.setDebugOutput(debug); - ejbc.setRetainSource(retainSource); - - /* Execute the ejbc utility -- stubs/skeletons are rebuilt, if needed */ - try { - ejbc.execute(); - } catch (IOException e) { - System.out.println("An IOException has occurred while reading the " - + "XML descriptors (" + e.getMessage() + ")."); - return; - } catch (SAXException e) { - System.out.println("A SAXException has occurred while reading the " - + "XML descriptors (" + e.getMessage() + ")."); - return; - } catch (IPlanetEjbc.EjbcException e) { - System.out.println("An error has occurred while executing the ejbc " - + "utility (" + e.getMessage() + ")."); - return; - } - } - - /** - * Print a usage statement. - */ - private static void usage() { - System.out.println("java org.apache.tools.ant.taskdefs.optional.ejb.IPlanetEjbc \\"); - System.out.println(" [OPTIONS] [EJB 1.1 descriptor] [iAS EJB descriptor]"); - System.out.println(""); - System.out.println("Where OPTIONS are:"); - System.out.println(" -debug -- for additional debugging output"); - System.out.println(" -keepsource -- to retain Java source files generated"); - System.out.println(" -classpath [classpath] -- classpath used for compilation"); - System.out.println(" -d [destination directory] -- directory for compiled classes"); - System.out.println(""); - System.out.println("If a classpath is not specified, the system classpath"); - System.out.println("will be used. If a destination directory is not specified,"); - System.out.println("the current working directory will be used (classes will"); - System.out.println("still be placed in subfolders which correspond to their"); - System.out.println("package name)."); - System.out.println(""); - System.out.println("The EJB home interface, remote interface, and implementation"); - System.out.println("class must be found in the destination directory. In"); - System.out.println("addition, the destination will look for the stubs and skeletons"); - System.out.println("in the destination directory to ensure they are up to date."); - } - - /** - * Compiles the stub and skeletons for the specified EJBs, if they need to - * be updated. - * - * @throws EjbcException If the ejbc utility cannot be correctly configured - * or if one or more of the EJB "source" classes - * cannot be found in the destination directory + public void setIasHomeDir(File iasHomeDir) { + this.iasHomeDir = iasHomeDir; + } + + /** + * Returns a Hashtable which contains a list of EJB class files processed by + * the ejbc utility (both "source" class files as well as stubs and + * skeletons). The key for the Hashtable is a String representing the path + * to the class file (relative to the destination directory). The value for + * the Hashtable is a File object which reference the actual class file. + * + * @return The list of EJB files processed by the ejbc utility. + */ + public Hashtable getEjbFiles() { + return ejbFiles; + } + + /** + * Returns the display-name element read from the standard EJB descriptor. + * + * @return The EJB-JAR display name. + */ + public String getDisplayName() { + return displayName; + } + + /** + * Returns the list of CMP descriptors referenced in the EJB descriptors. + * + * @return An array of CMP descriptors. + */ + public String[] getCmpDescriptors() { + List returnList = new ArrayList(); + + EjbInfo[] ejbs = handler.getEjbs(); + + for (int i = 0; i < ejbs.length ; i++) { + List descriptors = (List) ejbs[i].getCmpDescriptors(); + returnList.addAll(descriptors); + } + + return (String[]) returnList.toArray(new String[returnList.size()]); + } + + /** + * Main application method for the iPlanet Application Server ejbc utility. + * If the application is run with no commandline arguments, a usage + * statement is printed for the user. + * + * @param args The commandline arguments passed to the application. + */ + public static void main(String[] args) { + File stdDescriptor; + File iasDescriptor; + File destDirectory = null; + String classpath = null; + SAXParser parser = null; + boolean debug = false; + boolean retainSource = false; + IPlanetEjbc ejbc; + + if ((args.length < 2) || (args.length > 8)) { + usage(); + return; + } + + stdDescriptor = new File(args[args.length - 2]); + iasDescriptor = new File(args[args.length - 1]); + + for (int i = 0; i < args.length - 2; i++) { + if (args[i].equals("-classpath")) { + classpath = args[++i]; + } else if (args[i].equals("-d")) { + destDirectory = new File(args[++i]); + } else if (args[i].equals("-debug")) { + debug = true; + } else if (args[i].equals("-keepsource")) { + retainSource = true; + } else { + usage(); + return; + } + } + + /* If the -classpath flag isn't specified, use the system classpath */ + if (classpath == null) { + Properties props = System.getProperties(); + classpath = props.getProperty("java.class.path"); + } + + /* + * If the -d flag isn't specified, use the working directory as the + * destination directory + */ + if (destDirectory == null) { + Properties props = System.getProperties(); + destDirectory = new File(props.getProperty("user.dir")); + } + + /* Construct a SAXParser used to process the descriptors */ + SAXParserFactory parserFactory = SAXParserFactory.newInstance(); + parserFactory.setValidating(true); + try { + parser = parserFactory.newSAXParser(); + } catch (Exception e) { + // SAXException or ParserConfigurationException may be thrown + System.out.println("An exception was generated while trying to "); + System.out.println("create a new SAXParser."); + e.printStackTrace(); + return; + } + + /* Build and populate an instance of the ejbc utility */ + ejbc = new IPlanetEjbc(stdDescriptor, iasDescriptor, destDirectory, + classpath, parser); + ejbc.setDebugOutput(debug); + ejbc.setRetainSource(retainSource); + + /* Execute the ejbc utility -- stubs/skeletons are rebuilt, if needed */ + try { + ejbc.execute(); + } catch (IOException e) { + System.out.println("An IOException has occurred while reading the " + + "XML descriptors (" + e.getMessage() + ")."); + return; + } catch (SAXException e) { + System.out.println("A SAXException has occurred while reading the " + + "XML descriptors (" + e.getMessage() + ")."); + return; + } catch (IPlanetEjbc.EjbcException e) { + System.out.println("An error has occurred while executing the ejbc " + + "utility (" + e.getMessage() + ")."); + return; + } + } + + /** + * Print a usage statement. + */ + private static void usage() { + System.out.println("java org.apache.tools.ant.taskdefs.optional.ejb.IPlanetEjbc \\"); + System.out.println(" [OPTIONS] [EJB 1.1 descriptor] [iAS EJB descriptor]"); + System.out.println(""); + System.out.println("Where OPTIONS are:"); + System.out.println(" -debug -- for additional debugging output"); + System.out.println(" -keepsource -- to retain Java source files generated"); + System.out.println(" -classpath [classpath] -- classpath used for compilation"); + System.out.println(" -d [destination directory] -- directory for compiled classes"); + System.out.println(""); + System.out.println("If a classpath is not specified, the system classpath"); + System.out.println("will be used. If a destination directory is not specified,"); + System.out.println("the current working directory will be used (classes will"); + System.out.println("still be placed in subfolders which correspond to their"); + System.out.println("package name)."); + System.out.println(""); + System.out.println("The EJB home interface, remote interface, and implementation"); + System.out.println("class must be found in the destination directory. In"); + System.out.println("addition, the destination will look for the stubs and skeletons"); + System.out.println("in the destination directory to ensure they are up to date."); + } + + /** + * Compiles the stub and skeletons for the specified EJBs, if they need to + * be updated. + * + * @throws EjbcException If the ejbc utility cannot be correctly configured + * or if one or more of the EJB "source" classes + * cannot be found in the destination directory * @throws IOException If the parser encounters a problem reading the XML - * file - * @throws SAXException If the parser encounters a problem processing the - * XML descriptor (it may wrap another exception) + * file + * @throws SAXException If the parser encounters a problem processing the + * XML descriptor (it may wrap another exception) */ - public void execute() throws EjbcException, IOException, SAXException { + public void execute() throws EjbcException, IOException, SAXException { - checkConfiguration(); // Throws EjbcException if unsuccessful + checkConfiguration(); // Throws EjbcException if unsuccessful - EjbInfo[] ejbs = getEjbs(); // Returns list of EJBs for processing + EjbInfo[] ejbs = getEjbs(); // Returns list of EJBs for processing + + for (int i = 0; i < ejbs.length ; i++) { + log("EJBInfo..."); + log(ejbs[i].toString()); + } - for (int i = 0; i < ejbs.length ; i++) { - log("EJBInfo..."); - log(ejbs[i].toString()); - } - - for (int i=0; i < ejbs.length; i++) { - EjbInfo ejb = ejbs[i]; + for (int i=0; i < ejbs.length; i++) { + EjbInfo ejb = ejbs[i]; - ejb.checkConfiguration(destDirectory); // Throws EjbcException + ejb.checkConfiguration(destDirectory); // Throws EjbcException - if (ejb.mustBeRecompiled(destDirectory)) { - log(ejb.getName() + " must be recompiled using ejbc."); + if (ejb.mustBeRecompiled(destDirectory)) { + log(ejb.getName() + " must be recompiled using ejbc."); - String[] arguments = buildArgumentList(ejb); - callEjbc(arguments); + String[] arguments = buildArgumentList(ejb); + callEjbc(arguments); - } else { - log(ejb.getName() + " is up to date."); - } - } - } + } else { + log(ejb.getName() + " is up to date."); + } + } + } - /** + /** * Executes the iPlanet Application Server ejbc command-line utility. - * - * @param arguments Command line arguments to be passed to the ejbc utility. + * + * @param arguments Command line arguments to be passed to the ejbc utility. */ - private void callEjbc(String[] arguments) { - - /* Concatenate all of the command line arguments into a single String */ - StringBuffer args = new StringBuffer(); - for (int i = 0; i < arguments.length; i++) { - args.append(arguments[i]).append(" "); - } - - /* If an iAS home directory is specified, prepend it to the commmand */ - String command; - if (iasHomeDir == null) { - command = ""; - } else { - command = iasHomeDir.toString() + File.separator + "bin" - + File.separator; - } - command += "ejbc "; - - log(command + args); - - /* - * Use the Runtime object to execute an external command. Use the - * RedirectOutput inner class to direct the standard and error output - * from the command to the JRE's standard output - */ - try { - Process p = Runtime.getRuntime().exec(command + args); - RedirectOutput output = new RedirectOutput(p.getInputStream()); - RedirectOutput error = new RedirectOutput(p.getErrorStream()); - output.start(); - error.start(); - p.waitFor(); - p.destroy(); - } catch (IOException e) { - log("An IOException has occurred while trying to execute ejbc."); - e.printStackTrace(); - } catch (InterruptedException e) { - // Do nothing - } - } + private void callEjbc(String[] arguments) { + + /* Concatenate all of the command line arguments into a single String */ + StringBuffer args = new StringBuffer(); + for (int i = 0; i < arguments.length; i++) { + args.append(arguments[i]).append(" "); + } + + /* If an iAS home directory is specified, prepend it to the commmand */ + String command; + if (iasHomeDir == null) { + command = ""; + } else { + command = iasHomeDir.toString() + File.separator + "bin" + + File.separator; + } + command += "ejbc "; + + log(command + args); + + /* + * Use the Runtime object to execute an external command. Use the + * RedirectOutput inner class to direct the standard and error output + * from the command to the JRE's standard output + */ + try { + Process p = Runtime.getRuntime().exec(command + args); + RedirectOutput output = new RedirectOutput(p.getInputStream()); + RedirectOutput error = new RedirectOutput(p.getErrorStream()); + output.start(); + error.start(); + p.waitFor(); + p.destroy(); + } catch (IOException e) { + log("An IOException has occurred while trying to execute ejbc."); + e.printStackTrace(); + } catch (InterruptedException e) { + // Do nothing + } + } /** * Verifies that the user selections are valid. - * - * @throws EjbcException If the user selections are invalid. + * + * @throws EjbcException If the user selections are invalid. */ - protected void checkConfiguration() throws EjbcException { - - String msg = ""; - - if (stdDescriptor == null) { - msg += "A standard XML descriptor file must be specified. "; - } - if (iasDescriptor == null) { - msg += "An iAS-specific XML descriptor file must be specified. "; - } - if (classpath == null) { - msg += "A classpath must be specified. "; - } - if (parser == null) { - msg += "An XML parser must be specified. "; - } - - if (destDirectory == null) { - msg += "A destination directory must be specified. "; - } else if (!destDirectory.exists()) { - msg += "The destination directory specified does not exist. "; - } else if (!destDirectory.isDirectory()) { - msg += "The destination specified is not a directory. "; - } - - if (msg.length() > 0) { - throw new EjbcException(msg); - } - } + protected void checkConfiguration() throws EjbcException { + + String msg = ""; + + if (stdDescriptor == null) { + msg += "A standard XML descriptor file must be specified. "; + } + if (iasDescriptor == null) { + msg += "An iAS-specific XML descriptor file must be specified. "; + } + if (classpath == null) { + msg += "A classpath must be specified. "; + } + if (parser == null) { + msg += "An XML parser must be specified. "; + } + + if (destDirectory == null) { + msg += "A destination directory must be specified. "; + } else if (!destDirectory.exists()) { + msg += "The destination directory specified does not exist. "; + } else if (!destDirectory.isDirectory()) { + msg += "The destination specified is not a directory. "; + } + + if (msg.length() > 0) { + throw new EjbcException(msg); + } + } /** * Parses the EJB descriptors and returns a list of EJBs which may need to - * be compiled. - * - * @return An array of objects which describe the EJBs to be - * processed. + * be compiled. + * + * @return An array of objects which describe the EJBs to be + * processed. * @throws IOException If the parser encounters a problem reading the XML - * files - * @throws SAXException If the parser encounters a problem processing the - * XML descriptor (it may wrap another exception) - */ - private EjbInfo[] getEjbs() throws IOException, SAXException { - EjbInfo[] ejbs = null; + * files + * @throws SAXException If the parser encounters a problem processing the + * XML descriptor (it may wrap another exception) + */ + private EjbInfo[] getEjbs() throws IOException, SAXException { + EjbInfo[] ejbs = null; - /* - * The EJB information is gathered from the standard XML EJB descriptor - * and the iAS-specific XML EJB descriptor using a SAX parser. - */ + /* + * The EJB information is gathered from the standard XML EJB descriptor + * and the iAS-specific XML EJB descriptor using a SAX parser. + */ - parser.parse(stdDescriptor, handler); - parser.parse(iasDescriptor, handler); - ejbs = handler.getEjbs(); + parser.parse(stdDescriptor, handler); + parser.parse(iasDescriptor, handler); + ejbs = handler.getEjbs(); - return ejbs; - } + return ejbs; + } /** * Based on this object's instance variables as well as the EJB to be - * processed, the correct flags and parameters are set for the ejbc - * command-line utility. - * @param ejb The EJB for which stubs and skeletons will be compiled. - * @return An array of Strings which are the command-line parameters for - * for the ejbc utility. - */ + * processed, the correct flags and parameters are set for the ejbc + * command-line utility. + * @param ejb The EJB for which stubs and skeletons will be compiled. + * @return An array of Strings which are the command-line parameters for + * for the ejbc utility. + */ private String[] buildArgumentList(EjbInfo ejb) { - List arguments = new ArrayList(); + List arguments = new ArrayList(); - /* OPTIONAL COMMAND LINE PARAMETERS */ + /* OPTIONAL COMMAND LINE PARAMETERS */ - if (debugOutput) { - arguments.add("-debug"); - } + if (debugOutput) { + arguments.add("-debug"); + } - /* No beantype flag is needed for an entity bean */ - if (ejb.getBeantype().equals(STATELESS_SESSION)) { - arguments.add("-sl"); - } else if (ejb.getBeantype().equals(STATEFUL_SESSION)) { - arguments.add("-sf"); - } + /* No beantype flag is needed for an entity bean */ + if (ejb.getBeantype().equals(STATELESS_SESSION)) { + arguments.add("-sl"); + } else if (ejb.getBeantype().equals(STATEFUL_SESSION)) { + arguments.add("-sf"); + } - if (ejb.getIiop()) { - arguments.add("-iiop"); - } + if (ejb.getIiop()) { + arguments.add("-iiop"); + } - if (ejb.getCmp()) { - arguments.add("-cmp"); - } + if (ejb.getCmp()) { + arguments.add("-cmp"); + } - if (retainSource) { - arguments.add("-gs"); - } + if (retainSource) { + arguments.add("-gs"); + } - if (ejb.getHasession()) { - arguments.add("-fo"); - } + if (ejb.getHasession()) { + arguments.add("-fo"); + } - /* REQUIRED COMMAND LINE PARAMETERS */ + /* REQUIRED COMMAND LINE PARAMETERS */ - arguments.add("-classpath"); - arguments.add(classpath); + arguments.add("-classpath"); + arguments.add(classpath); - arguments.add("-d"); - arguments.add(destDirectory.toString()); + arguments.add("-d"); + arguments.add(destDirectory.toString()); - arguments.add(ejb.getHome().getQualifiedClassName()); - arguments.add(ejb.getRemote().getQualifiedClassName()); - arguments.add(ejb.getImplementation().getQualifiedClassName()); + arguments.add(ejb.getHome().getQualifiedClassName()); + arguments.add(ejb.getRemote().getQualifiedClassName()); + arguments.add(ejb.getImplementation().getQualifiedClassName()); - /* Convert the List into an Array and return it */ - return (String[])arguments.toArray(new String[arguments.size()]); - } + /* Convert the List into an Array and return it */ + return (String[])arguments.toArray(new String[arguments.size()]); + } /** * Convenience method used to print messages to the user if debugging - * messages are enabled. - * - * @param msg The String to print to standard output. - */ - private void log(String msg) { - if (debugOutput) { - System.out.println(msg); - } - } - - - /* Inner classes follow */ - - - /** - * This inner class is used to signal any problems during the execution of - * the ejbc compiler. - * - * @author Greg Nelson - * greg@netscape.com - */ - public class EjbcException extends Exception { - - /** - * Constructs an exception with the given descriptive message. - * - * @param msg Description of the exception which has occurred. - */ - public EjbcException(String msg) { - super(msg); - } - } // End of EjbcException inner class - - - /** - * This inner class is an XML document handler that can be used to parse EJB - * descriptors (both the standard EJB descriptor as well as the iAS-specific - * descriptor that stores additional values for iAS). Once the descriptors - * have been processed, the list of EJBs found can be obtained by calling - * the getEjbs() method. - * - * @see EjbInfo - * @author Greg Nelson - * greg@netscape.com - */ + * messages are enabled. + * + * @param msg The String to print to standard output. + */ + private void log(String msg) { + if (debugOutput) { + System.out.println(msg); + } + } + + + /* Inner classes follow */ + + + /** + * This inner class is used to signal any problems during the execution of + * the ejbc compiler. + * + * @author Greg Nelson + * greg@netscape.com + */ + public class EjbcException extends Exception { + + /** + * Constructs an exception with the given descriptive message. + * + * @param msg Description of the exception which has occurred. + */ + public EjbcException(String msg) { + super(msg); + } + } // End of EjbcException inner class + + + /** + * This inner class is an XML document handler that can be used to parse EJB + * descriptors (both the standard EJB descriptor as well as the iAS-specific + * descriptor that stores additional values for iAS). Once the descriptors + * have been processed, the list of EJBs found can be obtained by calling + * the getEjbs() method. + * + * @see EjbInfo + * @author Greg Nelson + * greg@netscape.com + */ private class EjbcHandler extends HandlerBase { - /* - * Two Maps are used to track local DTDs that will be used in case the - * remote copies of these DTDs cannot be accessed. The key for the Map - * is the DTDs public ID and the value is the local location for the DTD - */ - private Map resourceDtds = new HashMap(); - private Map fileDtds = new HashMap(); + /* + * Two Maps are used to track local DTDs that will be used in case the + * remote copies of these DTDs cannot be accessed. The key for the Map + * is the DTDs public ID and the value is the local location for the DTD + */ + private Map resourceDtds = new HashMap(); + private Map fileDtds = new HashMap(); - private Map ejbs = new HashMap(); // List of EJBs found in XML - private EjbInfo currentEjb; // One item within the Map + private Map ejbs = new HashMap(); // List of EJBs found in XML + private EjbInfo currentEjb; // One item within the Map private boolean iasDescriptor = false; // Is doc iAS or EJB descriptor - private String currentLoc = ""; // Tracks current element - private String currentText; // Tracks current text data - private String ejbType; // "session" or "entity" - - /** - * Constructs a new instance of the handler and registers local copies - * of the standard EJB 1.1 descriptor DTD as well as iAS's EJB - * descriptor DTD. - */ - public EjbcHandler() { - final String PUBLICID_EJB11 = - "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN"; - final String PUBLICID_IPLANET_EJB_60 = - "-//Sun Microsystems, Inc.//DTD iAS Enterprise JavaBeans 1.0//EN"; - - - final String DEFAULT_IAS60_EJB11_DTD_LOCATION = - "ejb-jar_1_1.dtd"; - final String DEFAULT_IAS60_DTD_LOCATION = - "IASEjb_jar_1_0.dtd"; - - registerDTD(PUBLICID_EJB11, DEFAULT_IAS60_EJB11_DTD_LOCATION); - registerDTD(PUBLICID_IPLANET_EJB_60, DEFAULT_IAS60_DTD_LOCATION); - } - - /** - * Returns the list of EJB objects found during the processing of the - * standard EJB 1.1 descriptor and iAS-specific EJB descriptor. - * - * @return An array of EJBs which were found during the descriptor - * parsing. - */ - public EjbInfo[] getEjbs() { - return (EjbInfo[])ejbs.values().toArray(new EjbInfo[ejbs.size()]); - } - - /** - * Returns the value of the display-name element found in the standard - * EJB 1.1 descriptor. - * - * @return String display-name value. - */ - public String getDisplayName() { - return displayName; - } - - /** - * Registers a local DTD that will be used when parsing an EJB - * descriptor. When the DTD's public identifier is found in an XML - * document, the parser will reference the local DTD rather than the - * remote DTD. This enables XML documents to be processed even when the - * public DTD isn't available. - * - * @param publicID The DTD's public identifier. - * @param location The location of the local DTD copy -- the location - * may either be a resource found on the classpath or a - * local file. - */ - public void registerDTD(String publicID, String location) { - log("Registering: " + location); - if ((publicID == null) || (location == null)) { - return; - } - - if (ClassLoader.getSystemResource(location) != null) { - log("Found resource: " + location); - resourceDtds.put(publicID, location); - } else { - File dtdFile = new File(location); - if (dtdFile.exists() && dtdFile.isFile()) { - log("Found file: " + location); - fileDtds.put(publicID, location); - } - } - } - - /** - * Resolves an external entity found during XML processing. If a public - * ID is found that has been registered with the handler, an - * InputSource will be returned which refers to the local copy. - * If the public ID hasn't been registered or if an error occurs, the - * superclass implementation is used. - * - * @param publicId The DTD's public identifier. - * @param systemId The location of the DTD, as found in the XML document. - */ - public InputSource resolveEntity(String publicId, String systemId) - throws SAXException { - InputStream inputStream = null; - - - try { - - /* Search the resource Map and (if not found) file Map */ - - String location = (String)resourceDtds.get(publicId); - if (location != null) { - inputStream - = ClassLoader.getSystemResource(location).openStream(); - } else { - location = (String)fileDtds.get(publicId); - if (location != null) { - inputStream = new FileInputStream(location); - } - } - } catch (IOException e) { - return super.resolveEntity(publicId, systemId); - } - - if (inputStream == null) { - return super.resolveEntity(publicId, systemId); - } else { - return new InputSource(inputStream); - } - } - - /** - * Receive notification that the start of an XML element has been found. - * - * @param name String name of the element found. - * @param atts AttributeList of the attributes included with the element - * (if any). - * @throws SAXException If the parser cannot process the document. - */ - public void startElement(String name, AttributeList atts) + private String currentLoc = ""; // Tracks current element + private String currentText; // Tracks current text data + private String ejbType; // "session" or "entity" + + /** + * Constructs a new instance of the handler and registers local copies + * of the standard EJB 1.1 descriptor DTD as well as iAS's EJB + * descriptor DTD. + */ + public EjbcHandler() { + final String PUBLICID_EJB11 = + "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN"; + final String PUBLICID_IPLANET_EJB_60 = + "-//Sun Microsystems, Inc.//DTD iAS Enterprise JavaBeans 1.0//EN"; + + + final String DEFAULT_IAS60_EJB11_DTD_LOCATION = + "ejb-jar_1_1.dtd"; + final String DEFAULT_IAS60_DTD_LOCATION = + "IASEjb_jar_1_0.dtd"; + + registerDTD(PUBLICID_EJB11, DEFAULT_IAS60_EJB11_DTD_LOCATION); + registerDTD(PUBLICID_IPLANET_EJB_60, DEFAULT_IAS60_DTD_LOCATION); + } + + /** + * Returns the list of EJB objects found during the processing of the + * standard EJB 1.1 descriptor and iAS-specific EJB descriptor. + * + * @return An array of EJBs which were found during the descriptor + * parsing. + */ + public EjbInfo[] getEjbs() { + return (EjbInfo[])ejbs.values().toArray(new EjbInfo[ejbs.size()]); + } + + /** + * Returns the value of the display-name element found in the standard + * EJB 1.1 descriptor. + * + * @return String display-name value. + */ + public String getDisplayName() { + return displayName; + } + + /** + * Registers a local DTD that will be used when parsing an EJB + * descriptor. When the DTD's public identifier is found in an XML + * document, the parser will reference the local DTD rather than the + * remote DTD. This enables XML documents to be processed even when the + * public DTD isn't available. + * + * @param publicID The DTD's public identifier. + * @param location The location of the local DTD copy -- the location + * may either be a resource found on the classpath or a + * local file. + */ + public void registerDTD(String publicID, String location) { + log("Registering: " + location); + if ((publicID == null) || (location == null)) { + return; + } + + if (ClassLoader.getSystemResource(location) != null) { + log("Found resource: " + location); + resourceDtds.put(publicID, location); + } else { + File dtdFile = new File(location); + if (dtdFile.exists() && dtdFile.isFile()) { + log("Found file: " + location); + fileDtds.put(publicID, location); + } + } + } + + /** + * Resolves an external entity found during XML processing. If a public + * ID is found that has been registered with the handler, an + * InputSource will be returned which refers to the local copy. + * If the public ID hasn't been registered or if an error occurs, the + * superclass implementation is used. + * + * @param publicId The DTD's public identifier. + * @param systemId The location of the DTD, as found in the XML document. + */ + public InputSource resolveEntity(String publicId, String systemId) + throws SAXException { + InputStream inputStream = null; + + + try { + + /* Search the resource Map and (if not found) file Map */ + + String location = (String)resourceDtds.get(publicId); + if (location != null) { + inputStream + = ClassLoader.getSystemResource(location).openStream(); + } else { + location = (String)fileDtds.get(publicId); + if (location != null) { + inputStream = new FileInputStream(location); + } + } + } catch (IOException e) { + return super.resolveEntity(publicId, systemId); + } + + if (inputStream == null) { + return super.resolveEntity(publicId, systemId); + } else { + return new InputSource(inputStream); + } + } + + /** + * Receive notification that the start of an XML element has been found. + * + * @param name String name of the element found. + * @param atts AttributeList of the attributes included with the element + * (if any). + * @throws SAXException If the parser cannot process the document. + */ + public void startElement(String name, AttributeList atts) throws SAXException { - /* - * I need to "push" the element onto the String (currentLoc) which - * always represents the current location in the XML document. - */ - currentLoc += "\\" + name; + /* + * I need to "push" the element onto the String (currentLoc) which + * always represents the current location in the XML document. + */ + currentLoc += "\\" + name; - /* A new element has started, so reset the text being captured */ - currentText = ""; + /* A new element has started, so reset the text being captured */ + currentText = ""; if (currentLoc.equals("\\ejb-jar")) { iasDescriptor = false; @@ -801,47 +801,47 @@ public class IPlanetEjbc { if ((name.equals("session")) || (name.equals("entity"))) { ejbType = name; } - } - - /** - * Receive notification that character data has been found in the XML - * document - * - * @param ch Array of characters which have been found in the document. - * @param start Starting index of the data found in the document. - * @param len The number of characters found in the document. - * @throws SAXException If the parser cannot process the document. - */ - public void characters(char[] ch, int start, int len) - throws SAXException { + } + + /** + * Receive notification that character data has been found in the XML + * document + * + * @param ch Array of characters which have been found in the document. + * @param start Starting index of the data found in the document. + * @param len The number of characters found in the document. + * @throws SAXException If the parser cannot process the document. + */ + public void characters(char[] ch, int start, int len) + throws SAXException { currentText += new String(ch).substring(start, start + len); } - /** - * Receive notification that the end of an XML element has been found. - * - * @param name String name of the element. - * @throws SAXException If the parser cannot process the document. - */ + /** + * Receive notification that the end of an XML element has been found. + * + * @param name String name of the element. + * @throws SAXException If the parser cannot process the document. + */ public void endElement(String name) throws SAXException { - - /* - * If this is a standard EJB 1.1 descriptor, we are looking for one - * set of data, while if this is an iAS-specific descriptor, we're - * looking for different set of data. Hand the processing off to - * the appropriate method. - */ + + /* + * If this is a standard EJB 1.1 descriptor, we are looking for one + * set of data, while if this is an iAS-specific descriptor, we're + * looking for different set of data. Hand the processing off to + * the appropriate method. + */ if (iasDescriptor) { iasCharacters(currentText); } else { stdCharacters(currentText); } - /* - * I need to "pop" the element off the String (currentLoc) which - * always represents my current location in the XML document. - */ + /* + * I need to "pop" the element off the String (currentLoc) which + * always represents my current location in the XML document. + */ int nameLength = name.length() + 1; // Add one for the "\" int locLength = currentLoc.length(); @@ -849,20 +849,20 @@ public class IPlanetEjbc { currentLoc = currentLoc.substring(0, locLength - nameLength); } - /** - * Receive notification that character data has been found in a standard - * EJB 1.1 descriptor. We're interested in retrieving the home - * interface, remote interface, implementation class, the type of bean, - * and if the bean uses CMP. - * - * @param value String data found in the XML document. - */ + /** + * Receive notification that character data has been found in a standard + * EJB 1.1 descriptor. We're interested in retrieving the home + * interface, remote interface, implementation class, the type of bean, + * and if the bean uses CMP. + * + * @param value String data found in the XML document. + */ private void stdCharacters(String value) { - if (currentLoc.equals("\\ejb-jar\\display-name")) { - displayName = value; - return; - } + if (currentLoc.equals("\\ejb-jar\\display-name")) { + displayName = value; + return; + } String base = "\\ejb-jar\\enterprise-beans\\" + ejbType; @@ -885,16 +885,16 @@ public class IPlanetEjbc { } } - /** - * Receive notification that character data has been found in an - * iAS-specific descriptor. We're interested in retrieving data - * indicating whether the bean must support RMI/IIOP access, whether - * the bean must provide highly available stubs and skeletons (in the - * case of stateful session beans), and if this bean uses additional - * CMP XML descriptors (in the case of entity beans with CMP). - * - * @param value String data found in the XML document. - */ + /** + * Receive notification that character data has been found in an + * iAS-specific descriptor. We're interested in retrieving data + * indicating whether the bean must support RMI/IIOP access, whether + * the bean must provide highly available stubs and skeletons (in the + * case of stateful session beans), and if this bean uses additional + * CMP XML descriptors (in the case of entity beans with CMP). + * + * @param value String data found in the XML document. + */ private void iasCharacters(String value) { String base = "\\ias-ejb-jar\\enterprise-beans\\" + ejbType; @@ -909,72 +909,72 @@ public class IPlanetEjbc { } else if (currentLoc.equals(base + "\\failover-required")) { currentEjb.setHasession(value); } else if (currentLoc.equals(base + "\\persistence-manager" - + "\\properties-file-location")) { - currentEjb.addCmpDescriptor(value); - } + + "\\properties-file-location")) { + currentEjb.addCmpDescriptor(value); + } } } // End of EjbcHandler inner class - /** - * This inner class represents an EJB that will be compiled using ejbc. - * - * @author Greg Nelson - * greg@netscape.com - */ + /** + * This inner class represents an EJB that will be compiled using ejbc. + * + * @author Greg Nelson + * greg@netscape.com + */ private class EjbInfo { - private String name; // EJB's display name - private Classname home; // EJB's home interface name - private Classname remote; // EJB's remote interface name - private Classname implementation; // EJB's implementation class + private String name; // EJB's display name + private Classname home; // EJB's home interface name + private Classname remote; // EJB's remote interface name + private Classname implementation; // EJB's implementation class private String beantype = "entity"; // or "stateful" or "stateless" - private boolean cmp = false; // Does this EJB support CMP? - private boolean iiop = false; // Does this EJB support IIOP? - private boolean hasession = false; // Does this EJB require failover? - private List cmpDescriptors = new ArrayList(); // CMP descriptor list - - /** - * Construct a new EJBInfo object with the given name. - * - * @param name The display name for the EJB. - */ - public EjbInfo(String name) { + private boolean cmp = false; // Does this EJB support CMP? + private boolean iiop = false; // Does this EJB support IIOP? + private boolean hasession = false; // Does this EJB require failover? + private List cmpDescriptors = new ArrayList(); // CMP descriptor list + + /** + * Construct a new EJBInfo object with the given name. + * + * @param name The display name for the EJB. + */ + public EjbInfo(String name) { this.name = name; } - /** - * Returns the display name of the EJB. If a display name has not been - * set, it returns the EJB implementation classname (if the - * implementation class is not set, it returns "[unnamed]"). - * - * @return The display name for the EJB. - */ + /** + * Returns the display name of the EJB. If a display name has not been + * set, it returns the EJB implementation classname (if the + * implementation class is not set, it returns "[unnamed]"). + * + * @return The display name for the EJB. + */ public String getName() { - if (name == null) { - if (implementation == null) { - return "[unnamed]"; - } else { - return implementation.getClassName(); - } - } + if (name == null) { + if (implementation == null) { + return "[unnamed]"; + } else { + return implementation.getClassName(); + } + } return name; } - /* - * Below are getter's and setter's for each of the instance variables. - * Note that (in addition to supporting setters with the same type as - * the instance variable) a setter is provided with takes a String - * argument -- this are provided so the XML document handler can set - * the EJB values using the Strings it parses. - */ + /* + * Below are getter's and setter's for each of the instance variables. + * Note that (in addition to supporting setters with the same type as + * the instance variable) a setter is provided with takes a String + * argument -- this are provided so the XML document handler can set + * the EJB values using the Strings it parses. + */ public void setHome(String home) { setHome(new Classname(home)); } - public void setHome(Classname home) { - this.home = home; - } + public void setHome(Classname home) { + this.home = home; + } public Classname getHome() { return home; @@ -984,9 +984,9 @@ public class IPlanetEjbc { setRemote(new Classname(remote)); } - public void setRemote(Classname remote) { - this.remote = remote; - } + public void setRemote(Classname remote) { + this.remote = remote; + } public Classname getRemote() { return remote; @@ -996,9 +996,9 @@ public class IPlanetEjbc { setImplementation(new Classname(implementation)); } - public void setImplementation(Classname implementation) { - this.implementation = implementation; - } + public void setImplementation(Classname implementation) { + this.implementation = implementation; + } public Classname getImplementation() { return implementation; @@ -1048,442 +1048,441 @@ public class IPlanetEjbc { return hasession; } - public void addCmpDescriptor(String descriptor) { - cmpDescriptors.add(descriptor); - } - - public List getCmpDescriptors() { - return cmpDescriptors; - } - - /** - * Verifies that the EJB is valid--if it is invalid, an exception is - * thrown - * - * - * @param buildDir The directory where the EJB remote interface, home - * interface, and implementation class must be found. - * @throws EjbcException If the EJB is invalid. - */ - private void checkConfiguration(File buildDir) throws EjbcException { - - /* Check that the specified instance variables are valid */ - if (home == null) { - throw new EjbcException("A home interface was not found " - + "for the " + name + " EJB."); - } - if (remote == null) { - throw new EjbcException("A remote interface was not found " - + "for the " + name + " EJB."); - } - if (implementation == null) { - throw new EjbcException("An EJB implementation class was not " - + "found for the " + name + " EJB."); - } - - if ((!beantype.equals(ENTITY_BEAN)) - && (!beantype.equals(STATELESS_SESSION)) - && (!beantype.equals(STATEFUL_SESSION))) { - throw new EjbcException("The beantype found (" + beantype + ") " - + "isn't valid in the " + name + " EJB."); - } - - if (cmp && (!beantype.equals(ENTITY_BEAN))) { - System.out.println("CMP stubs and skeletons may not be generated" - + " for a Session Bean -- the \"cmp\" attribute will be" - + " ignoredfor the " + name + " EJB."); - } - - if (hasession && (!beantype.equals(STATEFUL_SESSION))) { - System.out.println("Highly available stubs and skeletons may " - + "only be generated for a Stateful Session Bean -- the " - + "\"hasession\" attribute will be ignored for the " - + name + " EJB."); - } - - /* Check that the EJB "source" classes all exist */ - if (!remote.getClassFile(buildDir).exists()) { - throw new EjbcException("The remote interface " - + remote.getQualifiedClassName() + " could not be " - + "found."); - } - if (!home.getClassFile(buildDir).exists()) { - throw new EjbcException("The home interface " - + home.getQualifiedClassName() + " could not be " - + "found."); - } - if (!implementation.getClassFile(buildDir).exists()) { - throw new EjbcException("The EJB implementation class " - + implementation.getQualifiedClassName() + " could " - + "not be found."); - } - } - - /** - * Determines if the ejbc utility needs to be run or not. If the stubs - * and skeletons can all be found in the destination directory AND all - * of their timestamps are more recent than the EJB source classes - * (home, remote, and implementation classes), the method returns - * false. Otherwise, the method returns true. - * - * @param destDir The directory where the EJB source classes, stubs and - * skeletons are located. - * @return A boolean indicating whether or not the ejbc utility needs to - * be run to bring the stubs and skeletons up to date. - */ - public boolean mustBeRecompiled(File destDir) { - - long sourceModified = sourceClassesModified(destDir); - - long destModified = destClassesModified(destDir); - - return (destModified < sourceModified); - } - - /** - * Examines each of the EJB source classes (home, remote, and - * implementation) and returns the modification timestamp for the - * "oldest" class. - * - * @param classpath The classpath to be used to find the source EJB - * classes. If null, the system classpath - * is used. - * @return The modification timestamp for the "oldest" EJB source class. - * @throws BuildException If one of the EJB source classes cannot be - * found on the classpath. - */ - private long sourceClassesModified(File buildDir) { - long latestModified; // The timestamp of the "newest" class - long modified; // Timestamp for a given class - File remoteFile; // File for the remote interface class - File homeFile; // File for the home interface class - File implFile; // File for the EJB implementation class - - /* Check the timestamp on the remote interface */ - remoteFile = remote.getClassFile(buildDir); - modified = remoteFile.lastModified(); - if (modified == -1) { - System.out.println("The class " - + remote.getQualifiedClassName() + " couldn't " - + "be found on the classpath"); - return -1; - } - latestModified = modified; - - /* Check the timestamp on the home interface */ - homeFile = home.getClassFile(buildDir); - modified = homeFile.lastModified(); - if (modified == -1) { - System.out.println("The class " - + home.getQualifiedClassName() + " couldn't be " - + "found on the classpath"); - return -1; - } - latestModified = Math.max(latestModified, modified); - - /* Check the timestamp on the EJB implementation class. - * - * Note that if ONLY the implementation class has changed, it's not - * necessary to rebuild the EJB stubs and skeletons. For this - * reason, we ensure the file exists (using lastModified above), but - * we DON'T compare it's timestamp with the timestamps of the home - * and remote interfaces (because it's irrelevant in determining if - * ejbc must be run) - */ - implFile = implementation.getClassFile(buildDir); - modified = implFile.lastModified(); - if (modified == -1) { - System.out.println("The class " - + implementation.getQualifiedClassName() - + " couldn't be found on the classpath"); - return -1; - } - - String pathToFile = remote.getQualifiedClassName(); - pathToFile = pathToFile.replace('.', File.separatorChar) + ".class"; - ejbFiles.put(pathToFile, remoteFile); - - pathToFile = home.getQualifiedClassName(); - pathToFile = pathToFile.replace('.', File.separatorChar) + ".class"; - ejbFiles.put(pathToFile, homeFile); - - pathToFile = implementation.getQualifiedClassName(); - pathToFile = pathToFile.replace('.', File.separatorChar) + ".class"; - ejbFiles.put(pathToFile, implFile); - - return latestModified; - } - - /** - * Examines each of the EJB stubs and skeletons in the destination - * directory and returns the modification timestamp for the "oldest" - * class. If one of the stubs or skeletons cannot be found, -1 - * is returned. - * - * @param dest The directory in which the EJB stubs and skeletons are - * stored. - * @return The modification timestamp for the "oldest" EJB stub or - * skeleton. If one of the classes cannot be found, -1 - * is returned. - * @throws BuildException If the canonical path of the destination - * directory cannot be found. - */ - private long destClassesModified(File destDir) { - String[] classnames = classesToGenerate(); // List of all stubs & skels - long destClassesModified = new Date().getTime(); // Earliest mod time - boolean allClassesFound = true; // Has each been found? - - /* - * Loop through each stub/skeleton class that must be generated, and - * determine (if all exist) which file has the most recent timestamp - */ - for (int i=0; i < classnames.length; i++) { - - String pathToClass = - classnames[i].replace('.', File.separatorChar) + ".class"; - File classFile = new File(destDir, pathToClass); - - /* - * Add each stub/skeleton class to the list of EJB files. Note - * that each class is added even if it doesn't exist now. - */ - ejbFiles.put(pathToClass, classFile); - - allClassesFound = allClassesFound && classFile.exists(); - - if (allClassesFound) { - long fileMod = classFile.lastModified(); - - /* Keep track of the oldest modification timestamp */ - destClassesModified = Math.min(destClassesModified, fileMod); - } - } - - return (allClassesFound) ? destClassesModified : -1; - } - - /** - * Builds an array of class names which represent the stubs and - * skeletons which need to be generated for a given EJB. The class - * names are fully qualified. Nine classes are generated for all EJBs - * while an additional six classes are generated for beans requiring - * RMI/IIOP access. - * - * @return An array of Strings representing the fully-qualified class - * names for the stubs and skeletons to be generated. - */ - private String[] classesToGenerate() { - String[] classnames = (iiop) ? new String[15] : new String[9]; - - final String remotePkg = remote.getPackageName() + "."; - final String remoteClass = remote.getClassName(); - final String homePkg = home.getPackageName() + "."; - final String homeClass = home.getClassName(); - final String implPkg = implementation.getPackageName() + "."; - final String implFullClass = implementation.getQualifiedWithUnderscores(); - int index = 0; - - String fullPath; - - classnames[index++] = implPkg + "ejb_fac_" + implFullClass; - classnames[index++] = implPkg + "ejb_home_" + implFullClass; - classnames[index++] = implPkg + "ejb_skel_" + implFullClass; - classnames[index++] = remotePkg + "ejb_kcp_skel_" + remoteClass; - classnames[index++] = homePkg + "ejb_kcp_skel_" + homeClass; - classnames[index++] = remotePkg + "ejb_kcp_stub_" + remoteClass; - classnames[index++] = homePkg + "ejb_kcp_stub_" + homeClass; - classnames[index++] = remotePkg + "ejb_stub_" + remoteClass; - classnames[index++] = homePkg + "ejb_stub_" + homeClass; - - if (!iiop) { - return classnames; - } - - classnames[index++] = remotePkg + "_" + remoteClass + "_Stub"; - classnames[index++] = homePkg + "_" + homeClass + "_Stub"; - classnames[index++] = remotePkg + "_ejb_RmiCorbaBridge_" - + remoteClass + "_Tie"; - classnames[index++] = homePkg + "_ejb_RmiCorbaBridge_" + homeClass - + "_Tie"; - classnames[index++] = remotePkg + "ejb_RmiCorbaBridge_" - + remoteClass; - classnames[index++] = homePkg + "ejb_RmiCorbaBridge_" + homeClass; - - return classnames; - } - - /** - * Convenience method which creates a String representation of all the - * instance variables of an EjbInfo object. - * - * @return A String representing the EjbInfo instance. - */ - public String toString() { - String s = "EJB name: " + name - + "\n\r home: " + home - + "\n\r remote: " + remote - + "\n\r impl: " + implementation - + "\n\r beantype: " + beantype - + "\n\r cmp: " + cmp - + "\n\r iiop: " + iiop - + "\n\r hasession: " + hasession; - - Iterator i = cmpDescriptors.iterator(); - while (i.hasNext()) { - s += "\n\r CMP Descriptor: " + i.next(); - } - - return s; - } - - } // End of EjbInfo inner class - - /** - * Convenience class used to represent the fully qualified name of a Java - * class. It provides an easy way to retrieve components of the class name - * in a format that is convenient for building iAS stubs and skeletons. - * - * @author Greg Nelson greg@netscape.com - */ - private class Classname { - private String qualifiedName; // Fully qualified name of the Java class - private String packageName; // Name of the package for this class - private String className; // Name of the class without the package - - /** - * This constructor builds an object which represents the name of a Java - * class. - * - * @param qualifiedName String representing the fully qualified class - * name of the Java class. - */ - public Classname(String qualifiedName) { - if (qualifiedName == null) { - return; - } - - this.qualifiedName = qualifiedName; - - int index = qualifiedName.lastIndexOf('.'); - if (index == -1) { - className = qualifiedName; - packageName = ""; - } else { - packageName = qualifiedName.substring(0, index); - className = qualifiedName.substring(index + 1); - } - } - - /** - * Gets the fully qualified name of the Java class. - * - * @return String representing the fully qualified class name. - */ - public String getQualifiedClassName() { - return qualifiedName; - } - - /** - * Gets the package name for the Java class. - * - * @return String representing the package name for the class. - */ - public String getPackageName() { - return packageName; - } - - /** - * Gets the Java class name without the package structure. - * - * @return String representing the name for the class. - */ - public String getClassName() { - return className; - } - - /** - * Gets the fully qualified name of the Java class with underscores - * separating the components of the class name rather than periods. - * This format is used in naming some of the stub and skeleton classes - * for the iPlanet Application Server. - * - * @return String representing the fully qualified class name using - * underscores instead of periods. - */ - public String getQualifiedWithUnderscores() { - return qualifiedName.replace('.', '_'); - } - - /** - * Returns a File which references the class relative to the specified - * directory. Note that the class file may or may not exist. - * - * @param directory A File referencing the base directory containing - * class files. - * @return File referencing this class. - */ - public File getClassFile(File directory) { - String pathToFile = qualifiedName.replace('.', File.separatorChar) - + ".class"; - return new File(directory, pathToFile); - } - - /** - * String representation of this class name. It returns the fully - * qualified class name. - * - * @return String representing the fully qualified class name. - */ - public String toString() { - return getQualifiedClassName(); - } - } // End of Classname inner class - - - /** - * Thread class used to redirect output from an InputStream to - * the JRE standard output. This class may be used to redirect output from - * an external process to the standard output. - * - * @author Greg Nelson greg@netscape.com - */ - private class RedirectOutput extends Thread { - InputStream stream; // Stream to read and redirect to standard output - - /** - * Constructs a new instance that will redirect output from the - * specified stream to the standard output. - * - * @param stream InputStream which will be read and redirected to the - * standard output. - */ - public RedirectOutput(InputStream stream) { - this.stream = stream; - } - - /** - * Reads text from the input stream and redirects it to standard output - * using a separate thread. - */ - public void run() { - BufferedReader reader = new BufferedReader( - new InputStreamReader(stream)); - String text; - try { - while ((text = reader.readLine()) != null) { - System.out.println(text); - } - } catch (IOException e) { - e.printStackTrace(); - } finally { - try { - reader.close(); - } catch (IOException e) { - // Do nothing - } - } - } - } // End of RedirectOutput inner class - -} - \ No newline at end of file + public void addCmpDescriptor(String descriptor) { + cmpDescriptors.add(descriptor); + } + + public List getCmpDescriptors() { + return cmpDescriptors; + } + + /** + * Verifies that the EJB is valid--if it is invalid, an exception is + * thrown + * + * + * @param buildDir The directory where the EJB remote interface, home + * interface, and implementation class must be found. + * @throws EjbcException If the EJB is invalid. + */ + private void checkConfiguration(File buildDir) throws EjbcException { + + /* Check that the specified instance variables are valid */ + if (home == null) { + throw new EjbcException("A home interface was not found " + + "for the " + name + " EJB."); + } + if (remote == null) { + throw new EjbcException("A remote interface was not found " + + "for the " + name + " EJB."); + } + if (implementation == null) { + throw new EjbcException("An EJB implementation class was not " + + "found for the " + name + " EJB."); + } + + if ((!beantype.equals(ENTITY_BEAN)) + && (!beantype.equals(STATELESS_SESSION)) + && (!beantype.equals(STATEFUL_SESSION))) { + throw new EjbcException("The beantype found (" + beantype + ") " + + "isn't valid in the " + name + " EJB."); + } + + if (cmp && (!beantype.equals(ENTITY_BEAN))) { + System.out.println("CMP stubs and skeletons may not be generated" + + " for a Session Bean -- the \"cmp\" attribute will be" + + " ignoredfor the " + name + " EJB."); + } + + if (hasession && (!beantype.equals(STATEFUL_SESSION))) { + System.out.println("Highly available stubs and skeletons may " + + "only be generated for a Stateful Session Bean -- the " + + "\"hasession\" attribute will be ignored for the " + + name + " EJB."); + } + + /* Check that the EJB "source" classes all exist */ + if (!remote.getClassFile(buildDir).exists()) { + throw new EjbcException("The remote interface " + + remote.getQualifiedClassName() + " could not be " + + "found."); + } + if (!home.getClassFile(buildDir).exists()) { + throw new EjbcException("The home interface " + + home.getQualifiedClassName() + " could not be " + + "found."); + } + if (!implementation.getClassFile(buildDir).exists()) { + throw new EjbcException("The EJB implementation class " + + implementation.getQualifiedClassName() + " could " + + "not be found."); + } + } + + /** + * Determines if the ejbc utility needs to be run or not. If the stubs + * and skeletons can all be found in the destination directory AND all + * of their timestamps are more recent than the EJB source classes + * (home, remote, and implementation classes), the method returns + * false. Otherwise, the method returns true. + * + * @param destDir The directory where the EJB source classes, stubs and + * skeletons are located. + * @return A boolean indicating whether or not the ejbc utility needs to + * be run to bring the stubs and skeletons up to date. + */ + public boolean mustBeRecompiled(File destDir) { + + long sourceModified = sourceClassesModified(destDir); + + long destModified = destClassesModified(destDir); + + return (destModified < sourceModified); + } + + /** + * Examines each of the EJB source classes (home, remote, and + * implementation) and returns the modification timestamp for the + * "oldest" class. + * + * @param classpath The classpath to be used to find the source EJB + * classes. If null, the system classpath + * is used. + * @return The modification timestamp for the "oldest" EJB source class. + * @throws BuildException If one of the EJB source classes cannot be + * found on the classpath. + */ + private long sourceClassesModified(File buildDir) { + long latestModified; // The timestamp of the "newest" class + long modified; // Timestamp for a given class + File remoteFile; // File for the remote interface class + File homeFile; // File for the home interface class + File implFile; // File for the EJB implementation class + + /* Check the timestamp on the remote interface */ + remoteFile = remote.getClassFile(buildDir); + modified = remoteFile.lastModified(); + if (modified == -1) { + System.out.println("The class " + + remote.getQualifiedClassName() + " couldn't " + + "be found on the classpath"); + return -1; + } + latestModified = modified; + + /* Check the timestamp on the home interface */ + homeFile = home.getClassFile(buildDir); + modified = homeFile.lastModified(); + if (modified == -1) { + System.out.println("The class " + + home.getQualifiedClassName() + " couldn't be " + + "found on the classpath"); + return -1; + } + latestModified = Math.max(latestModified, modified); + + /* Check the timestamp on the EJB implementation class. + * + * Note that if ONLY the implementation class has changed, it's not + * necessary to rebuild the EJB stubs and skeletons. For this + * reason, we ensure the file exists (using lastModified above), but + * we DON'T compare it's timestamp with the timestamps of the home + * and remote interfaces (because it's irrelevant in determining if + * ejbc must be run) + */ + implFile = implementation.getClassFile(buildDir); + modified = implFile.lastModified(); + if (modified == -1) { + System.out.println("The class " + + implementation.getQualifiedClassName() + + " couldn't be found on the classpath"); + return -1; + } + + String pathToFile = remote.getQualifiedClassName(); + pathToFile = pathToFile.replace('.', File.separatorChar) + ".class"; + ejbFiles.put(pathToFile, remoteFile); + + pathToFile = home.getQualifiedClassName(); + pathToFile = pathToFile.replace('.', File.separatorChar) + ".class"; + ejbFiles.put(pathToFile, homeFile); + + pathToFile = implementation.getQualifiedClassName(); + pathToFile = pathToFile.replace('.', File.separatorChar) + ".class"; + ejbFiles.put(pathToFile, implFile); + + return latestModified; + } + + /** + * Examines each of the EJB stubs and skeletons in the destination + * directory and returns the modification timestamp for the "oldest" + * class. If one of the stubs or skeletons cannot be found, -1 + * is returned. + * + * @param dest The directory in which the EJB stubs and skeletons are + * stored. + * @return The modification timestamp for the "oldest" EJB stub or + * skeleton. If one of the classes cannot be found, -1 + * is returned. + * @throws BuildException If the canonical path of the destination + * directory cannot be found. + */ + private long destClassesModified(File destDir) { + String[] classnames = classesToGenerate(); // List of all stubs & skels + long destClassesModified = new Date().getTime(); // Earliest mod time + boolean allClassesFound = true; // Has each been found? + + /* + * Loop through each stub/skeleton class that must be generated, and + * determine (if all exist) which file has the most recent timestamp + */ + for (int i=0; i < classnames.length; i++) { + + String pathToClass = + classnames[i].replace('.', File.separatorChar) + ".class"; + File classFile = new File(destDir, pathToClass); + + /* + * Add each stub/skeleton class to the list of EJB files. Note + * that each class is added even if it doesn't exist now. + */ + ejbFiles.put(pathToClass, classFile); + + allClassesFound = allClassesFound && classFile.exists(); + + if (allClassesFound) { + long fileMod = classFile.lastModified(); + + /* Keep track of the oldest modification timestamp */ + destClassesModified = Math.min(destClassesModified, fileMod); + } + } + + return (allClassesFound) ? destClassesModified : -1; + } + + /** + * Builds an array of class names which represent the stubs and + * skeletons which need to be generated for a given EJB. The class + * names are fully qualified. Nine classes are generated for all EJBs + * while an additional six classes are generated for beans requiring + * RMI/IIOP access. + * + * @return An array of Strings representing the fully-qualified class + * names for the stubs and skeletons to be generated. + */ + private String[] classesToGenerate() { + String[] classnames = (iiop) ? new String[15] : new String[9]; + + final String remotePkg = remote.getPackageName() + "."; + final String remoteClass = remote.getClassName(); + final String homePkg = home.getPackageName() + "."; + final String homeClass = home.getClassName(); + final String implPkg = implementation.getPackageName() + "."; + final String implFullClass = implementation.getQualifiedWithUnderscores(); + int index = 0; + + String fullPath; + + classnames[index++] = implPkg + "ejb_fac_" + implFullClass; + classnames[index++] = implPkg + "ejb_home_" + implFullClass; + classnames[index++] = implPkg + "ejb_skel_" + implFullClass; + classnames[index++] = remotePkg + "ejb_kcp_skel_" + remoteClass; + classnames[index++] = homePkg + "ejb_kcp_skel_" + homeClass; + classnames[index++] = remotePkg + "ejb_kcp_stub_" + remoteClass; + classnames[index++] = homePkg + "ejb_kcp_stub_" + homeClass; + classnames[index++] = remotePkg + "ejb_stub_" + remoteClass; + classnames[index++] = homePkg + "ejb_stub_" + homeClass; + + if (!iiop) { + return classnames; + } + + classnames[index++] = remotePkg + "_" + remoteClass + "_Stub"; + classnames[index++] = homePkg + "_" + homeClass + "_Stub"; + classnames[index++] = remotePkg + "_ejb_RmiCorbaBridge_" + + remoteClass + "_Tie"; + classnames[index++] = homePkg + "_ejb_RmiCorbaBridge_" + homeClass + + "_Tie"; + classnames[index++] = remotePkg + "ejb_RmiCorbaBridge_" + + remoteClass; + classnames[index++] = homePkg + "ejb_RmiCorbaBridge_" + homeClass; + + return classnames; + } + + /** + * Convenience method which creates a String representation of all the + * instance variables of an EjbInfo object. + * + * @return A String representing the EjbInfo instance. + */ + public String toString() { + String s = "EJB name: " + name + + "\n\r home: " + home + + "\n\r remote: " + remote + + "\n\r impl: " + implementation + + "\n\r beantype: " + beantype + + "\n\r cmp: " + cmp + + "\n\r iiop: " + iiop + + "\n\r hasession: " + hasession; + + Iterator i = cmpDescriptors.iterator(); + while (i.hasNext()) { + s += "\n\r CMP Descriptor: " + i.next(); + } + + return s; + } + + } // End of EjbInfo inner class + + /** + * Convenience class used to represent the fully qualified name of a Java + * class. It provides an easy way to retrieve components of the class name + * in a format that is convenient for building iAS stubs and skeletons. + * + * @author Greg Nelson greg@netscape.com + */ + private class Classname { + private String qualifiedName; // Fully qualified name of the Java class + private String packageName; // Name of the package for this class + private String className; // Name of the class without the package + + /** + * This constructor builds an object which represents the name of a Java + * class. + * + * @param qualifiedName String representing the fully qualified class + * name of the Java class. + */ + public Classname(String qualifiedName) { + if (qualifiedName == null) { + return; + } + + this.qualifiedName = qualifiedName; + + int index = qualifiedName.lastIndexOf('.'); + if (index == -1) { + className = qualifiedName; + packageName = ""; + } else { + packageName = qualifiedName.substring(0, index); + className = qualifiedName.substring(index + 1); + } + } + + /** + * Gets the fully qualified name of the Java class. + * + * @return String representing the fully qualified class name. + */ + public String getQualifiedClassName() { + return qualifiedName; + } + + /** + * Gets the package name for the Java class. + * + * @return String representing the package name for the class. + */ + public String getPackageName() { + return packageName; + } + + /** + * Gets the Java class name without the package structure. + * + * @return String representing the name for the class. + */ + public String getClassName() { + return className; + } + + /** + * Gets the fully qualified name of the Java class with underscores + * separating the components of the class name rather than periods. + * This format is used in naming some of the stub and skeleton classes + * for the iPlanet Application Server. + * + * @return String representing the fully qualified class name using + * underscores instead of periods. + */ + public String getQualifiedWithUnderscores() { + return qualifiedName.replace('.', '_'); + } + + /** + * Returns a File which references the class relative to the specified + * directory. Note that the class file may or may not exist. + * + * @param directory A File referencing the base directory containing + * class files. + * @return File referencing this class. + */ + public File getClassFile(File directory) { + String pathToFile = qualifiedName.replace('.', File.separatorChar) + + ".class"; + return new File(directory, pathToFile); + } + + /** + * String representation of this class name. It returns the fully + * qualified class name. + * + * @return String representing the fully qualified class name. + */ + public String toString() { + return getQualifiedClassName(); + } + } // End of Classname inner class + + + /** + * Thread class used to redirect output from an InputStream to + * the JRE standard output. This class may be used to redirect output from + * an external process to the standard output. + * + * @author Greg Nelson greg@netscape.com + */ + private class RedirectOutput extends Thread { + InputStream stream; // Stream to read and redirect to standard output + + /** + * Constructs a new instance that will redirect output from the + * specified stream to the standard output. + * + * @param stream InputStream which will be read and redirected to the + * standard output. + */ + public RedirectOutput(InputStream stream) { + this.stream = stream; + } + + /** + * Reads text from the input stream and redirects it to standard output + * using a separate thread. + */ + public void run() { + BufferedReader reader = new BufferedReader( + new InputStreamReader(stream)); + String text; + try { + while ((text = reader.readLine()) != null) { + System.out.println(text); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + reader.close(); + } catch (IOException e) { + // Do nothing + } + } + } + } // End of RedirectOutput inner class + +} diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbcTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbcTask.java index 494abcb44..33180a7e6 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbcTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbcTask.java @@ -67,34 +67,34 @@ import org.apache.tools.ant.types.Path; import org.apache.tools.ant.BuildException; /** - * Task to compile EJB stubs and skeletons for the iPlanet Application Server. + * Task to compile EJB stubs and skeletons for the iPlanet Application Server. * The EJBs to be processed are specified by the EJB 1.1 standard XML - * descriptor, and additional attributes are obtained from the iPlanet Application - * Server-specific XML descriptor. Since the XML descriptors can include - * multiple EJBs, this is a convenient way of specifying many EJBs in a single + * descriptor, and additional attributes are obtained from the iPlanet Application + * Server-specific XML descriptor. Since the XML descriptors can include + * multiple EJBs, this is a convenient way of specifying many EJBs in a single * Ant task. The following attributes are allowed: *

*

* For each EJB specified, this task will locate the three classes that comprise * the EJB. If these class files cannot be located in the dest - * directory, the task will fail. The task will also attempt to locate the EJB - * stubs and skeletons in this directory. If found, the timestamps on the + * directory, the task will fail. The task will also attempt to locate the EJB + * stubs and skeletons in this directory. If found, the timestamps on the * stubs and skeletons will be checked to ensure they are up to date. Only if * these files cannot be found or if they are out of date will ejbc be called * to generate new stubs and skeletons. @@ -123,42 +123,42 @@ import org.apache.tools.ant.BuildException; */ public class IPlanetEjbcTask extends Task { - /* Attributes set by the Ant build file */ - private File ejbdescriptor; - private File iasdescriptor; - private File dest; - private Path classpath; - private boolean keepgenerated = false; - private boolean debug = false; - private File iashome; + /* Attributes set by the Ant build file */ + private File ejbdescriptor; + private File iasdescriptor; + private File dest; + private Path classpath; + private boolean keepgenerated = false; + private boolean debug = false; + private File iashome; /** * Sets the location of the standard XML EJB descriptor. Typically, this - * file is named "ejb-jar.xml". - * - * @param ejbdescriptor The name and location of the EJB descriptor. + * file is named "ejb-jar.xml". + * + * @param ejbdescriptor The name and location of the EJB descriptor. */ - public void setEjbdescriptor(File ejbdescriptor) { - this.ejbdescriptor = ejbdescriptor; - } + public void setEjbdescriptor(File ejbdescriptor) { + this.ejbdescriptor = ejbdescriptor; + } /** - * Sets the location of the iAS-specific XML EJB descriptor. Typically, - * this file is named "ias-ejb-jar.xml". - * - * @param iasdescriptor The name and location of the iAS-specific EJB - * descriptor. + * Sets the location of the iAS-specific XML EJB descriptor. Typically, + * this file is named "ias-ejb-jar.xml". + * + * @param iasdescriptor The name and location of the iAS-specific EJB + * descriptor. */ - public void setIasdescriptor (File iasdescriptor) { - this.iasdescriptor = iasdescriptor; - } + public void setIasdescriptor (File iasdescriptor) { + this.iasdescriptor = iasdescriptor; + } /** * Sets the destination directory where the EJB "source" classes must exist - * and where the stubs and skeletons will be written. The destination - * directory must exist before this task is executed. - * - * @param dest The directory where the compiled classes will be written. + * and where the stubs and skeletons will be written. The destination + * directory must exist before this task is executed. + * + * @param dest The directory where the compiled classes will be written. */ public void setDest(File dest) { this.dest = dest; @@ -166,8 +166,8 @@ public class IPlanetEjbcTask extends Task { /** * Sets the classpath to be used when compiling the EJB stubs and skeletons. - * - * @param classpath The classpath to be used. + * + * @param classpath The classpath to be used. */ public void setClasspath(Path classpath) { if (this.classpath == null) { @@ -188,107 +188,107 @@ public class IPlanetEjbcTask extends Task { } /** - * Sets whether or not the Java source files which are generated by the - * ejbc process should be retained or automatically deleted. - * - * @param keepgenerated A boolean indicating if the Java source files for - * the stubs and skeletons should be retained. + * Sets whether or not the Java source files which are generated by the + * ejbc process should be retained or automatically deleted. + * + * @param keepgenerated A boolean indicating if the Java source files for + * the stubs and skeletons should be retained. */ - public void setKeepgenerated(boolean keepgenerated) { - this.keepgenerated = keepgenerated; - } + public void setKeepgenerated(boolean keepgenerated) { + this.keepgenerated = keepgenerated; + } /** * Sets whether or not debugging output will be generated when ejbc is - * executed. - * - * @param debug A boolean indicating if debugging output should be generated + * executed. + * + * @param debug A boolean indicating if debugging output should be generated */ - public void setDebug(boolean debug) { - this.debug = debug; - } - + public void setDebug(boolean debug) { + this.debug = debug; + } + /** * Setter method used to store the "home" directory of the user's iAS - * installation. The directory specified should typically be - * [install-location]/iplanet/ias6/ias. - * + * installation. The directory specified should typically be + * [install-location]/iplanet/ias6/ias. + * * @param iashome The home directory for the user's iAS installation. */ - public void setIashome(File iashome) { - this.iashome = iashome; - } + public void setIashome(File iashome) { + this.iashome = iashome; + } /** * Does the work. */ public void execute() throws BuildException { - checkConfiguration(); + checkConfiguration(); + + executeEjbc(getParser()); + } - executeEjbc(getParser()); - } - /** * Verifies that the user selections are valid. - * - * @throws BuildException If the user selections are invalid. + * + * @throws BuildException If the user selections are invalid. */ - private void checkConfiguration() throws BuildException { + private void checkConfiguration() throws BuildException { - if (ejbdescriptor == null) { - String msg = "The standard EJB descriptor must be specified using " - + "the \"ejbdescriptor\" attribute."; - throw new BuildException(msg, location); - } - if ((!ejbdescriptor.exists()) || (!ejbdescriptor.isFile())) { - String msg = "The standard EJB descriptor (" + ejbdescriptor - + ") was not found or isn't a file."; - throw new BuildException(msg, location); - } + if (ejbdescriptor == null) { + String msg = "The standard EJB descriptor must be specified using " + + "the \"ejbdescriptor\" attribute."; + throw new BuildException(msg, location); + } + if ((!ejbdescriptor.exists()) || (!ejbdescriptor.isFile())) { + String msg = "The standard EJB descriptor (" + ejbdescriptor + + ") was not found or isn't a file."; + throw new BuildException(msg, location); + } - if (iasdescriptor == null) { - String msg = "The iAS-speific XML descriptor must be specified using" - + " the \"iasdescriptor\" attribute."; - throw new BuildException(msg, location); - } - if ((!iasdescriptor.exists()) || (!iasdescriptor.isFile())) { - String msg = "The iAS-specific XML descriptor (" + iasdescriptor - + ") was not found or isn't a file."; - throw new BuildException(msg, location); - } + if (iasdescriptor == null) { + String msg = "The iAS-speific XML descriptor must be specified using" + + " the \"iasdescriptor\" attribute."; + throw new BuildException(msg, location); + } + if ((!iasdescriptor.exists()) || (!iasdescriptor.isFile())) { + String msg = "The iAS-specific XML descriptor (" + iasdescriptor + + ") was not found or isn't a file."; + throw new BuildException(msg, location); + } - if (dest == null) { - String msg = "The destination directory must be specified using " - + "the \"dest\" attribute."; - throw new BuildException(msg, location); - } - if ((!dest.exists()) || (!dest.isDirectory())) { - String msg = "The destination directory (" + dest + ") was not " - + "found or isn't a directory."; - throw new BuildException(msg, location); - } + if (dest == null) { + String msg = "The destination directory must be specified using " + + "the \"dest\" attribute."; + throw new BuildException(msg, location); + } + if ((!dest.exists()) || (!dest.isDirectory())) { + String msg = "The destination directory (" + dest + ") was not " + + "found or isn't a directory."; + throw new BuildException(msg, location); + } - if ((iashome != null) && (!iashome.isDirectory())) { - String msg = "If \"iashome\" is specified, it must be a valid " - + "directory (it was set to " + iashome + ")."; - throw new BuildException(msg, getLocation()); - } - } + if ((iashome != null) && (!iashome.isDirectory())) { + String msg = "If \"iashome\" is specified, it must be a valid " + + "directory (it was set to " + iashome + ")."; + throw new BuildException(msg, getLocation()); + } + } /** * Returns a SAXParser that may be used to process the XML descriptors. - * - * @return Parser which may be used to process the EJB descriptors. - * @throws BuildException If the parser cannot be created or configured. + * + * @return Parser which may be used to process the EJB descriptors. + * @throws BuildException If the parser cannot be created or configured. */ - private SAXParser getParser() throws BuildException { + private SAXParser getParser() throws BuildException { - SAXParser saxParser = null; - try { + SAXParser saxParser = null; + try { SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); saxParserFactory.setValidating(true); saxParser = saxParserFactory.newSAXParser(); - } catch (SAXException e) { + } catch (SAXException e) { String msg = "Unable to create a SAXParser: " + e.getMessage(); throw new BuildException(msg, e, location); } @@ -297,57 +297,57 @@ public class IPlanetEjbcTask extends Task { throw new BuildException(msg, e, location); } - return saxParser; - } + return saxParser; + } /** * Executes the EJBc utility using the SAXParser provided. - * - * @param saxParser SAXParser that may be used to process the EJB - * descriptors - * @throws BuildException If there is an error reading or parsing the XML - * descriptors + * + * @param saxParser SAXParser that may be used to process the EJB + * descriptors + * @throws BuildException If there is an error reading or parsing the XML + * descriptors */ - private void executeEjbc(SAXParser saxParser) throws BuildException { - IPlanetEjbc ejbc = new IPlanetEjbc(ejbdescriptor, - iasdescriptor, - dest, - getClasspath().toString(), - saxParser); - ejbc.setRetainSource(keepgenerated); - ejbc.setDebugOutput(debug); - if (iashome != null) { - ejbc.setIasHomeDir(iashome); - } + private void executeEjbc(SAXParser saxParser) throws BuildException { + IPlanetEjbc ejbc = new IPlanetEjbc(ejbdescriptor, + iasdescriptor, + dest, + getClasspath().toString(), + saxParser); + ejbc.setRetainSource(keepgenerated); + ejbc.setDebugOutput(debug); + if (iashome != null) { + ejbc.setIasHomeDir(iashome); + } - try { - ejbc.execute(); - } catch (IOException e) { + try { + ejbc.execute(); + } catch (IOException e) { String msg = "An IOException occurred while trying to read the XML " - + "descriptor file: " + e.getMessage(); + + "descriptor file: " + e.getMessage(); throw new BuildException(msg, e, location); } catch (SAXException e) { String msg = "A SAXException occurred while trying to read the XML " - + "descriptor file: " + e.getMessage(); + + "descriptor file: " + e.getMessage(); throw new BuildException(msg, e, location); } catch (IPlanetEjbc.EjbcException e) { String msg = "An exception occurred while trying to run the ejbc " - + "utility: " + e.getMessage(); + + "utility: " + e.getMessage(); throw new BuildException(msg, e, location); } - } + } /** * Returns the CLASSPATH to be used when calling EJBc. If no user CLASSPATH - * is specified, the System classpath is returned instead. - * - * @return Path The classpath to be used for EJBc. - */ - private Path getClasspath() { - if (classpath == null) { - classpath = Path.systemClasspath; - } + * is specified, the System classpath is returned instead. + * + * @return Path The classpath to be used for EJBc. + */ + private Path getClasspath() { + if (classpath == null) { + classpath = Path.systemClasspath; + } - return classpath; - } + return classpath; + } } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJAntTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJAntTool.java index 5c9ab7c8f..05e48e2e7 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJAntTool.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJAntTool.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -9,7 +9,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -17,15 +17,15 @@ * distribution. * * 3. The end-user documentation included with the redistribution, if - * any, must include the following acknowlegement: - * "This product includes software developed by the + * any, must include the following acknowlegement: + * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived - * from this software without prior written permission. For written + * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" @@ -73,20 +73,20 @@ import org.apache.tools.ant.BuildException; public class VAJAntTool { private final static String TOOL_DATA_KEY = "AntTool"; - + /** * Loads the BuildInfo for the specified VAJ project from the * tool data for this project. * If there is no build info stored for that project, a new * default BuildInfo is returned - * + * * @return BuildInfo buildInfo build info for the specified project * @param projectName String project name */ public static VAJBuildInfo loadBuildData(String projectName) { VAJBuildInfo result = null; try { - Project project = + Project project = VAJLocalUtil.getWorkspace().loadedProjectNamed( projectName ); if ( project.testToolRepositoryData(TOOL_DATA_KEY) ) { ToolData td = project.getToolRepositoryData(TOOL_DATA_KEY); @@ -97,7 +97,7 @@ public class VAJAntTool { } result.setVAJProjectName( projectName ); } catch (Throwable t) { - throw new BuildException("BuildInfo for Project " + throw new BuildException("BuildInfo for Project " + projectName + " could not be loaded" + t); } return result; @@ -108,7 +108,7 @@ public class VAJAntTool { * Starts the application. * * @param args an array of command-line arguments. VAJ puts the - * VAJ project name into args[1] when starting the + * VAJ project name into args[1] when starting the * tool from the project context menu */ public static void main(java.lang.String[] args) { @@ -117,11 +117,11 @@ public class VAJAntTool { if ( args.length >= 2 && args[1] instanceof String ) { String projectName = (String)args[1]; info = loadBuildData( projectName ); - } + } else { info = new VAJBuildInfo(); } - + VAJAntToolGUI mainFrame = new VAJAntToolGUI( info ); mainFrame.show(); } catch ( Throwable t ) { @@ -141,10 +141,10 @@ public class VAJAntTool { String data = info.asDataString(); try { ToolData td = new ToolData( TOOL_DATA_KEY, data ); - VAJLocalUtil.getWorkspace().loadedProjectNamed( + VAJLocalUtil.getWorkspace().loadedProjectNamed( info.getVAJProjectName() ).setToolRepositoryData( td ); } catch (Throwable t) { - throw new BuildException("BuildInfo for Project " + throw new BuildException("BuildInfo for Project " + info.getVAJProjectName() + " could not be saved", t); } } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJAntToolGUI.java b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJAntToolGUI.java index 3260898a0..3537e58f0 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJAntToolGUI.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJAntToolGUI.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -9,7 +9,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -17,15 +17,15 @@ * distribution. * * 3. The end-user documentation included with the redistribution, if - * any, must include the following acknowlegement: - * "This product includes software developed by the + * any, must include the following acknowlegement: + * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived - * from this software without prior written permission. For written + * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" @@ -95,14 +95,14 @@ import org.apache.tools.ant.BuildEvent; import org.apache.tools.ant.Project; /** - * This is a simple grafical user interface to provide the information needed + * This is a simple grafical user interface to provide the information needed * by ANT and to start the build-process within IBM VisualAge for Java. *

- * I was using AWT to make it independent from the JDK-version. Please don't - * ask me for a Swing-version:I am very familiar with Swing and I really think + * I was using AWT to make it independent from the JDK-version. Please don't + * ask me for a Swing-version:I am very familiar with Swing and I really think * that it's not necessary for such a simple gui! *

- * It is completely developed in VAJ using the visual composition editor. + * It is completely developed in VAJ using the visual composition editor. * About 90% of the code is generated by VAJ, * but in fact I did a lot of code-beautification ;-). *

@@ -111,7 +111,7 @@ import org.apache.tools.ant.Project; */ public class VAJAntToolGUI extends Frame { /** - * Members + * Members */ private VAJBuildLogger logger = new VAJBuildLogger(); private String lineSeparator = "\r\n"; @@ -138,7 +138,7 @@ public class VAJAntToolGUI extends Frame { // Project name private Label iProjectLabel = null; private Label iProjectText = null; - // XML-file + // XML-file private Label iBuildFileLabel = null; private TextField iBuildFileTextField = null; private boolean iConnPtoP2Aligning = false; @@ -151,7 +151,7 @@ public class VAJAntToolGUI extends Frame { private List iTargetList = null; // Command-buttons private Button iBuildButton = null; - private Button iReloadButton = null; + private Button iReloadButton = null; private Button iCloseButton = null; /** * log-Window @@ -180,7 +180,7 @@ public class VAJAntToolGUI extends Frame { private Button iAboutOkButton = null; /** - * This internal BuildLogger, to be honest, is just a BuildListener. + * This internal BuildLogger, to be honest, is just a BuildListener. * It does nearly the same as the DefaultLogger, but uses the Loggin-Window for output. */ private class VAJBuildLogger implements BuildListener { @@ -203,7 +203,7 @@ public class VAJAntToolGUI extends Frame { getStopButton().setEnabled(false); getBuildButton().setEnabled(true); getBuildButton().requestFocus(); - + Throwable error = event.getException(); if (error == null) { @@ -235,7 +235,7 @@ public class VAJAntToolGUI extends Frame { error.printStackTrace(System.err); } } - + /** * Fired before any targets are started. */ @@ -300,7 +300,7 @@ public class VAJAntToolGUI extends Frame { public void taskStarted(BuildEvent event) { } } - + /** * Eventhandler to handle all AWT-events */ @@ -320,7 +320,7 @@ public class VAJAntToolGUI extends Frame { getBuildFileTextField().setText(getFileDialog().getDirectory() + getFileDialog().getFile()); } } - // dispose and exit application + // dispose and exit application if (e.getSource() == VAJAntToolGUI.this.getCloseButton()) { dispose(); System.exit(0); @@ -344,21 +344,21 @@ public class VAJAntToolGUI extends Frame { } } // MenuItems - if (e.getSource() == VAJAntToolGUI.this.getSaveMenuItem()) + if (e.getSource() == VAJAntToolGUI.this.getSaveMenuItem()) saveBuildInfo(); - if (e.getSource() == VAJAntToolGUI.this.getAboutMenuItem()) + if (e.getSource() == VAJAntToolGUI.this.getAboutMenuItem()) getAboutDialog().show(); - if (e.getSource() == VAJAntToolGUI.this.getShowLogMenuItem()) + if (e.getSource() == VAJAntToolGUI.this.getShowLogMenuItem()) getMessageFrame().show(); /* #### About dialog #### */ - if (e.getSource() == VAJAntToolGUI.this.getAboutOkButton()) + if (e.getSource() == VAJAntToolGUI.this.getAboutOkButton()) getAboutDialog().dispose(); /* #### Log frame #### */ if (e.getSource() == VAJAntToolGUI.this.getMessageOkButton()) getMessageFrame().dispose(); - if (e.getSource() == VAJAntToolGUI.this.getMessageClearLogButton()) + if (e.getSource() == VAJAntToolGUI.this.getMessageClearLogButton()) getMessageTextArea().setText(""); - if (e.getSource() == VAJAntToolGUI.this.getMessageOkButton()) + if (e.getSource() == VAJAntToolGUI.this.getMessageOkButton()) getMessageFrame().dispose(); } catch (Throwable exc) { @@ -371,36 +371,36 @@ public class VAJAntToolGUI extends Frame { */ public void itemStateChanged(ItemEvent e) { try { - if (e.getSource() == VAJAntToolGUI.this.getTargetList()) + if (e.getSource() == VAJAntToolGUI.this.getTargetList()) getBuildButton().setEnabled(true); - if (e.getSource() == VAJAntToolGUI.this.getMessageOutputLevelChoice()) + if (e.getSource() == VAJAntToolGUI.this.getMessageOutputLevelChoice()) getBuildInfo().setOutputMessageLevel(getMessageOutputLevelChoice().getSelectedIndex()); - if (e.getSource() == VAJAntToolGUI.this.getTargetList()) + if (e.getSource() == VAJAntToolGUI.this.getTargetList()) getBuildInfo().setTarget(getTargetList().getSelectedItem()); } catch (Throwable exc) { handleException(exc); } } - + /** * PropertyChangeListener method */ public void propertyChange(java.beans.PropertyChangeEvent evt) { - if (evt.getSource() == VAJAntToolGUI.this.getBuildInfo() && (evt.getPropertyName().equals("projectName"))) + if (evt.getSource() == VAJAntToolGUI.this.getBuildInfo() && (evt.getPropertyName().equals("projectName"))) connectProjectNameToLabel(); - if (evt.getSource() == VAJAntToolGUI.this.getBuildInfo() && (evt.getPropertyName().equals("buildFileName"))) + if (evt.getSource() == VAJAntToolGUI.this.getBuildInfo() && (evt.getPropertyName().equals("buildFileName"))) connectBuildFileNameToTextField(); } - + /** * TextListener method */ public void textValueChanged(TextEvent e) { - if (e.getSource() == VAJAntToolGUI.this.getBuildFileTextField()) + if (e.getSource() == VAJAntToolGUI.this.getBuildFileTextField()) connectTextFieldToBuildFileName(); } - + /** * WindowListener methods */ @@ -410,9 +410,9 @@ public class VAJAntToolGUI extends Frame { dispose(); System.exit(0); } - if (e.getSource() == VAJAntToolGUI.this.getAboutDialog()) + if (e.getSource() == VAJAntToolGUI.this.getAboutDialog()) getAboutDialog().dispose(); - if (e.getSource() == VAJAntToolGUI.this.getMessageFrame()) + if (e.getSource() == VAJAntToolGUI.this.getMessageFrame()) getMessageFrame().dispose(); } catch (Throwable exc) { @@ -426,7 +426,7 @@ public class VAJAntToolGUI extends Frame { public void windowIconified(WindowEvent e) {}; public void windowOpened(WindowEvent e) {}; } - + /** * AntMake default-constructor. */ @@ -438,7 +438,7 @@ public class VAJAntToolGUI extends Frame { * AntMake constructor called by VAJAntTool integration. * @param buildInfo VAJBuildInfo */ - + public VAJAntToolGUI(VAJBuildInfo newBuildInfo) { super(); setBuildInfo(newBuildInfo); @@ -503,12 +503,12 @@ public class VAJAntToolGUI extends Frame { * external build of a .jar-file */ private void executeTarget() { - try { + try { getMessageFrame().show(); getBuildInfo().executeProject(logger); } catch (Throwable exc) { - logger.logException( exc ); + logger.logException( exc ); } return; } @@ -1293,7 +1293,7 @@ public class VAJAntToolGUI extends Frame { getMessageTextArea().append(lineSeparator + lineSeparator + trace); getMessageFrame().show(); - + } /** * Initializes connections diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJBuildInfo.java b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJBuildInfo.java index df7d73404..29abf46f8 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJBuildInfo.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJBuildInfo.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -9,7 +9,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -17,15 +17,15 @@ * distribution. * * 3. The end-user documentation included with the redistribution, if - * any, must include the following acknowlegement: - * "This product includes software developed by the + * any, must include the following acknowlegement: + * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived - * from this software without prior written permission. For written + * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" @@ -54,7 +54,7 @@ package org.apache.tools.ant.taskdefs.optional.ide; - + import java.util.Vector; import java.util.Enumeration; import java.util.StringTokenizer; @@ -80,7 +80,7 @@ import org.apache.tools.ant.BuildEvent; * execute target) * - manages a seperate thread for Ant project execution * this allows interrupting a running build from a GUI - * + * * @author Wolf Siberski, TUI Infotec GmbH */ @@ -102,7 +102,7 @@ class VAJBuildInfo implements Runnable { private class InterruptedChecker implements BuildListener { // the real listener BuildListener wrappedListener; - + /** * Can only be constructed as wrapper around a real listener * @param listener the real listener @@ -182,11 +182,10 @@ class VAJBuildInfo implements Runnable { checkInterrupted(); } } - - + // name of the VA project this BuildInfo belongs to private String vajProjectName = ""; - + // name of the Ant build file private String buildFileName = ""; @@ -208,30 +207,30 @@ class VAJBuildInfo implements Runnable { // Support for bound properties protected transient PropertyChangeSupport propertyChange; - // thread for Ant build execution + // thread for Ant build execution private Thread buildThread; // the listener used to log output. private BuildListener projectLogger; - + /** - * The addPropertyChangeListener method was generated to support the + * The addPropertyChangeListener method was generated to support the * propertyChange field. */ public synchronized void addPropertyChangeListener(PropertyChangeListener listener) { getPropertyChange().addPropertyChangeListener(listener); } - + /** * Returns the BuildInfo information as String. The BuildInfo can * be rebuilt from that String by calling parse(). * @return java.lang.String */ public String asDataString() { - String result = getOutputMessageLevel() + "|" + getBuildFileName() + String result = getOutputMessageLevel() + "|" + getBuildFileName() + "|" + getTarget(); - for ( Enumeration e = getProjectTargets().elements(); + for ( Enumeration e = getProjectTargets().elements(); e.hasMoreElements(); ) { result = result + "|" + e.nextElement(); } @@ -286,14 +285,14 @@ class VAJBuildInfo implements Runnable { } return project; } - + /** * return a list of all targets in the current buildfile */ public Vector getProjectTargets() { return projectTargets; } - + /** * Accessor for the propertyChange field. */ @@ -373,13 +372,13 @@ class VAJBuildInfo implements Runnable { } /** - * The removePropertyChangeListener method was generated + * The removePropertyChangeListener method was generated * to support the propertyChange field. */ public synchronized void removePropertyChangeListener(PropertyChangeListener listener) { getPropertyChange().removePropertyChangeListener(listener); } - + /** * Sets the build file name * @param buildFileName build file name @@ -390,7 +389,7 @@ class VAJBuildInfo implements Runnable { setProjectInitialized(false); firePropertyChange("buildFileName", oldValue, buildFileName); } - + /** * Sets the log level (value must be one of the constants in Project) * @param outputMessageLevel log level. @@ -398,7 +397,7 @@ class VAJBuildInfo implements Runnable { public void setOutputMessageLevel(int newOutputMessageLevel) { int oldValue = outputMessageLevel; outputMessageLevel = newOutputMessageLevel; - firePropertyChange("outputMessageLevel", + firePropertyChange("outputMessageLevel", new Integer(oldValue), new Integer(outputMessageLevel)); } @@ -410,7 +409,7 @@ class VAJBuildInfo implements Runnable { int level = Integer.parseInt( outputMessageLevel ); setOutputMessageLevel( level ); } - + /** * sets the initialized flag */ @@ -461,7 +460,7 @@ class VAJBuildInfo implements Runnable { /** - * cancels a build. + * cancels a build. */ public void cancelBuild() { buildThread.interrupt(); @@ -484,7 +483,7 @@ class VAJBuildInfo implements Runnable { } catch (Error err) { error = err; throw err; - } + } } /** @@ -501,7 +500,7 @@ class VAJBuildInfo implements Runnable { if (!isProjectInitialized()) { initProject(); } - + project.addBuildListener( ic ); project.executeTarget(target); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJExport.java b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJExport.java index 57911f642..a22a2617e 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJExport.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJExport.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -9,7 +9,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -17,15 +17,15 @@ * distribution. * * 3. The end-user documentation included with the redistribution, if - * any, must include the following acknowlegement: - * "This product includes software developed by the + * any, must include the following acknowlegement: + * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived - * from this software without prior written permission. For written + * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" @@ -51,7 +51,7 @@ * information on the Apache Software Foundation, please see * . */ - + package org.apache.tools.ant.taskdefs.optional.ide; @@ -61,21 +61,21 @@ import org.apache.tools.ant.BuildException; import org.apache.tools.ant.types.PatternSet; /** - * Export packages from the Visual Age for Java workspace. - * The packages are specified similar to all other MatchingTasks. - * Since the VA Workspace is not file based, this task is simulating + * Export packages from the Visual Age for Java workspace. + * The packages are specified similar to all other MatchingTasks. + * Since the VA Workspace is not file based, this task is simulating * a directory hierarchy for the workspace: - * The 'root' contains all project 'dir's, and the projects contain + * The 'root' contains all project 'dir's, and the projects contain * their respective package 'dir's. - * Example: - *

+ * Example: + *
* <vajexport destdir="C:/builddir/source"> *  <include name="/MyVAProject/org/foo/subsystem1/**" /> *  <exclude name="/MyVAProject/org/foo/subsystem1/test/**"/> * </vajexport> *
* exports all packages in the project MyVAProject which start with - * 'org.foo.subsystem1' except of these starting with + * 'org.foo.subsystem1' except of these starting with * 'org.foo.subsystem1.test'. * * There are flags to choose which items to export: @@ -89,124 +89,124 @@ import org.apache.tools.ant.types.PatternSet; */ public class VAJExport extends VAJTask { - //set set... method comments for description - protected File destDir; - protected boolean exportSources = true; - protected boolean exportResources = true; - protected boolean exportClasses = false; - protected boolean exportDebugInfo = false; - protected boolean useDefaultExcludes = true; - protected boolean overwrite = true; - - protected PatternSet patternSet = new PatternSet(); - - /** - * add a name entry on the exclude list - */ - public PatternSet.NameEntry createExclude() { - return patternSet.createExclude(); - } - - /** - * add a name entry on the include list - */ - public PatternSet.NameEntry createInclude() { - return patternSet.createInclude(); - } - - /** - * do the export - */ - public void execute() throws BuildException { - // first off, make sure that we've got a destdir - if (destDir == null) { - throw new BuildException("destdir attribute must be set!"); - } - - // delegate the export to the VAJUtil object. - getUtil().exportPackages(destDir, - patternSet.getIncludePatterns(getProject()), - patternSet.getExcludePatterns(getProject()), - exportClasses, exportDebugInfo, - exportResources, exportSources, - useDefaultExcludes, overwrite); - } - - /** - * Sets whether default exclusions should be used or not. - * - * @param useDefaultExcludes "true"|"on"|"yes" when default exclusions - * should be used, "false"|"off"|"no" when they - * shouldn't be used. - */ - public void setDefaultexcludes(boolean useDefaultExcludes) { - this.useDefaultExcludes = useDefaultExcludes; - } - - /** - * Set the destination directory into which the selected - * items should be exported - */ - public void setDestdir(File destDir) { - this.destDir = destDir; - } - - /** - * Sets the set of exclude patterns. Patterns may be separated by a comma - * or a space. Currently only patterns denoting packages are - * supported - * - * @param excludes the string containing the exclude patterns - */ - public void setExcludes(String excludes) { - patternSet.setExcludes(excludes); - } - - /** - * if exportClasses is set, class files are exported - */ - public void setExportClasses(boolean doExport) { - exportClasses = doExport; - } - - /** - * if exportDebugInfo is set, the exported class files contain - * debug info - */ - public void setExportDebugInfo(boolean doExport) { - exportDebugInfo = doExport; - } - - /** - * if exportResources is set, resource file will be exported - */ - public void setExportResources(boolean doExport) { - exportResources = doExport; - } - - /** - * if exportSources is set, java files will be exported - */ - public void setExportSources(boolean doExport) { - exportSources = doExport; - } - - /** - * Sets the set of include patterns. Patterns may be separated by a comma - * or a space.Currently only patterns denoting packages are - * supported - * - * @param includes the string containing the include patterns - */ - public void setIncludes(String includes) { - patternSet.setIncludes(includes); - } - - /** - * if Overwrite is set, files will be overwritten during export - */ - public void setOverwrite(boolean doOverwrite) { - overwrite = doOverwrite; - } - + //set set... method comments for description + protected File destDir; + protected boolean exportSources = true; + protected boolean exportResources = true; + protected boolean exportClasses = false; + protected boolean exportDebugInfo = false; + protected boolean useDefaultExcludes = true; + protected boolean overwrite = true; + + protected PatternSet patternSet = new PatternSet(); + + /** + * add a name entry on the exclude list + */ + public PatternSet.NameEntry createExclude() { + return patternSet.createExclude(); + } + + /** + * add a name entry on the include list + */ + public PatternSet.NameEntry createInclude() { + return patternSet.createInclude(); + } + + /** + * do the export + */ + public void execute() throws BuildException { + // first off, make sure that we've got a destdir + if (destDir == null) { + throw new BuildException("destdir attribute must be set!"); + } + + // delegate the export to the VAJUtil object. + getUtil().exportPackages(destDir, + patternSet.getIncludePatterns(getProject()), + patternSet.getExcludePatterns(getProject()), + exportClasses, exportDebugInfo, + exportResources, exportSources, + useDefaultExcludes, overwrite); + } + + /** + * Sets whether default exclusions should be used or not. + * + * @param useDefaultExcludes "true"|"on"|"yes" when default exclusions + * should be used, "false"|"off"|"no" when they + * shouldn't be used. + */ + public void setDefaultexcludes(boolean useDefaultExcludes) { + this.useDefaultExcludes = useDefaultExcludes; + } + + /** + * Set the destination directory into which the selected + * items should be exported + */ + public void setDestdir(File destDir) { + this.destDir = destDir; + } + + /** + * Sets the set of exclude patterns. Patterns may be separated by a comma + * or a space. Currently only patterns denoting packages are + * supported + * + * @param excludes the string containing the exclude patterns + */ + public void setExcludes(String excludes) { + patternSet.setExcludes(excludes); + } + + /** + * if exportClasses is set, class files are exported + */ + public void setExportClasses(boolean doExport) { + exportClasses = doExport; + } + + /** + * if exportDebugInfo is set, the exported class files contain + * debug info + */ + public void setExportDebugInfo(boolean doExport) { + exportDebugInfo = doExport; + } + + /** + * if exportResources is set, resource file will be exported + */ + public void setExportResources(boolean doExport) { + exportResources = doExport; + } + + /** + * if exportSources is set, java files will be exported + */ + public void setExportSources(boolean doExport) { + exportSources = doExport; + } + + /** + * Sets the set of include patterns. Patterns may be separated by a comma + * or a space.Currently only patterns denoting packages are + * supported + * + * @param includes the string containing the include patterns + */ + public void setIncludes(String includes) { + patternSet.setIncludes(includes); + } + + /** + * if Overwrite is set, files will be overwritten during export + */ + public void setOverwrite(boolean doOverwrite) { + overwrite = doOverwrite; + } + } \ No newline at end of file diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJImport.java b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJImport.java index 481bdaedf..fbf6da54b 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJImport.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJImport.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -9,7 +9,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -17,15 +17,15 @@ * distribution. * * 3. The end-user documentation included with the redistribution, if - * any, must include the following acknowlegement: - * "This product includes software developed by the + * any, must include the following acknowlegement: + * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived - * from this software without prior written permission. For written + * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" @@ -64,11 +64,11 @@ import org.apache.tools.ant.types.FileSet; import java.lang.reflect.Field; /** - * Import source, class files, and resources to the Visual Age for Java + * Import source, class files, and resources to the Visual Age for Java * workspace using FileSets. *

- * Example: - *

 
+ * Example:
+ * 
  * <vajimport project="MyVAProject">
  *   <fileset dir="src">
  *     <include name="org/foo/subsystem1/**" />
@@ -77,7 +77,7 @@ import java.lang.reflect.Field;
  * </vajexport>
  * 
* import all source and resource files from the "src" directory - * which start with 'org.foo.subsystem1', except of these starting with + * which start with 'org.foo.subsystem1', except of these starting with * 'org.foo.subsystem1.test' into the project MyVAProject. *

*

If MyVAProject isn't loaded into the Workspace, a new edition is @@ -117,116 +117,116 @@ import java.lang.reflect.Field; * @author: Glenn McAllister, inspired by a similar task written by Peter Kelley */ public class VAJImport extends VAJTask { - protected Vector filesets = new Vector(); - protected boolean importSources = true; - protected boolean importResources = true; - protected boolean importClasses = false; - protected String importProject = null; - protected boolean useDefaultExcludes = true; - - - /** - * The VisualAge for Java Project name to import into. - */ - public void setProject(String projectName) { - this.importProject = projectName; - } - - /** - * Adds a set of files (nested fileset attribute). - */ - public void addFileset(FileSet set) { - filesets.addElement(set); - } - - /** - * Import .class files. - */ - public void setImportClasses(boolean importClasses) { - this.importClasses = importClasses; - } - - /** - * Import resource files (anything that doesn't end in - * .class or .java) - */ - public void setImportResources(boolean importResources) { - this.importResources = importResources; - } - - /** - * Import .java files - */ - public void setImportSources(boolean importSources) { - this.importSources = importSources; - } - - /** - * Sets whether default exclusions should be used or not. - * - * @param useDefaultExcludes "true"|"on"|"yes" when default exclusions - * should be used, "false"|"off"|"no" when they - * shouldn't be used. - */ - public void setDefaultexcludes(boolean useDefaultExcludes) { - this.useDefaultExcludes = useDefaultExcludes; - } - - /** - * Do the import. - */ - public void execute() throws BuildException { - if (filesets.size() == 0) { - throw new BuildException("At least one fileset is required!"); - } - - if (importProject == null || "".equals(importProject)) { - throw new BuildException("The VisualAge for Java Project name is required!"); - } - - for (Enumeration e = filesets.elements(); e.hasMoreElements();) { - importFileset((FileSet) e.nextElement()); - } - } - - /** - * Import all files from the fileset into the Project in the - * Workspace. - */ - protected void importFileset(FileSet fileset) { - DirectoryScanner ds = fileset.getDirectoryScanner(this.project); - if (ds.getIncludedFiles().length == 0) { - return; - } - - String[] includes = null; - String[] excludes = null; - - // Hack to get includes and excludes. We could also use getIncludedFiles, - // but that would result in very long HTTP-requests. - // Therefore we want to send the patterns only to the remote tool server - // and let him figure out the files. - try { - Class directoryScanner = ds.getClass(); - - Field includesField = directoryScanner.getDeclaredField("includes"); - includesField.setAccessible(true); - includes = (String[]) includesField.get(ds); - - Field excludesField = directoryScanner.getDeclaredField("excludes"); - excludesField.setAccessible(true); - excludes = (String[]) excludesField.get(ds); - } catch (NoSuchFieldException nsfe) { - throw new BuildException( - "DirectoryScanner.includes or .excludes missing" + nsfe.getMessage()); - } catch (IllegalAccessException iae) { - throw new BuildException( - "Access to DirectoryScanner.includes or .excludes not allowed"); - } - - getUtil().importFiles( importProject, ds.getBasedir(), - includes, excludes, - importClasses, importResources, importSources, - useDefaultExcludes); - } + protected Vector filesets = new Vector(); + protected boolean importSources = true; + protected boolean importResources = true; + protected boolean importClasses = false; + protected String importProject = null; + protected boolean useDefaultExcludes = true; + + + /** + * The VisualAge for Java Project name to import into. + */ + public void setProject(String projectName) { + this.importProject = projectName; + } + + /** + * Adds a set of files (nested fileset attribute). + */ + public void addFileset(FileSet set) { + filesets.addElement(set); + } + + /** + * Import .class files. + */ + public void setImportClasses(boolean importClasses) { + this.importClasses = importClasses; + } + + /** + * Import resource files (anything that doesn't end in + * .class or .java) + */ + public void setImportResources(boolean importResources) { + this.importResources = importResources; + } + + /** + * Import .java files + */ + public void setImportSources(boolean importSources) { + this.importSources = importSources; + } + + /** + * Sets whether default exclusions should be used or not. + * + * @param useDefaultExcludes "true"|"on"|"yes" when default exclusions + * should be used, "false"|"off"|"no" when they + * shouldn't be used. + */ + public void setDefaultexcludes(boolean useDefaultExcludes) { + this.useDefaultExcludes = useDefaultExcludes; + } + + /** + * Do the import. + */ + public void execute() throws BuildException { + if (filesets.size() == 0) { + throw new BuildException("At least one fileset is required!"); + } + + if (importProject == null || "".equals(importProject)) { + throw new BuildException("The VisualAge for Java Project name is required!"); + } + + for (Enumeration e = filesets.elements(); e.hasMoreElements();) { + importFileset((FileSet) e.nextElement()); + } + } + + /** + * Import all files from the fileset into the Project in the + * Workspace. + */ + protected void importFileset(FileSet fileset) { + DirectoryScanner ds = fileset.getDirectoryScanner(this.project); + if (ds.getIncludedFiles().length == 0) { + return; + } + + String[] includes = null; + String[] excludes = null; + + // Hack to get includes and excludes. We could also use getIncludedFiles, + // but that would result in very long HTTP-requests. + // Therefore we want to send the patterns only to the remote tool server + // and let him figure out the files. + try { + Class directoryScanner = ds.getClass(); + + Field includesField = directoryScanner.getDeclaredField("includes"); + includesField.setAccessible(true); + includes = (String[]) includesField.get(ds); + + Field excludesField = directoryScanner.getDeclaredField("excludes"); + excludesField.setAccessible(true); + excludes = (String[]) excludesField.get(ds); + } catch (NoSuchFieldException nsfe) { + throw new BuildException( + "DirectoryScanner.includes or .excludes missing" + nsfe.getMessage()); + } catch (IllegalAccessException iae) { + throw new BuildException( + "Access to DirectoryScanner.includes or .excludes not allowed"); + } + + getUtil().importFiles( importProject, ds.getBasedir(), + includes, excludes, + importClasses, importResources, importSources, + useDefaultExcludes); + } } \ No newline at end of file diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJImportServlet.java b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJImportServlet.java index 2655ef352..5e6057237 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJImportServlet.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJImportServlet.java @@ -59,7 +59,7 @@ import java.io.File; /** * A Remote Access to Tools Servlet to import a Project - * from files into the Repository. The following + * from files into the Repository. The following * table describes the servlet parameters. * * @@ -95,8 +95,8 @@ public class VAJImportServlet extends VAJToolsServlet { getBooleanParam(RESOURCES_PARAM, true), getBooleanParam(SOURCES_PARAM, true), false // no default excludes, because they - // are already added on client side - // getBooleanParam(DEFAULT_EXCLUDES_PARAM, true) + // are already added on client side + // getBooleanParam(DEFAULT_EXCLUDES_PARAM, true) ); } } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJLocalUtil.java b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJLocalUtil.java index e84647916..63237cb9d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJLocalUtil.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJLocalUtil.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2001 The Apache Software Foundation. All rights + * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -9,7 +9,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -17,15 +17,15 @@ * distribution. * * 3. The end-user documentation included with the redistribution, if - * any, must include the following acknowlegement: - * "This product includes software developed by the + * any, must include the following acknowlegement: + * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived - * from this software without prior written permission. For written + * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" @@ -81,7 +81,7 @@ import org.apache.tools.ant.DirectoryScanner; abstract class VAJLocalUtil implements VAJUtil{ // singleton containing the VAJ workspace private static Workspace workspace; - + /** * Wraps IvjException into a BuildException * @@ -100,7 +100,7 @@ abstract class VAJLocalUtil implements VAJUtil{ } return new BuildException(errMsg, e); } - + /** * returns the current VAJ workspace. * @return com.ibm.ivj.util.base.Workspace @@ -111,7 +111,7 @@ abstract class VAJLocalUtil implements VAJUtil{ if (workspace == null) { throw new BuildException( "Unable to connect to Workspace! " - + "Make sure you are running in VisualAge for Java."); + + "Make sure you are running in VisualAge for Java."); } } @@ -122,7 +122,7 @@ abstract class VAJLocalUtil implements VAJUtil{ //----------------------------------------------------------- // export //----------------------------------------------------------- - + /** * export packages */ @@ -131,7 +131,7 @@ abstract class VAJLocalUtil implements VAJUtil{ String[] includePatterns, String[] excludePatterns, boolean exportClasses, boolean exportDebugInfo, boolean exportResources, boolean exportSources, - boolean useDefaultExcludes, boolean overwrite) { + boolean useDefaultExcludes, boolean overwrite) { if (includePatterns == null || includePatterns.length == 0) { log( "You must specify at least one include attribute. " + "Not exporting", MSG_ERR); @@ -147,7 +147,7 @@ abstract class VAJLocalUtil implements VAJUtil{ Package[] packages = scanner.getIncludedPackages(); - log( "Exporting " + packages.length + " package(s) to " + log( "Exporting " + packages.length + " package(s) to " + dest, MSG_INFO); for (int i = 0; i < packages.length; i++) { log(" " + packages[i].getName(), MSG_VERBOSE); @@ -174,7 +174,7 @@ abstract class VAJLocalUtil implements VAJUtil{ //----------------------------------------------------------- // load //----------------------------------------------------------- - + /** * Load specified projects. */ @@ -188,26 +188,26 @@ abstract class VAJLocalUtil implements VAJUtil{ log("No Projects match the name " + d.getName(), MSG_WARN); } } - - log( "Loading " + expandedDescs.size() + + log( "Loading " + expandedDescs.size() + " project(s) into workspace", MSG_INFO); - - for (Enumeration e = expandedDescs.elements(); + + for (Enumeration e = expandedDescs.elements(); e.hasMoreElements(); ) { VAJProjectDescription d = (VAJProjectDescription) e.nextElement(); ProjectEdition pe = findProjectEdition(d.getName(), d.getVersion()); try { - log( "Loading '" + d.getName() + "', Version '" + d.getVersion() - + "', into Workspace", MSG_VERBOSE ); + log( "Loading '" + d.getName() + "', Version '" + d.getVersion() + + "', into Workspace", MSG_VERBOSE ); pe.loadIntoWorkspace(); } catch (IvjException ex) { - throw createBuildException( "Project '" + d.getName() - + "' could not be loaded.", ex ); + throw createBuildException( "Project '" + d.getName() + + "' could not be loaded.", ex ); } } } - + /** * returns a list of project names matching the given pattern */ @@ -237,17 +237,17 @@ abstract class VAJLocalUtil implements VAJUtil{ private Vector getExpandedDescriptions(Vector projectDescs) { Vector expandedDescs = new Vector(projectDescs.size()); try { - String[] projectNames = + String[] projectNames = getWorkspace().getRepository().getProjectNames(); for (int i = 0; i < projectNames.length; i++) { - for (Enumeration e = projectDescs.elements(); + for (Enumeration e = projectDescs.elements(); e.hasMoreElements();) { VAJProjectDescription d = (VAJProjectDescription) e.nextElement(); String pattern = d.getName(); if (VAJWorkspaceScanner.match(pattern, projectNames[i])) { d.setProjectFound(); expandedDescs.addElement(new VAJProjectDescription( - projectNames[i], d.getVersion())); + projectNames[i], d.getVersion())); break; } } @@ -283,8 +283,8 @@ abstract class VAJLocalUtil implements VAJUtil{ } } if (pe == null) { - throw new BuildException( "Version " + versionName - + " of Project " + name + " doesn't exist" ); + throw new BuildException( "Version " + versionName + + " of Project " + name + " doesn't exist" ); } return pe; @@ -299,18 +299,18 @@ abstract class VAJLocalUtil implements VAJUtil{ //----------------------------------------------------------- // import //----------------------------------------------------------- - + /** * Do the import. */ public void importFiles( - String importProject, File srcDir, - String[] includePatterns, String[] excludePatterns, - boolean importClasses, boolean importResources, - boolean importSources, boolean useDefaultExcludes) + String importProject, File srcDir, + String[] includePatterns, String[] excludePatterns, + boolean importClasses, boolean importResources, + boolean importSources, boolean useDefaultExcludes) throws BuildException { - + if (importProject == null || "".equals(importProject)) { throw new BuildException("The VisualAge for Java project " + "name is required!"); @@ -332,20 +332,20 @@ abstract class VAJLocalUtil implements VAJUtil{ Vector sources = new Vector(); Vector resources = new Vector(); - scanForImport( srcDir, ds.getIncludedFiles(), classes, sources, resources); + scanForImport( srcDir, ds.getIncludedFiles(), classes, sources, resources); StringBuffer summaryLog = new StringBuffer("Importing "); addFilesToImport( importSpec, importClasses, classes, "Class", summaryLog ); addFilesToImport( importSpec, importSources, sources, "Java", summaryLog ); addFilesToImport( importSpec, importResources, resources, "Resource", summaryLog ); importSpec.setResourcePath(srcDir.getAbsolutePath()); - + summaryLog.append( " into the project '" ); summaryLog.append( importProject ); summaryLog.append( "'." ); log(summaryLog.toString(), MSG_INFO); - + try { Type[] importedTypes = getWorkspace().importData(importSpec); if (importedTypes == null) { @@ -354,9 +354,9 @@ abstract class VAJLocalUtil implements VAJUtil{ else { log( importedTypes.length + " types imported", MSG_DEBUG); for( int i = 0; i < importedTypes.length; i++ ) { - log( importedTypes[i].getPackage().getName() - + "." + importedTypes[i].getName() - + " into " + importedTypes[i].getProject().getName(), + log( importedTypes[i].getPackage().getName() + + "." + importedTypes[i].getName() + + " into " + importedTypes[i].getProject().getName(), MSG_DEBUG); } } @@ -387,10 +387,10 @@ abstract class VAJLocalUtil implements VAJUtil{ found = getWorkspace().createProject(importProject, true); } catch (IvjException e) { throw createBuildException( "Error while creating Project " - + importProject + ": ", e ); + + importProject + ": ", e ); } } - + return found; } @@ -399,10 +399,10 @@ abstract class VAJLocalUtil implements VAJUtil{ * Sort the files into classes, sources, and resources. */ private void scanForImport( - File dir, - String[] files, - Vector classes, - Vector sources, + File dir, + String[] files, + Vector classes, + Vector sources, Vector resources) { for (int i = 0; i < files.length; i++) { String file = (new File(dir, files[i])).getAbsolutePath(); @@ -438,11 +438,11 @@ abstract class VAJLocalUtil implements VAJUtil{ String[] fileArr = new String[files.size()]; files.copyInto(fileArr); try { - // here it is assumed that fileType is one of the + // here it is assumed that fileType is one of the // following strings: // "Java", "Class", "Resource" String methodName = "set"+fileType+"Files"; Class[] methodParams = new Class[]{fileArr.getClass()}; - java.lang.reflect.Method method = + java.lang.reflect.Method method = spec.getClass().getDeclaredMethod( methodName, methodParams); method.invoke(spec, new Object[]{fileArr}); } catch( Exception e ) { diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJProjectDescription.java b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJProjectDescription.java index f30b16788..4d3f47d5d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJProjectDescription.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJProjectDescription.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2001 The Apache Software Foundation. All rights + * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -9,7 +9,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -17,15 +17,15 @@ * distribution. * * 3. The end-user documentation included with the redistribution, if - * any, must include the following acknowlegement: - * "This product includes software developed by the + * any, must include the following acknowlegement: + * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived - * from this software without prior written permission. For written + * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" @@ -67,31 +67,31 @@ public class VAJProjectDescription { public VAJProjectDescription() { } - + public VAJProjectDescription(String n, String v) { name = n; version = v; } - + public String getName() { return name; } - + public String getVersion() { return version; } - + public boolean projectFound() { return projectFound; } - + public void setName(String newName) { if (newName == null || newName.equals("")) { throw new BuildException("name attribute must be set"); } name = newName; } - + public void setVersion(String newVersion) { if (newVersion == null || newVersion.equals("")) { throw new BuildException("version attribute must be set"); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJRemoteUtil.java b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJRemoteUtil.java index d9fb978e8..4be586365 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJRemoteUtil.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJRemoteUtil.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2001 The Apache Software Foundation. All rights + * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -9,7 +9,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -17,15 +17,15 @@ * distribution. * * 3. The end-user documentation included with the redistribution, if - * any, must include the following acknowlegement: - * "This product includes software developed by the + * any, must include the following acknowlegement: + * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived - * from this software without prior written permission. For written + * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" @@ -90,7 +90,7 @@ class VAJRemoteUtil implements VAJUtil{ /** * export the array of Packages */ - public void exportPackages(File destDir, + public void exportPackages(File destDir, String[] includePatterns, String[] excludePatterns, boolean exportClasses, boolean exportDebugInfo, boolean exportResources, boolean exportSources, boolean useDefaultExcludes, boolean overwrite ) { @@ -112,13 +112,13 @@ class VAJRemoteUtil implements VAJUtil{ * Do the import. */ public void importFiles( - String importProject, File srcDir, - String[] includePatterns, String[] excludePatterns, - boolean importClasses, boolean importResources, + String importProject, File srcDir, + String[] includePatterns, String[] excludePatterns, + boolean importClasses, boolean importResources, boolean importSources, boolean useDefaultExcludes) { try { String request = "http://" + remoteServer + "/servlet/vajimport?" - + VAJImportServlet.PROJECT_NAME_PARAM + "=" + + VAJImportServlet.PROJECT_NAME_PARAM + "=" + importProject + "&" + assembleImportExportParams( srcDir, includePatterns, excludePatterns, @@ -128,7 +128,7 @@ class VAJRemoteUtil implements VAJUtil{ } catch (Exception ex) { throw new BuildException(ex); } - + } /** @@ -137,11 +137,11 @@ class VAJRemoteUtil implements VAJUtil{ */ private String assembleImportExportParams( File dir, - String[] includePatterns, String[] excludePatterns, - boolean includeClasses, boolean includeResources, + String[] includePatterns, String[] excludePatterns, + boolean includeClasses, boolean includeResources, boolean includeSources, boolean useDefaultExcludes) { String result = - VAJToolsServlet.DIR_PARAM + "=" + VAJToolsServlet.DIR_PARAM + "=" + dir.getAbsolutePath().replace('\\', '/') + "&" + VAJToolsServlet.CLASSES_PARAM + "=" + includeClasses + "&" + VAJToolsServlet.RESOURCES_PARAM + "=" + includeResources + "&" @@ -156,14 +156,14 @@ class VAJRemoteUtil implements VAJUtil{ } if ( excludePatterns != null ) { for ( int i = 0; i < excludePatterns.length; i++ ){ - result = result + "&" + VAJExportServlet.EXCLUDE_PARAM + "=" + result = result + "&" + VAJExportServlet.EXCLUDE_PARAM + "=" + excludePatterns[i].replace(' ', '+').replace('\\', '/'); } } return result; } - + /** * Load specified projects. */ @@ -173,8 +173,8 @@ class VAJRemoteUtil implements VAJUtil{ String delimiter = ""; for ( Enumeration e = projectDescriptions.elements(); e.hasMoreElements(); ){ VAJProjectDescription pd = (VAJProjectDescription)e.nextElement(); - request = request - + delimiter + VAJLoadServlet.PROJECT_NAME_PARAM + request = request + + delimiter + VAJLoadServlet.PROJECT_NAME_PARAM + "=" + pd.getName().replace(' ', '+') + "&" + VAJLoadServlet.VERSION_PARAM + "=" + pd.getVersion().replace(' ', '+'); @@ -201,10 +201,10 @@ class VAJRemoteUtil implements VAJUtil{ boolean requestFailed = false; try { log("Request: " + request, MSG_DEBUG); - + //must be HTTP connection URL requestUrl = new URL( request ); - HttpURLConnection connection = + HttpURLConnection connection = (HttpURLConnection) requestUrl.openConnection(); InputStream is = null; @@ -238,7 +238,7 @@ class VAJRemoteUtil implements VAJUtil{ log( line.substring(2), level ); line = br.readLine(); } - + } catch (IOException ex) { log("Error sending tool request to VAJ" + ex, MSG_ERR); throw new BuildException("Couldn't execute " + request ); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJTask.java index 158a067a3..90408b18a 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJTask.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2001 The Apache Software Foundation. All rights + * Copyright (c) 2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -9,7 +9,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -17,15 +17,15 @@ * distribution. * * 3. The end-user documentation included with the redistribution, if - * any, must include the following acknowlegement: - * "This product includes software developed by the + * any, must include the following acknowlegement: + * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived - * from this software without prior written permission. For written + * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" @@ -57,12 +57,12 @@ package org.apache.tools.ant.taskdefs.optional.ide; /** * Super class for all VAJ tasks. Contains common * attributes (remoteServer) and util methods - * + * * @author: Wolf Siberski */ import org.apache.tools.ant.Task; - + public class VAJTask extends Task { /** * Adaption of VAJLocalUtil to Task context. @@ -79,7 +79,7 @@ public class VAJTask extends Task { // holds the appropriate VAJUtil implementation private VAJUtil util = null; - + /** * returns the VAJUtil implementation */ @@ -93,7 +93,7 @@ public class VAJTask extends Task { } return util; } - + /** * Set remote server attribute */ diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJToolsServlet.java b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJToolsServlet.java index 21f4d5049..d5106e426 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJToolsServlet.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJToolsServlet.java @@ -69,7 +69,7 @@ import org.apache.tools.ant.BuildException; /** * Abstract base class to provide common services for the - * VAJ tool API servlets + * VAJ tool API servlets * * @author Wolf Siberski, based on servlets written by Glenn McAllister */ @@ -88,7 +88,7 @@ public abstract class VAJToolsServlet extends HttpServlet { if ( nlPos == -1 ) { nlPos = msg.length(); } - response.getWriter().println( Integer.toString(level) + response.getWriter().println( Integer.toString(level) + " " + msg.substring( i, nlPos )); i = nlPos + 1; } @@ -99,7 +99,7 @@ public abstract class VAJToolsServlet extends HttpServlet { } } } - + // constants for servlet param names public final static String DIR_PARAM = "dir"; public final static String INCLUDE_PARAM = "include"; @@ -124,17 +124,17 @@ public abstract class VAJToolsServlet extends HttpServlet { /** * Execute the request by calling the appropriate * VAJ tool API methods. This method must be implemented - * by the concrete servlets + * by the concrete servlets */ protected abstract void executeRequest(); - + /** * Respond to a HTTP request. This method initializes - * the servlet and handles errors. - * The real work is done in the abstract method executeRequest() + * the servlet and handles errors. + * The real work is done in the abstract method executeRequest() */ public void doGet(HttpServletRequest req, HttpServletResponse res) - throws ServletException, IOException { + throws ServletException, IOException { try { response = res; request = req; @@ -148,14 +148,14 @@ public abstract class VAJToolsServlet extends HttpServlet { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); String trace = new String( sw.getBuffer() ); - util.log("Program error in " + this.getClass().getName() + util.log("Program error in " + this.getClass().getName() + ":\n" + trace, VAJUtil.MSG_ERR); } } catch( Throwable t ) { t.printStackTrace(); } finally { if ( ! (e instanceof BuildException) ) - { + { throw new ServletException( e.getMessage() ); } } @@ -171,7 +171,7 @@ public abstract class VAJToolsServlet extends HttpServlet { util = new VAJLocalServletUtil(); } } - + /** * Get the VAJUtil implementation */ @@ -224,5 +224,5 @@ public abstract class VAJToolsServlet extends HttpServlet { protected boolean toBoolean(String string) { String lower = string.toLowerCase(); return (lower.equals("yes") || lower.equals("true") || lower.equals("ok")); - } + } } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJUtil.java b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJUtil.java index 75fe8e4e5..2424462a3 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJUtil.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJUtil.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -9,7 +9,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -17,15 +17,15 @@ * distribution. * * 3. The end-user documentation included with the redistribution, if - * any, must include the following acknowlegement: - * "This product includes software developed by the + * any, must include the following acknowlegement: + * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived - * from this software without prior written permission. For written + * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" @@ -64,39 +64,39 @@ import java.io.File; * @author Wolf Siberski, TUI Infotec GmbH */ interface VAJUtil { - // log levels - public static final int MSG_DEBUG = 4; - public static final int MSG_ERR = 0; - public static final int MSG_INFO = 2; - public static final int MSG_VERBOSE = 3; - public static final int MSG_WARN = 1; + // log levels + public static final int MSG_DEBUG = 4; + public static final int MSG_ERR = 0; + public static final int MSG_INFO = 2; + public static final int MSG_VERBOSE = 3; + public static final int MSG_WARN = 1; - /** - * export the array of Packages - */ - void exportPackages( - File dest, - String[] includePatterns, String[] excludePatterns, - boolean exportClasses, boolean exportDebugInfo, - boolean exportResources, boolean exportSources, - boolean useDefaultExcludes, boolean overwrite); + /** + * export the array of Packages + */ + void exportPackages( + File dest, + String[] includePatterns, String[] excludePatterns, + boolean exportClasses, boolean exportDebugInfo, + boolean exportResources, boolean exportSources, + boolean useDefaultExcludes, boolean overwrite); - /** - * Do the import. - */ - void importFiles( - String importProject, File srcDir, - String[] includePatterns, String[] excludePatterns, - boolean importClasses, boolean importResources, - boolean importSources, boolean useDefaultExcludes); + /** + * Do the import. + */ + void importFiles( + String importProject, File srcDir, + String[] includePatterns, String[] excludePatterns, + boolean importClasses, boolean importResources, + boolean importSources, boolean useDefaultExcludes); - /** - * Load specified projects. - */ - void loadProjects(Vector projectDescriptions); + /** + * Load specified projects. + */ + void loadProjects(Vector projectDescriptions); - /** - * Logs a message with the specified log level. - */ - void log(String msg, int level); + /** + * Logs a message with the specified log level. + */ + void log(String msg, int level); } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJWorkspaceScanner.java b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJWorkspaceScanner.java index faec26d5b..0cd032455 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJWorkspaceScanner.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJWorkspaceScanner.java @@ -79,7 +79,7 @@ import org.apache.tools.ant.DirectoryScanner; *
  • VisualAge*\**
  • * *

    - * This class works like DirectoryScanner. + * This class works like DirectoryScanner. * * @see org.apache.tools.ant.DirectoryScanner * @@ -88,19 +88,19 @@ import org.apache.tools.ant.DirectoryScanner; class VAJWorkspaceScanner extends DirectoryScanner { // Patterns that should be excluded by default. - private final static String[] DEFAULTEXCLUDES = + private final static String[] DEFAULTEXCLUDES = { - "IBM*/**", - "Java class libraries/**", - "Sun class libraries*/**", - "JSP Page Compile Generated Code/**", - "VisualAge*/**", - }; + "IBM*/**", + "Java class libraries/**", + "Sun class libraries*/**", + "JSP Page Compile Generated Code/**", + "VisualAge*/**", + }; - // The packages that where found and matched at least + // The packages that where found and matched at least // one includes, and matched no excludes. private Vector packagesIncluded = new Vector(); - + /** * Adds the array with default exclusions to the current exclusions set. */ @@ -114,11 +114,11 @@ class VAJWorkspaceScanner extends DirectoryScanner { for (int i = 0; i < DEFAULTEXCLUDES.length; i++) { newExcludes[i + excludesLength] = DEFAULTEXCLUDES[i]. replace( '/', File.separatorChar ). - replace( '\\', File.separatorChar ); + replace( '\\', File.separatorChar ); } excludes = newExcludes; } - + /** * Finds all Projects specified in include patterns. * @@ -133,11 +133,11 @@ class VAJWorkspaceScanner extends DirectoryScanner { for (int i = 0; i < projects.length; i++) { Project project = projects[i]; for (int j = 0; j < includes.length && !allProjectsMatch; j++) { - StringTokenizer tok = + StringTokenizer tok = new StringTokenizer(includes[j], File.separator); String projectNamePattern = tok.nextToken(); if (projectNamePattern.equals("**")) { - // if an include pattern starts with '**', + // if an include pattern starts with '**', // all projects match allProjectsMatch = true; } else @@ -157,7 +157,7 @@ class VAJWorkspaceScanner extends DirectoryScanner { return matchingProjects; } - + /** * Get the names of the packages that matched at least one of the include * patterns, and didn't match one of the exclude patterns. @@ -172,7 +172,7 @@ class VAJWorkspaceScanner extends DirectoryScanner { } return packages; } - + /** * Matches a string against a pattern. The pattern contains two special * characters: @@ -212,7 +212,7 @@ class VAJWorkspaceScanner extends DirectoryScanner { scanProject(project); } } - + /** * Scans a project for packages that match at least one include * pattern, and don't match any exclude patterns. @@ -227,10 +227,10 @@ class VAJWorkspaceScanner extends DirectoryScanner { // replace '.' by file seperator because the patterns are // using file seperator syntax (and we can use the match // methods this way). - String name = + String name = project.getName() + File.separator - + item.getName().replace('.', File.separatorChar); + + item.getName().replace('.', File.separatorChar); if (isIncluded(name) && !isExcluded(name)) { packagesIncluded.addElement(item); } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java index 4528b1e4e..32b28c842 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java @@ -153,7 +153,7 @@ public class JDependTask extends Task { * @see #setFork(boolean) */ public void setJvm(String value) { - _jvm = value; + _jvm = value; } @@ -230,18 +230,18 @@ public class JDependTask extends Task { public void setFormat(FormatAttribute ea) { - format = ea.getValue(); - } + format = ea.getValue(); + } - public static class FormatAttribute extends EnumeratedAttribute - { - private String [] formats = new String[]{"xml","text"}; + public static class FormatAttribute extends EnumeratedAttribute + { + private String [] formats = new String[]{"xml","text"}; - public String[] getValues() - { - return formats; - } - } + public String[] getValues() + { + return formats; + } + } /** @@ -255,16 +255,16 @@ public class JDependTask extends Task { public void execute() throws BuildException { - CommandlineJava commandline = new CommandlineJava(); + CommandlineJava commandline = new CommandlineJava(); - if("text".equals(format)) - commandline.setClassname("jdepend.textui.JDepend"); - else - if("xml".equals(format)) - commandline.setClassname("jdepend.xmlui.JDepend"); + if("text".equals(format)) + commandline.setClassname("jdepend.textui.JDepend"); + else + if("xml".equals(format)) + commandline.setClassname("jdepend.xmlui.JDepend"); - if(_jvm!=null) - commandline.setVm(_jvm); + if(_jvm!=null) + commandline.setVm(_jvm); if (getSourcespath() == null) throw new BuildException("Missing Sourcepath required argument"); @@ -311,9 +311,9 @@ public class JDependTask extends Task { jdepend.textui.JDepend jdepend; if("xml".equals(format)) - jdepend = new jdepend.xmlui.JDepend(); + jdepend = new jdepend.xmlui.JDepend(); else - jdepend = new jdepend.textui.JDepend(); + jdepend = new jdepend.textui.JDepend(); if (getOutputFile() != null) { FileWriter fw; diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java index 02482eb5f..3edbb8dd1 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java @@ -96,10 +96,10 @@ public class AggregateTransformer { public final static String NOFRAMES = "noframes"; public static class Format extends EnumeratedAttribute { - public String[] getValues(){ - return new String[]{FRAMES, NOFRAMES}; - } - } + public String[] getValues(){ + return new String[]{FRAMES, NOFRAMES}; + } + } /** Task */ protected Task task; diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/BaseTest.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/BaseTest.java index 868955d49..eaaee4dc8 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/BaseTest.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/BaseTest.java @@ -60,7 +60,7 @@ import java.util.Vector; /** * Baseclass for BatchTest and JUnitTest. * - * @author Stefan Bodewig + * @author Stefan Bodewig * @author Stephane Bailliez */ public abstract class BaseTest { @@ -116,12 +116,12 @@ public abstract class BaseTest { * Sets the destination directory. */ public void setTodir(File destDir) { - this.destDir = destDir; + this.destDir = destDir; } /** * @return the destination directory as an absolute path if it exists - * otherwise return null + * otherwise return null */ public String getTodir(){ if (destDir != null){ @@ -133,15 +133,15 @@ public abstract class BaseTest { public java.lang.String getFailureProperty() { return failureProperty; } - + public void setFailureProperty(String failureProperty) { this.failureProperty = failureProperty; } - + public java.lang.String getErrorProperty() { return errorProperty; } - + public void setErrorProperty(String errorProperty) { this.errorProperty = errorProperty; } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java index c592ad896..a5ddc6ffd 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java @@ -92,31 +92,31 @@ import org.apache.tools.ant.util.DOMElementWriter; * @author Stephane Bailliez */ public class XMLResultAggregator extends Task implements XMLConstants { - + /** the list of all filesets, that should contains the xml to aggregate */ protected Vector filesets = new Vector(); - + /** the name of the result file */ protected String toFile; - + /** the directory to write the file to */ protected File toDir; - + protected Vector transformers = new Vector(); - + /** the default directory: .. It is resolved from the project directory */ public final static String DEFAULT_DIR = "."; - + /** the default file name: TESTS-TestSuites.xml */ public final static String DEFAULT_FILENAME = "TESTS-TestSuites.xml"; - - + + public AggregateTransformer createReport(){ AggregateTransformer transformer = new AggregateTransformer(this); transformers.addElement(transformer); return transformer; } - + /** * Set the name of the file aggregating the results. It must be relative * from the todir attribute. If not set it will use {@link #DEFAULT_FILENAME} @@ -126,7 +126,7 @@ public class XMLResultAggregator extends Task implements XMLConstants { public void setTofile(String value){ toFile = value; } - + /** * Set the destination directory where the results should be written. If not * set if will use {@link #DEFAULT_DIR}. When given a relative directory @@ -137,7 +137,7 @@ public class XMLResultAggregator extends Task implements XMLConstants { public void setTodir(File value){ toDir = value; } - + /** * Add a new fileset containing the xml results to aggregate * @param fs the new fileset of xml results. @@ -145,12 +145,12 @@ public class XMLResultAggregator extends Task implements XMLConstants { public void addFileSet(FileSet fs) { filesets.addElement(fs); } - + /** * Aggregate all testsuites into a single document and write it to the * specified directory and file. - * @throws BuildException thrown if there is a serious error while writing - * the document. + * @throws BuildException thrown if there is a serious error while writing + * the document. */ public void execute() throws BuildException { Element rootElement = createDocument(); @@ -170,7 +170,7 @@ public class XMLResultAggregator extends Task implements XMLConstants { transformer.transform(); } } - + /** * Get the full destination file where to write the result. It is made of * the todir and tofile attributes. @@ -185,7 +185,7 @@ public class XMLResultAggregator extends Task implements XMLConstants { } return new File(toDir, toFile); } - + /** * Get all .xml files in the fileset. * @@ -208,14 +208,14 @@ public class XMLResultAggregator extends Task implements XMLConstants { } } } - + File[] files = new File[v.size()]; v.copyInto(files); return files; } - + //----- from now, the methods are all related to DOM tree manipulation - + /** * Write the DOM tree to a file. * @param doc the XML document to dump to disk. @@ -234,12 +234,12 @@ public class XMLResultAggregator extends Task implements XMLConstants { throw new IOException("Error while writing DOM content"); } } - + /** - *

    Create a DOM tree. + *

    Create a DOM tree. * Has 'testsuites' as firstchild and aggregates all * testsuite results that exists in the base directory. - * @return the root element of DOM tree that aggregates all testsuites. + * @return the root element of DOM tree that aggregates all testsuites. */ protected Element createDocument() { // create the dom tree @@ -247,7 +247,7 @@ public class XMLResultAggregator extends Task implements XMLConstants { Document doc = builder.newDocument(); Element rootElement = doc.createElement(TESTSUITES); doc.appendChild(rootElement); - + // get all files and add them to the document File[] files = getFiles(); for (int i = 0; i < files.length; i++) { @@ -278,7 +278,7 @@ public class XMLResultAggregator extends Task implements XMLConstants { } return rootElement; } - + /** *

    Add a new testsuite node to the document. * The main difference is that it @@ -294,17 +294,17 @@ public class XMLResultAggregator extends Task implements XMLConstants { protected void addTestSuite(Element root, Element testsuite){ String fullclassname = testsuite.getAttribute(ATTR_NAME); int pos = fullclassname.lastIndexOf('.'); - + // a missing . might imply no package at all. Don't get fooled. String pkgName = (pos == -1) ? "" : fullclassname.substring(0, pos); String classname = (pos == -1) ? fullclassname : fullclassname.substring(pos + 1); Element copy = (Element)DOMUtil.importNode(root, testsuite); - + // modify the name attribute and set the package copy.setAttribute(ATTR_NAME, classname); copy.setAttribute(ATTR_PACKAGE, pkgName); } - + /** * Create a new document builder. Will issue an ExceptionInitializerError * if something is going wrong. It is fatal anyway. @@ -318,5 +318,5 @@ public class XMLResultAggregator extends Task implements XMLConstants { throw new ExceptionInInitializerError(exc); } } - + } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/metamata/MMetricsStreamHandler.java b/src/main/org/apache/tools/ant/taskdefs/optional/metamata/MMetricsStreamHandler.java index 4af92e8ae..9e3ccce28 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/metamata/MMetricsStreamHandler.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/metamata/MMetricsStreamHandler.java @@ -85,7 +85,7 @@ import org.apache.tools.ant.Project; * A handy metrics handler. Most of this code was done only with the * screenshots on the documentation since the evaluation version as * of this writing does not allow to save metrics or to run it via - * command line. + * command line. *

    * This class can be used to transform a text file or to process the * output stream directly. @@ -96,23 +96,23 @@ public class MMetricsStreamHandler implements ExecuteStreamHandler { /** CLASS construct, it should be named something like 'MyClass' */ protected final static String CLASS = "class"; - + /** package construct, it should be look like 'com.mycompany.something' */ protected final static String PACKAGE = "package"; - + /** FILE construct, it should look like something 'MyClass.java' or 'MyClass.class' */ protected final static String FILE = "file"; - + /** METHOD construct, it should looke like something 'doSomething(...)' or 'doSomething()' */ protected final static String METHOD = "method"; - + protected final static String[] ATTRIBUTES = { "name", "vg", "loc", "dit", "noa", "nrm", "nlm", "wmc", "rfc", "dac", "fanout", "cbo", "lcom", "nocl" }; - + /** reader for stdout */ protected InputStream metricsOutput; - + /** * this is where the XML output will go, should mostly be a file * the caller is responsible for flushing and closing this stream @@ -121,7 +121,7 @@ public class MMetricsStreamHandler implements ExecuteStreamHandler { /** metrics handler */ protected TransformerHandler metricsHandler; - + /** the task */ protected Task task; @@ -130,7 +130,7 @@ public class MMetricsStreamHandler implements ExecuteStreamHandler { * know if we have to close an element or not. */ protected Stack stack = new Stack(); - + /** initialize this handler */ MMetricsStreamHandler(Task task, OutputStream xmlOut){ this.task = task; @@ -162,7 +162,7 @@ public class MMetricsStreamHandler implements ExecuteStreamHandler { metricsHandler.setResult( new StreamResult( new OutputStreamWriter(xmlOutputStream, "UTF-8")) ); Transformer transformer = metricsHandler.getTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); - + // start the document with a 'metrics' root metricsHandler.startDocument(); AttributesImpl attr = new AttributesImpl(); @@ -179,7 +179,7 @@ public class MMetricsStreamHandler implements ExecuteStreamHandler { } /** - * Pretty dangerous business here. + * Pretty dangerous business here. */ public void stop() { try { @@ -197,7 +197,7 @@ public class MMetricsStreamHandler implements ExecuteStreamHandler { e.printStackTrace(); throw new IllegalStateException(e.getMessage()); } - } + } /** read each line and process it */ protected void parseOutput() throws IOException, SAXException { @@ -221,12 +221,12 @@ public class MMetricsStreamHandler implements ExecuteStreamHandler { MetricsElement elem = MetricsElement.parse(line); startElement(elem); } catch (ParseException e) { - e.printStackTrace(); + e.printStackTrace(); // invalid lines are sent to the output as information, it might be anything, task.log(line, Project.MSG_INFO); } } - + /** * Start a new construct. Elements are popped until we are on the same * parent node, then the element type is guessed and pushed on the @@ -249,7 +249,7 @@ public class MMetricsStreamHandler implements ExecuteStreamHandler { } } catch (EmptyStackException ignored){} } - + // ok, now start the new construct String type = getConstructType(elem); Attributes attrs = createAttributes(elem); @@ -272,7 +272,7 @@ public class MMetricsStreamHandler implements ExecuteStreamHandler { if ( elem.isCompilationUnit() ){ return FILE; } - + // same, we're sure it's a method if ( elem.isMethod() ){ return METHOD; @@ -282,7 +282,7 @@ public class MMetricsStreamHandler implements ExecuteStreamHandler { if ( stack.size() == 0 ){ return PACKAGE; } - + // ok, this is now black magic time, we will guess the type based on // the previous type and its indent... final ElementEntry previous = (ElementEntry)stack.peek(); @@ -299,16 +299,16 @@ public class MMetricsStreamHandler implements ExecuteStreamHandler { if ( prevType.equals(CLASS) && indent >= prevIndent ){ return CLASS; } - + // we assume the other are package return PACKAGE; - } - - + } + + /** * Create all attributes of a MetricsElement skipping those who have an * empty string - * @param elem + * @param elem */ protected Attributes createAttributes(MetricsElement elem){ AttributesImpl impl = new AttributesImpl(); @@ -325,7 +325,7 @@ public class MMetricsStreamHandler implements ExecuteStreamHandler { } return impl; } - + /** * helper class to keep track of elements via its type and indent * that's all we need to guess a type. @@ -348,35 +348,35 @@ public class MMetricsStreamHandler implements ExecuteStreamHandler { class MetricsElement { - private final static NumberFormat METAMATA_NF; - - private final static NumberFormat NEUTRAL_NF; - static { + private final static NumberFormat METAMATA_NF; + + private final static NumberFormat NEUTRAL_NF; + static { METAMATA_NF = NumberFormat.getInstance(); METAMATA_NF.setMaximumFractionDigits(1); NEUTRAL_NF = NumberFormat.getInstance(); - if (NEUTRAL_NF instanceof DecimalFormat) { - ((DecimalFormat) NEUTRAL_NF).applyPattern("###0.###;-###0.###"); - } + if (NEUTRAL_NF instanceof DecimalFormat) { + ((DecimalFormat) NEUTRAL_NF).applyPattern("###0.###;-###0.###"); + } NEUTRAL_NF.setMaximumFractionDigits(1); - } - + } + private int indent; - + private String construct; - + private Vector metrics; - + MetricsElement(int indent, String construct, Vector metrics){ this.indent = indent; this.construct = construct; this.metrics = metrics; } - + public int getIndent(){ return indent; } - + public String getName(){ return construct; } @@ -384,38 +384,38 @@ class MetricsElement { public Enumeration getMetrics(){ return metrics.elements(); } - + public boolean isCompilationUnit(){ return ( construct.endsWith(".java") || construct.endsWith(".class") ); } - + public boolean isMethod(){ return ( construct.endsWith("(...)") || construct.endsWith("()") ); } - + public static MetricsElement parse(String line) throws ParseException { final Vector metrics = new Vector(); int pos; - + // i'm using indexOf since I need to know if there are empty strings // between tabs and I find it easier than with StringTokenizer while ( (pos = line.indexOf('\t')) != -1 ){ String token = line.substring(0, pos); // only parse what coudl be a valid number. ie not constructs nor no value /*if (metrics.size() != 0 || token.length() != 0){ - Number num = METAMATA_NF.parse(token); // parse with Metamata NF - token = NEUTRAL_NF.format(num.doubleValue()); // and format with a neutral NF - }*/ + Number num = METAMATA_NF.parse(token); // parse with Metamata NF + token = NEUTRAL_NF.format(num.doubleValue()); // and format with a neutral NF + }*/ metrics.addElement( token ); line = line.substring(pos + 1); } metrics.addElement( line ); - + // there should be exactly 14 tokens (1 name + 13 metrics), if not, there is a problem ! if ( metrics.size() != 14 ){ throw new ParseException("Could not parse the following line as a metrics: -->" + line +"<--", -1); } - + // remove the first token it's made of the indentation string and the // construct name, we'll need all this to figure out what type of // construct it is since we lost all semantics :( diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Edit.java b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Edit.java index 36e287bf6..151c81200 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Edit.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Edit.java @@ -68,18 +68,18 @@ import org.apache.tools.ant.BuildException; * * ToDo: Should call reopen if file is already open in one of our changelists perhaps? */ - + public class P4Edit extends P4Base { - - public String change = null; - - public void setChange(String change) { - this.change = change; - } - - public void execute() throws BuildException { - if(change != null ) P4CmdOpts = "-c "+change; - if(P4View == null) throw new BuildException("No view specified to edit"); - execP4Command("-s edit "+P4CmdOpts+" "+P4View, new SimpleP4OutputHandler(this)); - } + + public String change = null; + + public void setChange(String change) { + this.change = change; + } + + public void execute() throws BuildException { + if(change != null ) P4CmdOpts = "-c "+change; + if(P4View == null) throw new BuildException("No view specified to edit"); + execP4Command("-s edit "+P4CmdOpts+" "+P4View, new SimpleP4OutputHandler(this)); + } } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4HandlerAdapter.java b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4HandlerAdapter.java index 00f63eac0..f6eb1ce86 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4HandlerAdapter.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4HandlerAdapter.java @@ -78,7 +78,7 @@ public abstract class P4HandlerAdapter implements P4Handler { public void start() throws BuildException { try{ - //First write any output to P4 + //First write any output to P4 if(p4input != null && p4input.length() >0 && os != null) { os.write(p4input.getBytes()); os.flush(); @@ -86,17 +86,17 @@ public abstract class P4HandlerAdapter implements P4Handler { } //Now read any input and process - + BufferedReader input = new BufferedReader( new InputStreamReader( new SequenceInputStream(is,es))); String line; - while((line = input.readLine()) != null) { - process(line); - } - - input.close(); + while((line = input.readLine()) != null) { + process(line); + } + + input.close(); }catch(Exception e) { diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Label.java b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Label.java index 720afdfb6..429cfd342 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Label.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Label.java @@ -72,7 +72,7 @@ import java.text.SimpleDateFormat; * * Label name defaults to AntLabel if none set. * - * Example Usage: + * Example Usage: *

      *   <P4Label name="MyLabel-${TSTAMP}-${DSTAMP}" desc="Auto Build Label" />
      * 
    @@ -84,46 +84,46 @@ public class P4Label extends P4Base { protected String name; protected String desc; protected String lock; - + public void setName(String name) { this.name = name; } - + public void setDesc(String desc) { this.desc = desc; } - - public void setLock(String lock) { - this.lock = lock; - } - + + public void setLock(String lock) { + this.lock = lock; + } + public void execute() throws BuildException { log("P4Label exec:",Project.MSG_INFO); - + if(P4View == null || P4View.length() < 1) { log("View not set, assuming //depot/...", Project.MSG_WARN); P4View = "//depot/..."; } - + if(desc == null || desc.length() < 1) { log("Label Description not set, assuming 'AntLabel'", Project.MSG_WARN); desc = "AntLabel"; } - - if(lock != null && !lock.equalsIgnoreCase("locked")) { - log("lock attribute invalid - ignoring",Project.MSG_WARN); - } - + + if(lock != null && !lock.equalsIgnoreCase("locked")) { + log("lock attribute invalid - ignoring",Project.MSG_WARN); + } + if(name == null || name.length() < 1) { SimpleDateFormat formatter = new SimpleDateFormat ("yyyy.MM.dd-hh:mm"); Date now = new Date(); name = "AntLabel-"+formatter.format(now); log("name not set, assuming '"+name+"'", Project.MSG_WARN); } - - + + //We have to create a unlocked label first - String newLabel = + String newLabel = "Label: "+name+"\n"+ "Description: "+desc+"\n"+ "Options: unlocked\n"+ @@ -138,56 +138,56 @@ public class P4Label extends P4Base { handler.setOutput(newLabel); execP4Command("label -i", handler); - + execP4Command("labelsync -l "+name, new P4HandlerAdapter() { public void process(String line) { log(line, Project.MSG_VERBOSE); } }); - - + + log("Created Label "+name+" ("+desc+")", Project.MSG_INFO); //Now lock if required if (lock != null && lock.equalsIgnoreCase("locked")) { - - log("Modifying lock status to 'locked'",Project.MSG_INFO); - final StringBuffer labelSpec = new StringBuffer(); - - //Read back the label spec from perforce, + log("Modifying lock status to 'locked'",Project.MSG_INFO); + + final StringBuffer labelSpec = new StringBuffer(); + + //Read back the label spec from perforce, //Replace Options //Submit back to Perforce - - handler = new P4HandlerAdapter() { - public void process(String line) { - log(line, Project.MSG_VERBOSE); - - if(util.match("/^Options:/",line)) { - line = "Options: "+lock; - } - + + handler = new P4HandlerAdapter() { + public void process(String line) { + log(line, Project.MSG_VERBOSE); + + if(util.match("/^Options:/",line)) { + line = "Options: "+lock; + } + labelSpec.append(line+"\n"); - } - }; - - - - execP4Command("label -o "+name, handler); + } + }; + + + + execP4Command("label -o "+name, handler); log(labelSpec.toString(),Project.MSG_DEBUG); log("Now locking label...",Project.MSG_VERBOSE); - handler = new P4HandlerAdapter() { - public void process(String line) { - log(line, Project.MSG_VERBOSE); - } - }; + handler = new P4HandlerAdapter() { + public void process(String line) { + log(line, Project.MSG_VERBOSE); + } + }; handler.setOutput(labelSpec.toString()); - execP4Command("label -i", handler); + execP4Command("label -i", handler); } - - + + } } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Submit.java b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Submit.java index 19a0c2740..94add98e6 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Submit.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Submit.java @@ -63,8 +63,8 @@ import org.apache.tools.ant.Project; /** P4Submit - submit a numbered changelist to Perforce. * - * Note: P4Submit cannot (yet) submit the default changelist. - * This shouldn't be a problem with the ANT API as the usual flow is + * Note: P4Submit cannot (yet) submit the default changelist. + * This shouldn't be a problem with the ANT API as the usual flow is * P4Change to create a new numbered change followed by P4Edit then P4Submit. * * Example Usage:-
    @@ -75,25 +75,27 @@ import org.apache.tools.ant.Project; */ public class P4Submit extends P4Base { - //ToDo: If dealing with default cl need to parse out + //ToDo: If dealing with default cl need to parse out public String change; public void setChange(String change) { this.change = change; - } + } public void execute() throws BuildException { if(change != null) { - execP4Command("submit -c "+change, new P4HandlerAdapter(){ - public void process(String line) { - log(line, Project.MSG_VERBOSE); - } - }); - - } else { - //here we'd parse the output from change -o into submit -i - //in order to support default change. - throw new BuildException("No change specified (no support for default change yet...."); - } - } - + execP4Command("submit -c "+change, + new P4HandlerAdapter() { + public void process(String line) { + log(line, Project.MSG_VERBOSE); + } + } + ); + + } else { + //here we'd parse the output from change -o into submit -i + //in order to support default change. + throw new BuildException("No change specified (no support for default change yet...."); + } + } + } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/SimpleP4OutputHandler.java b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/SimpleP4OutputHandler.java index 7bb964fe0..69b88d400 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/SimpleP4OutputHandler.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/SimpleP4OutputHandler.java @@ -63,30 +63,30 @@ import org.apache.tools.ant.Project; public class SimpleP4OutputHandler extends P4HandlerAdapter { - P4Base parent; - public SimpleP4OutputHandler(P4Base parent) { - this.parent = parent; - } - - public void process(String line) throws BuildException { - if(parent.util.match("/^exit/",line)) return; + P4Base parent; + public SimpleP4OutputHandler(P4Base parent) { + this.parent = parent; + } - //Throw exception on errors (except up-to-date) - //p4 -s is unpredicatable. For example a server down - //does not return error: markup - // - //Some forms producing commands (p4 -s change -o) do tag the output - //others don't..... - //Others mark errors as info, for example edit a file - //which is already open for edit..... - //Just look for error: - catches most things.... + public void process(String line) throws BuildException { + if(parent.util.match("/^exit/",line)) return; - if(parent.util.match("/error:/", line) && !parent.util.match("/up-to-date/", line)) { - throw new BuildException(line); - - } + //Throw exception on errors (except up-to-date) + //p4 -s is unpredicatable. For example a server down + //does not return error: markup + // + //Some forms producing commands (p4 -s change -o) do tag the output + //others don't..... + //Others mark errors as info, for example edit a file + //which is already open for edit..... + //Just look for error: - catches most things.... - parent.log(parent.util.substitute("s/^.*: //",line), Project.MSG_INFO); - - } + if(parent.util.match("/error:/", line) && !parent.util.match("/up-to-date/", line)) { + throw new BuildException(line); + + } + + parent.log(parent.util.substitute("s/^.*: //",line), Project.MSG_INFO); + + } } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/XMLReport.java b/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/XMLReport.java index 32c87c34b..cb54e3f51 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/XMLReport.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/XMLReport.java @@ -409,7 +409,7 @@ public class XMLReport { methods.addElement(method); log("keeping " + signature); } else { -// log("discarding " + signature); +// log("discarding " + signature); } } return methods; diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/bytecode/ClassPathLoader.java b/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/bytecode/ClassPathLoader.java index 1dd1bcf59..919a15747 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/bytecode/ClassPathLoader.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/bytecode/ClassPathLoader.java @@ -75,155 +75,155 @@ import java.util.zip.ZipEntry; * @author Stephane Bailliez */ public class ClassPathLoader { - - public final static FileLoader NULL_LOADER = new NullLoader(); - - /** the list of files to look for */ - protected File[] files; - - /** - * create a new instance with a given classpath. It must be urls - * separated by the platform specific path separator. - * @param classPath the classpath to load all the classes from. - */ - public ClassPathLoader(String classPath){ - StringTokenizer st = new StringTokenizer(classPath, File.pathSeparator); - Vector entries = new Vector(); - while (st.hasMoreTokens()){ - File file = new File(st.nextToken()); - entries.addElement(file); - } - files = new File[entries.size()]; - entries.copyInto(files); - } - - /** - * create a new instance with a given set of urls. - * @param entries valid file urls (either .jar, .zip or directory) - */ - public ClassPathLoader(String[] entries){ - files = new File[entries.length]; - for (int i = 0; i < entries.length; i++){ - files[i] = new File(entries[i]); - } - } - - /** - * create a new instance with a given set of urls - * @param entries file urls to look for classes (.jar, .zip or directory) - */ - public ClassPathLoader(File[] entries){ - files = entries; - } - - /** the interface to implement to look up for specific resources */ - public interface FileLoader { - /** the file url that is looked for .class files */ - public File getFile(); - /** return the set of classes found in the file */ - public ClassFile[] getClasses() throws IOException; - } - - /** - * @return the set of FileLoader loaders matching the given classpath. - */ - public Enumeration loaders(){ - return new LoaderEnumeration(); - } - - /** - * return the whole set of classes in the classpath. Note that this method - * can be very resource demanding since it must load all bytecode from - * all classes in all resources in the classpath at a time. - * To process it in a less resource demanding way, it is maybe better to - * use the loaders() that will return loader one by one. - * - * @return the hashtable containing ALL classes that are found in the given - * classpath. Note that the first entry of a given classname will shadow - * classes with the same name (as a classloader does) - */ - public Hashtable getClasses() throws IOException { - Hashtable map = new Hashtable(); - Enumeration enum = loaders(); - while ( enum.hasMoreElements() ){ - FileLoader loader = (FileLoader)enum.nextElement(); - System.out.println("Processing " + loader.getFile()); - long t0 = System.currentTimeMillis(); - ClassFile[] classes = loader.getClasses(); - long dt = System.currentTimeMillis() - t0; - System.out.println("" + classes.length + " classes loaded in " + dt + "ms"); - for (int j = 0; j < classes.length; j++){ - String name = classes[j].getFullName(); - // do not allow duplicates entries to preserve 'classpath' behavior - // first class in wins - if ( !map.containsKey(name) ){ - map.put(name, classes[j]); - } - } - } - return map; - } - - /** the loader enumeration that will return loaders */ - protected class LoaderEnumeration implements Enumeration { - protected int index = 0; - public boolean hasMoreElements(){ - return index < files.length; - } - public Object nextElement(){ - if (index >= files.length){ - throw new NoSuchElementException(); - } - File file = files[index++]; - if ( !file.exists() ){ - return new NullLoader(file); - } - if ( file.isDirectory() ){ - // it's a directory - return new DirectoryLoader(file); - } else if ( file.getName().endsWith(".zip") || file.getName().endsWith(".jar") ){ - // it's a jar/zip file - return new JarLoader(file); - } - return new NullLoader(file); - - } - } - - /** - * useful methods to read the whole input stream in memory so that - * it can be accessed faster. Processing rt.jar and tools.jar from JDK 1.3.1 - * brings time from 50s to 7s. - */ + + public final static FileLoader NULL_LOADER = new NullLoader(); + + /** the list of files to look for */ + protected File[] files; + + /** + * create a new instance with a given classpath. It must be urls + * separated by the platform specific path separator. + * @param classPath the classpath to load all the classes from. + */ + public ClassPathLoader(String classPath){ + StringTokenizer st = new StringTokenizer(classPath, File.pathSeparator); + Vector entries = new Vector(); + while (st.hasMoreTokens()){ + File file = new File(st.nextToken()); + entries.addElement(file); + } + files = new File[entries.size()]; + entries.copyInto(files); + } + + /** + * create a new instance with a given set of urls. + * @param entries valid file urls (either .jar, .zip or directory) + */ + public ClassPathLoader(String[] entries){ + files = new File[entries.length]; + for (int i = 0; i < entries.length; i++){ + files[i] = new File(entries[i]); + } + } + + /** + * create a new instance with a given set of urls + * @param entries file urls to look for classes (.jar, .zip or directory) + */ + public ClassPathLoader(File[] entries){ + files = entries; + } + + /** the interface to implement to look up for specific resources */ + public interface FileLoader { + /** the file url that is looked for .class files */ + public File getFile(); + /** return the set of classes found in the file */ + public ClassFile[] getClasses() throws IOException; + } + + /** + * @return the set of FileLoader loaders matching the given classpath. + */ + public Enumeration loaders(){ + return new LoaderEnumeration(); + } + + /** + * return the whole set of classes in the classpath. Note that this method + * can be very resource demanding since it must load all bytecode from + * all classes in all resources in the classpath at a time. + * To process it in a less resource demanding way, it is maybe better to + * use the loaders() that will return loader one by one. + * + * @return the hashtable containing ALL classes that are found in the given + * classpath. Note that the first entry of a given classname will shadow + * classes with the same name (as a classloader does) + */ + public Hashtable getClasses() throws IOException { + Hashtable map = new Hashtable(); + Enumeration enum = loaders(); + while ( enum.hasMoreElements() ){ + FileLoader loader = (FileLoader)enum.nextElement(); + System.out.println("Processing " + loader.getFile()); + long t0 = System.currentTimeMillis(); + ClassFile[] classes = loader.getClasses(); + long dt = System.currentTimeMillis() - t0; + System.out.println("" + classes.length + " classes loaded in " + dt + "ms"); + for (int j = 0; j < classes.length; j++){ + String name = classes[j].getFullName(); + // do not allow duplicates entries to preserve 'classpath' behavior + // first class in wins + if ( !map.containsKey(name) ){ + map.put(name, classes[j]); + } + } + } + return map; + } + + /** the loader enumeration that will return loaders */ + protected class LoaderEnumeration implements Enumeration { + protected int index = 0; + public boolean hasMoreElements(){ + return index < files.length; + } + public Object nextElement(){ + if (index >= files.length){ + throw new NoSuchElementException(); + } + File file = files[index++]; + if ( !file.exists() ){ + return new NullLoader(file); + } + if ( file.isDirectory() ){ + // it's a directory + return new DirectoryLoader(file); + } else if ( file.getName().endsWith(".zip") || file.getName().endsWith(".jar") ){ + // it's a jar/zip file + return new JarLoader(file); + } + return new NullLoader(file); + + } + } + + /** + * useful methods to read the whole input stream in memory so that + * it can be accessed faster. Processing rt.jar and tools.jar from JDK 1.3.1 + * brings time from 50s to 7s. + */ public static InputStream getCachedStream(InputStream is) throws IOException { - is = new BufferedInputStream(is); - byte[] buffer = new byte[8192]; - ByteArrayOutputStream baos = new ByteArrayOutputStream(2048); - int n; - baos.reset(); - while ((n = is.read(buffer, 0, buffer.length)) != -1) { - baos.write(buffer, 0, n); - } - is.close(); - return new ByteArrayInputStream(baos.toByteArray()); + is = new BufferedInputStream(is); + byte[] buffer = new byte[8192]; + ByteArrayOutputStream baos = new ByteArrayOutputStream(2048); + int n; + baos.reset(); + while ((n = is.read(buffer, 0, buffer.length)) != -1) { + baos.write(buffer, 0, n); + } + is.close(); + return new ByteArrayInputStream(baos.toByteArray()); } } /** a null loader to return when the file is not valid */ class NullLoader implements ClassPathLoader.FileLoader { - private File file; - NullLoader(){ - this(null); - } - NullLoader(File file){ - this.file = file; - } - public File getFile(){ - return file; - } - public ClassFile[] getClasses() throws IOException { - return new ClassFile[0]; - } + private File file; + NullLoader(){ + this(null); + } + NullLoader(File file){ + this.file = file; + } + public File getFile(){ + return file; + } + public ClassFile[] getClasses() throws IOException { + return new ClassFile[0]; + } } /** @@ -232,30 +232,30 @@ class NullLoader implements ClassPathLoader.FileLoader { * entry. */ class JarLoader implements ClassPathLoader.FileLoader { - private File file; - JarLoader(File file){ - this.file = file; - } - public File getFile(){ - return file; - } - public ClassFile[] getClasses() throws IOException { - ZipFile zipFile = new ZipFile(file); - Vector v = new Vector(); - Enumeration entries = zipFile.entries(); - while (entries.hasMoreElements()){ - ZipEntry entry = (ZipEntry)entries.nextElement(); - if (entry.getName().endsWith(".class")){ - InputStream is = ClassPathLoader.getCachedStream(zipFile.getInputStream(entry)); - ClassFile classFile = new ClassFile(is); - is.close(); - v.addElement(classFile); - } - } - ClassFile[] classes = new ClassFile[v.size()]; - v.copyInto(classes); - return classes; - } + private File file; + JarLoader(File file){ + this.file = file; + } + public File getFile(){ + return file; + } + public ClassFile[] getClasses() throws IOException { + ZipFile zipFile = new ZipFile(file); + Vector v = new Vector(); + Enumeration entries = zipFile.entries(); + while (entries.hasMoreElements()){ + ZipEntry entry = (ZipEntry)entries.nextElement(); + if (entry.getName().endsWith(".class")){ + InputStream is = ClassPathLoader.getCachedStream(zipFile.getInputStream(entry)); + ClassFile classFile = new ClassFile(is); + is.close(); + v.addElement(classFile); + } + } + ClassFile[] classes = new ClassFile[v.size()]; + v.copyInto(classes); + return classes; + } } /** @@ -264,93 +264,93 @@ class JarLoader implements ClassPathLoader.FileLoader { * match the directory ? */ class DirectoryLoader implements ClassPathLoader.FileLoader { - private File directory; - - DirectoryLoader(File dir){ - directory = dir; - } - public File getFile(){ - return directory; - } - public ClassFile[] getClasses() throws IOException { - Vector v = new Vector(); - Vector files = listFiles( directory, new ClassFilter(), true); - for (int i = 0; i < files.size(); i++){ - File file = (File)files.elementAt(i); - InputStream is = null; - try { - is = ClassPathLoader.getCachedStream(new FileInputStream(file)); - ClassFile classFile = new ClassFile(is); - is.close(); - is = null; - v.addElement(classFile); - } finally { - if (is != null){ - try { - is.close(); - } catch (IOException ignored){} - } - } - } - ClassFile[] classes = new ClassFile[v.size()]; - v.copyInto(classes); - return classes; - } + private File directory; - /** - * List files that obeys to a specific filter recursively from a given base - * directory. - * @param directory the directory where to list the files from. - * @param filter the file filter to apply - * @param recurse tells whether or not the listing is recursive. - * @return the list of File objects that applies to the given - * filter. - */ - public static Vector listFiles(File directory, FilenameFilter filter, boolean recurse){ - if (!directory.isDirectory()){ - throw new IllegalArgumentException(directory + " is not a directory"); - } - Vector list = new Vector(); - listFilesTo(list, directory, filter, recurse); - return list; - } + DirectoryLoader(File dir){ + directory = dir; + } + public File getFile(){ + return directory; + } + public ClassFile[] getClasses() throws IOException { + Vector v = new Vector(); + Vector files = listFiles( directory, new ClassFilter(), true); + for (int i = 0; i < files.size(); i++){ + File file = (File)files.elementAt(i); + InputStream is = null; + try { + is = ClassPathLoader.getCachedStream(new FileInputStream(file)); + ClassFile classFile = new ClassFile(is); + is.close(); + is = null; + v.addElement(classFile); + } finally { + if (is != null){ + try { + is.close(); + } catch (IOException ignored){} + } + } + } + ClassFile[] classes = new ClassFile[v.size()]; + v.copyInto(classes); + return classes; + } + + /** + * List files that obeys to a specific filter recursively from a given base + * directory. + * @param directory the directory where to list the files from. + * @param filter the file filter to apply + * @param recurse tells whether or not the listing is recursive. + * @return the list of File objects that applies to the given + * filter. + */ + public static Vector listFiles(File directory, FilenameFilter filter, boolean recurse){ + if (!directory.isDirectory()){ + throw new IllegalArgumentException(directory + " is not a directory"); + } + Vector list = new Vector(); + listFilesTo(list, directory, filter, recurse); + return list; + } - /** - * List and add files to a given list. As a convenience it sends back the - * instance of the list given as a parameter. - * @param list the list of files where the filtered files should be added - * @param directory the directory where to list the files from. - * @param filter the file filter to apply - * @param recurse tells whether or not the listing is recursive. - * @return the list instance that was passed as the list argument. - */ - private static Vector listFilesTo(Vector list, File directory, FilenameFilter filter, boolean recurse){ - String[] files = directory.list(filter); - for (int i = 0; i < files.length; i++){ - list.addElement( new File(directory, files[i]) ); - } - files = null; // we don't need it anymore - if (recurse){ - String[] subdirs = directory.list( new DirectoryFilter() ); - for (int i = 0; i < subdirs.length; i++){ - listFilesTo(list, new File(directory, subdirs[i]), filter, recurse); - } - } - return list; - } + /** + * List and add files to a given list. As a convenience it sends back the + * instance of the list given as a parameter. + * @param list the list of files where the filtered files should be added + * @param directory the directory where to list the files from. + * @param filter the file filter to apply + * @param recurse tells whether or not the listing is recursive. + * @return the list instance that was passed as the list argument. + */ + private static Vector listFilesTo(Vector list, File directory, FilenameFilter filter, boolean recurse){ + String[] files = directory.list(filter); + for (int i = 0; i < files.length; i++){ + list.addElement( new File(directory, files[i]) ); + } + files = null; // we don't need it anymore + if (recurse){ + String[] subdirs = directory.list( new DirectoryFilter() ); + for (int i = 0; i < subdirs.length; i++){ + listFilesTo(list, new File(directory, subdirs[i]), filter, recurse); + } + } + return list; + } } /** Convenient filter that accepts only directory File */ class DirectoryFilter implements FilenameFilter { - public boolean accept(File directory, String name){ - File pathname = new File(directory, name); - return pathname.isDirectory(); - } + public boolean accept(File directory, String name){ + File pathname = new File(directory, name); + return pathname.isDirectory(); + } } /** convenient filter to accept only .class files */ class ClassFilter implements FilenameFilter { - public boolean accept(File dir, String name){ - return name.endsWith(".class"); - } + public boolean accept(File dir, String name){ + return name.endsWith(".class"); + } } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/bytecode/Utils.java b/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/bytecode/Utils.java index 092738762..be6f6d049 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/bytecode/Utils.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/bytecode/Utils.java @@ -64,320 +64,320 @@ import java.util.Vector; * @author Stephane Bailliez */ public class Utils { - /** public access flag */ + /** public access flag */ public final static short ACC_PUBLIC = 1; - /** private access flag */ + /** private access flag */ public final static short ACC_PRIVATE = 2; - /** protected access flag */ + /** protected access flag */ public final static short ACC_PROTECTED = 4; - /** static access flag */ + /** static access flag */ public final static short ACC_STATIC = 8; - /** final access flag */ + /** final access flag */ public final static short ACC_FINAL = 16; - /** super access flag */ + /** super access flag */ public final static short ACC_SUPER = 32; - /** synchronized access flag */ + /** synchronized access flag */ public final static short ACC_SYNCHRONIZED = 32; - /** volatile access flag */ + /** volatile access flag */ public final static short ACC_VOLATILE = 64; - /** transient access flag */ + /** transient access flag */ public final static short ACC_TRANSIENT = 128; - /** native access flag */ + /** native access flag */ public final static short ACC_NATIVE = 256; - /** interface access flag */ + /** interface access flag */ public final static short ACC_INTERFACE = 512; - /** abstract access flag */ + /** abstract access flag */ public final static short ACC_ABSTRACT = 1024; - /** strict access flag */ + /** strict access flag */ public final static short ACC_STRICT = 2048; - /** private constructor */ - private Utils(){ - } - - /** - * return an UTF8 value from the pool located a a specific index. - * @param pool the constant pool to look at - * @param index index of the UTF8 value in the constant pool - * @return the value of the string if it exists - * @throws ClassCastException if the index is not an UTF8 constant. - */ - public static String getUTF8Value(ConstantPool pool, int index){ - return ((Utf8CPInfo)pool.getEntry(index)).getValue(); - } - - /** - * parse all parameters from a descritor into fields of java name. - * @param descriptor of a method. - * @return the parameter list of a given method descriptor. Each string - * represent a java object with its fully qualified classname or the - * primitive name such as int, long, ... - */ - public static String[] getMethodParams(String descriptor){ - int i = 0; - if (descriptor.charAt(i) != '('){ - throw new IllegalArgumentException("Method descriptor should start with a '('"); - } - Vector params = new Vector(); - StringBuffer param = new StringBuffer(); + /** private constructor */ + private Utils(){ + } + + /** + * return an UTF8 value from the pool located a a specific index. + * @param pool the constant pool to look at + * @param index index of the UTF8 value in the constant pool + * @return the value of the string if it exists + * @throws ClassCastException if the index is not an UTF8 constant. + */ + public static String getUTF8Value(ConstantPool pool, int index){ + return ((Utf8CPInfo)pool.getEntry(index)).getValue(); + } + + /** + * parse all parameters from a descritor into fields of java name. + * @param descriptor of a method. + * @return the parameter list of a given method descriptor. Each string + * represent a java object with its fully qualified classname or the + * primitive name such as int, long, ... + */ + public static String[] getMethodParams(String descriptor){ + int i = 0; + if (descriptor.charAt(i) != '('){ + throw new IllegalArgumentException("Method descriptor should start with a '('"); + } + Vector params = new Vector(); + StringBuffer param = new StringBuffer(); i++; while ( (i = descriptor2java(descriptor, i, param)) < descriptor.length() ){ - params.add(param.toString()); - param.setLength(0); // reset - if (descriptor.charAt(i) == ')'){ - i++; - break; - } - } - String[] array = new String[params.size()]; - params.copyInto(array); - return array; - } - - /** - * return the object type of a return type. - * @param descriptor - * @return get the return type objet of a given descriptor - */ - public static String getMethodReturnType(String descriptor){ - int pos = descriptor.indexOf(')'); - StringBuffer rettype = new StringBuffer(); - descriptor2java(descriptor, pos + 1, rettype); - return rettype.toString(); + params.add(param.toString()); + param.setLength(0); // reset + if (descriptor.charAt(i) == ')'){ + i++; + break; + } + } + String[] array = new String[params.size()]; + params.copyInto(array); + return array; } - - /** - * Parse a single descriptor symbol and returns it java equivalent. - * @param descriptor the descriptor symbol. - * @param i the index to look at the symbol in the descriptor string - * @param sb the stringbuffer to return the java equivalent of the symbol - * @return the index after the descriptor symbol - */ - public static int descriptor2java(String descriptor, int i, StringBuffer sb){ - // get the dimension - StringBuffer dim = new StringBuffer(); - for (;descriptor.charAt(i) == '['; i++){ - dim.append("[]"); - } - // now get the type - switch (descriptor.charAt(i)){ - case 'B': sb.append("byte"); break; - case 'C': sb.append("char"); break; - case 'D': sb.append("double"); break; - case 'F': sb.append("float"); break; - case 'I': sb.append("int"); break; - case 'J': sb.append("long"); break; - case 'S': sb.append("short"); break; - case 'Z': sb.append("boolean"); break; - case 'V': sb.append("void"); break; - case 'L': - // it is a class - int pos = descriptor.indexOf(';', i + 1); - String classname = descriptor.substring(i + 1, pos).replace('/', '.'); - sb.append(classname); - i = pos; - break; - default: - //@todo, yeah this happens because I got things like: - // ()Ljava/lang/Object; and it will return and ) will be here - // think about it. - - //ooooops should never happen - //throw new IllegalArgumentException("Invalid descriptor symbol: '" + i + "' in '" + descriptor + "'"); - } - sb.append(dim.toString()); - return ++i; - } - - /** - * check for abstract access - * @param access_flags access flags - */ + + /** + * return the object type of a return type. + * @param descriptor + * @return get the return type objet of a given descriptor + */ + public static String getMethodReturnType(String descriptor){ + int pos = descriptor.indexOf(')'); + StringBuffer rettype = new StringBuffer(); + descriptor2java(descriptor, pos + 1, rettype); + return rettype.toString(); + } + + /** + * Parse a single descriptor symbol and returns it java equivalent. + * @param descriptor the descriptor symbol. + * @param i the index to look at the symbol in the descriptor string + * @param sb the stringbuffer to return the java equivalent of the symbol + * @return the index after the descriptor symbol + */ + public static int descriptor2java(String descriptor, int i, StringBuffer sb){ + // get the dimension + StringBuffer dim = new StringBuffer(); + for (;descriptor.charAt(i) == '['; i++){ + dim.append("[]"); + } + // now get the type + switch (descriptor.charAt(i)){ + case 'B': sb.append("byte"); break; + case 'C': sb.append("char"); break; + case 'D': sb.append("double"); break; + case 'F': sb.append("float"); break; + case 'I': sb.append("int"); break; + case 'J': sb.append("long"); break; + case 'S': sb.append("short"); break; + case 'Z': sb.append("boolean"); break; + case 'V': sb.append("void"); break; + case 'L': + // it is a class + int pos = descriptor.indexOf(';', i + 1); + String classname = descriptor.substring(i + 1, pos).replace('/', '.'); + sb.append(classname); + i = pos; + break; + default: + //@todo, yeah this happens because I got things like: + // ()Ljava/lang/Object; and it will return and ) will be here + // think about it. + + //ooooops should never happen + //throw new IllegalArgumentException("Invalid descriptor symbol: '" + i + "' in '" + descriptor + "'"); + } + sb.append(dim.toString()); + return ++i; + } + + /** + * check for abstract access + * @param access_flags access flags + */ public static boolean isAbstract(int access_flags) { return (access_flags & ACC_ABSTRACT) != 0; } - /** - * check for public access - * @param access_flags access flags - */ + /** + * check for public access + * @param access_flags access flags + */ public static boolean isPublic(int access_flags) { return (access_flags & ACC_PUBLIC) != 0; } - /** - * check for a static access - * @param access_flags access flags - */ + /** + * check for a static access + * @param access_flags access flags + */ public static boolean isStatic(int access_flags) { return (access_flags & ACC_STATIC) != 0; } - /** - * check for native access - * @param access_flags access flags - */ + /** + * check for native access + * @param access_flags access flags + */ public static boolean isNative(int access_flags) { return (access_flags & ACC_NATIVE) != 0; } - /** - * check for class access - * @param access_flags access flags - */ + /** + * check for class access + * @param access_flags access flags + */ public static boolean isClass(int access_flags) { return !isInterface(access_flags); } - /** - * check for strict access - * @param access_flags access flags - */ + /** + * check for strict access + * @param access_flags access flags + */ public static boolean isStrict(int access_flags) { return (access_flags & ACC_STRICT) != 0; } - /** - * check for interface access - * @param access_flags access flags - */ + /** + * check for interface access + * @param access_flags access flags + */ public static boolean isInterface(int access_flags) { return (access_flags & ACC_INTERFACE) != 0; } - /** - * check for private access - * @param access_flags access flags - */ + /** + * check for private access + * @param access_flags access flags + */ public static boolean isPrivate(int access_flags) { return (access_flags & ACC_PRIVATE) != 0; } - /** - * check for transient flag - * @param access_flags access flags - */ + /** + * check for transient flag + * @param access_flags access flags + */ public static boolean isTransient(int access_flags) { return (access_flags & ACC_TRANSIENT) != 0; } - /** - * check for volatile flag - * @param access_flags access flags - */ + /** + * check for volatile flag + * @param access_flags access flags + */ public static boolean isVolatile(int access_flags){ return (access_flags & ACC_VOLATILE) != 0; } - /** - * check for super flag - * @param access_flags access flag - */ + /** + * check for super flag + * @param access_flags access flag + */ public static boolean isSuper(int access_flags) { return (access_flags & ACC_SUPER) != 0; } - /** - * check for protected flag - * @param access_flags access flags - */ + /** + * check for protected flag + * @param access_flags access flags + */ public static boolean isProtected(int access_flags) { return (access_flags & ACC_PROTECTED) != 0; } - /** - * chck for final flag - * @param access_flags access flags - */ + /** + * chck for final flag + * @param access_flags access flags + */ public static boolean isFinal(int access_flags) { return (access_flags & ACC_FINAL) != 0; } - /** - * check for synchronized flag - * @param access_flags access flags - */ + /** + * check for synchronized flag + * @param access_flags access flags + */ public static boolean isSynchronized(int access_flags) { return (access_flags & ACC_SYNCHRONIZED) != 0; } - - /** - * return the method access flag as java modifiers - * @param access_flags access flags - * @return the access flags as modifier strings - */ + + /** + * return the method access flag as java modifiers + * @param access_flags access flags + * @return the access flags as modifier strings + */ public static String getMethodAccess(int access_flags) { StringBuffer sb = new StringBuffer(); if(isPublic(access_flags)){ sb.append("public "); - } else if(isPrivate(access_flags)){ + } else if(isPrivate(access_flags)){ sb.append("private "); - } else if(isProtected(access_flags)){ + } else if(isProtected(access_flags)){ sb.append("protected "); - } - if(isFinal(access_flags)){ + } + if(isFinal(access_flags)){ sb.append("final "); - } + } if(isStatic(access_flags)){ sb.append("static "); - } + } if(isSynchronized(access_flags)){ sb.append("synchronized "); - } + } if(isNative(access_flags)){ sb.append("native "); - } + } if(isAbstract(access_flags)){ sb.append("abstract "); - } + } return sb.toString().trim(); } - /** - * return the field access flag as java modifiers - * @param access_flags access flags - * @return the access flags as modifier strings - */ + /** + * return the field access flag as java modifiers + * @param access_flags access flags + * @return the access flags as modifier strings + */ public static String getFieldAccess(int access_flags) { StringBuffer sb = new StringBuffer(); if(isPublic(access_flags)){ sb.append("public "); - } else if(isPrivate(access_flags)){ + } else if(isPrivate(access_flags)){ sb.append("private "); - } else if (isProtected(access_flags)){ + } else if (isProtected(access_flags)){ sb.append("protected "); - } + } if(isFinal(access_flags)){ sb.append("final "); - } + } if(isStatic(access_flags)){ sb.append("static "); - } + } if(isVolatile(access_flags)){ sb.append("volatile "); - } + } if(isTransient(access_flags)){ sb.append("transient "); - } + } return sb.toString().trim(); } - /** - * return the class access flag as java modifiers - * @param access_flags access flags - * @return the access flags as modifier strings - */ + /** + * return the class access flag as java modifiers + * @param access_flags access flags + * @return the access flags as modifier strings + */ public static String getClassAccess(int access_flags) { StringBuffer sb = new StringBuffer(); if(isPublic(access_flags)){ sb.append("public "); - } else if (isProtected(access_flags)){ - sb.append("protected "); - } else if (isPrivate(access_flags)){ - sb.append("private "); - } - if(isFinal(access_flags)){ + } else if (isProtected(access_flags)){ + sb.append("protected "); + } else if (isPrivate(access_flags)){ + sb.append("private "); + } + if(isFinal(access_flags)){ sb.append("final "); - } + } if(isSuper(access_flags)){ sb.append("/*super*/ "); - } + } if(isInterface(access_flags)){ sb.append("interface "); - } + } if(isAbstract(access_flags)){ sb.append("abstract "); - } + } if(isClass(access_flags)){ sb.append("class "); - } + } return sb.toString().trim(); } } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java b/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java index 899ee0e2d..23375fc26 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java @@ -137,32 +137,32 @@ public class AntSoundPlayer implements LineListener, BuildListener { AudioInputStream audioInputStream = null; - try { - audioInputStream = AudioSystem.getAudioInputStream(file); - } - catch (UnsupportedAudioFileException uafe) { - project.log("Audio format is not yet supported: "+uafe.getMessage()); - } + try { + audioInputStream = AudioSystem.getAudioInputStream(file); + } + catch (UnsupportedAudioFileException uafe) { + project.log("Audio format is not yet supported: "+uafe.getMessage()); + } catch (IOException ioe) { ioe.printStackTrace(); } - if (audioInputStream != null) { - AudioFormat format = audioInputStream.getFormat(); - DataLine.Info info = new DataLine.Info(Clip.class, format, + if (audioInputStream != null) { + AudioFormat format = audioInputStream.getFormat(); + DataLine.Info info = new DataLine.Info(Clip.class, format, AudioSystem.NOT_SPECIFIED); - try { - audioClip = (Clip) AudioSystem.getLine(info); - audioClip.addLineListener(this); + try { + audioClip = (Clip) AudioSystem.getLine(info); + audioClip.addLineListener(this); audioClip.open(audioInputStream); - } - catch (LineUnavailableException e) { + } + catch (LineUnavailableException e) { project.log("The sound device is currently unavailable"); return; - } - catch (IOException e) { - e.printStackTrace(); - } + } + catch (IOException e) { + e.printStackTrace(); + } if (duration != null) { playClip(audioClip, duration.longValue()); @@ -171,10 +171,10 @@ public class AntSoundPlayer implements LineListener, BuildListener { } audioClip.drain(); audioClip.close(); - } - else { - project.log("Can't get data from file " + file.getName()); - } + } + else { + project.log("Can't get data from file " + file.getName()); + } } private void playClip(Clip clip, int loops) { @@ -203,16 +203,16 @@ public class AntSoundPlayer implements LineListener, BuildListener { if (event.getType().equals(LineEvent.Type.STOP)) { Line line = event.getLine(); line.close(); - } - else if (event.getType().equals(LineEvent.Type.CLOSE)) { - /* - * There is a bug in JavaSound 0.90 (jdk1.3beta). - * It prevents correct termination of the VM. - * So we have to exit ourselves. - */ - //System.exit(0); - } - } + } + else if (event.getType().equals(LineEvent.Type.CLOSE)) { + /* + * There is a bug in JavaSound 0.90 (jdk1.3beta). + * It prevents correct termination of the VM. + * So we have to exit ourselves. + */ + //System.exit(0); + } + } /** @@ -220,7 +220,7 @@ public class AntSoundPlayer implements LineListener, BuildListener { */ public void buildStarted(BuildEvent event){ } - + /** * Fired after the last target has finished. This event * will still be thrown if an error occured during the build.