diff --git a/crd-generator/collector/src/main/java/io/fabric8/crd/generator/collector/CustomResourceClassLoader.java b/crd-generator/collector/src/main/java/io/fabric8/crd/generator/collector/CustomResourceClassLoader.java index 9a82f1e8034..c1cb0925df4 100644 --- a/crd-generator/collector/src/main/java/io/fabric8/crd/generator/collector/CustomResourceClassLoader.java +++ b/crd-generator/collector/src/main/java/io/fabric8/crd/generator/collector/CustomResourceClassLoader.java @@ -33,7 +33,7 @@ class CustomResourceClassLoader { private ClassLoader parentClassLoader; - private ClassLoader classLoader; + private ClassLoader cachedClassLoader; public CustomResourceClassLoader withParentClassLoader(ClassLoader parentClassLoader) { this.parentClassLoader = parentClassLoader; @@ -74,8 +74,8 @@ private Class loadClass(String className) { } private ClassLoader getClassLoader() { - if (classLoader != null) { - return classLoader; + if (cachedClassLoader != null) { + return cachedClassLoader; } if (!classpathElements.isEmpty()) { @@ -89,19 +89,19 @@ private ClassLoader getClassLoader() { }).toArray(URL[]::new); if (parentClassLoader != null) { - this.classLoader = new URLClassLoader(urls, parentClassLoader); + this.cachedClassLoader = new URLClassLoader(urls, parentClassLoader); } else { - this.classLoader = new URLClassLoader(urls); + this.cachedClassLoader = new URLClassLoader(urls); } } else { if (parentClassLoader != null) { - this.classLoader = parentClassLoader; + this.cachedClassLoader = parentClassLoader; } else { - this.classLoader = Thread.currentThread().getContextClassLoader(); + this.cachedClassLoader = Thread.currentThread().getContextClassLoader(); } } - return classLoader; + return cachedClassLoader; } } diff --git a/crd-generator/collector/src/main/java/io/fabric8/crd/generator/collector/CustomResourceCollector.java b/crd-generator/collector/src/main/java/io/fabric8/crd/generator/collector/CustomResourceCollector.java index 8cd38dad0a0..38e676a1b75 100644 --- a/crd-generator/collector/src/main/java/io/fabric8/crd/generator/collector/CustomResourceCollector.java +++ b/crd-generator/collector/src/main/java/io/fabric8/crd/generator/collector/CustomResourceCollector.java @@ -40,7 +40,7 @@ public class CustomResourceCollector { private static final Logger log = LoggerFactory.getLogger(CustomResourceCollector.class); private final CustomResourceClassLoader customResourceClassLoader = new CustomResourceClassLoader(); - private final CustomResourceJandexCollector jandexCollector = new CustomResourceJandexCollector(); + private final JandexCustomResourceClassScanner jandexCustomResourceClassScanner = new JandexCustomResourceClassScanner(); private final Set customResourceClassNames = new HashSet<>(); @@ -78,27 +78,27 @@ public CustomResourceCollector withCustomResourceClasses(Collection clas } public CustomResourceCollector withIndex(IndexView... index) { - jandexCollector.withIndex(index); + jandexCustomResourceClassScanner.withIndex(index); return this; } public CustomResourceCollector withIndices(Collection indices) { - jandexCollector.withIndices(indices); + jandexCustomResourceClassScanner.withIndices(indices); return this; } public CustomResourceCollector withFileToIndex(File... files) { - jandexCollector.withFileToIndex(files); + jandexCustomResourceClassScanner.withFileToIndex(files); return this; } public CustomResourceCollector withFilesToIndex(Collection files) { - jandexCollector.withFilesToIndex(files); + jandexCustomResourceClassScanner.withFilesToIndex(files); return this; } public CustomResourceCollector withForceIndex(boolean forceIndex) { - jandexCollector.withForceIndex(forceIndex); + jandexCustomResourceClassScanner.withForceIndex(forceIndex); return this; } @@ -127,10 +127,10 @@ public CustomResourceCollector withExcludePackages(Collection packages) private List> findCustomResourceClassesAsList() { Set customResourcesClassNames = new HashSet<>(customResourceClassNames); - // use indices only if custom resource class names are not explicitly given + // search only if custom resource class names are not explicitly given if (customResourcesClassNames.isEmpty()) { - customResourcesClassNames.addAll(jandexCollector.findCustomResourceClasses()); - log.debug("Found {} custom resource classes before filtering", customResourcesClassNames.size()); + customResourcesClassNames.addAll(jandexCustomResourceClassScanner.findCustomResourceClasses()); + log.debug("Found {} custom resource classes", customResourcesClassNames.size()); } else { log.debug("Using explicit {} custom resource classes and skip scanning", customResourcesClassNames); } diff --git a/crd-generator/collector/src/main/java/io/fabric8/crd/generator/collector/CustomResourceJandexCollector.java b/crd-generator/collector/src/main/java/io/fabric8/crd/generator/collector/JandexCustomResourceClassScanner.java similarity index 61% rename from crd-generator/collector/src/main/java/io/fabric8/crd/generator/collector/CustomResourceJandexCollector.java rename to crd-generator/collector/src/main/java/io/fabric8/crd/generator/collector/JandexCustomResourceClassScanner.java index f732e8d154e..3271f53bc2c 100644 --- a/crd-generator/collector/src/main/java/io/fabric8/crd/generator/collector/CustomResourceJandexCollector.java +++ b/crd-generator/collector/src/main/java/io/fabric8/crd/generator/collector/JandexCustomResourceClassScanner.java @@ -20,54 +20,57 @@ import io.fabric8.kubernetes.model.annotation.Group; import io.fabric8.kubernetes.model.annotation.Version; import org.jboss.jandex.ClassInfo; -import org.jboss.jandex.CompositeIndex; import org.jboss.jandex.Index; import org.jboss.jandex.IndexView; import org.jboss.jandex.Indexer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Objects; -import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; /** - * Collects multiple Jandex index sources and allows to find Custom Resource class names by using - * {@link CustomResourceJandexCollector#findCustomResourceClasses()} in the resulting composite index. + * Collects multiple Jandex index sources and allows to find Custom Resource class names in the + * resulting composite index by using {@link JandexCustomResourceClassScanner#findCustomResourceClasses()}. + *

+ * If not overridden by {@link JandexCustomResourceClassScanner#forceIndex}, the implementation uses an + * existing Jandex index if found in the source. Otherwise, the index will be created on the fly. + *

* * @see Index * @see JandexIndexer + * @see JandexUtils */ -class CustomResourceJandexCollector { - - private static final Logger log = LoggerFactory.getLogger(CustomResourceJandexCollector.class); +public class JandexCustomResourceClassScanner { private final List indices = new LinkedList<>(); private final Set filesToIndex = new HashSet<>(); + /** + * If true, indices will always be created even if an index exists at the source. + */ private boolean forceIndex = false; - public CustomResourceJandexCollector withForceIndex(boolean forceIndex) { + public JandexCustomResourceClassScanner withForceIndex(boolean forceIndex) { this.forceIndex = forceIndex; return this; } - public CustomResourceJandexCollector withIndex(IndexView... index) { + public JandexCustomResourceClassScanner withIndex(IndexView... index) { if (index != null) { withIndices(Arrays.asList(index)); } return this; } - public CustomResourceJandexCollector withIndices(Collection indices) { + public JandexCustomResourceClassScanner withIndices(Collection indices) { if (indices != null) { indices.stream() .filter(Objects::nonNull) @@ -76,14 +79,14 @@ public CustomResourceJandexCollector withIndices(Collection indices) return this; } - public CustomResourceJandexCollector withFileToIndex(File... files) { + public JandexCustomResourceClassScanner withFileToIndex(File... files) { if (files != null) { withFilesToIndex(Arrays.asList(files)); } return this; } - public CustomResourceJandexCollector withFilesToIndex(Collection files) { + public JandexCustomResourceClassScanner withFilesToIndex(Collection files) { if (files != null) { files.stream() .filter(Objects::nonNull) @@ -92,39 +95,33 @@ public CustomResourceJandexCollector withFilesToIndex(Collection files) { return this; } - public List findCustomResourceClasses() { - Collection allIndices = new LinkedList<>(); - allIndices.add(createBaseIndex()); - allIndices.addAll(this.indices); - - if (!filesToIndex.isEmpty()) { - Set actualFilesToIndex = new HashSet<>(); - for (File file : filesToIndex) { - if (forceIndex) { - // no lookup for existing indices - actualFilesToIndex.add(file); - } else { - Optional index = JandexUtils.findExistingIndex(file); - if (index.isPresent()) { - allIndices.add(index.get()); - } else { - actualFilesToIndex.add(file); - } - } - } - - log.debug("Creating {} indices", actualFilesToIndex.size()); - allIndices.add(JandexIndexer.indexFor(actualFilesToIndex)); - } + /** + * Finds Custom Resource classes in the pre-configured scope. + * + * @return the Custom Resource classes + */ + public Collection findCustomResourceClasses() { + List actualIndices = new ArrayList<>(indices); + actualIndices.add(createBaseIndex()); - CompositeIndex compositeIndex = CompositeIndex.create(allIndices); - return findCustomResourceClasses(compositeIndex).stream() + IndexView index = JandexUtils.createIndex(actualIndices, filesToIndex, forceIndex); + + return findCustomResourceClasses(index).stream() .map(ClassInfo::toString) .collect(Collectors.toList()); } + /** + * Finds Custom Resource classes in an index. + * + * @param index the index + * @return the Custom Resource classes + * + * @see JandexCustomResourceClassScanner#createBaseIndex() + */ private List findCustomResourceClasses(IndexView index) { - // Only works if HasMetadata and all intermediate classes (like CustomResource) have been indexed + // Only works if HasMetadata and all intermediate classes (like CustomResource) + // are included in given index. return index.getAllKnownImplementors(HasMetadata.class) .stream() .filter(classInfo -> classInfo.hasAnnotation(Group.class)) @@ -133,9 +130,11 @@ private List findCustomResourceClasses(IndexView index) { } /** - * Creates the base index required to scan for custom resources. + * Creates the base index required to scan for Custom Resource classes. * * @return the base index. + * + * @see JandexCustomResourceClassScanner#findCustomResourceClasses(IndexView) */ private Index createBaseIndex() { try { diff --git a/crd-generator/collector/src/main/java/io/fabric8/crd/generator/collector/JandexException.java b/crd-generator/collector/src/main/java/io/fabric8/crd/generator/collector/JandexException.java new file mode 100644 index 00000000000..6fbc0f098f7 --- /dev/null +++ b/crd-generator/collector/src/main/java/io/fabric8/crd/generator/collector/JandexException.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.generator.collector; + +public class JandexException extends RuntimeException { + + public JandexException(String message) { + super(message); + } + + public JandexException(String message, Throwable cause) { + super(message, cause); + } + + public JandexException(Throwable cause) { + super(cause); + } +} diff --git a/crd-generator/collector/src/main/java/io/fabric8/crd/generator/collector/JandexIndexer.java b/crd-generator/collector/src/main/java/io/fabric8/crd/generator/collector/JandexIndexer.java index 18d88bbf963..a75a2b24682 100644 --- a/crd-generator/collector/src/main/java/io/fabric8/crd/generator/collector/JandexIndexer.java +++ b/crd-generator/collector/src/main/java/io/fabric8/crd/generator/collector/JandexIndexer.java @@ -27,19 +27,19 @@ import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Enumeration; -import java.util.List; -import java.util.Objects; import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.stream.Stream; /** * Allows to create a Jandex index based on given class files, directories and JAR archives. - * Unlike {@link Index#of(File...)}, this implementation performs a recursive scan of the directories. + *

+ * Unlike {@link Index#of(File...)}, this implementation performs a recursive scan + * of the directories and enforces some limits. + *

*/ class JandexIndexer { @@ -48,28 +48,10 @@ class JandexIndexer { private static final String CLASS_FILE_SUFFIX = ".class"; private static final String JAR_FILE_SUFFIX = ".jar"; - private final List files = new ArrayList<>(); - - private int maxJarEntries = 10000; + private int maxJarEntries = 100000; private long maxBytesReadFromJar = 100000000; // 100 MB private long maxClassFileSize = 1000000; // 1 MB - public JandexIndexer withFile(File... file) { - if (file != null) { - withFiles(Arrays.asList(file)); - } - return this; - } - - public JandexIndexer withFiles(Collection files) { - if (files != null) { - files.stream() - .filter(Objects::nonNull) - .forEach(this.files::add); - } - return this; - } - public JandexIndexer withMaxJarEntries(int maxJarEntries) { if (maxJarEntries < 1) throw new IllegalArgumentException("maxJarEntries must be greater than 0"); @@ -91,13 +73,17 @@ public JandexIndexer withMaxBytesReadFromJar(long maxBytesReadFromJar) { return this; } - public Index createIndex() { + public Index createIndex(File... files) { + return createIndex(Arrays.asList(files)); + } + + public Index createIndex(Collection files) { Indexer indexer = new Indexer(); - appendToIndex(indexer); + appendToIndex(files, indexer); return indexer.complete(); } - private void appendToIndex(Indexer indexer) { + private void appendToIndex(Collection files, Indexer indexer) { for (File file : files) { if (file.isDirectory()) { scanDirectoryAndAddToIndex(file, indexer); @@ -180,12 +166,6 @@ private long addToIndex(InputStream inputStream, Indexer indexer) throws IOExcep } } - public static Index indexFor(Collection files) { - return new JandexIndexer() - .withFiles(files) - .createIndex(); - } - static class BoundedInputStream extends InputStream implements AutoCloseable { private final long maxBytes; private final InputStream inputStream; diff --git a/crd-generator/collector/src/main/java/io/fabric8/crd/generator/collector/JandexUtils.java b/crd-generator/collector/src/main/java/io/fabric8/crd/generator/collector/JandexUtils.java index f19f93e2d8b..48195d6ffe1 100644 --- a/crd-generator/collector/src/main/java/io/fabric8/crd/generator/collector/JandexUtils.java +++ b/crd-generator/collector/src/main/java/io/fabric8/crd/generator/collector/JandexUtils.java @@ -15,34 +15,91 @@ */ package io.fabric8.crd.generator.collector; +import org.jboss.jandex.CompositeIndex; import org.jboss.jandex.Index; import org.jboss.jandex.IndexReader; +import org.jboss.jandex.IndexView; import org.jboss.jandex.UnsupportedVersion; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; +import java.util.Collection; +import java.util.HashSet; +import java.util.LinkedList; import java.util.Optional; +import java.util.Set; import java.util.jar.JarEntry; import java.util.jar.JarFile; /** - * Utility methods to find an existing Jandex index in a directory or JAR file. + * Utility methods for Jandex */ class JandexUtils { + private static final Logger log = LoggerFactory.getLogger(JandexIndexer.class); + static final String JAR_FILE_SUFFIX = ".jar"; private static final String DEFAULT_JANDEX_INDEX = "META-INF/jandex.idx"; private JandexUtils() { } + /** + * Creates a composite index from given Jandex indices, class files, directories of class files + * and JAR files containing class files. + *

+ * If not forced, the implementation uses an existing Jandex index if found in the source. + * Otherwise, the index will be created on the fly. + *

+ * + * @param indices Jandex indices + * @param filesToIndex files to index + * @param forceIndex If true, indices will always be created even if an index + * exists at the source. + * @return the composite index + */ + static IndexView createIndex(Collection indices, Collection filesToIndex, + boolean forceIndex) { + Collection allIndices = new LinkedList<>(indices); + if (!filesToIndex.isEmpty()) { + Set actualFilesToIndex = new HashSet<>(); + for (File file : filesToIndex) { + if (forceIndex) { + // skip finding existing index and always create new index + actualFilesToIndex.add(file); + } else { + // use existing index if exist otherwise create new index + Optional index = findExistingIndex(file); + if (index.isPresent()) { + allIndices.add(index.get()); + } else { + actualFilesToIndex.add(file); + } + } + } + + log.debug("Creating {} indices", actualFilesToIndex.size()); + allIndices.add(new JandexIndexer().createIndex(actualFilesToIndex)); + } + return CompositeIndex.create(allIndices); + } + static Optional findExistingIndex(File file) { return findExistingIndexInDirectory(file).map(Optional::of) .orElseGet(() -> findExistingIndexInJarFile(file)); } + /** + * Returns the index from the given file if the file is a directory and the index exists. + * + * @param file the file + * @return the index + * @throws JandexException if a fatal error occurs + */ static Optional findExistingIndexInDirectory(File file) { if (!file.isDirectory()) { return Optional.empty(); @@ -55,11 +112,18 @@ static Optional findExistingIndexInDirectory(File file) { try (InputStream in = Files.newInputStream(jandexIndexFile.toPath())) { return Optional.of(readIndex(in)); } catch (IOException e) { - throw new CustomResourceCollectorException( + throw new JandexException( "Could not read Jandex index from directory: " + file, e); } } + /** + * Returns the index from the given file if the file is a JAR file and the index exists. + * + * @param file the file + * @return the index + * @throws JandexException if a fatal error occurs + */ static Optional findExistingIndexInJarFile(File file) { if (!file.isFile() || !file.getName().endsWith(JAR_FILE_SUFFIX)) { return Optional.empty(); @@ -72,7 +136,7 @@ static Optional findExistingIndexInJarFile(File file) { } return Optional.of(readIndex(zip.getInputStream(entry))); } catch (IOException | IllegalArgumentException | UnsupportedVersion e) { - throw new CustomResourceCollectorException( + throw new JandexException( "Could not read Jandex index from JAR file " + file, e); } } diff --git a/crd-generator/collector/src/test/java/io/fabric8/crd/generator/collector/JandexIndexerTest.java b/crd-generator/collector/src/test/java/io/fabric8/crd/generator/collector/JandexIndexerTest.java index a3ae5edb82e..96b82d67ba3 100644 --- a/crd-generator/collector/src/test/java/io/fabric8/crd/generator/collector/JandexIndexerTest.java +++ b/crd-generator/collector/src/test/java/io/fabric8/crd/generator/collector/JandexIndexerTest.java @@ -41,16 +41,14 @@ void checkClassFile() { "target/test-classes/io/fabric8/crd/generator/collector/examples/MyCustomResource.class"); JandexIndexer indexer = new JandexIndexer(); - indexer.withFile(customResourceClassFile1); - Index index = indexer.createIndex(); + Index index = indexer.createIndex(customResourceClassFile1); assertEquals(1, index.getKnownClasses().size()); } @Test void checkDirectoryWithNoClassFiles(@TempDir File tempDir) { JandexIndexer indexer = new JandexIndexer(); - indexer.withFile(tempDir); - Index index = indexer.createIndex(); + Index index = indexer.createIndex(tempDir); assertEquals(0, index.getKnownClasses().size()); } @@ -58,8 +56,7 @@ void checkDirectoryWithNoClassFiles(@TempDir File tempDir) { void checkDirectoryWithClassFiles(@TempDir File tempDir) throws IOException { List expectedClasses = TestUtils.prepareDirectoryWithClasses(tempDir); JandexIndexer indexer = new JandexIndexer(); - indexer.withFile(tempDir); - Index index = indexer.createIndex(); + Index index = indexer.createIndex(tempDir); expectedClasses.forEach(s -> assertNotNull(index.getClassByName(s))); } @@ -68,8 +65,7 @@ void checkJarFileWithNoClassFiles(@TempDir File tempDir) throws IOException { File jarFile = new File(tempDir, "my-dependency.jar"); TestUtils.prepareEmptyJarFile(jarFile); JandexIndexer indexer = new JandexIndexer(); - indexer.withFile(jarFile); - Index index = indexer.createIndex(); + Index index = indexer.createIndex(jarFile); assertEquals(0, index.getKnownClasses().size()); } @@ -78,29 +74,17 @@ void checkJarFileWithClassFiles(@TempDir File tempDir) throws IOException { File jarFile = new File(tempDir, "my-dependency.jar"); List expectedClasses = TestUtils.prepareJarFileWithClasses(jarFile); JandexIndexer indexer = new JandexIndexer(); - indexer.withFile(jarFile); - Index index = indexer.createIndex(); + Index index = indexer.createIndex(jarFile); expectedClasses.forEach(s -> assertNotNull(index.getClassByName(s))); } - @Test - void checkNullsafe() { - JandexIndexer indexer = new JandexIndexer(); - indexer.withFile((File[]) null); - indexer.withFile((File) null); - indexer.withFiles(null); - Index index = indexer.createIndex(); - assertNotNull(index); - } - @Test void checkJarFileEntriesLimit(@TempDir File tempDir) throws IOException { File jarFile = new File(tempDir, "my-dependency.jar"); TestUtils.prepareJarFileWithClasses(jarFile); JandexIndexer indexer = new JandexIndexer(); indexer.withMaxJarEntries(1); - indexer.withFile(jarFile); - assertThrows(CustomResourceCollectorException.class, indexer::createIndex); + assertThrows(CustomResourceCollectorException.class, () -> indexer.createIndex(jarFile)); } @Test @@ -109,8 +93,7 @@ void checkJarFileBytesReadLimit(@TempDir File tempDir) throws IOException { TestUtils.prepareJarFileWithClasses(jarFile); JandexIndexer indexer = new JandexIndexer(); indexer.withMaxBytesReadFromJar(10); - indexer.withFile(jarFile); - assertThrows(CustomResourceCollectorException.class, indexer::createIndex); + assertThrows(CustomResourceCollectorException.class, () -> indexer.createIndex(jarFile)); } @Test @@ -119,8 +102,7 @@ void checkClassFileBytesReadLimit(@TempDir File tempDir) throws IOException { TestUtils.prepareJarFileWithClasses(jarFile); JandexIndexer indexer = new JandexIndexer(); indexer.withMaxClassFileSize(10); - indexer.withFile(jarFile); - assertThrows(CustomResourceCollectorException.class, indexer::createIndex); + assertThrows(CustomResourceCollectorException.class, () -> indexer.createIndex(jarFile)); } @Test diff --git a/crd-generator/collector/src/test/java/io/fabric8/crd/generator/collector/JandexUtilsTest.java b/crd-generator/collector/src/test/java/io/fabric8/crd/generator/collector/JandexUtilsTest.java index f4db58a5bc6..a144c4488c1 100644 --- a/crd-generator/collector/src/test/java/io/fabric8/crd/generator/collector/JandexUtilsTest.java +++ b/crd-generator/collector/src/test/java/io/fabric8/crd/generator/collector/JandexUtilsTest.java @@ -32,7 +32,7 @@ class JandexUtilsTest { @Test - void checkDirectoryWithIndex(@TempDir File tempDir) throws IOException { + void directoryWithIndex_whenFindExistingIndex(@TempDir File tempDir) throws IOException { List expectedClasses = TestUtils.prepareDirectoryWithClassesAndIndex(tempDir); Optional index = JandexUtils.findExistingIndex(tempDir); assertTrue(index.isPresent()); @@ -40,13 +40,13 @@ void checkDirectoryWithIndex(@TempDir File tempDir) throws IOException { } @Test - void checkDirectoryWithoutIndex(@TempDir File tempDir) { + void directoryWithoutIndex_whenFindExistingIndex(@TempDir File tempDir) { Optional index = JandexUtils.findExistingIndex(tempDir); assertFalse(index.isPresent()); } @Test - void checkJarFileWithIndex(@TempDir File tempDir) throws IOException { + void jarFileWithIndex_whenFindExistingIndex(@TempDir File tempDir) throws IOException { File jarFile = new File(tempDir, "my-dependency.jar"); List expectedClasses = TestUtils.prepareJarFileWithClassesAndIndex(jarFile); Optional index = JandexUtils.findExistingIndex(jarFile); @@ -55,7 +55,7 @@ void checkJarFileWithIndex(@TempDir File tempDir) throws IOException { } @Test - void checkJarFileWithoutIndex(@TempDir File tempDir) throws IOException { + void jarFileWithoutIndex_whenFindExistingIndex(@TempDir File tempDir) throws IOException { File jarFile = new File(tempDir, "my-dependency.jar"); TestUtils.prepareJarFileWithClasses(jarFile); Optional index = JandexUtils.findExistingIndex(jarFile); @@ -63,10 +63,10 @@ void checkJarFileWithoutIndex(@TempDir File tempDir) throws IOException { } @Test - void checkJarFileWithInvalidIndex(@TempDir File tempDir) throws IOException { + void jarFileWithInvalidIndex_whenFindExistingIndex(@TempDir File tempDir) throws IOException { File jarFile = new File(tempDir, "my-dependency.jar"); TestUtils.prepareJarFileWithInvalidIndex(jarFile); - assertThrows(CustomResourceCollectorException.class, () -> JandexUtils.findExistingIndex(jarFile)); + assertThrows(JandexException.class, () -> JandexUtils.findExistingIndex(jarFile)); } }