geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r573926 - in /geronimo/sandbox/gshell/trunk: gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/ gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/descriptor/ gshell-command-api/src/test/java/org/apache/geronimo/gshel...
Date Sat, 08 Sep 2007 23:00:28 GMT
Author: jdillon
Date: Sat Sep  8 16:00:27 2007
New Revision: 573926

URL: http://svn.apache.org/viewvc?rev=573926&view=rev
Log:
Hook back up the gshell-maven-plugin to generate the commands.xml descriptor

Added:
    geronimo/sandbox/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/descriptor/CommandSetDescriptorWriter.java
  (with props)
    geronimo/sandbox/gshell/trunk/gshell-command-api/src/test/java/org/apache/geronimo/gshell/command/descriptor/
    geronimo/sandbox/gshell/trunk/gshell-command-api/src/test/java/org/apache/geronimo/gshell/command/descriptor/CommandSetDescriptorWriterTest.java
      - copied, changed from r573906, geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/layout/model/BasicModelValidationTest.java
    geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandSetDescriptorMojo.java
  (contents, props changed)
      - copied, changed from r573906, geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/PluginDescriptorMojo.java
Removed:
    geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/gshell/
    geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/PluginDescriptorMojo.java
Modified:
    geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
    geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/pom.xml
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/Slf4jLoggingManager.java
    geronimo/sandbox/gshell/trunk/gshell-maven-plugin/pom.xml

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=573926&r1=573925&r2=573926&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
Sat Sep  8 16:00:27 2007
@@ -21,7 +21,6 @@
 
 import java.util.ArrayList;
 import java.util.List;
-import java.io.IOException;
 
 import jline.Terminal;
 import org.apache.geronimo.gshell.ExitNotification;

