Return-Path: Delivered-To: apmail-felix-commits-archive@www.apache.org Received: (qmail 92454 invoked from network); 3 Sep 2009 13:39:59 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 3 Sep 2009 13:39:59 -0000 Received: (qmail 36051 invoked by uid 500); 3 Sep 2009 13:39:59 -0000 Delivered-To: apmail-felix-commits-archive@felix.apache.org Received: (qmail 36002 invoked by uid 500); 3 Sep 2009 13:39:59 -0000 Mailing-List: contact commits-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list commits@felix.apache.org Received: (qmail 35987 invoked by uid 99); 3 Sep 2009 13:39:59 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Sep 2009 13:39:59 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Sep 2009 13:39:56 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id D99182388896; Thu, 3 Sep 2009 13:39:34 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r810936 - in /felix/trunk/fileinstall: pom.xml src/main/java/org/apache/felix/fileinstall/util/Util.java Date: Thu, 03 Sep 2009 13:39:34 -0000 To: commits@felix.apache.org From: gnodet@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090903133934.D99182388896@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: gnodet Date: Thu Sep 3 13:39:34 2009 New Revision: 810936 URL: http://svn.apache.org/viewvc?rev=810936&view=rev Log: FELIX-1553: fileinstall bundle should have an optional import on org.osgi.service.log instead of exporting it Modified: felix/trunk/fileinstall/pom.xml felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/util/Util.java Modified: felix/trunk/fileinstall/pom.xml URL: http://svn.apache.org/viewvc/felix/trunk/fileinstall/pom.xml?rev=810936&r1=810935&r2=810936&view=diff ============================================================================== --- felix/trunk/fileinstall/pom.xml (original) +++ felix/trunk/fileinstall/pom.xml Thu Sep 3 13:39:34 2009 @@ -48,14 +48,22 @@ org.apache.felix maven-bundle-plugin - 1.4.3 + 2.0.0 true - org.apache.felix.fileinstall.*,org.osgi.service.cm, org.osgi.service.log + + org.apache.felix.fileinstall*, + org.osgi.service.cm + + + org.osgi.service.log;resolution:=optional, + * + org.apache.felix.fileinstall.FileInstall ${pom.artifactId} The Apache Software Foundation + <_versionpolicy>[$(version;==;$(@)),$(version;+;$(@))) Modified: felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/util/Util.java URL: http://svn.apache.org/viewvc/felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/util/Util.java?rev=810936&r1=810935&r2=810936&view=diff ============================================================================== --- felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/util/Util.java (original) +++ felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/util/Util.java Thu Sep 3 13:39:34 2009 @@ -175,48 +175,92 @@ */ public static void log(BundleContext context, long debug, String message, Throwable e) { - LogService log = getLogService(context); - if (log == null) + getLogger(context).log(debug > 0, message, e); + } + + private static Logger getLogger(BundleContext context) + { + if (logger != null) + { + return logger; + } + try + { + logger = new OsgiLogger(context); + } + catch (Throwable t) + { + logger = new StdOutLogger(); + } + return logger; + } + + private static Logger logger; + + interface Logger + { + void log(boolean debug, java.lang.String message, java.lang.Throwable throwable); + } + + static class StdOutLogger implements Logger + { + public void log(boolean debug, String message, Throwable throwable) { - System.out.println(message + (e == null ? "" : ": " + e)); - if (debug > 0 && e != null) + System.out.println(message + (throwable == null ? "" : ": " + throwable)); + if (debug && throwable != null) { - e.printStackTrace(System.out); + throwable.printStackTrace(System.out); } } - else + } + + static class OsgiLogger extends StdOutLogger + { + + private BundleContext context; + + OsgiLogger(BundleContext context) { - if (e != null) + this.context = context; + } + + public void log(boolean debug, String message, Throwable throwable) + { + LogService log = getLogService(); + if (log != null) { - log.log(LogService.LOG_ERROR, message, e); - if (debug > 0 && e != null) + if (throwable != null) + { + log.log(LogService.LOG_ERROR, message, throwable); + if (debug) + { + throwable.printStackTrace(); + } + } + else { - e.printStackTrace(); + log.log(LogService.LOG_INFO, message); } } else { - log.log(LogService.LOG_INFO, message); + super.log(debug, message, throwable); } } - } - /** - * Answer the Log Service - * - * @return - */ - private static LogService getLogService(BundleContext context) - { - ServiceReference ref = context.getServiceReference(LogService.class.getName()); - if (ref != null) + private LogService getLogService() { - LogService log = (LogService) context.getService(ref); - return log; + ServiceReference ref = context.getServiceReference(LogService.class.getName()); + if (ref != null) + { + LogService log = (LogService) context.getService(ref); + return log; + } + return null; } - return null; } + /** * Jar up a directory *