You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2007/10/05 02:08:51 UTC
svn commit: r582036 - in /geronimo/sandbox/gshell/trunk/gshell-maven-plugin:
./ src/main/java/org/apache/geronimo/gshell/maven/gshell/
Author: jdillon
Date: Thu Oct 4 17:08:50 2007
New Revision: 582036
URL: http://svn.apache.org/viewvc?rev=582036&view=rev
Log:
Re-implement the descriptor mojo
Added:
geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandDescriptorExtractor.java (with props)
geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandDescriptorGleaner.java (with props)
geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/DescriptorMojo.java (contents, props changed)
- copied, changed from r580765, geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandSetDescriptorMojo.java
Removed:
geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandSetDescriptorMojo.java
Modified:
geronimo/sandbox/gshell/trunk/gshell-maven-plugin/pom.xml
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=582036&r1=582035&r2=582036&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-maven-plugin/pom.xml (original)
+++ geronimo/sandbox/gshell/trunk/gshell-maven-plugin/pom.xml Thu Oct 4 17:08:50 2007
@@ -72,23 +72,13 @@
</dependency>
<dependency>
- <groupId>org.apache.xbean</groupId>
- <artifactId>xbean-finder</artifactId>
- <version>3.1</version>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
</dependency>
-
+
<dependency>
- <groupId>asm</groupId>
- <artifactId>asm</artifactId>
- <version>2.2.3</version>
- <scope>runtime</scope>
- </dependency>
-
- <dependency>
- <groupId>asm</groupId>
- <artifactId>asm-commons</artifactId>
- <version>2.2.3</version>
- <scope>runtime</scope>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
</dependency>
</dependencies>
Added: geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandDescriptorExtractor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandDescriptorExtractor.java?rev=582036&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandDescriptorExtractor.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandDescriptorExtractor.java Thu Oct 4 17:08:50 2007
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2007 the original author or authors.
+ *
+ * Licensed 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.maven.gshell;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.geronimo.gshell.descriptor.CommandDescriptor;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.DirectoryScanner;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Extracts {@link CommandDescriptor} instances from class files.
+ *
+ * @version $Id$
+ */
+public class CommandDescriptorExtractor
+{
+ public static enum Scope
+ {
+ COMPILE,
+ TEST;
+ }
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ private CommandDescriptorGleaner gleaner = new CommandDescriptorGleaner();
+
+ public List<CommandDescriptor> extract(final MavenProject project, final Scope scope) throws Exception {
+ assert project != null;
+ assert scope != null;
+
+ log.debug("Gleaner: {}, scope: {}", gleaner, scope);
+
+ List classpath;
+ File classesDir;
+
+ if (scope == Scope.COMPILE) {
+ classpath = project.getCompileClasspathElements();
+ classesDir = new File(project.getBuild().getOutputDirectory());
+ }
+ else if (scope == Scope.TEST) {
+ classpath = project.getTestClasspathElements();
+ classesDir = new File(project.getBuild().getTestOutputDirectory());
+ }
+ else {
+ throw new InternalError();
+ }
+
+ if (!classesDir.exists()) {
+ log.warn("Skipping descriptor generation; missing classes directory: {}", classesDir);
+
+ return Collections.emptyList();
+ }
+
+ final ClassLoader prev = Thread.currentThread().getContextClassLoader();
+ final ClassLoader cl = createClassLoader(classpath);
+
+ Thread.currentThread().setContextClassLoader(cl);
+
+ try {
+ return extract(classesDir, cl);
+ }
+ finally {
+ Thread.currentThread().setContextClassLoader(prev);
+ }
+ }
+
+ private ClassLoader createClassLoader(final List elements) throws Exception {
+ List<URL> list = new ArrayList<URL>();
+
+ // Add the projects dependencies
+ for (Object element : elements) {
+ String filename = (String) element;
+
+ try {
+ list.add(new File(filename).toURI().toURL());
+ }
+ catch (MalformedURLException e) {
+ throw new MojoExecutionException("Invalid classpath entry: " + filename, e);
+ }
+ }
+
+ URL[] urls = list.toArray(new URL[list.size()]);
+
+ log.debug("Classpath:");
+
+ for (URL url : urls) {
+ log.debug(" " + url);
+ }
+
+ return new URLClassLoader(urls, getClass().getClassLoader());
+ }
+
+ private List<CommandDescriptor> extract(final File classesDir, final ClassLoader cl) throws Exception {
+ assert classesDir != null;
+ assert cl != null;
+
+ List<CommandDescriptor> descriptors = new ArrayList<CommandDescriptor>();
+
+ DirectoryScanner scanner = new DirectoryScanner();
+ scanner.setBasedir(classesDir);
+ scanner.addDefaultExcludes();
+ scanner.setIncludes(new String[]{ "**/*.class" });
+
+ log.debug("Scanning for classes in: {}", classesDir);
+
+ scanner.scan();
+
+ for (String include : scanner.getIncludedFiles()) {
+ String className = include.substring(0, include.lastIndexOf(".class")).replace('\\', '.').replace('/', '.');
+
+ log.debug("Loading class: {}", className);
+
+ try {
+ Class type = cl.loadClass(className);
+
+ log.debug("Gleaning from: {}", type);
+
+ CommandDescriptor command = gleaner.glean(type);
+
+ if (command != null) {
+ descriptors.add(command);
+ }
+ }
+ catch (VerifyError e) {
+ log.error("Failed to load class: " + className + "; cause: " + e);
+ }
+ }
+
+ log.debug("Extracted {} descriptor(s)", descriptors.size());
+
+ return descriptors;
+ }
+}
\ No newline at end of file
Propchange: geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandDescriptorExtractor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandDescriptorExtractor.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/CommandDescriptorExtractor.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandDescriptorGleaner.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandDescriptorGleaner.java?rev=582036&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandDescriptorGleaner.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandDescriptorGleaner.java Thu Oct 4 17:08:50 2007
@@ -0,0 +1,220 @@
+/*
+ * Copyright (C) 2007 the original author or authors.
+ *
+ * Licensed 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.maven.gshell;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.geronimo.gshell.command.annotation.CommandComponent;
+import org.apache.geronimo.gshell.command.annotation.Configuration;
+import org.apache.geronimo.gshell.command.annotation.Requirement;
+import org.apache.geronimo.gshell.descriptor.CommandConfiguration;
+import org.apache.geronimo.gshell.descriptor.CommandDescriptor;
+import org.apache.geronimo.gshell.descriptor.CommandRequirement;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * ????
+ *
+ * @version $Id$
+ */
+public class CommandDescriptorGleaner
+{
+ private static final String EMPTY_STRING = "";
+
+ protected final Logger log = LoggerFactory.getLogger(getClass());
+
+ protected String filterEmptyAsNull(final String value) {
+ if (value == null) {
+ return null;
+ }
+ else if (EMPTY_STRING.equals(value.trim())) {
+ return null;
+ }
+ else {
+ return value;
+ }
+ }
+
+ protected boolean isRequirementListType(final Class type) {
+ assert type != null;
+
+ return Collection.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type);
+ }
+
+ protected String deHump(final String string) {
+ assert string != null;
+
+ StringBuffer buff = new StringBuffer();
+
+ for (int i = 0; i < string.length(); i++) {
+ if (i != 0 && Character.isUpperCase(string.charAt(i))) {
+ buff.append('-');
+ }
+
+ buff.append(string.charAt(i));
+ }
+
+ return buff.toString().trim().toLowerCase();
+ }
+
+ public CommandDescriptor glean(final Class clazz) throws Exception {
+ assert clazz != null;
+
+ // Cast to <?> so that we don't have to cast below
+ Class<?> type = (Class<?>)clazz;
+
+ // Skip abstract classes
+ if (Modifier.isAbstract(type.getModifiers())) {
+ return null;
+ }
+
+ CommandComponent anno = type.getAnnotation(CommandComponent.class);
+
+ if (anno == null) {
+ return null;
+ }
+
+ log.debug("Creating descriptor for: {}", type);
+
+ CommandDescriptor command = new CommandDescriptor();
+
+ //
+ // TODO: Set the source...
+ //
+
+ command.setId(anno.id());
+
+ command.setDescription(filterEmptyAsNull(anno.description()));
+
+ command.setImplementation(type.getName());
+
+ command.setVersion(filterEmptyAsNull(anno.version()));
+
+ for (Class t : getClasses(type)) {
+ for (Field field : t.getDeclaredFields()) {
+ CommandRequirement requirement = findRequirement(field);
+
+ if (requirement != null) {
+ command.addRequirement(requirement);
+ }
+
+ CommandConfiguration config = findConfiguration(field);
+
+ if (config != null) {
+ command.getConfiguration().addChild(config);
+ }
+ }
+
+ //
+ // TODO: Inspect methods?
+ //
+ }
+
+ return command;
+ }
+
+ /**
+ * Returns a list of all of the classes which the given type inherits from.
+ */
+ private List<Class> getClasses(Class<?> type) {
+ assert type != null;
+
+ List<Class> classes = new ArrayList<Class>();
+
+ while (type != null) {
+ classes.add(type);
+ type = type.getSuperclass();
+
+ //
+ // TODO: See if we need to include interfaces here too?
+ //
+ }
+
+ return classes;
+ }
+
+ private CommandRequirement findRequirement(final Field field) {
+ assert field != null;
+
+ Requirement anno = field.getAnnotation(Requirement.class);
+
+ if (anno == null) {
+ return null;
+ }
+
+ Class<?> type = field.getType();
+
+ CommandRequirement requirement = new CommandRequirement();
+
+ if (isRequirementListType(type)) {
+ requirement.setCollection(true);
+ }
+
+ requirement.setId(filterEmptyAsNull(anno.id()));
+
+ if (anno.type().isAssignableFrom(Void.class)) {
+ requirement.setType(type.getName());
+ }
+ else {
+ requirement.setType(anno.type().getName());
+ }
+
+ String name = filterEmptyAsNull(anno.name());
+
+ if (name == null) {
+ name = field.getName();
+ }
+
+ requirement.setName(name);
+
+ return requirement;
+ }
+
+ private CommandConfiguration findConfiguration(final Field field) {
+ assert field != null;
+
+ Configuration anno = field.getAnnotation(Configuration.class);
+
+ if (anno == null) {
+ return null;
+ }
+
+ String name = filterEmptyAsNull(anno.name());
+
+ if (name == null) {
+ name = field.getName();
+ }
+
+ name = deHump(name);
+
+ CommandConfiguration config = new CommandConfiguration(name);
+
+ String value = filterEmptyAsNull(anno.value());
+
+ if (value != null) {
+ config.setValue(value);
+ }
+
+ return config;
+ }
+}
\ No newline at end of file
Propchange: geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandDescriptorGleaner.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandDescriptorGleaner.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/CommandDescriptorGleaner.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/DescriptorMojo.java (from r580765, geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandSetDescriptorMojo.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/DescriptorMojo.java?p2=geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/DescriptorMojo.java&p1=geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandSetDescriptorMojo.java&r1=580765&r2=582036&rev=582036&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/CommandSetDescriptorMojo.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/DescriptorMojo.java Thu Oct 4 17:08:50 2007
@@ -22,58 +22,37 @@
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
-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.geronimo.gshell.descriptor.CommandDescriptor;
+import org.apache.geronimo.gshell.descriptor.CommandSetDescriptor;
+import org.apache.maven.artifact.handler.ArtifactHandler;
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;
+import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
+import org.apache.geronimo.gshell.maven.gshell.CommandDescriptorExtractor.Scope;
+
/**
- * Generates a GShell XML commands descriptor.
+ * Generates a GShell <tt>commands.xml</tt> descriptor.
*
- * @version $Rev$ $Date$
- * @goal commands-descriptor
+ * @goal descriptor
* @phase process-classes
* @requiresDependencyResolution runtime
+ *
+ * @version $Rev$ $Date$
*/
-public class CommandSetDescriptorMojo
- extends AbstractMojo {
- /**
- * The directory where class files have been built.
- *
- * @parameter expression="${project.build.outputDirectory}
- */
- private File classesDirectory;
-
- /**
- * The full list of compile time dependencies.
- *
- * @parameter expression="${project.compileClasspathElements}
- * @readonly
- */
- private List<String> classpathElements;
-
+public class DescriptorMojo
+ extends AbstractMojo
+{
/**
- * The location where the generated descriptor will be placed.
+ * The directory where the descriptor is written.
*
* @parameter expression="${project.build.outputDirectory}"
+ * @required
*/
private File outputDirectory;
@@ -92,175 +71,73 @@
*/
private MavenProject project;
- //
- // Mojo
- //
-
- protected URL[] getClasspath() {
- List<URL> list = new ArrayList<URL>();
-
- // Add the projects dependencies
- for (String filename : classpathElements) {
- try {
- list.add(new File(filename).toURI().toURL());
- }
- catch (MalformedURLException e) {
- throw new RuntimeException(e);
- }
- }
-
- getLog().debug("Classpath:");
- for (Object obj : list) {
- getLog().debug(" " + obj);
- }
-
- return list.toArray(new URL[list.size()]);
- }
-
- private List<Class> loadClasses(final ClassLoader cl) throws MojoExecutionException {
- DirectoryScanner scanner = new DirectoryScanner();
- scanner.setBasedir(classesDirectory);
- scanner.setIncludes(new String[]{"**/*.class"});
- scanner.scan();
-
- List<Class> classes = new ArrayList<Class>();
-
- for (String file : scanner.getIncludedFiles()) {
- String className = file.substring(0, file.lastIndexOf(".class")).replace('\\', '.').replace('/', '.');
- Class<?> c;
-
- try {
- c = cl.loadClass(className);
- }
- catch (ClassNotFoundException e) {
- throw new MojoExecutionException("Failed to load class: " + className, e);
- }
+ public void execute() throws MojoExecutionException {
+ // Only execute if the current project looks like its got Java bits in it
+ ArtifactHandler artifactHandler = project.getArtifact().getArtifactHandler();
- classes.add(c);
+ if (!"java".equals(artifactHandler.getLanguage())) {
+ getLog().debug("Not executing on non-Java project");
}
+ else {
+ File outputFile = new File(outputDirectory, fileName);
- return classes;
- }
-
- private List<Class> getClasses(Class<?> type) {
- assert type != null;
-
- List<Class> classes = new ArrayList<Class>();
-
- while (type != null) {
- classes.add(type);
- type = type.getSuperclass();
+ generateDescriptor(Scope.COMPILE, outputFile);
}
-
- return classes;
}
- private CommandDescriptor createCommandDescriptor(final Class<?> type) {
- getLog().info("Found command: " + type);
+ protected void generateDescriptor(final Scope scope, final File outputFile) throws MojoExecutionException {
+ assert scope != null;
+ assert outputFile != null;
- CommandDescriptor desc = new CommandDescriptor();
+ List<CommandDescriptor> descriptors = new ArrayList<CommandDescriptor>();
- CommandComponent anno = type.getAnnotation(CommandComponent.class);
+ CommandDescriptorExtractor extractor = new CommandDescriptorExtractor();
- desc.setId(anno.id());
- desc.setDescription(anno.description());
- desc.setImplementation(type.getName());
+ try {
+ List<CommandDescriptor> list = extractor.extract(project, scope);
- // Have to look at each class in the tree to look at its declared fields
- List<Class> classes = getClasses(type);
-
- 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);
- }
-
- Configuration configAnno = f.getAnnotation(Configuration.class);
-
- if (configAnno != null) {
- PlexusConfiguration config = null; // new PlexusConfiguration();
-
- //
- // TODO: Convert the annoation to a PlexusConfiguration
- //
-
- getLog().debug("Found configuration: " + config);
-
- desc.setConfiguration(config);
- }
+ if (list != null && !list.isEmpty()) {
+ descriptors.addAll(list);
}
}
-
- 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 (Exception e) {
+ throw new MojoExecutionException("Failed to extract descriptors", e);
}
- if (commands.size() > 0) {
- getLog().info("Discovered " + commands.size() + " command type(s)");
+ if (descriptors.size() == 0) {
+ getLog().debug("No commands found");
+ }
+ else {
+ getLog().info("Discovered " + descriptors.size() + " command descriptors(s)");
- CommandSetDescriptor setDesc = new CommandSetDescriptor();
- setDesc.setId(project.getArtifactId());
+ CommandSetDescriptor commands = new CommandSetDescriptor(project.getId()); // .getArtifactId());
+ commands.setCommands(descriptors);
- for (Class type : commands) {
- CommandDescriptor commandDesc = createCommandDescriptor(type);
- setDesc.addCommandDescriptor(commandDesc);
+ try {
+ writeDescriptor(commands, outputFile);
}
-
- File outputFile = new File(outputDirectory, fileName);
- if (!outputFile.getParentFile().exists() && !outputFile.getParentFile().mkdirs()) {
- throw new MojoExecutionException("Cannot create directory: " + outputFile.getParent());
+ catch (Exception e) {
+ throw new MojoExecutionException("Failed to write descriptor: " + outputFile, e);
}
+ }
+ }
- // Write the file
+ private void writeDescriptor(final CommandSetDescriptor commands, final File outputFile) throws Exception {
+ assert commands != null;
+ assert outputFile != null;
- BufferedWriter output = null;
- try {
- output = new BufferedWriter(new FileWriter(outputFile));
- CommandSetDescriptorWriter writer = new CommandSetDescriptorWriter();
+ FileUtils.forceMkdir(outputFile.getParentFile());
- writer.write(output, setDesc);
+ BufferedWriter output = new BufferedWriter(new FileWriter(outputFile));
- getLog().debug("Wrote " + outputFile);
- }
- catch (Exception e) {
- throw new MojoExecutionException("Failed to write commands descriptor", e);
- }
- finally {
- IOUtil.close(output);
- }
+ try {
+ CommandSetDescriptor.toXML(commands, output);
+ output.flush();
}
+ finally {
+ IOUtil.close(output);
+ }
+
+ getLog().debug("Wrote: " + outputFile);
}
}
Propchange: geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/DescriptorMojo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/gshell/trunk/gshell-maven-plugin/src/main/java/org/apache/geronimo/gshell/maven/gshell/DescriptorMojo.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/DescriptorMojo.java
------------------------------------------------------------------------------
svn:mime-type = text/plain