Skip to content

Commit e951877

Browse files
committed
指定されたテンプレートのディレクトリが存在しない場合はエラーを表示して終了。
修正前では、存在しない場合にデフォルトのテンプレートでスケルトンを生成していた。 つまり、エラーを出さなかったので、パスの指定間違いに気付きにくかったため修正した。
1 parent c5cc60e commit e951877

5 files changed

Lines changed: 17 additions & 2 deletions

File tree

modules/deviceconnect-codegen/src/main/java/org/deviceconnect/codegen/DConnectCodegen.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,12 @@ public static void main(String[] args) {
162162
}
163163
}
164164
if (cmd.hasOption("t")) {
165-
clientOpts.getProperties().put(CodegenConstants.TEMPLATE_DIR, String.valueOf(cmd.getOptionValue("t")));
165+
String dirPath = String.valueOf(cmd.getOptionValue("t"));
166+
if (!new File(dirPath).exists()) {
167+
reportError(new Errors.TemplateDirNotFound(dirPath));
168+
return;
169+
}
170+
clientOpts.getProperties().put(CodegenConstants.TEMPLATE_DIR, dirPath);
166171
}
167172

168173
String displayName;

modules/deviceconnect-codegen/src/main/java/org/deviceconnect/codegen/error/Errors.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ public UnrecognizedOption(final UnrecognizedOptionException e) {
7979
}
8080
}
8181

82+
public static class TemplateDirNotFound extends CodegenError {
83+
84+
public TemplateDirNotFound(final String dirPath) {
85+
String message = getMessageForKey("errorTemplateDirNotFound");
86+
mMessage = message + ": " + dirPath;
87+
}
88+
}
89+
8290
public static class InvalidJson extends CodegenError {
8391
public InvalidJson(final File file, final JsonProcessingException e) {
8492
ErrorFormat format = new ErrorFormat("json");

modules/deviceconnect-codegen/src/main/resources/Messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
errorMissingOption=Missing option
22
errorMissingArgument=Missing argument for option
33
errorAlreadySelectedOption=Already selected option
4+
errorTemplateDirNotFound=Template directory is not Found
45
errorUndefinedOption=Undefined option
56
errorInvalidSwagger=Invalid Swagger 2.0 file
67

modules/deviceconnect-codegen/src/main/resources/Messages_ja.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
errorMissingOption=必須オプションが指定されていません
22
errorMissingArgument=オプションに対して引数が指定されていません
33
errorAlreadySelectedOption=選択済みのオプションです
4+
errorTemplateDirNotFound=テンプレート用ディレクトリが見つかりません
45
errorUndefinedOption=未定義のオプションが指定されています
56
errorInvalidSwagger=Swagger 2.0 として不正なファイルが入力されました
67

samples/android-plugin.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ DISPLAY_NAME="MyPlugin"
2121
# スケルトンコード生成ツールのバイナリ
2222
JAR_FILE="../bin/deviceconnect-codegen.jar"
2323

24-
ARGS="--input-spec $SPEC --lang deviceConnectAndroidPlugin --config configs/android-plugin.json --template-dir $TEMPLATE_DIR --package-name $PACKAGE_NAME --connection-type $CONNECTION_TYPE --display-name $DISPLAY_NAME --output $OUTPUT_DIR"
24+
ARGS="--overwrite --input-spec $SPEC --lang deviceConnectAndroidPlugin --config configs/android-plugin.json --template-dir $TEMPLATE_DIR --package-name $PACKAGE_NAME --connection-type $CONNECTION_TYPE --display-name $DISPLAY_NAME --output $OUTPUT_DIR"
2525

2626
java -Dfile.encoding=UTF-8 -jar $JAR_FILE $ARGS

0 commit comments

Comments
 (0)