Commits

Anonymous committed c647dad

moving source to atlassian_tutorials on BB

  • Participants

Comments (0)

Files changed (6)

+<?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.plugins.tutorial</groupId>
+    <artifactId>AddDraftLabelAction</artifactId>
+    <version>1.0-SNAPSHOT</version>
+
+    <organization>
+        <name>Atlassian</name>
+        <url>http://www.atlassian.com/</url>
+    </organization>
+
+    <name>Add 'draft' label</name>
+    <description>This plugin adds the label 'draft' to the page, via an "Add 'draft' label" action from the Tools menu.</description>
+    <packaging>atlassian-plugin</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.6</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.atlassian.confluence</groupId>
+            <artifactId>confluence</artifactId>
+            <version>${confluence.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.atlassian.confluence.plugin</groupId>
+            <artifactId>func-test</artifactId>
+            <version>2.1.1</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>com.atlassian.maven.plugins</groupId>
+                <artifactId>maven-confluence-plugin</artifactId>
+                <version>3.0.4</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Import-Package>
+                            com.atlassian.confluence.*;version="3.0.1"
+                        </Import-Package>
+                    </instructions>
+                    <productVersion>${confluence.version}</productVersion>
+                    <productDataVersion>${confluence.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>
+        <confluence.version>3.0.1</confluence.version>
+        <confluence.data.version>3.0</confluence.data.version>
+    </properties>
+
+</project>

trunk/src/main/java/com/atlassian/plugins/tutorial/AddDraftLabelAction.java

+package com.atlassian.plugins.tutorial;
+
+import com.atlassian.confluence.core.ConfluenceActionSupport;
+import com.atlassian.confluence.labels.Label;
+import com.atlassian.confluence.labels.LabelManager;
+import com.atlassian.confluence.pages.AbstractPage;
+import com.atlassian.confluence.pages.actions.PageAware;
+
+/**
+ * This Confluence action adds the label 'draft' to the page or blog post when a user selects it from the
+ * 'Tools' menu in Confluence. Refer to the 'atlassian-plugin.xml' file for details on how this action is
+ * implemented in Confluence.
+ */
+public class AddDraftLabelAction extends ConfluenceActionSupport implements PageAware
+{
+    private AbstractPage page;
+    private LabelManager labelManager;
+
+    /**
+     * Implementation of PageAware
+     */
+    public AbstractPage getPage()
+    {
+        return page;
+    }
+
+    /**
+     * Implementation of PageAware
+     */
+    public void setPage(AbstractPage page)
+    {
+        this.page = page;
+    }
+
+    /**
+     * Implementation of PageAware:
+     * Returning 'true' ensures that the
+     * page is set before the action commences.
+     */
+    public boolean isPageRequired()
+    {
+        return true;
+    }
+
+    /**
+     * Implementation of PageAware:
+     * Returning 'true' ensures that the
+     * current version of the page is used.
+     */
+    public boolean isLatestVersionRequired()
+    {
+        return true;
+    }
+
+    /**
+     * Implementation of PageAware:
+     * Returning 'true' ensures that the user
+     * requires page view permissions.
+     */
+    public boolean isViewPermissionRequired()
+    {
+        return true;
+    }
+
+    /**
+     * Dependency-injection of the Confluence LabelManager.
+     */
+    public void setLabelManager(LabelManager labelManager)
+    {
+        this.labelManager = labelManager;
+    }
+
+    public String execute()
+    {
+        // page is already retrieved by Confluence's PageAwareInterceptor
+        // labelManager is injected by Confluence -- see setLabelManager() below
+        Label label = new Label("draft");
+        labelManager.addLabel(page, label);
+        return "success";
+    }
+}

trunk/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>
+
+    <web-item name="add-draft-label-action-web-ui" key="add-draft-label-action-web-ui" section="system.content.action/primary" weight="10">
+        <description key="item.add-draft-label-action-web-ui.link.desc">Adds the "Add 'draft' label" action into the Tools menu.</description>
+        <label key="Add ''draft'' label"/>
+        <link linkId="add-draft-label-action">/plugins/add-draft-label/add-label.action?pageId=$page.id</link>
+    </web-item>
+
+    <xwork name="add-draft-label-action-xwork" key="add-draft-label-action-xwork">
+        <description key="item.add-draft-label-action-xwork.link.desc">Defines what the "Add 'draft' label" action does.</description>
+        <package name="add-draft-label" extends="default" namespace="/plugins/add-draft-label">
+            <default-interceptor-ref name="defaultStack"/>
+            <action name="add-label" class="com.atlassian.plugins.tutorial.AddDraftLabelAction">
+                <result name="success" type="redirect">${page.urlPath}</result>
+            </action>
+        </package>
+    </xwork>
+
+</atlassian-plugin>

trunk/src/test/java/com/atlassian/plugins/tutorial/AddDraftLabelActionTest.java

+package com.atlassian.plugins.tutorial;
+
+import org.junit.Test;
+
+/**
+ * Testing {@link AddDraftLabelAction}
+ */
+public class AddDraftLabelActionTest
+{
+    @Test
+    public void basic()
+    {
+        // add test here...
+    }
+}

trunk/src/test/java/it/AbstractIntegrationTestCase.java

+package it;
+
+import com.atlassian.confluence.plugin.functest.AbstractConfluencePluginWebTestCase;
+import com.atlassian.confluence.plugin.functest.ConfluenceWebTester;
+
+public class AbstractIntegrationTestCase extends AbstractConfluencePluginWebTestCase
+{
+    @Override
+    protected ConfluenceWebTester createConfluenceWebTester()
+    {
+        ConfluenceWebTester tester = new ConfluenceWebTester();
+        tester.setAdminUserName("admin");
+        tester.setAdminPassword("admin");
+        tester.setHostName("localhost");
+        tester.setPort(Integer.parseInt(System.getProperty("http.port")));
+        tester.setContextPath(System.getProperty("context.path"));
+        tester.setProtocol("http");
+        tester.setSoapServicePath("/rpc/soap-axis/confluenceservice-v1?wsdl");
+        tester.getTestContext().setBaseUrl(tester.getBaseUrl());
+        tester.setScriptingEnabled(false);
+
+        return tester;
+    }
+}

trunk/src/test/java/it/IntegrationTestMyPlugin.java

+package it;
+
+public class IntegrationTestMyPlugin extends AbstractIntegrationTestCase
+{
+	public void testSomething()
+	{
+        gotoPage("");
+        assertTextPresent("Welcome");
+	}
+}