You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Tim Fennell <tf...@rcn.com> on 2000/07/24 05:43:53 UTC

[PATCH] Available.java - to detect JDK versions

Here is the patch. It supports the syntax suggested:
	1.2.2 - matches specified version
	1.2+  - matches 1.2 or higher
	1.2-	- matches 1.2 or lower

Note both the +/- version are *inclusive*, so check for 1.99- if you want pre
1.2 etc!

-t

---------------------------Begin Patch----------------------------
Index: Available.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Available.jav
a,v
retrieving revision 1.6
diff -u -r1.6 Available.java
--- Available.java	2000/07/06 16:48:13	1.6
+++ Available.java	2000/07/24 03:43:23
@@ -62,6 +62,7 @@
  * Will set the given property if the requested resource is available at
runtime.
  *
  * @author Stefano Mazzocchi <a
href="mailto:stefano@apache.org">stefano@apache.org</a>
+ * @author Tim Fennell <a
href="mailto:tfennell@sapient.com">tfennell@sapient.com</a>
  */

 public class Available extends Task {
@@ -70,6 +71,7 @@
     private String classname;
     private String file;
     private String resource;
+    private String jdk;

     public void setProperty(String property) {
         this.property = property;
@@ -94,10 +96,16 @@
         this.resource = resource;
     }

+    /** Setter method to set the value of the JDK to check for. */
+    public void setJdk(String jdk) {
+        this.jdk = jdk;
+    }
+
     public void init() throws BuildException {
         if ((classname != null) && !checkClass(classname)) return;
         if ((file != null) && !checkFile(file)) return;
         if ((resource != null) && !checkResource(resource)) return;
+        if ((jdk != null) && !checkJdk(jdk)) return;

         this.project.setProperty(property, "true");
     }
@@ -125,4 +133,75 @@
             return false;
         }
     }
+
+    /**
+     * Checks to see if the current JDK version (the one this method is called
+     * within) matches a criteria. Either that it is 'equal', 'equal or higher'
+     * or 'equal of lower'.
+     * @param jdk version of the JDK to check for. Terminate with a '+' to
check
+     *        for a version or higher. Terminate with a '-' to check for a
+     *         version or lower.
+     * @return boolean true if the current JDK matches the criteria.
+     */
+    private boolean checkJdk(String jdk) {
+        double checkVersion = 0.0;
+        double currentVersion = 0.0;
+        int    returnCheck  = 0;
+        int    returnValue  = 0;
+
+        // Determine if we are looking for an exact match, greater than or less
+        // than... And convert the jdk string to a double.
+        if (jdk.endsWith("-")) {
+            returnCheck = -1;
+            checkVersion = stringToDouble(jdk.substring(0, jdk.length() -1));
+        }
+        else if (jdk.endsWith("+")) {
+            returnCheck = +1;
+            checkVersion = stringToDouble(jdk.substring(0, jdk.length() -1));
+        }
+        else {
+            returnCheck = 0;
+            checkVersion = stringToDouble(jdk);
+        }
+
+        // Get the current JDK version as a double
+        currentVersion = stringToDouble(System.getProperty("java.version"));
+
+        // Check the current version against the checkVersion
+        if (checkVersion == currentVersion)
+            returnValue = 0;
+        else if (currentVersion < checkVersion)
+            returnValue = -1;
+        else if (currentVersion > checkVersion)
+            returnValue = +1;
+
+        // If the versions are an exact match, return true. Otherwise check to
+        // see if the returnValue is equal to the checkValue.
+        if (returnValue == 0) return true;
+        else return (returnValue == returnCheck);
+
+    }
+
+    /**
+     * Utility method to convert strings with multiple decimal places into
+     * doubles that can be safely compared with one another for numerical
+     * equality.
+     * @param inString the String to convert to a decimal.
+     * @return double the value of the string as a double.
+     */
+    public static double stringToDouble(String inString) {
+        double returnValue = 0.0;
+        int    divisor     = 1;
+        String digits      = null;
+        StringTokenizer tokenizer = new StringTokenizer(inString, ".");
+
+        while (tokenizer.hasMoreTokens()) {
+            digits = tokenizer.nextToken();
+            returnValue += (Double.parseDouble(digits) / (divisor *
digits.length()) );
+            divisor *= 10;
+        }
+
+        return returnValue;
+    }
+
 }


