Commits

Jon Mort committed 8584870

initial commit

  • Participants

Comments (0)

Files changed (22)

+# use glob syntax.
+syntax: glob
+
+*.iml
+*.ipr
+*.iws
+*.DS_Store
+target
+To avoid future confusion, we recommend that you include a license with your plugin.
+This file is simply a reminder.
+
+For a template license you can have a look at: http://www.opensource.org/licenses/
+
+Atlassian releases most of its modules under a BSD license: http://www.opensource.org/licenses/bsd-license.php

File consumer-dynamic/pom.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+         xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <artifactId>plugins-bug</artifactId>
+        <groupId>com.adaptavist.plugin.bug</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <artifactId>consumer-dynamic</artifactId>
+    <packaging>atlassian-plugin</packaging>
+    <name>Dynamic Import Consumer of the service to show the bug</name>
+    <description>This plugin is designed to show a bug in the plugins system. It consumes one service via a dynamic Import.</description>
+    <organization>
+        <name>Adaptavist.com Ltd.</name>
+        <url>http://www.adaptavist.com/</url>
+    </organization>
+    <developers>
+        <developer>
+            <name>Jonathan Mort</name>
+            <email>jmort@adaptavist.com</email>
+        </developer>
+    </developers>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>com.atlassian.maven.plugins</groupId>
+                <artifactId>maven-refapp-plugin</artifactId>
+                <version>3.2.4</version>
+                <extensions>true</extensions>
+            </plugin>
+            <plugin>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.5</source>
+                    <target>1.5</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    <dependencies>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+            <version>2.4</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.adaptavist.plugin.bug</groupId>
+            <artifactId>service-provider</artifactId>
+            <version>${project.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+            <version>4.2.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>4.2.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.osgi</groupId>
+            <artifactId>spring-osgi-core</artifactId>
+            <version>1.2.1</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+</project>

File consumer-dynamic/src/main/java/com/adaptavist/plugin/bug/consumer/MyDynamicDictionary.java

+package com.adaptavist.plugin.bug.consumer;
+
+import com.adaptavist.plugin.bug.service.Dictionary;
+
+public class MyDynamicDictionary implements Dictionary {
+    public String getDefinition(String text) {
+        return "Dynamic: " + text;
+    }
+}

File consumer-dynamic/src/main/resources/atlassian-plugin.xml

+<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.name}" plugins-version="2">
+    <plugin-info>
+        <description>${project.description}</description>
+        <version>${project.version}</version>
+        <vendor name="${project.organization.name}" url="${project.organization.url}"/>
+        <bundle-instructions>
+            <DynamicImport-Package>com.adaptavist.plugin.bug.service</DynamicImport-Package>
+            <Import-Package>!com.adaptavist.plugin.bug.service;*;resolution:=optional</Import-Package>
+        </bundle-instructions>
+    </plugin-info>
+
+    <dictionary key="myDynamicDictionary" lang="dynamic" class="com.adaptavist.plugin.bug.consumer.MyDynamicDictionary" />
+
+</atlassian-plugin>

File consumer/pom.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+         xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <artifactId>plugins-bug</artifactId>
+        <groupId>com.adaptavist.plugin.bug</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <artifactId>consumer</artifactId>
+    <packaging>atlassian-plugin</packaging>
+    <name>Consumer of the service to show the bug</name>
+    <description>This plugin is designed to show a bug in the plugins system. It consumes one service.</description>
+    <organization>
+        <name>Adaptavist.com Ltd.</name>
+        <url>http://www.adaptavist.com/</url>
+    </organization>
+    <developers>
+        <developer>
+            <name>Jonathan Mort</name>
+            <email>jmort@adaptavist.com</email>
+        </developer>
+    </developers>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>com.atlassian.maven.plugins</groupId>
+                <artifactId>maven-refapp-plugin</artifactId>
+                <version>3.2.4</version>
+                <extensions>true</extensions>
+            </plugin>
+            <plugin>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.5</source>
+                    <target>1.5</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    <dependencies>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+            <version>2.4</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.adaptavist.plugin.bug</groupId>
+            <artifactId>service-provider</artifactId>
+            <version>${project.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+            <version>4.2.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>4.2.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.osgi</groupId>
+            <artifactId>spring-osgi-core</artifactId>
+            <version>1.2.1</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+</project>

File consumer/src/main/java/com/adaptavist/plugin/bug/consumer/MyDictionary.java

+package com.adaptavist.plugin.bug.consumer;
+
+import com.adaptavist.plugin.bug.service.Dictionary;
+
+public class MyDictionary implements Dictionary {
+    public String getDefinition(String text) {
+        return "No Config: " + text;
+    }
+}

File consumer/src/main/resources/atlassian-plugin.xml

+<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.name}" plugins-version="2">
+    <plugin-info>
+        <description>${project.description}</description>
+        <version>${project.version}</version>
+        <vendor name="${project.organization.name}" url="${project.organization.url}"/>
+    </plugin-info>
+
+    <dictionary key="myEnglishDictionary" lang="english" class="com.adaptavist.plugin.bug.consumer.MyDictionary" />
+
+</atlassian-plugin>