Added: geronimo/sandbox/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/descriptor/CommandSetDescriptorWriter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/descriptor/CommandSetDescriptorWriter.java?rev=573926&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/descriptor/CommandSetDescriptorWriter.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/descriptor/CommandSetDescriptorWriter.java
Sat Sep  8 16:00:27 2007
@@ -0,0 +1,159 @@
+/*
+ * 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.command.descriptor;
+
+import java.io.Writer;
+import java.util.List;
+
+import org.codehaus.plexus.component.repository.ComponentRequirement;
+import org.codehaus.plexus.component.repository.ComponentRequirementList;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+import org.codehaus.plexus.configuration.PlexusConfigurationException;
+import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
+import org.codehaus.plexus.util.xml.XMLWriter;
+
+/**
+ * Writes out a {@link CommandSetDescriptor} as XML.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CommandSetDescriptorWriter
+{
+    private static final String LS = System.getProperty("line.separator");
+
+    public void write(final Writer writer, final CommandSetDescriptor desc) throws Exception
{
+        try {
+            XMLWriter w = new PrettyPrintXMLWriter(writer);
+
+            w.startElement("command-set");
+            
+            writeCommands(w, desc.getCommandDescriptors());
+
+            w.endElement();
+
+            writer.write(LS);
+
+            writer.close();
+        }
+        catch (PlexusConfigurationException e) {
+            throw new Exception("Internal error while writing out the configuration", e);
+        }
+    }
+
+    private void writeCommands(final XMLWriter w, final List<CommandDescriptor> descs)
throws Exception {
+        if (descs == null) {
+            return;
+        }
+
+        w.startElement("commands");
+
+        for (CommandDescriptor descriptor : descs) {
+            w.startElement("command");
+
+            element(w, "id", descriptor.getId());
+            element(w, "implementation", descriptor.getImplementation());
+            element(w, "version", descriptor.getVersion());
+            element(w, "description", descriptor.getDescription());
+
+            writeRequirements(w, descriptor.getRequirements());
+
+            writeConfiguration(w, descriptor.getConfiguration());
+
+            w.endElement();
+        }
+
+        w.endElement();
+    }
+
+    private void writeRequirements(final XMLWriter w, final List<ComponentRequirement>
requirements) {
+        if (requirements == null || requirements.size() == 0) {
+            return;
+        }
+
+        w.startElement("requirements");
+
+        for (ComponentRequirement requirement : requirements) {
+            w.startElement("requirement");
+
+            element(w, "role", requirement.getRole());
+            element(w, "role-hint", requirement.getRoleHint());
+            element(w, "field-name", requirement.getFieldName());
+
+            w.endElement();
+        }
+
+        w.endElement();
+    }
+
+    private void writeConfiguration(final XMLWriter w, final PlexusConfiguration configuration)
throws Exception {
+        if (configuration == null || configuration.getChildCount() == 0) {
+            return;
+        }
+
+        if (!configuration.getName().equals("configuration")) {
+            throw new Exception("The root node of the configuration must be 'configuration'.");
+        }
+
+        writePlexusConfiguration(w, configuration);
+    }
+
+    private void writePlexusConfiguration(final XMLWriter xmlWriter, final PlexusConfiguration
c) throws Exception {
+        if (c.getAttributeNames().length == 0 && c.getChildCount() == 0 &&
c.getValue() == null) {
+            return;
+        }
+
+        xmlWriter.startElement(c.getName());
+
+        // Attributes
+        for (String name : c.getAttributeNames()) {
+            xmlWriter.addAttribute(name, c.getAttribute(name));
+        }
+
+        // Children
+        PlexusConfiguration[] children = c.getChildren();
+
+        if (children.length > 0) {
+            for (PlexusConfiguration child : children) {
+                writePlexusConfiguration(xmlWriter, child);
+            }
+        }
+        else {
+            String value = c.getValue();
+
+            if (value != null) {
+                xmlWriter.writeText(value);
+            }
+        }
+
+        xmlWriter.endElement();
+    }
+
+    private void element(final XMLWriter w, final String name, final String value) {
+        if (value == null) {
+            return;
+        }
+
+        w.startElement(name);
+
+        w.writeText(value);
+
+        w.endElement();
+    }
+}
\ No newline at end of file

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

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

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

Copied: geronimo/sandbox/gshell/trunk/gshell-command-api/src/test/java/org/apache/geronimo/gshell/command/descriptor/CommandSetDescriptorWriterTest.java
(from r573906, geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/layout/model/BasicModelValidationTest.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-command-api/src/test/java/org/apache/geronimo/gshell/command/descriptor/CommandSetDescriptorWriterTest.java?p2=geronimo/sandbox/gshell/trunk/gshell-command-api/src/test/java/org/apache/geronimo/gshell/command/descriptor/CommandSetDescriptorWriterTest.java&p1=geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/layout/model/BasicModelValidationTest.java&r1=573906&r2=573926&rev=573926&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/layout/model/BasicModelValidationTest.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-command-api/src/test/java/org/apache/geronimo/gshell/command/descriptor/CommandSetDescriptorWriterTest.java
Sat Sep  8 16:00:27 2007
@@ -17,45 +17,31 @@
  * under the License.
  */
 
-package org.apache.geronimo.gshell.layout.model;
+package org.apache.geronimo.gshell.command.descriptor;
+
+import java.io.StringWriter;
 
-import com.thoughtworks.xstream.XStream;
-import com.thoughtworks.xstream.annotations.Annotations;
-import com.thoughtworks.xstream.io.xml.DomDriver;
 import junit.framework.TestCase;
 
 /**
- * Basic validation of the layout model muck.
+ * Tests for the {@link CommandSetDescriptorWriter} class.
  *
  * @version $Rev$ $Date$
  */
-public class BasicModelValidationTest
+public class CommandSetDescriptorWriterTest
     extends TestCase
 {
-    public void testReadLayout1() throws Exception {
-        Layout layout = Layout.fromXML(getClass().getResourceAsStream("layout1.xml"));
-        assertNotNull(layout);
-    }
+    public void testEmpty() throws Exception {
+        CommandSetDescriptorWriter writer = new CommandSetDescriptorWriter();
+        CommandSetDescriptor desc = new CommandSetDescriptor();
 
-    public void testReadLayout2() throws Exception {
-        Layout layout = Layout.fromXML(getClass().getResourceAsStream("layout2.xml"));
-        assertNotNull(layout);
-    }
-    
-    public void testDumpLayout1() throws Exception {
-        Layout layout = new Layout("/");
-        
-        layout.nodes().add(new CommandNode("foo", "bar"));
-        layout.nodes().add(new AliasNode("f", "foo"));
-
-        GroupNode g = new GroupNode("test");
-        g.nodes().add(new CommandNode("a", "b"));
-        g.nodes().add(new CommandNode("c", "d"));
-
-        layout.nodes().add(g);
-        
-        String xml = Layout.toXML(layout);
+        StringWriter w = new StringWriter();
+        writer.write(w, desc);
+
+        String have = w.getBuffer().toString();
+
+        String expect = "<command-set/>\n";
 
-        System.err.println("XML: " + xml);
+        assertEquals(expect, have);
     }
-}
+}
\ No newline at end of file

