Skip to content

Commit

Permalink
[Update]: build a spring boot application
Browse files Browse the repository at this point in the history
  • Loading branch information
yutaro-sakamoto committed Oct 22, 2024
1 parent 0ce384b commit dff0a9d
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 105 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "server/opensourcecobol4j"]
path = server/opensourcecobol4j
path = server/app/opensourcecobol4j
url = https://github.com/yutaro-sakamoto/opensourcecobol4j
2 changes: 2 additions & 0 deletions server/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/main/java/cobol4j/aws/web/sample*.java
lib/
126 changes: 122 additions & 4 deletions server/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")

Expand All @@ -48,3 +63,106 @@ tasks.named<Test>("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<Exec>("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<Exec>("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<Exec>("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")
}
File renamed without changes.
1 change: 1 addition & 0 deletions server/app/opensourcecobol4j
Submodule opensourcecobol4j added at e1dfe8
10 changes: 5 additions & 5 deletions server/app/src/main/java/cobol4j/aws/web/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
93 changes: 0 additions & 93 deletions server/build.gradle.kts

This file was deleted.

1 change: 0 additions & 1 deletion server/opensourcecobol4j
Submodule opensourcecobol4j deleted from 3dcaa5
2 changes: 1 addition & 1 deletion server/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ plugins {
}

rootProject.name = "cobol4j-aws-web"
//include("app")
include("app")

0 comments on commit dff0a9d

Please sign in to comment.