Commits

Don Brown  committed 3acce22

Update example to remotable plugins

  • Participants
  • Parent commits cc3c5c9

Comments (0)

Files changed (8)

 *.iws
 .idea
 target
+.cache
+data
     <name>Hello World Page App Plugin</name>
     <packaging>atlassian-plugin</packaging>
     <description>
-        A sample remote app plugin (universal binary) that shows a hello world general page.
+        A sample remote plugin (universal binary) that shows a hello world general page.
     </description>
 
     <dependencies>
         <dependency>
-            <groupId>com.atlassian.labs</groupId>
-            <artifactId>remoteapps-servlet-kit</artifactId>
-            <version>${remoteapps.version}</version>
+            <groupId>com.atlassian.plugins</groupId>
+            <artifactId>remotable-plugins-servlet-kit</artifactId>
+            <version>${remotable.plugins.version}</version>
         </dependency>
 
         <dependency>
-            <groupId>com.samskivert</groupId>
-            <artifactId>jmustache</artifactId>
-            <version>1.3</version>
-        </dependency>
-        <dependency>
-            <groupId>org.springframework</groupId>
-            <artifactId>org.springframework.context</artifactId>
-            <version>2.5.6</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>javax.servlet</groupId>
-            <artifactId>servlet-api</artifactId>
-            <version>2.5</version>
+            <groupId>com.atlassian.plugins</groupId>
+            <artifactId>remotable-plugins-api</artifactId>
+            <version>${remotable.plugins.version}</version>
             <scope>provided</scope>
         </dependency>
 
             <plugin>
                 <groupId>com.atlassian.maven.plugins</groupId>
                 <artifactId>maven-amps-plugin</artifactId>
-                <version>3.9</version>
+                <version>4.0</version>
                 <extensions>true</extensions>
                 <configuration>
-                    <productVersion>2.15.0</productVersion>
                     <extractDependencies>true</extractDependencies>
-                    <pluginArtifacts>
-                        <pluginArtifact>
-                            <groupId>com.atlassian.labs</groupId>
-                            <artifactId>remoteapps-plugin</artifactId>
-                            <version>${remoteapps.version}</version>
-                        </pluginArtifact>
-                    </pluginArtifacts>
                 </configuration>
             </plugin>
         </plugins>
     </build>
     <properties>
-        <remoteapps.version>0.4.387.163652a181518c315cab6d6a5e913cfca4e99a8f</remoteapps.version>
+        <remotable.plugins.version>0.5.725</remotable.plugins.version>
     </properties>
 </project>

File src/main/java/services/Renderer.java

-package services;
-
-import com.samskivert.mustache.Mustache;
-import org.springframework.stereotype.Component;
-
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.StringWriter;
-import java.nio.charset.Charset;
-import java.util.Map;
-
-/**
- *
- */
-@Component
-public class Renderer
-{
-    public void renderHtml(HttpServletResponse resp, String template, Map<String, Object> context) throws IOException
-    {
-        resp.setContentType("text/html");
-        byte[] bytes = render(template, context).getBytes(Charset.forName("UTF-8"));
-        resp.setContentLength(bytes.length);
-        resp.getOutputStream().write(bytes);
-        resp.getOutputStream().close();
-    }
-
-    public static String render(String template, Map<String,Object> context)
-    {
-        StringWriter writer = new StringWriter();
-        InputStream resourceAsStream = null;
-        try
-        {
-            resourceAsStream = Renderer.class.getClassLoader().getResourceAsStream("templates/" + template);
-            Mustache.compiler().compile(
-                new InputStreamReader(resourceAsStream)).execute(context,
-                writer);
-        }
-        finally
-        {
-            try
-            {
-                resourceAsStream.close();
-            }
-            catch (IOException e)
-            {
-                throw new RuntimeException(e);
-            }
-        }
-        return writer.toString();
-    }
-}

File src/main/java/servlets/HelloWorldServlet.java

 package servlets;
 
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-import services.Renderer;
+import com.atlassian.plugin.remotable.kit.servlet.AbstractPageServlet;
 
+import javax.inject.Singleton;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 /**
  *
  */
-@Component
-public class HelloWorldServlet extends HttpServlet
+@Singleton
+public class HelloWorldServlet extends AbstractPageServlet
 {
-    private final Renderer renderer;
-
-    @Autowired
-    public HelloWorldServlet(Renderer renderer)
-    {
-        this.renderer = renderer;
-    }
-
     @Override
     protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
     {
-        renderer.renderHtml(resp, "hello-world.html.mu",
-                Collections.<String, Object>singletonMap("date", new Date().toString()));
+        render(req, resp, Collections.<String, Object>singletonMap("date", new Date().toString()));
 
     }
 }

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

 <atlassian-plugin key="helloworldpage-app-plugin" name="${project.name}" plugins-version="2">
     <plugin-info>
+        <description>
+            Demonstrates a "universal binary" plugin
+        </description>
         <version>${project.version}</version>
+        <vendor name="Atlassian" url="http://atlassian.com" />
     </plugin-info>
+
+    <remote-plugin-container key="container" display-url="http://helloworldpage-app-plugin.herokuapp.com/helloworldpage-app-plugin" />
+
+    <general-page key="helloWorld" name="Hello World" url="/helloWorld"/>
 </atlassian-plugin>

File src/main/resources/atlassian-remote-app.xml

-<remote-app key="helloworldpage-app-plugin" name="Hello World Page App Plugin" version="1" icon-url="https://atlassian.com/favicon.ico"
-            display-url="-- to be replaced --">
-    <vendor name="Atlassian" url="http://atlassian.com" />
-    <description>
-        Demonstrates a "universal binary" app plugin
-    </description>
-
-    <general-page key="helloWorld" name="Hello World" url="/helloWorld"/>
-</remote-app>

File src/main/resources/templates/hello-world.html.mu

-<html>
-    <head>
-        <script src="https://remoteapps.jira.com/remoteapps/all.js" type="text/javascript"></script>
-    </head>
-    <body>
-        <h2>Hello World at {{date}}</h2>
-        <script type="text/javascript">
-            RA.init();
-        </script>
-    </body>
-</html>

File src/main/resources/views/hello-world.vm

+<div>
+    <h2>Hello World at ${date}</h2>
+</div>