Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*.{kt,kts,gradle}]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 4
insert_final_newline = true
max_line_length = off
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
9 changes: 6 additions & 3 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4

- name: Check formatting
run: ./gradlew spotlessCheck --no-daemon

- name: Run backend tests with coverage
run: ./gradlew test jacocoTestReport --no-daemon

Expand Down Expand Up @@ -63,9 +66,9 @@ jobs:

- name: Upload backend coverage report
if: always()
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v3
with:
name: backend-jacoco-report
path: backend/build/reports/jacoco/test
path: build/reports/jacoco/test
if-no-files-found: ignore
retention-days: 14
retention-days: 14
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,12 @@ cp .env.dev.example .env.dev
- Docker or prod: container environment variables or a secret manager mounted as env

The same property keys are used in every environment, so you do not need to change Kotlin code when moving from local development to CI or production.

## Formatting

The project now enforces one shared code style for Kotlin and Gradle files through Gradle and CI.

- Check formatting: `./gradlew spotlessCheck`
- Apply the project format: `./gradlew spotlessApply`

`./gradlew check` also runs the formatting check, and GitHub Actions will fail if pushed code does not match the checked-in style.
21 changes: 20 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile

plugins {
id 'jacoco'
id 'com.diffplug.spotless' version '6.25.0'
id 'org.jetbrains.kotlin.jvm' version '2.2.21'
id 'org.jetbrains.kotlin.plugin.spring' version '2.2.21'
id 'org.springframework.boot' version '4.0.5'
Expand Down Expand Up @@ -69,6 +70,24 @@ allOpen {
annotation 'jakarta.persistence.Embeddable'
}

spotless {
kotlin {
target 'src/**/*.kt'
ktlint('1.5.0')
trimTrailingWhitespace()
endWithNewline()
}
groovyGradle {
target '*.gradle', 'gradle/**/*.gradle'
trimTrailingWhitespace()
endWithNewline()
}
}

tasks.named('check') {
dependsOn tasks.named('spotlessCheck')
}

tasks.named('test') {
useJUnitPlatform()
environment 'SPRING_DATASOURCE_URL', 'jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;MODE=MySQL'
Expand All @@ -85,4 +104,4 @@ tasks.named('jacocoTestReport') {
xml.required = true
html.required = true
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package edu.ntnu.idi.idatt.backend

import org.springframework.boot.context.properties.ConfigurationPropertiesScan
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.context.properties.ConfigurationPropertiesScan
import org.springframework.boot.runApplication

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ import java.nio.file.Paths
*/
@Configuration
class WebMvcConfig(
@Value("\${app.uploads.base-dir:\${user.home}/nettdetektivene/uploads}") private val baseDirPath: String,
@Value($$"${app.uploads.base-dir:${user.home}/nettdetektivene/uploads}") private val baseDirPath: String,
) : WebMvcConfigurer {
override fun addResourceHandlers(registry: ResourceHandlerRegistry) {
val uploadPath =
Paths
.get(baseDirPath)
.toAbsolutePath()
.toUri()
.toString()

override fun addResourceHandlers(registry: ResourceHandlerRegistry) {
val uploadPath = Paths.get(baseDirPath).toAbsolutePath().toUri().toString()

registry
.addResourceHandler("/uploads/**")
.addResourceLocations(uploadPath)
registry
.addResourceHandler("/uploads/**")
.addResourceLocations(uploadPath)
}
}
}
Loading