Skip to content

Commit

Permalink
Reimplement with Kotlin (#70)
Browse files Browse the repository at this point in the history
Re-implement in Kotlin

Also

- restructure package
- better sanitize filename
- use proper webmvc test
- cleanup slices 
- fix code-styles
  • Loading branch information
EugenMayer authored Jan 30, 2023
1 parent db63d6a commit 865a550
Show file tree
Hide file tree
Showing 28 changed files with 511 additions and 475 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ docker run --memory 512m --name converter-prod --rm -p 8080:8080 ghcr.io/eugenma
Now convert a `docx` to `html`
```bash
cd officeconverter
curl -F file=@examples/example.docx "localhost:14080/conversion?format=html" -o /tmp/test.html
curl -F file=@src/test/resources/testfiles/withpictures.docx "localhost:14080/conversion?format=html" -o /tmp/test.html
curl -F file=@src/test/resources/testfiles/template.dotx "localhost:14080/conversion?format=html" -o /tmp/test.html
```

## Build
Expand Down
84 changes: 17 additions & 67 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
buildscript {
ext.kotlin_version = '1.8.0'
ext {
// @see https://mvnrepository.com/artifact/org.jodconverter/jodconverter-local
jodconverterVersion = '4.4.6'
Expand All @@ -22,6 +23,14 @@ buildscript {
// @see https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime
jaxb = "4.0.1"
}
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}

ext['log4j2.version'] = '2.19.0'
}

plugins {
Expand All @@ -41,85 +50,26 @@ plugins {

// @see https://plugins.gradle.org/plugin/org.sonarqube
id "org.sonarqube" version "3.5.0.2730"

id "org.jetbrains.kotlin.jvm" version "1.8.0"
id "org.jetbrains.kotlin.plugin.allopen" version "1.8.0"
id "org.jetbrains.kotlin.plugin.spring" version "1.8.0"
}

apply plugin: 'io.spring.dependency-management'
apply plugin: 'kotlin'
apply plugin: 'org.springframework.boot'
apply from: 'gradle/repositories.gradle'
apply from: 'gradle/dependencies.gradle'
apply from: 'gradle/build.gradle'
apply from: 'gradle/tests.gradle'
apply from: 'gradle/spring_bootRun.gradle'
apply from: 'gradle/sonarqube.gradle'
apply from: 'gradle/kotlin.gradle'
apply from: 'gradle/configuration.gradle'

configurations {
compileOnly {
extendsFrom annotationProcessor
}

developmentOnly

providedRuntime

// needed to get lombok working in our tests
testImplementation {
extendsFrom annotationProcessor
}
}

group = 'de.kontextwork'
// this lets us set the version during build using cli -Pversion=1.1.1
version = "${version}"
sourceCompatibility = 17
targetCompatibility = 17

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

ext['log4j2.version'] = '2.19.0'

// @see https://github.com/sbrannen/spring-events/blob/master/build.gradle#L38
// and @see https://stackoverflow.com/a/54605523/3625317
dependencies {
implementation(
"org.jodconverter:jodconverter-local:$jodconverterVersion",
"org.jodconverter:jodconverter-spring-boot-starter:$jodconverterVersion",
"org.springframework.boot:spring-boot-starter-web",
"org.springframework:spring-core",
"commons-io:commons-io:$commonsIo",

// needed when compiling against > Java 8 since jaxb is no longer included
// you would get Error creating bean with name 'xmlModelPlugin': Lookup method resolution failed
"org.glassfish.jaxb:jaxb-runtime:$jaxb"
)

testImplementation(
"org.springframework.boot:spring-boot-starter-test",
"org.junit.jupiter:junit-jupiter-api",
"org.junit.jupiter:junit-jupiter-params",
"org.mockito:mockito-core:$mockitoVersion",
"org.mockito:mockito-junit-jupiter:$mockitoVersion",
"org.apache.tika:tika-core:${tikaVersion}",
"org.apache.tika:tika-parsers:${tikaVersion}",
)

testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")

annotationProcessor(
"javax.annotation:javax.annotation-api:$javaxAnnotations",
"org.projectlombok:lombok:$lombokVersion"
)

testAnnotationProcessor(
"org.projectlombok:lombok:$lombokVersion",
)

compileOnly(
"org.projectlombok:lombok:$lombokVersion",
"org.springframework.boot:spring-boot-configuration-processor"
)

developmentOnly("org.springframework.boot:spring-boot-devtools")

providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
}
Binary file removed examples/example.docx
Binary file not shown.
24 changes: 24 additions & 0 deletions gradle/configuration.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
configurations {
compileOnly {
// If we enable this, we will rebuild the entire project everytime we change anything, not compile cache
extendsFrom annotationProcessor
}
developmentOnly {}
runtimeClasspath {
extendsFrom developmentOnly
}

// needed to get lombok working in our tests
testImplementation {
extendsFrom testAnnotationProcessor
// we do not need junit5 asserts / integrations, remove for more auto include convenience
exclude module: 'junit'
// exclude hamcrest so we do not mix assertThat with assertj - we only use assertj
// exclude group: 'org.hamcrest', module: 'hamcrest-library'
// exclude group: 'org.hamcrest', module: 'hamcrest-core'
}

// Exclude Springs default logging framework since we use Log4j2g
all*.exclude module : 'spring-boot-starter-logging'
all*.exclude module : 'logback-classic'
}
51 changes: 51 additions & 0 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

// @see https://github.com/sbrannen/spring-events/blob/master/build.gradle#L38
// and @see https://stackoverflow.com/a/54605523/3625317
dependencies {
implementation(
"org.jodconverter:jodconverter-local:$jodconverterVersion",
"org.jodconverter:jodconverter-spring-boot-starter:$jodconverterVersion",
"org.springframework.boot:spring-boot-starter-web",
"org.springframework:spring-core",
"commons-io:commons-io:$commonsIo",

// needed when compiling against > Java 8 since jaxb is no longer included
// you would get Error creating bean with name 'xmlModelPlugin': Lookup method resolution failed
"org.glassfish.jaxb:jaxb-runtime:$jaxb",

"org.jetbrains.kotlin:kotlin-reflect",
"org.jetbrains.kotlin:kotlin-stdlib-jdk8",
'org.apache.logging.log4j:log4j-api-kotlin:1.2.0'
)

testImplementation(
"org.springframework.boot:spring-boot-starter-test",
"org.junit.jupiter:junit-jupiter-api",
"org.junit.jupiter:junit-jupiter-params",
"org.mockito:mockito-core:$mockitoVersion",
"org.mockito:mockito-junit-jupiter:$mockitoVersion",
"org.apache.tika:tika-core:${tikaVersion}",
"org.apache.tika:tika-parsers:${tikaVersion}",
)

testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")

annotationProcessor(
"javax.annotation:javax.annotation-api:$javaxAnnotations",
"org.projectlombok:lombok:$lombokVersion"
)

testAnnotationProcessor(
"org.projectlombok:lombok:$lombokVersion",
)

compileOnly(
"org.projectlombok:lombok:$lombokVersion",
"org.springframework.boot:spring-boot-configuration-processor"
)

developmentOnly("org.springframework.boot:spring-boot-devtools")

runtimeOnly 'org.springframework.boot:spring-boot-starter-tomcat'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}
19 changes: 19 additions & 0 deletions gradle/kotlin.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
kotlin {
// see https://docs.gradle.org/current/userguide/toolchains.html
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}

compileKotlin {
compilerOptions {
freeCompilerArgs = ["-Xjsr305=strict"]
}
}

compileTestKotlin {
compilerOptions {
freeCompilerArgs = ["-Xjsr305=strict"]
}
}

12 changes: 0 additions & 12 deletions src/main/java/de/kontextwork/converter/ConverterApplication.java

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 865a550

Please sign in to comment.