本ページではKotlinでastah*プラグインを開発する手順を記載します。


1. プロジェクト作成

プラグインプロジェクトを新規作成します。
プラグインプロジェクトを作成したいディレクトリへ移動し、次のコマンドを入力しましょう。

astah* professional、UMLの場合
> astah-generate-project
astah* SysMLの場合
> astah-sysml-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でプロジェクトをインポートします。

>

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ファイル修正 ①

4. pom.xml を開き、(※SDK1.4では、手順4は不要です)


xml:
<plugin>
          <artifactId>maven-compiler-plugin</artifactId>
					<version>2.3.2</version>
					<configuration>
					  <encoding>UTF-8</encoding>
						<source>1.6</source>
						<target>1.6</target>
					</configuration>
</plugin>

の部分を削除し、


xml:
<plugin>
        <artifactId>maven-compiler-plugin</artifactId>
				<version>3.6.1</version>
				<configuration>
				<encoding>UTF-8</encoding>
				<source>1.8</source>
				<target>1.8</target>
				</configuration>
</plugin>

を追記してください。



5. XMLファイル修正 ②

同じく、pom.xml


xml:
<plugin>
        <groupId>org.jetbrains.kotlin</groupId>
				<artifactId>kotlin-maven-plugin</artifactId>
				<version>${kotlin.version}</version>
				<executions>
				     <execution>
						      <id>compile</id>
							    <phase>compile</phase>


xml:
 <phase>compile</phase>;

の部分を削除し、


xml:
 <phase>process-sources</phase>

を追記してください。


6. ビルド

プロジェクトのフォルダに移動して、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] ------------------------------------------------------------------------
							$

7. 実行

確かめてみましょう。コマンドラインから astah-launch を実行してください。
astah*が立ち上がった後、新しいプロジェクトを作成し、次のメニューを選択してください。



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



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