geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r454309 - in /geronimo/genesis/trunk/plugins/plugin-support/src/main: java/org/apache/geronimo/genesis/ant/ resources/META-INF/plexus/
Date Mon, 09 Oct 2006 08:38:28 GMT
Author: jdillon
Date: Mon Oct  9 01:38:26 2006
New Revision: 454309

URL: http://svn.apache.org/viewvc?view=rev&rev=454309
Log:
Adding plexus AntHelper component to try and move away from inheritance to share code

Added:
    geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/AntHelper.java
  (with props)
    geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/CommonsLoggingAntLoggerAdapter.java
  (with props)
    geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/MavenAntLoggerAdapter.java
  (contents, props changed)
      - copied, changed from r454236, geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/AntLoggerAdapter.java
Removed:
    geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/AntLoggerAdapter.java
Modified:
    geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/AntMojoSupport.java
    geronimo/genesis/trunk/plugins/plugin-support/src/main/resources/META-INF/plexus/components.xml

Added: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/AntHelper.java
URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/AntHelper.java?view=auto&rev=454309
==============================================================================
--- geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/AntHelper.java
(added)
+++ geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/AntHelper.java
Mon Oct  9 01:38:26 2006
@@ -0,0 +1,173 @@
+/*
+ * 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.ant;
+
+import java.io.File;
+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.types.Environment;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.taskdefs.Property;
+import org.apache.tools.ant.taskdefs.Java;
+import org.apache.tools.ant.taskdefs.Mkdir;
+import org.apache.tools.ant.taskdefs.Echo;
+import org.apache.maven.project.MavenProject;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;
+
+/**
+ * Support for Ant-based Mojos.
+ *
+ * @version $Rev$ $Date$
+ */
+public class AntHelper
+{
+    private static final Log log = LogFactory.getLog(AntHelper.class);
+
+    private MavenProject project;
+
+    private Project ant;
+
+    public Project getAnt() {
+        if (ant == null) {
+            ant = new Project();
+            ant.setBaseDir(getProject().getBasedir());
+
+            initAntLogger(ant);
+
+            ant.init();
+        }
+
+        return ant;
+    }
+
+    public void setProject(final MavenProject project) {
+        assert project != null;
+
+        this.project = project;
+    }
+
+    private MavenProject getProject() {
+        if (project == null) {
+            throw new IllegalStateException("Not initialized; missing MavenProject");
+        }
+        return project;
+    }
+
+    public FileSet createFileSet() {
+        FileSet set = new FileSet();
+        set.setProject(getAnt());
+        return set;
+    }
+
+    public Task createTask(final String name) throws BuildException {
+        assert name != null;
+
+        return getAnt().createTask(name);
+    }
+
+    protected void initAntLogger(final Project ant) {
+        CommonsLoggingAntLoggerAdapter antLogger = new CommonsLoggingAntLoggerAdapter(log);
+        antLogger.setEmacsMode(true);
+        antLogger.setOutputPrintStream(System.out);
+        antLogger.setErrorPrintStream(System.err);
+
+        if (log.isDebugEnabled()) {
+            antLogger.setMessageOutputLevel(Project.MSG_VERBOSE);
+        }
+        else {
+            antLogger.setMessageOutputLevel(Project.MSG_INFO);
+        }
+
+        ant.addBuildListener(antLogger);
+    }
+
+    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();
+    }
+
+    public 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());
+    }
+    
+    public void setSystemProperty(final Java java, final String name, final String value)
{
+        assert java != null;
+        assert name != null;
+        assert value != null;
+
+        Environment.Variable var = new Environment.Variable();
+        var.setKey(name);
+        var.setValue(value);
+        java.addSysproperty(var);
+    }
+
+    public void setSystemProperty(final Java java, final String name, final File value) {
+        assert java != null;
+        assert name != null;
+        assert value != null;
+
+        Environment.Variable var = new Environment.Variable();
+        var.setKey(name);
+        var.setFile(value);
+        java.addSysproperty(var);
+    }
+
+    public void mkdir(final File dir) {
+        assert dir != null;
+
+        Mkdir mkdir = (Mkdir)createTask("mkdir");
+        mkdir.setDir(dir);
+        mkdir.execute();
+    }
+
+    public void echo(final String msg) {
+        assert msg != null;
+        
+        Echo echo = (Echo)createTask("echo");
+        echo.setMessage(msg);
+        echo.execute();
+    }
+}

