geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r706614 - in /geronimo/gshell/trunk: gshell-application/src/main/java/org/apache/geronimo/gshell/application/model/ gshell-commands/gshell-log4j/src/main/java/org/apache/geronimo/gshell/commands/log4j/ gshell-commands/gshell-vfs/src/main/ja...
Date Tue, 21 Oct 2008 12:52:03 GMT
Author: jdillon
Date: Tue Oct 21 05:52:02 2008
New Revision: 706614

URL: http://svn.apache.org/viewvc?rev=706614&view=rev
Log:
Added local file muck to FileSystemAccess, dropping custom local provider, using reflection
LocalFile->File lookup
Changed log4j/configure to use FileObject.getURL()

Removed:
    geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/provider/local/
Modified:
    geronimo/gshell/trunk/gshell-application/src/main/java/org/apache/geronimo/gshell/application/model/Branding.java
    geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/java/org/apache/geronimo/gshell/commands/log4j/ConfigureAction.java
    geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/EditAction.java
    geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/FileSystemAccess.java
    geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/FileSystemAccessImpl.java
    geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/resources/META-INF/spring/components.xml

Modified: geronimo/gshell/trunk/gshell-application/src/main/java/org/apache/geronimo/gshell/application/model/Branding.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-application/src/main/java/org/apache/geronimo/gshell/application/model/Branding.java?rev=706614&r1=706613&r2=706614&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-application/src/main/java/org/apache/geronimo/gshell/application/model/Branding.java
(original)
+++ geronimo/gshell/trunk/gshell-application/src/main/java/org/apache/geronimo/gshell/application/model/Branding.java
Tue Oct 21 05:52:02 2008
@@ -107,7 +107,7 @@
             return "";
         }
         else {
-            return new StringBuffer(str.length())
+            return new StringBuilder(str.length())
                     .append(Character.toTitleCase(str.charAt(0)))
                     .append(str.substring(1))
                     .toString();

Modified: geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/java/org/apache/geronimo/gshell/commands/log4j/ConfigureAction.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/java/org/apache/geronimo/gshell/commands/log4j/ConfigureAction.java?rev=706614&r1=706613&r2=706614&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/java/org/apache/geronimo/gshell/commands/log4j/ConfigureAction.java
(original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/java/org/apache/geronimo/gshell/commands/log4j/ConfigureAction.java
Tue Oct 21 05:52:02 2008
@@ -21,23 +21,17 @@
 
 import org.apache.commons.vfs.FileName;
 import org.apache.commons.vfs.FileObject;
-import org.apache.commons.vfs.Selectors;
 import org.apache.geronimo.gshell.clp.Argument;
 import org.apache.geronimo.gshell.command.CommandAction;
 import org.apache.geronimo.gshell.command.CommandContext;
 import org.apache.geronimo.gshell.io.IO;
 import org.apache.geronimo.gshell.vfs.FileObjects;
 import org.apache.geronimo.gshell.vfs.FileSystemAccess;
-import org.apache.geronimo.gshell.vfs.provider.local.LocalFile;
-import org.apache.geronimo.gshell.vfs.provider.local.LocalFileSystem;
 import org.apache.log4j.PropertyConfigurator;
 import org.apache.log4j.xml.DOMConfigurator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.File;
-
-
 /**
  * Configure logging.
  *
@@ -67,51 +61,20 @@
 
         // TODO: Validate
 
-        FileObject tmp = file;
-
-        // If the file is not on the local file system, then create tmp file for editing
-        if (!(file.getFileSystem() instanceof LocalFileSystem)) {
-            // Create a new temporary file, copy the contents for editing
-            tmp = fileSystemAccess.resolveFile(null, "tmp:/gshell.log4j.config-" + System.currentTimeMillis()
+ ".txt");
-            log.debug("Using temporary file for edit: {} ({})", tmp, tmp.getClass());
-            tmp.createFile();
-            tmp.copyFrom(file, Selectors.SELECT_SELF);
-        }
-
-        File configFile = getLocalFile(tmp);
-
-        FileName name = tmp.getName();
+        FileName name = file.getName();
         if (name.getExtension().equals("properties")) {
-            PropertyConfigurator.configure(configFile.toURI().toURL());
+            PropertyConfigurator.configure(file.getURL());
         }
         else if (name.getExtension().equals("xml")) {
-            DOMConfigurator.configure(configFile.toURI().toURL());
+            DOMConfigurator.configure(file.getURL());
         }
         else {
-            io.error("Don't know how to handle configuration file: {}", path);
+            io.error("Do no know how to handle configuration file: {}", path);
             return Result.FAILURE;
         }
 
-        if (tmp != file) {
-            tmp.delete();
-            FileObjects.close(tmp);
-        }
-
         FileObjects.close(file);
 
         return Result.SUCCESS;
     }
-
-    private File getLocalFile(final FileObject file) throws Exception {
-        assert file != null;
-        assert file instanceof LocalFile;
-
-        // This uses our custom accessible LocalFile implementation, which allows us to grap
the File object.
-        LocalFile lfile = (LocalFile)file;
-
-        // Force the file to attach if it hasn't already
-        lfile.refresh();
-
-        return lfile.getLocalFile();
-    }
 }
\ No newline at end of file

Modified: geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/EditAction.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/EditAction.java?rev=706614&r1=706613&r2=706614&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/EditAction.java
(original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/EditAction.java
Tue Oct 21 05:52:02 2008
@@ -20,16 +20,12 @@
 package org.apache.geronimo.gshell.commands.vfs;
 
 import org.apache.commons.vfs.FileObject;
-import org.apache.commons.vfs.FileSystem;
 import org.apache.commons.vfs.Selectors;
 import org.apache.commons.vfs.util.Os;
 import org.apache.geronimo.gshell.clp.Argument;
 import org.apache.geronimo.gshell.clp.Option;
 import org.apache.geronimo.gshell.command.CommandContext;
-import org.apache.geronimo.gshell.io.IO;
 import org.apache.geronimo.gshell.vfs.FileObjects;
-import org.apache.geronimo.gshell.vfs.provider.local.LocalFile;
-import org.apache.geronimo.gshell.vfs.provider.local.LocalFileSystem;
 
 import java.io.File;
 import java.util.Arrays;
@@ -51,7 +47,6 @@
 
     public Object execute(final CommandContext context) throws Exception {
         assert context != null;
-        IO io = context.getIo();
 
         FileObject file = resolveFile(context, path);
 
@@ -62,20 +57,17 @@
  
         FileObject tmp = file;
 
-        FileSystem fs = file.getFileSystem();
-        log.debug("File system: {}", fs);
-
         // If the file is not on the local file system, then create tmp file for editing
-        if (!(fs instanceof LocalFileSystem)) {
+        if (!getFileSystemAccess().isLocalFile(file)) {
             // Create a new temporary file, copy the contents for editing
-            tmp = resolveFile(context, "tmp:/gshell.edit-" + System.currentTimeMillis() +
".txt");
-            log.debug("Using temporary file for edit: {} ({})", tmp, tmp.getClass());
+            tmp = resolveFile(context, "tmp:/gshell-edit-" + System.currentTimeMillis() +
".txt");
+            log.debug("Using temporary file: {} ({})", tmp, tmp.getClass());
             tmp.createFile();
             tmp.copyFrom(file, Selectors.SELECT_SELF);
         }
 
         // Have to dereference the VFS file into a local file so the editor can access it
-        File localFile = getLocalFile(tmp);
+        File localFile = getFileSystemAccess().getLocalFile(tmp);
         Object result = edit(context, localFile);
 
         // If we had to use a tmp file for editing, then copy back and clean up
@@ -91,19 +83,6 @@
         return result;
     }
 
-    private File getLocalFile(final FileObject file) throws Exception {
-        assert file != null;
-        assert file instanceof LocalFile;
-
-        // This uses our custom accessible LocalFile implementation, which allows us to grap
the File object.
-        LocalFile lfile = (LocalFile)file;
-
-        // Force the file to attach if it hasn't already
-        lfile.refresh();
-
-        return lfile.getLocalFile();
-    }
-
     private Object edit(final CommandContext context, final File localFile) throws Exception
{
         assert context != null;
         assert localFile != null;

Modified: geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/FileSystemAccess.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/FileSystemAccess.java?rev=706614&r1=706613&r2=706614&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/FileSystemAccess.java
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/FileSystemAccess.java
Tue Oct 21 05:52:02 2008
@@ -24,6 +24,8 @@
 import org.apache.commons.vfs.FileSystemManager;
 import org.apache.geronimo.gshell.command.Variables;
 
+import java.io.File;
+
 /**
  * Provides access to VFS file systems.
  *
@@ -44,4 +46,8 @@
     FileObject resolveFile(FileObject baseFile, String name) throws FileSystemException;
 
     FileObject resolveFile(String name) throws FileSystemException;
+
+    boolean isLocalFile(FileObject file);
+
+    File getLocalFile(FileObject file) throws FileSystemException;
 }

Modified: geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/FileSystemAccessImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/FileSystemAccessImpl.java?rev=706614&r1=706613&r2=706614&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/FileSystemAccessImpl.java
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/FileSystemAccessImpl.java
Tue Oct 21 05:52:02 2008
@@ -22,11 +22,15 @@
 import org.apache.commons.vfs.FileObject;
 import org.apache.commons.vfs.FileSystemException;
 import org.apache.commons.vfs.FileSystemManager;
+import org.apache.commons.vfs.provider.local.LocalFile;
 import org.apache.geronimo.gshell.application.ApplicationManager;
 import org.apache.geronimo.gshell.command.Variables;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.File;
+import java.lang.reflect.Field;
+
 /**
  * {@link FileSystemAccess} component.
  *
@@ -124,4 +128,31 @@
     public FileObject resolveFile(final String name) throws FileSystemException {
         return getManager().resolveFile(getCurrentDirectory(), name);
     }
+
+    public boolean isLocalFile(final FileObject file) {
+        return file instanceof LocalFile;
+    }
+
+    public File getLocalFile(final FileObject file) throws FileSystemException {
+        if (!isLocalFile(file)) {
+            throw new FileSystemException("Unable to get local file from: " + file.getClass());
+        }
+
+        try {
+            file.refresh();
+            Field field = LocalFile.class.getDeclaredField("file");
+            
+            try {
+                return (File)field.get(file);
+            }
+            catch (IllegalAccessException ignore) {
+                // try again
+                field.setAccessible(true);
+                return (File)field.get(file);
+            }
+        }
+        catch (Exception e) {
+            throw new FileSystemException(e);
+        }
+    }
 }
\ No newline at end of file

Modified: geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/resources/META-INF/spring/components.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/resources/META-INF/spring/components.xml?rev=706614&r1=706613&r2=706614&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/resources/META-INF/spring/components.xml
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/resources/META-INF/spring/components.xml
Tue Oct 21 05:52:02 2008
@@ -67,6 +67,14 @@
 
     <bean class="org.apache.geronimo.gshell.vfs.config.FileProviderConfigurer">
         <property name="fileSystemManager" ref="fileSystemManager"/>
+        <property name="scheme" value="file"/>
+        <property name="provider">
+            <bean class="org.apache.commons.vfs.provider.local.DefaultLocalFileProvider"/>
+        </property>
+    </bean>
+
+    <bean class="org.apache.geronimo.gshell.vfs.config.FileProviderConfigurer">
+        <property name="fileSystemManager" ref="fileSystemManager"/>
         <property name="scheme" value="tmp"/>
         <property name="provider">
             <bean class="org.apache.commons.vfs.provider.temp.TemporaryFileProvider"/>
@@ -129,12 +137,4 @@
         <constructor-arg ref="fileSystemAccess"/>
     </bean>
 
-    <bean class="org.apache.geronimo.gshell.vfs.config.FileProviderConfigurer">
-        <property name="fileSystemManager" ref="fileSystemManager"/>
-        <property name="scheme" value="file"/>
-        <property name="provider">
-            <bean class="org.apache.geronimo.gshell.vfs.provider.local.LocalFileProvider"/>
-        </property>
-    </bean>
-
 </beans>
\ No newline at end of file



Mime
View raw message