Commits

Mary Anthony  committed 11a64ec

Moving source code to BB atlassian_tutorials

  • Participants

Comments (0)

Files changed (12)

+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
+You have successfully created a plugin using the JIRA plugin archetype!
+
+Here are the SDK commands you'll use immediately:
+
+* atlas-run   -- installs this plugin into JIRA and starts it on http://localhost:2990/jira
+* atlas-debug -- same as atlas-run, but allows a debugger to attach at port 5005
+* atlas-cli   -- after atlas-run or atlas-debug, opens a Maven command line window:
+                 - 'pi' reinstalls the plugin into the running JIRA instance
+* atlas-help  -- prints description for all commands in the SDK
+
+Full documentation is always available at:
+
+http://confluence.atlassian.com/display/DEVNET/Developing+your+Plugin+using+the+Atlassian+Plugin+SDK
+<?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.atlassian.tutorials</groupId>
+    <artifactId>dialogs</artifactId>
+    <version>1.0-SNAPSHOT</version>
+
+    <organization>
+        <name>Example Company</name>
+        <url>http://www.example.com/</url>
+    </organization>
+
+    <name>dialogs</name>
+    <description>This is the com.atlassian.tutorials:dialogs plugin for Atlassian JIRA.</description>
+    <packaging>atlassian-plugin</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.atlassian.jira</groupId>
+            <artifactId>atlassian-jira</artifactId>
+            <version>${jira.version}</version>
+            <scope>provided</scope>
+        </dependency>        
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.6</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.atlassian.jira</groupId>
+            <artifactId>jira-func-tests</artifactId>
+            <version>${jira.version}</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>com.atlassian.maven.plugins</groupId>
+                <artifactId>maven-jira-plugin</artifactId>
+                <version>3.2</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <productVersion>${jira.version}</productVersion>
+                    <productDataVersion>${jira.data.version}</productDataVersion>
+                </configuration>
+            </plugin>
+            <plugin>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.5</source>
+                    <target>1.5</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <properties>
+        <jira.version>4.2-beta3</jira.version>
+        <jira.data.version>4.2-beta3</jira.data.version>
+    </properties>
+
+</project>

File src/main/java/com/example/dialog/AddWatchers.java

+package com.example.dialog;
+
+import com.atlassian.core.user.UserUtils;
+import com.atlassian.jira.issue.watchers.WatcherManager;
+import com.atlassian.jira.web.action.issue.AbstractIssueSelectAction;
+import org.apache.commons.lang.StringUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * TODO: Document this class / interface here
+ *
+ * @since v4.0
+ */
+public class AddWatchers extends AbstractIssueSelectAction
+{
+    private final WatcherManager watcherManager;
+    private final BeanFactory beanFactory;
+    private String[] watcherUserNames = new String[0];
+    private List<String> validUsernames = new ArrayList<String>();
+
+    public AddWatchers(final WatcherManager watcherManager, final BeanFactory beanFactory)
+    {
+        this.watcherManager = watcherManager;
+        this.beanFactory = beanFactory;
+    }
+
+
+    @Override
+    public String doDefault() throws Exception
+    {
+        return INPUT;
+    }
+
+    @Override
+    protected void doValidation()
+    {
+        for (String username : watcherUserNames)
+        {
+            username = username.trim();
+
+            if (UserUtils.existsUser(username))
+            {
+                validUsernames.add(username);
+            }
+            else
+            {
+                addErrorMessage(beanFactory.getInstance(getRemoteUser()).getText("tutorial.errors.user", username));
+            }
+        }
+    }
+
+    @Override
+    public String doExecute() throws Exception
+    {
+        for (String validUsername : validUsernames)
+        {
+            watcherManager.startWatching(UserUtils.getUser(validUsername), getIssue());
+        }
+
+        return returnCompleteWithInlineRedirect("/browse/" + getIssueObject().getKey());
+    }
+
+    public void setWatcherUserNames(String userNames) throws Exception
+    {
+        if(StringUtils.isNotBlank(userNames))
+        {
+            watcherUserNames = userNames.split(",", 10); // split into array of user names
+
+        }
+    }
+}

