Author: jdillon Date: Mon Sep 4 07:55:16 2006 New Revision: 440099 URL: http://svn.apache.org/viewvc?view=rev&rev=440099 Log: Adding a prototype of a custom maven invoker module, so we can pass profile & other flags to the child Added: geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/MavenMojo.java (with props) Modified: geronimo/genesis/trunk/plugins/tools-maven-plugin/pom.xml geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/RequireJavaVersionMojo.java Modified: geronimo/genesis/trunk/plugins/tools-maven-plugin/pom.xml URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/tools-maven-plugin/pom.xml?view=diff&rev=440099&r1=440098&r2=440099 ============================================================================== --- geronimo/genesis/trunk/plugins/tools-maven-plugin/pom.xml (original) +++ geronimo/genesis/trunk/plugins/tools-maven-plugin/pom.xml Mon Sep 4 07:55:16 2006 @@ -54,6 +54,18 @@ - + + + + + org.apache.maven.plugins + maven-plugin-plugin + + tools + + + + + Added: geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/MavenMojo.java URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/MavenMojo.java?view=auto&rev=440099 ============================================================================== --- geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/MavenMojo.java (added) +++ geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/MavenMojo.java Mon Sep 4 07:55:16 2006 @@ -0,0 +1,158 @@ +/* + * 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.geronimo.genesis.plugins.tools; + +import java.io.File; +import java.io.IOException; + +import java.util.Map; +import java.util.Iterator; + +import org.apache.geronimo.genesis.AntMojoSupport; + +import org.apache.maven.project.MavenProject; +import org.apache.maven.plugin.MojoExecutionException; + +import org.codehaus.plexus.util.Os; + +import org.apache.tools.ant.taskdefs.ExecTask; + +/** + * Invoke Maven in a sub-process. + * + * @goal maven + * + * @version $Rev$ $Date$ + */ +public class MavenMojo + extends AntMojoSupport +{ + /** + * ??? + * + * @parameter expression="${pomFile}" + * @required + */ + private File pomFile = null; + + /** + * ??? + * + * @parameter + */ + private String[] flags = null; + + /** + * ??? + * + * @parameter + */ + private Map parameters = null; + + /** + * ??? + * + * @parameter + */ + private String[] goals = null; + + // + // MojoSupport Hooks + // + + /** + * The maven project. + * + * @parameter expression="${project}" + * @required + * @readonly + */ + protected MavenProject project = null; + + protected MavenProject getProject() { + return project; + } + + protected void doExecute() throws Exception { + ExecTask exec = (ExecTask)createTask("exec"); + + exec.setExecutable(getMavenExecutable().getAbsolutePath()); + exec.setFailIfExecutionFails(true); + exec.setFailonerror(true); + + if (flags != null) { + for (int i=0; i< flags.length; i++) { + exec.createArg().setValue(flags[i]); + } + } + + if (parameters != null) { + Iterator iter = parameters.keySet().iterator(); + while (iter.hasNext()) { + String name = (String)iter.next(); + Object value = parameters.get(name); + exec.createArg().setValue("-D" + name + "=" + value); + } + } + + if (goals != null) { + for (int i=0; i< goals.length; i++) { + exec.createArg().setValue(goals[i]); + } + } + + if (!pomFile.exists()) { + throw new MojoExecutionException("Missing pom file as: " + pomFile); + } + else { + exec.createArg().setValue("-f"); + exec.createArg().setFile(pomFile); + } + + log.info("Starting Maven..."); + + exec.execute(); + } + + private File getMavenExecutable() throws MojoExecutionException, IOException { + String path = System.getProperty("maven.home"); + if (path == null) { + // This should really never happen + throw new MojoExecutionException("Missing msaven.home system property"); + } + + File home = new File(path); + File cmd; + + if (Os.isFamily("windows")) { + cmd = new File(home, "bin/mvn.bat"); + } + else { + cmd = new File(home, "bin/mvn"); + } + + cmd = cmd.getCanonicalFile(); + if (!cmd.exists()) { + throw new MojoExecutionException("Maven executable not found at: " + cmd); + } + + return cmd; + } +} Propchange: geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/MavenMojo.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/MavenMojo.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/MavenMojo.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/RequireJavaVersionMojo.java URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/RequireJavaVersionMojo.java?view=diff&rev=440099&r1=440098&r2=440099 ============================================================================== --- geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/RequireJavaVersionMojo.java (original) +++ geronimo/genesis/trunk/plugins/tools-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/tools/RequireJavaVersionMojo.java Mon Sep 4 07:55:16 2006 @@ -34,7 +34,8 @@ * @version $Rev$ $Date$ */ public class RequireJavaVersionMojo - extends MojoSupport { + extends MojoSupport +{ /** * Specify the required version of Java (1.1, 1.2, 1.3, 1.4, 1.5). *