Move native hints into individual modules
* Use aot.factories approach for registration * Add tests * final tweaks- Thanks Josh!
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package org.springframework.ai.reader.pdf.aot;
|
||||
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* The PdfReaderRuntimeHints class is responsible for registering runtime hints for PDFBox
|
||||
* resources.
|
||||
*
|
||||
* @author Josh Long
|
||||
* @author Christian Tzolov
|
||||
* @author Mark Pollack
|
||||
*/
|
||||
public class PdfReaderRuntimeHints implements RuntimeHintsRegistrar {
|
||||
|
||||
@Override
|
||||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
||||
try {
|
||||
|
||||
var resolver = new PathMatchingResourcePatternResolver();
|
||||
|
||||
var patterns = Set.of("/org/apache/pdfbox/resources/glyphlist/zapfdingbats.txt",
|
||||
"/org/apache/pdfbox/resources/glyphlist/glyphlist.txt", "/org/apache/fontbox/cmap/**",
|
||||
"/org/apache/pdfbox/resources/afm/**", "/org/apache/pdfbox/resources/glyphlist/**",
|
||||
"/org/apache/pdfbox/resources/icc/**", "/org/apache/pdfbox/resources/text/**",
|
||||
"/org/apache/pdfbox/resources/ttf/**", "/org/apache/pdfbox/resources/version.properties");
|
||||
|
||||
for (var pattern : patterns)
|
||||
for (var resourceMatch : resolver.getResources(pattern))
|
||||
hints.resources().registerResource(resourceMatch);
|
||||
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
org.springframework.aot.hint.RuntimeHintsRegistrar=\
|
||||
org.springframework.ai.reader.pdf.aot.PdfReaderRuntimeHints
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.springframework.ai.reader.pdf.aot;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.TypeReference;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
import static org.springframework.ai.aot.AiRuntimeHints.findJsonAnnotatedClassesInPackage;
|
||||
import static org.springframework.aot.hint.predicate.RuntimeHintsPredicates.reflection;
|
||||
import static org.springframework.aot.hint.predicate.RuntimeHintsPredicates.resource;
|
||||
|
||||
class PdfReaderRuntimeHintsTests {
|
||||
|
||||
@Test
|
||||
void registerHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
PdfReaderRuntimeHints pdfReaderRuntimeHints = new PdfReaderRuntimeHints();
|
||||
pdfReaderRuntimeHints.registerHints(runtimeHints, null);
|
||||
|
||||
Assertions.assertThat(runtimeHints)
|
||||
.matches(resource().forResource("/org/apache/pdfbox/resources/glyphlist/zapfdingbats.txt"));
|
||||
Assertions.assertThat(runtimeHints)
|
||||
.matches(resource().forResource("/org/apache/pdfbox/resources/glyphlist/glyphlist.txt"));
|
||||
// Assertions.assertThat(runtimeHints).matches(resource().forResource("/org/apache/pdfbox/resources/afm/**"));
|
||||
// Assertions.assertThat(runtimeHints).matches(resource().forResource("/org/apache/pdfbox/resources/glyphlist/**"));
|
||||
// Assertions.assertThat(runtimeHints).matches(resource().forResource("/org/apache/pdfbox/resources/icc/**"));
|
||||
// Assertions.assertThat(runtimeHints).matches(resource().forResource("/org/apache/pdfbox/resources/text/**"));
|
||||
// Assertions.assertThat(runtimeHints).matches(resource().forResource("/org/apache/pdfbox/resources/ttf/**"));
|
||||
Assertions.assertThat(runtimeHints)
|
||||
.matches(resource().forResource("/org/apache/pdfbox/resources/version.properties"));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user