tohokuaikiのチラシの裏

技術的ネタとか。

Confluenceのプラグインを作ってみるメモ(2)

WikiWorksというConfluenceからHTMLマニュアルとかなどを出力する製品を作ってて、Confluence自体に手を入れたかったのでプラグインを作ってみようと思ったのが発端。

プラグインのスケルトンを作る

Scaffoldみたいな感じ。

  • 適当なところに空のディレクトリを作る C:\Users\itoh\ConfluencePluginDev
  • cmdを立ち上げて、そこに移動する。そして、atlas-create-APPLICATION-pluginをコマンドする。APPLICATIONには、confluenceとかjiraとか入る。なんか、おもむろにダウンロードし始める。そのプロジェクトのソースコードを一式ダウンロードして、buildするので結構い時間が掛かります。
  • プロンプトが出てきたら、次の設定値を入れる。

'groupID' ― あなたのプロジェクト名に相当するもの。たとえばcom.mycompany.confluence.pluginsみたいな感じで。これはデフォルトでパッケージ名になります。
'artifactId' ― 「sarahtest」みたいなプラグイン名。スペースは含めてはいけない。
'version' ―  バージョン名デフォルトでリターンすると「1.0-SNAPSHOT」
'package' ― パッケージ名。このままリターンするとgroupIDと同じになる。

  • これらを入れて良ければYをさらに続けて入力リターン。すると「BUILD SUCCESSFUL」と出ればOK.Warningが出てもこの時点では無視してよい。

エラーメッセージとか出たら↓見るといいみたい。
http://confluence.atlassian.com/display/DEVNET/Writing+your+first+plugin+FAQ

NetBeansで開く

先ほど作ったスケルトンはpom.xmlがあるので、mavenプロジェクトとして認識される。

そこで、「ファイル」→「プロジェクトを開く」で開く

こんな感じ。

プラグインがインストールされた状態のApplicationを起動する

http://confluence.atlassian.com/display/DEVNET/Step+2.+Start+the+Host+Application+with+your+Plugin+Installed
今の場合は、Confluenceね。1900番ポートで開く。というのがどっかで書いてあった。忘れた。

起動のさせ方

  • cmdを立ち上げて、さっき作ったスケルトンのpom.xmlのあるディレクトリまで移動
  • atlas-run を実行。・・・最初はガバっとソースを落としてくるのでちょっと時間が掛かる。もしWindowsとかでセキュリティソフトに引っかかったらOKしてあげて。
  • 全部が終わると

[WARNING] [talledLocalContainer] INFO: Server startup in 87246 ms
[INFO] [talledLocalContainer] Tomcat 6.x started on port [1990]
[INFO] confluence started successfully and available at http://localhost:1990/confluence
[INFO] Type CTRL-C to exit

というメッセージが出るので、http://localhost:1990/confluence をブラウザで開く。ID/PASSともに"admin"。で、自分のプラグインがデプロイされているのを見つける


ダウンロードしたのは、ソースコードではなく、JARファイルなのでソースコードが欲しい場合はまた別途。

IDEでプロジェクトのファイルを作ったりする

http://confluence.atlassian.com/display/DEVNET/Step+3.+Generate+Project+Files+for+your+IDE
http://confluence.atlassian.com/display/DEVNET/Step+4.+Write+Some+Code

pom.xmlをいじる
  • 会社名とかプラグインに関する情報とかいろいろここでいじくる
  • 依存関係とかあればここで。nekohtmlとか使ってるよ。
atlassian-plugin.xmlをいじる
  • plugin-modulesっていう値があって、それは色々重要らしい。Confluenceだと、そのプラグインでマクロを定義したり、editorでWYSYWYGのアレを改造できるらしい。


とかやってると、NetBeansでエラーが出てた。

右クリックして「問題を表示して解決」を見ると

2 problems were encountered while building the effective model for jp.junoe.confluence.plugins:firstplugin:1.0-SNAPSHOT
[ERROR] Unresolveable build extension: Plugin com.atlassian.maven.plugins:maven-confluence-plugin:3.2.4 or one of its dependencies could not be resolved: The following artifacts could not be resolved: junit:junit:jar:3.8.1, org.apache.maven.reporting:maven-reporting-api:jar:2.0.6, org.apache.maven.doxia:doxia-sink-api:jar:1.0-alpha-8, org.codehaus.plexus:plexus-interpolation:jar:1.11, org.codehaus.plexus:plexus-interactivity-api:jar:1.0-alpha-4, backport-util-concurrent:backport-util-concurrent:jar:3.1, org.sonatype.plexus:plexus-sec-dispatcher:jar:1.1, org.sonatype.plexus:plexus-cipher:jar:1.1: The repository system is offline but the artifact junit:junit:jar:3.8.1 is not available in the local repository. @
[ERROR] Unknown packaging: atlassian-plugin @ line 19, column 16
for project jp.junoe.confluence.plugins:firstplugin:1.0-SNAPSHOT at C:\Users\itoh\ConfluencePluginDev\firstplugin\pom.xml

とか出てる。