Modified: geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/pom.xml?rev=573926&r1=573925&r2=573926&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/pom.xml (original)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/pom.xml Sat Sep  8 16:00:27
2007
@@ -50,8 +50,7 @@
             <version>${pom.version}</version>
         </dependency>
     </dependencies>
-    
-    <!--
+
     <build>
         <plugins>
             <plugin>
@@ -61,13 +60,12 @@
                 <executions>
                     <execution>
                         <goals>
-                            <goal>plugin-descriptor</goal>
+                            <goal>commands-descriptor</goal>
                         </goals>
                     </execution>
                 </executions>
             </plugin>
         </plugins>
     </build>
-    -->
 
 </project>

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/Slf4jLoggingManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/Slf4jLoggingManager.java?rev=573926&r1=573925&r2=573926&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/Slf4jLoggingManager.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/Slf4jLoggingManager.java
Sat Sep  8 16:00:27 2007
@@ -31,7 +31,6 @@
  *
  * @version $Rev$ $Date$
  */
-@Component(role=LoggerManager.class, hint="slf4j")
 public class Slf4jLoggingManager
     extends BaseLoggerManager
 {

Modified: geronimo/sandbox/gshell/trunk/gshell-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-maven-plugin/pom.xml?rev=573926&r1=573925&r2=573926&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-maven-plugin/pom.xml (original)
+++ geronimo/sandbox/gshell/trunk/gshell-maven-plugin/pom.xml Sat Sep  8 16:00:27 2007
@@ -62,20 +62,19 @@
         </dependency>
 
         <dependency>
-            <groupId>org.apache.xbean</groupId>
-            <artifactId>xbean-finder</artifactId>
-            <version>3.1</version>
-        </dependency>
-        
-        <dependency>
             <groupId>org.codehaus.plexus</groupId>
-            <artifactId>plexus-cdc</artifactId>
-            <version>1.0-alpha-11-SNAPSHOT</version>
+            <artifactId>plexus-component-api</artifactId>
         </dependency>
         
         <dependency>
             <groupId>org.codehaus.plexus</groupId>
             <artifactId>plexus-component-annotations</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.xbean</groupId>
+            <artifactId>xbean-finder</artifactId>
+            <version>3.1</version>
         </dependency>
         
         <dependency>

Copied: geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandSetDescriptorMojo.java
(from r573906, geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/PluginDescriptorMojo.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandSetDescriptorMojo.java?p2=geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandSetDescriptorMojo.java&p1=geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/PluginDescriptorMojo.java&r1=573906&r2=573926&rev=573926&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/PluginDescriptorMojo.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandSetDescriptorMojo.java
Sat Sep  8 16:00:27 2007
@@ -19,36 +19,41 @@
 
 package org.apache.geronimo.gshell.maven.gshell;
 
+import java.io.BufferedWriter;
 import java.io.File;
-import java.io.IOException;
 import java.io.FileWriter;
-import java.io.BufferedWriter;
 import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.geronimo.gshell.command.annotation.CommandComponent;
+import org.apache.geronimo.gshell.command.descriptor.CommandDescriptor;
+import org.apache.geronimo.gshell.command.descriptor.CommandSetDescriptor;
+import org.apache.geronimo.gshell.command.descriptor.CommandSetDescriptorWriter;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
-
 import org.apache.xbean.finder.ClassFinder;
-
+import org.codehaus.plexus.component.annotations.Configuration;
 import org.codehaus.plexus.component.annotations.Requirement;
+import org.codehaus.plexus.component.repository.ComponentRequirement;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
 import org.codehaus.plexus.util.DirectoryScanner;
 
 /**
- * Generates a GShell XML plugin descriptor.
+ * Generates a GShell XML commands descriptor.
  *
- * @goal plugin-descriptor
+ * @goal commands-descriptor
  * @phase process-classes
  * @requiresDependencyResolution runtime
  *
  * @version $Rev$ $Date$
  */
-public class PluginDescriptorMojo
+public class CommandSetDescriptorMojo
     extends AbstractMojo
 {
     /**
@@ -76,7 +81,7 @@
     /**
      * The filename of the descriptor.
      *
-     * @parameter expression="META-INF/gshell/plugin.xml"
+     * @parameter expression="META-INF/gshell/commands.xml"
      * @required
      */
     private String fileName;
@@ -87,7 +92,7 @@
      * @required
      */
     private MavenProject project;
-
+    
     //
     // Mojo
     //
@@ -105,116 +110,155 @@
             }
         }
 
-        /*
+        getLog().debug("Classpath:");
         for (Object obj : list) {
-            System.err.println("    " + obj);
+            getLog().debug("    " + obj);
         }
-        */
 
-        return (URL[])list.toArray(new URL[list.size()]);
+        return list.toArray(new URL[list.size()]);
     }
 
