You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2018/03/26 03:22:17 UTC

[1/2] groovy git commit: improve doco/tests for dateutil module - test could fail for one hour around a daulight saving time change

Repository: groovy
Updated Branches:
  refs/heads/master dfefeefa6 -> 3bb44bfb3


improve doco/tests for dateutil module - test could fail for one hour around a daulight saving time change


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/72da4738
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/72da4738
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/72da4738

Branch: refs/heads/master
Commit: 72da47385c6b489790e5cec5429ad35ead9afd07
Parents: dfefeef
Author: paulk <pa...@asert.com.au>
Authored: Mon Mar 26 13:18:12 2018 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Mon Mar 26 13:21:11 2018 +1000

----------------------------------------------------------------------
 .../runtime/DefaultGroovyStaticMethods.java     | 47 +---------
 .../extensions/DateTimeStaticExtensions.java    |  4 +
 subprojects/groovy-dateutil/build.gradle        |  2 +-
 .../dateutil/extensions/DateUtilExtensions.java |  3 +-
 .../extensions/DateUtilStaticExtensions.java    | 91 ++++++++++++++++++++
 .../gdk/WorkingWithDateUtilTypesTest.groovy     | 11 ++-
 6 files changed, 107 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/72da4738/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyStaticMethods.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyStaticMethods.java b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyStaticMethods.java
index 04421af..7d94771 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyStaticMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyStaticMethods.java
@@ -161,60 +161,19 @@ public class DefaultGroovyStaticMethods {
         sleepImpl(milliseconds, onInterrupt);
     }
 
-    /**
-     * Parse a String into a Date instance using the given pattern.
-     * This convenience method acts as a wrapper for {@link java.text.SimpleDateFormat}.
-     * <p>
-     * Note that a new SimpleDateFormat instance is created for every
-     * invocation of this method (for thread safety).
-     *
-     * @param self   placeholder variable used by Groovy categories; ignored for default static methods
-     * @param format pattern used to parse the input string.
-     * @param input  String to be parsed to create the date instance
-     * @return a new Date instance representing the parsed input string
-     * @throws ParseException if there is a parse error
-     * @see java.text.SimpleDateFormat#parse(java.lang.String)
-     * @since 1.5.7
-     */
+    @Deprecated
     public static Date parse(Date self, String format, String input) throws ParseException {
         return new SimpleDateFormat(format).parse(input);
     }
 
-    /**
-     * Parse a String into a Date instance using the given pattern and TimeZone.
-     * This convenience method acts as a wrapper for {@link java.text.SimpleDateFormat}.
-     * <p>
-     * Note that a new SimpleDateFormat instance is created for every
-     * invocation of this method (for thread safety).
-     *
-     * @param self   placeholder variable used by Groovy categories; ignored for default static methods
-     * @param format pattern used to parse the input string.
-     * @param input  String to be parsed to create the date instance
-     * @param zone   TimeZone to use when parsing
-     * @return a new Date instance representing the parsed input string
-     * @throws ParseException if there is a parse error
-     * @see java.text.SimpleDateFormat#parse(java.lang.String)
-     * @since 2.4.1
-     */
+    @Deprecated
     public static Date parse(Date self, String format, String input, TimeZone zone) throws ParseException {
         SimpleDateFormat sdf = new SimpleDateFormat(format);
         sdf.setTimeZone(zone);
         return sdf.parse(input);
     }
 
