felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
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 GMT
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 @@
       <plugin>
         <groupId>org.apache.felix</groupId>
         <artifactId>maven-bundle-plugin</artifactId>
-        <version>1.4.3</version>
+        <version>2.0.0</version>
         <extensions>true</extensions>
         <configuration>
           <instructions>
-            <Export-Package>org.apache.felix.fileinstall.*,org.osgi.service.cm, org.osgi.service.log</Export-Package>
+            <Export-Package>
+                org.apache.felix.fileinstall*,
+                org.osgi.service.cm
+            </Export-Package>
+            <Import-Package>
+                org.osgi.service.log;resolution:=optional,
+                *
+            </Import-Package>
             <Bundle-Activator>org.apache.felix.fileinstall.FileInstall</Bundle-Activator>
             <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
             <Bundle-Vendor>The Apache Software Foundation</Bundle-Vendor>
+            <_versionpolicy>[$(version;==;$(@)),$(version;+;$(@)))</_versionpolicy>
           </instructions>
         </configuration>
       </plugin>

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
      *



Mime
View raw message