SDK6中的Confluence宏开发

时间:2016-03-23 06:33:59

标签: confluence

我有点沮丧。我正在尝试开发一个简单的“hello world”宏来进行汇合。但是所有的教程都不再适用于实际的SDK6。

我试过这个教程:

https://developer.atlassian.com/confdev/tutorials/macro-tutorials-for-confluence/creating-a-new-confluence-macro#CreatingaNewConfluenceMacro-Step1.Createthepluginprojectandtrimtheskeleton

但正如你可以看到文章讨论的那样,它不再正常工作了。我认为一些元素已经使用SDK6进行了修改,并且教程不再是最新的。

我在confluence论坛上寻求帮助,但没有任何运气。有几个帖子围绕这个问题没有任何解决方案。

问题是,插件/插件在系统管理面板中是可见的,但是我无法在页面上使用宏,而且我在宏浏览器中看不到宏。

现在可行 - 更新

这就是我所做的:

1)下载SDK

我下载了sdk-installer-6.2.4.exe并安装了它

2)创建新插件

我通过输入

创建了一个用于融合的新插件
 atlas-create-confluence-plugin

使用以下这些群组和工件ID

groupid    : com.example.plugins.tutorial.confluence
artifactid : tutorial-confluence-macro-demo
version    : 1.0-SNAPSHOT
package    : package    com.example.plugins.tutorial.confluence

3)创建eclipse项目

然后我输入

创建了eclipse项目
atlas-mvn eclipse:eclipse

4)修改pom.xml

我像ppasler在他的回答中解释的那样修改了pom.xml。我还修改了公司名称和版本以便检查汇合,如果修改将产生影响。 pom看起来像这样:

<?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.confluence</groupId>
    <artifactId>tutorial-confluence-macro-demo</artifactId>
    <version>4.4-SNAPSHOT</version>

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

    <name>tutorial-confluence-macro-demo</name>
    <description>This is the com.example.plugins.tutorial.confluence:tutorial-confluence-macro-demo plugin for Atlassian Confluence.</description>
    <packaging>atlassian-plugin</packaging>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</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.plugin</groupId>
            <artifactId>atlassian-spring-scanner-annotation</artifactId>
            <version>${atlassian.spring.scanner.version}</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>com.atlassian.plugin</groupId>
            <artifactId>atlassian-spring-scanner-runtime</artifactId>
            <version>${atlassian.spring.scanner.version}</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
            <scope>provided</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>
    </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>
                    <enableQuickReload>true</enableQuickReload>
                    <enableFastdev>false</enableFastdev>

                    <!-- See here for an explanation of default instructions: -->
                    <!-- https://developer.atlassian.com/docs/advanced-topics/configuration-of-instructions-in-atlassian-plugins -->
                    <instructions>
                        <Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>

                        <!-- Add package to export here -->
                        <Export-Package>
                            com.example.plugins.tutorial.confluence.api,
                        </Export-Package>

                        <!-- Add package import here -->
                        <Import-Package>
                            org.springframework.osgi.*;resolution:="optional",
                            org.eclipse.gemini.blueprint.*;resolution:="optional",
                            *
                        </Import-Package>

                        <!-- Ensure plugin is spring powered -->
                        <Spring-Context>*</Spring-Context>
                    </instructions>
                </configuration>
            </plugin>

            <plugin>
                <groupId>com.atlassian.plugin</groupId>
                <artifactId>atlassian-spring-scanner-maven-plugin</artifactId>
                <version>1.2.6</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>atlassian-spring-scanner</goal>
                        </goals>
                        <phase>process-classes</phase>
                    </execution>
                </executions>
                <configuration>
                    <scannedDependencies>
                        <dependency>
                            <groupId>com.atlassian.plugin</groupId>
                            <artifactId>atlassian-spring-scanner-external-jar</artifactId>
                        </dependency>
                    </scannedDependencies>
                    <verbose>false</verbose>
                </configuration>
            </plugin>
        </plugins>
    </build>


    <properties>
    <confluence.version>5.9.7</confluence.version>
    <confluence.data.version>5.9.7</confluence.data.version>
    <amps.version>6.2.4</amps.version>
    <plugin.testrunner.version>1.1.1</plugin.testrunner.version>
     <atlassian.spring.scanner.version>1.2.6</atlassian.spring.scanner.version>
    </properties>
<!--
    <properties>
        <confluence.version>5.9.7</confluence.version>
        <confluence.data.version>5.9.7</confluence.data.version>
        <amps.version>6.2.3</amps.version>
        <plugin.testrunner.version>1.2.3</plugin.testrunner.version>
        <atlassian.spring.scanner.version>1.2.6</atlassian.spring.scanner.version>
        <atlassian.plugin.key>${project.groupId}.${project.artifactId}</atlassian.plugin.key>
    </properties>
-->
</project>

5)开始日食

我将项目导入Eclilpse

Version: Mars.1 Release (4.5.1)
Build id: 20150924-1200
Java JDK 1.8.0_60

