From bc00122db1dd747e43e3267f577e17541a3cb8f1 Mon Sep 17 00:00:00 2001 From: Luke Sikina Date: Mon, 10 Feb 2025 15:18:06 -0500 Subject: [PATCH] [CHORE] Code formatting --- README.md | 6 + code-formatting/eclipse-formatter.xml | 402 ++++++++++++++++++++++++++ code-formatting/pre-commit.sh | 28 ++ pic-sure-auth-services/pom.xml | 15 + pom.xml | 64 ++-- 5 files changed, 495 insertions(+), 20 deletions(-) create mode 100644 code-formatting/eclipse-formatter.xml create mode 100755 code-formatting/pre-commit.sh diff --git a/README.md b/README.md index efb69a59b..1e616eb60 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,12 @@ ### Local Development At present, local development is conducted using our [All-In-One](https://github.com/hms-dbmi/pic-sure-all-in-one) Virtual Box. We offer implementations for both [CentOS](https://github.com/hms-dbmi/pic-sure-all-in-one/tree/master) and [Redhat](https://github.com/hms-dbmi/pic-sure-all-in-one/tree/feature/redhat) based operating systems. To get started, please consult the [README](https://github.com/hms-dbmi/pic-sure-all-in-one/tree/master#readme) section of the [All-In-One](https://github.com/hms-dbmi/pic-sure-all-in-one) repository. +Before contributing code, please set up our git hook: +`cp code-formatting/pre-commit.sh .git/hooks/pre-commit` +To skip formatting on a block of code, wrap in `spotless:off`, `spotless:on` comments + + + #### To add an initial top admin user in the system If you follow the steps above, spins up the docker containers and you can see the login page in the browser, you are almost there. diff --git a/code-formatting/eclipse-formatter.xml b/code-formatting/eclipse-formatter.xml new file mode 100644 index 000000000..e7cfababf --- /dev/null +++ b/code-formatting/eclipse-formatter.xml @@ -0,0 +1,402 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/code-formatting/pre-commit.sh b/code-formatting/pre-commit.sh new file mode 100755 index 000000000..ed051d182 --- /dev/null +++ b/code-formatting/pre-commit.sh @@ -0,0 +1,28 @@ +#!/bin/sh -e +CWD=$(pwd) +cd $(git rev-parse --show-toplevel) +format_cmd="" + +# skip if NO_VERIFY env var set +if [ "$NO_VERIFY" ]; then + echo 'code formatting skipped' 1>&2 + exit 0 +fi + +# I'm not great at bash, so this is a bit ugly, but I'll explain each pipe +# 1. Get all staged files +# 2. Reduce to just .java files +# 3. Replace newlines with commas (this was really hard to do in sed) +# 4. Replace commas with $,^.* +# 5. Crop off the last 4 chars +# This results in foo.java$,^.*bar.java$,^.*baz.java$ +# I then append ^.* to the beginning of that. +STAGED_JAVA_FILES_AS_REGEX=$(git diff --staged --name-only --diff-filter=ACMR | grep '.java$' | tr '\n' ',' | sed -e 's/,/$,^.*/g' | sed 's/.\{4\}$//') +FILES_TO_RESTAGE=$(git diff --staged --name-only --diff-filter=ACMR) +if [ -n "$STAGED_JAVA_FILES_AS_REGEX" ]; then + echo "Found the following staged java files to format: $STAGED_JAVA_FILES_AS_REGEX" + mvn spotless:apply -DspotlessFiles=^.*$STAGED_JAVA_FILES_AS_REGEX + git add $FILES_TO_RESTAGE +fi + +cd $CWD \ No newline at end of file diff --git a/pic-sure-auth-services/pom.xml b/pic-sure-auth-services/pom.xml index 0bc59189c..6f836b100 100644 --- a/pic-sure-auth-services/pom.xml +++ b/pic-sure-auth-services/pom.xml @@ -28,6 +28,7 @@ 21 + 2.41.1 @@ -213,6 +214,20 @@ org.springframework.boot spring-boot-maven-plugin + + com.diffplug.spotless + spotless-maven-plugin + ${spotless.version} + + + + 4.26 + code-formatting/eclipse-formatter.xml + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index f0a497ade..6042774bb 100644 --- a/pom.xml +++ b/pom.xml @@ -1,22 +1,46 @@ - - 4.0.0 - edu.harvard.hms.dbmi.avillach.picsure.auth.microapp - pic-sure-auth-microapp - 2.0-SNAPSHOT - pom - pic-sure-auth-microapp - - pic-sure-auth-services - - - - github - GitHub HMS-DBMI Apache Maven Packages - https://maven.pkg.github.com/hms-dbmi/pic-sure - - true - - - + + 4.0.0 + edu.harvard.hms.dbmi.avillach.picsure.auth.microapp + pic-sure-auth-microapp + 2.0-SNAPSHOT + pom + pic-sure-auth-microapp + + 2.41.1 + + + pic-sure-auth-services + + + + github + GitHub HMS-DBMI Apache Maven Packages + https://maven.pkg.github.com/hms-dbmi/pic-sure + + true + + + + + + + + com.diffplug.spotless + spotless-maven-plugin + ${spotless.version} + + + + 4.26 + code-formatting/eclipse-formatter.xml + + + + + + + +