本ページではKotlinでastah*プラグインを開発する手順を記載します。
1. プロジェクト作成
プラグインプロジェクトを新規作成します。
プラグインプロジェクトを作成したいディレクトリへ移動し、次のコマンドを入力してください。
astah* professional、UML
> astah-generate-project
astah* SysML
> astah-sysml-generate-project
astah* System Safety
> astah-safety-generate-project
bash: $ astah-generate-project [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Stub Project (No POM) 1 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] >>> maven-archetype-plugin:2.4:generate (default-cli) @ standalone-pom >>> [INFO] [INFO] <<< maven-archetype-plugin:2.4:generate (default-cli) @ standalone-pom <<< [INFO] [INFO] --- maven-archetype-plugin:2.4:generate (default-cli) @ standalone-pom --- [INFO] Generating project in Interactive mode [INFO] Archetype [com.change_vision.astah:plugin-archetype:1.0.0] found in catalog file:////Users/takaitoshinori/astah-plugin-SDK-1.3/repository/archetype-catalog.xml Define value for property 'groupId': : com.example Define value for property 'artifactId': : hello Define value for property 'version': 1.0-SNAPSHOT: : Define value for property 'package': com.example: : Confirm properties configuration: groupId: com.example artifactId: hello version: 1.0-SNAPSHOT package: com.example Y: : y [INFO] ---------------------------------------------------------------------------- [INFO] Using following parameters for creating project from Archetype:
plugin-archetype:1.0.0 [INFO] ---------------------------------------------------------------------------- [INFO] Parameter: groupId, Value: com.example [INFO] Parameter: artifactId, Value: hello [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] Parameter: package, Value: com.example [INFO] Parameter: packageInPathFormat, Value: com/example [INFO] Parameter: package, Value: com.example [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] Parameter: groupId, Value: com.example [INFO] Parameter: artifactId, Value: hello [INFO] project created from Archetype in dir:
/Users/takaitoshinori/astah-plugin-tests/hello [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 24.130s [INFO] Finished at: Sat Oct 21 21:17:05 JST 2017 [INFO] Final Memory: 13M/123M [INFO] ------------------------------------------------------------------------ $
2. インポート
IntelliJ IDEA の設定を行ったIntelliJでプロジェクトをインポートします。

3.ファイル作成
Kotlinのファイルを1つ作成します。
ここで、KotlinをMavenで使う際のコンフィグレーションするか聞かれますので、
as Kotlin (Maven) module 及び OK を押下してください。


試しに、一つ作ったKotlinのファイルは次のような中身にしておきます。
kotlin:
package com.example
class Hello {
fun hello() {
println("Hello")
}
}
また、これを呼び出すように TempleteAction.java に次のように追記しておきます。
( try のすぐ下です)
java:
package com.example;
import javax.swing.JOptionPane;
import com.change_vision.jude.api.inf.AstahAPI;
import com.change_vision.jude.api.inf.exception.ProjectNotFoundException;
import com.change_vision.jude.api.inf.project.ProjectAccessor;
import com.change_vision.jude.api.inf.ui.IPluginActionDelegate;
import com.change_vision.jude.api.inf.ui.IWindow;
public class TemplateAction implements IPluginActionDelegate {
public Object run(IWindow window) throws UnExpectedException {
try {
Hello hello = new Hello();
hello.hello();
AstahAPI api = AstahAPI.getAstahAPI();
ProjectAccessor projectAccessor = api.getProjectAccessor();
projectAccessor.getProject();
JOptionPane.showMessageDialog(window.getParent(),"Hello");
} catch (ProjectNotFoundException e) {
String message = "Project is not opened.Please open the project or create new project.";
JOptionPane.showMessageDialog(window.getParent(), message,
"Warning", JOptionPane.WARNING_MESSAGE);
} catch (Exception e) {
JOptionPane.showMessageDialog(window.getParent(),
"Unexpected error has occurred.", "Alert",
JOptionPane.ERROR_MESSAGE);
throw new UnExpectedException();
}
return null;
}
}4. XMLファイル修正 ①
先ほどの手順3.ファイル作成で、 pom.xml が書き換わり、maven-compiler-plugin の記述が重複しているはずなので下記手順でマージしてください。
1. 先の記述に後の記述の必要箇所をコピーして貼り付けます。
先の記述:
xml: <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <encoding>UTF-8</encoding> <source>1.8</source> <target>1.8</target> </configuration> <!-- ここへ挿入 --> </plugin>
後の記述:
xml: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <!-- ここからコピー --> <executions> <execution> <id>default-compile</id> <phase>none</phase> </execution> <!-- 中略 --> <execution> <id>testCompile</id> <phase>test-compile</phase> <goals> <goal>testCompile</goal> </goals> </execution> </executions> <!-- ここまで --> </plugin>
2. 後の記述は不要になるので削除します。
5. XMLファイル修正 ②
xml:
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<execution>
<id>compile</id>
<phase>compile</phase>
8行目の以下の部分を削除します
xml: <phase>compile</phase>
以下を追記してください。
xml: <phase>process-sources</phase>
6. XMLファイル修正 ③
maven-bundle-plugin の Export-Package に kotlin.* を追加します。
下記に該当する箇所を書き換えてください。
xml:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<!-- 中略 -->
<!-- | assume public classes are in the top package, and private classes
are under ".internal" -->
<Export-Package>!${bundle.namespace}.internal.*,${bundle.namespace}.*;version="${project.version}"</Export-Package>
<Private-Package>${bundle.namespace}.internal.*</Private-Package>
<!-- 中略 -->
</plugin>以下の部分を削除します
xml:
<Export-Package>!${bundle.namespace}.internal.*,${bundle.namespace}.*;version="${project.version}"</Export-Package>以下を追記してください。
xml:
<Export-Package>!${bundle.namespace}.internal.*,${bundle.namespace}.*,kotlin.*;version="${project.version}"</Export-Package>7. ビルド
プロジェクトのフォルダに移動して、astah-build
を実行します。
ここまでのプロセスがうまくいっていれば、ビルドに成功します。
shell-session: $ cd hello $ ls hello.iml osgi.bnd pom.xml src/ $ astah-build [INFO] Scanning for projects... [WARNING] [WARNING] Some problems were encountered while building the effective model for com.example:hello:jar:1.0-SNAPSHOT [WARNING] 'build.plugins.plugin.(groupId:artifactId)' must be unique but found duplicate declaration of plugin org.apache.maven.plugins:maven-compiler-plugin @ line 264, column 21 [WARNING] [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build. [WARNING] [WARNING] For this reason, future Maven versions might no longer support building such malformed projects. [WARNING] [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building %bundle.name 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ hello --- [INFO] [INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ hello --- [debug] execute contextualize [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 5 resources [INFO] [INFO] --- maven-dependency-plugin:2.4: copy-dependencies (copy-dependencies) @ hello --- [INFO] Copying kotlin-test-1.1.51.jar to /Users/takaitoshinori/astah-plugin-tests/hello/target/classes/ kotlin-test-1.1.51.jar [INFO] Copying junit-4.10.jar to /Users/takaitoshinori/astah-plugin-tests/hello/target/classes/ junit-4.10.jar [INFO] Copying kotlin-stdlib-jre8-1.1.51.jar to /Users/takaitoshinori/astah-plugin-tests/hello/target/classes/ kotlin-stdlib-jre8-1.1.51.jar [INFO] Copying kotlin-stdlib-1.1.51.jar to /Users/takaitoshinori/astah-plugin-tests/hello/target/classes/ kotlin-stdlib-1.1.51.jar [INFO] Copying kotlin-stdlib-jre7-1.1.51.jar to /Users/takaitoshinori/astah-plugin-tests/hello/target/classes/ kotlin-stdlib-jre7-1.1.51.jar [INFO] Copying hamcrest-core-1.1.jar to /Users/takaitoshinori/astah-plugin-tests/hello/target/classes/ hamcrest-core-1.1.jar [INFO] Copying annotations-13.0.jar to /Users/takaitoshinori/astah-plugin-tests/hello/target/classes/ annotations-13.0.jar [INFO] [INFO] --- kotlin-maven-plugin:1.1.51:compile (compile) @ hello --- [INFO] Kotlin version 1.1.51 (JRE 1.8.0_144-b01) [INFO] Compiling Kotlin sources from [/Users/takaitoshinori/astah-plugin-tests/hello/src/main/java] [INFO] Module name is hello [INFO] [INFO] --- maven-compiler-plugin:3.6.1:compile (java-compile) @ hello --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 2 source files to /Users/takaitoshinori/astah-plugin-tests/hello/target/classes [INFO] [INFO] --- maven-compiler-plugin:3.6.1:compile (compile) @ hello --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 2 source files to /Users/takaitoshinori/astah-plugin-tests/hello/target/classes [INFO] [INFO] --- maven-bundle-plugin:2.3.7:bundle (build-manifest) @ hello --- [WARNING] Bundle com.example:hello:jar:1.0-SNAPSHOT : Instructions in Private-Package, or -testpackages that are never used: com\.example\.internal\..*|com\.example\.internal Classpath: Jar:.,Jar:astah-api,Jar:org.osgi.core,Jar:org.osgi.compendium, Jar:kotlin-stdlib-jre8,Jar:kotlin-stdlib,Jar:annotations,Jar:kotlin-stdlib-jre7 [WARNING] Bundle com.example:hello:jar:1.0-SNAPSHOT : Instructions in Export-Package that are never used: com\.example\.internal\..*|com\.example\.internal Classpath: Jar:.,Jar:astah-api,Jar:org.osgi.core,Jar:org.osgi.compendium, Jar:kotlin-stdlib-jre8,Jar:kotlin-stdlib,Jar:annotations,Jar:kotlin-stdlib-jre7 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 20.130s [INFO] Finished at: Sat Oct 21 22:01:01 JST 2017 [INFO] Final Memory: 37M/373M [INFO] ------------------------------------------------------------------------ $
8. 実行
確かめてみましょう。コマンドラインから astah-launch
を実行してください。
astah*が立ち上がった後、新しいプロジェクトを作成し、次のメニューを選択してください。

コンソールプラグインがインストールされていることが前提ですが、次のように、コンソールにもHelloと表示されていれば成功です。

これで、Kotlinでastah*プラグインが作成できるようになりました。