Skip to content

Commit

Permalink
Initial project.
Browse files Browse the repository at this point in the history
  • Loading branch information
brettryan committed Jul 8, 2012
0 parents commit 828884c
Show file tree
Hide file tree
Showing 8 changed files with 281 additions and 0 deletions.
6 changes: 6 additions & 0 deletions LICENSE.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
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
13 changes: 13 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
You have successfully created a plugin using the Confluence plugin archetype!

Here are the SDK commands you'll use immediately:

* atlas-run -- installs this plugin into Confluence and starts it on http://<machinename>:1990/confluence
* 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 Confluence instance
* atlas-help -- prints description for all commands in the SDK

Full documentation is always available at:

https://developer.atlassian.com/display/DOCS/Developing+with+the+Atlassian+Plugin+SDK
82 changes: 82 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?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.drunkendev.confluence.plugins</groupId>
<artifactId>attachment-tools-plugin</artifactId>
<version>1.0-SNAPSHOT</version>

<organization>
<name>Example Company</name>
<url>http://www.example.com/</url>
</organization>

<name>attachment-tools-plugin</name>
<description>This is the com.drunkendev.confluence.plugins:attachment-tools-plugin plugin for Atlassian Confluence.</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.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.jwebunit</groupId>
<artifactId>jwebunit-htmlunit-plugin</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.12</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-confluence-plugin</artifactId>
<version>${amps.version}</version>
<extensions>true</extensions>
<configuration>
<productVersion>${confluence.version}</productVersion>
<productDataVersion>${confluence.data.version}</productDataVersion>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>

<properties>
<confluence.version>4.1.6</confluence.version>
<confluence.data.version>3.5</confluence.data.version>
<amps.version>3.11</amps.version>
</properties>

</project>
97 changes: 97 additions & 0 deletions src/main/java/com/drunkendev/confluence/plugins/ExampleMacro.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.drunkendev.confluence.plugins;

import java.util.Map;
import java.util.List;

import com.atlassian.confluence.content.render.xhtml.ConversionContext;
import com.atlassian.confluence.macro.Macro;
import com.atlassian.confluence.macro.MacroExecutionException;
import com.atlassian.confluence.pages.PageManager;
import com.atlassian.confluence.pages.Page;
import com.atlassian.confluence.spaces.SpaceManager;
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal;
import com.atlassian.user.User;
import com.opensymphony.util.TextUtils;

/**
* This very simple macro shows you the very basic use-case of displaying *something* on the Confluence page where it is used.
* Use this example macro to toy around, and then quickly move on to the next example - this macro doesn't
* really show you all the fun stuff you can do with Confluence.
*/
public class ExampleMacro implements Macro
{

// We just have to define the variables and the setters, then Spring injects the correct objects for us to use. Simple and efficient.
// You just need to know *what* you want to inject and use.

private final PageManager pageManager;
private final SpaceManager spaceManager;

public ExampleMacro(PageManager pageManager, SpaceManager spaceManager)
{
this.pageManager = pageManager;
this.spaceManager = spaceManager;
}

/**
* This method returns XHTML to be displayed on the page that uses this macro
* we just do random stuff here, trying to show how you can access the most basic
* managers and model objects. No emphasis is put on beauty of code nor on
* doing actually useful things :-)
*/
@Override
public String execute(Map<String, String> parameters, String body, ConversionContext context) throws MacroExecutionException
{
// in this most simple example, we build the result in memory, appending HTML code to it at will.
// this is something you absolutely don't want to do once you start writing plugins for real. Refer
// to the next example for better ways to render content.
StringBuffer result = new StringBuffer();

// get the currently logged in user and display his name
User user = AuthenticatedUserThreadLocal.getUser();
if (user != null)
{
String greeting = "<p>Hello <b>" + TextUtils.htmlEncode(user.getFullName()) + "</b>.</p>";
result.append(greeting);
}

//get the pages added in the last 55 days to the DS space ("Demo Space"), and display them
List<Page> list = pageManager.getRecentlyAddedPages(55, "DS");
result.append("<p>");
result.append("Some stats for <b>Demonstration Space</b>:");
result.append("<table class=\"confluenceTable\">");
result.append("<thead><tr><th class=\"confluenceTh\">Page</th><th class=\"confluenceTh\">Number of children</th></tr></thead>");
result.append("<tbody>");
for (Page page : list)
{
int numberOfChildren = page.getChildren().size();
String pageWithChildren = "<tr><td class=\"confluenceTd\">" + TextUtils.htmlEncode(page.getTitle()) + "</td><td class=\"confluenceTd\" style=\"text-align:right\">" + numberOfChildren + "</td></tr>";
result.append(pageWithChildren);
}
result.append("</tbody>");
result.append("</table>");
result.append("</p>");

// and show the number of all spaces in this installation.
String spaces = "<p>Altogether, this installation has <b>" + spaceManager.getAllSpaces().size() + "</b> spaces.</p>";
result.append(spaces);

// this concludes our little demo. Now you should understand the basics of code injection use in Confluence, and how
// to get a really simple macro running.

return result.toString();
}

@Override
public BodyType getBodyType()
{
return BodyType.NONE;
}

@Override
public OutputType getOutputType()
{
return OutputType.BLOCK;
}

}
11 changes: 11 additions & 0 deletions src/main/resources/atlassian-plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<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>

<xhtml-macro name="attachment-tools-plugin" class="com.drunkendev.confluence.plugins.ExampleMacro" key="my-macro">
<parameters/>
</xhtml-macro>
</atlassian-plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.drunkendev.confluence.plugins;

import org.junit.Test;

/**
* Testing {@link com.drunkendev.confluence.plugins.ExampleMacro}
*/
public class ExampleMacroTest
{
@Test
public void basic()
{
// add test here...
}
}
47 changes: 47 additions & 0 deletions src/test/java/it/AbstractIntegrationTestCase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package it;

import com.atlassian.confluence.plugin.functest.AbstractConfluencePluginWebTestCase;
import com.atlassian.confluence.plugin.functest.JWebUnitConfluenceWebTester;
import com.atlassian.confluence.plugin.functest.TesterConfiguration;
import junit.framework.Assert;

import java.io.IOException;
import java.util.Properties;

public class AbstractIntegrationTestCase extends AbstractConfluencePluginWebTestCase
{
@Override
protected JWebUnitConfluenceWebTester createConfluenceWebTester()
{
Properties props = new Properties();
props.put("confluence.webapp.protocol", "http");
props.put("confluence.webapp.host", "localhost");

// this is deceiving: the func test library checks for the system properties
// *before* checking in this properties file for these values, so these
// properties are technically ignored
props.put("confluence.webapp.port", Integer.parseInt(System.getProperty("http.port")));
props.put("confluence.webapp.context.path", System.getProperty("context.path"));

props.put("confluence.auth.admin.username", "admin");
props.put("confluence.auth.admin.password", "admin");

TesterConfiguration conf;
try
{
conf = new TesterConfiguration(props);
}
catch (IOException ioe)
{
Assert.fail("Unable to create tester: " + ioe.getMessage());
return null;
}

JWebUnitConfluenceWebTester tester = new JWebUnitConfluenceWebTester(conf);

tester.getTestContext().setBaseUrl(tester.getBaseUrl());
tester.setScriptingEnabled(false);

return tester;
}
}
10 changes: 10 additions & 0 deletions src/test/java/it/IntegrationTestMyPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package it;

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

0 comments on commit 828884c

Please sign in to comment.