Skip to content

Commit

Permalink
chore: バージョン情報をpropertiesファイルから取得するように変更した #62 (#77)
Browse files Browse the repository at this point in the history
* chore: Version.javaをKotlinに移植した

* 埋め込む文字列はpropertiesファイルで管理するように変更
  • Loading branch information
jiro4989 authored Dec 27, 2021
1 parent da4239c commit 6c8bb7a
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 40 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ apply plugin: 'org.junit.platform.gradle.plugin'
// に値を差し替える。
def commitHash = 'dev'

def VERSION_JAVA_FILE = 'Version.java'
def SRC_FILE = 'template/' + VERSION_JAVA_FILE
def DST_DIR = 'src/main/java/com/jiro4989/tkfm'
def DST_FILE = DST_DIR + '/' + VERSION_JAVA_FILE
def VERSION_SOURCE_FILE = 'application.properties'
def SRC_FILE = 'template/' + VERSION_SOURCE_FILE
def DST_DIR = 'src/main/resources/com/jiro4989/tkfm/properties'
def DST_FILE = DST_DIR + '/' + VERSION_SOURCE_FILE

def LIB_DIR = './lib'

Expand Down
6 changes: 0 additions & 6 deletions src/main/java/com/jiro4989/tkfm/Version.java

This file was deleted.

28 changes: 19 additions & 9 deletions src/main/kotlin/com/jiro4989/tkfm/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.jiro4989.tkfm

import com.jiro4989.tkfm.controller.MainViewController
import com.jiro4989.tkfm.model.WindowPropertiesModel
import java.util.Properties
import javafx.application.Application
import javafx.fxml.FXMLLoader
import javafx.scene.Scene
Expand All @@ -13,15 +14,6 @@ val title = "TKoolFacetileMaker2"

/** プログラムのエントリーポイント */
fun main(args: Array<String>) {
println("--------------------------------------------")
println("application_name: $title")
println("version: ${Version.version}")
println("commit_hash: ${Version.commitHash}")
println("document: README.txt")
println("author: 次郎 (jiro)")
println("contact: https://twitter.com/jiro_saburomaru")
println("--------------------------------------------")

Application.launch(Main::class.java, *args)
}

Expand All @@ -33,6 +25,7 @@ class Main : Application() {
private val prop = WindowPropertiesModel()

override fun start(primaryStage: Stage) {
printApplicationInformation()
prop.load()
stage = primaryStage
try {
Expand Down Expand Up @@ -69,4 +62,21 @@ class Main : Application() {
store()
}
}

fun printApplicationInformation() {
val property = Properties()
this.javaClass.getResourceAsStream("properties/application.properties")?.bufferedReader().use {
property.load(it)
}
val version = property.get("version")
val commitHash = property.get("commithash")
println("--------------------------------------------")
println("application_name: $title")
println("version: $version")
println("commit_hash: $commitHash")
println("document: README.txt")
println("author: 次郎 (jiro)")
println("contact: https://twitter.com/jiro_saburomaru")
println("--------------------------------------------")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version = dev
commithash = dev
13 changes: 0 additions & 13 deletions src/test/java/com/jiro4989/tkfm/VersionTest.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ class PropertiesModelTest {
fun testLoadStoreChoosedFile() {
val p = ChoosedFilePropertiesModel(file = configFile("test_choosed_file"))
// 存在するファイルなら何でも良い
p.openedFile = File("src/main/java/com/jiro4989/tkfm/Version.java")
p.openedFile = File("src/main/kotlin/com/jiro4989/tkfm/controller/MainViewController.kt")
p.savedFile = File("src/main/kotlin/com/jiro4989/tkfm/Main.kt")
p.store()

p.load()
assertNotNull(p.openedFile)
p.openedFile?.let { assertEquals("Version.java", it.name) }
p.openedFile?.let { assertEquals("MainViewController.kt", it.name) }
assertNotNull(p.savedFile)
p.savedFile?.let { assertEquals("Main.kt", it.name) }
}
Expand Down
6 changes: 0 additions & 6 deletions template/Version.java

This file was deleted.

2 changes: 2 additions & 0 deletions template/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version = $version
commithash = $commitHash

0 comments on commit 6c8bb7a

Please sign in to comment.