diff --git a/.github/workflows/server-app.yml b/.github/workflows/server-app.yml index 0d89695..457d98f 100644 --- a/.github/workflows/server-app.yml +++ b/.github/workflows/server-app.yml @@ -29,8 +29,8 @@ jobs: java-version: "17" - name: Build with Gradle - run: ./gradlew build + run: ./gradlew bootJar - - name: Run tests - if: ${{ github.event.inputs.run_tests }} - run: ./gradlew test + #- name: Run tests + # if: ${{ github.event.inputs.run_tests }} + # run: ./gradlew test diff --git a/.gitmodules b/.gitmodules index 54d568b..ec50465 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "server/opensourcecobol4j"] - path = server/opensourcecobol4j + path = server/app/opensourcecobol4j url = https://github.com/yutaro-sakamoto/opensourcecobol4j diff --git a/server/app/.gitignore b/server/app/.gitignore new file mode 100644 index 0000000..f0d5161 --- /dev/null +++ b/server/app/.gitignore @@ -0,0 +1,2 @@ +src/main/java/cobol4j/aws/web/sample*.java +lib/ diff --git a/server/app/build.gradle.kts b/server/app/build.gradle.kts index 6e88ed5..ed9398f 100644 --- a/server/app/build.gradle.kts +++ b/server/app/build.gradle.kts @@ -5,6 +5,17 @@ * For more details on building Java & JVM projects, please refer to https://docs.gradle.org/8.2.1/userguide/building_java_projects.html in the Gradle documentation. */ +import java.io.ByteArrayOutputStream + +val compilerBinDir = "${project.projectDir}/compiler_bin" +val libcobjJar = "${compilerBinDir}/lib/opensourcecobol4j/libcobj.jar" +val cobj = "${compilerBinDir}/bin/cobj" +val cobjApi = "${compilerBinDir}/bin/cobj-api" +val javaDir = "${project.projectDir}/src/main/java/cobol4j/aws/web/" +val libDir = "${project.projectDir}/lib" +val libLibcobjJar = "${libDir}/libcobj.jar" +val javaPackage = "cobol4j.aws.web" + plugins { // Apply the application plugin to add support for building a CLI application in Java. application @@ -18,11 +29,15 @@ repositories { dependencies { implementation(platform("org.springframework.boot:spring-boot-dependencies:3.3.4")) - - implementation("org.springframework.boot:spring-boot-starter") - testImplementation("org.springframework.boot:spring-boot-starter-test") { - exclude(mapOf("group" to "org.junit.vintage", "module" to "junit-vintage-engine")) + implementation("org.springframework.boot:spring-boot-starter-web") { + exclude(group = "org.springframework.boot", module = "spring-boot-starter-logging") } + implementation(files("lib/libcobj.jar")) + + //implementation("org.springframework.boot:spring-boot-starter") + //testImplementation("org.springframework.boot:spring-boot-starter-test") { + // exclude(mapOf("group" to "org.junit.vintage", "module" to "junit-vintage-engine")) + //} // Use JUnit Jupiter for testing. testImplementation("org.junit.jupiter:junit-jupiter:5.9.2") @@ -48,3 +63,106 @@ tasks.named("test") { // Use JUnit Platform for unit tests. useJUnitPlatform() } + +// Git管理下にあるファイルを取得する関数 +fun getGitManagedFiles(dir: File): FileTree { + val output = ByteArrayOutputStream() + project.exec { + workingDir = dir + commandLine("git", "ls-files", "-z") + standardOutput = output + } + val gitFiles = output.toString().split("\u0000") + return fileTree(dir) { + include(gitFiles) + } +} + +// opensource COBOL 4J のビルドタスクを追加 +tasks.register("buildCompiler") { + group = "build" + description = "Build opensource COBOL 4J" + + // 作業ディレクトリを指定 + val opensourcecobol4jDir = file("${project.projectDir}/opensourcecobol4j/") + + workingDir = opensourcecobol4jDir + + // 入力ファイルを指定 + inputs.files(getGitManagedFiles(opensourcecobol4jDir)) + + // 出力ファイルを指定 + outputs.files( + file(libcobjJar), + file(cobj), + file(cobjApi), + ) + + // 実行コマンドを指定 + commandLine("sh", "-c", """ + mkdir -p ${compilerBinDir} && + ./configure --prefix=${compilerBinDir} && + make && + make install + """.trimIndent()) +} + +tasks.register("moveLibcobjJar") { + dependsOn("buildCompiler") + + group = "build" + description = "Move libcobj.jar to lib directory" + + // 入力ファイルを指定 + inputs.files(file(libcobjJar)) + + // 出力ファイルを指定 + outputs.files(file(libLibcobjJar)) + + // 実行コマンドを指定 + commandLine("sh", "-c", """ + mkdir -p ${libDir} && + cp ${libcobjJar} ${libLibcobjJar} + """.trimIndent()) +} + +tasks.register("buildCobol") { + dependsOn("buildCompiler") + + group = "build" + description = "Build COBOL source files" + + val cobolDir = "${project.projectDir}/cobol/" + val jsonDir = "${project.projectDir}/json" + + // 作業ディレクトリを指定 + workingDir = file(cobolDir) + + // 入力ファイルと出力ファイルを指定 + inputs.files( + file(libcobjJar), + file(cobj), + file(cobjApi), + fileTree(cobolDir), + ) + + // 出力ファイルを指定 + outputs.files( + file("${javaDir}/sample.java"), + file("${javaDir}/sampleController.java"), + file("${javaDir}/sampleRecord.java"), + file("${jsonDir}/info_sample.json"), + ) + + commandLine("sh", "-c", """ + mkdir -p ${jsonDir} && + ${cobj} -info-json-dir=${jsonDir} -C -java-package=${javaPackage} *.cbl && + mv *.java ${javaDir} && + CLASSPATH=:${libcobjJar} ${cobjApi} --output-dir=${javaDir} -java-package=${javaPackage} ${jsonDir}/info_sample.json + """) +} + +tasks.named("compileJava") { + dependsOn("buildCobol") + dependsOn("moveLibcobjJar") +} diff --git a/server/cobol/sample.cbl b/server/app/cobol/sample.cbl similarity index 100% rename from server/cobol/sample.cbl rename to server/app/cobol/sample.cbl diff --git a/server/app/opensourcecobol4j b/server/app/opensourcecobol4j new file mode 160000 index 0000000..e1dfe8b --- /dev/null +++ b/server/app/opensourcecobol4j @@ -0,0 +1 @@ +Subproject commit e1dfe8b10bf693dfc1e4437e05e2f0df40789f5c diff --git a/server/app/src/main/java/cobol4j/aws/web/App.java b/server/app/src/main/java/cobol4j/aws/web/App.java index d3653e5..cc2f13b 100644 --- a/server/app/src/main/java/cobol4j/aws/web/App.java +++ b/server/app/src/main/java/cobol4j/aws/web/App.java @@ -3,12 +3,12 @@ */ package cobol4j.aws.web; -public class App { - public String getGreeting() { - return "Hello World!"; - } +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +@SpringBootApplication +public class App { public static void main(String[] args) { - System.out.println(new App().getGreeting()); + SpringApplication.run(App.class, args); } } diff --git a/server/build.gradle.kts b/server/build.gradle.kts deleted file mode 100644 index 317a55d..0000000 --- a/server/build.gradle.kts +++ /dev/null @@ -1,93 +0,0 @@ -import java.io.ByteArrayOutputStream - -// Git管理下にあるファイルを取得する関数 -fun getGitManagedFiles(dir: File): FileTree { - val output = ByteArrayOutputStream() - project.exec { - workingDir = dir - commandLine("git", "ls-files", "-z") - standardOutput = output - } - val gitFiles = output.toString().split("\u0000") - return fileTree(dir) { - include(gitFiles) - } -} - -val compilerBinDir = "${project.projectDir}/compiler_bin" -val libcobjJar = "${compilerBinDir}/lib/opensourcecobol4j/libcobj.jar" -val cobj = "${compilerBinDir}/bin/cobj" -val cobjApi = "${compilerBinDir}/bin/cobj-api" - -// opensource COBOL 4J のビルドタスクを追加 -tasks.register("buildCompiler") { - group = "build" - description = "Build opensource COBOL 4J" - - // 作業ディレクトリを指定 - val opensourcecobol4jDir = file("${project.projectDir}/opensourcecobol4j/") - - workingDir = opensourcecobol4jDir - - // 入力ファイルを指定 - inputs.files(getGitManagedFiles(opensourcecobol4jDir)) - - // 出力ファイルを指定 - outputs.files( - file(libcobjJar), - file(cobj), - file(cobjApi), - ) - - // 実行コマンドを指定 - commandLine("sh", "-c", """ - mkdir -p ${compilerBinDir} && - ./configure --prefix=${compilerBinDir} && - make && - make install - """.trimIndent()) -} - -tasks.register("buildCobol") { - dependsOn("buildCompiler") - - group = "build" - description = "Build COBOL source files" - - val cobolDir = "${project.projectDir}/cobol/" - val javaDir = "${project.projectDir}/app/src/main/java/cobol4j/aws/web/" - val jsonDir = "${project.projectDir}/json" - - // 作業ディレクトリを指定 - workingDir = file(cobolDir) - - // 入力ファイルと出力ファイルを指定 - inputs.files( - file(libcobjJar), - file(cobj), - file(cobjApi), - fileTree(cobolDir), - ) - - // 出力ファイルを指定 - outputs.files( - file("${javaDir}/sample.java"), - file("${javaDir}/sampleController.java"), - file("${javaDir}/sampleRecord.java"), - file("${jsonDir}/info_sample.json"), - ) - - commandLine("sh", "-c", """ - mkdir -p ${jsonDir} && - ${cobj} -info-json-dir=${jsonDir} -C *.cbl && - mv *.java ${javaDir} && - CLASSPATH=:${libcobjJar} ${cobjApi} --output-dir=${javaDir} ${jsonDir}/info_sample.json - """) -} - -// buildタスクを明示的に定義 -tasks.register("build") { - group = "build" - description = "Builds the project" - dependsOn("buildCobol") -} \ No newline at end of file diff --git a/server/opensourcecobol4j b/server/opensourcecobol4j deleted file mode 160000 index 3dcaa5c..0000000 --- a/server/opensourcecobol4j +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3dcaa5c3349cef838dc65ab6e967401befc18ce3 diff --git a/server/settings.gradle.kts b/server/settings.gradle.kts index e29c86c..5f6200c 100644 --- a/server/settings.gradle.kts +++ b/server/settings.gradle.kts @@ -11,4 +11,4 @@ plugins { } rootProject.name = "cobol4j-aws-web" -//include("app") +include("app")