Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use cached URLs for locating the Jandex indexes #1590

Merged
merged 2 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion microprofile/openapi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
</goals>
<phase>process-test-classes</phase>
<configuration>
<classesDir>${project.build.directory}/test-classes}</classesDir>
<classesDir>${project.build.directory}/test-classes</classesDir>
<indexName>other.idx</indexName>
<fileSets>
<fileSet>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public class OpenApiCdiExtension implements Extension {
HelidonFeatures.register("OpenAPI");
}

private final List<URL> indexURLs;
private final String[] indexPaths;
private final int indexURLCount;

private final Set<Class<?>> annotatedTypes = new HashSet<>();

Expand All @@ -86,7 +87,9 @@ public OpenApiCdiExtension() throws IOException {
}

OpenApiCdiExtension(String... indexPaths) throws IOException {
indexURLs = findIndexFiles(indexPaths);
this.indexPaths = indexPaths;
List<URL> indexURLs = findIndexFiles(indexPaths);
indexURLCount = indexURLs.size();
if (indexURLs.isEmpty()) {
LOGGER.log(Level.INFO, () -> String.format(
"OpenAPI support could not locate the Jandex index file %s "
Expand Down Expand Up @@ -128,7 +131,7 @@ void registerOpenApi(@Observes @Priority(PLATFORM_AFTER) @Initialized(Applicatio
* @param event {@code ProcessAnnotatedType} event
*/
private <X> void processAnnotatedType(@Observes ProcessAnnotatedType<X> event) {
if (indexURLs.isEmpty()) {
if (indexURLCount == 0) {
Class<?> c = event.getAnnotatedType()
.getJavaClass();
annotatedTypes.add(c);
Expand All @@ -144,7 +147,7 @@ private <X> void processAnnotatedType(@Observes ProcessAnnotatedType<X> event) {
* reading class bytecode from the classpath
*/
public IndexView indexView() throws IOException {
return !indexURLs.isEmpty() ? existingIndexFileReader() : indexFromHarvestedClasses();
return indexURLCount > 0 ? existingIndexFileReader() : indexFromHarvestedClasses();
}

/**
Expand All @@ -155,13 +158,16 @@ public IndexView indexView() throws IOException {
*/
private IndexView existingIndexFileReader() throws IOException {
List<IndexView> indices = new ArrayList<>();
for (URL indexURL : indexURLs) {
/*
* Do not reuse the previously-computed indexURLs; those values will be incorrect with native images.
*/
for (URL indexURL : findIndexFiles(indexPaths)) {
try (InputStream indexIS = indexURL.openStream()) {
LOGGER.log(Level.CONFIG, "Adding Jandex index at {0}", indexURL.toString());
indices.add(new IndexReader(indexIS).read());
} catch (IOException ex) {
throw new IOException("Attempted to read from previously-located index file "
+ indexURL + " but the file cannot be found", ex);
+ indexURL + " but the index cannot be found", ex);
}
}
return indices.size() == 1 ? indices.get(0) : CompositeIndex.create(indices);
Expand Down