From 67df77d9fe413759d3483cbf732c87c3c075ea6e Mon Sep 17 00:00:00 2001 From: tinycodecrank Date: Thu, 14 Dec 2023 17:37:31 +0100 Subject: [PATCH] filter non class files --- .github/workflows/maven-publish.yml | 47 ++++++++++++ pom.xml | 2 +- .../asm/cache/DecoratorCache.java | 72 +++++++++++-------- 3 files changed, 91 insertions(+), 30 deletions(-) create mode 100644 .github/workflows/maven-publish.yml diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml new file mode 100644 index 0000000..dbbc67b --- /dev/null +++ b/.github/workflows/maven-publish.yml @@ -0,0 +1,47 @@ +# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created +# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path + +name: Maven Package + +on: + release: + types: [created] + workflow_dispatch: + inputs: + logLevel: + description: 'Log level' + required: true + default: 'warning' + type: choice + options: + - info + - warning + - debug + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 18 + uses: actions/setup-java@v3 + with: + java-version: '18' + distribution: 'temurin' + server-id: github # Value of the distributionManagement/repository/id field of the pom.xml + settings-path: ${{ github.workspace }} # location for the settings.xml file + + - name: Build with Maven + env: + GITHUB_TOKEN: ${{ secrets.MAVEN_REGISTRY_TOKEN }} + run: mvn -B package -s $GITHUB_WORKSPACE/settings.xml --file pom.xml + + - name: Publish to GitHub Packages Apache Maven + run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml + env: + GITHUB_TOKEN: ${{ secrets.MAVEN_REGISTRY_TOKEN }} diff --git a/pom.xml b/pom.xml index a946ada..8e9646f 100644 --- a/pom.xml +++ b/pom.xml @@ -3,6 +3,7 @@ de.tinycodecrank cache_builder 1.0.0 + CacheBuilder A java bytecode manipulator to decorate annotated functions with a specified cache @@ -131,5 +132,4 @@ - CacheBuilder \ No newline at end of file diff --git a/src/de/tinycodecrank/asm/cache/DecoratorCache.java b/src/de/tinycodecrank/asm/cache/DecoratorCache.java index a5bc6b9..df94af8 100644 --- a/src/de/tinycodecrank/asm/cache/DecoratorCache.java +++ b/src/de/tinycodecrank/asm/cache/DecoratorCache.java @@ -129,9 +129,23 @@ record CacheTarget(MethodNode method, AnnotationNode annotation) private static boolean adapt(Class annotation, File classFile) { + if (!classFile.getName().endsWith(".class")) + { + System.out.printf("Skipping: Not a .class file: %s\n", classFile); + return false; + } try (InputStream iStream = new FileInputStream(classFile)) { - ClassReader reader = new ClassReader(iStream); + final ClassReader reader; + try + { + reader = new ClassReader(iStream); + } + catch (IllegalArgumentException e) + { + System.err.printf("Unable to process %s\n%s", classFile, e.getMessage()); + return false; + } return adapt(annotation, reader).filter(classNode -> compile(classFile, classNode)).isPresent(); } catch (IOException e) @@ -402,20 +416,20 @@ private static MethodNode generateCached( .add(new MethodInsnNode(INVOKESTATIC, toInternal(c), "valueOf", fDesc(c, loc.desc))); switch (type.getSort()) { - case Type.BOOLEAN -> toObject.accept(Boolean.class); - case Type.CHAR -> toObject.accept(Character.class); - case Type.BYTE -> toObject.accept(Byte.class); - case Type.SHORT -> toObject.accept(Short.class); - case Type.INT -> toObject.accept(Integer.class); - case Type.FLOAT -> toObject.accept(Float.class); - case Type.LONG -> toObject.accept(Long.class); - case Type.DOUBLE -> toObject.accept(Double.class); - case Type.ARRAY, Type.OBJECT, Type.METHOD -> - {} /* nothing to do here */ - case Type.VOID -> - {} - default -> throw new IllegalStateException( - "Parameter of type: " + type.getSort() + " are not supported"); + case Type.BOOLEAN -> toObject.accept(Boolean.class); + case Type.CHAR -> toObject.accept(Character.class); + case Type.BYTE -> toObject.accept(Byte.class); + case Type.SHORT -> toObject.accept(Short.class); + case Type.INT -> toObject.accept(Integer.class); + case Type.FLOAT -> toObject.accept(Float.class); + case Type.LONG -> toObject.accept(Long.class); + case Type.DOUBLE -> toObject.accept(Double.class); + case Type.ARRAY, Type.OBJECT, Type.METHOD -> + {} /* nothing to do here */ + case Type.VOID -> + {} + default -> throw new IllegalStateException( + "Parameter of type: " + type.getSort() + " are not supported"); } cached.instructions.add(new InsnNode(AASTORE)); } @@ -450,20 +464,20 @@ private static MethodNode generateCached( }; switch (returnType.getSort()) { - case Type.BOOLEAN -> toPrimitive.accept(Boolean.class, "booleanValue"); - case Type.CHAR -> toPrimitive.accept(Character.class, "charValue"); - case Type.BYTE -> toPrimitive.accept(Byte.class, "byteValue"); - case Type.SHORT -> toPrimitive.accept(Short.class, "shortValue"); - case Type.INT -> toPrimitive.accept(Integer.class, "intValue"); - case Type.FLOAT -> toPrimitive.accept(Float.class, "floatValue"); - case Type.LONG -> toPrimitive.accept(Long.class, "longValue"); - case Type.DOUBLE -> toPrimitive.accept(Double.class, "doubleValue"); - case Type.ARRAY, Type.OBJECT, Type.METHOD -> cached.instructions - .add(new TypeInsnNode(CHECKCAST, returnType.getInternalName())); - case Type.VOID -> - {} - default -> throw new IllegalStateException("ReturnType: " + returnType.getSort() + " is not supported"); - + case Type.BOOLEAN -> toPrimitive.accept(Boolean.class, "booleanValue"); + case Type.CHAR -> toPrimitive.accept(Character.class, "charValue"); + case Type.BYTE -> toPrimitive.accept(Byte.class, "byteValue"); + case Type.SHORT -> toPrimitive.accept(Short.class, "shortValue"); + case Type.INT -> toPrimitive.accept(Integer.class, "intValue"); + case Type.FLOAT -> toPrimitive.accept(Float.class, "floatValue"); + case Type.LONG -> toPrimitive.accept(Long.class, "longValue"); + case Type.DOUBLE -> toPrimitive.accept(Double.class, "doubleValue"); + case Type.ARRAY, Type.OBJECT, Type.METHOD -> cached.instructions + .add(new TypeInsnNode(CHECKCAST, returnType.getInternalName())); + case Type.VOID -> + {} + default -> throw new IllegalStateException("ReturnType: " + returnType.getSort() + " is not supported"); + } cached.instructions.add(new InsnNode(returnType.getOpcode(IRETURN))); cached.instructions.add(end);