geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r703536 - in /geronimo/gshell/trunk: gshell-assembly/src/main/underlay/etc/ gshell-commands/gshell-log4j/ gshell-commands/gshell-log4j/src/main/java/org/apache/geronimo/gshell/commands/log4j/ gshell-commands/gshell-log4j/src/main/resources/...
Date Fri, 10 Oct 2008 17:56:50 GMT
Author: jdillon
Date: Fri Oct 10 10:56:50 2008
New Revision: 703536

URL: http://svn.apache.org/viewvc?rev=703536&view=rev
Log:
Add more log4j commands

Added:
    geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/java/org/apache/geronimo/gshell/commands/log4j/ConfigureAction.java
  (with props)
    geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/resources/org/apache/geronimo/gshell/commands/log4j/ConfigureAction.properties
  (contents, props changed)
      - copied, changed from r703515, geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/resources/org/apache/geronimo/gshell/commands/log4j/LoggerAction.properties
Modified:
    geronimo/gshell/trunk/gshell-assembly/src/main/underlay/etc/application.xml
    geronimo/gshell/trunk/gshell-commands/gshell-log4j/pom.xml
    geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/resources/META-INF/spring/components.xml

Modified: geronimo/gshell/trunk/gshell-assembly/src/main/underlay/etc/application.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-assembly/src/main/underlay/etc/application.xml?rev=703536&r1=703535&r2=703536&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-assembly/src/main/underlay/etc/application.xml (original)
+++ geronimo/gshell/trunk/gshell-assembly/src/main/underlay/etc/application.xml Fri Oct 10
10:56:50 2008
@@ -62,6 +62,11 @@
 
             <dependency>
                 <groupId>org.apache.geronimo.gshell.support</groupId>
+                <artifactId>gshell-vfs-local</artifactId>
+            </dependency>
+
+            <dependency>
+                <groupId>org.apache.geronimo.gshell.support</groupId>
                 <artifactId>gshell-vfs-truezip</artifactId>
             </dependency>
         </dependencyGroup>

Modified: geronimo/gshell/trunk/gshell-commands/gshell-log4j/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-log4j/pom.xml?rev=703536&r1=703535&r2=703536&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-log4j/pom.xml (original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-log4j/pom.xml Fri Oct 10 10:56:50 2008
@@ -42,7 +42,17 @@
             <groupId>org.apache.geronimo.gshell.support</groupId>
             <artifactId>gshell-spring</artifactId>
         </dependency>
-        
+
+        <dependency>
+            <groupId>org.apache.geronimo.gshell.support</groupId>
+            <artifactId>gshell-vfs</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.geronimo.gshell.support</groupId>
+            <artifactId>gshell-vfs-local</artifactId>
+        </dependency>
+
         <dependency>
             <groupId>log4j</groupId>
             <artifactId>log4j</artifactId>

Added: 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=703536&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/java/org/apache/geronimo/gshell/commands/log4j/ConfigureAction.java
(added)
+++ geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/java/org/apache/geronimo/gshell/commands/log4j/ConfigureAction.java
Fri Oct 10 10:56:50 2008
@@ -0,0 +1,112 @@
+/*
+ * 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.geronimo.gshell.commands.log4j;
+
+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.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ConfigureAction
+    implements CommandAction
+{
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private FileSystemAccess fileSystemAccess;
+
+    @Argument
+    private String path;
+
+    public Object execute(final CommandContext context) throws Exception {
+        assert context != null;
+        IO io = context.getIo();
+
+        FileObject cwd = fileSystemAccess.getCurrentDirectory();
+        FileObject file = fileSystemAccess.resolveFile(cwd, path);
+
+        // 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();
+        if (name.getExtension().equals("properties")) {
+            PropertyConfigurator.configure(configFile.toURI().toURL());
+        }
+        else if (name.getExtension().equals("xml")) {
+            DOMConfigurator.configure(configFile.toURI().toURL());
+        }
+        else {
+            io.error("Don't 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

Propchange: geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/java/org/apache/geronimo/gshell/commands/log4j/ConfigureAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/java/org/apache/geronimo/gshell/commands/log4j/ConfigureAction.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/java/org/apache/geronimo/gshell/commands/log4j/ConfigureAction.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/resources/META-INF/spring/components.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/resources/META-INF/spring/components.xml?rev=703536&r1=703535&r2=703536&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/resources/META-INF/spring/components.xml
(original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/resources/META-INF/spring/components.xml
Fri Oct 10 10:56:50 2008
@@ -44,6 +44,10 @@
             <gshell:command name="log4j/ndc">
                 <gshell:action class="org.apache.geronimo.gshell.commands.log4j.NdcAction"/>
             </gshell:command>
+
+            <gshell:command name="log4j/configure">
+                <gshell:action class="org.apache.geronimo.gshell.commands.log4j.ConfigureAction"/>
+            </gshell:command>
         </gshell:command-bundle>
     </gshell:plugin>
 

Copied: geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/resources/org/apache/geronimo/gshell/commands/log4j/ConfigureAction.properties
(from r703515, geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/resources/org/apache/geronimo/gshell/commands/log4j/LoggerAction.properties)
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/resources/org/apache/geronimo/gshell/commands/log4j/ConfigureAction.properties?p2=geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/resources/org/apache/geronimo/gshell/commands/log4j/ConfigureAction.properties&p1=geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/resources/org/apache/geronimo/gshell/commands/log4j/LoggerAction.properties&r1=703515&r2=703536&rev=703536&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/resources/org/apache/geronimo/gshell/commands/log4j/LoggerAction.properties
(original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/resources/org/apache/geronimo/gshell/commands/log4j/ConfigureAction.properties
Fri Oct 10 10:56:50 2008
@@ -21,13 +21,10 @@
 ## $Rev$ $Date$
 ##
 
-command.description=Get or set a loggers level.
+command.description=Configure logging.
 
-command.argument.loggerName=Logger name to query/modify
-command.argument.loggerName.token=LOGGER
-
-command.argument.levelName=Level to set logger at
-command.argument.levelName.token=LEVEL
+command.argument.path=Path to the file/url of the configuration to load.
+command.argument.path.token=FILE
 
 command.manual=\
-  TODO: logger manual
\ No newline at end of file
+  TODO: configure manual
\ No newline at end of file

Propchange: geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/resources/org/apache/geronimo/gshell/commands/log4j/ConfigureAction.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/resources/org/apache/geronimo/gshell/commands/log4j/ConfigureAction.properties
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/resources/org/apache/geronimo/gshell/commands/log4j/ConfigureAction.properties
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: geronimo/gshell/trunk/gshell-commands/gshell-log4j/src/main/resources/org/apache/geronimo/gshell/commands/log4j/ConfigureAction.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message