Author: hlship
Date: Wed Sep  1 00:01:53 2010
New Revision: 991402

URL: http://svn.apache.org/viewvc?rev=991402&view=rev
Log:
TAP5-1188: Refactory URLChangeTracker from tapestry-core to tapestry-ioc

Added:
    
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/URLChangeTracker.java
   (contents, props changed)
      - copied, changed from r991401, 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/util/URLChangeTracker.java
    
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/URLChangeTrackerTest.java
   (contents, props changed)
      - copied, changed from r991401, 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/util/URLChangeTrackerTest.java
Removed:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/util/URLChangeTracker.java
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/util/URLChangeTrackerTest.java
Modified:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSourceImpl.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImpl.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentTemplateSourceImpl.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MessagesSourceImpl.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceCacheImpl.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ValidationMessagesSourceImpl.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImplTest.java
    
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/test/IOCTestCase.java
    
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ReloadTest.java

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSourceImpl.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSourceImpl.java?rev=991402&r1=991401&r2=991402&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSourceImpl.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSourceImpl.java
 Wed Sep  1 00:01:53 2010
@@ -29,13 +29,13 @@ import javassist.NotFoundException;
 import javassist.Translator;
 
 import org.apache.tapestry5.internal.event.InvalidationEventHubImpl;
-import org.apache.tapestry5.internal.util.URLChangeTracker;
 import org.apache.tapestry5.ioc.internal.services.ClassFactoryClassPool;
 import org.apache.tapestry5.ioc.internal.services.ClassFactoryImpl;
 import org.apache.tapestry5.ioc.internal.services.CtClassSource;
 import org.apache.tapestry5.ioc.internal.services.CtClassSourceImpl;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
+import org.apache.tapestry5.ioc.internal.util.URLChangeTracker;
 import org.apache.tapestry5.ioc.services.ClassFabUtils;
 import org.apache.tapestry5.ioc.services.ClassFactory;
 import org.apache.tapestry5.ioc.services.ClasspathURLConverter;

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImpl.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImpl.java?rev=991402&r1=991401&r2=991402&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImpl.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImpl.java
 Wed Sep  1 00:01:53 2010
@@ -21,11 +21,11 @@ import java.util.Locale;
 
 import org.apache.tapestry5.SymbolConstants;
 import org.apache.tapestry5.func.Worker;
-import org.apache.tapestry5.internal.util.URLChangeTracker;
 import org.apache.tapestry5.ioc.Messages;
 import org.apache.tapestry5.ioc.Resource;
 import org.apache.tapestry5.ioc.annotations.Symbol;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry5.ioc.internal.util.URLChangeTracker;
 import org.apache.tapestry5.ioc.services.ClasspathURLConverter;
 import org.apache.tapestry5.model.ComponentModel;
 import org.apache.tapestry5.services.InvalidationEventHub;

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentTemplateSourceImpl.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentTemplateSourceImpl.java?rev=991402&r1=991401&r2=991402&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentTemplateSourceImpl.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentTemplateSourceImpl.java
 Wed Sep  1 00:01:53 2010
@@ -19,11 +19,11 @@ import org.apache.tapestry5.internal.eve
 import org.apache.tapestry5.internal.parser.ComponentTemplate;
 import org.apache.tapestry5.internal.parser.TemplateToken;
 import org.apache.tapestry5.internal.util.MultiKey;
-import org.apache.tapestry5.internal.util.URLChangeTracker;
 import org.apache.tapestry5.ioc.Location;
 import org.apache.tapestry5.ioc.Resource;
 import org.apache.tapestry5.ioc.annotations.Primary;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry5.ioc.internal.util.URLChangeTracker;
 import org.apache.tapestry5.ioc.services.ClasspathURLConverter;
 import org.apache.tapestry5.model.ComponentModel;
 import org.apache.tapestry5.services.InvalidationEventHub;

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MessagesSourceImpl.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MessagesSourceImpl.java?rev=991402&r1=991401&r2=991402&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MessagesSourceImpl.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MessagesSourceImpl.java
 Wed Sep  1 00:01:53 2010
@@ -21,11 +21,11 @@ import java.util.Map;
 
 import org.apache.tapestry5.internal.event.InvalidationEventHubImpl;
 import org.apache.tapestry5.internal.util.MultiKey;
