Samuel Le Berrigaud avatar Samuel Le Berrigaud committed a65308c

Re-add deprecated services for backward compatibility.

- TemplateRendererFactory
- VelocityTemplateRendererFactory

Comments (0)

Files changed (6)

api/src/main/java/com/atlassian/templaterenderer/TemplateRendererFactory.java

+package com.atlassian.templaterenderer;
+
+/**
+ * Factory for getting template renderers with a given classloader.
+ *
+ * @deprecated This factory is no longer needed. Plugins can import TemplateRenderer, and they will get a template
+ *             renderer appropriately initialised with the right bundle context.
+ */
+@Deprecated
+public interface TemplateRendererFactory
+{
+    TemplateRenderer getInstance(ClassLoader classLoader);
+}

velocity1.6/src/main/java/com/atlassian/templaterenderer/velocity/one/six/VelocityTemplateRendererFactory.java

+package com.atlassian.templaterenderer.velocity.one.six;
+
+import java.util.Map;
+
+import com.atlassian.templaterenderer.TemplateRenderer;
+import com.atlassian.templaterenderer.TemplateRendererFactory;
+
+/**
+ * Factory for plugins wanting to pass specific properties to a velocity template renderer
+ */
+@Deprecated
+public interface VelocityTemplateRendererFactory extends TemplateRendererFactory
+{
+    /**
+     * @deprecated This method is no longer needed, as the factory service imported by plugins will be one that already
+     *             knows what the plugins bundles classloader should be.  Use {@link #getInstance(Map<String, String>)}
+     *             instead.
+     */
+    @Deprecated TemplateRenderer getInstance(ClassLoader classLoader, Map<String, String> properties);
+
+    /**
+     * Get an instance of a velocity template renderer initialised with the given properties for the velocity engine
+     *
+     * @param properties The properties to initialise the template renderer with
+     * @return A template renderer
+     */
+    TemplateRenderer getInstance(Map<String, String> properties);
+}

velocity1.6/src/main/java/com/atlassian/templaterenderer/velocity/one/six/VelocityWebPanelRenderer.java

 import com.atlassian.templaterenderer.velocity.one.six.internal.VelocityTemplateRendererImpl;
 
 import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
 import java.util.Collections;
 
 /**
- * @since   2.5.0
+ * @since 2.5.0
  */
