sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject [sling-ide-tooling] 14/14: SLING-5648 - Make Non-Eclipse Module regular Maven Packages
Date Thu, 05 Apr 2018 11:04:00 GMT
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch feature/intellij
in repository https://gitbox.apache.org/repos/asf/sling-ide-tooling.git

commit 88f99e046b7e3d33890b441ffc62b2bef743c348
Author: Robert Munteanu <rombert@apache.org>
AuthorDate: Tue Apr 3 17:23:23 2018 +0300

    SLING-5648 - Make Non-Eclipse Module regular Maven Packages
    
    Allow impl-vlt to contribute a PluginLogger without explicitly relying on eclipse-core.
---
 .../eclipse/core/debug/PluginLoggerRegistrar.java  | 62 +++++++++++++++++++---
 .../sling/ide/eclipse/core/debug/impl/Tracer.java  | 15 +++---
 .../sling/ide/eclipse/core/internal/Activator.java | 11 +++-
 .../sling/ide/eclipse/m2e/internal/Activator.java  |  2 +-
 .../ide/eclipse/sightly/internal/Activator.java    |  2 +-
 .../sling/ide/eclipse/ui/internal/Activator.java   |  2 +-
 shared/modules/impl-vlt/bnd.bnd                    |  1 +
 .../sling/ide/impl/vlt/VltRepositoryFactory.java   |  4 +-
 .../vlt/serialization/VltSerializationManager.java |  1 -
 9 files changed, 78 insertions(+), 22 deletions(-)

diff --git a/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/debug/PluginLoggerRegistrar.java
b/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/debug/PluginLoggerRegistrar.java
index 969a756..25b40fc 100644
--- a/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/debug/PluginLoggerRegistrar.java
+++ b/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/debug/PluginLoggerRegistrar.java
@@ -18,38 +18,84 @@ package org.apache.sling.ide.eclipse.core.debug;
 
 import java.util.Dictionary;
 import java.util.Hashtable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 
 import org.apache.sling.ide.eclipse.core.debug.impl.Tracer;
 import org.apache.sling.ide.log.Logger;
-import org.eclipse.core.runtime.Plugin;
 import org.eclipse.osgi.service.debug.DebugOptions;
 import org.eclipse.osgi.service.debug.DebugOptionsListener;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
 import org.osgi.framework.ServiceRegistration;
 
 /**
  * The <tt>PluginLoggerRegistrar</tt> registers {@link Logger} implementations
for use for specific plugins
  *
  */
