Commits

Anonymous committed 788fd07

Tutorial sweep updates

Comments (0)

Files changed (16)

+Copyright 2013 Atlassian Pty Ltd
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
 This project is a tutorial for developers learning to write a message handler for JIRA.
 You can find the entire tutorial at: 
 
-https://developer.atlassian.com/display/JIRADEV/Plugin+Tutorial+-+Writing+a+Custom+Message+%28Mail%29+Handler+for+JIRA
+https://developer.atlassian.com/display/JIRADEV/Custom+Message+%28Mail%29+Handler+for+JIRA
 <?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">
+         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.example.plugins.tutorial.jira</groupId>
-	<artifactId>mail-handler-demo</artifactId>
-	<version>1.0-SNAPSHOT</version>
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>com.example.plugins.tutorial.jira</groupId>
+    <artifactId>mail-handler-demo</artifactId>
+    <version>1.0-SNAPSHOT</version>
 
-	<organization>
-		<name>Example Company</name>
-		<url></url>
-	</organization>
+    <organization>
+        <name>Example Company</name>
+        <url>http://www.example.com/</url>
+    </organization>
 
-	<name>Mail Handler Demo</name>
-	<description>This plugin demonstrates how to add a custom message handler to Atlassian JIRA</description>
-	<packaging>atlassian-plugin</packaging>
+    <name>Mail Handler Demo</name>
+    <description>This plugin demonstrates how to add a custom message handler to Atlassian JIRA</description>
+    <packaging>atlassian-plugin</packaging>
 
-	<dependencies>
-		<dependency>
-			<groupId>com.atlassian.jira</groupId>
-			<artifactId>jira-api</artifactId>
-			<version>${jira.version}</version>
-			<scope>provided</scope>
-		</dependency>
-		<!-- Add dependency on jira-core if you want access to JIRA implementation classes as well as the sanctioned API. -->
-		<!-- This is not normally recommended, but may be required eg when migrating a plugin originally developed against JIRA 4.x -->
-		<!--
-				<dependency>
-					<groupId>com.atlassian.jira</groupId>
-					<artifactId>jira-core</artifactId>
-					<version>${jira.version}</version>
-					<scope>provided</scope>
-				</dependency>
-				-->
-		<dependency>
-			<groupId>junit</groupId>
-			<artifactId>junit</artifactId>
-			<version>4.8.1</version>
-			<scope>test</scope>
-		</dependency>
-		<dependency>
-			<groupId>com.atlassian.jira</groupId>
-			<artifactId>jira-tests</artifactId>
-			<version>${jira.version}</version>
-			<scope>test</scope>
-		</dependency>
-		<dependency>
-			<groupId>com.atlassian.jira</groupId>
-			<artifactId>jira-func-tests</artifactId>
-			<version>${jira.version}</version>
-			<scope>test</scope>
-		</dependency>
-		<dependency>
-			<groupId>com.atlassian.jira</groupId>
-			<artifactId>jira-mail-plugin</artifactId>
-			<version>5.0-SNAPSHOT</version>
-			<scope>provided</scope>
-		</dependency>
-		<dependency>
-			<groupId>com.atlassian.mail</groupId>
-			<artifactId>atlassian-mail</artifactId>
-			<version>2.1</version>
-			<scope>provided</scope>
-		</dependency>
-		<dependency>
-			<groupId>javax.mail</groupId>
-			<artifactId>mail</artifactId>
-			<version>1.4.4</version>
-			<scope>provided</scope>
-		</dependency>
-	</dependencies>
+    <dependencies>
+        <dependency>
+            <groupId>com.atlassian.jira</groupId>
+            <artifactId>jira-api</artifactId>
+            <version>${jira.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.10</version>
+            <scope>test</scope>
+        </dependency>
 
+        <!-- WIRED TEST RUNNER DEPENDENCIES -->
+        <dependency>
+            <groupId>com.atlassian.plugins</groupId>
+            <artifactId>atlassian-plugins-osgi-testrunner</artifactId>
+            <version>${plugin.testrunner.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.ws.rs</groupId>
+            <artifactId>jsr311-api</artifactId>
+            <version>1.1.1</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.google.code.gson</groupId>
+            <artifactId>gson</artifactId>
+            <version>2.2.2-atlassian-1</version>
+        </dependency>
 
-	<build>
-		<plugins>
-			<plugin>
-				<groupId>com.atlassian.maven.plugins</groupId>
-				<artifactId>maven-jira-plugin</artifactId>
-				<version>3.7</version>
-				<extensions>true</extensions>
-				<configuration>
-					<productVersion>${jira.version}</productVersion>
-					<productDataVersion>${jira.version}</productDataVersion>
-				</configuration>
-			</plugin>
-			<plugin>
-				<artifactId>maven-compiler-plugin</artifactId>
-				<configuration>
-					<source>1.6</source>
-					<target>1.6</target>
-				</configuration>
-			</plugin>
-		</plugins>
-	</build>
+        <dependency>
+            <groupId>com.atlassian.jira</groupId>
+            <artifactId>jira-mail-plugin</artifactId>
+            <version>${jira.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.atlassian.mail</groupId>
+            <artifactId>atlassian-mail</artifactId>
+            <version>2.1</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.mail</groupId>
+            <artifactId>mail</artifactId>
+            <version>1.4.4</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
 
-	<properties>
-		<!-- TODO: Update to 5.0 after release of 5.0 final -->
-		<jira.version>5.0-SNAPSHOT</jira.version>
-		<amps.version>3.7</amps.version>
-	</properties>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>com.atlassian.maven.plugins</groupId>
+                <artifactId>maven-jira-plugin</artifactId>
+                <version>${amps.version}</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <productVersion>${jira.version}</productVersion>
+                    <productDataVersion>${jira.version}</productDataVersion>
+					<!-- Uncomment to install TestKit backdoor in JIRA. -->
+					<!--
+					<pluginArtifacts>
+						<pluginArtifact>
+							<groupId>com.atlassian.jira.tests</groupId>
+							<artifactId>jira-testkit-plugin</artifactId>
+							<version>${testkit.version}</version>
+						</pluginArtifact>
+					</pluginArtifacts>
+					-->
+                </configuration>
+            </plugin>
+            <plugin>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.6</source>
+                    <target>1.6</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <properties>
+        <jira.version>6.0.4</jira.version>
+        <amps.version>4.2.0</amps.version>
+        <plugin.testrunner.version>1.1.1</plugin.testrunner.version>
+		<!-- TestKit version 5.x for JIRA 5.x, 6.x for JIRA 6.x -->
+		<testkit.version>5.2.26</testkit.version>
+    </properties>
 
 </project>

src/main/java/com/example/plugins/tutorial/jira/mailhandlerdemo/DemoHandler.java

 		return true; // returning true means that we have handled the message successfully. It means it will be deleted next.
 	}
 }
+

src/main/java/com/example/plugins/tutorial/jira/mailhandlerdemo/EditDemoHandlerDetailsWebAction.java

 		super(pluginAccessor);
 		this.issueKeyValidator = issueKeyValidator;
 	}
