You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by ro...@apache.org on 2018/10/30 21:27:52 UTC

svn commit: r1845282 - in /aries/trunk/spi-fly: spi-fly-core/ spi-fly-core/src/main/java/org/apache/aries/spifly/ spi-fly-dynamic-bundle/ spi-fly-dynamic-bundle/src/main/java/org/apache/aries/spifly/dynamic/ spi-fly-dynamic-framework-extension/ spi-fly...

Author: rotty3000
Date: Tue Oct 30 21:27:52 2018
New Revision: 1845282

URL: http://svn.apache.org/viewvc?rev=1845282&view=rev
Log:
ARIES-1855 Finish removing legacy of LogService

Signed-off-by: Raymond Auge <ro...@apache.org>

Modified:
    aries/trunk/spi-fly/spi-fly-core/pom.xml
    aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/BaseActivator.java
    aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/ProviderBundleTrackerCustomizer.java
    aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/Util.java
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/pom.xml
    aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/main/java/org/apache/aries/spifly/dynamic/ClientWeavingHook.java
    aries/trunk/spi-fly/spi-fly-dynamic-framework-extension/pom.xml
    aries/trunk/spi-fly/spi-fly-static-bundle/pom.xml

Modified: aries/trunk/spi-fly/spi-fly-core/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-core/pom.xml?rev=1845282&r1=1845281&r2=1845282&view=diff
==============================================================================
--- aries/trunk/spi-fly/spi-fly-core/pom.xml (original)
+++ aries/trunk/spi-fly/spi-fly-core/pom.xml Tue Oct 30 21:27:52 2018
@@ -51,13 +51,6 @@
             <artifactId>org.osgi.core</artifactId>
             <scope>provided</scope>
         </dependency>
-
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.compendium</artifactId>
-            <scope>provided</scope>
-        </dependency>
-
         <dependency>
             <groupId>org.apache.aries</groupId>
             <artifactId>org.apache.aries.util</artifactId>

Modified: aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/BaseActivator.java
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/BaseActivator.java?rev=1845282&r1=1845281&r2=1845282&view=diff
==============================================================================
--- aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/BaseActivator.java (original)
+++ aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/BaseActivator.java Tue Oct 30 21:27:52 2018
@@ -43,7 +43,6 @@ import org.osgi.framework.BundleContext;
 import org.osgi.framework.wiring.BundleRevision;
 import org.osgi.framework.wiring.BundleWire;
 import org.osgi.framework.wiring.BundleWiring;
-import org.osgi.service.log.LogService;
 import org.osgi.util.tracker.BundleTracker;
 
 public abstract class BaseActivator implements BundleActivator {
@@ -152,46 +151,54 @@ public abstract class BaseActivator impl
         providerBundleTracker.close();
     }
 