File 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>
+
+    <resource type="i18n" name="i18n" location="com.example.dialog.i18n" />
+
+    <webwork1 key="tutorial.actions" name="Adds Watchers" class="java.lang.Object">
+        <actions>
+            <action name="com.example.dialog.AddWatchers" alias="AddWatchers">
+                <view name="input">/templates/add-watchers.vm</view>
+            </action>
+        </actions>
+    </webwork1>
+
+    <web-item key="tutorial.operations.webitem" name="My Dialog Item" section="operations-voteswatchers" weight="1">
+        <label key="tutorial.labels.add.watchers" />
+        <link linkId="add-watchers">/AddWatchers!default.jspa?id=${issue.id}</link>
+    </web-item>
+
+    <web-resource name="Resources" key="resources">
+        <resource name="tutorial.js" type="download" location="/js/tutorial.js"/>
+       <context>atl.general</context>
+    </web-resource>
+
+</atlassian-plugin>

File src/main/resources/com/example/dialog/i18n.properties

+tutorial.labels.add.watchers = Add Watcher(s)
+
+tutorial.fields.users.label = User(s):
+tutorial.fields.users.desc = Enter the username(s) to add as watcher(s)
+
+tutorial.errors.user = Invalid User ''{0}''
+
+tutorial.common.cancel = Cancel
+tutorial.common.add = Add

File src/main/resources/js/tutorial.js

+jQuery(function () {
+
+    new AJS.FormPopup({
+        id: "add-watchers-dialog",
+        trigger: "#add-watchers"
+    });
+
+});

File src/main/resources/templates/add-watchers.vm

+<h2 class="dialog-title">$i18n.getText('tutorial.labels.add.watchers')</h2>
+
+<form class="aui" action="AddWatchers.jspa" method="post">
+
+    <input type="hidden" name="atl_token" value="${atl_token}" />
+    <input type="hidden" name="id" value="$action.id" />
+
+    <div class="content-body">
+
+        #if ($action.hasAnyErrors())
+        <div class="form-message error">
+            #foreach ($error in $action.getErrorMessages())
+                <p>$textutils.htmlEncode(${error})</p>
+            #end
+            #foreach ($error in $action.errors)
+                <p>$textutils.htmlEncode(${error})</p>
+            #end
+        </div>
+        #end
+
+        <div class="field-group">
+            <label>$i18n.getText('tutorial.fields.users.label') <span class="aui-icon icon-required"></span></label>
+            &nbsp;<textarea name="watcherUserNames" class="textarea long-field"></textarea>
+            <div class="description">$i18n.getText('tutorial.fields.users.desc'))</div>
+        </div>
+    </div>
+
+    <div class="buttons-container content-footer">
+        <div class="buttons">
+            <a href="#" class="cancel">$i18n.getText('tutorial.common.cancel')</a>
+            <input class="button" type="submit" value="$i18n.getText('tutorial.common.add')" />
+        </div>
+    </div>
+
+</form>

File src/test/java/com/atlassian/tutorials/MyPluginTest.java

+package com.atlassian.tutorials;
+
+import org.junit.Test;
+
+public class MyPluginTest
+{
+    @Test
+    public void testSomething()
+    {
+    }
+}

File src/test/java/it/MyPluginTest.java

+package it;
+
+import org.junit.Test;
+
+public class MyPluginTest
+{
+    @Test
+    public void integrationTest()
+    {
+    }
+}

File src/test/resources/TEST_RESOURCES_README

+Create any of the test resources you might need in this directory.
+
+Please remove this file before releasing your plugin.

File src/test/xml/TEST_XML_RESOURCES_README

+Create all XML test resources here - these might be needed for populating JIRA instance at the integration-test phase with test data.
+
+Please remove this file before releasing your plugin.