diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 1ef0730..947c5f3 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -4,7 +4,9 @@ updates: directory: "/" schedule: interval: "daily" + open-pull-requests-limit: 3 - package-ecosystem: "github-actions" directory: "/" schedule: interval: "daily" + open-pull-requests-limit: 2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6f0fd48..6a737a1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,18 +64,6 @@ jobs: run: | bash <(curl -s https://codecov.io/bash) - automerge: - needs: - - test - runs-on: ubuntu-latest - permissions: - pull-requests: write - contents: write - steps: - - uses: fastify/github-action-merge-dependabot@v3.6.0 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - release: needs: - test diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index 60de7a3..0000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: "CodeQL" - -on: - schedule: - - cron: '0 15 * * 0' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: [ 'java' ] - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - - - name: JDK 11 - uses: actions/setup-java@v3 - with: - java-version: '11' - distribution: 'adopt' - cache: gradle - - - name: Build - run: | - gradle build - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..afba109 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 669386b..5c00f61 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.4-all.zip +networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c787..65dcd68 100755 --- a/gradlew +++ b/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,10 +80,10 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' @@ -143,12 +143,16 @@ fi if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -205,6 +209,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index ac1b06f..6689b85 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/puma4j-core/src/main/java/io/github/vitorsalgado/puma4j/core/DefaultResourceProvider.java b/puma4j-core/src/main/java/io/github/vitorsalgado/puma4j/core/DefaultResourceProvider.java index d9b0a72..6cf341b 100644 --- a/puma4j-core/src/main/java/io/github/vitorsalgado/puma4j/core/DefaultResourceProvider.java +++ b/puma4j-core/src/main/java/io/github/vitorsalgado/puma4j/core/DefaultResourceProvider.java @@ -18,15 +18,11 @@ class DefaultResourceProvider implements Provider { public Object provide(final Args args) { requireNonNull(args); - final String resourceName = args - .getResourceFilename() - .orElse(""); + final String resourceName = args.getResourceFilename().orElse(""); final String filename; if (resourceName.isEmpty()) { - final Res res = args - .getTargetElement() - .getAnnotation(Res.class); + final Res res = args.getTargetElement().getAnnotation(Res.class); filename = res.value(); } else { filename = resourceName; @@ -38,73 +34,43 @@ public Object provide(final Args args) { final Class type = args.getTargetElementClass(); final Unmarshaller unmarshaller; - final Optional optUse = - lookForAnnotation(Use.class, args.getTargetElement(), - args.getTestClass()); + final Optional optUse = lookForAnnotation(Use.class, args.getTargetElement(), args.getTestClass()); if (optUse.isPresent()) { final Use use = optUse.get(); try { - unmarshaller = use - .value() - .getDeclaredConstructor() - .newInstance(); + unmarshaller = use.value().getDeclaredConstructor().newInstance(); } catch (final Exception ex) { - throw new InvalidMarshallerClassException(use - .value() - .getSimpleName(), ex); + throw new InvalidMarshallerClassException(use.value().getSimpleName(), ex); } } else { if (type.isAssignableFrom(String.class)) { - unmarshaller = Puma4j - .instance() - .textMarshaller(); + unmarshaller = Puma4j.instance().textMarshaller(); } else if (type.isAssignableFrom(byte[].class) || type.isAssignableFrom(Byte[].class)) { - unmarshaller = Puma4j - .instance() - .binaryMarshaller(); + unmarshaller = Puma4j.instance().binaryMarshaller(); } else if (type.isAssignableFrom(Properties.class)) { - unmarshaller = Puma4j - .instance() - .propertiesMarshaller(); + unmarshaller = Puma4j.instance().propertiesMarshaller(); } else { if (hasExtension) { - unmarshaller = - Puma4j - .instance() - .getMarshallerByExtension(extension) - .orElseThrow(() -> newExtNotSupportedException(args, filename, extension)); + unmarshaller = Puma4j.instance() + .getMarshallerByExtension(extension) + .orElseThrow(() -> newExtNotSupportedException(args, filename, extension)); } else { throw new NoMarshallerException( - buildErrorMessage( - "Unable to find a properly marshaller for specified resource.", - args, filename)); + buildErrorMessage("Unable to find a properly marshaller for specified resource.", args, filename)); } } } - final String path = Paths - .get(args - .getContext() - .getBasePath(), filename) - .toString(); + final String path = Paths.get(args.getContext().getBasePath(), filename).toString(); - try (final InputStream input = args - .getTestClass() - .getResourceAsStream(path)) { + try (final InputStream input = args.getTestClass().getResourceAsStream(path)) { return unmarshaller.unmarshal( - new Unmarshaller.Args( - input, - args.getTargetElementType(), - args.getTestClass(), - args.getTargetElement())); + new Unmarshaller.Args(input, args.getTargetElementType(), args.getTestClass(), args.getTargetElement())); } catch (final Exception ex) { throw new UnmarshallingException( - buildErrorMessage( - "Error unmarshalling resource to specified type.", - args, - filename), ex); + buildErrorMessage("Error unmarshalling resource to specified type.", args, filename), ex); } } } diff --git a/puma4j-core/src/main/java/io/github/vitorsalgado/puma4j/core/unmarshallers/BinaryUnmarshaller.java b/puma4j-core/src/main/java/io/github/vitorsalgado/puma4j/core/unmarshallers/BinaryUnmarshaller.java index cbe5202..10346b4 100644 --- a/puma4j-core/src/main/java/io/github/vitorsalgado/puma4j/core/unmarshallers/BinaryUnmarshaller.java +++ b/puma4j-core/src/main/java/io/github/vitorsalgado/puma4j/core/unmarshallers/BinaryUnmarshaller.java @@ -12,15 +12,12 @@ public class BinaryUnmarshaller implements Unmarshaller { public byte[] unmarshal(final Args args) throws IOException { requireNonNull(args); - final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - int reading; - final byte[] data = new byte[args - .getInput() - .available()]; + final int size = args.getInput().available(); + final ByteArrayOutputStream buffer = new ByteArrayOutputStream(size); + final byte[] data = new byte[size]; - while ((reading = args - .getInput() - .read(data, 0, data.length)) != -1) { + int reading; + while ((reading = args.getInput().read(data, 0, data.length)) != -1) { buffer.write(data, 0, reading); } diff --git a/puma4j-core/src/main/java/io/github/vitorsalgado/puma4j/core/unmarshallers/PropertiesUnmarshaller.java b/puma4j-core/src/main/java/io/github/vitorsalgado/puma4j/core/unmarshallers/PropertiesUnmarshaller.java index 8cd36a9..b2db996 100644 --- a/puma4j-core/src/main/java/io/github/vitorsalgado/puma4j/core/unmarshallers/PropertiesUnmarshaller.java +++ b/puma4j-core/src/main/java/io/github/vitorsalgado/puma4j/core/unmarshallers/PropertiesUnmarshaller.java @@ -4,6 +4,7 @@ import io.github.vitorsalgado.puma4j.core.Unmarshaller; import java.io.IOException; +import java.io.InputStream; import java.util.Properties; public class PropertiesUnmarshaller implements Unmarshaller { @@ -12,8 +13,10 @@ public class PropertiesUnmarshaller implements Unmarshaller { public Properties unmarshal(final Args args) throws IOException { requireNonNull(args); - final Properties properties = new Properties(); - properties.load(args.getInput()); + final InputStream in = args.getInput(); + final Properties properties = new Properties(in.available()); + + properties.load(in); return properties; } diff --git a/puma4j-core/src/main/java/io/github/vitorsalgado/puma4j/core/unmarshallers/YamlUnmarshaller.java b/puma4j-core/src/main/java/io/github/vitorsalgado/puma4j/core/unmarshallers/YamlUnmarshaller.java index 37e40f8..a672d1a 100644 --- a/puma4j-core/src/main/java/io/github/vitorsalgado/puma4j/core/unmarshallers/YamlUnmarshaller.java +++ b/puma4j-core/src/main/java/io/github/vitorsalgado/puma4j/core/unmarshallers/YamlUnmarshaller.java @@ -19,8 +19,6 @@ public Object unmarshal(final Args args) throws IOException { requireNonNull(args); return objectMapper.readValue( - args.getInput(), objectMapper - .getTypeFactory() - .constructType(args.getType())); + args.getInput(), objectMapper.getTypeFactory().constructType(args.getType())); } }