charRangeSet =
79 | Formatter.lineRangesToCharRanges(unformattedContent, lineRanges.rangeSet());
80 | return formatter.formatSource(unformattedContent, charRangeSet.asRanges());
81 | }
82 |
83 | private String fixImports(final String unformattedContent) throws FormatterException {
84 | String formattedContent = unformattedContent;
85 | if (!options.isSkipRemovingUnusedImports()) {
86 | formattedContent = RemoveUnusedImports.removeUnusedImports(formattedContent);
87 | }
88 | if (!options.isSkipSortingImports()) {
89 | formattedContent = ImportOrderer.reorderImports(formattedContent);
90 | }
91 | return formattedContent;
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/google-java-format/src/main/java/com/cosium/code/format_gjf/GoogleJavaFormatterFactory.java:
--------------------------------------------------------------------------------
1 | package com.cosium.code.format_gjf;
2 |
3 | import com.cosium.code.format_spi.CodeFormatter;
4 | import com.cosium.code.format_spi.CodeFormatterConfiguration;
5 | import com.cosium.code.format_spi.CodeFormatterFactory;
6 |
7 | /**
8 | * @author Réda Housni Alaoui
9 | */
10 | public class GoogleJavaFormatterFactory implements CodeFormatterFactory {
11 | @Override
12 | public String configurationId() {
13 | return "googleJavaFormat";
14 | }
15 |
16 | @Override
17 | public CodeFormatter build(CodeFormatterConfiguration configuration, String sourceEncoding) {
18 |
19 | return new GoogleJavaFormatter(new GoogleJavaFormatterOptions(configuration), sourceEncoding);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/google-java-format/src/main/java/com/cosium/code/format_gjf/GoogleJavaFormatterOptions.java:
--------------------------------------------------------------------------------
1 | package com.cosium.code.format_gjf;
2 |
3 | import static com.google.googlejavaformat.java.JavaFormatterOptions.Style.AOSP;
4 | import static com.google.googlejavaformat.java.JavaFormatterOptions.Style.GOOGLE;
5 |
6 | import com.cosium.code.format_spi.CodeFormatterConfiguration;
7 | import com.google.googlejavaformat.java.JavaFormatterOptions;
8 |
9 | /**
10 | * @author Réda Housni Alaoui
11 | */
12 | class GoogleJavaFormatterOptions {
13 |
14 | private final JavaFormatterOptions.Style style;
15 | private final boolean formatJavadoc;
16 | private final boolean fixImportsOnly;
17 | private final boolean skipSortingImports;
18 | private final boolean skipRemovingUnusedImports;
19 |
20 | public GoogleJavaFormatterOptions(CodeFormatterConfiguration configuration) {
21 | boolean aosp = configuration.getValue("aosp").map(Boolean::parseBoolean).orElse(false);
22 | if (aosp) {
23 | style = AOSP;
24 | } else {
25 | style = GOOGLE;
26 | }
27 | formatJavadoc = configuration.getValue("formatJavadoc").map(Boolean::parseBoolean).orElse(true);
28 | fixImportsOnly =
29 | configuration.getValue("fixImportsOnly").map(Boolean::parseBoolean).orElse(false);
30 | skipSortingImports =
31 | configuration.getValue("skipSortingImports").map(Boolean::parseBoolean).orElse(false);
32 | skipRemovingUnusedImports =
33 | configuration
34 | .getValue("skipRemovingUnusedImports")
35 | .map(Boolean::parseBoolean)
36 | .orElse(false);
37 | }
38 |
39 | public JavaFormatterOptions javaFormatterOptions() {
40 | return JavaFormatterOptions.builder().style(style).formatJavadoc(formatJavadoc).build();
41 | }
42 |
43 | public boolean isFixImportsOnly() {
44 | return fixImportsOnly;
45 | }
46 |
47 | public boolean isSkipSortingImports() {
48 | return skipSortingImports;
49 | }
50 |
51 | public boolean isSkipRemovingUnusedImports() {
52 | return skipRemovingUnusedImports;
53 | }
54 |
55 | @Override
56 | public String toString() {
57 | return "GoogleJavaFormatterOptions{"
58 | + "style="
59 | + style
60 | + ", fixImportsOnly="
61 | + fixImportsOnly
62 | + ", skipSortingImports="
63 | + skipSortingImports
64 | + ", skipRemovingUnusedImports="
65 | + skipRemovingUnusedImports
66 | + '}';
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/google-java-format/src/main/resources/META-INF/services/com.cosium.code.format_spi.CodeFormatterFactory:
--------------------------------------------------------------------------------
1 | com.cosium.code.format_gjf.GoogleJavaFormatterFactory
2 |
--------------------------------------------------------------------------------
/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Apache Maven Wrapper startup batch script, version 3.1.1
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | # e.g. to debug Maven itself, use
32 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | # ----------------------------------------------------------------------------
35 |
36 | if [ -z "$MAVEN_SKIP_RC" ] ; then
37 |
38 | if [ -f /usr/local/etc/mavenrc ] ; then
39 | . /usr/local/etc/mavenrc
40 | fi
41 |
42 | if [ -f /etc/mavenrc ] ; then
43 | . /etc/mavenrc
44 | fi
45 |
46 | if [ -f "$HOME/.mavenrc" ] ; then
47 | . "$HOME/.mavenrc"
48 | fi
49 |
50 | fi
51 |
52 | # OS specific support. $var _must_ be set to either true or false.
53 | cygwin=false;
54 | darwin=false;
55 | mingw=false
56 | case "`uname`" in
57 | CYGWIN*) cygwin=true ;;
58 | MINGW*) mingw=true;;
59 | Darwin*) darwin=true
60 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
61 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
62 | if [ -z "$JAVA_HOME" ]; then
63 | if [ -x "/usr/libexec/java_home" ]; then
64 | JAVA_HOME="`/usr/libexec/java_home`"; export JAVA_HOME
65 | else
66 | JAVA_HOME="/Library/Java/Home"; export JAVA_HOME
67 | fi
68 | fi
69 | ;;
70 | esac
71 |
72 | if [ -z "$JAVA_HOME" ] ; then
73 | if [ -r /etc/gentoo-release ] ; then
74 | JAVA_HOME=`java-config --jre-home`
75 | fi
76 | fi
77 |
78 | # For Cygwin, ensure paths are in UNIX format before anything is touched
79 | if $cygwin ; then
80 | [ -n "$JAVA_HOME" ] &&
81 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
82 | [ -n "$CLASSPATH" ] &&
83 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
84 | fi
85 |
86 | # For Mingw, ensure paths are in UNIX format before anything is touched
87 | if $mingw ; then
88 | [ -n "$JAVA_HOME" ] &&
89 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
90 | fi
91 |
92 | if [ -z "$JAVA_HOME" ]; then
93 | javaExecutable="`which javac`"
94 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
95 | # readlink(1) is not available as standard on Solaris 10.
96 | readLink=`which readlink`
97 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
98 | if $darwin ; then
99 | javaHome="`dirname \"$javaExecutable\"`"
100 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
101 | else
102 | javaExecutable="`readlink -f \"$javaExecutable\"`"
103 | fi
104 | javaHome="`dirname \"$javaExecutable\"`"
105 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
106 | JAVA_HOME="$javaHome"
107 | export JAVA_HOME
108 | fi
109 | fi
110 | fi
111 |
112 | if [ -z "$JAVACMD" ] ; then
113 | if [ -n "$JAVA_HOME" ] ; then
114 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
115 | # IBM's JDK on AIX uses strange locations for the executables
116 | JAVACMD="$JAVA_HOME/jre/sh/java"
117 | else
118 | JAVACMD="$JAVA_HOME/bin/java"
119 | fi
120 | else
121 | JAVACMD="`\\unset -f command; \\command -v java`"
122 | fi
123 | fi
124 |
125 | if [ ! -x "$JAVACMD" ] ; then
126 | echo "Error: JAVA_HOME is not defined correctly." >&2
127 | echo " We cannot execute $JAVACMD" >&2
128 | exit 1
129 | fi
130 |
131 | if [ -z "$JAVA_HOME" ] ; then
132 | echo "Warning: JAVA_HOME environment variable is not set."
133 | fi
134 |
135 | # traverses directory structure from process work directory to filesystem root
136 | # first directory with .mvn subdirectory is considered project base directory
137 | find_maven_basedir() {
138 | if [ -z "$1" ]
139 | then
140 | echo "Path not specified to find_maven_basedir"
141 | return 1
142 | fi
143 |
144 | basedir="$1"
145 | wdir="$1"
146 | while [ "$wdir" != '/' ] ; do
147 | if [ -d "$wdir"/.mvn ] ; then
148 | basedir=$wdir
149 | break
150 | fi
151 | # workaround for JBEAP-8937 (on Solaris 10/Sparc)
152 | if [ -d "${wdir}" ]; then
153 | wdir=`cd "$wdir/.."; pwd`
154 | fi
155 | # end of workaround
156 | done
157 | printf '%s' "$(cd "$basedir"; pwd)"
158 | }
159 |
160 | # concatenates all lines of a file
161 | concat_lines() {
162 | if [ -f "$1" ]; then
163 | echo "$(tr -s '\n' ' ' < "$1")"
164 | fi
165 | }
166 |
167 | BASE_DIR=$(find_maven_basedir "$(dirname $0)")
168 | if [ -z "$BASE_DIR" ]; then
169 | exit 1;
170 | fi
171 |
172 | MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR
173 | if [ "$MVNW_VERBOSE" = true ]; then
174 | echo $MAVEN_PROJECTBASEDIR
175 | fi
176 |
177 | ##########################################################################################
178 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
179 | # This allows using the maven wrapper in projects that prohibit checking in binary data.
180 | ##########################################################################################
181 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
182 | if [ "$MVNW_VERBOSE" = true ]; then
183 | echo "Found .mvn/wrapper/maven-wrapper.jar"
184 | fi
185 | else
186 | if [ "$MVNW_VERBOSE" = true ]; then
187 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
188 | fi
189 | if [ -n "$MVNW_REPOURL" ]; then
190 | wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar"
191 | else
192 | wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar"
193 | fi
194 | while IFS="=" read key value; do
195 | case "$key" in (wrapperUrl) wrapperUrl="$value"; break ;;
196 | esac
197 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
198 | if [ "$MVNW_VERBOSE" = true ]; then
199 | echo "Downloading from: $wrapperUrl"
200 | fi
201 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
202 | if $cygwin; then
203 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
204 | fi
205 |
206 | if command -v wget > /dev/null; then
207 | QUIET="--quiet"
208 | if [ "$MVNW_VERBOSE" = true ]; then
209 | echo "Found wget ... using wget"
210 | QUIET=""
211 | fi
212 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
213 | wget $QUIET "$wrapperUrl" -O "$wrapperJarPath"
214 | else
215 | wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath"
216 | fi
217 | [ $? -eq 0 ] || rm -f "$wrapperJarPath"
218 | elif command -v curl > /dev/null; then
219 | QUIET="--silent"
220 | if [ "$MVNW_VERBOSE" = true ]; then
221 | echo "Found curl ... using curl"
222 | QUIET=""
223 | fi
224 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
225 | curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L
226 | else
227 | curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L
228 | fi
229 | [ $? -eq 0 ] || rm -f "$wrapperJarPath"
230 | else
231 | if [ "$MVNW_VERBOSE" = true ]; then
232 | echo "Falling back to using Java to download"
233 | fi
234 | javaSource="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
235 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class"
236 | # For Cygwin, switch paths to Windows format before running javac
237 | if $cygwin; then
238 | javaSource=`cygpath --path --windows "$javaSource"`
239 | javaClass=`cygpath --path --windows "$javaClass"`
240 | fi
241 | if [ -e "$javaSource" ]; then
242 | if [ ! -e "$javaClass" ]; then
243 | if [ "$MVNW_VERBOSE" = true ]; then
244 | echo " - Compiling MavenWrapperDownloader.java ..."
245 | fi
246 | # Compiling the Java class
247 | ("$JAVA_HOME/bin/javac" "$javaSource")
248 | fi
249 | if [ -e "$javaClass" ]; then
250 | # Running the downloader
251 | if [ "$MVNW_VERBOSE" = true ]; then
252 | echo " - Running MavenWrapperDownloader.java ..."
253 | fi
254 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
255 | fi
256 | fi
257 | fi
258 | fi
259 | ##########################################################################################
260 | # End of extension
261 | ##########################################################################################
262 |
263 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
264 |
265 | # For Cygwin, switch paths to Windows format before running java
266 | if $cygwin; then
267 | [ -n "$JAVA_HOME" ] &&
268 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
269 | [ -n "$CLASSPATH" ] &&
270 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
271 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
272 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
273 | fi
274 |
275 | # Provide a "standardized" way to retrieve the CLI args that will
276 | # work with both Windows and non-Windows executions.
277 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
278 | export MAVEN_CMD_LINE_ARGS
279 |
280 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
281 |
282 | exec "$JAVACMD" \
283 | $MAVEN_OPTS \
284 | $MAVEN_DEBUG_OPTS \
285 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
286 | "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
287 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
288 |
--------------------------------------------------------------------------------
/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM http://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Apache Maven Wrapper startup batch script, version 3.1.1
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
28 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
29 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
30 | @REM e.g. to debug Maven itself, use
31 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
32 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
33 | @REM ----------------------------------------------------------------------------
34 |
35 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
36 | @echo off
37 | @REM set title of command window
38 | title %0
39 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
40 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
41 |
42 | @REM set %HOME% to equivalent of $HOME
43 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
44 |
45 | @REM Execute a user defined script before this one
46 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
47 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
48 | if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %*
49 | if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %*
50 | :skipRcPre
51 |
52 | @setlocal
53 |
54 | set ERROR_CODE=0
55 |
56 | @REM To isolate internal variables from possible post scripts, we use another setlocal
57 | @setlocal
58 |
59 | @REM ==== START VALIDATION ====
60 | if not "%JAVA_HOME%" == "" goto OkJHome
61 |
62 | echo.
63 | echo Error: JAVA_HOME not found in your environment. >&2
64 | echo Please set the JAVA_HOME variable in your environment to match the >&2
65 | echo location of your Java installation. >&2
66 | echo.
67 | goto error
68 |
69 | :OkJHome
70 | if exist "%JAVA_HOME%\bin\java.exe" goto init
71 |
72 | echo.
73 | echo Error: JAVA_HOME is set to an invalid directory. >&2
74 | echo JAVA_HOME = "%JAVA_HOME%" >&2
75 | echo Please set the JAVA_HOME variable in your environment to match the >&2
76 | echo location of your Java installation. >&2
77 | echo.
78 | goto error
79 |
80 | @REM ==== END VALIDATION ====
81 |
82 | :init
83 |
84 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
85 | @REM Fallback to current working directory if not found.
86 |
87 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
88 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
89 |
90 | set EXEC_DIR=%CD%
91 | set WDIR=%EXEC_DIR%
92 | :findBaseDir
93 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
94 | cd ..
95 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
96 | set WDIR=%CD%
97 | goto findBaseDir
98 |
99 | :baseDirFound
100 | set MAVEN_PROJECTBASEDIR=%WDIR%
101 | cd "%EXEC_DIR%"
102 | goto endDetectBaseDir
103 |
104 | :baseDirNotFound
105 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
106 | cd "%EXEC_DIR%"
107 |
108 | :endDetectBaseDir
109 |
110 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
111 |
112 | @setlocal EnableExtensions EnableDelayedExpansion
113 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
114 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
115 |
116 | :endReadAdditionalConfig
117 |
118 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
121 |
122 | set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar"
123 |
124 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
125 | IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B
126 | )
127 |
128 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
129 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data.
130 | if exist %WRAPPER_JAR% (
131 | if "%MVNW_VERBOSE%" == "true" (
132 | echo Found %WRAPPER_JAR%
133 | )
134 | ) else (
135 | if not "%MVNW_REPOURL%" == "" (
136 | SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar"
137 | )
138 | if "%MVNW_VERBOSE%" == "true" (
139 | echo Couldn't find %WRAPPER_JAR%, downloading it ...
140 | echo Downloading from: %WRAPPER_URL%
141 | )
142 |
143 | powershell -Command "&{"^
144 | "$webclient = new-object System.Net.WebClient;"^
145 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
146 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
147 | "}"^
148 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^
149 | "}"
150 | if "%MVNW_VERBOSE%" == "true" (
151 | echo Finished downloading %WRAPPER_JAR%
152 | )
153 | )
154 | @REM End of extension
155 |
156 | @REM Provide a "standardized" way to retrieve the CLI args that will
157 | @REM work with both Windows and non-Windows executions.
158 | set MAVEN_CMD_LINE_ARGS=%*
159 |
160 | %MAVEN_JAVA_EXE% ^
161 | %JVM_CONFIG_MAVEN_PROPS% ^
162 | %MAVEN_OPTS% ^
163 | %MAVEN_DEBUG_OPTS% ^
164 | -classpath %WRAPPER_JAR% ^
165 | "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
166 | %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
167 | if ERRORLEVEL 1 goto error
168 | goto end
169 |
170 | :error
171 | set ERROR_CODE=1
172 |
173 | :end
174 | @endlocal & set ERROR_CODE=%ERROR_CODE%
175 |
176 | if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost
177 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
178 | if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat"
179 | if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd"
180 | :skipRcPost
181 |
182 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
183 | if "%MAVEN_BATCH_PAUSE%"=="on" pause
184 |
185 | if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE%
186 |
187 | cmd /C exit /B %ERROR_CODE%
188 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 | com.cosium.code
5 | git-code-format-maven-plugin-parent
6 | 5.4-SNAPSHOT
7 | pom
8 |
9 | Git Code Format Maven Plugin Parent
10 | A maven plugin that automatically deploys code formatters
11 | as pre-commit git hook
12 |
13 | https://github.com/Cosium/git-code-format-maven-plugin
14 |
15 |
16 | UTF-8
17 | 1.8
18 | 2.19.0
19 | 3.17.0
20 | 1.5.0
21 | 5.13.1.202206130422-r
22 | 0.8.13
23 | 3.1.1
24 | 1.27.0
25 |
26 |
27 |
28 | spi
29 | core
30 | google-java-format
31 |
32 |
33 |
34 |
35 |
36 | com.google.guava
37 | guava
38 | 33.4.8-jre
39 |
40 |
41 | commons-io
42 | commons-io
43 | ${org.apache.commons.io.version}
44 |
45 |
46 | org.apache.commons
47 | commons-lang3
48 | ${org.apache.commons.lang.version}
49 |
50 |
51 | org.apache.commons
52 | commons-exec
53 | ${org.apache.commons.exec.version}
54 |
55 |
56 | com.google.googlejavaformat
57 | google-java-format
58 | ${google-java-format.version}
59 |
60 |
61 | org.eclipse.jgit
62 | org.eclipse.jgit
63 | ${jgit.version}
64 |
65 |
66 | org.apache.maven
67 | maven-core
68 | 3.3.9
69 |
70 |
71 | org.apache.maven
72 | maven-plugin-api
73 | 3.3.9
74 |
75 |
76 | org.apache.maven.plugin-tools
77 | maven-plugin-annotations
78 | 3.15.1
79 |
80 |
81 | org.codehaus.plexus
82 | plexus-utils
83 | 3.2.1
84 |
85 |
86 | org.eclipse.sisu
87 | org.eclipse.sisu.plexus
88 | 0.3.5
89 |
90 |
91 | junit
92 | junit
93 | 4.13.2
94 |
95 |
96 | org.assertj
97 | assertj-core
98 | 3.27.3
99 |
100 |
101 | io.takari.maven.plugins
102 | takari-plugin-testing
103 | ${takari-plugin-testing.version}
104 |
105 |
106 | io.takari.maven.plugins
107 | takari-plugin-integration-testing
108 | ${takari-plugin-testing.version}
109 | pom
110 |
111 |
112 | ch.qos.logback
113 | logback-classic
114 | 1.5.18
115 |
116 |
117 | commons-codec
118 | commons-codec
119 | 1.18.0
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 | org.apache.maven.plugins
128 | maven-compiler-plugin
129 | 3.14.0
130 |
131 | ${source.level}
132 | ${source.level}
133 |
134 |
135 |
136 | org.apache.maven.plugins
137 | maven-source-plugin
138 | 3.3.1
139 |
140 |
141 | attach-sources
142 |
143 | jar-no-fork
144 |
145 |
146 |
147 |
148 |
149 | org.apache.maven.plugins
150 | maven-javadoc-plugin
151 | 3.11.2
152 |
153 |
154 | attach-javadocs
155 |
156 | jar
157 |
158 |
159 |
160 |
161 | false
162 | -Xdoclint:none
163 |
164 |
165 |
166 | org.apache.maven.plugins
167 | maven-deploy-plugin
168 | 3.1.4
169 |
170 |
171 | org.apache.maven.plugins
172 | maven-release-plugin
173 | 2.5.3
174 |
175 | false
176 | true
177 | true
178 | true
179 | release
180 | deploy
181 | @{project.version}
182 |
183 |
184 |
185 | org.jacoco
186 | jacoco-maven-plugin
187 | ${jacoco.version}
188 |
189 |
190 |
191 | prepare-agent
192 |
193 |
194 |
195 | report
196 | test
197 |
198 | report
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 | release-sign-artifacts
208 |
209 |
210 | performRelease
211 | true
212 |
213 |
214 |
215 |
216 |
217 | org.apache.maven.plugins
218 | maven-gpg-plugin
219 | 1.6
220 |
221 |
222 | sign-artifacts
223 | verify
224 |
225 | sign
226 |
227 |
228 |
229 |
230 |
231 | org.sonatype.plugins
232 | nexus-staging-maven-plugin
233 | 1.7.0
234 | true
235 |
236 | ossrh
237 | https://oss.sonatype.org/
238 | true
239 | true
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 | ossrh
250 | https://oss.sonatype.org/content/repositories/snapshots
251 |
252 |
253 | ossrh
254 | https://oss.sonatype.org/service/local/staging/deploy/maven2/
255 |
256 |
257 |
258 |
259 | scm:git:https://github.com/Cosium/git-code-format-maven-plugin
260 | scm:git:https://github.com/Cosium/git-code-format-maven-plugin
261 | https://github.com/Cosium/git-code-format-maven-plugin
262 | HEAD
263 |
264 |
265 |
266 | Cosium
267 | http://www.cosium.com
268 |
269 |
270 |
271 |
272 | reda-alaoui
273 | Réda Housni Alaoui
274 | reda-alaoui@hey.com
275 | https://github.com/reda-alaoui
276 |
277 |
278 |
279 |
280 |
281 | MIT License
282 | http://www.opensource.org/licenses/mit-license.php
283 | repo
284 |
285 |
286 |
287 |
--------------------------------------------------------------------------------
/release.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | ./mvnw --batch-mode clean release:prepare release:perform && git push && git push --tags
3 |
--------------------------------------------------------------------------------
/spi/.gitignore:
--------------------------------------------------------------------------------
1 | target
2 |
--------------------------------------------------------------------------------
/spi/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | com.cosium.code
6 | git-code-format-maven-plugin-parent
7 | 5.4-SNAPSHOT
8 |
9 |
10 | git-code-format-maven-plugin-spi
11 | jar
12 |
13 | Git Code Format Maven Plugin SPI
14 |
15 |
16 |
17 | com.google.guava
18 | guava
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/spi/src/main/java/com/cosium/code/format_spi/CodeFormatter.java:
--------------------------------------------------------------------------------
1 | package com.cosium.code.format_spi;
2 |
3 | import java.io.InputStream;
4 | import java.io.OutputStream;
5 |
6 | /**
7 | * @author Réda Housni Alaoui
8 | */
9 | public interface CodeFormatter {
10 |
11 | /**
12 | * @return The file extension supported by this formatter.
13 | */
14 | FileExtension fileExtension();
15 |
16 | /**
17 | * Formats a content.
18 | *
19 | * The formatter SHOULD strive to format only lines part of the provided line ranges.
20 | *
21 | * @param content The content to format.
22 | * @param lineRanges The line ranges to format.
23 | * @param formattedContent The {@link OutputStream} to write the formatted content to.
24 | */
25 | void format(InputStream content, LineRanges lineRanges, OutputStream formattedContent);
26 |
27 | /**
28 | * @return true if the provided content is correctly formatted. false otherwise.
29 | */
30 | boolean validate(InputStream content);
31 | }
32 |
--------------------------------------------------------------------------------
/spi/src/main/java/com/cosium/code/format_spi/CodeFormatterConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.cosium.code.format_spi;
2 |
3 | import java.util.Optional;
4 |
5 | /**
6 | * @author Réda Housni Alaoui
7 | */
8 | public interface CodeFormatterConfiguration {
9 |
10 | Optional getValue(String key);
11 | }
12 |
--------------------------------------------------------------------------------
/spi/src/main/java/com/cosium/code/format_spi/CodeFormatterFactory.java:
--------------------------------------------------------------------------------
1 | package com.cosium.code.format_spi;
2 |
3 | /**
4 | * @author Réda Housni Alaoui
5 | */
6 | public interface CodeFormatterFactory {
7 |
8 | /**
9 | * The prefix that will be used by the plugin user to configure formatters created by this
10 | * factory.
11 | *
12 | * e.g. If the prefix was 'fooBar', a configuration attribute named 'baz' would have to be
13 | * declared as 'fooBar.baz' in the plugin configuration.
14 | */
15 | String configurationId();
16 |
17 | /**
18 | * @param configuration This code formatter factory configuration
19 | * @param sourceEncoding The files source encoding
20 | * @return The formatter to use
21 | */
22 | CodeFormatter build(CodeFormatterConfiguration configuration, String sourceEncoding);
23 | }
24 |
--------------------------------------------------------------------------------
/spi/src/main/java/com/cosium/code/format_spi/FileExtension.java:
--------------------------------------------------------------------------------
1 | package com.cosium.code.format_spi;
2 |
3 | import com.google.common.io.Files;
4 | import java.nio.file.Path;
5 | import java.util.Objects;
6 |
7 | /**
8 | * @author Réda Housni Alaoui
9 | */
10 | public final class FileExtension {
11 |
12 | private final String value;
13 |
14 | private FileExtension(String value) {
15 | this.value = value;
16 | }
17 |
18 | public static FileExtension parse(Path path) {
19 | return new FileExtension(Files.getFileExtension(path.getFileName().toString()));
20 | }
21 |
22 | public static FileExtension parse(String path) {
23 | return new FileExtension(Files.getFileExtension(path));
24 | }
25 |
26 | public static FileExtension of(String value) {
27 | return new FileExtension(value);
28 | }
29 |
30 | @Override
31 | public String toString() {
32 | return value;
33 | }
34 |
35 | @Override
36 | public boolean equals(Object o) {
37 | if (this == o) {
38 | return true;
39 | }
40 | if (o == null || getClass() != o.getClass()) {
41 | return false;
42 | }
43 |
44 | FileExtension that = (FileExtension) o;
45 |
46 | return Objects.equals(value, that.value);
47 | }
48 |
49 | @Override
50 | public int hashCode() {
51 | return value != null ? value.hashCode() : 0;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/spi/src/main/java/com/cosium/code/format_spi/LineRanges.java:
--------------------------------------------------------------------------------
1 | package com.cosium.code.format_spi;
2 |
3 | import com.google.common.collect.Range;
4 | import com.google.common.collect.RangeSet;
5 | import com.google.common.collect.TreeRangeSet;
6 | import java.util.Collections;
7 | import java.util.Set;
8 |
9 | /**
10 | * @author Réda Housni Alaoui
11 | */
12 | public final class LineRanges {
13 |
14 | private static final LineRanges ALL =
15 | new LineRanges(TreeRangeSet.create(Collections.singleton(Range.all())));
16 |
17 | private final RangeSet rangeSet;
18 |
19 | private LineRanges(RangeSet rangeSet) {
20 | if (rangeSet.isEmpty()) {
21 | throw new IllegalArgumentException("There must be at least one range");
22 | }
23 |
24 | this.rangeSet = rangeSet;
25 | }
26 |
27 | public static LineRanges all() {
28 | return ALL;
29 | }
30 |
31 | public static LineRanges of(Set> ranges) {
32 | return new LineRanges(TreeRangeSet.create(ranges));
33 | }
34 |
35 | public static LineRanges singleton(Range range) {
36 | return new LineRanges(TreeRangeSet.create(Collections.singleton(range)));
37 | }
38 |
39 | public boolean isAll() {
40 | return this == ALL;
41 | }
42 |
43 | public RangeSet rangeSet() {
44 | return rangeSet;
45 | }
46 |
47 | public static LineRanges concat(LineRanges lineRanges1, LineRanges lineRanges2) {
48 | if (lineRanges1.isAll()) {
49 | return lineRanges1;
50 | }
51 | if (lineRanges2.isAll()) {
52 | return lineRanges2;
53 | }
54 |
55 | RangeSet newRangeSet = TreeRangeSet.create();
56 | newRangeSet.addAll(lineRanges1.rangeSet);
57 | newRangeSet.addAll(lineRanges2.rangeSet);
58 |
59 | return new LineRanges(newRangeSet);
60 | }
61 |
62 | @Override
63 | public String toString() {
64 | return rangeSet.toString();
65 | }
66 | }
67 |
--------------------------------------------------------------------------------