diff --git a/.githooks/post-commit b/.githooks/post-commit new file mode 100755 index 0000000..93d990d --- /dev/null +++ b/.githooks/post-commit @@ -0,0 +1,6 @@ +#!/bin/sh + +# update git's index (bc they get messy with the pre-commit hook) according to +# https://prettier.io/docs/en/precommit.html +# see also https://github.com/prettier/prettier/issues/2978 +git update-index -g diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 20c5091..cb526ff 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -3,11 +3,11 @@ registries: github: type: "maven-repository" url: "https://maven.pkg.github.com/pcalouche/*" - username: ${{ secrets.MAVEN_SERVER_USERNAME }} - password: ${{ secrets.MAVEN_SERVER_PASSWORD }} + username: ${{ github.actor }} + password: ${{ github.token }} updates: - package-ecosystem: "maven" - directory: "/" # Location of package manifests + directory: "/" registries: "*" schedule: interval: "daily" diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index df4892c..bb66f4e 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -2,29 +2,34 @@ name: Continuous Integration on: push: -env: - MAVEN_SERVER_USERNAME: ${{ secrets.MAVEN_SERVER_USERNAME }} - MAVEN_SERVER_PASSWORD: ${{ secrets.MAVEN_SERVER_PASSWORD }} + branches-ignore: + - main permissions: contents: read + packages: read + +concurrency: + group: "${{ github.workflow }}-${{ github.ref != 'refs/heads/main' && github.ref || github.run_id }}" + cancel-in-progress: true jobs: - maven-verify: + build-and-run-tests: + name: Build and Run Tests runs-on: ubuntu-latest steps: - - name: Checkout + - name: Checkout Repo uses: actions/checkout@v4 with: show-progress: false - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v4 with: - java-version: '17' + java-version: '21' distribution: 'temurin' cache: maven - server-id: github - server-username: MAVEN_SERVER_USERNAME - server-password: MAVEN_SERVER_PASSWORD - - name: Verify build - run: mvn -B verify \ No newline at end of file + - name: Run Maven + run: mvn -B clean verify + env: + GITHUB_ACTOR: ${{ github.actor }} + GITHUB_TOKEN: ${{ github.token }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index ec1d806..b706b2c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,32 +1,45 @@ +# Heavily influenced by https://www.toptal.com/developers/gitignore?templates=java,jetbrains,macos + +### Additional inclusions and exclusions specific to this project ### + +### Java ### +# Compiled class file +*.class + +# Log file +*.log + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* + +### Maven ### target/ -!.mvn/wrapper/maven-wrapper.jar -!**/src/main/**/target/ -!**/src/test/**/target/ - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea +# flatten-maven-plugin +.flattened-pom.xml + +### JetBrains ### +.idea/* +!.idea/codeStyles +!.idea/runConfigurations *.iws *.iml *.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ -!**/src/main/**/build/ -!**/src/test/**/build/ +out/ ### VS Code ### -.vscode/ \ No newline at end of file +.vscode/ + +### macOS ### +.DS_Store +.AppleDouble +.LSOverride diff --git a/.idea/runConfigurations/All_in_spring_boot_excel.xml b/.idea/runConfigurations/All_in_spring_boot_excel.xml new file mode 100644 index 0000000..de457bc --- /dev/null +++ b/.idea/runConfigurations/All_in_spring_boot_excel.xml @@ -0,0 +1,22 @@ + + + + + + + \ No newline at end of file diff --git a/.mvn/settings.xml b/.mvn/settings.xml new file mode 100644 index 0000000..7fe494b --- /dev/null +++ b/.mvn/settings.xml @@ -0,0 +1,11 @@ + + + + github + ${env.GITHUB_ACTOR} + ${env.GITHUB_TOKEN} + + + \ No newline at end of file diff --git a/.run/SpringBootExcelApplication (Default).run.xml b/.run/SpringBootExcelApplication (Default).run.xml new file mode 100644 index 0000000..50235d2 --- /dev/null +++ b/.run/SpringBootExcelApplication (Default).run.xml @@ -0,0 +1,21 @@ + + + + \ No newline at end of file diff --git a/Makefile b/Makefile index 321949e..20c6b9e 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,47 @@ -# format the code +# Format the code .PHONY: format format: mvn spotless:apply spring-javaformat:apply +# Run tests and verify .PHONY: mvn-verify mvn-verify: format mvn clean verify +# Skip tests and verify +.PHONY: mvn-verify-skip-tests +mvn-verify-skip-tests: format + mvn clean verify -DskipTests + +# Run tests and install locally .PHONY: mvn-install mvn-install: format - mvn clean install \ No newline at end of file + mvn clean install + +# Skip tests and install locally +.PHONY: mvn-install-skip-tests +mvn-install-skip-tests: format + mvn clean install -DskipTests + +# Check if version is a SNAPSHOT +.PHONY: check-if-snapshot-version +check-if-snapshot-version: + version="$(shell mvn help:evaluate -Dexpression=spring-enzymes.version -q -DforceStdout)" ; \ + echo "version is $$version" ; \ + if [[ $$version == *-SNAPSHOT ]]; then \ + echo "Release version is a SNAPSHOT, so manual deploy can proceed." ; \ + else \ + echo "Release version is NOT a SNAPSHOT. Use a SNAPSHOT version to deploy or deploy with GitHub Actions CD." ; \ + exit 1 ; \ + fi + +# Run tests and deploy SNAPSHOT version +.PHONY: mvn-deploy-snapshot +mvn-deploy-snapshot: check-if-snapshot-version format + mvn clean deploy + +# Skip tests and deploy SNAPSHOT version +.PHONY: mvn-deploy-snapshot-skip-tests +mvn-deploy-snapshot-skip-tests: check-if-snapshot-version format + mvn clean deploy -DskipTests + diff --git a/pom.xml b/pom.xml index 958ee2a..d418402 100644 --- a/pom.xml +++ b/pom.xml @@ -1,28 +1,27 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.pcalouche.poms - calouche-company-pom + dev.pcalouche.springforge.spring33x + spring-forge-starter-parent 1.0.0-SNAPSHOT - - com.pcalouche - excel-spring-boot - 0.0.1-SNAPSHOT + dev.pcalouche.springboot + spring-boot-excel + 1.0.0-SNAPSHOT Excel Export Spring Boot Example - org.apache.poi - poi-ooxml + dev.pcalouche.springforge.spring33x + pcalouche-spring-boot-starter-app - org.springframework.boot - spring-boot-starter-web + org.apache.poi + poi-ooxml org.springframework.boot @@ -36,8 +35,8 @@ runtime - org.springframework.boot - spring-boot-starter-test + dev.pcalouche.springforge.spring33x + pcalouche-spring-boot-starter-test test @@ -61,4 +60,4 @@ - \ No newline at end of file + diff --git a/src/main/java/com/pcalouche/excelspringboot/ExcelSpringBootApplication.java b/src/main/java/dev/pcalouche/springboot/excel/SpringBootExcelApplication.java similarity index 57% rename from src/main/java/com/pcalouche/excelspringboot/ExcelSpringBootApplication.java rename to src/main/java/dev/pcalouche/springboot/excel/SpringBootExcelApplication.java index 51a4b85..ee199a1 100644 --- a/src/main/java/com/pcalouche/excelspringboot/ExcelSpringBootApplication.java +++ b/src/main/java/dev/pcalouche/springboot/excel/SpringBootExcelApplication.java @@ -1,13 +1,13 @@ -package com.pcalouche.excelspringboot; +package dev.pcalouche.springboot.excel; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication -public class ExcelSpringBootApplication { +public class SpringBootExcelApplication { public static void main(String[] args) { - SpringApplication.run(ExcelSpringBootApplication.class, args); + SpringApplication.run(SpringBootExcelApplication.class, args); } } diff --git a/src/main/java/com/pcalouche/excelspringboot/controller/ExcelController.java b/src/main/java/dev/pcalouche/springboot/excel/controller/ExcelController.java similarity index 73% rename from src/main/java/com/pcalouche/excelspringboot/controller/ExcelController.java rename to src/main/java/dev/pcalouche/springboot/excel/controller/ExcelController.java index 7cf4c39..9b3e3df 100644 --- a/src/main/java/com/pcalouche/excelspringboot/controller/ExcelController.java +++ b/src/main/java/dev/pcalouche/springboot/excel/controller/ExcelController.java @@ -1,7 +1,7 @@ -package com.pcalouche.excelspringboot.controller; +package dev.pcalouche.springboot.excel.controller; -import com.pcalouche.excelspringboot.excel.NonStreamingExcelExport; -import com.pcalouche.excelspringboot.excel.StreamExcelExport; +import dev.pcalouche.springboot.excel.excel.NonStreamingExcelExport; +import dev.pcalouche.springboot.excel.excel.StreamExcelExport; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.ResponseEntity; @@ -18,7 +18,7 @@ public class ExcelController { @GetMapping("non-streaming-excel") public ResponseEntity nonStreamingExcel(@RequestParam int columns, @RequestParam int rows) { - logger.info("columns->" + columns + " rows->" + rows); + logger.info("columns->{} rows->{}", columns, rows); Long startTime = System.currentTimeMillis(); logger.info("start of Non Streaming Excel request"); @@ -26,14 +26,14 @@ public ResponseEntity nonStreamingExcel(@RequestParam int columns, @Requ NonStreamingExcelExport nonStreamingExcelExport = new NonStreamingExcelExport(columns, rows); Long endTime = System.currentTimeMillis(); - logger.info("end of Non Streaming Excel request->" + (endTime - startTime) / 1000 + " seconds."); + logger.info("end of Non Streaming Excel request->{} seconds.", (endTime - startTime) / 1000); return nonStreamingExcelExport.getResponseEntity(); } @GetMapping("streaming-excel") public ResponseEntity streamingExcel(@RequestParam int columns, @RequestParam int rows) { - logger.info("columns->" + columns + " rows->" + rows); + logger.info("columns->{} rows->{}", columns, rows); Long startTime = System.currentTimeMillis(); logger.info("start of Streaming Excel request"); @@ -41,7 +41,7 @@ public ResponseEntity streamingExcel(@RequestParam int columns, @Request StreamExcelExport streamExcelExport = new StreamExcelExport(columns, rows); Long endTime = System.currentTimeMillis(); - logger.info("end of Streaming Excel request->" + (endTime - startTime) / 1000 + " seconds."); + logger.info("end of Streaming Excel request->{} seconds.", (endTime - startTime) / 1000); return streamExcelExport.getResponseEntity(); } diff --git a/src/main/java/com/pcalouche/excelspringboot/excel/ExcelExport.java b/src/main/java/dev/pcalouche/springboot/excel/excel/ExcelExport.java similarity index 94% rename from src/main/java/com/pcalouche/excelspringboot/excel/ExcelExport.java rename to src/main/java/dev/pcalouche/springboot/excel/excel/ExcelExport.java index c0fe6aa..55a74bf 100755 --- a/src/main/java/com/pcalouche/excelspringboot/excel/ExcelExport.java +++ b/src/main/java/dev/pcalouche/springboot/excel/excel/ExcelExport.java @@ -1,6 +1,6 @@ -package com.pcalouche.excelspringboot.excel; +package dev.pcalouche.springboot.excel.excel; -import com.pcalouche.excelspringboot.util.DownloadableFile; +import dev.pcalouche.springboot.excel.util.DownloadableFile; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.file.Files; @@ -37,7 +37,7 @@ public abstract class ExcelExport implements DownloadableFile { // ExcelExport is created static { EXCEL_TEMP_FILE_PATH = Paths.get(System.getProperty("user.dir")).resolve("excelStaging"); - logger.info("Excel temp file staging path set to->" + EXCEL_TEMP_FILE_PATH.toAbsolutePath()); + logger.info("Excel temp file staging path set to->{}", EXCEL_TEMP_FILE_PATH.toAbsolutePath()); if (!Files.exists(EXCEL_TEMP_FILE_PATH)) { try { Files.createDirectories(EXCEL_TEMP_FILE_PATH); @@ -50,7 +50,7 @@ public abstract class ExcelExport implements DownloadableFile { // Deleting an old files at startup try (Stream streamPath = Files.list(EXCEL_TEMP_FILE_PATH)) { streamPath.forEach(path -> { - logger.info("Deleting old Excel temp file->" + path.toAbsolutePath()); + logger.info("Deleting old Excel temp file->{}", path.toAbsolutePath()); try { Files.deleteIfExists(path); } diff --git a/src/main/java/com/pcalouche/excelspringboot/excel/NonStreamingExcelExport.java b/src/main/java/dev/pcalouche/springboot/excel/excel/NonStreamingExcelExport.java similarity index 79% rename from src/main/java/com/pcalouche/excelspringboot/excel/NonStreamingExcelExport.java rename to src/main/java/dev/pcalouche/springboot/excel/excel/NonStreamingExcelExport.java index aca567e..aea8f28 100644 --- a/src/main/java/com/pcalouche/excelspringboot/excel/NonStreamingExcelExport.java +++ b/src/main/java/dev/pcalouche/springboot/excel/excel/NonStreamingExcelExport.java @@ -1,6 +1,6 @@ -package com.pcalouche.excelspringboot.excel; +package dev.pcalouche.springboot.excel.excel; -import com.pcalouche.excelspringboot.util.DownloadableFile; +import dev.pcalouche.springboot.excel.util.DownloadableFile; public class NonStreamingExcelExport extends ExcelExport implements DownloadableFile { diff --git a/src/main/java/com/pcalouche/excelspringboot/excel/StreamExcelExport.java b/src/main/java/dev/pcalouche/springboot/excel/excel/StreamExcelExport.java similarity index 88% rename from src/main/java/com/pcalouche/excelspringboot/excel/StreamExcelExport.java rename to src/main/java/dev/pcalouche/springboot/excel/excel/StreamExcelExport.java index 2f00a8c..84dd04d 100644 --- a/src/main/java/com/pcalouche/excelspringboot/excel/StreamExcelExport.java +++ b/src/main/java/dev/pcalouche/springboot/excel/excel/StreamExcelExport.java @@ -1,4 +1,4 @@ -package com.pcalouche.excelspringboot.excel; +package dev.pcalouche.springboot.excel.excel; public class StreamExcelExport extends ExcelExport { diff --git a/src/main/java/com/pcalouche/excelspringboot/util/DownloadableFile.java b/src/main/java/dev/pcalouche/springboot/excel/util/DownloadableFile.java similarity index 91% rename from src/main/java/com/pcalouche/excelspringboot/util/DownloadableFile.java rename to src/main/java/dev/pcalouche/springboot/excel/util/DownloadableFile.java index 33cdff0..647db24 100755 --- a/src/main/java/com/pcalouche/excelspringboot/util/DownloadableFile.java +++ b/src/main/java/dev/pcalouche/springboot/excel/util/DownloadableFile.java @@ -1,4 +1,4 @@ -package com.pcalouche.excelspringboot.util; +package dev.pcalouche.springboot.excel.util; import org.springframework.http.*; diff --git a/src/main/resources/application.properties b/src/main/resources/application.yml similarity index 100% rename from src/main/resources/application.properties rename to src/main/resources/application.yml diff --git a/src/test/java/com/pcalouche/excelspringboot/ExcelSpringBootApplicationTests.java b/src/test/java/dev/pcalouche/springboot/excel/SpringBootExcelApplicationTest.java similarity index 64% rename from src/test/java/com/pcalouche/excelspringboot/ExcelSpringBootApplicationTests.java rename to src/test/java/dev/pcalouche/springboot/excel/SpringBootExcelApplicationTest.java index 953802c..a4d72c9 100644 --- a/src/test/java/com/pcalouche/excelspringboot/ExcelSpringBootApplicationTests.java +++ b/src/test/java/dev/pcalouche/springboot/excel/SpringBootExcelApplicationTest.java @@ -1,10 +1,10 @@ -package com.pcalouche.excelspringboot; +package dev.pcalouche.springboot.excel; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest -public class ExcelSpringBootApplicationTests { +public class SpringBootExcelApplicationTest { @Test public void contextLoads() {