-
 	private String issueKey;
-
 	public String getIssueKey() {
 		return issueKey;
 	}
         this.issueKey = issueKey;
     }
 
-    // this method is called to let us populate our variables (or action state) with current handler settings
-    // managed by associated service (file or mail).
+    // this method is called to let us populate our variables (or action state) 
+    // with current handler settings managed by associated service (file or mail).
 	@Override
 	protected void copyServiceSettings(JiraServiceContainer jiraServiceContainer) throws ObjectConfigurationException {
 		final String params = jiraServiceContainer.getProperty(AbstractMessageHandlingService.KEY_HANDLER_PARAMS);
 		issueKey = parameterMap.get(DemoHandler.KEY_ISSUE_KEY);
 	}
 
-
 	@Override
 	protected Map<String, String> getHandlerParams() {
 		return MapBuilder.build(DemoHandler.KEY_ISSUE_KEY, issueKey);
 	}
 
-
 	@Override
 	protected void doValidation() {
 		if (configuration == null) {
 		super.doValidation();
 		issueKeyValidator.validateIssue(issueKey, new WebWorkErrorCollector());
 	}
-
-
 }
+

src/main/java/com/example/plugins/tutorial/jira/mailhandlerdemo/IssueKeyValidator.java

 
 	public Issue validateIssue(String issueKey, MessageHandlerErrorCollector collector) {
 		if (StringUtils.isBlank(issueKey)) {
-			collector.error("Issue key has to be defined. Found '" + issueKey + "'" );
+			collector.error("Issue key cannot be undefined.");
 			return null;
 		}
 
 		}
 		return issue;
 	}
-
 }

src/main/java/com/example/plugins/tutorial/jira/mailhandlerdemo/MyPluginComponent.java

+package com.example.plugins.tutorial.jira.mailhandlerdemo;
+
+public interface MyPluginComponent
+{
+    String getName();
+}

src/main/java/com/example/plugins/tutorial/jira/mailhandlerdemo/MyPluginComponentImpl.java

+package com.example.plugins.tutorial.jira.mailhandlerdemo;
+
+import com.atlassian.sal.api.ApplicationProperties;
+
+public class MyPluginComponentImpl implements MyPluginComponent
+{
+    private final ApplicationProperties applicationProperties;
+
+    public MyPluginComponentImpl(ApplicationProperties applicationProperties)
+    {
+        this.applicationProperties = applicationProperties;
+    }
+
+    public String getName()
+    {
+        if(null != applicationProperties)
+        {
+            return "myComponent:" + applicationProperties.getDisplayName();
+        }
+        
+        return "myComponent";
+    }
+}

