diff --git a/.github/workflows/aot-test.yml b/.github/workflows/aot-test.yml index 5713bfe..1a870f9 100644 --- a/.github/workflows/aot-test.yml +++ b/.github/workflows/aot-test.yml @@ -31,45 +31,52 @@ jobs: run: sbt GraalVMNativeImage/packageBin - name: Test the binary + shell: bash run: | - set -eux + set -euo pipefail # See if it runs at all - target/graalvm-native-image/jelly-cli version + target/graalvm-native-image/jelly-cli version || exit 1 # Make sure reflection is supported - target/graalvm-native-image/jelly-cli version | grep "JVM reflection: supported" + target/graalvm-native-image/jelly-cli version | grep "JVM reflection: supported" \ + || exit 1 # Make sure large RDF/XML file parsing is supported - target/graalvm-native-image/jelly-cli version | grep "Large RDF/XML file parsing: supported" + target/graalvm-native-image/jelly-cli version | grep "Large RDF/XML file parsing: supported" \ + || exit 1 # Test RDF conversions echo '_:b _:b .' > in.nt target/graalvm-native-image/jelly-cli \ rdf to-jelly --in-format=nt in.nt > out.jelly && \ - [ -s out.jelly ] + [ -s out.jelly ] || exit 1 target/graalvm-native-image/jelly-cli \ rdf from-jelly --out-format=jelly-text out.jelly > out.txt && \ - [ -s out.txt ] + [ -s out.txt ] || exit 1 + # From jelly-text + target/graalvm-native-image/jelly-cli \ + rdf to-jelly --in-format=jelly-text out.txt > out2.jelly && \ + [ -s out2.jelly ] || exit 1 target/graalvm-native-image/jelly-cli \ rdf from-jelly --out-format=jsonld out.jelly > out.json && \ - [ -s out.json ] + [ -s out.json ] || exit 1 echo '{"@graph":[{"@id":"http://e.org/r","http://e.org/p":{"@value":"v"}}]}' | \ target/graalvm-native-image/jelly-cli rdf to-jelly --in-format "jsonld" > jsonld.jelly && \ - [ -s jsonld.jelly ] + [ -s jsonld.jelly ] || exit 1 echo '' | \ target/graalvm-native-image/jelly-cli rdf to-jelly --in-format "rdfxml" > rdfxml.jelly && \ - [ -s rdfxml.jelly ] + [ -s rdfxml.jelly ] || exit 1 # Invalid RDF/XMl input test # Regression test for: https://github.com/Jelly-RDF/cli/issues/217 echo 'invalidxml' | \ ( ! target/graalvm-native-image/jelly-cli rdf to-jelly --in-format "rdfxml" &> error.txt ) && \ - grep 'Content is not allowed in prolog' error.txt + grep 'Content is not allowed in prolog' error.txt || exit 1 # Test rdf validate target/graalvm-native-image/jelly-cli \ - rdf validate out.jelly --compare-to-rdf-file in.nt + rdf validate out.jelly --compare-to-rdf-file in.nt || exit 1 - name: Upload binary uses: actions/upload-artifact@v4 diff --git a/src/main/java/eu/neverblink/jelly/cli/graal/GraalSubstitutes.java b/src/main/java/eu/neverblink/jelly/cli/graal/GraalSubstitutes.java index 130ef12..f4eaa7e 100644 --- a/src/main/java/eu/neverblink/jelly/cli/graal/GraalSubstitutes.java +++ b/src/main/java/eu/neverblink/jelly/cli/graal/GraalSubstitutes.java @@ -3,9 +3,9 @@ import com.apicatalog.jsonld.JsonLdError; import com.apicatalog.jsonld.http.HttpClient; import com.apicatalog.jsonld.http.HttpResponse; -import com.oracle.svm.core.annotate.Delete; -import com.oracle.svm.core.annotate.Substitute; -import com.oracle.svm.core.annotate.TargetClass; +import com.google.protobuf.Descriptors; +import com.google.protobuf.TextFormat; +import com.oracle.svm.core.annotate.*; import java.net.URI; import java.nio.charset.Charset; @@ -93,3 +93,22 @@ final class UnicodeDetectingInputStreamSubstitute { @Delete private static Charset UTF_32LE; } + +/** + * Alias for TextFormat.TextGenerator to be used in substitutions (TextGenerator is private). + */ +@TargetClass(className = "com.google.protobuf.TextFormat", innerClass = "TextGenerator") +final class TextFormatTextGeneratorAlias { +} + +/** + * Disable redaction support in protobuf TextFormat printer, which we don't need. + * This a lot of reflection-heavy code that we can do without. + */ +@TargetClass(className = "com.google.protobuf.TextFormat", innerClass = "Printer") +final class TextFormatPrinterSubstitute { + @Substitute + private boolean shouldRedact(final Descriptors.FieldDescriptor field, TextFormatTextGeneratorAlias generator) { + return false; + } +} diff --git a/src/main/scala/eu/neverblink/jelly/cli/graal/ProtobufFeature.scala b/src/main/scala/eu/neverblink/jelly/cli/graal/ProtobufFeature.scala index 29011d1..ab0ce91 100644 --- a/src/main/scala/eu/neverblink/jelly/cli/graal/ProtobufFeature.scala +++ b/src/main/scala/eu/neverblink/jelly/cli/graal/ProtobufFeature.scala @@ -14,11 +14,13 @@ class ProtobufFeature extends Feature: override def beforeAnalysis(access: BeforeAnalysisAccess): Unit = val reflections = Reflections("eu.neverblink.jelly.core.proto.google.v1", Scanners.SubTypes) - val classes = reflections.getSubTypesOf( + val classesForSubtyping: Seq[Class[?]] = Seq( classOf[com.google.protobuf.GeneratedMessage], - ).asScala ++ - reflections.getSubTypesOf(classOf[com.google.protobuf.GeneratedMessage.Builder[?]]).asScala ++ - reflections.getSubTypesOf(classOf[com.google.protobuf.ProtocolMessageEnum]).asScala + classOf[com.google.protobuf.GeneratedMessage.Builder[?]], + classOf[com.google.protobuf.ProtocolMessageEnum], + ) + val classes: Seq[Class[?]] = + classesForSubtyping.flatMap(reflections.getSubTypesOf(_).asScala.toSeq) classes.foreach(clazz => { RuntimeReflection.register(clazz) RuntimeReflection.register(clazz.getDeclaredMethods*)