ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sbaill...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant Diagnostics.java
Date Fri, 28 Jun 2002 11:45:23 GMT
sbailliez    2002/06/28 04:45:23

  Modified:    src/main/org/apache/tools/ant Tag: ANT_15_BRANCH
                        Diagnostics.java
  Log:
  Use reflection to make it compile under JDK 1.1
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.3   +53 -11    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.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- Diagnostics.java	26 Jun 2002 23:14:31 -0000	1.1.2.2
  +++ Diagnostics.java	28 Jun 2002 11:45:23 -0000	1.1.2.3
  @@ -100,7 +100,8 @@
               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) ){
  +            
  +            if (coreVersion != null && !coreVersion.equals(optionalVersion) ){
                   throw new BuildException(
                           "Invalid implementation version between Ant core and Ant optional
tasks.\n" +
                           " core    : " + coreVersion + "\n" +
  @@ -149,13 +150,19 @@
        * '?.?' 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();
  +        try {
  +          // Package pkg = clazz.getPackage();        
  +          Method method = Class.class.getMethod("getPackage", new Class[0]);
  +          Object pkg = method.invoke(clazz, null);
  +          if (pkg != null) {
  +              // pkg.getImplementationVersion();
  +              method = pkg.getClass().getMethod("getImplementationVersion", new Class[0]);
  +              Object version = method.invoke(pkg, null);          
  +              return (String)version;
  +          }
  +        } catch (Exception e){
  +          // JDK < 1.2 should land here because the methods above don't exist.
  +          return "?.?";
           }
           return null;
       }
  @@ -171,15 +178,15 @@
           out.println("-------------------------------------------");
           out.println(" Implementation Version (JDK1.2+ only)");
           out.println("-------------------------------------------");
  -        out.println(" core tasks     : " + getImplementationVersion(Main.class));
  +        out.println("core tasks     : " + getImplementationVersion(Main.class));
   
           Class optional = null;
           try {
               optional = Class.forName(
                       "org.apache.tools.ant.taskdefs.optional.Test");
  -            out.println(" optional tasks : " + getImplementationVersion(optional));
  +            out.println("optional tasks : " + getImplementationVersion(optional));
           } catch (ClassNotFoundException e){
  -            out.println(" optional tasks : not available");
  +            out.println("optional tasks : not available");
           }
   
           out.println();
  @@ -192,6 +199,19 @@
                       + " (" + libs[i].length() + " bytes)");
           }
   
  +/*
  +        out.println();
  +        out.println("-------------------------------------------");
  +        out.println(" Core tasks availability");
  +        out.println("-------------------------------------------");
  +        Properties props = new Properties();
  +        InputStream is = Main.class.getResourceAsStream("org/apache/tools/ant/taskdefs/default.properties");
  +
  +        out.println();
  +        out.println("-------------------------------------------");
  +        out.println(" Optional tasks availability");
  +        out.println("-------------------------------------------");
  +*/
           out.println();
           Throwable error = null;
           try {
  @@ -227,5 +247,27 @@
   
           out.println();
       }
  +
  +/*
  +    private void doReportTasksAvailability(PrintStream out, InputStream in) {
  +        if (is == null) {
  +            out.println("None available");
  +        } else {
  +            props.load(is);
  +            for (Enumeration keys = props.keys(); keys.hasMoreElements();){
  +                String key = (String)keys.nextElement();
  +                String classname = props.getProperty(key);
  +                try {
  +                    Class.forName(classname);
  +                    props.remove(key);
  +                } catch (ClassNotFoundException e){
  +                    out.println(classname + " : Not Available");
  +                }
  +            }
  +            if (props.size() == 0){
  +                out.println("All defined tasks are available");
  +            }          
  +        }      
  +    } */
   
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message