-public class PluginLoggerRegistrar {
+public class PluginLoggerRegistrar implements BundleListener {
+    
+    private final ConcurrentMap<Long, ServiceRegistration<Logger>> registrations
= new ConcurrentHashMap<>();
 
     /**
-     * Registers a new tracer for the specified plugin
+     * Registers a new tracer for the specified bundle
      * 
-     * @param plugin the plugin to register for
+     * @param bundle the bundle to register for
      * @return the service registration
      */
-    public static ServiceRegistration<Logger> register(Plugin plugin) {
+    public static ServiceRegistration<Logger> register(Bundle bundle) {
 
         Dictionary<String, Object> props = new Hashtable<>();
-        props.put(DebugOptions.LISTENER_SYMBOLICNAME, plugin.getBundle().getSymbolicName());
-        BundleContext ctx = plugin.getBundle().getBundleContext();
+        props.put(DebugOptions.LISTENER_SYMBOLICNAME, bundle.getSymbolicName());
+        BundleContext ctx = bundle.getBundleContext();
         
         // safe to downcast since we are registering the Tracer which implements Logger
         @SuppressWarnings("unchecked")
         ServiceRegistration<Logger> serviceRegistration = (ServiceRegistration<Logger>)
ctx.registerService(new String[] { DebugOptionsListener.class.getName(), Logger.class.getName()
},
-                new Tracer(plugin), props);
+                new Tracer(bundle), props);
+        
         
         return serviceRegistration;
     }
+
+    public void init(Bundle[] bundles) {
+        for ( Bundle bundle : bundles )
+            registerIfEnabled(bundle);
+    }
+    
+    public void shutdown() {
+        for ( ServiceRegistration<Logger> reg : registrations.values() ) 
+            reg.unregister();
+    }
+    
+    @Override
+    public void bundleChanged(BundleEvent evt) {
+        switch ( evt.getType() ) {
+            case BundleEvent.STARTED:
+                registerIfEnabled(evt.getBundle());
+                break;
+                
+            case BundleEvent.STOPPING:
+                unregister(evt.getBundle());
+                break;
+        }
+    }
+
+    private void unregister(Bundle bundle) {
+        ServiceRegistration<Logger> reg = registrations.remove(bundle.getBundleId());
+        if ( reg != null )
+            reg.unregister();
+        
+    }
+
+    private void registerIfEnabled(final Bundle bundle) {
+        String enabled = bundle.getHeaders().get("SlingIDE-PluginLoggerEnabled");
+        if ( Boolean.valueOf(enabled)) {
+            System.out.println("Registering for bundle " + bundle.getSymbolicName());
+            ServiceRegistration<Logger> reg = register(bundle);
+            registrations.put(bundle.getBundleId(), reg);
+        }
+    }
 }
diff --git a/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/debug/impl/Tracer.java
b/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/debug/impl/Tracer.java
index d5abe22..cea6f88 100644
--- a/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/debug/impl/Tracer.java
+++ b/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/debug/impl/Tracer.java
@@ -20,12 +20,13 @@ import java.util.Date;
 
 import org.apache.sling.ide.log.Logger;
 import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Plugin;
+import org.eclipse.core.runtime.Platform;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.osgi.service.debug.DebugOptions;
 import org.eclipse.osgi.service.debug.DebugOptionsListener;
 import org.eclipse.osgi.service.debug.DebugTrace;
 import org.eclipse.osgi.util.NLS;
+import org.osgi.framework.Bundle;
 
 /**
  * The <tt>Tracer</tt> is the default implementation of the <tt>Logger</tt>
@@ -34,20 +35,20 @@ public class Tracer implements DebugOptionsListener, Logger {
 
     private static final long PERF_IGNORE_THRESHOLD = 50;
 
-    private final Plugin plugin;
+    private final Bundle bundle;
     private boolean debugEnabled;
     private boolean consoleEnabled;
     private boolean performanceEnabled;
     private DebugTrace trace;
     
-    public Tracer(Plugin plugin) {
-        this.plugin = plugin;
+    public Tracer(Bundle bundle) {
+        this.bundle = bundle;
     }
 
     @Override
     public void optionsChanged(DebugOptions options) {
     	
-        String pluginId = plugin.getBundle().getSymbolicName();
+        String pluginId = bundle.getSymbolicName();
 
         debugEnabled = options.getBooleanOption(pluginId + "/debug", false);
         consoleEnabled = options.getBooleanOption(pluginId + "/debug/console", false) &&
debugEnabled;
@@ -73,7 +74,7 @@ public class Tracer implements DebugOptionsListener, Logger {
     private void writeToConsole(String message, Throwable t) {
 
         System.out.println("[" + Thread.currentThread().getName() + "] " + new Date() + "
"
-                + plugin.getBundle().getSymbolicName() + " : " + message);
+                + bundle.getSymbolicName() + " : " + message);
         if (t != null)
             t.printStackTrace(System.out);
     }
@@ -130,6 +131,6 @@ public class Tracer implements DebugOptionsListener, Logger {
     }
 
     private void logInternal(int statusCode, String message, Throwable cause) {
-        plugin.getLog().log(new Status(statusCode, plugin.getBundle().getSymbolicName(),
message, cause));
+        Platform.getLog(bundle).log(new Status(statusCode, bundle.getSymbolicName(), message,
cause));
     }
 }
diff --git a/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/Activator.java
b/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/Activator.java
index f3671d5..1cebe9c 100644
--- a/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/Activator.java
+++ b/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/Activator.java
@@ -70,11 +70,17 @@ public class Activator extends Plugin {
 
     private Preferences preferences;
 
+    private PluginLoggerRegistrar pluginLoggerRegistrar;
+
 	public void start(BundleContext context) throws Exception {
 		super.start(context);
 		plugin = this;
+		
+		pluginLoggerRegistrar = new PluginLoggerRegistrar();
+		pluginLoggerRegistrar.init(context.getBundles());
+        context.addBundleListener(pluginLoggerRegistrar);
 
-        tracerRegistration = PluginLoggerRegistrar.register(this);
+        tracerRegistration = PluginLoggerRegistrar.register(context.getBundle());
 
         eventAdmin = new ServiceTracker<>(context, EventAdmin.class, null);
         eventAdmin.open();
@@ -111,6 +117,9 @@ public class Activator extends Plugin {
 	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
 	 */
 	public void stop(BundleContext context) throws Exception {
+	    
+	    context.removeBundleListener(pluginLoggerRegistrar);
+	    pluginLoggerRegistrar.shutdown();
 
         tracerRegistration.unregister();
 
diff --git a/eclipse/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/m2e/internal/Activator.java
b/eclipse/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/m2e/internal/Activator.java
index 10ef667..2c7401d 100644
--- a/eclipse/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/m2e/internal/Activator.java
+++ b/eclipse/eclipse-m2e-ui/src/org/apache/sling/ide/eclipse/m2e/internal/Activator.java
@@ -62,7 +62,7 @@ public class Activator extends Plugin {
                 null);
         osgiClientFactory.open();
 
-        tracerRegistration = PluginLoggerRegistrar.register(this);
+        tracerRegistration = PluginLoggerRegistrar.register(context.getBundle());
 
         tracer = new ServiceTracker<>(context, tracerRegistration.getReference(), null);
         tracer.open();
diff --git a/eclipse/eclipse-sightly-core/src/org/apache/sling/ide/eclipse/sightly/internal/Activator.java
b/eclipse/eclipse-sightly-core/src/org/apache/sling/ide/eclipse/sightly/internal/Activator.java
index 554c372..42c07a0 100644
--- a/eclipse/eclipse-sightly-core/src/org/apache/sling/ide/eclipse/sightly/internal/Activator.java
+++ b/eclipse/eclipse-sightly-core/src/org/apache/sling/ide/eclipse/sightly/internal/Activator.java
@@ -39,7 +39,7 @@ public class Activator extends Plugin {
 
     public void start(BundleContext context) throws Exception {
         
-        loggerRegistration = PluginLoggerRegistrar.register(this);
+        loggerRegistration = PluginLoggerRegistrar.register(context.getBundle());
         loggerTracker = new ServiceTracker<>(context, loggerRegistration.getReference(),
null);
         loggerTracker.open();
         
diff --git a/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/Activator.java
b/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/Activator.java
index 27141be..c8864dc 100644
--- a/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/Activator.java
+++ b/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/Activator.java
@@ -59,7 +59,7 @@ public class Activator extends AbstractUIPlugin {
     public void start(BundleContext context) throws Exception {
         super.start(context);
 
-        tracerRegistration = PluginLoggerRegistrar.register(this);
+        tracerRegistration = PluginLoggerRegistrar.register(context.getBundle());
 
         serializationManager = new ServiceTracker<>(context, SerializationManager.class,
null);
         serializationManager.open();
diff --git a/shared/modules/impl-vlt/bnd.bnd b/shared/modules/impl-vlt/bnd.bnd
index 9906412..398eae2 100644
--- a/shared/modules/impl-vlt/bnd.bnd
+++ b/shared/modules/impl-vlt/bnd.bnd
@@ -2,3 +2,4 @@ Bundle-ActivationPolicy: lazy
 -exportcontents: ${packages;VERSIONED}
 -includeresource: plugin.xml, .options
 Bundle-SymbolicName: org.apache.sling.ide.impl-vlt;singleton:=true
+SlingIDE-PluginLoggerEnabled: true
\ No newline at end of file
diff --git a/shared/modules/impl-vlt/src/main/java/org/apache/sling/ide/impl/vlt/VltRepositoryFactory.java
b/shared/modules/impl-vlt/src/main/java/org/apache/sling/ide/impl/vlt/VltRepositoryFactory.java
index fab8329..5b3dc00 100644
--- a/shared/modules/impl-vlt/src/main/java/org/apache/sling/ide/impl/vlt/VltRepositoryFactory.java
+++ b/shared/modules/impl-vlt/src/main/java/org/apache/sling/ide/impl/vlt/VltRepositoryFactory.java
@@ -38,9 +38,9 @@ public class VltRepositoryFactory implements RepositoryFactory {
     @Reference
     private EventAdmin eventAdmin;
     
-    @Reference
+    @Reference(target = "(listener.symbolic.name=org.apache.sling.ide.impl-vlt)")
     private Logger logger;
-
+    
     private Map<String,VltRepository> repositoryMap = new HashMap<>();
 
     @Override
diff --git a/shared/modules/impl-vlt/src/main/java/org/apache/sling/ide/impl/vlt/serialization/VltSerializationManager.java
b/shared/modules/impl-vlt/src/main/java/org/apache/sling/ide/impl/vlt/serialization/VltSerializationManager.java
index 42909a6..a68475f 100644
--- a/shared/modules/impl-vlt/src/main/java/org/apache/sling/ide/impl/vlt/serialization/VltSerializationManager.java
+++ b/shared/modules/impl-vlt/src/main/java/org/apache/sling/ide/impl/vlt/serialization/VltSerializationManager.java
@@ -58,7 +58,6 @@ public class VltSerializationManager implements SerializationManager {
 
     static final String EXTENSION_XML = ".xml";
 
-    @Reference
     private VltSerializationDataBuilder builder;
     
     @Reference

-- 
To stop receiving notification emails like this one, please contact
rombert@apache.org.

Mime
View raw message