commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tcu...@apache.org
Subject svn commit: r573936 - in /commons/proper/jci/trunk: core/src/main/java/org/apache/commons/jci/ core/src/main/java/org/apache/commons/jci/compilers/ core/src/main/java/org/apache/commons/jci/readers/ core/src/main/java/org/apache/commons/jci/stores/ cor...
Date Sun, 09 Sep 2007 00:42:16 GMT
Author: tcurdt
Date: Sat Sep  8 17:42:15 2007
New Revision: 573936

URL: http://svn.apache.org/viewvc?rev=573936&view=rev
Log:
improving code coverage,
fixing problems reported by findbugs


Modified:
    commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/ReloadingClassLoader.java
    commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/CompilationResult.java
    commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/readers/MemoryResourceReader.java
    commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/stores/ResourceStoreClassLoader.java
    commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/utils/ConversionUtils.java
    commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/readers/ResourceReaderTestCase.java
    commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/stores/ResourceStoreTestCase.java
    commons/proper/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/ConfigurationReloading.java
    commons/proper/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspGenerator.java
    commons/proper/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/ServerPageServlet.java
    commons/proper/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java
    commons/proper/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/FilesystemAlterationObserverImpl.java
    commons/proper/jci/trunk/fam/src/test/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitorTestCase.java

Modified: commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/ReloadingClassLoader.java
URL: http://svn.apache.org/viewvc/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/ReloadingClassLoader.java?rev=573936&r1=573935&r2=573936&view=diff
==============================================================================
--- commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/ReloadingClassLoader.java
(original)
+++ commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/ReloadingClassLoader.java
Sat Sep  8 17:42:15 2007
@@ -58,7 +58,7 @@
             stores = newStores;
             delegate = new ResourceStoreClassLoader(parent, stores);            
             return true;
-        } catch ( final Exception e ) {
+        } catch ( final RuntimeException e ) {
             log.error("could not add resource store " + pStore);
         }
         return false;

Modified: commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/CompilationResult.java
URL: http://svn.apache.org/viewvc/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/CompilationResult.java?rev=573936&r1=573935&r2=573936&view=diff
==============================================================================
--- commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/CompilationResult.java
(original)
+++ commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/CompilationResult.java
Sat Sep  8 17:42:15 2007
@@ -55,10 +55,14 @@
     }
     
     public CompilationProblem[] getErrors() {
-        return errors;
+    	final CompilationProblem[] res = new CompilationProblem[errors.length];
+    	System.arraycopy(errors, 0, res, 0, res.length);
+        return res;
     }
 
     public CompilationProblem[] getWarnings() {
-        return warnings;
+    	final CompilationProblem[] res = new CompilationProblem[warnings.length];
+    	System.arraycopy(warnings, 0, res, 0, res.length);
+        return res;
     }
 }

