geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r422336 - in /geronimo/xbean/branches/colossus: maven-xbean-plugin/src/main/java/org/apache/xbean/maven/ xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/ xbean-spring-v1/src/test/java/org/apache/xbean/spring/generator/ x...
Date Sun, 16 Jul 2006 01:55:59 GMT
Author: dain
Date: Sat Jul 15 18:55:59 2006
New Revision: 422336

URL: http://svn.apache.org/viewvc?rev=422336&view=rev
Log:
Added excludedClasses flag to QdoxMappingLoader and exposed it to the maven mojo and ant task.
The excludedClasses is a comma separated list of classes or packages that qdox should not
parse.

Added:
    geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/java/org/apache/xbean/spring/generator/CheeseService.java
    geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/java/org/apache/xbean/spring/generator/CheeseService.java
Modified:
    geronimo/xbean/branches/colossus/maven-xbean-plugin/src/main/java/org/apache/xbean/maven/XBeanMojo.java
    geronimo/xbean/branches/colossus/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/MappingGeneratorTask.java
    geronimo/xbean/branches/colossus/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/QdoxMappingLoader.java
    geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/java/org/apache/xbean/spring/generator/ModelTest.java
    geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/java/org/apache/xbean/spring/generator/ModelTest.java

Modified: geronimo/xbean/branches/colossus/maven-xbean-plugin/src/main/java/org/apache/xbean/maven/XBeanMojo.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/maven-xbean-plugin/src/main/java/org/apache/xbean/maven/XBeanMojo.java?rev=422336&r1=422335&r2=422336&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/maven-xbean-plugin/src/main/java/org/apache/xbean/maven/XBeanMojo.java
(original)
+++ geronimo/xbean/branches/colossus/maven-xbean-plugin/src/main/java/org/apache/xbean/maven/XBeanMojo.java
Sat Jul 15 18:55:59 2006
@@ -70,6 +70,11 @@
     private File srcDir;
     
     /**
+     * @parameter
+     */
+    private String excludedClasses;
+
+    /**
      * @parameter expression="${basedir}/target/xbean/"
      * @required
      */
@@ -84,20 +89,21 @@
      * @parameter expression="org.apache.xbean.spring.context.impl"
      */
     private String propertyEditorPaths;