-import org.apache.tapestry5.internal.util.URLChangeTracker;
 import org.apache.tapestry5.ioc.Messages;
 import org.apache.tapestry5.ioc.Resource;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 import org.apache.tapestry5.ioc.internal.util.LocalizedNameGenerator;
+import org.apache.tapestry5.ioc.internal.util.URLChangeTracker;
 import org.apache.tapestry5.services.messages.PropertiesFileParser;
 
 /**

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceCacheImpl.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceCacheImpl.java?rev=991402&r1=991401&r2=991402&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceCacheImpl.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceCacheImpl.java
 Wed Sep  1 00:01:53 2010
@@ -15,9 +15,9 @@
 package org.apache.tapestry5.internal.services;
 
 import org.apache.tapestry5.internal.event.InvalidationEventHubImpl;
-import org.apache.tapestry5.internal.util.URLChangeTracker;
 import org.apache.tapestry5.ioc.Resource;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry5.ioc.internal.util.URLChangeTracker;
 import org.apache.tapestry5.ioc.services.ClasspathURLConverter;
 import org.apache.tapestry5.services.ResourceDigestGenerator;
 import org.apache.tapestry5.services.UpdateListener;

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ValidationMessagesSourceImpl.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ValidationMessagesSourceImpl.java?rev=991402&r1=991401&r2=991402&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ValidationMessagesSourceImpl.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ValidationMessagesSourceImpl.java
 Wed Sep  1 00:01:53 2010
@@ -14,11 +14,11 @@
 
 package org.apache.tapestry5.internal.services;
 
-import org.apache.tapestry5.internal.util.URLChangeTracker;
 import org.apache.tapestry5.ioc.MessageFormatter;
 import org.apache.tapestry5.ioc.Messages;
 import org.apache.tapestry5.ioc.Resource;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry5.ioc.internal.util.URLChangeTracker;
 import org.apache.tapestry5.ioc.services.ClasspathURLConverter;
 import org.apache.tapestry5.services.UpdateListener;
 import org.apache.tapestry5.services.ValidationMessagesSource;

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java?rev=991402&r1=991401&r2=991402&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/test/TapestryTestCase.java
 Wed Sep  1 00:01:53 2010
@@ -14,14 +14,10 @@
 
 package org.apache.tapestry5.test;
 
-import static java.lang.Thread.sleep;
 import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newList;
 
-import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.net.URL;
 import java.util.Arrays;
@@ -317,30 +313,6 @@ public abstract class TapestryTestCase e
         return newMock(Validator.class);
     }
 
-    /**
-     * Writes a change to a file.
-     */
-    protected final void touch(File f) throws Exception
-    {
-        long startModified = f.lastModified();
-
-        while (true)
-        {
-            OutputStream o = new FileOutputStream(f);
-            o.write(0);
-            o.close();
-
-            long newModified = f.lastModified();
-
-            if (newModified != startModified)
-                return;
-
-            // Sleep 1/20 second and try again
-
-            sleep(50);
-        }
-    }
-
     /** @deprecated May be removed in Tapestry 5.3 */
     protected final void train_addField(ClassTransformation transformation, 
int modifiers, String type,
             String suggestedName, String actualName)

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImplTest.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImplTest.java?rev=991402&r1=991401&r2=991402&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImplTest.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImplTest.java
 Wed Sep  1 00:01:53 2010
@@ -20,11 +20,11 @@ import java.util.Locale;
 
 import 
org.apache.tapestry5.internal.services.messages.PropertiesFileParserImpl;
 import org.apache.tapestry5.internal.test.InternalBaseTestCase;
-import org.apache.tapestry5.internal.util.URLChangeTracker;
 import org.apache.tapestry5.ioc.Messages;
 import org.apache.tapestry5.ioc.Resource;
 import org.apache.tapestry5.ioc.internal.services.ClasspathURLConverterImpl;
 import org.apache.tapestry5.ioc.internal.util.ClasspathResource;
+import org.apache.tapestry5.ioc.internal.util.URLChangeTracker;
 import org.apache.tapestry5.ioc.services.ClasspathURLConverter;
 import org.apache.tapestry5.model.ComponentModel;
 import org.apache.tapestry5.services.messages.ComponentMessagesSource;

Copied: 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/URLChangeTracker.java
 (from r991401, 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/util/URLChangeTracker.java)
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/URLChangeTracker.java?p2=tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/URLChangeTracker.java&p1=tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/util/URLChangeTracker.java&r1=991401&r2=991402&rev=991402&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/util/URLChangeTracker.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/URLChangeTracker.java
 Wed Sep  1 00:01:53 2010
@@ -4,7 +4,7 @@
 // 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
+// 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,
@@ -12,9 +12,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package org.apache.tapestry5.internal.util;
+package org.apache.tapestry5.ioc.internal.util;
 
-import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 import org.apache.tapestry5.ioc.services.ClassFabUtils;
 import org.apache.tapestry5.ioc.services.ClasspathURLConverter;
 
@@ -37,56 +36,63 @@ public class URLChangeTracker
     private final Map<File, Long> fileToTimestamp = 
CollectionFactory.newConcurrentMap();
 
     private final boolean granularitySeconds;
-    
-    private final ClasspathURLConverter classpathURLConverter; 
+
+    private final ClasspathURLConverter classpathURLConverter;
 
     /**
      * Creates a new URL change tracker with millisecond-level granularity.
      * 
-     * @param classpathURLConverter used to convert URLs from one protocol to 
another
+     * @param classpathURLConverter
+     *            used to convert URLs from one protocol to another
      */
     public URLChangeTracker(ClasspathURLConverter classpathURLConverter)
     {
         this(classpathURLConverter, false);
-        
+
     }
 
     /**
      * Creates a new URL change tracker, using either millisecond-level 
granularity or second-level granularity.
-     *
-     * @param classpathURLConverter used to convert URLs from one protocol to 
another
-     * @param granularitySeconds whether or not to use second granularity (as 
opposed to millisecond granularity)
+     * 
+     * @param classpathURLConverter
+     *            used to convert URLs from one protocol to another
+     * @param granularitySeconds
+     *            whether or not to use second granularity (as opposed to 
millisecond granularity)
      */
     public URLChangeTracker(ClasspathURLConverter classpathURLConverter, 
boolean granularitySeconds)
     {
         this.granularitySeconds = granularitySeconds;
-        
+
         this.classpathURLConverter = classpathURLConverter;
     }
 
     /**
      * Stores a new URL into the tracker, or returns the previous time stamp 
for a previously added URL. Filters out all
      * non-file URLs.
-     *
-     * @param url of the resource to add, or null if not known
+     * 
+     * @param url
+     *            of the resource to add, or null if not known
      * @return the current timestamp for the URL (possibly rounded off for 
granularity reasons), or 0 if the URL is
      *         null
      */
     public long add(URL url)
     {
-        if (url == null) return 0;
-        
+        if (url == null)
+            return 0;
+
         URL converted = classpathURLConverter.convert(url);
 
-        if (!converted.getProtocol().equals("file")) return 
timestampForNonFileURL(converted);
+        if (!converted.getProtocol().equals("file"))
+            return timestampForNonFileURL(converted);
 
         File resourceFile = ClassFabUtils.toFileFromFileProtocolURL(converted);
 
-        if (fileToTimestamp.containsKey(resourceFile)) return 
fileToTimestamp.get(resourceFile);
+        if (fileToTimestamp.containsKey(resourceFile))
+            return fileToTimestamp.get(resourceFile);
 
         long timestamp = readTimestamp(resourceFile);
 
-        // A quick and imperfect fix for TAPESTRY-1918.  When a file
+        // A quick and imperfect fix for TAPESTRY-1918. When a file
         // is added, add the directory containing the file as well.
 
         fileToTimestamp.put(resourceFile, timestamp);
@@ -99,7 +105,6 @@ public class URLChangeTracker
             fileToTimestamp.put(dir, dirTimestamp);
         }
 
-
         return timestamp;
     }
 
@@ -143,7 +148,8 @@ public class URLChangeTracker
             long newTimestamp = readTimestamp(entry.getKey());
             long current = entry.getValue();
 
-            if (current == newTimestamp) continue;
+            if (current == newTimestamp)
+                continue;
 
             result = true;
             entry.setValue(newTimestamp);
@@ -157,7 +163,8 @@ public class URLChangeTracker
      */
     private long readTimestamp(File file)
     {
-        if (!file.exists()) return FILE_DOES_NOT_EXIST_TIMESTAMP;
+        if (!file.exists())
+            return FILE_DOES_NOT_EXIST_TIMESTAMP;
 
         return applyGranularity(file.lastModified());
     }
@@ -169,7 +176,8 @@ public class URLChangeTracker
         // are only accurate to one second. The extra level of detail creates 
false positives
         // for changes, and undermines HTTP response caching in the client.
 
-        if (granularitySeconds) return timestamp - (timestamp % 1000);
+        if (granularitySeconds)
+            return timestamp - (timestamp % 1000);
 
         return timestamp;
     }

Propchange: 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/URLChangeTracker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/test/IOCTestCase.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/test/IOCTestCase.java?rev=991402&r1=991401&r2=991402&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/test/IOCTestCase.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/test/IOCTestCase.java
 Wed Sep  1 00:01:53 2010
@@ -4,7 +4,7 @@
 // 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
+// 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,
@@ -22,9 +22,13 @@ import org.apache.tapestry5.ioc.def.Modu
 import org.apache.tapestry5.ioc.def.ServiceDef;
 import org.apache.tapestry5.ioc.services.*;
 
+import static java.lang.Thread.sleep;
 import static org.easymock.EasyMock.isA;
 import org.slf4j.Logger;
 
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.net.URL;
@@ -52,11 +56,12 @@ public class IOCTestCase extends TestBas
     {
         for (Method method : clazz.getMethods())
         {
-            if (method.getName().equals(methodName)) return method;
+            if (method.getName().equals(methodName))
+                return method;
         }
 
-        throw new IllegalArgumentException(
-                String.format("Class %s does not provide a method named 
'%s'.", clazz.getName(), methodName));
+        throw new IllegalArgumentException(String.format("Class %s does not 
provide a method named '%s'.",
+                clazz.getName(), methodName));
     }
 
     protected final Method findMethod(Object subject, String methodName)
@@ -295,7 +300,7 @@ public class IOCTestCase extends TestBas
     }
 
     protected final <T> void train_getService(ObjectLocator locator, String 
serviceId, Class<T> serviceInterface,
-                                              T service)
+            T service)
     {
         expect(locator.getService(serviceId, 
serviceInterface)).andReturn(service);
     }
@@ -341,7 +346,7 @@ public class IOCTestCase extends TestBas
     }
 
     protected final <T> void train_provide(ObjectProvider provider, Class<T> 
objectType,
-                                           AnnotationProvider 
annotationProvider, ObjectLocator locator, T object)
+            AnnotationProvider annotationProvider, ObjectLocator locator, T 
object)
     {
         expect(provider.provide(objectType, annotationProvider, 
locator)).andReturn(object);
     }
@@ -352,7 +357,7 @@ public class IOCTestCase extends TestBas
     }
 
     protected final <T extends Annotation> void 
train_getAnnotation(AnnotationProvider annotationProvider,
-                                                                    Class<T> 
annotationClass, T annotation)
+            Class<T> annotationClass, T annotation)
     {
         
expect(annotationProvider.getAnnotation(annotationClass)).andReturn(annotation);
     }
@@ -429,4 +434,30 @@ public class IOCTestCase extends TestBas
     {
         
expect(symbolSource.valueForSymbol(symbolName)).andReturn(value).atLeastOnce();
     }
+
+    /**
+     * Writes a change to a file. The contents of the file are lost. May 
repeatedly modify
+     * the file, and does not return until the last modified time for the file 
actually changes (how long that takes
+     * is JDK, OS and file system dependent).
+     */
+    protected final void touch(File f) throws Exception
+    {
+        long startModified = f.lastModified();
+
+        while (true)
+        {
+            OutputStream o = new FileOutputStream(f);
+            o.write(0);
+            o.close();
+
+            long newModified = f.lastModified();
+
+            if (newModified != startModified)
+                return;
+
+            // Sleep 1/20 second and try again
+
+            sleep(50);
+        }
+    }
 }

Modified: 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ReloadTest.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ReloadTest.java?rev=991402&r1=991401&r2=991402&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ReloadTest.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ReloadTest.java
 Wed Sep  1 00:01:53 2010
@@ -24,6 +24,7 @@ import javassist.CtClass;
 import javassist.CtConstructor;
 import javassist.CtMethod;
 
+import org.apache.tapestry5.ioc.test.IOCTestCase;
 import org.apache.tapestry5.ioc.test.TestBase;
 import org.apache.tapestry5.services.UpdateListenerHub;
 import org.testng.annotations.BeforeClass;
