Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@apache.org Received: (qmail 43037 invoked from network); 27 Jun 2002 00:04:15 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by 209.66.108.5 with SMTP; 27 Jun 2002 00:04:15 -0000 Received: (qmail 4390 invoked by uid 97); 27 Jun 2002 00:04:17 -0000 Delivered-To: qmlist-jakarta-archive-ant-dev@jakarta.apache.org Received: (qmail 4352 invoked by uid 97); 27 Jun 2002 00:04:16 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 4340 invoked by uid 98); 27 Jun 2002 00:04:16 -0000 X-Antivirus: nagoya (v4198 created Apr 24 2002) Message-ID: <00e901c21d6e$279b9170$6401a8c0@darden.virginia.edu> From: "Erik Hatcher" To: "Ant Developers List" References: <20020626231431.1241.qmail@icarus.apache.org> Subject: Re: cvs commit: jakarta-ant/src/main/org/apache/tools/ant Main.java Diagnostics.java Date: Wed, 26 Jun 2002 20:04:05 -0400 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Spam-Rating: 209.66.108.5 1.6.2 0/1000/N X-Spam-Rating: 209.66.108.5 1.6.2 0/1000/N Another handy diagnostic would be to walk all the classes in both defaults.properties files and attempt do Class.forName and see if they are there. Even if a user has optional.jar does not mean they have a complete one. Any casual user that attempts to build Ant themselves may not realize that they've only got a partial build unless they jump through lots of hoops to get all the necessary dependencies (like I did to get the Starteam SDK, etc!). The current incarnation of proposal/xdocs requires a full-build of Ant to work properly, because as it analyzes the source code, it also asks IntrospectionHelper for the supported attributes/elements, as well as constructing EnumeratedAttribute subclasses to call getValues. Erik ----- Original Message ----- From: To: Sent: Wednesday, June 26, 2002 7:14 PM Subject: cvs commit: jakarta-ant/src/main/org/apache/tools/ant Main.java Diagnostics.java > sbailliez 2002/06/26 16:14:31 > > Modified: src/main/org/apache/tools/ant Tag: ANT_15_BRANCH Main.java > Diagnostics.java > Log: > Adding a diagnostic mode to the Ant command line > via -diagnostics that will generate a report on > the console and give some bare information that > may help in solving problems quickly. > > Note that Ant will now break immediately if the > implementation version of optional.jar > (if available) and ant.jar do not match exactly. > (The check will occur for JDK 1.2+ only) > > Revision Changes Path > No revision > > > No revision > > > 1.65.2.5 +4 -1 jakarta-ant/src/main/org/apache/tools/ant/Main.java > > Index: Main.java > =================================================================== > RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Main.java,v > retrieving revision 1.65.2.4 > retrieving revision 1.65.2.5 > diff -u -r1.65.2.4 -r1.65.2.5 > --- Main.java 12 Jun 2002 15:31:39 -0000 1.65.2.4 > +++ Main.java 26 Jun 2002 23:14:31 -0000 1.65.2.5 > @@ -176,6 +176,7 @@ > Main m = null; > > try { > + Diagnostics.validateVersion(); > m = new Main(args); > } catch (Throwable exc) { > printMessage(exc); > @@ -263,6 +264,9 @@ > } else if (arg.equals("-version")) { > printVersion(); > return; > + } else if (arg.equals("-diagnostics")){ > + Diagnostics.doReport(System.out); > + return; > } else if (arg.equals("-quiet") || arg.equals("-q")) { > msgOutputLevel = Project.MSG_WARN; > } else if (arg.equals("-verbose") || arg.equals("-v")) { > @@ -784,7 +788,6 @@ > props.load(in); > in.close(); > > - String lSep = System.getProperty("line.separator"); > StringBuffer msg = new StringBuffer(); > msg.append("Apache Ant version "); > msg.append(props.getProperty("VERSION")); > > > > 1.1.2.2 +72 -34 jakarta-ant/src/main/org/apache/tools/ant/Attic/Diagnostics.java > > Index: Diagnostics.java > =================================================================== > RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Attic/Diagnostics.java,v > retrieving revision 1.1.2.1 > retrieving revision 1.1.2.2 > diff -u -r1.1.2.1 -r1.1.2.2 > --- Diagnostics.java 26 Jun 2002 08:42:05 -0000 1.1.2.1 > +++ Diagnostics.java 26 Jun 2002 23:14:31 -0000 1.1.2.2 > @@ -55,48 +55,59 @@ > > import java.io.File; > import java.io.FilenameFilter; > -import java.io.PrintWriter; > import java.io.PrintStream; > import java.util.Enumeration; > import java.lang.reflect.Method; > import java.lang.reflect.InvocationTargetException; > > +import org.apache.tools.ant.util.JavaEnvUtils; > + > /** > - * A little diagnostic helper that output some information > - * that may help in support. > + * A little diagnostic helper that output some information that may help > + * in support. It should quickly give correct information about the > + * jar existing in ant.home/lib and the jar versions... > * > * @since Ant 1.5 > * @author Stephane Bailliez > */ > -public class Diagnostics { > +public final class Diagnostics { > + > + /** utility class */ > + private Diagnostics(){ > + } > > /** > - * Check if optional tasks are available and if they are implementation > - * version identical with core. > - * @return true if optional tasks are available and implementation > - * version is correct. false if optional tasks are not available. > - * @throws BuildException if the implementation version of optional tasks > - * does not match the core implementation version. > + * Check if optional tasks are available. Not that it does not check > + * for implementation version. Use validateVersion() for this. > + * @return true if optional tasks are available. > */ > public static boolean isOptionalAvailable() { > - Class optional = null; > try { > - optional = Class.forName("org.apache.tools.ant.taskdefs.optional.Test"); > + Class.forName("org.apache.tools.ant.taskdefs.optional.Test"); > } catch (ClassNotFoundException e){ > return false; > } > + return true; > + } > > - Package corePkg = Main.class.getPackage(); > - String coreVersion = corePkg.getImplementationVersion(); > - Package optionalPkg = optional.getPackage(); > - String optionalVersion = optionalPkg.getImplementationVersion(); > - if (coreVersion == null || !coreVersion.equals(optionalVersion) ){ > - throw new BuildException( > - "Invalid implementation version between Ant core and Ant optional tasks.\n" + > - " core : " + corePkg + "\n" + > - " optional: " + optionalPkg); > + /** > + * Check if core and optional implementation version do match. > + * @throws BuildException if the implementation version of optional tasks > + * does not match the core implementation version. > + */ > + public static void validateVersion() throws BuildException { > + try { > + Class optional = Class.forName("org.apache.tools.ant.taskdefs.optional.Test"); > + String coreVersion = getImplementationVersion(Main.class); > + String optionalVersion = getImplementationVersion(optional); > + if (coreVersion == null || !coreVersion.equals(optionalVersion) ){ > + throw new BuildException( > + "Invalid implementation version between Ant core and Ant optional tasks.\n" + > + " core : " + coreVersion + "\n" + > + " optional: " + optionalVersion); > + } > + } catch (ClassNotFoundException e){ > } > - return true; > } > > /** > @@ -113,37 +124,64 @@ > return name.endsWith(".jar"); > } > }; > - return libDir.listFiles(filter); > + // listFiles is JDK 1.2+ method... > + String[] filenames = libDir.list(filter); > + File[] files = new File[filenames.length]; > + for (int i = 0; i < filenames.length; i++){ > + files[i] = new File(libDir, filenames[i]); > + } > + return files; > } > > - > + /** > + * main entry point for command line > + * @param args command line arguments. > + */ > public static void main(String[] args){ > doReport(System.out); > } > > > /** > - * > + * Helper method to get the implementation version. > + * @param clazz the class to get the information from. > + * @return null if there is no package or implementation version. > + * '?.?' for JDK 1.0 or 1.1. > + */ > + private static String getImplementationVersion(Class clazz){ > + if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_0) > + || JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1)){ > + return "?.?"; > + } > + Package pkg = clazz.getPackage(); > + if (pkg != null) { > + return pkg.getImplementationVersion(); > + } > + return null; > + } > + > + /** > + * Print a report to the given stream. > + * @param out the stream to print the report to. > */ > public static void doReport(PrintStream out){ > out.println("------- Ant diagnostics report -------"); > out.println(Main.getAntVersion()); > out.println(); > out.println("-------------------------------------------"); > - out.println(" Implementation Version"); > + out.println(" Implementation Version (JDK1.2+ only)"); > out.println("-------------------------------------------"); > - out.println(" core tasks : " + Main.class.getPackage().getImplementationVersion()); > + out.println(" core tasks : " + getImplementationVersion(Main.class)); > > + Class optional = null; > try { > - Class.forName( > + optional = Class.forName( > "org.apache.tools.ant.taskdefs.optional.Test"); > + out.println(" optional tasks : " + getImplementationVersion(optional)); > } catch (ClassNotFoundException e){ > + out.println(" optional tasks : not available"); > } > > - Package optionalPkg = Package.getPackage("org.apache.tools.ant.taskdefs.optional"); > - out.println(" optional tasks : " + > - (optionalPkg == null ? "not available": optionalPkg.getImplementationVersion()) ); > - > out.println(); > out.println("-------------------------------------------"); > out.println(" ANT_HOME/lib jar listing"); > @@ -162,10 +200,10 @@ > out.println("-------------------------------------------"); > Class which = Class.forName("org.apache.env.Which"); > Method method = which.getMethod("main", new Class[]{ String[].class }); > - method.invoke(null, new String[]{}); > + method.invoke(null, new Object[]{new String[]{}}); > } catch (ClassNotFoundException e) { > out.println("Not available."); > - out.println("For detailed XML related diagnostics, get Which from http://xml.apache.org/commons/"); > + out.println("Download it at http://xml.apache.org/commons/"); > } catch (InvocationTargetException e) { > error = e.getTargetException() == null ? e : e.getTargetException(); > } catch (Exception e) { > > > > > -- > To unsubscribe, e-mail: > For additional commands, e-mail: > > -- To unsubscribe, e-mail: For additional commands, e-mail: