Author: fmeschbe
Date: Sun Mar 3 13:54:07 2013
New Revision: 1452040
URL: http://svn.apache.org/r1452040
Log:
FELIX-3945 Remove Dependency on SLF4J
Add static log method using LogService if available;
otherwise write to stdou
Modified:
felix/trunk/inventory/pom.xml
felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/Activator.java
felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterManagerImpl.java
Modified: felix/trunk/inventory/pom.xml
URL:
http://svn.apache.org/viewvc/felix/trunk/inventory/pom.xml?rev=1452040&r1=1452039&r2=1452040&view=diff
==============================================================================
--- felix/trunk/inventory/pom.xml (original)
+++ felix/trunk/inventory/pom.xml Sun Mar 3 13:54:07 2013
@@ -74,12 +74,6 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.5.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
Modified:
felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/Activator.java
URL:
http://svn.apache.org/viewvc/felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/Activator.java?rev=1452040&r1=1452039&r2=1452040&view=diff
==============================================================================
---
felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/Activator.java
(original)
+++
felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/Activator.java
Sun Mar 3 13:54:07 2013
@@ -5,9 +5,9 @@
* 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.
@@ -19,6 +19,9 @@ package org.apache.felix.inventory.impl;
import org.apache.felix.inventory.impl.webconsole.WebConsoleAdapter;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.ServiceTracker;
/**
* Activate bridges and internal manager.
@@ -26,6 +29,10 @@ import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator
{
+ private static Object logService;
+
+ private ServiceTracker logServiceTracker;
+
private InventoryPrinterManagerImpl printerManager;
private WebConsoleAdapter webAdapter;
@@ -35,8 +42,26 @@ public class Activator implements Bundle
*/
public void start(final BundleContext context) throws Exception
{
- this.webAdapter = new WebConsoleAdapter(context);
- this.printerManager = new InventoryPrinterManagerImpl(context);
+ this.logServiceTracker = new ServiceTracker(context,
"org.osgi.service.log.LogService", null)
+ {
+ public Object addingService(ServiceReference reference)
+ {
+ Activator.logService = super.addingService(reference);
+ return Activator.logService;
+ }
+
+ public void removedService(ServiceReference reference, Object
service)
+ {
+ Activator.logService = null;
+ super.removedService(reference, service);
+ }
+ };
+ this.logServiceTracker.open();
+
+// this.webAdapter = new WebConsoleAdapter(context);
+// this.printerManager = new InventoryPrinterManagerImpl(context);
+
+ log(null, LogService.LOG_INFO, "Starting Framework Inventory Support",
null);
}
/**
@@ -54,5 +79,48 @@ public class Activator implements Bundle
this.webAdapter.dispose();
this.webAdapter = null;
}
+ Activator.logService = null;
+ if (this.logServiceTracker != null)
+ {
+ this.logServiceTracker.close();
+ this.logServiceTracker = null;
+ }
+ }
+
+ public static void log(final ServiceReference sr, final int level, final
String message, final Throwable exception)
+ {
+ Object logService = Activator.logService;
+ if (logService != null)
+ {
+ ((LogService) logService).log(sr, level, message, exception);
+ }
+ else
+ {
+ final String code;
+ switch (level)
+ {
+ case LogService.LOG_INFO:
+ code = "*INFO *";
+ break;
+
+ case LogService.LOG_WARNING:
+ code = "*WARN *";
+ break;
+
+ case LogService.LOG_ERROR:
+ code = "*ERROR*";
+ break;
+
+ case LogService.LOG_DEBUG:
+ default:
+ code = "*DEBUG*";
+ }
+
+ System.err.println(code + " " + message);
+ if (exception != null)
+ {
+ exception.printStackTrace(System.out);
+ }
+ }
}
}
Modified:
felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterManagerImpl.java
URL:
http://svn.apache.org/viewvc/felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterManagerImpl.java?rev=1452040&r1=1452039&r2=1452040&view=diff
==============================================================================
---
felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterManagerImpl.java
(original)
+++
felix/trunk/inventory/src/main/java/org/apache/felix/inventory/impl/InventoryPrinterManagerImpl.java
Sun Mar 3 13:54:07 2013
@@ -5,9 +5,9 @@
* 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.
@@ -33,10 +33,9 @@ import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.log.LogService;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* The manager keeps track of all inventory printers and maintains them
@@ -46,9 +45,6 @@ import org.slf4j.LoggerFactory;
public class InventoryPrinterManagerImpl implements ServiceTrackerCustomizer
{
- /** Logger. */
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
-
/** Bundle Context . */
private final BundleContext bundleContext;
@@ -69,7 +65,7 @@ public class InventoryPrinterManagerImpl
/**
* Create the inventory printer manager
- *
+ *
* @param btx Bundle Context
* @throws InvalidSyntaxException Should only happen if we have an error in
* the code
@@ -132,17 +128,20 @@ public class InventoryPrinterManagerImpl
boolean valid = true;
if (desc.getModes() == null)
{
- logger.info("Ignoring inventory printer - printer modes
configuration is missing: {}", reference);
+ Activator.log(null, LogService.LOG_INFO,
+ "Ignoring inventory printer - printer modes configuration is
missing: " + reference, null);
valid = false;
}
if (desc.getName() == null)
{
- logger.info("Ignoring inventory printer - name configuration is
missing: {}", reference);
+ Activator.log(null, LogService.LOG_INFO, "Ignoring inventory
printer - name configuration is missing: "
+ + reference, null);
valid = false;
}
if (desc.getTitle() == null)
{
- logger.info("Ignoring inventory printer - title configuration is
missing: {}", reference);
+ Activator.log(null, LogService.LOG_INFO, "Ignoring inventory
printer - title configuration is missing: "
+ + reference, null);
valid = false;
}
if (valid)
@@ -150,7 +149,8 @@ public class InventoryPrinterManagerImpl
final InventoryPrinterAdapter adapter =
InventoryPrinterAdapter.createAdapter(desc, obj);
if (adapter == null)
{
- logger.info("Ignoring inventory printer - printer method is
missing: {}", reference);
+ Activator.log(null, LogService.LOG_INFO, "Ignoring inventory
printer - printer method is missing: "
+ + reference, null);
}
else
{
@@ -271,7 +271,7 @@ public class InventoryPrinterManagerImpl
/**
* Get all inventory printer handlers.
- *
+ *
* @return A list of handlers - might be empty.
*/
public InventoryPrinterHandler[] getAllHandlers()
@@ -282,7 +282,7 @@ public class InventoryPrinterManagerImpl
/**
* Get all handlers supporting the mode.
- *
+ *
* @return A list of handlers - might be empty.
*/
public InventoryPrinterHandler[] getHandlers(final PrinterMode mode)
@@ -302,7 +302,7 @@ public class InventoryPrinterManagerImpl
/**
* Return a handler for the unique name.
- *
+ *
* @return The corresponding handler or <code>null</code>.
*/
public InventoryPrinterHandler getHandler(final String name)