geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r470159 - in /geronimo/genesis/trunk/plugins/plugin-support/src/main: java/org/apache/geronimo/genesis/ java/org/apache/geronimo/genesis/ant/ java/org/apache/geronimo/genesis/logging/ java/org/apache/geronimo/genesis/util/ resources/
Date Thu, 02 Nov 2006 01:19:18 GMT
Author: jdillon
Date: Wed Nov  1 17:19:16 2006
New Revision: 470159

URL: http://svn.apache.org/viewvc?view=rev&rev=470159
Log:
Refactored the Commons-Logging bridging bits to maybe work better... Maven sure doesn't make
things easy

Added:
    geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ComponentSupport.java
  (with props)
    geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/logging/
    geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/logging/DelegatingLog.java
  (with props)
    geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/logging/Logging.java
  (with props)
    geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/logging/MavenPluginLog.java
  (contents, props changed)
      - copied, changed from r467934, geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/util/MavenPluginLog.java
Removed:
    geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/util/MavenPluginLog.java
    geronimo/genesis/trunk/plugins/plugin-support/src/main/resources/commons-logging.properties
Modified:
    geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/MojoSupport.java
    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/ComponentSupport.java
URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ComponentSupport.java?view=auto&rev=470159
==============================================================================
--- geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ComponentSupport.java
(added)
+++ geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ComponentSupport.java
Wed Nov  1 17:19:16 2006
@@ -0,0 +1,39 @@
+/*
+ * 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 org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.geronimo.genesis.logging.Logging;
+
+/**
+ * Support for Plexus components.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentSupport
+{
+    protected Log log = LogFactory.getLog(getClass());
+    
+    protected ComponentSupport() {
+        Logging.init();
+    }
+}

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

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

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

Modified: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/MojoSupport.java
URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/MojoSupport.java?view=diff&rev=470159&r1=470158&r2=470159
==============================================================================
--- geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/MojoSupport.java
(original)
+++ geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/MojoSupport.java
Wed Nov  1 17:19:16 2006
@@ -53,7 +53,9 @@
 
 import org.apache.geronimo.genesis.dependency.DependencyHelper;
 import org.apache.geronimo.genesis.util.ArtifactItem;
-import org.apache.geronimo.genesis.util.MavenPluginLog;
+import org.apache.geronimo.genesis.logging.MavenPluginLog;
+import org.apache.geronimo.genesis.logging.Logging;
+import org.apache.geronimo.genesis.logging.DelegatingLog;
 
 /**
  * Support for Mojo implementations.
@@ -64,25 +66,6 @@
     extends AbstractMojo
     implements Contextualizable
 {
-    static {
-        //
-        // NOTE: Force install our custom JCL Log bridge, and disable Geronimo's bootstrap
logging
-        //       in case any sub-clas ends up dependening on geronimo-kernel which will muck
-        //       with logging in unexpected ways.
-        //
-
-        System.setProperty("org.apache.commons.logging.LogFactory", "org.apache.commons.logging.impl.LogFactoryImpl");
-
-        //
-        // NOTE: org.apache.commons.logging.Log is set in commons-logging.properties.  Hard-coding
this here
-        //       causes some other Maven plugins to have problems (like the site plugin when
it runs checkstyle).
-        //       Not sure that this will always get picked up though... :-(
-        //
-        // System.setProperty("org.apache.commons.logging.Log", "org.apache.geronimo.genesis.util.MavenPluginLog");
-
-        System.setProperty("geronimo.bootstrap.logging.enabled", "false");
-    }
-
     protected PlexusContainer container;
 
     /**
@@ -93,6 +76,11 @@
     
     private DependencyHelper dependencyHelper;
 
+    protected MojoSupport() {
+        // Need to init our logging support before components are initialized and attached
+        Logging.init();
+    }
+
     /**
      * Initializes logging.  Called by {@link #execute}.
      *
@@ -103,8 +91,9 @@
         this.log = getLog();
 
         // Install the bridge from JCL to this plugins Log
-        MavenPluginLog.setLog(log);
-
+        MavenPluginLog.setMojo(this);
+        DelegatingLog.setDelegateType(MavenPluginLog.class);
+        
         //
         // NOTE: Using direct lookup because this class may not have been directly configured
         //
@@ -147,6 +136,10 @@
             else {
                 throw new MojoExecutionException(e.getMessage(), e);
             }
+        }
+        finally {
+            // Reset logging after we are done to avoid complications with other plugins
using JCL
+            Logging.reset();
         }
     }
 

Modified: 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=diff&rev=470159&r1=470158&r2=470159
==============================================================================
--- geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/AntHelper.java
(original)
+++ geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/ant/AntHelper.java
Wed Nov  1 17:19:16 2006
@@ -33,8 +33,8 @@
 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;
+
+import org.apache.geronimo.genesis.ComponentSupport;
 
 /**
  * Support for Ant-based Mojos.
@@ -42,9 +42,8 @@
  * @version $Rev$ $Date$
  */
 public class AntHelper