-    public void execute() throws MojoExecutionException {
-        //
-        // FIXME: This is one huge hack after another...
-        //
-
+    private List<Class> loadClasses(final ClassLoader cl) throws MojoExecutionException
{
         DirectoryScanner scanner = new DirectoryScanner();
         scanner.setBasedir(classesDirectory);
-        scanner.setIncludes(new String[]{"**/*.class"});
+        scanner.setIncludes(new String[]{ "**/*.class" });
         scanner.scan();
 
-        /*
-        //
-        // FIXME: Probably better to use QDox instead of this crapo...
-        //
-
-        URL[] classpath = getClasspath();
-        ClassLoader parent = getClass().getClassLoader();
-        ClassLoader cl = new URLClassLoader(classpath, parent);
-        
-        List<Class> localClasses = new ArrayList<Class>();
+        List<Class> classes = new ArrayList<Class>();
 
         for (String file : scanner.getIncludedFiles()) {
-            String className = file.substring( 0, file.lastIndexOf( ".class" ) ).replace(
'\\', '.' ).replace( '/', '.' );
+            String className = file.substring(0, file.lastIndexOf(".class")).replace('\\',
'.').replace('/', '.');
             Class<?> c;
 
             try {
                 c = cl.loadClass(className);
             }
             catch (ClassNotFoundException e) {
-                throw new MojoExecutionException("Error scanning class " + className, e);
+                throw new MojoExecutionException("Failed to load class: " + className, e);
             }
 
-            localClasses.add(c);
+            classes.add(c);
         }
 
-        List<Class> commands = new ClassFinder(localClasses).findAnnotatedClasses(CommandComponent.class);
+        return classes;
+    }
 
-        Plugin plugin = new Plugin();
-        plugin.setName(project.getArtifactId());
+    private List<Class> getClasses(Class<?> type) {
+        assert type != null;
         
-        for (Class type : commands) {
-            CommandComponent meta = (CommandComponent)type.getAnnotation(CommandComponent.class);
+        List<Class> classes = new ArrayList<Class>();
+
+        while (type != null) {
+            classes.add(type);
+            type = type.getSuperclass();
+        }
+        
+        return classes;
+    }
+
+    private CommandDescriptor createCommandDescriptor(final Class<?> type) {
+        getLog().debug("Processing command: " + type);
+
+        CommandDescriptor desc = new CommandDescriptor();
+
+        CommandComponent anno = type.getAnnotation(CommandComponent.class);
 
-            Command c = new Command();
+        desc.setId(anno.id());
+        desc.setDescription(anno.description());
+        desc.setImplementation(type.getName());
 
-            c.setName(meta.name());
-            c.setDescription(meta.description());
-            c.setImplementation(type.getName());
-
-            // Have to look at each class in the tree to look at its declared fields
-            List<Class> classes = new ArrayList<Class>();
-            while (type != null) {
-                classes.add(type);
-                type = type.getSuperclass();
-            }
-            
-            for (Class t : classes) {
-                for (Field f : t.getDeclaredFields()) {
-                    Requirement requirement = f.getAnnotation(Requirement.class);
-
-                    if (requirement != null) {
-                        org.apache.geronimo.gshell.plugin.model.Requirement r = new org.apache.geronimo.gshell.plugin.model.Requirement();
-
-                        if (requirement.role().isAssignableFrom(Object.class)) {
-                            r.setRole(f.getType().getName());
-                        }
-                        else {
-                            r.setRole(requirement.role().getName());
-                        }
-
-                        r.setRoleHint(requirement.hint());
-                        r.setFieldName(f.getName());
-                        // req.setFieldMappingType(f.getType().getName());
+        // Have to look at each class in the tree to look at its declared fields
+        List<Class> classes = getClasses(type);
 
-                        c.addRequirement(r);
+        for (Class t : classes) {
+            for (Field f : t.getDeclaredFields()) {
+                Requirement requirementAnno = f.getAnnotation(Requirement.class);
+
+                if (requirementAnno != null) {
+                    ComponentRequirement requirement = new ComponentRequirement();
+
+                    if (requirementAnno.role().isAssignableFrom(Object.class)) {
+                        requirement.setRole(f.getType().getName());
+                    }
+                    else {
+                        requirement.setRole(requirementAnno.role().getName());
                     }
+
+                    requirement.setRoleHint(requirementAnno.hint());
+                    requirement.setFieldName(f.getName());
+                    requirement.setFieldMappingType(f.getType().getName());
+
+                    getLog().debug("Found requirement: " + requirement);
+                    
+                    desc.addRequirement(requirement);
                 }
-            }
 
-            //
-            // TODO: Configuration?
-            //
+                Configuration configAnno = f.getAnnotation(Configuration.class);
 
-            plugin.addCommand(c);
-        }
+                if (configAnno != null) {
+                    PlexusConfiguration config = null; // new PlexusConfiguration();
 
-        File outputFile = new File(outputDirectory, fileName);
-        if (!outputFile.getParentFile().exists() && !outputFile.getParentFile().mkdirs())
{
-            throw new MojoExecutionException("Cannot create directory: " + outputFile.getParent());
+                    //
+                    // TODO: Convert the annoation to a PlexusConfiguration
+                    //
+
+                    getLog().debug("Found configuration: " + config);
+
+                    desc.setConfiguration(config);
+                }
+            }
         }
-        
-        try {
-            BufferedWriter output = new BufferedWriter(new FileWriter(outputFile));
-            PluginXpp3Writer writer = new PluginXpp3Writer();
-            
-            writer.write(output, plugin);
-            output.close();
+
+        return desc;
+    }
+
+    public void execute() throws MojoExecutionException {
+        getLog().debug("Attempting to discover comamnds...");
+
+        ClassLoader cl = new URLClassLoader(getClasspath(), getClass().getClassLoader());
+
+        List<Class> classes = loadClasses(cl);
+
+        List<Class> commands = new ClassFinder(classes).findAnnotatedClasses(CommandComponent.class);
+
+        // Stip off any commands which aren't public or are abstract
+        for (Class type : commands) {
+            int mod = type.getModifiers();
+
+            if (!Modifier.isPublic(mod) || Modifier.isAbstract(mod)) {
+                commands.remove(type);
+            }
         }
-        catch (IOException e) {
-            throw new MojoExecutionException("Failed to write plugin descriptor", e);
+
+        if (commands.size() > 0) {
+            getLog().info("Discovered " + commands.size() + " command type(s)");
+
+            CommandSetDescriptor setDesc = new CommandSetDescriptor();
+
+            for (Class type : commands) {
+                CommandDescriptor commandDesc = createCommandDescriptor(type);
+                setDesc.addCommandDescriptor(commandDesc);
+            }
+
+            File outputFile = new File(outputDirectory, fileName);
+            if (!outputFile.getParentFile().exists() && !outputFile.getParentFile().mkdirs())
{
+                throw new MojoExecutionException("Cannot create directory: " + outputFile.getParent());
+            }
+
+            // Write the file
+
+            try {
+                BufferedWriter output = new BufferedWriter(new FileWriter(outputFile));
+                CommandSetDescriptorWriter writer = new CommandSetDescriptorWriter();
+
+                writer.write(output, setDesc);
+                output.close();
+
+                getLog().debug("Wrote " + outputFile);
+            }
+            catch (Exception e) {
+                throw new MojoExecutionException("Failed to write commands descriptor", e);
+            }
         }
-        */
     }
 }

Propchange: geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandSetDescriptorMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

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



Mime
View raw message