geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r696376 - in /geronimo/gshell/trunk: gshell-commands/gshell-builtins/src/main/resources/META-INF/spring/ gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/ gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache...
Date Wed, 17 Sep 2008 17:38:27 GMT
Author: jdillon
Date: Wed Sep 17 10:38:26 2008
New Revision: 696376

URL: http://svn.apache.org/viewvc?rev=696376&view=rev
Log:
Hacked up some activation muck for plugins, pending some refinements

Added:
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/ActivationContext.java
  (with props)
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/ActivationRule.java
  (with props)
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/ActivationTask.java
  (with props)
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/DefaultCommandBundleActivationRule.java
  (with props)
Modified:
    geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/spring/components.xml
    geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainerImpl.java
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/PluginImpl.java

Modified: geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/spring/components.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/spring/components.xml?rev=696376&r1=696375&r2=696376&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/spring/components.xml
(original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/spring/components.xml
Wed Sep 17 10:38:26 2008
@@ -40,7 +40,7 @@
         </property>
 
         <property name="messages">
-            <bean class="org.apache.geronimo.gshell.wisdom.command.CommandMessageSource"/>
+            <bean class="org.apache.geronimo.gshell.wisdom.command.CommandMessageSourceImpl"/>
         </property>
     </bean>
     -->
@@ -48,9 +48,13 @@
     <bean class="org.apache.geronimo.gshell.wisdom.plugin.PluginImpl">
         <property name="id" value="gshell-bultins"/>
 
-        <!-- Plugin MetaData -->
-
-        <!-- Activation Rules -->
+        <property name="activationRules">
+            <list>
+                <bean class="org.apache.geronimo.gshell.wisdom.plugin.activation.DefaultCommandBundleActivationRule">
+                    <property name="bundleId" value="default"/>
+                </bean>
+            </list>
+        </property>
     </bean>
 
     <bean class="org.apache.geronimo.gshell.wisdom.plugin.CommandBundle" lazy-init="true">
@@ -91,18 +95,18 @@
                 </bean>
 
                 <bean class="org.apache.geronimo.gshell.wisdom.command.CommandImpl">
-                    <property name="id" value="gshell-builtins:set"/>
+                    <property name="id" value="gshell-builtins:source"/>
 
                     <property name="action">
-                        <bean class="org.apache.geronimo.gshell.commands.builtins.SetCommand"/>
+                        <bean class="org.apache.geronimo.gshell.commands.builtins.SourceCommand"/>
                     </property>
                 </bean>
-
+                
                 <bean class="org.apache.geronimo.gshell.wisdom.command.CommandImpl">
-                    <property name="id" value="gshell-builtins:source"/>
+                    <property name="id" value="gshell-builtins:set"/>
 
                     <property name="action">
-                        <bean class="org.apache.geronimo.gshell.commands.builtins.SourceCommand"/>
+                        <bean class="org.apache.geronimo.gshell.commands.builtins.SetCommand"/>
                     </property>
                 </bean>
 

Modified: geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainerImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainerImpl.java?rev=696376&r1=696375&r2=696376&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainerImpl.java
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-spring/src/main/java/org/apache/geronimo/gshell/spring/BeanContainerImpl.java
Wed Sep 17 10:38:26 2008
@@ -85,8 +85,6 @@
         // Construct the container and add customizations
         context = new BeanContainerContext(classRealm, parent != null ? parent.context :
null);
         context.registerShutdownHook();
-
-        // TODO: Configure this in components.xml ?
         context.addBeanPostProcessor(new BeanContainerAwareProcessor(this));
 
         // Refresh to load things up

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/PluginImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/PluginImpl.java?rev=696376&r1=696375&r2=696376&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/PluginImpl.java
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/PluginImpl.java
Wed Sep 17 10:38:26 2008
@@ -24,11 +24,16 @@
 import org.apache.geronimo.gshell.command.Command;
 import org.apache.geronimo.gshell.command.CommandRegistry;
 import org.apache.geronimo.gshell.application.plugin.Plugin;
+import org.apache.geronimo.gshell.wisdom.plugin.activation.ActivationRule;
+import org.apache.geronimo.gshell.wisdom.plugin.activation.ActivationContext;
+import org.apache.geronimo.gshell.wisdom.plugin.activation.ActivationTask;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
 
 /**
  * Default implementation of {@link Plugin}.
@@ -36,22 +41,13 @@
  * @version $Rev$ $Date$
  */
 public class PluginImpl
-    implements Plugin, BeanContainerAware
+    implements Plugin
 {
     private final Logger log = LoggerFactory.getLogger(getClass());
 
-    @Autowired
-    private CommandRegistry commandRegistry;
-
-    private BeanContainer container;
-
     private String id;
 
-    public void setBeanContainer(final BeanContainer container) {
-        assert container != null;
-
-        this.container = container;
-    }
+    private List<ActivationRule> activationRules;
 
     public String getId() {
         return id;
@@ -63,27 +59,63 @@
         this.id = id;
     }
 
+    public List<ActivationRule> getActivationRules() {
+        return activationRules;
+    }
+
+    public void setActivationRules(final List<ActivationRule> activationRules) {
+        assert activationRules != null;
+
+        this.activationRules = activationRules;
+    }
+
     public void activate() {
-        log.debug("Activating");
+        if (activationRules == null) {
+            log.warn("No activation rules configured");
+            return;
+        }
 
-        //
-        // TODO: Create activate rules and execute them here.
-        //
-        
-        assert container != null;
-        Map<String, CommandBundle> bundles = container.getBeans(CommandBundle.class);
+        ActivationContext context = new ActivationContext() {
+            private List<ActivationTask> tasks = new ArrayList<ActivationTask>();
 
-        log.debug("Discovered {} command bundles", bundles.size());
+            public List<ActivationTask> getTasks() {
+                return tasks;
+            }
+
+            public void addTask(final ActivationTask task) {
+                tasks.add(task);
+            }
+        };
 
-        for (CommandBundle bundle : bundles.values()) {
-            log.debug("Processing command bundle: {}", bundle.getId());
+        log.debug("Evaluating activation rules");
 
-            if (!bundle.isEmpty()) {
-                log.debug("Discovered {} commands in bundle {}", bundle.size(), bundle.getId());
+        for (ActivationRule rule : activationRules) {
+            log.debug("Evaluating activation rule: {}", rule);
 
-                for (Command command : bundle.getCommands()) {
-                    commandRegistry.register(command);
-                }
+            try {
+                rule.evaluate(context);
+            }
+            catch (Exception e) {
+                log.warn("Failed to evaluate activation rule: " + rule, e);
+            }
+        }
+
+        List<ActivationTask> tasks = context.getTasks();
+        if (tasks.isEmpty()) {
+            log.debug("No activation tasks configured in context");
+            return;
+        }
+
+        log.debug("Executing activation tasks");
+        
+        for (ActivationTask task : tasks) {
+            log.debug("Executing activation task: {}", task);
+            
+            try {
+                task.execute();
+            }
+            catch (Exception e) {
+                log.warn("Failed to execute activation task: " + task, e);
             }
         }
     }

Added: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/ActivationContext.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/ActivationContext.java?rev=696376&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/ActivationContext.java
(added)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/ActivationContext.java
Wed Sep 17 10:38:26 2008
@@ -0,0 +1,34 @@
+/*
+ * 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.wisdom.plugin.activation;
+
+import java.util.List;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ActivationContext
+{
+    List<ActivationTask> getTasks();
+
+    void addTask(ActivationTask task);
+}
\ No newline at end of file

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/ActivationContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/ActivationContext.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/ActivationContext.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/ActivationContext.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/ActivationRule.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/ActivationRule.java?rev=696376&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/ActivationRule.java
(added)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/ActivationRule.java
Wed Sep 17 10:38:26 2008
@@ -0,0 +1,30 @@
+/*
+ * 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.wisdom.plugin.activation;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ActivationRule
+{
+    void evaluate(ActivationContext context) throws Exception;
+}
\ No newline at end of file

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/ActivationRule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/ActivationRule.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/ActivationRule.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/ActivationRule.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/ActivationTask.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/ActivationTask.java?rev=696376&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/ActivationTask.java
(added)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/ActivationTask.java
Wed Sep 17 10:38:26 2008
@@ -0,0 +1,30 @@
+/*
+ * 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.wisdom.plugin.activation;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ActivationTask
+{
+    void execute() throws Exception;
+}
\ No newline at end of file

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/ActivationTask.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/ActivationTask.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/ActivationTask.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/ActivationTask.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/DefaultCommandBundleActivationRule.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/DefaultCommandBundleActivationRule.java?rev=696376&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/DefaultCommandBundleActivationRule.java
(added)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/DefaultCommandBundleActivationRule.java
Wed Sep 17 10:38:26 2008
@@ -0,0 +1,101 @@
+/*
+ * 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.wisdom.plugin.activation;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.apache.geronimo.gshell.command.CommandRegistry;
+import org.apache.geronimo.gshell.command.Command;
+import org.apache.geronimo.gshell.spring.BeanContainer;
+import org.apache.geronimo.gshell.spring.BeanContainerAware;
+import org.apache.geronimo.gshell.wisdom.plugin.CommandBundle;
+
+import java.util.Map;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultCommandBundleActivationRule
+    implements ActivationRule, BeanContainerAware
+{
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Autowired
+    private CommandRegistry commandRegistry;
+
+    private BeanContainer container;
+
+    private String bundleId;
+
+    public void setBeanContainer(final BeanContainer container) {
+        assert container != null;
+
+        this.container = container;
+    }
+
+    public String getBundleId() {
+        return bundleId;
+    }
+
+    public void setBundleId(final String bundleId) {
+        this.bundleId = bundleId;
+    }
+
+    public void evaluate(final ActivationContext context) throws Exception {
+        assert context != null;
+
+        if (context.getTasks().isEmpty()) {
+            ActivationTask task = new ActivationTask() {
+                public void execute() throws Exception {
+                    assert container != null;
+                    Map<String, CommandBundle> bundles = container.getBeans(CommandBundle.class);
+
+                    assert bundleId != null;
+                    CommandBundle bundle = null;
+                    for (CommandBundle b : bundles.values()) {
+                        if (b.getId().equals(bundleId)) {
+                            bundle = b;
+                            break;
+                        }
+                    }
+
+                    if (bundle == null) {
+                        throw new Exception("No bundle found with id: " + bundleId);
+                    }
+
+                    log.debug("Processing command bundle: {}", bundle.getId());
+
+                    if (!bundle.isEmpty()) {
+                        log.debug("Discovered {} commands in bundle {}", bundle.size(), bundle.getId());
+
+                        for (Command command : bundle.getCommands()) {
+                            commandRegistry.register(command);
+                        }
+                    }
+                }
+            };
+
+            context.addTask(task);
+        }
+    }
+}
\ No newline at end of file

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/DefaultCommandBundleActivationRule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/DefaultCommandBundleActivationRule.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/DefaultCommandBundleActivationRule.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/activation/DefaultCommandBundleActivationRule.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message