You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2006/08/27 09:41:16 UTC
svn commit: r437321 - in /geronimo/genesis/trunk/plugins/plugin-support:
pom.xml src/main/java/org/apache/geronimo/genesis/
src/main/java/org/apache/geronimo/genesis/AntMojoSupport.java
Author: jdillon
Date: Sun Aug 27 00:41:15 2006
New Revision: 437321
URL: http://svn.apache.org/viewvc?rev=437321&view=rev
Log:
Adding a helper for Mojo's that need to access Ant to do stuff
Added:
geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/
geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/AntMojoSupport.java (with props)
Modified:
geronimo/genesis/trunk/plugins/plugin-support/pom.xml
Modified: geronimo/genesis/trunk/plugins/plugin-support/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/plugin-support/pom.xml?rev=437321&r1=437320&r2=437321&view=diff
==============================================================================
--- geronimo/genesis/trunk/plugins/plugin-support/pom.xml (original)
+++ geronimo/genesis/trunk/plugins/plugin-support/pom.xml Sun Aug 27 00:41:15 2006
@@ -7,9 +7,9 @@
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
@@ -38,6 +38,22 @@
<description>
Provides common support classes used by plugins.
</description>
-
+
+ <dependencies>
+
+ <dependency>
+ <groupId>ant</groupId>
+ <artifactId>ant</artifactId>
+ <version>1.6.5</version>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.1</version>
+ </dependency>
+
+ </dependencies>
+
</project>
Added: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/AntMojoSupport.java
URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/AntMojoSupport.java?rev=437321&view=auto
==============================================================================
--- geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/AntMojoSupport.java (added)
+++ geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/AntMojoSupport.java Sun Aug 27 00:41:15 2006
@@ -0,0 +1,142 @@
+/*
+ * 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;
+
+import java.io.File;
+import java.io.PrintStream;
+
+import java.util.Map;
+import java.util.Iterator;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildLogger;
+import org.apache.tools.ant.DefaultLogger;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.taskdefs.Mkdir;
+import org.apache.tools.ant.taskdefs.Property;
+
+import org.apache.geronimo.plugin.MojoSupport;
+
+/**
+ * Support for Ant-based Mojos.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class AntMojoSupport
+ extends MojoSupport
+{
+ protected Project ant;
+
+ protected void init() {
+ super.init();
+
+ ant = new Project();
+ ant.setBaseDir(getProject().getBasedir());
+
+ BuildLogger antLogger = new DefaultLogger() {
+ protected void printMessage(final String message, final PrintStream stream, final int priority) {
+ assert message != null;
+ assert stream != null;
+
+ switch (priority) {
+ case Project.MSG_ERR:
+ log.error(message);
+ break;
+
+ case Project.MSG_WARN:
+ log.warn(message);
+ break;
+
+ case Project.MSG_INFO:
+ log.info(message);
+ break;
+
+ case Project.MSG_VERBOSE:
+ case Project.MSG_DEBUG:
+ log.debug(message);
+ break;
+ }
+ }
+ };
+
+ antLogger.setOutputPrintStream(System.out);
+ antLogger.setErrorPrintStream(System.err);
+ antLogger.setMessageOutputLevel(Project.MSG_INFO);
+
+ ant.addBuildListener(antLogger);
+
+ ant.init();
+
+ // Inherit properties from Maven
+ inheritProperties();
+ }
+
+ protected void setProperty(final String name, Object value) {
+ assert name != null;
+ assert value != null;
+
+ String valueAsString = String.valueOf(value);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Setting property: " + name + "=" + valueAsString);
+ }
+
+ Property prop = (Property)createTask("property");
+ prop.setName(name);
+ prop.setValue(valueAsString);
+ prop.execute();
+ }
+
+ protected void inheritProperties() {
+ // Propagate properties
+ Map props = getProject().getProperties();
+ Iterator iter = props.keySet().iterator();
+ while (iter.hasNext()) {
+ String name = (String)iter.next();
+ String value = String.valueOf(props.get(name));
+ setProperty(name, value);
+ }
+
+ // Hardcode a few
+ setProperty("pom.basedir", getProject().getBasedir());
+ }
+
+ protected FileSet createFileSet() {
+ FileSet set = new FileSet();
+ set.setProject(ant);
+ return set;
+ }
+
+ protected Task createTask(final String name) throws BuildException {
+ assert name != null;
+
+ return ant.createTask(name);
+ }
+
+ protected void mkdir(final File dir) {
+ assert dir != null;
+
+ Mkdir mkdir = (Mkdir)createTask("mkdir");
+ mkdir.setDir(dir);
+ mkdir.execute();
+ }
+}
\ No newline at end of file
Propchange: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/AntMojoSupport.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/AntMojoSupport.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/AntMojoSupport.java
------------------------------------------------------------------------------
svn:mime-type = text/plain