From bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a Mon Sep 17 00:00:00 2001 From: dims Date: Tue, 17 Jun 2008 00:23:01 +0000 Subject: Move Tuscany from Incubator to top level. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68 --- .../ant/generator/plugin/AntGeneratorMojo.java | 207 +++++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 branches/sca-java-1.0.1/modules/maven-ant-generator/src/main/java/org/apache/tuscany/tools/ant/generator/plugin/AntGeneratorMojo.java (limited to 'branches/sca-java-1.0.1/modules/maven-ant-generator/src') diff --git a/branches/sca-java-1.0.1/modules/maven-ant-generator/src/main/java/org/apache/tuscany/tools/ant/generator/plugin/AntGeneratorMojo.java b/branches/sca-java-1.0.1/modules/maven-ant-generator/src/main/java/org/apache/tuscany/tools/ant/generator/plugin/AntGeneratorMojo.java new file mode 100644 index 0000000000..32838a6c5c --- /dev/null +++ b/branches/sca-java-1.0.1/modules/maven-ant-generator/src/main/java/org/apache/tuscany/tools/ant/generator/plugin/AntGeneratorMojo.java @@ -0,0 +1,207 @@ +/* + * 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.tools.ant.generator.plugin; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; +import org.apache.maven.settings.Settings; + +/** + * @version $Rev$ $Date$ + * @goal generate + * @phase generate-sources + * @requiresDependencyResolution test + * @description Generate Ant build script for an SCA project + */ +public class AntGeneratorMojo extends AbstractMojo { + /** + * The project to create a build for. + * + * @parameter expression="${project}" + * @required + */ + private MavenProject project; + + /** + * Used for resolving artifacts + * + * @component + */ + private ArtifactResolver resolver; + + /** + * Factory for creating artifact objects + * + * @component + */ + private ArtifactFactory factory; + + /** + * The local repository where the artifacts are located + * + * @parameter expression="${localRepository}" + * @required + */ + private ArtifactRepository localRepository; + + /** + * The remote repositories where artifacts are located + * + * @parameter expression="${project.remoteArtifactRepositories}" + */ + private List remoteRepositories; + + /** + * The current user system settings for use in Maven. + * + * @parameter expression="${settings}" + * @required + * @readonly + */ + private Settings settings; + + /** + * The main class name. + * @parameter + */ + private String mainClass; + + /** + * The build.xml file to generate. + * @parameter expression="${basedir}/build.xml" + */ + private String buildFile; + + public void execute() throws MojoExecutionException { + + System.out.println("Generating " + buildFile); + + // Open the target build.xml file + File targetFile = new File(buildFile); + PrintWriter pw; + try { + pw = new PrintWriter(new FileOutputStream(targetFile)); + } catch (FileNotFoundException e) { + throw new MojoExecutionException(e.toString()); + } + + // Determine the project packaging + String packaging = project.getPackaging().toLowerCase(); + + // Determine the module dependencies + List tuscanyModules = new ArrayList(); + List otherModules = new ArrayList(); + for (Artifact artifact: (List)project.getRuntimeArtifacts()) { + if (artifact.getGroupId().startsWith("org.apache.tuscany.sca")) { + tuscanyModules.add(artifact); + } else { + otherModules.add(artifact); + } + } + + pw.println(""); + pw.println(); + + // Generate the compile target + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(" "); + + // Build a JAR + if (packaging.equals("jar")) { + pw.println(" "); + pw.println(" "); + if (mainClass != null) { + pw.println(" "); + } + pw.println(" "); + pw.println(" "); + + } else if (packaging.equals("war")) { + + // Build a WAR + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(" "); + } + pw.println(" "); + pw.println(); + + // Generate the run target + if (mainClass != null) { + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(); + } + + // Generate the clean target + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(" "); + pw.println(); + + // Generate the classpath + pw.println(" "); + for (Artifact artifact: tuscanyModules) { + pw.println(" "); + } + pw.println(" "); + pw.println(" "); + for (Artifact artifact: otherModules) { + pw.println(" "); + } + pw.println(" "); + pw.println(); + + pw.println(""); + pw.close(); + } + +} \ No newline at end of file -- cgit v1.2.3