Skip to content

Commit

Permalink
filter non class files
Browse files Browse the repository at this point in the history
  • Loading branch information
kryptonbutterfly committed Dec 14, 2023
1 parent 776ad6c commit 67df77d
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 30 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
@@ -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 }}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<groupId>de.tinycodecrank</groupId>
<artifactId>cache_builder</artifactId>
<version>1.0.0</version>
<name>CacheBuilder</name>
<description>A java bytecode manipulator to decorate annotated functions with a specified cache</description>

<distributionManagement>
Expand Down Expand Up @@ -131,5 +132,4 @@
</plugin>
</plugins>
</build>
<name>CacheBuilder</name>
</project>
72 changes: 43 additions & 29 deletions src/de/tinycodecrank/asm/cache/DecoratorCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 67df77d

Please sign in to comment.