File osgi-logger/pom.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>com.adaptavist.plugin.bug</groupId>
+        <artifactId>plugins-bug</artifactId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <organization>
+        <name>Adaptavist.com Ltd.</name>
+        <url>http://www.adaptavist.com/</url>
+    </organization>
+    <developers>
+        <developer>
+            <name>Jonathan Mort</name>
+            <email>jmort@adaptavist.com</email>
+        </developer>
+    </developers>
+
+    <artifactId>osgi-logger</artifactId>
+    <name>OSGi Logger Plugin</name>
+    <packaging>atlassian-plugin</packaging>
+    <description>Plugin for logging OSGi Activity</description>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>com.atlassian.maven.plugins</groupId>
+                <artifactId>maven-amps-plugin</artifactId>
+                <extensions>true</extensions>
+                <version>3.2.4</version>
+                <configuration>
+                    <instructions>
+                        <Import-Package>
+                            org.springframework.osgi.context;version="1.2",
+                            org.osgi.framework;version="1.4",
+                            org.osgi.util.tracker;version="1.4",
+                            org.slf4j;version="1.5"
+                        </Import-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>4.1.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>1.5.10</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.osgi</groupId>
+            <artifactId>spring-osgi-core</artifactId>
+            <version>1.2.1</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+</project>

File osgi-logger/src/main/java/com/adaptavist/plugin/osgi/logger/LoggerComponent.java

+package com.adaptavist.plugin.osgi.logger;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.osgi.context.BundleContextAware;
+
+public class LoggerComponent implements BundleContextAware, BundleListener {
+    private final Logger log = LoggerFactory.getLogger(LoggerComponent.class);
+
+    public void setBundleContext(BundleContext bundleContext) {
+        bundleContext.addBundleListener(this);
+    }
+
+    public void bundleChanged(BundleEvent event) {
+        log.warn("OSGi Event, Type {}, Bundle {}",
+                getTypeString(event),
+                event.getBundle());
+    }
+
+    private String getTypeString(BundleEvent event) {
+        switch(event.getType()) {
+            case BundleEvent.INSTALLED: return "INSTALLED";
+            case BundleEvent.LAZY_ACTIVATION: return "LAZY_ACTIVATION";
+            case BundleEvent.RESOLVED: return "RESOLVED";
+            case BundleEvent.STARTED: return "STARTED";
+            case BundleEvent.STARTING: return "STARTING";
+            case BundleEvent.STOPPED: return "STOPPED";
+            case BundleEvent.STOPPING: return "STOPPING";
+            case BundleEvent.UNINSTALLED: return "UNINSTALLED";
+            case BundleEvent.UNRESOLVED: return "UNRESOLVED";
+            case BundleEvent.UPDATED: return "UPDATED";
+            default: return "!!!!UNKNOWN!!!!";
+        }
+    }
+}

File osgi-logger/src/main/resources/META-INF/spring/applicationContext.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+             xsi:schemaLocation="http://www.springframework.org/schema/beans
+                http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
+
+    <bean id="osgiLogger" class="com.adaptavist.plugin.osgi.logger.LoggerComponent" />
+</beans>

File osgi-logger/src/main/resources/atlassian-plugin.xml

