You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by mm...@apache.org on 2007/03/28 07:56:17 UTC

svn commit: r523188 - in /incubator/cxf/trunk/tools/jdee: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/cxf/ src/main/java/org/apache/cxf/maven_plugin/ src/main/java/org/apache/cxf/maven_plugin/j...

Author: mmao
Date: Tue Mar 27 22:56:15 2007
New Revision: 523188

URL: http://svn.apache.org/viewvc?view=rev&rev=523188
Log:
Add a maven-jdee-plugin for emacs users to generate a jdee project file
  * jdee:jdee to generate project file 
  * jdee:clean to clean the project file 

Added:
    incubator/cxf/trunk/tools/jdee/
    incubator/cxf/trunk/tools/jdee/pom.xml
    incubator/cxf/trunk/tools/jdee/src/
    incubator/cxf/trunk/tools/jdee/src/main/
    incubator/cxf/trunk/tools/jdee/src/main/java/
    incubator/cxf/trunk/tools/jdee/src/main/java/org/
    incubator/cxf/trunk/tools/jdee/src/main/java/org/apache/
    incubator/cxf/trunk/tools/jdee/src/main/java/org/apache/cxf/
    incubator/cxf/trunk/tools/jdee/src/main/java/org/apache/cxf/maven_plugin/
    incubator/cxf/trunk/tools/jdee/src/main/java/org/apache/cxf/maven_plugin/jdee/
    incubator/cxf/trunk/tools/jdee/src/main/java/org/apache/cxf/maven_plugin/jdee/CleanMojo.java
    incubator/cxf/trunk/tools/jdee/src/main/java/org/apache/cxf/maven_plugin/jdee/JdeeMojo.java
    incubator/cxf/trunk/tools/jdee/src/main/java/org/apache/cxf/maven_plugin/jdee/prj.vm

Added: incubator/cxf/trunk/tools/jdee/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/jdee/pom.xml?view=auto&rev=523188
==============================================================================
--- incubator/cxf/trunk/tools/jdee/pom.xml (added)
+++ incubator/cxf/trunk/tools/jdee/pom.xml Tue Mar 27 22:56:15 2007
@@ -0,0 +1,93 @@
+<!--
+    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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" 
+	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+	 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>org.apache.cxf.maven</groupId>
+    <artifactId>maven-jdee-plugin</artifactId>
+    <packaging>maven-plugin</packaging>
+    <version>2.0-incubator-RC-SNAPSHOT</version>
+    <name>Apache CXF Maven2 Plugins</name>
+    <url>http://cwiki.apache.org/CXF</url>
+
+    <parent>
+	<groupId>org.apache.cxf</groupId>
+	<artifactId>cxf-parent</artifactId>
+	<version>2.0-incubator-RC-SNAPSHOT</version>
+	<relativePath>../../parent/pom.xml</relativePath>
+    </parent>
+
+    <dependencies>
+	<dependency>
+	    <groupId>junit</groupId>
+	    <artifactId>junit</artifactId>
+	    <scope>test</scope>
+	</dependency>
+
+	<dependency>
+	    <groupId>org.apache.maven</groupId>
+	    <artifactId>maven-plugin-api</artifactId>
+	    <scope>provided</scope>
+	</dependency>
+	<dependency>
+	    <groupId>org.apache.maven</groupId>
+	    <artifactId>maven-project</artifactId>
+	    <scope>provided</scope>
+	</dependency>
+	<dependency>
+	    <groupId>org.apache.maven</groupId>
+	    <artifactId>maven-artifact</artifactId>
+	    <scope>provided</scope>
+	</dependency>
+
+	<dependency>
+	    <groupId>velocity</groupId>
+	    <artifactId>velocity</artifactId>
+	</dependency>
+
+	<dependency>
+	    <groupId>commons-io</groupId>
+	    <artifactId>commons-io</artifactId>
+	    <version>1.3</version>
+	</dependency>
+
+	<dependency>
+	    <groupId>org.apache.cxf</groupId>
+	    <artifactId>cxf-tools-wsdlto-core</artifactId>
+	    <version>${project.version}</version>
+	</dependency>
+
+        <dependency>
+            <groupId>ant</groupId>
+            <artifactId>ant</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>ant</groupId>
+            <artifactId>ant-nodeps</artifactId>
+        </dependency>
+
+    </dependencies>
+
+    <scm>
+	<connection>scm:svn:http://svn.apache.org/repos/asf/incubator/cxf/trunk/codegen-plugin</connection>
+	<developerConnection>scm:svn:https://svn.apache.org/repos/asf/incubator/cxf/trunk/codegen-plugin</developerConnection>
+    </scm>
+
+</project>

