diff options
Diffstat (limited to '')
2 files changed, 135 insertions, 0 deletions
diff --git a/sca-java-1.x/trunk/tools/maven/maven-ant-generator/src/main/java/org/apache/tuscany/sca/tools/ant/generator/plugin/AntGeneratorMojo.java b/sca-java-1.x/trunk/tools/maven/maven-ant-generator/src/main/java/org/apache/tuscany/sca/tools/ant/generator/plugin/AntGeneratorMojo.java index 54ac6c7481..de1201ea2d 100644 --- a/sca-java-1.x/trunk/tools/maven/maven-ant-generator/src/main/java/org/apache/tuscany/sca/tools/ant/generator/plugin/AntGeneratorMojo.java +++ b/sca-java-1.x/trunk/tools/maven/maven-ant-generator/src/main/java/org/apache/tuscany/sca/tools/ant/generator/plugin/AntGeneratorMojo.java @@ -132,6 +132,24 @@ public class AntGeneratorMojo extends AbstractMojo { * @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 AbstractMojo { } 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 AbstractMojo { 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 AbstractMojo { 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\">"); diff --git a/sca-java-1.x/trunk/tools/maven/maven-ant-generator/src/main/java/org/apache/tuscany/sca/tools/ant/generator/plugin/JarFile.java b/sca-java-1.x/trunk/tools/maven/maven-ant-generator/src/main/java/org/apache/tuscany/sca/tools/ant/generator/plugin/JarFile.java new file mode 100644 index 0000000000..3d8bc581cb --- /dev/null +++ b/sca-java-1.x/trunk/tools/maven/maven-ant-generator/src/main/java/org/apache/tuscany/sca/tools/ant/generator/plugin/JarFile.java @@ -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;
+ }
+}
|