[PATCH] Style task to reprocess all files if stylesheet is modified.

Posted by Russell Gold <ru...@acm.org>.
Proposed patch: to take into consideration the data of the XLST stylesheet 
as well as the file to be transformed
in deciding which files need to be processed.

----- begin patch ------
Index: src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java,v
retrieving revision 1.6
diff -u -r1.6 XSLTProcess.java
--- src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java     2000/07/21 
09:43:15     1.6
+++ src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java     2000/07/24 
16:33:01
@@ -83,6 +83,7 @@
   *
   * @author <a href="mailto:kvisco@exoffice.com">Keith Visco</a>
   * @author <a href="mailto:rubys@us.ibm.com">Sam Ruby</a>
+ * @author <a href="mailto:russgold@acm.org">Russell Gold</a>
   * @version $Revision: 1.6 $ $Date: 2000/07/21 09:43:15 $
   */
  public class XSLTProcess extends MatchingTask {
@@ -138,22 +139,24 @@

         log("Using "+liaison.getClass().toString(), Project.MSG_VERBOSE);

-       try {
-           // Create a new XSL processor with the specified stylesheet
-           if (xslFile != null) {
-                String file = new File(baseDir,xslFile.toString()).toString();
-               log("Loading stylesheet " + file, Project.MSG_INFO);
-                liaison.setStylesheet( file );
-           }
-       } catch (Exception ex) {
-           log("Failed to read stylesheet " + xslFile, Project.MSG_INFO);
-            throw new BuildException(ex);
-       }
+    long styleSheetLastModified = 0;
+    if (xslFile != null) {
+        try {
+            // Create a new XSL processor with the specified stylesheet
+            File file = new File( baseDir, xslFile.toString() );
+            styleSheetLastModified = file.lastModified();
+            log( "Loading stylesheet " + file, Project.MSG_INFO);
+                 liaison.setStylesheet( file.toString() );
+        } catch (Exception ex) {
+            log("Failed to read stylesheet " + xslFile, Project.MSG_INFO);
+                throw new BuildException(ex);
+        }
+    }

         // Process all the files marked for styling
         list = scanner.getIncludedFiles();
         for (int i = 0;i < list.length; ++i) {
-           process(baseDir,list[i],destDir);
+           process( baseDir, list[i], destDir, styleSheetLastModified );
         }

         // Process all the directoried marked for styling
@@ -161,7 +164,7 @@
         for (int j = 0;j < dirs.length;++j){
             list=new File(baseDir,dirs[j]).list();
             for (int i = 0;i < list.length;++i)
-               process(baseDir,list[i],destDir);
+               process( baseDir, list[i], destDir, styleSheetLastModified );
         }
      } //-- execute

@@ -284,9 +287,8 @@
       * Processes the given input XML file and stores the result
       * in the given resultFile.
      **/
