You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by na...@apache.org on 2010/09/23 20:18:26 UTC

svn commit: r1000563 - in /tuscany/sca-java-1.x/branches/sca-java-1.6.1/tools/maven/maven-ant-generator/src/main/java/org/apache/tuscany/sca/tools/ant/generator/plugin: AntGeneratorMojo.java JarFile.java

Author: nash
Date: Thu Sep 23 18:18:26 2010
New Revision: 1000563

URL: http://svn.apache.org/viewvc?rev=1000563&view=rev
Log:
TUSCANY-3684: Provide additional configuration options for tuscany-maven-ant-generator

Added:
    tuscany/sca-java-1.x/branches/sca-java-1.6.1/tools/maven/maven-ant-generator/src/main/java/org/apache/tuscany/sca/tools/ant/generator/plugin/JarFile.java
Modified:
    tuscany/sca-java-1.x/branches/sca-java-1.6.1/tools/maven/maven-ant-generator/src/main/java/org/apache/tuscany/sca/tools/ant/generator/plugin/AntGeneratorMojo.java

Modified: tuscany/sca-java-1.x/branches/sca-java-1.6.1/tools/maven/maven-ant-generator/src/main/java/org/apache/tuscany/sca/tools/ant/generator/plugin/AntGeneratorMojo.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-1.x/branches/sca-java-1.6.1/tools/maven/maven-ant-generator/src/main/java/org/apache/tuscany/sca/tools/ant/generator/plugin/AntGeneratorMojo.java?rev=1000563&r1=1000562&r2=1000563&view=diff
==============================================================================
--- tuscany/sca-java-1.x/branches/sca-java-1.6.1/tools/maven/maven-ant-generator/src/main/java/org/apache/tuscany/sca/tools/ant/generator/plugin/AntGeneratorMojo.java (original)
+++ tuscany/sca-java-1.x/branches/sca-java-1.6.1/tools/maven/maven-ant-generator/src/main/java/org/apache/tuscany/sca/tools/ant/generator/plugin/AntGeneratorMojo.java Thu Sep 23 18:18:26 2010
@@ -132,6 +132,24 @@ public class AntGeneratorMojo extends Ab
      * @parameter expression="../.."
      */
     private String pathToRootDir; 
+
+    /**
+     * Additional run targets and corresponding class names
+     * @parameter
+     */
+    private Map<String, String> runTargets;
+
+    /**
+     * Set this to true if test source needs to be compiled
+     * @parameter
+     */
+    private boolean testSource;
+
+    /**
+     * Additional jar files to be produced
+     * @parameter
+     */
+    private List<JarFile> jarFiles;
     
     public void execute() throws MojoExecutionException {
         if ((buildDependencyFileOnly != null) &&
@@ -236,6 +254,46 @@ public class AntGeneratorMojo extends Ab
         }
         pw.println("        </copy>");
         
+        // Compile test source using code cut and pasted from above
+        if (testSource) {
+            pw.println("        <mkdir dir=\"target/test-classes\"/>");
+            pw.println("        <javac destdir=\"target/test-classes\" debug=\"on\" source=\"1.5\" target=\"1.5\">");
+            for (String source: (List<String>)project.getTestCompileSourceRoots()) {
+                if (source.length() > base) {
+                    source = source.substring(base);
+                } else {
+                    source = ".";
+                }
+                pw.println("            <src path=\"" + source + "\"/>");
+            }
+            pw.println("            <classpath>");
+            pw.println("                <fileset dir=\"target/classes\"/>");
+            pw.println("                <fileset refid=\"tuscany.jars\"/>");
+            pw.println("                <fileset refid=\"3rdparty.jars\"/>");
+            pw.println("            </classpath>");
+            pw.println("        </javac>");
+            pw.println("        <copy todir=\"target/test-classes\">");
+            for (FileSet resource: (List<FileSet>)project.getTestResources()) {
+                String source = resource.getDirectory();
+                if (source.length() > base) {
+                    source = source.substring(base);
+                    
+                    if (source.equals(".")){
+                        pw.println("            <fileset dir=\".\" includes=\"*\" excludes=\"src, target, pom.xml, build.xml\"/>");
+                    } else {
+                        pw.println("            <fileset dir=\"" + source + "\"/>");
+                    }
+                } else {
+                    if (project.getTestResources().size() > 1) {
+                        break;
+                    }
+                    pw.println("            <fileset dir=\".\" excludes=\"**/*.java, pom.xml, build.xml, target\"/>");
+                    source = ".";
+                }
+            }
+            pw.println("        </copy>");
+        }
+        
         // Build a JAR
         if (packaging.equals("jar")) {
             pw.println("        <jar destfile=\"target/" + project.getArtifactId() + ".jar\" basedir=\"target/classes\">");
@@ -256,6 +314,21 @@ public class AntGeneratorMojo extends Ab
             pw.println("            <classes dir=\"target/classes\"/>");
             pw.println("        </war>");
         }
+
+        // Build additional JARs
+        if (jarFiles != null) {
+            for (JarFile jarFile: jarFiles) {
+                pw.println("        <jar destfile=\"" + jarFile.getDestfile() + "\">");
+                if (jarFile.getFilesets() != null) {
+                    for (String fileset: jarFile.getFilesets()) {
+                        pw.println("            <fileset " + fileset + "/>");
+                    }
+                }
+                pw.println("        </jar>");
+            }
+        }
+
+        // Finish the compile target
         pw.println("    </target>");
         pw.println();
         
@@ -278,6 +351,22 @@ public class AntGeneratorMojo extends Ab
             pw.println("    </target>");
             pw.println();
         }
