geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r397898 - in /geronimo/xbean/trunk: ./ maven-xbean-plugin/ maven-xbean-plugin/src/ maven-xbean-plugin/src/main/ maven-xbean-plugin/src/main/java/ maven-xbean-plugin/src/main/java/org/ maven-xbean-plugin/src/main/java/org/apache/ maven-xbean...
Date Fri, 28 Apr 2006 13:40:44 GMT
Author: gnodet
Date: Fri Apr 28 06:40:42 2006
New Revision: 397898

URL: http://svn.apache.org/viewcvs?rev=397898&view=rev
Log:
XBEAN-4: Create a maven 2 plugin for spring mapping generation

Added:
    geronimo/xbean/trunk/maven-xbean-plugin/   (with props)
    geronimo/xbean/trunk/maven-xbean-plugin/pom.xml
    geronimo/xbean/trunk/maven-xbean-plugin/src/
    geronimo/xbean/trunk/maven-xbean-plugin/src/main/
    geronimo/xbean/trunk/maven-xbean-plugin/src/main/java/
    geronimo/xbean/trunk/maven-xbean-plugin/src/main/java/org/
    geronimo/xbean/trunk/maven-xbean-plugin/src/main/java/org/apache/
    geronimo/xbean/trunk/maven-xbean-plugin/src/main/java/org/apache/xbean/
    geronimo/xbean/trunk/maven-xbean-plugin/src/main/java/org/apache/xbean/maven/
    geronimo/xbean/trunk/maven-xbean-plugin/src/main/java/org/apache/xbean/maven/XBeanMojo.java
Modified:
    geronimo/xbean/trunk/pom.xml
    geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/XmlMetadataGenerator.java

Propchange: geronimo/xbean/trunk/maven-xbean-plugin/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Apr 28 06:40:42 2006
@@ -0,0 +1 @@
+target

Added: geronimo/xbean/trunk/maven-xbean-plugin/pom.xml
URL: http://svn.apache.org/viewcvs/geronimo/xbean/trunk/maven-xbean-plugin/pom.xml?rev=397898&view=auto
==============================================================================
--- geronimo/xbean/trunk/maven-xbean-plugin/pom.xml (added)
+++ geronimo/xbean/trunk/maven-xbean-plugin/pom.xml Fri Apr 28 06:40:42 2006
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Copyright 2005-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.
+-->
+<project
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns="http://maven.apache.org/POM/4.0.0">
+  
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.xbean</groupId>
+    <artifactId>xbean</artifactId>
+    <version>2.3-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>maven-xbean-plugin</artifactId>
+  <packaging>maven-plugin</packaging>
+  <name>Maven XBean Plugin</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-project</artifactId>
+      <version>2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-archiver</artifactId>
+      <version>1.0-alpha-5</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-archiver</artifactId>
+      <version>2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-utils</artifactId>
+      <version>1.1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-artifact</artifactId>
+      <version>2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>xbean-spring</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>qdox</groupId>
+      <artifactId>qdox</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>ant</groupId>
+      <artifactId>ant</artifactId>
+      <optional>true</optional>
+    </dependency>
+  </dependencies>
+</project>