-    public boolean isLogEnabled(int level) {
-        switch (level) {
-            case Integer.MAX_VALUE:
-                return logger.isLoggable(Level.FINEST);
-            case LogService.LOG_ERROR:
-                return logger.isLoggable(Level.SEVERE);
-            case LogService.LOG_INFO:
-                return logger.isLoggable(Level.INFO);
-            case LogService.LOG_DEBUG:
-                return logger.isLoggable(Level.FINE);
-            case LogService.LOG_WARNING:
-            default:
-                return logger.isLoggable(Level.WARNING);
-        }
+    public boolean isLogEnabled(Level level) {
+        return logger.isLoggable(level);
     }
 
     public void log(int level, String message) {
         log(level, message, null);
     }
 
+    public void log(Level level, String message) {
+        log(level, message, null);
+    }
+
     public void log(int level, String message, Throwable th) {
-        switch (level) {
-            case Integer.MAX_VALUE:
-                logger.log(Level.FINEST, message, th);
-                break;
-            case LogService.LOG_ERROR:
-                logger.log(Level.SEVERE, message, th);
-                break;
-            case LogService.LOG_WARNING:
-                logger.log(Level.WARNING, message, th);
-                break;
-            case LogService.LOG_INFO:
-                logger.log(Level.INFO, message, th);
-                break;
-            case LogService.LOG_DEBUG:
-                logger.log(Level.FINE, message, th);
-                break;
-            default:
-                logger.log(Level.SEVERE, "[Unknown Level: " + level + "] " + message, th);
+        Level levelObject;
+
+        if (Level.ALL.intValue() == level) {
+            levelObject = Level.ALL;
+        }
+        else if (Level.CONFIG.intValue() == level) {
+            levelObject = Level.CONFIG;
+        }
+        else if (Level.FINE.intValue() == level) {
+            levelObject = Level.FINE;
+        }
+        else if (Level.FINER.intValue() == level) {
+            levelObject = Level.FINER;
         }
+        else if (Level.FINEST.intValue() == level) {
+            levelObject = Level.FINEST;
+        }
+        else if (Level.INFO.intValue() == level) {
+            levelObject = Level.INFO;
+        }
+        else if (Level.SEVERE.intValue() == level) {
+            levelObject = Level.SEVERE;
+        }
+        else if (Level.WARNING.intValue() == level) {
+            levelObject = Level.WARNING;
+        }
+        else {
+            levelObject = Level.OFF;
+        }
+
+        log(levelObject, message, th);
+    }
+
+    public void log(Level level, String message, Throwable th) {
+        logger.log(level, message, th);
     }
 
     public Set<WeavingData> getWeavingData(Bundle b) {

Modified: aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/ProviderBundleTrackerCustomizer.java
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/ProviderBundleTrackerCustomizer.java?rev=1845282&r1=1845281&r2=1845282&view=diff
==============================================================================
--- aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/ProviderBundleTrackerCustomizer.java (original)
+++ aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/ProviderBundleTrackerCustomizer.java Tue Oct 30 21:27:52 2018
@@ -34,6 +34,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.jar.JarEntry;
 import java.util.jar.JarInputStream;
+import java.util.logging.Level;
 
 import org.apache.aries.util.manifest.ManifestHeaderProcessor;
 import org.apache.aries.util.manifest.ManifestHeaderProcessor.GenericMetadata;
@@ -48,7 +49,6 @@ import org.osgi.framework.ServiceRegistr
 import org.osgi.framework.wiring.BundleRevision;
 import org.osgi.framework.wiring.BundleWire;
 import org.osgi.framework.wiring.BundleWiring;
-import org.osgi.service.log.LogService;
 import org.osgi.util.tracker.BundleTrackerCustomizer;
 
 /**
@@ -65,8 +65,9 @@ public class ProviderBundleTrackerCustom
         this.spiBundle = spiBundle;
     }
 
+    @Override
     public List<ServiceRegistration> addingBundle(final Bundle bundle, BundleEvent event) {
-        log(LogService.LOG_DEBUG, "Bundle Considered for SPI providers: "
+        log(Level.FINE, "Bundle Considered for SPI providers: "
                 + bundle.getSymbolicName());
 
         if (bundle.equals(spiBundle))
@@ -78,7 +79,7 @@ public class ProviderBundleTrackerCustom
             try {
                 providedServices = readServiceLoaderMediatorCapabilityMetadata(bundle, customAttributes);
             } catch (InvalidSyntaxException e) {
-                log(LogService.LOG_ERROR, "Unable to read capabilities from bundle " + bundle, e);
+                log(Level.SEVERE, "Unable to read capabilities from bundle " + bundle, e);
             }
         }
 
@@ -95,13 +96,13 @@ public class ProviderBundleTrackerCustom
         }
 
         if (providedServices == null) {
-            log(LogService.LOG_DEBUG, "No '"
+            log(Level.FINE, "No '"
                     + SpiFlyConstants.SPI_PROVIDER_HEADER
                     + "' Manifest header. Skipping bundle: "
                     + bundle.getSymbolicName());
             return null;
         } else {
-            log(LogService.LOG_INFO, "Examining bundle for SPI provider: "
+            log(Level.INFO, "Examining bundle for SPI provider: "
                     + bundle.getSymbolicName());
         }
 
@@ -134,7 +135,7 @@ public class ProviderBundleTrackerCustom
 
         final List<ServiceRegistration> registrations = new ArrayList<ServiceRegistration>();
         for (URL serviceFileURL : serviceFileURLs) {
-            log(LogService.LOG_INFO, "Found SPI resource: " + serviceFileURL);
+            log(Level.INFO, "Found SPI resource: " + serviceFileURL);
 
             try {
                 BufferedReader reader = new BufferedReader(
@@ -161,7 +162,7 @@ public class ProviderBundleTrackerCustom
                             continue;
 
                         final Class<?> cls = bundle.loadClass(className);
-                        log(LogService.LOG_INFO, "Loaded SPI provider: " + cls);
+                        log(Level.INFO, "Loaded SPI provider: " + cls);
 
                         final Hashtable<String, Object> properties;
                         if (fromSPIProviderHeader)
@@ -180,7 +181,7 @@ public class ProviderBundleTrackerCustom
                                     reg = bundle.getBundleContext().registerService(
                                             registrationClassName, new ProviderServiceFactory(cls), properties);
                                 } else {
-                                    log(LogService.LOG_INFO, "Bundle " + bundle + " does not have the permission to register services of type: " + registrationClassName);
+                                    log(Level.INFO, "Bundle " + bundle + " does not have the permission to register services of type: " + registrationClassName);
                                 }
                             } else {
                                 reg = bundle.getBundleContext().registerService(
@@ -189,19 +190,19 @@ public class ProviderBundleTrackerCustom
 
                             if (reg != null) {
                                 registrations.add(reg);
-                                log(LogService.LOG_INFO, "Registered service: " + reg);
+                                log(Level.INFO, "Registered service: " + reg);
                             }
                         }
 
                         activator.registerProviderBundle(registrationClassName, bundle, customAttributes);
-                        log(LogService.LOG_INFO, "Registered provider: " + registrationClassName + " in bundle " + bundle.getSymbolicName());
+                        log(Level.INFO, "Registered provider: " + registrationClassName + " in bundle " + bundle.getSymbolicName());
                     } catch (Exception e) {
-                        log(LogService.LOG_WARNING,
+                        log(Level.WARNING,
                                 "Could not load SPI implementation referred from " + serviceFileURL, e);
                     }
                 }
             } catch (IOException e) {
-                log(LogService.LOG_WARNING, "Could not read SPI metadata from " + serviceFileURL, e);
+                log(Level.WARNING, "Could not read SPI metadata from " + serviceFileURL, e);
             }
         }
 
@@ -334,7 +335,7 @@ public class ProviderBundleTrackerCustom
                 }
             }
         } catch (IOException e) {
-            log(LogService.LOG_ERROR, "Problem opening embedded jar file: " + url, e);
+            log(Level.SEVERE, "Problem opening embedded jar file: " + url, e);
         }
         return urls;
     }
@@ -360,10 +361,12 @@ public class ProviderBundleTrackerCustom
         return reqsCaps;
     }
 
+    @Override
     public void modifiedBundle(Bundle bundle, BundleEvent event, Object registrations) {
         // should really be doing something here...
     }
 
+    @Override
     @SuppressWarnings("unchecked")
     public void removedBundle(Bundle bundle, BundleEvent event, Object registrations) {
         activator.unregisterProviderBundle(bundle);
@@ -373,15 +376,15 @@ public class ProviderBundleTrackerCustom
 
         for (ServiceRegistration reg : (List<ServiceRegistration>) registrations) {
             reg.unregister();
-            log(LogService.LOG_INFO, "Unregistered: " + reg);
+            log(Level.INFO, "Unregistered: " + reg);
         }
     }
 
-    private void log(int level, String message) {
+    private void log(Level level, String message) {
         activator.log(level, message);
     }
 
-    private void log(int level, String message, Throwable th) {
+    private void log(Level level, String message, Throwable th) {
         activator.log(level, message, th);
     }
 

Modified: aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/Util.java
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/Util.java?rev=1845282&r1=1845281&r2=1845282&view=diff
==============================================================================
--- aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/Util.java (original)
+++ aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/Util.java Tue Oct 30 21:27:52 2018
@@ -34,12 +34,12 @@ import java.util.Map;
 import java.util.ServiceLoader;
 import java.util.jar.JarEntry;
 import java.util.jar.JarInputStream;
+import java.util.logging.Level;
 
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleReference;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServicePermission;
-import org.osgi.service.log.LogService;
 
 /**
  * Methods used from ASM-generated code. They store, change and reset the thread context classloader.
@@ -80,7 +80,7 @@ public class Util {
         ClassLoader bundleLoader = caller.getClassLoader();
 
         if (!(bundleLoader instanceof BundleReference)) {
-            BaseActivator.activator.log(LogService.LOG_WARNING, "Classloader of consuming bundle doesn't implement BundleReference: " + bundleLoader);
+            BaseActivator.activator.log(Level.WARNING, "Classloader of consuming bundle doesn't implement BundleReference: " + bundleLoader);
             return ServiceLoader.load(service);
         }
 
@@ -118,7 +118,7 @@ public class Util {
         ClassLoader bundleLoader = caller.getClassLoader();
 
         if (!(bundleLoader instanceof BundleReference)) {
-            BaseActivator.activator.log(LogService.LOG_WARNING, "Classloader of consuming bundle doesn't implement BundleReference: " + bundleLoader);
+            BaseActivator.activator.log(Level.WARNING, "Classloader of consuming bundle doesn't implement BundleReference: " + bundleLoader);
             return ServiceLoader.load(service, specifiedClassLoader);
         }
 
@@ -143,7 +143,7 @@ public class Util {
 
         final ClassLoader cl = findContextClassloader(br.getBundle(), cls, method, clsArg);
         if (cl != null) {
-            BaseActivator.activator.log(LogService.LOG_INFO, "Temporarily setting Thread Context Classloader to: " + cl);
+            BaseActivator.activator.log(Level.INFO, "Temporarily setting Thread Context Classloader to: " + cl);
             AccessController.doPrivileged(new PrivilegedAction<Void>() {
                 @Override
                 public Void run() {
@@ -152,7 +152,7 @@ public class Util {
                 }
             });
         } else {
-            BaseActivator.activator.log(LogService.LOG_WARNING, "No classloader found for " + cls + ":" + method + "(" + clsArg + ")");
+            BaseActivator.activator.log(Level.WARNING, "No classloader found for " + cls + ":" + method + "(" + clsArg + ")");
         }
     }
 
@@ -172,7 +172,7 @@ public class Util {
                     sm.checkPermission(new ServicePermission(requestedClass, ServicePermission.GET));
                 } catch (AccessControlException ace) {
                     // access denied
-                    activator.log(LogService.LOG_INFO, "No permission to obtain service of type: " + requestedClass);
+                    activator.log(Level.INFO, "No permission to obtain service of type: " + requestedClass);
                     return null;
                 }
             }
@@ -182,7 +182,7 @@ public class Util {
         }
 
         Collection<Bundle> bundles = new ArrayList<Bundle>(activator.findProviderBundles(requestedClass));
-        activator.log(LogService.LOG_DEBUG, "Found bundles providing " + requestedClass + ": " + bundles);
+        activator.log(Level.FINE, "Found bundles providing " + requestedClass + ": " + bundles);
 
         Collection<Bundle> allowedBundles = activator.findConsumerRestrictions(consumerBundle, className, methodName, args);
 
@@ -298,7 +298,7 @@ public class Util {
         }
 
         if (!(bundleLoader instanceof BundleReference)) {
-            BaseActivator.activator.log(LogService.LOG_WARNING, "Classloader of consuming bundle doesn't implement BundleReference: " + bundleLoader);
+            BaseActivator.activator.log(Level.WARNING, "Classloader of consuming bundle doesn't implement BundleReference: " + bundleLoader);
             return null;
         }
 
@@ -325,7 +325,7 @@ public class Util {
                     jis.close();
             }
         } catch (IOException e) {
-            BaseActivator.activator.log(LogService.LOG_ERROR, "Problem loading class from embedded jar file: " + url +
+            BaseActivator.activator.log(Level.SEVERE, "Problem loading class from embedded jar file: " + url +
                 " in bundle " + b.getSymbolicName(), e);
         }
         return null;

Modified: aries/trunk/spi-fly/spi-fly-dynamic-bundle/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-dynamic-bundle/pom.xml?rev=1845282&r1=1845281&r2=1845282&view=diff
==============================================================================
--- aries/trunk/spi-fly/spi-fly-dynamic-bundle/pom.xml (original)
+++ aries/trunk/spi-fly/spi-fly-dynamic-bundle/pom.xml Tue Oct 30 21:27:52 2018
@@ -64,11 +64,6 @@
                     <groupId>org.osgi</groupId>
                     <artifactId>org.osgi.core</artifactId>
                 </exclusion>
-
-                <exclusion>
-                    <groupId>org.osgi</groupId>
-                    <artifactId>org.osgi.compendium</artifactId>
-                </exclusion>
             </exclusions>
         </dependency>
 
@@ -84,12 +79,6 @@
             <scope>provided</scope>
         </dependency>
 
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.compendium</artifactId>
-            <scope>provided</scope>
-        </dependency>
-
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>

Modified: aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/main/java/org/apache/aries/spifly/dynamic/ClientWeavingHook.java
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/main/java/org/apache/aries/spifly/dynamic/ClientWeavingHook.java?rev=1845282&r1=1845281&r2=1845282&view=diff
==============================================================================
--- aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/main/java/org/apache/aries/spifly/dynamic/ClientWeavingHook.java (original)
+++ aries/trunk/spi-fly/spi-fly-dynamic-bundle/src/main/java/org/apache/aries/spifly/dynamic/ClientWeavingHook.java Tue Oct 30 21:27:52 2018
@@ -21,6 +21,7 @@ package org.apache.aries.spifly.dynamic;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.util.Set;
+import java.util.logging.Level;
 
 import org.apache.aries.spifly.Util;
 import org.apache.aries.spifly.WeavingData;
@@ -34,7 +35,6 @@ import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.hooks.weaving.WeavingHook;
 import org.osgi.framework.hooks.weaving.WovenClass;
-import org.osgi.service.log.LogService;
 
 public class ClientWeavingHook implements WeavingHook {
     private final String addedImport;
@@ -51,7 +51,7 @@ public class ClientWeavingHook implement
         Bundle consumerBundle = wovenClass.getBundleWiring().getBundle();
         Set<WeavingData> wd = activator.getWeavingData(consumerBundle);
         if (wd != null) {
-            activator.log(LogService.LOG_DEBUG, "Weaving class " + wovenClass.getClassName());
+            activator.log(Level.FINE, "Weaving class " + wovenClass.getClassName());
 
             ClassReader cr = new ClassReader(wovenClass.getBytes());
             ClassWriter cw = new OSGiFriendlyClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES,
@@ -62,13 +62,13 @@ public class ClientWeavingHook implement
                 wovenClass.setBytes(cw.toByteArray());
                 if (tsv.additionalImportRequired())
                     wovenClass.getDynamicImports().add(addedImport);
-                if (activator.isLogEnabled(Integer.MAX_VALUE)) {
+                if (activator.isLogEnabled(Level.FINEST)) {
                     StringWriter stringWriter = new StringWriter();
                     ClassReader reader = new ClassReader(wovenClass.getBytes());
                     ClassVisitor tracer = new TraceClassVisitor(new PrintWriter(stringWriter));
                     ClassVisitor checker = new CheckClassAdapter(tracer, true);
                     reader.accept(checker, 0);
-                    activator.log(Integer.MAX_VALUE, "Woven class bytecode: \n" + stringWriter.toString());
+                    activator.log(Level.FINEST, "Woven class bytecode: \n" + stringWriter.toString());
                 }
             }
         }

Modified: aries/trunk/spi-fly/spi-fly-dynamic-framework-extension/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-dynamic-framework-extension/pom.xml?rev=1845282&r1=1845281&r2=1845282&view=diff
==============================================================================
--- aries/trunk/spi-fly/spi-fly-dynamic-framework-extension/pom.xml (original)
+++ aries/trunk/spi-fly/spi-fly-dynamic-framework-extension/pom.xml Tue Oct 30 21:27:52 2018
@@ -70,13 +70,6 @@
             <version>1.1-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
-
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.compendium</artifactId>
-            <scope>provided</scope>
-        </dependency>
-
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>

Modified: aries/trunk/spi-fly/spi-fly-static-bundle/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-static-bundle/pom.xml?rev=1845282&r1=1845281&r2=1845282&view=diff
==============================================================================
--- aries/trunk/spi-fly/spi-fly-static-bundle/pom.xml (original)
+++ aries/trunk/spi-fly/spi-fly-static-bundle/pom.xml Tue Oct 30 21:27:52 2018
@@ -60,12 +60,6 @@
             <artifactId>org.osgi.core</artifactId>
             <scope>provided</scope>
         </dependency>
-
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.compendium</artifactId>
-            <scope>provided</scope>
-        </dependency>
     </dependencies>
 
     <build>