geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r572529 - in /geronimo/sandbox/gshell/trunk: gshell-api/src/main/java/org/apache/geronimo/gshell/ gshell-bootstrap/src/main/java/org/apache/geronimo/gshell/bootstrap/ gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/ gshell-cli/src/m...
Date Tue, 04 Sep 2007 05:35:40 GMT
Author: jdillon
Date: Mon Sep  3 22:35:38 2007
New Revision: 572529

URL: http://svn.apache.org/viewvc?rev=572529&view=rev
Log:
(GSHELL-32) Hooking up an adapter to bridge plexus logging into slf4j
Introduce the Environment interface which will hold the basic execution state

Added:
    geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/Environment.java
  (with props)
    geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/PlexusLoggingAdapter.java
  (with props)
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/EnvironmentImpl.java
  (with props)
Modified:
    geronimo/sandbox/gshell/trunk/gshell-bootstrap/src/main/java/org/apache/geronimo/gshell/bootstrap/Launcher.java
    geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
    geronimo/sandbox/gshell/trunk/gshell-cli/src/main/resources/META-INF/plexus/plexus.xml
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/resources/META-INF/plexus/components.xml
    geronimo/sandbox/gshell/trunk/gshell-layout/src/main/java/org/apache/geronimo/gshell/layout/LayoutManagerImpl.java
    geronimo/sandbox/gshell/trunk/gshell-layout/src/main/resources/META-INF/plexus/components.xml

