Skip to content

Commit

Permalink
FDP-2318: spotless
Browse files Browse the repository at this point in the history
Signed-off-by: Loes Immens <[email protected]>
  • Loading branch information
loesimmens committed Sep 16, 2024
1 parent 1ebb49d commit 59173dd
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// SPDX-FileCopyrightText: Contributors to the GXF project
//
// SPDX-License-Identifier: Apache-2.0

package org.gxf.crestdevicesimulator.simulator.response

import org.springframework.stereotype.Service

@Service
class CommandService {
fun hasRebootCommand(command: String) =
command.contains("CMD:REBOOT")
// todo remove
fun hasRebootCommand(command: String) = command.contains("CMD:REBOOT")
}
26 changes: 25 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//
// SPDX-License-Identifier: Apache-2.0

import com.diffplug.gradle.spotless.SpotlessExtension
import com.github.davidmc24.gradle.plugin.avro.GenerateAvroJavaTask
import io.spring.gradle.dependencymanagement.internal.dsl.StandardDependencyManagementExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
Expand All @@ -15,6 +16,7 @@ plugins {
kotlin("plugin.spring") version "2.0.0" apply false
kotlin("plugin.jpa") version "2.0.0" apply false
id("com.github.davidmc24.gradle.plugin.avro") version "1.9.1" apply false
id("com.diffplug.spotless") version "6.25.0"
id("org.sonarqube") version "5.0.0.4638"
id("eclipse")
}
Expand All @@ -34,6 +36,7 @@ subprojects {
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "org.jetbrains.kotlin.plugin.spring")
apply(plugin = "io.spring.dependency-management")
apply(plugin = "com.diffplug.spotless")
apply(plugin = "eclipse")
apply(plugin = "org.jetbrains.kotlin.plugin.jpa")
apply(plugin = "jacoco")
Expand All @@ -46,6 +49,17 @@ subprojects {
mavenCentral()
}

extensions.configure<SpotlessExtension> {
kotlin {
// by default the target is every '.kt' and '.kts' file in the java source sets
ktfmt().dropboxStyle()
licenseHeaderFile(
"${project.rootDir}/license-template.kt",
"package")
.updateYearWithLatest(false)
}
}

extensions.configure<StandardDependencyManagementExtension> {
imports { mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES) }
}
Expand All @@ -59,8 +73,18 @@ subprojects {
}
}

tasks.register<Copy>("updateGitHooks") {
description = "Copies the pre-commit Git Hook to the .git/hooks folder."
group = "verification"
from("${project.rootDir}/scripts/pre-commit")
into("${project.rootDir}/.git/hooks")
}

tasks.withType<KotlinCompile> {
dependsOn(tasks.withType<GenerateAvroJavaTask>())
dependsOn(
tasks.withType<GenerateAvroJavaTask>(),
tasks.named("updateGitHooks")
)
}

tasks.withType<Test> {
Expand Down
3 changes: 3 additions & 0 deletions license-template.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// SPDX-FileCopyrightText: Contributors to the GXF project
//
// SPDX-License-Identifier: Apache-2.0
33 changes: 33 additions & 0 deletions scripts/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
echo "*********************************************************"
echo "Running git pre-commit hook. Running Spotless Apply... "
echo "*********************************************************"

# Gather the staged files - to make sure changes are saved only for these files.
stagedFiles=$(git diff --staged --name-only)

# run spotless apply
./gradlew spotlessApply

status=$?

if [ "$status" = 0 ] ; then
echo "Static analysis found no problems."
# Add staged file changes to git
for file in $stagedFiles; do
if test -f "$file"; then
git add $file
fi
done
#Exit
exit 0
else
echo "*********************************************************"
echo " ******************************************** "
echo 1>&2 "Spotless Apply found violations it could not fix."
echo "Run spotless apply in your terminal and fix the issues before trying to commit again."
echo " ******************************************** "
echo "*********************************************************"
#Exit
exit 1
fi

0 comments on commit 59173dd

Please sign in to comment.