-	
-    
-	public void execute() throws MojoExecutionException, MojoFailureException {
+
+
+    public void execute() throws MojoExecutionException, MojoFailureException {
         getLog().debug( " ======= XBeanMojo settings =======" );
         getLog().debug( "namespace[" + namespace + "]" );
         getLog().debug( "srcDir[" + srcDir + "]" );
         getLog().debug( "schema[" + schema + "]" );
+        getLog().debug( "excludedClasses" + Arrays.asList(excludedClasses) );
         getLog().debug( "outputDir[" + outputDir + "]" );
         getLog().debug( "propertyEditorPaths[" + propertyEditorPaths + "]" );
 
         if (schema == null) {
             schema = new File(outputDir, project.getArtifactId() + ".xsd");
         }
-        
+
         if (propertyEditorPaths != null) {
             List editorSearchPath = new LinkedList(Arrays.asList(PropertyEditorManager.getEditorSearchPath()));
             StringTokenizer paths = new StringTokenizer(propertyEditorPaths, " ,");
@@ -108,9 +114,13 @@
         ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
         Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
         try {
-        	schema.getParentFile().mkdirs();
-        	
-            MappingLoader mappingLoader = new QdoxMappingLoader(namespace, new File[] { srcDir
});
+            schema.getParentFile().mkdirs();
+
+            String[] excludedClasses = null;
+            if (this.excludedClasses != null) {
+                excludedClasses = this.excludedClasses.split(" *, *");
+            }
+            MappingLoader mappingLoader = new QdoxMappingLoader(namespace, new File[] { srcDir
}, excludedClasses);
             GeneratorPlugin[] plugins = new GeneratorPlugin[]{
                 new XmlMetadataGenerator(this, outputDir.getAbsolutePath()),
                 new DocumentationGenerator(this, schema),
@@ -131,7 +141,7 @@
                     plugin.generate(namespaceMapping);
                 }
             }
-            
+
             Resource res = new Resource();
             res.setDirectory(outputDir.toString());
             project.addResource(res);
@@ -142,7 +152,7 @@
         } finally {
             Thread.currentThread().setContextClassLoader(oldCL);
         }
-	}
+    }
 
 	public void log(String message) {
 		getLog().info(message);

Modified: geronimo/xbean/branches/colossus/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/MappingGeneratorTask.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/MappingGeneratorTask.java?rev=422336&r1=422335&r2=422336&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/MappingGeneratorTask.java
(original)
+++ geronimo/xbean/branches/colossus/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/MappingGeneratorTask.java
Sat Jul 15 18:55:59 2006
@@ -22,6 +22,7 @@
 public class MappingGeneratorTask extends MatchingTask implements LogFacade {
     private String namespace;
     private Path srcDir;
+    private String excludedClasses = null;
     private File destFile = new File("target/classes/schema.xsd");
     private String metaInfDir = "target/classes/";
     private String propertyEditorPaths = "org.apache.xbean.spring.context.impl";
@@ -87,7 +88,11 @@
         ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
         Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
         try {
-            MappingLoader mappingLoader = new QdoxMappingLoader(namespace, getFiles(srcDir));
+            String[] excludedClasses = null;
+            if (this.excludedClasses != null) {
+                excludedClasses = this.excludedClasses.split(" *, *");
+            }
+            MappingLoader mappingLoader = new QdoxMappingLoader(namespace, getFiles(srcDir),
excludedClasses);
 
             GeneratorPlugin[] plugins = new GeneratorPlugin[]{
                 new XmlMetadataGenerator(this, metaInfDir),

Modified: geronimo/xbean/branches/colossus/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/QdoxMappingLoader.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/QdoxMappingLoader.java?rev=422336&r1=422335&r2=422336&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/QdoxMappingLoader.java
(original)
+++ geronimo/xbean/branches/colossus/xbean-spring-common/src/main/java/org/apache/xbean/spring/generator/QdoxMappingLoader.java
Sat Jul 15 18:55:59 2006
@@ -27,6 +27,7 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
+import java.util.LinkedHashMap;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -59,11 +60,13 @@
     private static final Log log = LogFactory.getLog(QdoxMappingLoader.class);
     private final String defaultNamespace;
     private final File[] srcDirs;
+    private final String[] excludedClasses;
     private Type listType;
 
-    public QdoxMappingLoader(String defaultNamespace, File[] srcDirs) {
+    public QdoxMappingLoader(String defaultNamespace, File[] srcDirs, String[] excludedClasses)
{
         this.defaultNamespace = defaultNamespace;
         this.srcDirs = srcDirs;
+        this.excludedClasses = excludedClasses;
     }
 
     public String getDefaultNamespace() {
@@ -87,7 +90,11 @@
             }
             log.debug(" - " + sourceDirectory.getAbsolutePath());
 
-            builder.addSourceTree(sourceDirectory);
+            Map sourceFiles = getSourceFiles(sourceDirectory, excludedClasses);
+            for (Iterator iterator = sourceFiles.values().iterator(); iterator.hasNext();)
{
+                File file = (File) iterator.next();
+                builder.addSource(file);
+            }
         }
 
         listType = builder.getClassByName("java.util.List").asType();
@@ -462,5 +469,48 @@
         }
         buf.append(") : ").append(method.getLineNumber());
         return buf.toString();
+    }
+
+    private static Map getSourceFiles(File base, String[] excludedClasses) {
+        return listAllFileNames(base, "", excludedClasses);
+    }
+
+    private static Map listAllFileNames(File base, String prefix, String[] excludedClasses)
{
+        if (!base.canRead() || !base.isDirectory()) {
+            throw new IllegalArgumentException(base.getAbsolutePath());
+        }
+        Map map = new LinkedHashMap();
+        File[] hits = base.listFiles();
+        for (int i = 0; i < hits.length; i++) {
+            File hit = hits[i];
+            String name = prefix.equals("") ? hit.getName() : prefix + "/" + hit.getName();
+            if (hit.canRead() && !isExcluded(name, excludedClasses)) {
+                if (hit.isDirectory()) {
+                    map.putAll(listAllFileNames(hit, name, excludedClasses));
+                } else if (name.endsWith(".java")) {
+                    map.put(name, hit);
+                }
+            }
+        }
+        return map;
+    }
+
+    private static boolean isExcluded(String sourceName, String[] excludedClasses) {
+        if (excludedClasses == null) {
+            return false;
+        }
+
+        String className = sourceName;
+        if (sourceName.endsWith(".java")) {
+            className = className.substring(0, className.length() - ".java".length());
+        }
+        className = className.replace("/", ".");
+        for (int i = 0; i < excludedClasses.length; i++) {
+            String excludedClass = excludedClasses[i];
+            if (className.equals(excludedClass)) {
+                return true;
+            }
+        }
+        return false;
     }
 }

Added: geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/java/org/apache/xbean/spring/generator/CheeseService.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/java/org/apache/xbean/spring/generator/CheeseService.java?rev=422336&view=auto
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/java/org/apache/xbean/spring/generator/CheeseService.java
(added)
+++ geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/java/org/apache/xbean/spring/generator/CheeseService.java
Sat Jul 15 18:55:59 2006
@@ -0,0 +1,43 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ *  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.xbean.spring.generator;
+
+/**
+ * Cheezy goodness
+ *
+ * @org.apache.xbean.XBean element="cheese"
+ *
+ * @author Dain Sundstrom
+ * @version $Id$
+ */
+public class CheeseService {
+    private String id;
+    private String name;
+
+    public CheeseService(String id, String name) {
+        this.id = id;
+        this.name = name;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public String getName() {
+        return name;
+    }
+}

Modified: geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/java/org/apache/xbean/spring/generator/ModelTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/java/org/apache/xbean/spring/generator/ModelTest.java?rev=422336&r1=422335&r2=422336&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/java/org/apache/xbean/spring/generator/ModelTest.java
(original)
+++ geronimo/xbean/branches/colossus/xbean-spring-v1/src/test/java/org/apache/xbean/spring/generator/ModelTest.java
Sat Jul 15 18:55:59 2006
@@ -18,6 +18,7 @@
 
 import java.beans.PropertyEditorManager;
 import java.io.File;
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.LinkedList;
@@ -26,6 +27,7 @@
 import java.util.Set;
 
 import junit.framework.TestCase;
+import org.apache.xbean.spring.example.BeerService;
 
 /**
  * @author Dain Sundstrom
@@ -37,23 +39,11 @@
 
     public void testQdox() throws Exception{
         String basedir = System.getProperties().getProperty("basedir", ".");
-        QdoxMappingLoader mappingLoader = new QdoxMappingLoader(DEFAULT_NAMESPACE, new File[]
{ new File(basedir, "/src/test")});
-        Set namespaces = mappingLoader.loadNamespaces();
-        validateModel(namespaces);
-    }
-
-    private void validateModel(Set namespaces) {
-        assertFalse(namespaces.isEmpty());
+        QdoxMappingLoader mappingLoader = new QdoxMappingLoader(DEFAULT_NAMESPACE, new File[]
{ new File(basedir, "/src/test/java")}, null);
 
-        NamespaceMapping defaultNamespace = null;
-        for (Iterator iterator = namespaces.iterator(); iterator.hasNext();) {
-            NamespaceMapping namespaceMapping = (NamespaceMapping) iterator.next();
-            if (namespaceMapping.getNamespace().equals(DEFAULT_NAMESPACE)) {
-                defaultNamespace = namespaceMapping;
-                break;
-            }
-        }
+        NamespaceMapping defaultNamespace = getDefaultNamespace(mappingLoader);
         assertNotNull(defaultNamespace);
+
         ElementMapping element = defaultNamespace.getElement("pizza");
         assertNotNull(element);
         AttributeMapping attribute = element.getAttribute("myTopping");
@@ -66,13 +56,60 @@
         assertNotNull(beerId);
         AttributeMapping beerName = beer.getAttribute("name");
         assertNotNull(beerName);
-        
+
         ElementMapping recipeService = defaultNamespace.getElement("recipe-service");
         assertNotNull(recipeService);
-        
+
         Map flatCollections = recipeService.getFlatCollections();
         assertNotNull(flatCollections);
         assertEquals(1, flatCollections.size());
+    }
+
+    public void testQdoxExcludeClass() throws Exception{
+        String basedir = System.getProperties().getProperty("basedir", ".");
+        QdoxMappingLoader mappingLoader = new QdoxMappingLoader(DEFAULT_NAMESPACE,
+                new File[] { new File(basedir, "/src/test/java")},
+                new String[] { BeerService.class.getName() } );
+
+        NamespaceMapping defaultNamespace = getDefaultNamespace(mappingLoader);
+        assertNotNull(defaultNamespace);
+
+        ElementMapping element = defaultNamespace.getElement("pizza");
+        assertNotNull(element);
+        ElementMapping beer = defaultNamespace.getElement("beer");
+        assertNull(beer);
+    }
+
+    public void testQdoxExcludePackage() throws Exception{
+        String basedir = System.getProperties().getProperty("basedir", ".");
+        QdoxMappingLoader mappingLoader = new QdoxMappingLoader(DEFAULT_NAMESPACE,
+                new File[] { new File(basedir, "/src/test/java")},
+                new String[] { "org.apache.xbean.spring.example" } );
+
+        NamespaceMapping defaultNamespace = getDefaultNamespace(mappingLoader);
+        assertNotNull(defaultNamespace);
+
+        ElementMapping element = defaultNamespace.getElement("pizza");
+        assertNull(element);
+        ElementMapping beer = defaultNamespace.getElement("beer");
+        assertNull(beer);
+        ElementMapping cheese = defaultNamespace.getElement("cheese");
+        assertNotNull(cheese);
+    }
+
+    private NamespaceMapping getDefaultNamespace(QdoxMappingLoader mappingLoader) throws
IOException {
+        Set namespaces = mappingLoader.loadNamespaces();
+        assertFalse(namespaces.isEmpty());
+
+        NamespaceMapping defaultNamespace = null;
+        for (Iterator iterator = namespaces.iterator(); iterator.hasNext();) {
+            NamespaceMapping namespaceMapping = (NamespaceMapping) iterator.next();
+            if (namespaceMapping.getNamespace().equals(DEFAULT_NAMESPACE)) {
+                defaultNamespace = namespaceMapping;
+                break;
+            }
+        }
+        return defaultNamespace;
     }
 
     public void testPropertyEditor() {

Added: geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/java/org/apache/xbean/spring/generator/CheeseService.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/java/org/apache/xbean/spring/generator/CheeseService.java?rev=422336&view=auto
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/java/org/apache/xbean/spring/generator/CheeseService.java
(added)
+++ geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/java/org/apache/xbean/spring/generator/CheeseService.java
Sat Jul 15 18:55:59 2006
@@ -0,0 +1,43 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ *  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.xbean.spring.generator;
+
+/**
+ * Cheezy goodness
+ *
+ * @org.apache.xbean.XBean element="cheese"
+ *
+ * @author Dain Sundstrom
+ * @version $Id$
+ */
+public class CheeseService {
+    private String id;
+    private String name;
+
+    public CheeseService(String id, String name) {
+        this.id = id;
+        this.name = name;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public String getName() {
+        return name;
+    }
+}

Modified: geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/java/org/apache/xbean/spring/generator/ModelTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/java/org/apache/xbean/spring/generator/ModelTest.java?rev=422336&r1=422335&r2=422336&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/java/org/apache/xbean/spring/generator/ModelTest.java
(original)
+++ geronimo/xbean/branches/colossus/xbean-spring-v2/src/test/java/org/apache/xbean/spring/generator/ModelTest.java
Sat Jul 15 18:55:59 2006
@@ -18,6 +18,7 @@
 
 import java.beans.PropertyEditorManager;
 import java.io.File;
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.LinkedList;
@@ -26,6 +27,7 @@
 import java.util.Set;
 
 import junit.framework.TestCase;
+import org.apache.xbean.spring.example.BeerService;
 
 /**
  * @author Dain Sundstrom
@@ -37,23 +39,11 @@
 
     public void testQdox() throws Exception{
         String basedir = System.getProperties().getProperty("basedir", ".");
-        QdoxMappingLoader mappingLoader = new QdoxMappingLoader(DEFAULT_NAMESPACE, new File[]
{ new File(basedir, "/src/test")});
-        Set namespaces = mappingLoader.loadNamespaces();
-        validateModel(namespaces);
-    }
-
-    private void validateModel(Set namespaces) {
-        assertFalse(namespaces.isEmpty());
+        QdoxMappingLoader mappingLoader = new QdoxMappingLoader(DEFAULT_NAMESPACE, new File[]
{ new File(basedir, "/src/test/java")}, null);
 
-        NamespaceMapping defaultNamespace = null;
-        for (Iterator iterator = namespaces.iterator(); iterator.hasNext();) {
-            NamespaceMapping namespaceMapping = (NamespaceMapping) iterator.next();
-            if (namespaceMapping.getNamespace().equals(DEFAULT_NAMESPACE)) {
-                defaultNamespace = namespaceMapping;
-                break;
-            }
-        }
+        NamespaceMapping defaultNamespace = getDefaultNamespace(mappingLoader);
         assertNotNull(defaultNamespace);
+
         ElementMapping element = defaultNamespace.getElement("pizza");
         assertNotNull(element);
         AttributeMapping attribute = element.getAttribute("myTopping");
@@ -66,13 +56,60 @@
         assertNotNull(beerId);
         AttributeMapping beerName = beer.getAttribute("name");
         assertNotNull(beerName);
-        
+
         ElementMapping recipeService = defaultNamespace.getElement("recipe-service");
         assertNotNull(recipeService);
-        
+
         Map flatCollections = recipeService.getFlatCollections();
         assertNotNull(flatCollections);
         assertEquals(1, flatCollections.size());
+    }
+
+    public void testQdoxExcludeClass() throws Exception{
+        String basedir = System.getProperties().getProperty("basedir", ".");
+        QdoxMappingLoader mappingLoader = new QdoxMappingLoader(DEFAULT_NAMESPACE,
+                new File[] { new File(basedir, "/src/test/java")},
+                new String[] { BeerService.class.getName() } );
+
+        NamespaceMapping defaultNamespace = getDefaultNamespace(mappingLoader);
+        assertNotNull(defaultNamespace);
+
+        ElementMapping element = defaultNamespace.getElement("pizza");
+        assertNotNull(element);
+        ElementMapping beer = defaultNamespace.getElement("beer");
+        assertNull(beer);
+    }
+
+    public void testQdoxExcludePackage() throws Exception{
+        String basedir = System.getProperties().getProperty("basedir", ".");
+        QdoxMappingLoader mappingLoader = new QdoxMappingLoader(DEFAULT_NAMESPACE,
+                new File[] { new File(basedir, "/src/test/java")},
+                new String[] { "org.apache.xbean.spring.example" } );
+
+        NamespaceMapping defaultNamespace = getDefaultNamespace(mappingLoader);
+        assertNotNull(defaultNamespace);
+
+        ElementMapping element = defaultNamespace.getElement("pizza");
+        assertNull(element);
+        ElementMapping beer = defaultNamespace.getElement("beer");
+        assertNull(beer);
+        ElementMapping cheese = defaultNamespace.getElement("cheese");
+        assertNotNull(cheese);
+    }
+
+    private NamespaceMapping getDefaultNamespace(QdoxMappingLoader mappingLoader) throws
IOException {
+        Set namespaces = mappingLoader.loadNamespaces();
+        assertFalse(namespaces.isEmpty());
+
+        NamespaceMapping defaultNamespace = null;
+        for (Iterator iterator = namespaces.iterator(); iterator.hasNext();) {
+            NamespaceMapping namespaceMapping = (NamespaceMapping) iterator.next();
+            if (namespaceMapping.getNamespace().equals(DEFAULT_NAMESPACE)) {
+                defaultNamespace = namespaceMapping;
+                break;
+            }
+        }
+        return defaultNamespace;
     }
 
     public void testPropertyEditor() {



Mime
View raw message