Added: geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/Environment.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/Environment.java?rev=572529&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/Environment.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/Environment.java
Mon Sep  3 22:35:38 2007
@@ -0,0 +1,32 @@
+/*
+ * 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;
+
+import java.io.File;
+
+/**
+ * Provides a general abstraction of the shell's current executing environment.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Environment
+{
+    File getHomeDir();
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/Environment.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/Environment.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/Environment.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-bootstrap/src/main/java/org/apache/geronimo/gshell/bootstrap/Launcher.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-bootstrap/src/main/java/org/apache/geronimo/gshell/bootstrap/Launcher.java?rev=572529&r1=572528&r2=572529&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-bootstrap/src/main/java/org/apache/geronimo/gshell/bootstrap/Launcher.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-bootstrap/src/main/java/org/apache/geronimo/gshell/bootstrap/Launcher.java
Mon Sep  3 22:35:38 2007
@@ -38,6 +38,11 @@
     public static void main(final String[] args) throws Exception {
         assert args != null;
 
+        //
+        // FIXME: Maybe want to add some kinda of support to allow these "gshell.*" bits
to be named
+        //        for custom branding?
+        //
+        
         programName = getProgramName();
         setProperty("program.name", programName);
 

Modified: geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java?rev=572529&r1=572528&r2=572529&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
Mon Sep  3 22:35:38 2007
@@ -33,13 +33,12 @@
 import org.apache.geronimo.gshell.common.StopWatch;
 import org.apache.geronimo.gshell.console.Console;
 import org.apache.geronimo.gshell.console.IO;
-import org.apache.geronimo.gshell.cli.Banner;
-import org.apache.geronimo.gshell.cli.Version;
 import org.codehaus.plexus.ContainerConfiguration;
 import org.codehaus.plexus.DefaultContainerConfiguration;
 import org.codehaus.plexus.DefaultPlexusContainer;
 import org.codehaus.plexus.PlexusContainer;
 import org.codehaus.plexus.classworlds.ClassWorld;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -191,6 +190,8 @@
         config.setClassWorld(classWorld);
 
         PlexusContainer container = new DefaultPlexusContainer(config);
+
+        System.err.println("Logger manager: " + container.getLoggerManager());
 
         //
         // TODO: We need to pass in our I/O context to the container directly

Added: geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/PlexusLoggingAdapter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/PlexusLoggingAdapter.java?rev=572529&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/PlexusLoggingAdapter.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/PlexusLoggingAdapter.java
Mon Sep  3 22:35:38 2007
@@ -0,0 +1,90 @@
+/*
+ * 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.cli;
+
+import org.codehaus.plexus.logging.AbstractLogger;
+import org.codehaus.plexus.logging.BaseLoggerManager;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+//
+// TODO: Move me some place more approrpiate?
+//
+
+/**
+ * Adapts the Plexus logging system to GShell.
+ *
+ * @version $Rev$ $Date$
+ */
+public class PlexusLoggingAdapter
+{
+    /**
+     * Adapts the Plexus {@link org.codehaus.plexus.logging.LoggerManager} interface to the
GShell interface.
+     */
+    public static class LoggerManagerImpl
+        extends BaseLoggerManager
+    {
+        protected org.codehaus.plexus.logging.Logger createLogger(final String key) {
+            return new LoggerImpl(getThreshold(), LoggerFactory.getLogger(key));
+        }
+    }
+    
+    /**
+     * Adapts the Plexus {@link org.codehaus.plexus.logging.Logger} interface to the GShell
interface.
+     */
+    public static class LoggerImpl
+        extends AbstractLogger
+    {
+        private final Logger log;
+
+        public LoggerImpl(final int threshold, final Logger logger) {
+            super(threshold, logger.getName());
+
+            this.log = logger;
+        }
+
+        public void debug(final String message, final Throwable throwable) {
+            log.debug( message, throwable );
+        }
+
+        public void error(final String message, final Throwable throwable) {
+            log.error(message, throwable);
+        }
+
+        public void fatalError(final String message, final Throwable throwable) {
+            log.error(message, throwable);
+        }
+
+        public org.codehaus.plexus.logging.Logger getChildLogger(final String name) {
+            String childName = log.getName() + "." + name;
+
+            return new LoggerImpl(getThreshold(), LoggerFactory.getLogger(childName));
+        }
+
+        public void info(String message, final Throwable throwable) {
+            log.info(message, throwable);
+        }
+
+        public void warn(String message, final Throwable throwable) {
+            log.warn(message, throwable);
+        }
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/PlexusLoggingAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/PlexusLoggingAdapter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/PlexusLoggingAdapter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-cli/src/main/resources/META-INF/plexus/plexus.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-cli/src/main/resources/META-INF/plexus/plexus.xml?rev=572529&r1=572528&r2=572529&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-cli/src/main/resources/META-INF/plexus/plexus.xml
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-cli/src/main/resources/META-INF/plexus/plexus.xml
Mon Sep  3 22:35:38 2007
@@ -35,6 +35,16 @@
 
     <components>
         <component>
+            <role>org.codehaus.plexus.logging.LoggerManager</role>
+            <implementation>org.apache.geronimo.gshell.cli.PlexusLoggingAdapter$LoggerManagerImpl</implementation>
+        </component>
+
+        <component>
+            <role>org.apache.geronimo.gshell.GShellPluginCollector</role>
+            <implementation>org.apache.geronimo.gshell.GShellPluginCollector</implementation>
+        </component>
+
+        <component>
             <role>org.apache.geronimo.gshell.GShellPluginCollector</role>
             <implementation>org.apache.geronimo.gshell.GShellPluginCollector</implementation>
         </component>

Added: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/EnvironmentImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/EnvironmentImpl.java?rev=572529&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/EnvironmentImpl.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/EnvironmentImpl.java
Mon Sep  3 22:35:38 2007
@@ -0,0 +1,92 @@
+/*
+ * 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;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The default/standard/whatever implementation of {@link Environment}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class EnvironmentImpl
+    implements Environment, Initializable
+{
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private File homeDir;
+
+    public File getHomeDir() {
+        if (homeDir == null) {
+            throw new IllegalStateException();
+        }
+
+        return homeDir;
+    }
+
+    public void initialize() throws InitializationException {
+        homeDir = detectHomeDir();
+        log.debug("Using home directory: {}", homeDir);
+    }
+    
+    private File detectHomeDir() throws InitializationException {
+        // For right now we require that a "gshell.home" property be set, which should have
been set by the Bootstrapper.
+        // Will eventually allow this to be changed for shell branding mucko
+
+        String homePath = System.getProperty("gshell.home");
+
+        if (homePath == null) {
+            throw new InitializationException("The 'gsell.home' property must be set for
the shell to function correctly");
+        }
+
+        // And now lets resolve this sucker
+        File dir;
+        try {
+            dir = new File(homePath).getCanonicalFile();
+        }
+        catch (IOException e) {
+            throw new InitializationException("Failed to resolve home directory: " + homePath,
e);
+        }
+
+        // And some basic sanity too
+        if (!dir.exists() || !dir.isDirectory()) {
+            throw new InitializationException("Home directory configured but is not a valid
directory: " + dir);
+        }
+
+        return dir;
+    }
+
+    //
+    // TODO: Merge in the other command-context and variable access muck here.  The Environment
for the shell should be the one place
+    //       were all state is stored, so we can use this to multiplex shells and provide
commands with a simple/single interface
+    //       for interacting with the user.
+    //
+    //       IO
+    //       Variables
+    //       Shell information
+    //       Current command descriptor
+    //
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/EnvironmentImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/EnvironmentImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/EnvironmentImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/resources/META-INF/plexus/components.xml?rev=572529&r1=572528&r2=572529&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/resources/META-INF/plexus/components.xml
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/resources/META-INF/plexus/components.xml
Mon Sep  3 22:35:38 2007
@@ -115,5 +115,16 @@
             <instantiation-strategy>singleton</instantiation-strategy>
             <lifecycle-handler>plexus</lifecycle-handler>
         </component>
+
+        <!--
+        FIXME: Probably need to use a component factory and a thread-local here to properly
keep track of the shell's environment
+        -->
+        <component>
+            <role>org.apache.geronimo.gshell.Environment</role>
+            <role-hint>default</role-hint>
+            <implementation>org.apache.geronimo.gshell.EnvironmentImpl</implementation>
+            <instantiation-strategy>singleton</instantiation-strategy>
+            <lifecycle-handler>plexus</lifecycle-handler>
+        </component>
     </components>
 </component-set>

Modified: geronimo/sandbox/gshell/trunk/gshell-layout/src/main/java/org/apache/geronimo/gshell/layout/LayoutManagerImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-layout/src/main/java/org/apache/geronimo/gshell/layout/LayoutManagerImpl.java?rev=572529&r1=572528&r2=572529&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-layout/src/main/java/org/apache/geronimo/gshell/layout/LayoutManagerImpl.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-layout/src/main/java/org/apache/geronimo/gshell/layout/LayoutManagerImpl.java
Mon Sep  3 22:35:38 2007
@@ -28,10 +28,11 @@
 import com.thoughtworks.xstream.XStream;
 import com.thoughtworks.xstream.annotations.Annotations;
 import com.thoughtworks.xstream.io.xml.DomDriver;
+import org.apache.geronimo.gshell.Environment;
 import org.apache.geronimo.gshell.layout.model.Alias;
 import org.apache.geronimo.gshell.layout.model.Command;
 import org.apache.geronimo.gshell.layout.model.Layout;
-import org.codehaus.plexus.PlexusContainer;
+
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
 import org.slf4j.Logger;
@@ -47,26 +48,18 @@
     implements LayoutManager, Initializable
 {
     private final Logger log = LoggerFactory.getLogger(getClass());
-
+    
     // @Requirement
-    private PlexusContainer container;
+    private Environment env;
 
     private Layout layout;
     
     public void initialize() throws InitializationException {
-        //
-        // HACK: For now just hard code it... Really need to expose a helper object to find
the Shell's basic directory config muck
-        //
-
-        String homePath = System.getProperty("gshell.home");
-        if (homePath == null) {
-            throw new InitializationException("The 'gsell.home' property must be set for
the shell to function correctly");
-        }
+        assert env != null;
 
-        File homeDir = new File(homePath);
         URL url = null;
         try {
-            url = new File(homeDir, "etc/layout.xml").toURI().toURL();
+            url = new File(env.getHomeDir(), "etc/layout.xml").toURI().toURL();
         } catch (MalformedURLException e) {
             throw new InitializationException("Invalid URL for layout configuration", e);
         }

Modified: geronimo/sandbox/gshell/trunk/gshell-layout/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-layout/src/main/resources/META-INF/plexus/components.xml?rev=572529&r1=572528&r2=572529&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-layout/src/main/resources/META-INF/plexus/components.xml
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-layout/src/main/resources/META-INF/plexus/components.xml
Mon Sep  3 22:35:38 2007
@@ -30,8 +30,8 @@
             <lifecycle-handler>plexus</lifecycle-handler>
             <requirements>
                 <requirement>
-                    <role>org.codehaus.plexus.PlexusContainer</role>
-                    <field-name>container</field-name>
+                    <role>org.apache.geronimo.gshell.Environment</role>
+                    <field-name>env</field-name>
                 </requirement>
             </requirements>
         </component>



Mime
View raw message