+    extends ComponentSupport
 {
-    private static final Log log = LogFactory.getLog(AntHelper.class);
-
     private MavenProject project;
 
     private Project ant;

Added: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/logging/DelegatingLog.java
URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/logging/DelegatingLog.java?view=auto&rev=470159
==============================================================================
--- geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/logging/DelegatingLog.java
(added)
+++ geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/logging/DelegatingLog.java
Wed Nov  1 17:19:16 2006
@@ -0,0 +1,150 @@
+/*
+ * 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.logging;
+
+import java.io.Serializable;
+import java.lang.reflect.Constructor;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.impl.SimpleLog;
+
+/**
+ * Jakarta Commons Logging Log which delegates to another Log type.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DelegatingLog
+    implements Log, Serializable
+{
+    private static Constructor factory;
+
+    public static void setDelegateType(final Class type) {
+        assert type != null;
+
+        try {
+            factory = type.getConstructor(new Class[] { String.class });
+        }
+        catch (NoSuchMethodException e) {
+            throw new RuntimeException("Failed to lookup (String) constructor for type: "
+ type, e);
+        }
+    }
+
+    public static Log getDelegate(final String name) {
+        // If no factory is set, then use a SimpleLog... so logging always works
+        if (factory == null) {
+            return new SimpleLog(name);
+        }
+
+        try {
+            return (Log) factory.newInstance(new Object[] { name });
+        }
+        catch (Exception e) {
+            throw new RuntimeException("Failed to construct delegate logger using factory:
" + factory, e);
+        }
+    }
+
+    private String name;
+
+    public DelegatingLog(final String name) {
+        assert name != null;
+
+        this.name = name;
+    }
+
+    private Log getLog() {
+        return getDelegate(name);
+    }
+
+    public boolean isDebugEnabled() {
+        return getLog().isDebugEnabled();
+    }
+
+    public boolean isErrorEnabled() {
+        return getLog().isErrorEnabled();
+    }
+
+    public boolean isFatalEnabled() {
+        return getLog().isErrorEnabled();
+    }
+
+    public boolean isInfoEnabled() {
+        return getLog().isInfoEnabled();
+    }
+
+    public boolean isTraceEnabled() {
+        return getLog().isTraceEnabled();
+    }
+
+    public boolean isWarnEnabled() {
+        return getLog().isWarnEnabled();
+    }
+
+    private String createMessage(final Object object) {
+        return String.valueOf(object);
+    }
+
+    public void trace(final Object object) {
+        getLog().trace(object);
+    }
+
+    public void trace(final Object object, final Throwable throwable) {
+        getLog().trace(object, throwable);
+    }
+
+    public void debug(final Object object) {
+        getLog().debug(createMessage(object));
+    }
+
+    public void debug(final Object object, final Throwable throwable) {
+        getLog().debug(createMessage(object), throwable);
+    }
+
+    public void info(final Object object) {
+        getLog().info(createMessage(object));
+    }
+
+    public void info(final Object object, final Throwable throwable) {
+        getLog().info(createMessage(object), throwable);
+    }
+
+    public void warn(final Object object) {
+        getLog().warn(createMessage(object));
+    }
+
+    public void warn(final Object object, final Throwable throwable) {
+        getLog().warn(createMessage(object), throwable);
+    }
+
+    public void error(final Object object) {
+        getLog().error(createMessage(object));
+    }
+
+    public void error(final Object object, final Throwable throwable) {
+        getLog().error(createMessage(object), throwable);
+    }
+
+    public void fatal(final Object object) {
+        error(object);
+    }
+
+    public void fatal(final Object object, final Throwable throwable) {
+        error(object, throwable);
+    }
+}

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

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

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

Added: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/logging/Logging.java
URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/logging/Logging.java?view=auto&rev=470159
==============================================================================
--- geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/logging/Logging.java
(added)
+++ geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/logging/Logging.java
Wed Nov  1 17:19:16 2006
@@ -0,0 +1,70 @@
+/*
+ * 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.logging;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Maven plugin logging helpers to initialize and reset logging.
+ *
+ * @version $Rev$ $Date$
+ */
+public class Logging
+{
+    private static boolean initialized;
+
+    public synchronized static void init() {
+        if (!initialized) {
+            LogFactory.releaseAll();
+
+            // Setup the delegating log
+            System.setProperty("org.apache.commons.logging.Log", "org.apache.geronimo.genesis.logging.DelegatingLog");
+
+            // Make sure that Geronimo bootstrap logging does not clobber our logging
+            System.setProperty("geronimo.bootstrap.logging.enabled", "false");
+            
+            Log log = LogFactory.getLog(Logging.class);
+            log.debug("Initialized");
+
+            initialized = true;
+        }
+    }
+
+    public synchronized static void reset() {
+        if (initialized) {
+            Log log = LogFactory.getLog(Logging.class);
+            log.debug("Resetting");
+
+            LogFactory.releaseAll();
+
+            // Restore a reasonable default log impl
+            System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
+
+            // Make SimpleLog look more like Maven logs
+            System.setProperty("org.apache.commons.logging.simplelog.showShortLogname", "false");
+            
+            // Restore default Geornimo bootstrap behavior
+            System.getProperties().remove("geronimo.bootstrap.logging.enabled");
+
+            initialized = false;
+        }
+    }
+}

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

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

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

Copied: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/logging/MavenPluginLog.java
(from r467934, geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/util/MavenPluginLog.java)
URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/logging/MavenPluginLog.java?view=diff&rev=470159&p1=geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/util/MavenPluginLog.java&r1=467934&p2=geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/logging/MavenPluginLog.java&r2=470159
==============================================================================
--- geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/util/MavenPluginLog.java
(original)
+++ geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/logging/MavenPluginLog.java
Wed Nov  1 17:19:16 2006
@@ -17,44 +17,43 @@
  * under the License.
  */
 
-package org.apache.geronimo.genesis.util;
+package org.apache.geronimo.genesis.logging;
 
+import org.apache.maven.plugin.Mojo;
 import org.apache.commons.logging.Log;
 
-import java.io.Serializable;
-
 /**
  * Bridge from the Maven plugin Log to a JCL Log.
  *
  * @version $Rev$ $Date$
  */
 public class MavenPluginLog
-    implements Log, Serializable
+    implements Log
 {
-    private static org.apache.maven.plugin.logging.Log log;
+    private static Mojo mojo;
 
-    public static void setLog(final org.apache.maven.plugin.logging.Log log) {
-        assert log != null;
-        
-        MavenPluginLog.log = log;
-    }
+    public static void setMojo(final Mojo mojo) {
+        assert mojo != null;
 
-    public static org.apache.maven.plugin.logging.Log getLog() {
-        if (log == null) {
-            throw new RuntimeException("Maven plugin log delegate as not been initialized");
-        }
-
-        return log;
+        MavenPluginLog.mojo = mojo;
     }
 
     private String name;
 
     public MavenPluginLog(final String name) {
         assert name != null;
-        
+
         this.name = name;
     }
 
+    private org.apache.maven.plugin.logging.Log getLog() {
+        if (mojo == null) {
+            throw new RuntimeException("Mojo not set; can not delegate logging");
+        }
+
+        return mojo.getLog();
+    }
+
     public boolean isDebugEnabled() {
         return getLog().isDebugEnabled();
     }
@@ -72,10 +71,6 @@
     }
 
     public boolean isTraceEnabled() {
-        //
-        // FIXME: Trace is way to verbose to allow it to be turned on with debug
-        //        Maybe add a custom system prop to enable this
-        //
         // return getLog().isDebugEnabled();
         return false;
     }
@@ -92,56 +87,56 @@
             return String.valueOf(object);
         }
     }