-public class VelocityWebPanelRenderer extends AbstractCachingWebPanelRenderer
+@Named
+@Singleton
+public final class VelocityWebPanelRenderer extends AbstractCachingWebPanelRenderer
 {
     private final TemplateContextFactory templateContextFactory;
 

velocity1.6/src/main/java/com/atlassian/templaterenderer/velocity/one/six/internal/VelocityTemplateRendererFactoryImpl.java

+package com.atlassian.templaterenderer.velocity.one.six.internal;
+
+import java.util.Collections;
+import java.util.Map;
+
+import com.atlassian.templaterenderer.TemplateRenderer;
+import com.atlassian.templaterenderer.TemplateContextFactory;
+import com.atlassian.templaterenderer.velocity.one.six.VelocityTemplateRendererFactory;
+
+/**
+ * Factory for instantiating customised velocity template renderers.  This factory will ensure that the velocity engine
+ * created has the right class loader, and that all templates are resolved from the right classloader.
+ */
+@Deprecated
+public final class VelocityTemplateRendererFactoryImpl implements VelocityTemplateRendererFactory
+{
+    private final TemplateContextFactory templateContextFactory;
+    private final String pluginKey;
+    private final ClassLoader classLoader;
+
+    public VelocityTemplateRendererFactoryImpl(TemplateContextFactory templateContextFactory, String pluginKey,
+                                               ClassLoader classLoader)
+    {
+        this.templateContextFactory = templateContextFactory;
+        this.pluginKey = pluginKey;
+        this.classLoader = classLoader;
+    }
+
+    public TemplateRenderer getInstance(ClassLoader classLoader)
+    {
+        return getInstance(classLoader, Collections.<String, String>emptyMap());
+    }
+
+    public TemplateRenderer getInstance(ClassLoader classLoader, Map<String, String> properties)
+    {
+        return new VelocityTemplateRendererImpl(classLoader, pluginKey, properties, templateContextFactory);
+    }
+
+    public TemplateRenderer getInstance(Map<String, String> properties)
+    {
+        return new VelocityTemplateRendererImpl(classLoader, pluginKey, properties, templateContextFactory);
+    }
+}

velocity1.6/src/main/java/com/atlassian/templaterenderer/velocity/one/six/internal/VelocityTemplateRendererFactoryServiceFactory.java

+package com.atlassian.templaterenderer.velocity.one.six.internal;
+
+import com.atlassian.plugin.remotable.api.annotation.ComponentImport;
+import com.atlassian.plugin.remotable.api.annotation.PublicComponent;
+import com.atlassian.templaterenderer.BundleClassLoaderAccessor;
+import com.atlassian.templaterenderer.TemplateContextFactory;
+import com.atlassian.templaterenderer.TemplateRenderer;
+import com.atlassian.templaterenderer.TemplateRendererFactory;
+import com.atlassian.templaterenderer.velocity.one.six.VelocityTemplateRendererFactory;
+import com.google.inject.Inject;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
+
+import java.util.Map;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Service factory for instantiating velocity template renderer factories.  This will make sure the factory knows about
+ * the importing bundles class loader and plugin key.
+ */
+////////////////////
+// TODO: Once plugins has upgraded to Spring DM 1.2, remove implements VelocityTemplateRendererFactory.  This exists to
+// workaround the bug fixed in https://fisheye.springsource.org/changelog/spring-osgi?cs=2071
+////////////////////
+@PublicComponent({TemplateRendererFactory.class, VelocityTemplateRendererFactory.class})
+@Deprecated
+public final class VelocityTemplateRendererFactoryServiceFactory implements ServiceFactory
+{
+    /**
+     * This can be replaced with OsgiPlugin.ATLASSIAN_PLUGIN_KEY once we update to the latest version
+     */
+    private static final String ATLASSIAN_PLUGIN_KEY = "Atlassian-Plugin-Key";
+    private final TemplateContextFactory templateContextFactory;
+
+    @Inject
+    public VelocityTemplateRendererFactoryServiceFactory(@ComponentImport TemplateContextFactory templateContextFactory)
+    {
+        this.templateContextFactory = checkNotNull(templateContextFactory);
+    }
+
+    public Object getService(Bundle bundle, ServiceRegistration serviceRegistration)
+    {
+        String pluginKey = (String) bundle.getHeaders().get(ATLASSIAN_PLUGIN_KEY);
+        // We want velocity to use the callers classloader
+        ClassLoader bundleClassLoader = BundleClassLoaderAccessor.getClassLoader(bundle);
+        return new VelocityTemplateRendererFactoryImpl(templateContextFactory, pluginKey, bundleClassLoader);
+    }
+
+    public void ungetService(Bundle bundle, ServiceRegistration serviceRegistration, Object o)
+    {
+    }
+
+    ///////////////////
+    // TODO: Once plugins has upgraded to Spring DM 1.2, remove this code
+    ///////////////////
+    public TemplateRenderer getInstance(ClassLoader classLoader, Map<String, String> properties)
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public TemplateRenderer getInstance(Map<String, String> properties)
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public TemplateRenderer getInstance(ClassLoader classLoader)
+    {
+        throw new UnsupportedOperationException();
+    }
+    //////////////////
+    // END TODO
+    //////////////////
+}

velocity1.6/src/main/java/com/atlassian/templaterenderer/velocity/one/six/internal/VelocityTemplateRendererServiceFactory.java

 package com.atlassian.templaterenderer.velocity.one.six.internal;
 
 import com.atlassian.plugin.osgi.factory.OsgiPlugin;
+import com.atlassian.plugin.remotable.api.annotation.ComponentImport;
 import com.atlassian.plugin.remotable.api.annotation.PublicComponent;
+import com.atlassian.templaterenderer.BundleClassLoaderAccessor;
+import com.atlassian.templaterenderer.TemplateContextFactory;
 import com.atlassian.templaterenderer.TemplateRenderer;
 import com.atlassian.templaterenderer.velocity.one.six.VelocityTemplateRenderer;
-import org.osgi.framework.ServiceFactory;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceFactory;
 import org.osgi.framework.ServiceRegistration;
-import com.atlassian.templaterenderer.BundleClassLoaderAccessor;
-import com.atlassian.templaterenderer.TemplateContextFactory;
 
 import javax.inject.Inject;
 import java.util.Collections;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 /**
  * Service factory for instantiating a template renderer for the given bundle
  */
 @PublicComponent({TemplateRenderer.class, VelocityTemplateRenderer.class})
-public class VelocityTemplateRendererServiceFactory implements ServiceFactory
+public final class VelocityTemplateRendererServiceFactory implements ServiceFactory
 {
     private final TemplateContextFactory templateContextFactory;
 
     @Inject
-    public VelocityTemplateRendererServiceFactory(TemplateContextFactory templateContextFactory)
+    public VelocityTemplateRendererServiceFactory(@ComponentImport TemplateContextFactory templateContextFactory)
     {
-        this.templateContextFactory = templateContextFactory;
+        this.templateContextFactory = checkNotNull(templateContextFactory);
     }
 
     public Object getService(Bundle bundle, ServiceRegistration serviceRegistration)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.