Added: incubator/cxf/trunk/tools/jdee/src/main/java/org/apache/cxf/maven_plugin/jdee/CleanMojo.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/jdee/src/main/java/org/apache/cxf/maven_plugin/jdee/CleanMojo.java?view=auto&rev=523188
==============================================================================
--- incubator/cxf/trunk/tools/jdee/src/main/java/org/apache/cxf/maven_plugin/jdee/CleanMojo.java (added)
+++ incubator/cxf/trunk/tools/jdee/src/main/java/org/apache/cxf/maven_plugin/jdee/CleanMojo.java Tue Mar 27 22:56:15 2007
@@ -0,0 +1,60 @@
+/**
+ * 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.cxf.maven_plugin.jdee;
+
+import java.io.File;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.tools.ant.util.FileUtils;
+
+/**
+ * A super-simple Mojo to emit JDEE project files.
+ *
+ * @goal clean
+ * @description Outputs a JDEE project file.
+ * @requiresDependencyResolution test 
+ */
+public class CleanMojo extends AbstractMojo {
+    /**
+     * The Maven Project.
+     *
+     * @parameter expression="${project}"
+     * @required
+     * @readonly
+     */
+    protected MavenProject project;
+
+    private void cleanPrj() throws Exception {
+        FileUtils.delete(new File(project.getBasedir(), "prj.el"));
+        FileUtils.delete(new File(project.getBasedir(), ".jdee_sources"));
+        FileUtils.delete(new File(project.getBasedir(), ".jdee_classpath"));
+    }
+    
+    public void execute() throws MojoExecutionException {
+        try {
+            cleanPrj();
+        } catch (Exception e) {
+            getLog().debug(e);
+            throw new MojoExecutionException(e.getMessage(), e);
+        }
+    }
+}

