Commits

Anonymous committed 3eda15d

Tutorial sweep code updates

Comments (0)

Files changed (10)

+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 code accompanies the tutorial at:
+This example shows an Atlassian JIRA plugin that adds a simple JQL function to JIRA. It allows a user to search for issues only in those projects that the user has visited. 
 
-https://developer.atlassian.com/display/JIRADEV/Plugin+Tutorial+-+Adding+a+JQL+Function+to+JIRA
+For a complete description of the example, along with the steps to create it, see the tutorial at: 
+
+https://developer.atlassian.com/display/JIRADEV/Adding+a+JQL+Function+to+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">
-  <modelVersion>4.0.0</modelVersion>
-  <groupId>com.example.plugins.tutorial</groupId>
-  <artifactId>tutorial-jira-simple-jql-function</artifactId>
-  <packaging>atlassian-plugin</packaging>
-  <name>tutorial-jira-simple-jql-function</name>
-  <version>1.0</version>
-  <description>This is the com.example.plugins.tutorial:tutorial-jira-simple-jql-function plugin for Atlassian JIRA.</description>
-  <organization>
-    <name>Example Company</name>
-    <url>http://www.example.com/</url>
-  </organization>
-  <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>
-  <dependencies>
-    <dependency>
-      <groupId>com.atlassian.jira</groupId>
-      <artifactId>jira-api</artifactId>
-      <version>${jira.version}</version>
-      <scope>provided</scope>
-    </dependency>
-    <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>org.mockito</groupId>
-      <artifactId>mockito-all</artifactId>
-      <version>1.8.5</version>
-      <scope>test</scope>
-    </dependency>
-  </dependencies>
-  <properties>
-    <amps.version>3.7</amps.version>
-    <jira.version>5.0-beta1</jira.version>
-  </properties>
-</project>
-
+<?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.example.plugins.tutorial.jira</groupId>
+    <artifactId>jira-simple-jql-function</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <organization>
+        <name>Example Company</name>
+        <url>http://www.example.com/</url>
+    </organization>
+    <name>jira-simple-jql-function</name>
+    <description>Adds a custom JQL function named recentProjects to 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.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>
+        <!-- Uncomment to use TestKit in your project. Details at https://bitbucket.org/atlassian/jira-testkit -->
+        <!-- You can read more about TestKit at https://developer.atlassian.com/display/JIRADEV/Plugin+Tutorial+-+Smarter+integration+testing+with+TestKit -->
+        <!--
+		<dependency>
+			<groupId>com.atlassian.jira.tests</groupId>
+			<artifactId>jira-testkit-client</artifactId>
+			<version>${testkit.version}</version>
+			<scope>test</scope>
+		</dependency>
+		-->
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>1.6.6</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-all</artifactId>
+            <version>1.8.5</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+    <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.1-20130626</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/jql/RecentProjectFunction.java

 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-
 import com.atlassian.jira.JiraDataType;
 import com.atlassian.jira.JiraDataTypes;
 import com.atlassian.jira.jql.operand.QueryLiteral;
 import com.atlassian.jira.jql.query.QueryCreationContext;
 import com.atlassian.jira.plugin.jql.function.AbstractJqlFunction;
-import com.atlassian.jira.user.UserHistoryItem;
-import com.atlassian.jira.user.UserProjectHistoryManager;
 import com.atlassian.jira.util.MessageSet;
 import com.atlassian.jira.util.NotNull;
 import com.atlassian.query.clause.TerminalClause;
 import com.atlassian.query.operand.FunctionOperand;
 import com.google.common.collect.Iterables;
+
 import com.atlassian.crowd.embedded.api.User;
+import com.atlassian.jira.user.UserHistoryItem;
+import com.atlassian.jira.user.UserProjectHistoryManager;
+import java.util.LinkedList;
 
 import java.util.Collections;
-import java.util.LinkedList;
 import java.util.List;
 
