diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 4a0c0fe..aea0bdf 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -10,7 +10,6 @@ jobs: actions: read contents: read strategy: - #max-parallel: 3 fail-fast: false matrix: java: [ '17', '21' ] @@ -19,38 +18,12 @@ jobs: steps: - uses: actions/checkout@v3 with: - fetch-depth: '0' - - name: "Setup Git" - shell: bash - run: | - git branch -a - for branch in $( - git branch -a \ - | grep '^\s*remotes' \ - | egrep --invert-match '(:?HEAD|remotes/pull/[0-9]+/merge)$' \ - | sed -e "s/^.*remotes\/origin\///" - ); do - echo setting up $branch - git checkout $branch - git checkout - - done - git branch -a - git remote remove origin - git remote add origin git@github.com:${GITHUB_REPOSITORY}.git - git remote -v + fetch-depth: '1' - name: Setup java uses: actions/setup-java@v2 with: distribution: 'zulu' java-version: ${{ matrix.java }} - - name: prepare Gradle - shell: bash - run: | - mkdir -p ~/.gradle && echo "org.gradle.daemon=false" >> ~/.gradle/gradle.properties - - name: Check formatting - shell: bash - run: | - ./gradlew --no-daemon spotlessJavaCheck - name: "Gradle build" shell: bash run: | @@ -58,20 +31,6 @@ jobs: javac -version ./gradlew --no-daemon build - - name: Transorm static code analysis to SARIF - if: ${{ (success() || failure()) }} - run: | - npx violations-command-line -sarif sarif-report.json \ - -v "FINDBUGS" "." ".*build/reports/spotbugs/main\.xml$" "Spotbugs" \ - -v "CHECKSTYLE" "." ".*build/reports/checkstyle/main\.xml$" "Checkstyle" \ - -v "PMD" "." ".*build/reports/pmd/main\.xml$" "PMD" \ - -v "JUNIT" "." ".*/build/test-results/test/TEST-.*\.xml$" "JUNIT" - - uses: github/codeql-action/upload-sarif@v3 - if: ${{ (success() || failure()) }} - with: - sarif_file: sarif-report.json - category: violations-lib - - name: Publish Build uses: actions/upload-artifact@v4 if: failure() diff --git a/build.gradle b/build.gradle index 1a7c3a3..abaa5a8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,30 +1,85 @@ -apply plugin: 'java-library' - buildscript { repositories { + maven { url "https://oss.sonatype.org" } + maven { url "https://plugins.gradle.org/m2/" } mavenCentral() - mavenLocal() } dependencies { - classpath 'se.bjurr.gradle:gradle-scripts:2.+' + classpath "org.wiremock.tools.gradle:extension-convention-plugin:0.3.0" + classpath 'se.bjurr.gitchangelog:git-changelog-lib:1.175.2' + } +} + +plugins { + id 'idea' + id 'eclipse' + id 'project-report' + id 'com.diffplug.spotless' version '6.25.0' + id 'org.wiremock.tools.gradle.wiremock-extension-convention' version '0.3.0' +} + +def bumpVersionTo(version) { + def propertyFile = new File("$projectDir/gradle.properties") + def gradleProps = new Properties() + propertyFile.withReader { gradleProps.load(it) } + gradleProps.setProperty('version', version) + propertyFile.withWriter { gradleProps.store(it, null) } +} + +task setConventionalVersion() { + doFirst { + def nextVersion = se.bjurr.gitchangelog.api.GitChangelogApi.gitChangelogApiBuilder() + .withFromRepo(file('.')) + .withSemanticMajorVersionPattern("^[Bb]reak") + .withSemanticMinorVersionPattern("^[Ff]eat") + .getNextSemanticVersion() + .getVersion(); + def nextSnapshot = "${nextVersion}-SNAPSHOT" + logger.lifecycle("Setting version ${nextSnapshot}...") + bumpVersionTo(nextSnapshot) } } allprojects { + repositories { + mavenLocal() + mavenCentral() + } + apply plugin: 'java-library' + sourceCompatibility = 17 + targetCompatibility = 17 - project.ext.buildConfig = [ - repoType: "DEFAULT", - sourceCompatibility: 17, - targetCompatibility: 17, - staticCodeAnalysis: [ - maxViolations: 0 - ] - ] - apply from: project.buildscript.classLoader.getResource('main.gradle').toURI() + apply plugin: 'com.diffplug.spotless' + spotless { + java { + target 'src/**/*.java' + googleJavaFormat('1.17.0') + ratchetFrom 'origin/main' + trimTrailingWhitespace() + endWithNewline() + targetExclude '**/Tmp*.java' + } + groovyGradle { + target '**/*.gradle' + greclipse() + indentWithSpaces(2) + trimTrailingWhitespace() + endWithNewline() + } + json { + target 'src/**/*.json' + targetExclude '**/tmp*.json', 'src/test/resources/sample.json', 'src/main/resources/swagger/*.json', 'src/test/resources/filesource/subdir/deepfile.json', 'src/test/resources/schema-validation/*.json' + simple().indentWithSpaces(2) + } + } test { useJUnitPlatform() + testLogging { + events "PASSED", "FAILED", "SKIPPED" + exceptionFormat "full" + } } dependencies { @@ -42,7 +97,7 @@ project('wiremock-spring-boot', { api "org.springframework.boot:spring-boot-test:3.3.4" api "org.springframework:spring-test:6.1.13" api "org.slf4j:slf4j-api:2.0.16" - api "org.junit.jupiter:junit-jupiter-api:5.11.0" + api "org.junit.jupiter:junit-jupiter-api:5.11.0" } }) diff --git a/example/src/test/resources/custom-location/mappings/todos.json b/example/src/test/resources/custom-location/mappings/todos.json index f1d1f94..92ab4b1 100644 --- a/example/src/test/resources/custom-location/mappings/todos.json +++ b/example/src/test/resources/custom-location/mappings/todos.json @@ -4,13 +4,19 @@ "url": "/" }, "response": { - "status": 200, + "headers": {"Content-Type": "application/json"}, "jsonBody": [ - { "id": 1, "userId": 1, "title": "custom location todo 1" }, - { "id": 2, "userId": 1, "title": "custom location todo 2" } + { + "id": 1, + "title": "custom location todo 1", + "userId": 1 + }, + { + "id": 2, + "title": "custom location todo 2", + "userId": 1 + } ], - "headers": { - "Content-Type": "application/json" - } + "status": 200 } } diff --git a/example/src/test/resources/wiremock/user-client/mappings/get-users.json b/example/src/test/resources/wiremock/user-client/mappings/get-users.json index ed2d3ab..402f0e0 100644 --- a/example/src/test/resources/wiremock/user-client/mappings/get-users.json +++ b/example/src/test/resources/wiremock/user-client/mappings/get-users.json @@ -4,10 +4,11 @@ "url": "/1" }, "response": { - "status": 200, - "jsonBody": { "id": 1, "name": "Jenna" }, - "headers": { - "Content-Type": "application/json" - } + "headers": {"Content-Type": "application/json"}, + "jsonBody": { + "name": "Jenna", + "id": 1 + }, + "status": 200 } } diff --git a/example/src/test/wiremock-mappings/mappings/get.json b/example/src/test/wiremock-mappings/mappings/get.json index cc46bf3..41c4a46 100644 --- a/example/src/test/wiremock-mappings/mappings/get.json +++ b/example/src/test/wiremock-mappings/mappings/get.json @@ -4,7 +4,7 @@ "url": "/wiremockmappingsmock" }, "response": { - "status": 200, - "jsonBody": { "wiremockmappingsmock": "yes" } + "jsonBody": {"wiremockmappingsmock": "yes"}, + "status": 200 } } diff --git a/gradle.properties b/gradle.properties index c3309fc..dd99921 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,9 @@ -description="WireMock integration for Spring Boot." -version=1.0.0 +#Wed Sep 25 17:54:02 CEST 2024 +baseArtifact=wiremock-spring-boot +developer.id=tomasbjerre +githubRepo=wiremock-spring-boot +description=WireMock integration for Spring Boot. +developer.name=Tomas Bjerre +developer.email=tomas.bjerre85@gmail.com +version=3.0.0-SNAPSHOT group=org.wiremock.spring