-    /**
-     * Parse a String matching the pattern EEE MMM dd HH:mm:ss zzz yyyy
-     * containing US-locale-constants only (e.g. Sat for Saturdays).
-     * Such a string is generated by the toString method of {@link java.util.Date}
-     * <p>
-     * Note that a new SimpleDateFormat instance is created for every
-     * invocation of this method (for thread safety).
-     *
-     * @param self          placeholder variable used by Groovy categories; ignored for default static methods
-     * @param dateToString  String to be parsed to create the date instance. Must match the pattern EEE MMM dd HH:mm:ss zzz yyyy with US-locale symbols
-     * @return a new Date instance representing the parsed input string
-     * @throws ParseException if there is a parse error
-     */
+    @Deprecated
     public static Date parseToStringDate(Date self, String dateToString) throws ParseException {
         return new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US).parse(dateToString);
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/72da4738/subprojects/groovy-datetime/src/main/java/org/apache/groovy/datetime/extensions/DateTimeStaticExtensions.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-datetime/src/main/java/org/apache/groovy/datetime/extensions/DateTimeStaticExtensions.java b/subprojects/groovy-datetime/src/main/java/org/apache/groovy/datetime/extensions/DateTimeStaticExtensions.java
index 9015504..ef9e588 100644
--- a/subprojects/groovy-datetime/src/main/java/org/apache/groovy/datetime/extensions/DateTimeStaticExtensions.java
+++ b/subprojects/groovy-datetime/src/main/java/org/apache/groovy/datetime/extensions/DateTimeStaticExtensions.java
@@ -46,6 +46,8 @@ public class DateTimeStaticExtensions {
     /**
      * Parse text into a {@link java.time.LocalDate} using the provided pattern.
      *
+     * Note: the order of parameters differs from versions of this method for the legacy Date class.
+     *
      * @param type    placeholder variable used by Groovy categories; ignored for default static methods
      * @param text    String to be parsed to create the date instance
      * @param pattern pattern used to parse the text
@@ -63,6 +65,8 @@ public class DateTimeStaticExtensions {
     /**
      * Parse text into a {@link java.time.LocalDateTime} using the provided pattern.
      *
+     * Note: the order of parameters differs from versions of this method for the legacy Date class.
+     *
      * @param type    placeholder variable used by Groovy categories; ignored for default static methods
      * @param text    String to be parsed to create the date instance
      * @param pattern pattern used to parse the text

http://git-wip-us.apache.org/repos/asf/groovy/blob/72da4738/subprojects/groovy-dateutil/build.gradle
----------------------------------------------------------------------
diff --git a/subprojects/groovy-dateutil/build.gradle b/subprojects/groovy-dateutil/build.gradle
index 296f0fa..000f26d 100644
--- a/subprojects/groovy-dateutil/build.gradle
+++ b/subprojects/groovy-dateutil/build.gradle
@@ -23,6 +23,6 @@ dependencies {
 
 task moduleDescriptor(type: org.codehaus.groovy.gradle.WriteExtensionDescriptorTask) {
     extensionClasses = 'org.apache.groovy.dateutil.extensions.DateUtilExtensions'
-//    staticExtensionClasses = 'org.apache.groovy.dateutil.extensions.DateUtilStaticExtensions'
+    staticExtensionClasses = 'org.apache.groovy.dateutil.extensions.DateUtilStaticExtensions'
 }
 compileJava.dependsOn moduleDescriptor

http://git-wip-us.apache.org/repos/asf/groovy/blob/72da4738/subprojects/groovy-dateutil/src/main/java/org/apache/groovy/dateutil/extensions/DateUtilExtensions.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-dateutil/src/main/java/org/apache/groovy/dateutil/extensions/DateUtilExtensions.java b/subprojects/groovy-dateutil/src/main/java/org/apache/groovy/dateutil/extensions/DateUtilExtensions.java
index 19cf6dd..b2fb898 100644
--- a/subprojects/groovy-dateutil/src/main/java/org/apache/groovy/dateutil/extensions/DateUtilExtensions.java
+++ b/subprojects/groovy-dateutil/src/main/java/org/apache/groovy/dateutil/extensions/DateUtilExtensions.java
@@ -20,7 +20,6 @@ package org.apache.groovy.dateutil.extensions;
 
 import groovy.lang.Closure;
 import groovy.lang.GroovyRuntimeException;
-import org.codehaus.groovy.runtime.DefaultGroovyMethodsSupport;
 
 import java.sql.Timestamp;
 import java.text.DateFormat;
@@ -35,7 +34,7 @@ import java.util.TimeZone;
  * This class defines new groovy methods which appear on normal JDK
  * Date and Calendar classes inside the Groovy environment.
  */
-public class DateUtilExtensions extends DefaultGroovyMethodsSupport {
+public class DateUtilExtensions {
 
     /**
      * Support the subscript operator for a Date.

http://git-wip-us.apache.org/repos/asf/groovy/blob/72da4738/subprojects/groovy-dateutil/src/main/java/org/apache/groovy/dateutil/extensions/DateUtilStaticExtensions.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-dateutil/src/main/java/org/apache/groovy/dateutil/extensions/DateUtilStaticExtensions.java b/subprojects/groovy-dateutil/src/main/java/org/apache/groovy/dateutil/extensions/DateUtilStaticExtensions.java
new file mode 100644
index 0000000..ddfb1d4
--- /dev/null
+++ b/subprojects/groovy-dateutil/src/main/java/org/apache/groovy/dateutil/extensions/DateUtilStaticExtensions.java
@@ -0,0 +1,91 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.groovy.dateutil.extensions;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+
+/**
+ * This class defines new groovy static methods which appear on normal JDK
+ * Date and Calendar classes inside the Groovy environment.
+ */
+public class DateUtilStaticExtensions {
+    /**
+     * Parse a String into a Date instance using the given pattern.
+     * This convenience method acts as a wrapper for {@link java.text.SimpleDateFormat}.
+     * <p>
+     * Note that a new SimpleDateFormat instance is created for every
+     * invocation of this method (for thread safety).
+     *
+     * @param self   placeholder variable used by Groovy categories; ignored for default static methods
+     * @param format pattern used to parse the input string.
+     * @param input  String to be parsed to create the date instance
+     * @return a new Date instance representing the parsed input string
+     * @throws ParseException if there is a parse error
+     * @see java.text.SimpleDateFormat#parse(java.lang.String)
+     * @since 1.5.7
+     */
+    public static Date parse(Date self, String format, String input) throws ParseException {
+        return new SimpleDateFormat(format).parse(input);
+    }
+
+    /**
+     * Parse a String into a Date instance using the given pattern and TimeZone.
+     * This convenience method acts as a wrapper for {@link java.text.SimpleDateFormat}.
+     * <p>
+     * Note that a new SimpleDateFormat instance is created for every
+     * invocation of this method (for thread safety).
+     *
+     * @param self   placeholder variable used by Groovy categories; ignored for default static methods
+     * @param format pattern used to parse the input string.
+     * @param input  String to be parsed to create the date instance
+     * @param zone   TimeZone to use when parsing
+     * @return a new Date instance representing the parsed input string
+     * @throws ParseException if there is a parse error
+     * @see java.text.SimpleDateFormat#parse(java.lang.String)
+     * @since 2.4.1
+     */
+    public static Date parse(Date self, String format, String input, TimeZone zone) throws ParseException {
+        SimpleDateFormat sdf = new SimpleDateFormat(format);
+        sdf.setTimeZone(zone);
+        return sdf.parse(input);
+    }
+
+    /**
+     * Parse a String matching the pattern EEE MMM dd HH:mm:ss zzz yyyy
+     * containing US-locale-constants only (e.g. Sat for Saturdays).
+     * Such a string is generated by the toString method of {@link java.util.Date}
+     * <p>
+     * Note that a new SimpleDateFormat instance is created for every
+     * invocation of this method (for thread safety).
+     *
+     * @param self          placeholder variable used by Groovy categories; ignored for default static methods
+     * @param dateToString  String to be parsed to create the date instance. Must match the pattern EEE MMM dd HH:mm:ss zzz yyyy with US-locale symbols
+     * @return a new Date instance representing the parsed input string
+     * @throws ParseException if there is a parse error
+     * @since 1.8.4
+     */
+    public static Date parseToStringDate(Date self, String dateToString) throws ParseException {
+        return new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US).parse(dateToString);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/groovy/blob/72da4738/subprojects/groovy-dateutil/src/spec/test/gdk/WorkingWithDateUtilTypesTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-dateutil/src/spec/test/gdk/WorkingWithDateUtilTypesTest.groovy b/subprojects/groovy-dateutil/src/spec/test/gdk/WorkingWithDateUtilTypesTest.groovy
index 7599867..ec60df9 100644
--- a/subprojects/groovy-dateutil/src/spec/test/gdk/WorkingWithDateUtilTypesTest.groovy
+++ b/subprojects/groovy-dateutil/src/spec/test/gdk/WorkingWithDateUtilTypesTest.groovy
@@ -36,14 +36,17 @@ class WorkingWithDateUtilTypesTest extends GroovyTestCase {
 
     void testDateArithmetic() {
         // tag::date_arithmetic[]
-        def yesterday = new Date() - 1
-        def tomorrow = new Date() + 1
+        def utc = TimeZone.getTimeZone('UTC')
+        Date date = Date.parse("yyyy-MM-dd HH:mm", "2010-05-23 09:01", utc)
 
-        def diffInDays = tomorrow - yesterday
+        def prev = date - 1
+        def next = date + 1
+
+        def diffInDays = next - prev
         assert diffInDays == 2
 
         int count = 0
-        yesterday.upto(tomorrow) { count++ }
+        prev.upto(next) { count++ }
         assert count == 3
         // end::date_arithmetic[]
     }


[2/2] groovy git commit: remove an unused class

Posted by pa...@apache.org.
remove an unused class


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/3bb44bfb
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/3bb44bfb
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/3bb44bfb

Branch: refs/heads/master
Commit: 3bb44bfb305188f1b56a8a8b3c073d6317ec18fa
Parents: 72da473
Author: paulk <pa...@asert.com.au>
Authored: Mon Mar 26 13:20:28 2018 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Mon Mar 26 13:22:01 2018 +1000

----------------------------------------------------------------------
 .../codehaus/groovy/runtime/ClassExtender.java  | 89 --------------------
 1 file changed, 89 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/3bb44bfb/src/main/java/org/codehaus/groovy/runtime/ClassExtender.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/ClassExtender.java b/src/main/java/org/codehaus/groovy/runtime/ClassExtender.java
deleted file mode 100644
index 390cf9c..0000000
--- a/src/main/java/org/codehaus/groovy/runtime/ClassExtender.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-package org.codehaus.groovy.runtime;
-
-import groovy.lang.Closure;
-
-import java.util.HashMap;
-import java.util.Map;
-
-
-/**
- * A helper class used by the runtime to allow Groovy classes to be extended at runtime
- * 
- * @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
- */
-public class ClassExtender {
-    private Map variables;
-    private Map methods;
-
-    public synchronized Object get(String name) {
-        if (variables != null) {
-            return variables.get(name);
-        }
-        return null;
-    }
-
-    public synchronized void set(String name, Object value) {
-        if (variables == null) {
-            variables = createMap();
-        }
-        variables.put(name, value);
-    }
-
-    public synchronized void remove(String name) {
-        if (variables != null) {
-            variables.remove(name);
-        }
-    }
-
-    public void call(String name, Object params) {
-        Closure closure = null;
-        synchronized (this) {
-            if (methods != null) {
-                closure = (Closure) methods.get(name);
-            }
-        }
-        if (closure != null) {
-            closure.call(params);
-        }
-        /*
-        else {
-            throw DoesNotUnderstandException();
-        }
-        */
-    }
-
-    public synchronized void addMethod(String name, Closure closure) {
-        if (methods == null) {
-            methods = createMap();
-        }
-        methods.put(name, closure);
-    }
-
-    public synchronized void removeMethod(String name) {
-        if (methods != null) {
-            methods.remove(name);
-        }
-    }
-
-    protected Map createMap() {
-        return new HashMap();
-    }
-}