Added: incubator/cxf/trunk/tools/jdee/src/main/java/org/apache/cxf/maven_plugin/jdee/JdeeMojo.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/jdee/src/main/java/org/apache/cxf/maven_plugin/jdee/JdeeMojo.java?view=auto&rev=523188
==============================================================================
--- incubator/cxf/trunk/tools/jdee/src/main/java/org/apache/cxf/maven_plugin/jdee/JdeeMojo.java (added)
+++ incubator/cxf/trunk/tools/jdee/src/main/java/org/apache/cxf/maven_plugin/jdee/JdeeMojo.java Tue Mar 27 22:56:15 2007
@@ -0,0 +1,188 @@
+/**
+ * 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.cxf.maven_plugin.jdee;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.cxf.tools.wsdlto.core.VelocityWriter;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.Velocity;
+
+/**
+ * A super-simple Mojo to emit JDEE project files.
+ *
+ * @goal jdee
+ * @description Outputs a JDEE project file.
+ * @requiresDependencyResolution test
+ */
+
+// TODO: 
+//       * include the generated srouce root
+//
+
+public class JdeeMojo extends AbstractMojo {
+    /**
+     * The Maven Project.
+     *
+     * @parameter expression="${project}"
+     * @required
+     * @readonly
+     */
+    protected MavenProject project;
+
+    /**
+     * @component
+     */
+    protected ArtifactFactory artifactFactory;
+
+    /**
+     * Build directory
+     *
+     * @parameter expression="${project.build.outputDirectory}"
+     * @required
+     */
+    private File buildDirectory;
+
+    /**
+     * The set of dependencies required by the project 
+     * @parameter default-value="${project.artifacts}"
+     * @required
+     * @readonly
+     */
+    private java.util.Set dependencies;
+
+
+    private String getVelocityLogFile(String log) {
+        return new File(buildDirectory, log).toString();
+    }
+
+    @SuppressWarnings("unchecked")
+    private Set<String> getSourceDirs() throws Exception {
+        Set<String> results = new HashSet<String>();
+        File file = new File(".jdee_sources");
+        if (file.exists()) {
+            results.addAll(FileUtils.readLines(file));
+        } else {
+            file.createNewFile();
+        }
+
+        results.addAll(emitPaths(project.getCompileSourceRoots()));
+        results.addAll(emitPaths(project.getTestCompileSourceRoots()));
+        FileUtils.writeLines(file, results);
+        return results;
+    }
+
+    @SuppressWarnings("unchecked")
+    private Set<String> getGlobalClasspath() throws Exception {
+        Set<String> results = new HashSet<String>();
+        File file = new File(".jdee_classpath");
+        if (file.exists()) {
+            results.addAll(FileUtils.readLines(file));            
+        } else {
+            file.createNewFile();
+        }
+
+        results.addAll(emitPaths(project.getCompileClasspathElements()));
+        results.addAll(emitPaths(project.getTestClasspathElements()));
+        results.addAll(emitPaths(project.getSystemClasspathElements()));
+        results.addAll(getDependencies());
+        FileUtils.writeLines(file, results);
+        return results;
+    }
+
+    private Set<String> getDependencies() throws Exception {
+        Set<String> results = new HashSet<String>();
+        if (dependencies != null && !dependencies.isEmpty()) {
+            for (Iterator it = dependencies.iterator(); it.hasNext();) {
+                Artifact artifact = (Artifact)it.next();
+                results.add(artifact.getFile().toString().replace("\\", "/"));
+            }
+        }
+        return results;
+    }
+
+    private Set<String> emitPaths(List paths) throws IOException {
+        Set<String> np = new HashSet<String>();
+        for (Object path : paths) {
+            np.add(path.toString().replace("\\", "/"));
+        }
+        return np;
+    }
+
+    // TODO: Reuse the velocity in the tools 
+    private void initVelocity() throws Exception {
+        Properties props = new Properties();
+        String clzName = "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader";
+        props.put("resource.loader", "class");
+        props.put("class.resource.loader.class", clzName);
+        props.put("runtime.log", getVelocityLogFile("velocity.log"));
+
+        Velocity.init(props);
+    }
+
+    private void generatePrj() throws Exception {
+        initVelocity();
+
+        String templateFile = "/org/apache/cxf/maven_plugin/jdee/prj.vm";
+        Template tmpl = Velocity.getTemplate(templateFile);
+        if (tmpl == null) {
+            throw new RuntimeException("Can not load template file: " + templateFile);
+        }
+
+        File outputFile = new File("prj.el");
+        
+        VelocityContext ctx = new VelocityContext();
+        ctx.put("SOURCE_DIRS", getSourceDirs());
+        ctx.put("GLOBAL_CP", getGlobalClasspath());
+
+        Writer outputs = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(outputFile)),
+                                                "UTF-8");
+        VelocityWriter writer = new VelocityWriter(outputs);
+
+        tmpl.merge(ctx, writer);
+        writer.close();
+    }
+
+    public void execute() throws MojoExecutionException {
+        try {
+            generatePrj();
+        } catch (Exception e) {
+            getLog().debug(e);
+            throw new MojoExecutionException(e.getMessage(), e);
+        }
+    }
+}

Added: incubator/cxf/trunk/tools/jdee/src/main/java/org/apache/cxf/maven_plugin/jdee/prj.vm
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/jdee/src/main/java/org/apache/cxf/maven_plugin/jdee/prj.vm?view=auto&rev=523188
==============================================================================
--- incubator/cxf/trunk/tools/jdee/src/main/java/org/apache/cxf/maven_plugin/jdee/prj.vm (added)
+++ incubator/cxf/trunk/tools/jdee/src/main/java/org/apache/cxf/maven_plugin/jdee/prj.vm Tue Mar 27 22:56:15 2007
@@ -0,0 +1,4 @@
+(jde-project-file-version "1.0")
+(jde-set-variables
+  '(jde-sourcepath '(#foreach ($source in $SOURCE_DIRS)"$source" #end))
+  '(jde-global-classpath '(#foreach ($classpath in $GLOBAL_CP)"$classpath" #end)))
\ No newline at end of file