Added: geronimo/xbean/trunk/maven-xbean-plugin/src/main/java/org/apache/xbean/maven/XBeanMojo.java
URL: http://svn.apache.org/viewcvs/geronimo/xbean/trunk/maven-xbean-plugin/src/main/java/org/apache/xbean/maven/XBeanMojo.java?rev=397898&view=auto
==============================================================================
--- geronimo/xbean/trunk/maven-xbean-plugin/src/main/java/org/apache/xbean/maven/XBeanMojo.java
(added)
+++ geronimo/xbean/trunk/maven-xbean-plugin/src/main/java/org/apache/xbean/maven/XBeanMojo.java
Fri Apr 28 06:40:42 2006
@@ -0,0 +1,161 @@
+/**
+ * 
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors,  as applicable.
+ * 
+ * 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.maven;
+
+import java.beans.PropertyEditorManager;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.tools.ant.BuildException;
+import org.apache.xbean.spring.generator.DocumentationGenerator;
+import org.apache.xbean.spring.generator.GeneratorPlugin;
+import org.apache.xbean.spring.generator.LogFacade;
+import org.apache.xbean.spring.generator.MappingLoader;
+import org.apache.xbean.spring.generator.NamespaceMapping;
+import org.apache.xbean.spring.generator.QdoxMappingLoader;
+import org.apache.xbean.spring.generator.XmlMetadataGenerator;
+import org.apache.xbean.spring.generator.XsdGenerator;
+
+/**
+ * @author <a href="gnodet@apache.org">Guillaume Nodet</a>
+ * @version $Id: GenerateApplicationXmlMojo.java 314956 2005-10-12 16:27:15Z brett $
+ * @goal mapping
+ * @description Creates xbean mapping file
+ * @phase process-classes
+ * @requiresDependencyResolution runtime
+ */
+public class XBeanMojo extends AbstractMojo implements LogFacade {
+
+	/**
+     * @parameter
+     * @required
+	 */
+    private String namespace;
+    
+    /**
+     * @parameter expression="${basedir}/src/main/java"
+     * @required
+     */
+    private File srcDir;
+    
+    /**
+     * @parameter expression="${basedir}/target/classes/schema.xsd"
+     * @required
+     */
+    private File destFile;
+    
+    /**
+     * @parameter expression="${basedir}/target/classes/"
+     * @required
+     */
+    private File metaInfDir;
+    
+    /**
+     * @parameter expression="org.apache.xbean.spring.context.impl"
+     */
+    private String propertyEditorPaths;
+	
+    
+	public void execute() throws MojoExecutionException, MojoFailureException {
+        getLog().debug( " ======= XBeanMojo settings =======" );
+        getLog().debug( "namespace[" + namespace + "]" );
+        getLog().debug( "srcDir[" + srcDir + "]" );
+        getLog().debug( "destFile[" + destFile + "]" );
+        getLog().debug( "metaInfDir[" + metaInfDir + "]" );
+        getLog().debug( "propertyEditorPaths[" + propertyEditorPaths + "]" );
+
+        if (propertyEditorPaths != null) {
+            List editorSearchPath = new LinkedList(Arrays.asList(PropertyEditorManager.getEditorSearchPath()));
+            StringTokenizer paths = new StringTokenizer(propertyEditorPaths, " ,");
+            editorSearchPath.addAll(Collections.list(paths));
+            PropertyEditorManager.setEditorSearchPath((String[]) editorSearchPath.toArray(new
String[editorSearchPath.size()]));
+        }
+
+        ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
+        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+        try {
+        	destFile.getParentFile().mkdirs();
+        	
+            MappingLoader mappingLoader = new QdoxMappingLoader(namespace, new File[] { srcDir
});
+            GeneratorPlugin[] plugins = new GeneratorPlugin[]{
+                new XmlMetadataGenerator(this, metaInfDir.getAbsolutePath()),
+                new DocumentationGenerator(this, destFile),
+                new XsdGenerator(this, destFile)
+            };
+
+            // load the mappings
+            Set namespaces = mappingLoader.loadNamespaces();
+            if (namespaces.isEmpty()) {
+                System.out.println("Warning: no namespaces found!");
+            }
+
+            // generate the files
+            for (Iterator iterator = namespaces.iterator(); iterator.hasNext();) {
+                NamespaceMapping namespaceMapping = (NamespaceMapping) iterator.next();
+                for (int i = 0; i < plugins.length; i++) {
+                    GeneratorPlugin plugin = plugins[i];
+                    plugin.generate(namespaceMapping);
+                }
+            }
+
+            log("...done.");
+        } catch (Exception e) {
+            throw new BuildException(e);
+        } finally {
+            Thread.currentThread().setContextClassLoader(oldCL);
+        }
+	}
+
+    private File[] getFiles(File path) {
+        if (path == null) {
+            return null;
+        }
+        ArrayList files = new ArrayList();
+        recursiveList(path, files);
+        return (File[]) files.toArray(new File[files.size()]);
+    }
+    
+    private void recursiveList(File path, List files) {
+    	File[] children = path.listFiles();
+    	for (int i = 0; i < children.length; i++) {
+			if (children[i].isFile()) {
+				files.add(children[i]);
+			} else if (children[i].isDirectory()) {
+				recursiveList(children[i], files);
+			}
+		}
+    }
+
+	public void log(String message) {
+		getLog().info(message);
+	}
+
+	public void log(String message, int level) {
+		getLog().info(message);
+	}
+}

Modified: geronimo/xbean/trunk/pom.xml
URL: http://svn.apache.org/viewcvs/geronimo/xbean/trunk/pom.xml?rev=397898&r1=397897&r2=397898&view=diff
==============================================================================
--- geronimo/xbean/trunk/pom.xml (original)
+++ geronimo/xbean/trunk/pom.xml Fri Apr 28 06:40:42 2006
@@ -153,6 +153,7 @@
     <module>xbean-spring</module>
     <module>xbean-telnet</module>
     <module>xbean-tiger</module>
+    <module>maven-xbean-plugin</module>
   </modules>
 <!--
   <repositories>

Modified: geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/XmlMetadataGenerator.java
URL: http://svn.apache.org/viewcvs/geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/XmlMetadataGenerator.java?rev=397898&r1=397897&r2=397898&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/XmlMetadataGenerator.java
(original)
+++ geronimo/xbean/trunk/xbean-spring/src/main/java/org/apache/xbean/spring/generator/XmlMetadataGenerator.java
Fri Apr 28 06:40:42 2006
@@ -48,7 +48,7 @@
             return;
         }
 
-        File file = new File(metaInfDir + NamespaceHelper.createDiscoveryPathName(namespace));
+        File file = new File(metaInfDir, NamespaceHelper.createDiscoveryPathName(namespace));
         file.getParentFile().mkdirs();
         log.log("Generating META-INF properties file: " + file + " for namespace: " + namespace);
         PrintWriter out = new PrintWriter(new FileWriter(file));



Mime
View raw message