+<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.name}" plugins-version="2">
+    <plugin-info>
+        <description>${project.description}</description>
+        <version>${project.version}</version>
+        <vendor name="${project.organization.name}" url="${project.organization.url}"/>
+    </plugin-info>
+    <component key="loggerComponent" class="com.adaptavist.plugin.osgi.logger.LoggerComponent" />
+</atlassian-plugin>
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>com.adaptavist.plugin.bug</groupId>
+    <artifactId>plugins-bug</artifactId>
+    <packaging>pom</packaging>
+    <name>Plugin Bug Base POM</name>
+    <version>1.0-SNAPSHOT</version>
+    <organization>
+        <name>Adaptavist.com Ltd.</name>
+        <url>http://www.adaptavist.com/</url>
+    </organization>
+    <developers>
+        <developer>
+            <name>Jonathan Mort</name>
+            <email>jmort@adaptavist.com</email>
+        </developer>
+    </developers>
+    <modules>
+        <module>osgi-logger</module>
+    <module>service-provider</module>
+    <module>consumer</module>
+    <module>consumer-dynamic</module>
+    <module>tester</module>
+  </modules>
+</project>

File service-provider/pom.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+         xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <artifactId>plugins-bug</artifactId>
+        <groupId>com.adaptavist.plugin.bug</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <artifactId>service-provider</artifactId>
+    <packaging>atlassian-plugin</packaging>
+    <name>Service Provider</name>
+    <description>This service provides a single service</description>
+    <organization>
+        <name>Adaptavist.com Ltd.</name>
+        <url>http://www.adaptavist.com/</url>
+    </organization>
+    <developers>
+        <developer>
+            <name>Jonathan Mort</name>
+            <email>jmort@adaptavist.com</email>
+        </developer>
+    </developers>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>com.atlassian.maven.plugins</groupId>
+                <artifactId>maven-refapp-plugin</artifactId>
+                <version>3.2.4</version>
+                <extensions>true</extensions>
+            </plugin>
+            <plugin>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.5</source>
+                    <target>1.5</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    <dependencies>
+        <dependency>
+            <groupId>com.atlassian.plugins</groupId>
+            <artifactId>atlassian-plugins-core</artifactId>
+            <version>2.6.4</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+            <version>2.4</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+</project>

File service-provider/src/main/java/com/adaptavist/plugin/bug/service/BugDemoService.java

+package com.adaptavist.plugin.bug.service;
+
+public interface BugDemoService {
+    String message();
+}

File service-provider/src/main/java/com/adaptavist/plugin/bug/service/Dictionary.java

+package com.adaptavist.plugin.bug.service;
+
+public interface Dictionary {
+    String getDefinition(String text);
+}

File service-provider/src/main/java/com/adaptavist/plugin/bug/service/internal/BugDemoServiceImpl.java

+package com.adaptavist.plugin.bug.service.internal;
+
+import com.adaptavist.plugin.bug.service.BugDemoService;
+
+public class BugDemoServiceImpl implements BugDemoService {
+
+    public String message() {
+        return "Hello Service World";
+    }
+}

File service-provider/src/main/java/com/adaptavist/plugin/bug/service/internal/DictionaryModuleDescriptor.java

+package com.adaptavist.plugin.bug.service.internal;
+
+import com.adaptavist.plugin.bug.service.Dictionary;
+import com.atlassian.plugin.Plugin;
+import com.atlassian.plugin.PluginParseException;
+import com.atlassian.plugin.descriptors.AbstractModuleDescriptor;
+import com.atlassian.plugin.module.ModuleFactory;
+import org.dom4j.Element;
+
+public class DictionaryModuleDescriptor extends AbstractModuleDescriptor<Dictionary> {
+    private String language;
+
+    public DictionaryModuleDescriptor(ModuleFactory moduleFactory) {
+        super(moduleFactory);
+    }
+
+    @Override
+    public void init(Plugin plugin, Element element) throws PluginParseException {
+        super.init(plugin, element);
+        language = element.attributeValue("lang");
+    }
+
+    public Dictionary getModule() {
+        return moduleFactory.createModule(moduleClassName, this);
+    }
+
+    public String getLanguage() {
+        return language;
+    }
+}

File service-provider/src/main/java/com/adaptavist/plugin/bug/service/internal/ExampleServlet.java