-/**
- * A handler for the "recentHistory" function. This function will return all the projects within the user's history.
- */
 public class RecentProjectFunction extends AbstractJqlFunction
 {
     private static final Logger log = LoggerFactory.getLogger(RecentProjectFunction.class);
-
     private final UserProjectHistoryManager userProjectHistoryManager;
-
     public RecentProjectFunction(UserProjectHistoryManager userProjectHistoryManager)
     {
         this.userProjectHistoryManager = userProjectHistoryManager;
     }
-
-    /**
-     * This method validates the passed in args. In this case the function accepts no args, so let's validate that were none.
-     */
     public MessageSet validate(User searcher, FunctionOperand operand, TerminalClause terminalClause)
     {
         return validateNumberOfArgs(operand, 0);
     }
-
-    
     public List<QueryLiteral> getValues(QueryCreationContext queryCreationContext, FunctionOperand operand, TerminalClause terminalClause)
     {
         final List<QueryLiteral> literals = new LinkedList<QueryLiteral>();
-
-        /*
-        * We do not need to do a security check here as the search will do the security checks for us.
-        */
         final List<UserHistoryItem> projects = userProjectHistoryManager.getProjectHistoryWithoutPermissionChecks(queryCreationContext.getUser());
         for (final UserHistoryItem userHistoryItem : projects)
         {
             final String value = userHistoryItem.getEntityId();
-
             try
             {
                 literals.add(new QueryLiteral(operand, Long.parseLong(value)));
                 log.warn(String.format("User history returned a non numeric project ID '%s'.", value));
             }
         }
-
-         return literals;
+        return literals;
     }
-
-   /**
-    * This method returns the min number of args the function takes. In this case - 0
-    */
     public int getMinimumNumberOfExpectedArguments()
     {
         return 0;
     }
-
-   /**
-    * This method needs to return the type of objects the function deals with. In this case - Projects
-    */
     public JiraDataType getDataType()
     {
         return JiraDataTypes.PROJECT;
     }
-}
+}

src/main/resources/atlassian-plugin.xml

     <description>${project.description}</description>
     <version>${project.version}</version>
     <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>
-
+  <!-- add our i18n resource -->
+  <resource type="i18n" name="i18n" location="jira-simple-jql-function"/>
+  <!-- add our web resources -->
+  <web-resource key="jira-simple-jql-function-resources" name="jira-simple-jql-function Web Resources">
+    <dependency>com.atlassian.auiplugin:ajs</dependency>
+    <resource type="download" name="jira-simple-jql-function.css" location="/css/jira-simple-jql-function.css"/>
+    <resource type="download" name="jira-simple-jql-function.js" location="/js/jira-simple-jql-function.js"/>
+    <resource type="download" name="images/" location="/images"/>
+    <context>jira-simple-jql-function</context>
+  </web-resource>
+  <!-- publish our component -->
+  <component key="myPluginComponent" class="com.example.plugins.tutorial.jira.MyPluginComponentImpl" public="true">
+    <interface>com.example.plugins.tutorial.jira.MyPluginComponent</interface>
+  </component>
+  <!-- import from the product container -->
+  <component-import key="applicationProperties" interface="com.atlassian.sal.api.ApplicationProperties"/>
   <jql-function name="Recent Project Function" i18n-name-key="recent-project-function.name" key="recent-project-function" class="com.example.plugins.tutorial.jira.jql.RecentProjectFunction">
+    <description key="recent-project-function.description">The Recent Project Function Plugin</description>
     <fname>recentProjects</fname>
-    <description key="recent-project-function.description">Provides a JQL function to restrict the search to recently visited projects.</description>
     <list>true</list>
   </jql-function>
-    
-  <resource type="i18n" name="i18n" location="atlassian-plugin"/>
 </atlassian-plugin>

src/main/resources/css/jira-simple-jql-function.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/jira-simple-jql-function.properties

+#put any key/value pairs here
+my.plugin.name=MyPlugin
+recent-project-function.name=Recent Project Function
+recent-project-function.description=The Recent Project Function Plugin

src/main/resources/js/jira-simple-jql-function.js

Empty file added.