6)ExampleMacro类创建

我创建了“ExampleMacro”类

package com.example.plugins.tutorial.confluence;

import com.atlassian.confluence.content.render.xhtml.ConversionContext;
import com.atlassian.confluence.content.render.xhtml.XhtmlException;
import com.atlassian.confluence.macro.Macro;
import com.atlassian.confluence.macro.MacroExecutionException;
import com.atlassian.confluence.xhtml.api.MacroDefinition;
import com.atlassian.confluence.xhtml.api.MacroDefinitionHandler;
import com.atlassian.confluence.xhtml.api.XhtmlContent;

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

public class ExampleMacro implements Macro
{
    private final XhtmlContent xhtmlUtils;

    public ExampleMacro(XhtmlContent xhtmlUtils)
    {
        this.xhtmlUtils = xhtmlUtils;
    }

    @Override
    public String execute(Map<String, String> parameters, String bodyContent, ConversionContext conversionContext) throws MacroExecutionException
    {
        String body = conversionContext.getEntity().getBodyAsString();

        final List<MacroDefinition> macros = new ArrayList<MacroDefinition>();

        try
        {
            xhtmlUtils.handleMacroDefinitions(body, conversionContext, new MacroDefinitionHandler()
            {
                @Override
                public void handle(MacroDefinition macroDefinition)
                {
                    macros.add(macroDefinition);
                }
            });
        }
        catch (XhtmlException e)
        {
            throw new MacroExecutionException(e);
        }

        StringBuilder builder = new StringBuilder();
        builder.append("<p>");
        if (!macros.isEmpty())
        {
            builder.append("<table width=\"50%\">");
            builder.append("<tr><th>Macro Name</th><th>Has Body?</th></tr>");
            for (MacroDefinition defn : macros)
            {
                builder.append("<tr>");
                builder.append("<td>").append(defn.getName()).append("</td><td>").append(defn.hasBody()).append("</td>");
                builder.append("</tr>");
            }
            builder.append("</table>");
        }
        else
        {
            builder.append("You've done built yourself a macro! Nice work.");
        }
        builder.append("</p>");

        return builder.toString();

    }

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

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

7)修改了atlassian-plugin.xml文件

<atlassian-plugin key="${atlassian.plugin.key}" 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}" />
        <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="tutorial-confluence-macro-demo"/>

    <xhtml-macro name="tutorial-confluence-macro-demo" class="com.example.plugins.tutorial.confluence.ExampleMacro" key="my-macro">
        <parameters/>
    </xhtml-macro>

    <!-- add our web resources -->
    <web-resource key="tutorial-confluence-macro-demo-resources" name="tutorial-confluence-macro-demo Web Resources">
        <dependency>com.atlassian.auiplugin:ajs</dependency>

        <resource type="download" name="tutorial-confluence-macro-demo.css" location="/css/tutorial-confluence-macro-demo.css"/>
        <resource type="download" name="tutorial-confluence-macro-demo.js" location="/js/tutorial-confluence-macro-demo.js"/>
        <resource type="download" name="images/" location="/images"/>

        <context>tutorial-confluence-macro-demo</context>
    </web-resource>

</atlassian-plugin>

8)开始融合

atlas-clean
atlas-package
atlas-debug

9)登录汇合

这是汇合管理页面的结果

Confluence Administration Page

现在我也可以在宏浏览器中找到它并且它可以正常工作

enter image description here

由于 Hauke

2 个答案:

答案 0 :(得分:1)

使用atlassian插件真的很令人沮丧:)

我检查了宏source code from bitbucket并在pom中进行了以下更改

<properties>
    <confluence.version>5.9.7</confluence.version>
    <confluence.data.version>5.9.7</confluence.data.version>
    <amps.version>6.2.4</amps.version>
    <plugin.testrunner.version>1.1.1</plugin.testrunner.version>
</properties>

然后运行

atlas-clean
atlas-package
atlas-debug

之后,我可以使用宏浏览器添加宏(使用汇总5.8.6实例)。

不幸的是,我没有时间检查源代码和教程之间的差异,但我的解决方案会给你一个工作状态来尝试新的东西。

答案 1 :(得分:0)

您的图片正在显示${atlassian.plugin.key}。您的宏插件是否正常工作。它显示在宏浏览器中,但您可以在页面上使用它吗?我还注意到您在atlassian.plugin.key中注释了pom.xml

  

使用&lt; Atlassian-Plugin-Key&gt;这里告诉插件系统你是一个无变压器的插件,它应该跳过慢转换步骤。这是非常重要的。如果您的Manifest中没有此条目,插件系统将尝试转换您的插件,您将失去加载时间速度优势。您也可能会看到与Spring相关的错误。不要忘记指定此条目。

请参阅:Atlassian Spring Scanner

导入组件的新方法是使用Atlassian Spring Scanner。您可以通过注释atlassian.plugin.key来混合使用新旧导入组件的方式。

退房:Build a Macro Add-on

汇合示例:Confluence Add-on Development examples