src/main/resources/atlassian-plugin.xml

     <plugin-info>
         <description>${project.description}</description>
         <version>${project.version}</version>
-        <vendor name="${project.organization.name}" url="${project.organization.url}"/>
+        <vendor name="${project.organization.name}" url="${project.organization.url}" />
+        <param name="plugin-icon">images/pluginIcon.png</param>
+        <param name="plugin-logo">images/pluginLogo.png</param>
     </plugin-info>
-    <resource type="i18n" name="i18n" location="com.example.plugins.tutorial.jira.mailhandlerdemo.messages"/>
-    <component key="issue-key-validator" class="com.example.plugins.tutorial.jira.mailhandlerdemo.IssueKeyValidator"/>
+
+    <!-- add our i18n resource -->
+    <resource type="i18n" name="i18n" location="mail-handler-demo"/>
+    
+    <!-- add our web resources -->
+    <web-resource key="mail-handler-demo-resources" name="mail-handler-demo Web Resources">
+        <dependency>com.atlassian.auiplugin:ajs</dependency>
+        
+        <resource type="download" name="mail-handler-demo.css" location="/css/mail-handler-demo.css"/>
+        <resource type="download" name="mail-handler-demo.js" location="/js/mail-handler-demo.js"/>
+        <resource type="download" name="images/" location="/images"/>
+
+        <context>mail-handler-demo</context>
+    </web-resource>
+    
+    <!-- publish our component -->
+    <component key="myPluginComponent" class="com.example.plugins.tutorial.jira.mailhandlerdemo.MyPluginComponentImpl" public="true">
+        <interface>com.example.plugins.tutorial.jira.mailhandlerdemo.MyPluginComponent</interface>
+    </component>
+    
+    <!-- import from the product container -->
+    <component-import key="applicationProperties" interface="com.atlassian.sal.api.ApplicationProperties" />
 
     <message-handler i18n-name-key="demohandler.name"
             key="demoHandler" class="com.example.plugins.tutorial.jira.mailhandlerdemo.DemoHandler"
             add-edit-url="/secure/admin/EditDemoHandlerDetails!default.jspa"
             weight="0"/>
+    
+    <component key="issue-key-validator" class="com.example.plugins.tutorial.jira.mailhandlerdemo.IssueKeyValidator"/>
 
     <webwork1 key="actions" name="Actions" class="java.lang.Object">
         <actions>
             </action>
         </actions>
     </webwork1>
-</atlassian-plugin>
+</atlassian-plugin>

src/main/resources/com/example/plugins/tutorial/jira/mailhandlerdemo/messages.properties

-demohandler.name=My Demo Mail Handler
-demohandler.issue.key=Issue Key

src/main/resources/css/mail-handler-demo.css

Empty file added.

src/main/resources/images/pluginIcon.png

Added
New image

src/main/resources/images/pluginLogo.png

Added
New image

src/main/resources/js/mail-handler-demo.js

Empty file added.

src/main/resources/mail-handler-demo.properties

+#put any key/value pairs here
+my.plugin.name=MyPlugin
+demohandler.name=My Demo Mail Handler
+demohandler.issue.key=Issue Key

src/main/resources/view/editDemoHandlerDetails.vm

-#* @vtlvariable name="action" type="com.atlassian.jira.plugins.mailhandlerdemo.EditDemoHandlerDetailsWebAction" *#
+## couple of available navigation helpers
 #set ($modifierKey = $action.browserUtils.getModifierKey())
 #set ($submitAccessKey = $i18n.getText('AUI.form.submit.button.accesskey'))
 #set ($submitTitle = $i18n.getText('AUI.form.submit.button.tooltip', [$submitAccessKey, $modifierKey]))
-
 #set ($cancelAccessKey = $i18n.getText('AUI.form.cancel.link.accesskey'))
 #set ($cancelTitle = $i18n.getText('AUI.form.cancel.link.tooltip', [$cancelAccessKey, $modifierKey]))
 <html>
 <body>
     <form class="aui" action="EditDemoHandlerDetails.jspa" method="POST" name="mailHandlerForm" id="mailHandlerForm">
         <div class="form-body">
-            <h2>$action.handlerName</h2>
+           <h2>$action.handlerName</h2>
            <span class="global-errors-location">
                 #if ($action.getHasErrorMessages())
                     #foreach ($error in $action.getFlushedErrorMessages())
                         #AUImessage("error" "" $textutils.htmlEncode(${error}) "" "" "" "false")
-                        #end
+                    #end
                 #end
             </span>
             <input type="hidden" name="atl_token" value="$atl_token">
             <label for="issue-key">$i18n.getText('demohandler.issue.key')</label>
             <input type="text" class="text" id="issue-key" name="issueKey" value="$!textutils.htmlEncode($issueKey)">
 
-
         <div class="buttons-container form-footer">
             <div class="buttons">
                 #if ($action.editing)
     </form>
 </body>
 </html>
-