-    private void process(File baseDir,String xmlFile,File destDir)
-        throws BuildException
-    {
+    private void process( File baseDir, String xmlFile, File destDir, long 
styleSheetLastModified )
+            throws BuildException {
         String fileExt=targetExtension;
         File   outFile=null;
         File   inFile=null;
@@ -294,12 +296,12 @@
         try {
             inFile = new File(baseDir,xmlFile);
             outFile = new 
File(destDir,xmlFile.substring(0,xmlFile.lastIndexOf('.'))+fileExt);
-           if (inFile.lastModified() > outFile.lastModified()) {
-                ensureDirectoryFor( outFile );
-               //-- command line status
-               log("Processing " + xmlFile + " to " + outFile, 
Project.MSG_VERBOSE);
-
-               liaison.transform(inFile.toString(), outFile.toString());
+           if (Math.max( styleSheetLastModified, inFile.lastModified() ) > 
outFile.lastModified()) {
+            ensureDirectoryFor( outFile );
+               //-- command line status
+               log("Processing " + xmlFile + " to " + outFile, 
Project.MSG_VERBOSE);
+
+               liaison.transform(inFile.toString(), outFile.toString());
             }
          }
          catch (Exception ex) {
------ end patch -------


Re: [PATCH] Available.java - to detect JDK versions

Posted by Jesse Glick <Je...@netbeans.com>.
Tim Fennell wrote:
> First off, you're right. I'm not sure what I was going, but that code is totally
> whacked! About using int arithmatic though...Are we guaranteed that each minor
> version number will contain no leading zeros? If we are, then I'll implement it
> with ints.  Otherwise I'll do as you suggest but parse each major/minor version
> number to a double so I can deal with leading zeros appropriately. Consider the
> (hypothetical) case:
>         1.4.1
>         1.4.02
> 
> 1.4.1 should come first, but 02 will parseInt to 2 and make 1.4.02 greater.

I think the Java Versioning Specification is supposed to be used for
these numbers...that would specify a lexicographic Dewey-decimal-style
comparison, each segment by itself, and would treat 1.4.02 the same as
1.4.2. But beware: I have seen beta JDKs stick extra nonsense in there
such as "1.2beta" which screws things up. I sent a bug report to the JDC
complaining that they ought not use non-Dewey-decimal version numbers,
but to no apparent avail.

Anyway, comparisons should apply only to java.specification.version, not
java.version which is not guaranteed to be anything in particular other
than descriptive. For example in my VM all is well:

java.version: 1.3.0beta_refresh
java.specification.version: 1.3

-Jesse

-- 
Jesse Glick   <ma...@netbeans.com>
NetBeans, Open APIs  <http://www.netbeans.org/>
tel (+4202) 3300-9161 Sun Micro x49161 Praha CR

Re: [PATCH] Available.java - to detect JDK versions

Posted by James Duncan Davidson <du...@x180.com>.
on 7/24/00 7:11 AM, Conor MacNeill at conor@m64.com wrote:

> As far as I can tell, Sun's practice to date (e.g. 1.1.6) has been not to
> use .02 style numbers. Therefore I would prefer not to use doubles and
> complicate things for a situation which, at least today, does not exist.
> When it happens, we should deal with it then. Perhaps I just have an
> aversion for using doubles for things which should be exact. :-)

I would say that if you are going to provide any kind of version support
scheme, it should be more general than JDK version checking. :)

.duncan


RE: [PATCH] Available.java - to detect JDK versions

Posted by Conor MacNeill <co...@m64.com>.
Tim,

> Conor,
>
> First off, you're right. I'm not sure what I was going, but that
> code is totally
> whacked! About using int arithmatic though...Are we guaranteed
> that each minor
> version number will contain no leading zeros? If we are, then
> I'll implement it
> with ints.  Otherwise I'll do as you suggest but parse each
> major/minor version
> number to a double so I can deal with leading zeros
> appropriately. Consider the
> (hypothetical) case:
> 	1.4.1
> 	1.4.02
>
> 1.4.1 should come first, but 02 will parseInt to 2 and make
> 1.4.02 greater.
>

As far as I can tell, Sun's practice to date (e.g. 1.1.6) has been not to
use .02 style numbers. Therefore I would prefer not to use doubles and
complicate things for a situation which, at least today, does not exist.
When it happens, we should deal with it then. Perhaps I just have an
aversion for using doubles for things which should be exact. :-)


RE: [PATCH] Available.java - to detect JDK versions

Posted by Tim Fennell <tf...@rcn.com>.
Conor,

First off, you're right. I'm not sure what I was going, but that code is totally
whacked! About using int arithmatic though...Are we guaranteed that each minor
version number will contain no leading zeros? If we are, then I'll implement it
with ints.  Otherwise I'll do as you suggest but parse each major/minor version
number to a double so I can deal with leading zeros appropriately. Consider the
(hypothetical) case:
	1.4.1
	1.4.02

1.4.1 should come first, but 02 will parseInt to 2 and make 1.4.02 greater.

-t

-----Original Message-----
From: Conor MacNeill [mailto:conor@cortexebusiness.com.au]
Sent: Monday, July 24, 2000 00:21
To: ant-dev@jakarta.apache.org
Subject: RE: [PATCH] Available.java - to detect JDK versions


Tim,

Some quick feedback. I don't like the use of doubles. Wouldn't it be better
to compare minor and major version numbers separately as integers and
properly parse the version numbers supplied.

Have you considered how versions such as 10.1 and 1.10 will come out. From
my quick look (in other words, I might be wrong) these will be treated as
equal to 5.1 and 1.5 resp. Also, what about if someone mistypes a version as
1..1?

Conor

--
Conor MacNeill
conor@cortexebusiness.com.au
Cortex eBusiness
http://www.cortexebusiness.com.au

> -----Original Message-----
> From: Tim Fennell [mailto:tfenne@rcn.com]
> Sent: Monday, 24 July 2000 13:44
> To: ant-dev@jakarta.apache.org
> Subject: [PATCH] Available.java - to detect JDK versions
>
>
> Here is the patch. It supports the syntax suggested:
> 	1.2.2 - matches specified version
> 	1.2+  - matches 1.2 or higher
> 	1.2-	- matches 1.2 or lower
>
> Note both the +/- version are *inclusive*, so check for 1.99- if
> you want pre
> 1.2 etc!
>
> -t
>
> ---------------------------Begin Patch----------------------------
> Index: Available.java
> ===================================================================
> RCS file:
> /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs
> /Available.jav
> a,v
> retrieving revision 1.6
> diff -u -r1.6 Available.java
> --- Available.java	2000/07/06 16:48:13	1.6
> +++ Available.java	2000/07/24 03:43:23
> @@ -62,6 +62,7 @@
>   * Will set the given property if the requested resource is available at
> runtime.
>   *
>   * @author Stefano Mazzocchi <a
> href="mailto:stefano@apache.org">stefano@apache.org</a>
> + * @author Tim Fennell <a
> href="mailto:tfennell@sapient.com">tfennell@sapient.com</a>
>   */
>
>  public class Available extends Task {
> @@ -70,6 +71,7 @@
>      private String classname;
>      private String file;
>      private String resource;
> +    private String jdk;
>
>      public void setProperty(String property) {
>          this.property = property;
> @@ -94,10 +96,16 @@
>          this.resource = resource;
>      }
>
> +    /** Setter method to set the value of the JDK to check for. */
> +    public void setJdk(String jdk) {
> +        this.jdk = jdk;
> +    }
> +
>      public void init() throws BuildException {
>          if ((classname != null) && !checkClass(classname)) return;
>          if ((file != null) && !checkFile(file)) return;
>          if ((resource != null) && !checkResource(resource)) return;
> +        if ((jdk != null) && !checkJdk(jdk)) return;
>
>          this.project.setProperty(property, "true");
>      }
> @@ -125,4 +133,75 @@
>              return false;
>          }
>      }
> +
> +    /**
> +     * Checks to see if the current JDK version (the one this
> method is called
> +     * within) matches a criteria. Either that it is 'equal',
> 'equal or higher'
> +     * or 'equal of lower'.
> +     * @param jdk version of the JDK to check for. Terminate
> with a '+' to
> check
> +     *        for a version or higher. Terminate with a '-' to
> check for a
> +     *         version or lower.
> +     * @return boolean true if the current JDK matches the criteria.
> +     */
> +    private boolean checkJdk(String jdk) {
> +        double checkVersion = 0.0;
> +        double currentVersion = 0.0;
> +        int    returnCheck  = 0;
> +        int    returnValue  = 0;
> +
> +        // Determine if we are looking for an exact match,
> greater than or less
> +        // than... And convert the jdk string to a double.
> +        if (jdk.endsWith("-")) {
> +            returnCheck = -1;
> +            checkVersion = stringToDouble(jdk.substring(0,
> jdk.length() -1));
> +        }
> +        else if (jdk.endsWith("+")) {
> +            returnCheck = +1;
> +            checkVersion = stringToDouble(jdk.substring(0,
> jdk.length() -1));
> +        }
> +        else {
> +            returnCheck = 0;
> +            checkVersion = stringToDouble(jdk);
> +        }
> +
> +        // Get the current JDK version as a double
> +        currentVersion =
> stringToDouble(System.getProperty("java.version"));
> +
> +        // Check the current version against the checkVersion
> +        if (checkVersion == currentVersion)
> +            returnValue = 0;
> +        else if (currentVersion < checkVersion)
> +            returnValue = -1;
> +        else if (currentVersion > checkVersion)
> +            returnValue = +1;
> +
> +        // If the versions are an exact match, return true.
> Otherwise check to
> +        // see if the returnValue is equal to the checkValue.
> +        if (returnValue == 0) return true;
> +        else return (returnValue == returnCheck);
> +
> +    }
> +
> +    /**
> +     * Utility method to convert strings with multiple decimal
> places into
> +     * doubles that can be safely compared with one another for numerical
> +     * equality.
> +     * @param inString the String to convert to a decimal.
> +     * @return double the value of the string as a double.
> +     */
> +    public static double stringToDouble(String inString) {
> +        double returnValue = 0.0;
> +        int    divisor     = 1;
> +        String digits      = null;
> +        StringTokenizer tokenizer = new StringTokenizer(inString, ".");
> +
> +        while (tokenizer.hasMoreTokens()) {
> +            digits = tokenizer.nextToken();
> +            returnValue += (Double.parseDouble(digits) / (divisor *
> digits.length()) );
> +            divisor *= 10;
> +        }
> +
> +        return returnValue;
> +    }
> +
>  }
>
>