んーーとか思って、なんかmavenの依存関係でこけてる・・・・。そこで「その(1)」でやったpom.xmlの調整をしてみる。

要するに。

    <properties>
        <maven.local.repo>C:\AtlassianDev\atlassian-plugin-sdk-3.2.4\repository</maven.local.repo>        
        <confluence.version>3.4.7</confluence.version>
        <confluence.data.version>3.1</confluence.data.version>
    </properties>
	
    <repositories>
        <repository>
            <id>atlassian</id>
            <name>Atlassian Repository</name>
            <url>https://maven.atlassian.com/repository/public/</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </repository>
    </repositories>
 
 
    <pluginRepositories>
        <pluginRepository>
            <id>atlassian-public</id>
            <url>http://maven.atlassian.com/public</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

を加えてみた。

すると、いつの間にかなんとなくうまくいっていた。

あ、atlassian-publicのURLはこのページからなんとなく。


修正とデバッグ

http://confluence.atlassian.com/display/DEVNET/Step+5.+Run+your+Changes
コードを書き換えた際は、次のようにしてリコンパイル

  1. cmd開いて、作ってるpluginのrootディレクトリまで移動
  2. atlas-cliを実行させてしばらく待つ。
  3. しばらくすると、maven2> みたいなコマンドプロンプトが出てくるので、おもむろにpiと打つ。これはプラグインをインストールする。という意味。
  4. ブラウザを開いてみよう。さっきまでインストールされてなかったキミのプラグインがインストールされている。

そのほかのコマンド

  • atlas-compile でプラグインのリコンパイル
  • atlas-unit-test でUNITテストを走らせる
  • atlas-package でJARファイルを生成
  • atlas-debug を atlas-run の代わりに使うと、Debug情報がみられる。これをIDEのリモートデバッグと強調させると便利。localhostの5005ポートに吐き出すそうだ。

NetBeansだと、「デバッグ」→「デバッガを接続」でこんな感じ

すげー。当然かもしれないけど、これはIDE触ったことない時分にはカルチャーショックです。


maven2のヘルプメッセージは下記の通り

Goal commands:
clean org.apache.maven.plugins:maven-clean-plugin:clean
compile org.apache.maven.plugins:maven-compiler-plugin:compile
dependency-analyze org.apache.maven.plugins:maven-dependency-plugin:analyze
dependency-purge org.apache.maven.plugins:maven-dependency-plugin:purge-local-repository
dependency-resolve org.apache.maven.plugins:maven-dependency-plugin:resolve
dependency-resolve-plugins org.apache.maven.plugins:maven-dependency-plugin:resolve-plugins
dependency-tree org.apache.maven.plugins:maven-dependency-plugin:tree
deploy org.apache.maven.plugins:maven-deploy-plugin:deploy
help-allprofiles org.apache.maven.plugins:maven-help-plugin:all-profiles
help-effectivesettings org.apache.maven.plugins:maven-help-plugin:effective-settings
help-system org.apache.maven.plugins:maven-help-plugin:system
install org.apache.maven.plugins:maven-install-plugin:install
jar org.apache.maven.plugins:maven-jar-plugin:jar
package resources com.atlassian.maven.plugins:maven-confluence-plugin:filter-plugin-descriptor compile com.atlassian.maven.plugins:maven-confluence-plugin:copy-bundled-dependencies com.atlassian.maven.plugins:maven-confluence-plugin:generate-manifest com.atlassian.maven.plugins:maven-confluence-plugin:jar
pi resources com.atlassian.maven.plugins:maven-confluence-plugin:filter-plugin-descriptor compile com.atlassian.maven.plugins:maven-confluence-plugin:copy-bundled-dependencies com.atlassian.maven.plugins:maven-confluence-plugin:compress-resources com.atlassian.maven.plugins:maven-confluence-plugin:generate-manifest com.atlassian.maven.plugins:maven-confluence-plugin:validate-manifest com.atlassian.maven.plugins:maven-confluence-plugin:jar com.atlassian.maven.plugins:maven-confluence-plugin:install
resources org.apache.maven.plugins:maven-resources-plugin:resources
test org.apache.maven.plugins:maven-surefire-plugin:test
testCompile org.apache.maven.plugins:maven-compiler-plugin:testCompile
testResources org.apache.maven.plugins:maven-resources-plugin:testResources
war org.apache.maven.plugins:maven-war-plugin:war

Exit commands:
quit, exit, bye

List module commands:
list, ls

Help commands:
help, ?

基本的に、maven2コマンドラインでpiコマンドすれば変更点が反映されるみたい。少なくともConfluenceのプラグインはそう。JIRAの一部のPluginではこれが利かないみたい。

あと、pom.xml を直した場合はmaven2を抜けて、atlas-cliからやり直さないとだめ。

JARファイルのパッケージング

atlas-package コマンドを使って簡単にできる。
targetディレクトリにjarファイルができる。

あと
http://confluence.atlassian.com/display/DEVNET/Packaging+and+Releasing+your+Plugin
にこまごまとあるけど、ライセンス決めて公開しましょうってことかな?