+package com.adaptavist.plugin.bug.service.internal;
+
+import com.atlassian.plugin.ModuleDescriptor;
+import com.atlassian.plugin.PluginAccessor;
+import com.atlassian.plugin.predicate.ModuleDescriptorPredicate;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class ExampleServlet extends HttpServlet {
+
+    private final PluginAccessor pluginAccessor;
+
+    public ExampleServlet(PluginAccessor pluginAccessor) {
+        this.pluginAccessor = pluginAccessor;
+    }
+
+    @Override
+    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+        // To get all the enabled modules of this module descriptor
+        List<DictionaryModuleDescriptor> dictionaryModuleDescriptors =
+                pluginAccessor.getEnabledModuleDescriptorsByClass(DictionaryModuleDescriptor.class);
+        // Now we'll use each one to get a map of languages to translations of the word "OSGi"
+        Map<String, String> results = new HashMap<String, String>();
+        for (DictionaryModuleDescriptor dictionaryModuleDescriptor : dictionaryModuleDescriptors) {
+            try {
+            results.put(dictionaryModuleDescriptor.getLanguage(),
+                    dictionaryModuleDescriptor.getModule().getDefinition("OSGi"));
+            } catch (ClassCastException howCanThisBe) {
+                results.put("class Cast Exception", howCanThisBe.getMessage());
+            }
+        }
+
+        resp.getWriter().print(dictionaryModuleDescriptors.size());
+        resp.getWriter().println(" Dictionaries found");
+        for (String key : results.keySet()) {
+            resp.getWriter().print(key);
+            resp.getWriter().print(" = ");
+            resp.getWriter().println(results.get(key));
+        }
+
+        Collection<Object> modules = pluginAccessor.getModules(new ModuleDescriptorPredicate<Object>() {
+            public boolean matches(ModuleDescriptor<? extends Object> moduleDescriptor) {
+                return moduleDescriptor.getClass().getName().equals(DictionaryModuleDescriptor.class.getName());
+            }
+        });
+
+        resp.getWriter().println("Now using predicate by name and reflection to do the call");
+        resp.getWriter().print(modules.size());
+        resp.getWriter().println(" Dictionaries found");
+        for (Object module : modules) {
+            resp.getWriter().println(reflectivlyCallGetDefinition(module));
+        }
+
+        resp.getWriter().close();
+    }
+
+    private String reflectivlyCallGetDefinition(Object module) {
+        Class clazz = module.getClass();
+        try {
+            Method getDefinition = clazz.getMethod("getDefinition", String.class);
+            return (String)getDefinition.invoke(module, "Reflection");
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+}

File service-provider/src/main/resources/atlassian-plugin.xml

+<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.name}" plugins-version="2">
+    <plugin-info>
+        <description>${project.description}</description>
+        <version>${project.version}</version>
+        <vendor name="${project.organization.name}" url="${project.organization.url}" />
+        <bundle-instructions>
+            <Export-Package>com.adaptavist.plugin.bug.service</Export-Package>
+        </bundle-instructions>
+    </plugin-info>
+
+    <module-type key="dictionary" class="com.adaptavist.plugin.bug.service.internal.DictionaryModuleDescriptor" />
+    <servlet name="dictionary-servlet" class="com.adaptavist.plugin.bug.service.internal.ExampleServlet" key="test">
+        <url-pattern>/test</url-pattern>
+    </servlet>
+</atlassian-plugin>

File tester/pom.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+         xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <artifactId>plugins-bug</artifactId>
+        <groupId>com.adaptavist.plugin.bug</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <artifactId>tester</artifactId>
+    <packaging>atlassian-plugin</packaging>
+    <name>Test Project</name>
+    <description>This project is just for launching the product</description>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>com.atlassian.maven.plugins</groupId>
+                <artifactId>maven-refapp-plugin</artifactId>
+                <version>3.2.4</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <pluginArtifacts>
+                        <pluginArtifact>
+                            <groupId>${project.groupId}</groupId>
+                            <artifactId>consumer</artifactId>
+                            <version>${project.version}</version>
+                        </pluginArtifact>
+                        <pluginArtifact>
+                            <groupId>${project.groupId}</groupId>
+                            <artifactId>service-provider</artifactId>
+                            <version>${project.version}</version>
+                        </pluginArtifact>
+                    </pluginArtifacts>
+                </configuration>
+            </plugin>
+            <plugin>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.5</source>
+                    <target>1.5</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>consumer</artifactId>
+            <type>${project.packaging}</type>
+            <version>${project.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>service-provider</artifactId>
+            <type>${project.packaging}</type>
+            <version>${project.version}</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+</project>

File tester/src/main/resources/placeholder.txt

Empty file added.