@@ -36,7 +37,7 @@ import com.example.ReloadableService;
  * Test the ability to perform live class reloading of a service 
implementation.
  */
 @SuppressWarnings("unchecked")
-public class ReloadTest extends TestBase
+public class ReloadTest extends IOCTestCase
 {
     private static final String PACKAGE = "com.example";
 
@@ -48,6 +49,8 @@ public class ReloadTest extends TestBase
 
     public static boolean eagerLoadServiceWasInstantiated;
 
+    private File classFile;
+
     @BeforeClass
     public void setup() throws Exception
     {
@@ -63,6 +66,8 @@ public class ReloadTest extends TestBase
 
         classLoader = new URLClassLoader(new URL[]
         { classesURL }, Thread.currentThread().getContextClassLoader());
+
+        classFile = new File(classesDir, 
"com/example/ReloadableServiceImpl.class");
     }
 
     @Test
@@ -82,9 +87,7 @@ public class ReloadTest extends TestBase
 
         fireUpdateCheck(registry);
 
-        // Sleep long enough that the Java millisecond clock advances.
-
-        Thread.currentThread().sleep(1500);
+        touch(classFile);
 
         createImplementationClass("updated");
 
@@ -110,8 +113,6 @@ public class ReloadTest extends TestBase
 
         assertEquals(reloadable.getStatus(), "before delete");
 
-        File classFile = new File(classesDir, 
"com/example/ReloadableServiceImpl.class");
-
         assertTrue(classFile.exists(), "The class file must exist.");
 
         classFile.delete();
@@ -144,7 +145,7 @@ public class ReloadTest extends TestBase
 
         assertEquals(reloadable.getStatus(), "initial proxy");
 
-        Thread.currentThread().sleep(1500);
+        touch(classFile);
 
         createImplementationClass("updated proxy");
 
@@ -178,9 +179,9 @@ public class ReloadTest extends TestBase
 
         ReloadableService reloadable = 
registry.getService(ReloadableService.class);
 
-        createInvalidImplentationClass();
+        touch(classFile);
 
-        Thread.currentThread().sleep(1500);
+        createInvalidImplentationClass();
 
         fireUpdateCheck(registry);
 
@@ -243,7 +244,6 @@ public class ReloadTest extends TestBase
     @Test
     public void eager_load_service_with_proxy()
     {
-
         eagerLoadServiceWasInstantiated = false;
 
         Registry r = new 
RegistryBuilder().add(EagerProxyReloadModule.class).build();

Copied: 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/URLChangeTrackerTest.java
 (from r991401, 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/util/URLChangeTrackerTest.java)
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/URLChangeTrackerTest.java?p2=tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/URLChangeTrackerTest.java&p1=tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/util/URLChangeTrackerTest.java&r1=991401&r2=991402&rev=991402&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/util/URLChangeTrackerTest.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/URLChangeTrackerTest.java
 Wed Sep  1 00:01:53 2010
@@ -1,10 +1,10 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2010 The Apache Software Foundation
 //
 // Licensed 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
+// 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,
@@ -12,20 +12,21 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package org.apache.tapestry5.internal.util;
+package org.apache.tapestry5.ioc.internal.util;
+
+import java.io.File;
+import java.net.URL;
 
 import org.apache.tapestry5.ioc.internal.services.ClasspathURLConverterImpl;
 import org.apache.tapestry5.ioc.services.ClasspathURLConverter;
-import org.apache.tapestry5.test.TapestryTestCase;
+import org.apache.tapestry5.ioc.test.IOCTestCase;
+import org.apache.tapestry5.ioc.test.TestBase;
 import org.testng.annotations.Test;
 
-import java.io.File;
-import java.net.URL;
-
-public class URLChangeTrackerTest extends TapestryTestCase
+public class URLChangeTrackerTest extends IOCTestCase
 {
     private final ClasspathURLConverter converter = new 
ClasspathURLConverterImpl();
-    
+
     @Test
     public void contains_change_when_empty()
     {
@@ -102,7 +103,8 @@ public class URLChangeTrackerTest extend
         {
             File.createTempFile("changetracker1", ".tmp");
 
-            if (dir.lastModified() != timestamp) break;
+            if (dir.lastModified() != timestamp)
+                break;
 
             // Sometime Java need a moment to catch up in terms of
             // file system changes. Sleep for a few milliseconds

Propchange: 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/URLChangeTrackerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to