Modified: commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/readers/MemoryResourceReader.java
URL: http://svn.apache.org/viewvc/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/readers/MemoryResourceReader.java?rev=573936&r1=573935&r2=573936&view=diff
==============================================================================
--- commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/readers/MemoryResourceReader.java
(original)
+++ commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/readers/MemoryResourceReader.java
Sat Sep  8 17:42:15 2007
@@ -27,7 +27,7 @@
  */
 public class MemoryResourceReader implements ResourceReader {
     
-    private Map resources;
+    private Map resources = null;
 
     public boolean isAvailable( final String pResourceName ) {
         if (resources == null) {

Modified: commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/stores/ResourceStoreClassLoader.java
URL: http://svn.apache.org/viewvc/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/stores/ResourceStoreClassLoader.java?rev=573936&r1=573935&r2=573936&view=diff
==============================================================================
--- commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/stores/ResourceStoreClassLoader.java
(original)
+++ commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/stores/ResourceStoreClassLoader.java
Sat Sep  8 17:42:15 2007
@@ -34,7 +34,9 @@
 
     public ResourceStoreClassLoader( final ClassLoader pParent, final ResourceStore[] pStores
) {
         super(pParent);
-        stores = pStores;
+        
+        stores = new ResourceStore[pStores.length]; 
+        System.arraycopy(pStores, 0, stores, 0, stores.length);	
     }
 
     private Class fastFindClass(final String name) {

Modified: commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/utils/ConversionUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/utils/ConversionUtils.java?rev=573936&r1=573935&r2=573936&view=diff
==============================================================================
--- commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/utils/ConversionUtils.java
(original)
+++ commons/proper/jci/trunk/core/src/main/java/org/apache/commons/jci/utils/ConversionUtils.java
Sat Sep  8 17:42:15 2007
@@ -18,6 +18,7 @@
 package org.apache.commons.jci.utils;
 
 import java.io.File;
+import java.util.Locale;
 
 /**
  * Mainly common path manipultation helper methods
@@ -57,7 +58,7 @@
     }
 
     public static String toJavaCasing(final String pName) {
-        final char[] name = pName.toLowerCase().toCharArray();
+        final char[] name = pName.toLowerCase(Locale.US).toCharArray();
         name[0] = Character.toUpperCase(name[0]);
         return new String(name);
     }

Modified: commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/readers/ResourceReaderTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/readers/ResourceReaderTestCase.java?rev=573936&r1=573935&r2=573936&view=diff
==============================================================================
--- commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/readers/ResourceReaderTestCase.java
(original)
+++ commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/readers/ResourceReaderTestCase.java
Sat Sep  8 17:42:15 2007
@@ -34,15 +34,19 @@
         final MemoryResourceReader reader = new MemoryResourceReader();
         reader.add("test", "test".getBytes());
         checkRead(reader);
+        reader.remove(null);
+        assertTrue(reader.isAvailable("test"));
+        reader.remove("test");
+        assertFalse(reader.isAvailable("test"));
     }
 
     private void checkRead( final ResourceReader reader ) throws Exception {
         assertTrue(reader.isAvailable("test"));
         final byte[] content = reader.getBytes("test");
         assertTrue(content != null);
-        assertTrue("test".equals(new String(content)));        
+        assertEquals("test", new String(content));        
 
-        assertTrue(!reader.isAvailable("bla"));
+        assertFalse(reader.isAvailable("bla"));
         assertTrue(reader.getBytes("bla") == null);
     }
 }

Modified: commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/stores/ResourceStoreTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/stores/ResourceStoreTestCase.java?rev=573936&r1=573935&r2=573936&view=diff
==============================================================================
--- commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/stores/ResourceStoreTestCase.java
(original)
+++ commons/proper/jci/trunk/core/src/test/java/org/apache/commons/jci/stores/ResourceStoreTestCase.java
Sat Sep  8 17:42:15 2007
@@ -37,9 +37,13 @@
         checkRemove(new FileResourceStore(directory));
     }
 
-    public void testTransactionalFileResourceStore() {
+    public void testTransactionalFileResourceStore() {    	
         checkReadWrite(new TransactionalResourceStore(new FileResourceStore(directory)));
         checkRemove(new TransactionalResourceStore(new FileResourceStore(directory)));
+        
+        final ResourceStore rs = new FileResourceStore(directory);
+        final TransactionalResourceStore trs = new TransactionalResourceStore(rs);
+        assertEquals(rs.toString(), trs.toString());
     }
 
     private void checkReadWrite( final ResourceStore pStore ) {

Modified: commons/proper/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/ConfigurationReloading.java
URL: http://svn.apache.org/viewvc/commons/proper/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/ConfigurationReloading.java?rev=573936&r1=573935&r2=573936&view=diff
==============================================================================
--- commons/proper/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/ConfigurationReloading.java
(original)
+++ commons/proper/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/configuration/ConfigurationReloading.java
Sat Sep  8 17:42:15 2007
@@ -19,6 +19,8 @@
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
@@ -53,9 +55,10 @@
                     System.out.println("Configuration change detected " + configFile);
 
                     final Properties props = new Properties();
+                    InputStream is = null; 
                     try {
-
-                        props.load(new FileInputStream(configFile));
+                    	is = new FileInputStream(configFile);
+                        props.load(is);
 
                         System.out.println("Notifying about configuration change " + configFile);
 
@@ -66,6 +69,11 @@
 
                     } catch (Exception e) {
                         System.err.println("Failed to load configuration " + configFile);
+                    } finally {
+                    	try {
+							is.close();
+						} catch (IOException e) {
+						}
                     }
 
                 }

Modified: commons/proper/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspGenerator.java
URL: http://svn.apache.org/viewvc/commons/proper/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspGenerator.java?rev=573936&r1=573935&r2=573936&view=diff
==============================================================================
--- commons/proper/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspGenerator.java
(original)
+++ commons/proper/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspGenerator.java
Sat Sep  8 17:42:15 2007
@@ -68,10 +68,11 @@
 
     public byte[] generateJavaSource( final  String pResourceName, final File pFile ) {
 
+    	final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+        final Writer output = new OutputStreamWriter(outputStream);
+
         try {
-            final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
             final Reader input = new InputStreamReader(new FileInputStream(pFile));
-            final Writer output = new OutputStreamWriter(outputStream);
 
             final int p = pResourceName.lastIndexOf('/');
 
@@ -154,12 +155,15 @@
             output.append("  }").append('\n');
             output.append("}").append('\n');
 
-
-            output.close();
-
             return outputStream.toByteArray();
+
         } catch (IOException e) {
             return null;
+        } finally {
+            try {
+				output.close();
+			} catch (IOException e) {
+			}        	
         }
     }
 

Modified: commons/proper/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/ServerPageServlet.java
URL: http://svn.apache.org/viewvc/commons/proper/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/ServerPageServlet.java?rev=573936&r1=573935&r2=573936&view=diff
==============================================================================
--- commons/proper/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/ServerPageServlet.java
(original)
+++ commons/proper/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/ServerPageServlet.java
Sat Sep  8 17:42:15 2007
@@ -56,8 +56,8 @@
     private static final long serialVersionUID = 1L;
 
     private final ReloadingClassLoader classloader = new ReloadingClassLoader(ServerPageServlet.class.getClassLoader());
-    private FilesystemAlterationMonitor fam;
-    private CompilingListener jspListener; 
+    private FilesystemAlterationMonitor fam = null;
+    private CompilingListener jspListener = null; 
 
     private Map servletsByClassname = new HashMap();
 

Modified: commons/proper/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java
URL: http://svn.apache.org/viewvc/commons/proper/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java?rev=573936&r1=573935&r2=573936&view=diff
==============================================================================
--- commons/proper/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java
(original)
+++ commons/proper/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java
Sat Sep  8 17:42:15 2007
@@ -39,7 +39,7 @@
     private final Object observersLock = new Object();
     private Map observers = Collections.unmodifiableMap(new HashMap());    
     private long delay = 3000;
-    private Thread thread;
+    private Thread thread = null;
 
     private volatile boolean running = true;
         

Modified: commons/proper/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/FilesystemAlterationObserverImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/FilesystemAlterationObserverImpl.java?rev=573936&r1=573935&r2=573936&view=diff
==============================================================================
--- commons/proper/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/FilesystemAlterationObserverImpl.java
(original)
+++ commons/proper/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/FilesystemAlterationObserverImpl.java
Sat Sep  8 17:42:15 2007
@@ -321,16 +321,18 @@
     }
 
     
-    public synchronized void checkAndNotify() {
-        if (listeners.length == 0) {
-            return;
-        }
-
-        notifyOnStart();
-        
-        checkEntries();
-        
-        notifyOnStop();
+    public void checkAndNotify() {
+    	synchronized(listenersSet) {
+	        if (listeners.length == 0) {
+	            return;
+	        }
+	
+	        notifyOnStart();
+	        
+	        checkEntries();
+	        
+	        notifyOnStop();
+    	}
     }
 
     
@@ -338,29 +340,38 @@
         return rootDirectory;
     }
 
-    public synchronized void addListener( final FilesystemAlterationListener pListener )
{
-        if (listenersSet.add(pListener)) {
-            createArrayFromSet();
-        }
-    }
-
-    public synchronized void removeListener( final FilesystemAlterationListener pListener
) {
-        if (listenersSet.remove(pListener)) {
-            createArrayFromSet();
-        }
+    public void addListener( final FilesystemAlterationListener pListener ) {
+    	synchronized(listenersSet) {
+	        if (listenersSet.add(pListener)) {
+	            listeners = createArrayFromSet();
+	        }
+    	}
+    }
+
+    public void removeListener( final FilesystemAlterationListener pListener ) {
+    	synchronized(listenersSet) {
+	        if (listenersSet.remove(pListener)) {
+	            listeners = createArrayFromSet();
+	        }
+    	}
     }
 
-    private void createArrayFromSet() {
+    private FilesystemAlterationListener[] createArrayFromSet() {
         final FilesystemAlterationListener[] newListeners = new FilesystemAlterationListener[listenersSet.size()];
         listenersSet.toArray(newListeners);
-        listeners = newListeners;
+        return newListeners;
     }
 
     public FilesystemAlterationListener[] getListeners() {
-        return listeners;
+    	synchronized(listenersSet) {
+        	final FilesystemAlterationListener[] res = new FilesystemAlterationListener[listeners.length];
+        	System.arraycopy(listeners, 0, res, 0, res.length);
+            return res;
+    	}    	
     }
 
-
+    /*
+     
     public static void main( String[] args ) {
         final FilesystemAlterationObserverImpl observer = new FilesystemAlterationObserverImpl(new
File(args[0]));
         while(true) {
@@ -371,4 +382,6 @@
             }
         }
     }
+
+    */
 }

Modified: commons/proper/jci/trunk/fam/src/test/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitorTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/jci/trunk/fam/src/test/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitorTestCase.java?rev=573936&r1=573935&r2=573936&view=diff
==============================================================================
--- commons/proper/jci/trunk/fam/src/test/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitorTestCase.java
(original)
+++ commons/proper/jci/trunk/fam/src/test/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitorTestCase.java
Sat Sep  8 17:42:15 2007
@@ -147,20 +147,23 @@
         listener = new MyFilesystemAlterationListener();
         
         fam.addListener(directory, listener);
-        assertTrue(fam.getListenersFor(directory).length == 1);
+        assertEquals(1, fam.getListenersFor(directory).length);
         
         fam.addListener(directory, listener); 
-        assertTrue(fam.getListenersFor(directory).length == 1);
-    }
+        assertEquals(1, fam.getListenersFor(directory).length);
+        
+        fam.removeListener(listener);
+        assertEquals(0, fam.getListenersFor(directory).length);
+}
 
     public void testDirectoryDoublication() throws Exception {
         fam = new FilesystemAlterationMonitor();
 
         fam.addListener(directory, new MyFilesystemAlterationListener()); 
-        assertTrue(fam.getListenersFor(directory).length == 1);
+        assertEquals(1, fam.getListenersFor(directory).length);
         
         fam.addListener(directory, new MyFilesystemAlterationListener()); 
-        assertTrue(fam.getListenersFor(directory).length == 2);
+        assertEquals(2, fam.getListenersFor(directory).length);
     }
 
     public void testCreateFileDetection() throws Exception {
@@ -170,9 +173,39 @@
         
         listener.waitForCheck();
         
-        assertTrue(listener.getCreatedFiles().size() == 1);
+        assertEquals(1, listener.getCreatedFiles().size());
+        
+        stop();
+    }
+
+    public void testTimeout() throws Exception {
+    	listener = new MyFilesystemAlterationListener();
+    	
+    	try {
+        	listener.waitForFirstCheck();
+        	fail("should be an timeout");
+        } catch(Exception e) {
+        	assertEquals("timeout", e.getMessage());
+        }
+
+        start();
+
+        try {
+        	listener.waitForEvent();
+        	fail("should be an timeout");
+        } catch(Exception e) {
+        	assertEquals("timeout", e.getMessage());
+        }
         
         stop();
+
+        try {
+        	listener.waitForCheck();
+        	fail("should be an timeout");
+        } catch(Exception e) {
+        	assertEquals("timeout", e.getMessage());
+        }
+    
     }
 
     public void testCreateDirectoryDetection() throws Exception {
@@ -182,7 +215,7 @@
         
         listener.waitForCheck();
         
-        assertTrue(listener.getCreatedDirectories().size() == 1);
+        assertEquals(1, listener.getCreatedDirectories().size());
         
         stop();
     }
@@ -194,14 +227,15 @@
         
         listener.waitForCheck();
         
-        assertTrue(listener.getCreatedFiles().size() == 1);
+        assertEquals(1, listener.getCreatedFiles().size());
+        assertEquals(0, listener.getChangedDirectories().size());
         
         file.delete();
         assertTrue(!file.exists());
 
         listener.waitForCheck();
         
-        assertTrue(listener.getDeletedFiles().size() == 1);
+        assertEquals(1, listener.getDeletedFiles().size());
         
         stop();        
     }
@@ -238,7 +272,7 @@
         
         listener.waitForCheck();
         
-        assertTrue(listener.getCreatedFiles().size() == 1);
+        assertEquals(1, listener.getCreatedFiles().size());
 
         delay();
 
@@ -246,7 +280,7 @@
 
         listener.waitForCheck();
         
-        assertTrue(listener.getChangedFiles().size() == 1);
+        assertEquals(1, listener.getChangedFiles().size());
         
         stop();
     }



Mime
View raw message