-    
-    public void trace(Object object) {
+
+    public void trace(final Object object) {
         if (isTraceEnabled()) {
             debug(object);
         }
     }
 
-    public void trace(Object object, Throwable throwable) {
+    public void trace(final Object object, final Throwable throwable) {
         if (isTraceEnabled()) {
             debug(object, throwable);
         }
     }
 
-    public void debug(Object object) {
+    public void debug(final Object object) {
         getLog().debug(createMessage(object));
     }
 
-    public void debug(Object object, Throwable throwable) {
+    public void debug(final Object object, final Throwable throwable) {
         getLog().debug(createMessage(object), throwable);
     }
 
-    public void info(Object object) {
+    public void info(final Object object) {
         getLog().info(createMessage(object));
     }
 
-    public void info(Object object, Throwable throwable) {
+    public void info(final Object object, final Throwable throwable) {
         getLog().info(createMessage(object), throwable);
     }
 
-    public void warn(Object object) {
+    public void warn(final Object object) {
         getLog().warn(createMessage(object));
     }
 
-    public void warn(Object object, Throwable throwable) {
+    public void warn(final Object object, final Throwable throwable) {
         getLog().warn(createMessage(object), throwable);
     }
 
-    public void error(Object object) {
+    public void error(final Object object) {
         getLog().error(createMessage(object));
     }
 
-    public void error(Object object, Throwable throwable) {
+    public void error(final Object object, final Throwable throwable) {
         getLog().error(createMessage(object), throwable);
     }
 
-    public void fatal(Object object) {
+    public void fatal(final Object object) {
         error(object);
     }
 
-    public void fatal(Object object, Throwable throwable) {
+    public void fatal(final Object object, final Throwable throwable) {
         error(object, throwable);
     }
 }

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

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

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



Mime
View raw message