+
+        // Generate other run targets
+        if (runTargets != null) {
+            for (Map.Entry<String, String> element: runTargets.entrySet()) {
+                pw.println("    <target name=\"" + element.getKey() + "\">");
+                pw.println("        <java classname=\"" + element.getValue() + "\" fork=\"true\">");
+                pw.println("            <classpath>");
+                pw.println("                <pathelement location=\"target/" + project.getArtifactId() + ".jar\"/>");
+                pw.println("                <fileset refid=\"tuscany.jars\"/>");
+                pw.println("                <fileset refid=\"3rdparty.jars\"/>");
+                pw.println("            </classpath>");
+                pw.println("        </java>");
+                pw.println("    </target>");
+                pw.println();
+            }
+        }
         
         // Generate the clean target
         pw.println("    <target name=\"clean\">");

Added: tuscany/sca-java-1.x/branches/sca-java-1.6.1/tools/maven/maven-ant-generator/src/main/java/org/apache/tuscany/sca/tools/ant/generator/plugin/JarFile.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-1.x/branches/sca-java-1.6.1/tools/maven/maven-ant-generator/src/main/java/org/apache/tuscany/sca/tools/ant/generator/plugin/JarFile.java?rev=1000563&view=auto
==============================================================================
--- tuscany/sca-java-1.x/branches/sca-java-1.6.1/tools/maven/maven-ant-generator/src/main/java/org/apache/tuscany/sca/tools/ant/generator/plugin/JarFile.java (added)
+++ tuscany/sca-java-1.x/branches/sca-java-1.6.1/tools/maven/maven-ant-generator/src/main/java/org/apache/tuscany/sca/tools/ant/generator/plugin/JarFile.java Thu Sep 23 18:18:26 2010
@@ -0,0 +1,46 @@
+/*
+ * 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.tuscany.sca.tools.ant.generator.plugin;
+
+import java.util.List;
+
+public class JarFile {
+
+    /**
+     * The destfile attribute of the generated <jar> task
+     *
+     * @parameter
+     */
+    private String destfile;
+
+    /**
+     * The filesets to be included in the generated <jar> task
+     *
+     * @parameter
+     */
+    private List filesets;
+
+    public String getDestfile() {
+        return destfile;
+    }
+
+    public List<String> getFilesets() {
+        return filesets;
+    }
+}