Propchange: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/AntHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/AntHelper.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/AntHelper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/AntMojoSupport.java
URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/AntMojoSupport.java?view=diff&rev=454309&r1=454308&r2=454309
==============================================================================
--- geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/AntMojoSupport.java
(original)
+++ geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/AntMojoSupport.java
Mon Oct  9 01:38:26 2006
@@ -36,7 +36,7 @@
 import org.apache.tools.ant.taskdefs.Mkdir;
 import org.apache.tools.ant.taskdefs.Property;
 
-import org.apache.geronimo.genesis.ant.AntLoggerAdapter;
+import org.apache.geronimo.genesis.ant.MavenAntLoggerAdapter;
 import org.apache.geronimo.genesis.MojoSupport;
 
 /**
@@ -64,7 +64,7 @@
     }
     
     protected void initAntLogger(final Project ant) {
-        AntLoggerAdapter antLogger = new AntLoggerAdapter(log);
+        MavenAntLoggerAdapter antLogger = new MavenAntLoggerAdapter(log);
         antLogger.setEmacsMode(true);
         antLogger.setOutputPrintStream(System.out);
         antLogger.setErrorPrintStream(System.err);

Added: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/CommonsLoggingAntLoggerAdapter.java
URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/CommonsLoggingAntLoggerAdapter.java?view=auto&rev=454309
==============================================================================
--- geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/CommonsLoggingAntLoggerAdapter.java
(added)
+++ geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/CommonsLoggingAntLoggerAdapter.java
Mon Oct  9 01:38:26 2006
@@ -0,0 +1,69 @@
+/*
+ * 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.ant;
+
+import java.io.PrintStream;
+
+import org.apache.tools.ant.DefaultLogger;
+import org.apache.tools.ant.Project;
+import org.apache.commons.logging.Log;
+
+/**
+ * Adapts Ant logging to Jakarta Commons Logging.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CommonsLoggingAntLoggerAdapter
+    extends DefaultLogger
+{
+    protected Log log;
+
+    public CommonsLoggingAntLoggerAdapter(final Log log) {
+        super();
+
+        assert log != null;
+
+        this.log = log;
+    }
+
+    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;
+        }
+    }
+}

Propchange: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/CommonsLoggingAntLoggerAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/CommonsLoggingAntLoggerAdapter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/CommonsLoggingAntLoggerAdapter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/MavenAntLoggerAdapter.java
(from r454236, geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/AntLoggerAdapter.java)
URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/MavenAntLoggerAdapter.java?view=diff&rev=454309&p1=geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/AntLoggerAdapter.java&r1=454236&p2=geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/MavenAntLoggerAdapter.java&r2=454309
==============================================================================
--- geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/AntLoggerAdapter.java
(original)
+++ geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/MavenAntLoggerAdapter.java
Mon Oct  9 01:38:26 2006
@@ -27,16 +27,16 @@
 import org.apache.maven.plugin.logging.Log;
 
 /**
- * Support for Ant-based Mojos.
+ * Adapts Ant logging to Maven Logging.
  *
  * @version $Rev$ $Date$
  */
-public class AntLoggerAdapter
-    extends DefaultLogger
+public class MavenAntLoggerAdapter
+        extends DefaultLogger
 {
     protected Log log;
     
-    public AntLoggerAdapter(final Log log) {
+    public MavenAntLoggerAdapter(final Log log) {
         super();
         
         assert log != null;

Propchange: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/MavenAntLoggerAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/MavenAntLoggerAdapter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/MavenAntLoggerAdapter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/genesis/trunk/plugins/plugin-support/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/plugin-support/src/main/resources/META-INF/plexus/components.xml?view=diff&rev=454309&r1=454308&r2=454309
==============================================================================
--- geronimo/genesis/trunk/plugins/plugin-support/src/main/resources/META-INF/plexus/components.xml
(original)
+++ geronimo/genesis/trunk/plugins/plugin-support/src/main/resources/META-INF/plexus/components.xml
Mon Oct  9 01:38:26 2006
@@ -45,6 +45,11 @@
             </requirements>
         </component>
 
+        <component>
+            <role>org.apache.geronimo.genesis.ant.AntHelper</role>
+            <implementation>org.apache.geronimo.genesis.ant.AntHelper</implementation>
+        </component>
+
     </components>
 </component-set>
 



Mime
View raw message