Skip to content

Commit

Permalink
chore: simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorsalgado committed Feb 20, 2024
1 parent 3f3d453 commit c13cb81
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 128 deletions.
2 changes: 2 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 0 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 0 additions & 42 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
18 changes: 14 additions & 4 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -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/.
Expand All @@ -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"'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
15 changes: 9 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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%

Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,73 +34,43 @@ public Object provide(final Args args) {
final Class<?> type = args.getTargetElementClass();
final Unmarshaller<?> unmarshaller;

final Optional<Use> optUse =
lookForAnnotation(Use.class, args.getTargetElement(),
args.getTestClass());
final Optional<Use> 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@ public class BinaryUnmarshaller implements Unmarshaller<byte[]> {
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Properties> {
Expand All @@ -12,8 +13,10 @@ public class PropertiesUnmarshaller implements Unmarshaller<Properties> {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}

0 comments on commit c13cb81

Please sign in to comment.