RE: [PATCH] Available.java - to detect JDK versions

Posted by Conor MacNeill <co...@cortexebusiness.com.au>.
Tim,

Some quick feedback. I don't like the use of doubles. Wouldn't it be better
to compare minor and major version numbers separately as integers and
properly parse the version numbers supplied.

Have you considered how versions such as 10.1 and 1.10 will come out. From
my quick look (in other words, I might be wrong) these will be treated as
equal to 5.1 and 1.5 resp. Also, what about if someone mistypes a version as
1..1?

Conor

--
Conor MacNeill
conor@cortexebusiness.com.au
Cortex eBusiness
http://www.cortexebusiness.com.au

> -----Original Message-----
> From: Tim Fennell [mailto:tfenne@rcn.com]
> Sent: Monday, 24 July 2000 13:44
> To: ant-dev@jakarta.apache.org
> Subject: [PATCH] Available.java - to detect JDK versions
>
>
> Here is the patch. It supports the syntax suggested:
> 	1.2.2 - matches specified version
> 	1.2+  - matches 1.2 or higher
> 	1.2-	- matches 1.2 or lower
>
> Note both the +/- version are *inclusive*, so check for 1.99- if
> you want pre
> 1.2 etc!
>
> -t
>
> ---------------------------Begin Patch----------------------------
> Index: Available.java
> ===================================================================
> RCS file:
> /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs
> /Available.jav
> a,v
> retrieving revision 1.6
> diff -u -r1.6 Available.java
> --- Available.java	2000/07/06 16:48:13	1.6
> +++ Available.java	2000/07/24 03:43:23
> @@ -62,6 +62,7 @@
>   * Will set the given property if the requested resource is available at
> runtime.
>   *
>   * @author Stefano Mazzocchi <a
> href="mailto:stefano@apache.org">stefano@apache.org</a>
> + * @author Tim Fennell <a
> href="mailto:tfennell@sapient.com">tfennell@sapient.com</a>
>   */
>
>  public class Available extends Task {
> @@ -70,6 +71,7 @@
>      private String classname;
>      private String file;
>      private String resource;
> +    private String jdk;
>
>      public void setProperty(String property) {
>          this.property = property;
> @@ -94,10 +96,16 @@
>          this.resource = resource;
>      }
>
> +    /** Setter method to set the value of the JDK to check for. */
> +    public void setJdk(String jdk) {
> +        this.jdk = jdk;
> +    }
> +
>      public void init() throws BuildException {
>          if ((classname != null) && !checkClass(classname)) return;
>          if ((file != null) && !checkFile(file)) return;
>          if ((resource != null) && !checkResource(resource)) return;
> +        if ((jdk != null) && !checkJdk(jdk)) return;
>
>          this.project.setProperty(property, "true");
>      }
> @@ -125,4 +133,75 @@
>              return false;
>          }
>      }
> +
> +    /**
> +     * Checks to see if the current JDK version (the one this
> method is called
> +     * within) matches a criteria. Either that it is 'equal',
> 'equal or higher'
> +     * or 'equal of lower'.
> +     * @param jdk version of the JDK to check for. Terminate
> with a '+' to
> check
> +     *        for a version or higher. Terminate with a '-' to
> check for a
> +     *         version or lower.
> +     * @return boolean true if the current JDK matches the criteria.
> +     */
> +    private boolean checkJdk(String jdk) {
> +        double checkVersion = 0.0;
> +        double currentVersion = 0.0;
> +        int    returnCheck  = 0;
> +        int    returnValue  = 0;
> +
> +        // Determine if we are looking for an exact match,
> greater than or less
> +        // than... And convert the jdk string to a double.
> +        if (jdk.endsWith("-")) {
> +            returnCheck = -1;
> +            checkVersion = stringToDouble(jdk.substring(0,
> jdk.length() -1));
> +        }
> +        else if (jdk.endsWith("+")) {
> +            returnCheck = +1;
> +            checkVersion = stringToDouble(jdk.substring(0,
> jdk.length() -1));
> +        }
> +        else {
> +            returnCheck = 0;
> +            checkVersion = stringToDouble(jdk);
> +        }
> +
> +        // Get the current JDK version as a double
> +        currentVersion =
> stringToDouble(System.getProperty("java.version"));
> +
> +        // Check the current version against the checkVersion
> +        if (checkVersion == currentVersion)
> +            returnValue = 0;
> +        else if (currentVersion < checkVersion)
> +            returnValue = -1;
> +        else if (currentVersion > checkVersion)
> +            returnValue = +1;
> +
> +        // If the versions are an exact match, return true.
> Otherwise check to
> +        // see if the returnValue is equal to the checkValue.
> +        if (returnValue == 0) return true;
> +        else return (returnValue == returnCheck);
> +
> +    }
> +
> +    /**
> +     * Utility method to convert strings with multiple decimal
> places into
> +     * doubles that can be safely compared with one another for numerical
> +     * equality.
> +     * @param inString the String to convert to a decimal.
> +     * @return double the value of the string as a double.
> +     */
> +    public static double stringToDouble(String inString) {
> +        double returnValue = 0.0;
> +        int    divisor     = 1;
> +        String digits      = null;
> +        StringTokenizer tokenizer = new StringTokenizer(inString, ".");
> +
> +        while (tokenizer.hasMoreTokens()) {
> +            digits = tokenizer.nextToken();
> +            returnValue += (Double.parseDouble(digits) / (divisor *
> digits.length()) );
> +            divisor *= 10;
> +        }
> +
> +        return returnValue;
> +    }
> +
>  }
>
>