Interface ArtifactContentReader
- All Known Implementing Classes:
JarArtifactContentReader,ProjectArtifactContentReader,ZipArtifactContentReader
public interface ArtifactContentReader
Provides methods to read the content of an artifact (JAR, ZIP or project folder).
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumstatic final recordA compiled content entry in the artifact. -
Method Summary
Modifier and TypeMethodDescriptiondefault booleanappliesTo(org.apache.maven.artifact.Artifact artifact) Test whether the artifact is of the concerned file type.detectImplementationHierarchy(String className, org.apache.maven.artifact.Artifact artifact, Consumer<ClassNotFoundException> exceptionHandler) Detect the implementation hierarchy of a java class in the artifact.Test whether the artifact has a content entry satisfying the predicate.findEntryWithName(org.apache.maven.artifact.Artifact artifact, String entryName) Test whether the artifact has a content entry with the given name.Get the concerned artifact file type.default booleanhasEntryWithPath(org.apache.maven.artifact.Artifact artifact, Path entryPath) Test whether the artifact has a content entry at the given relative path.default booleanhasEntryWithPath(org.apache.maven.artifact.Artifact artifact, Predicate<Path> predicateOnPath) Test whether the artifact has a content entry satisfying the predicate.default voidlogIOException(IOException e, File file, Path entryPath) Log an IOException when reading the artifact content.default voidreadEntries(org.apache.maven.artifact.Artifact artifact, Predicate<Path> predicateOnPath, Consumer<ArtifactContentReader.Entry> reader) Read the (compiled) content of the artifact entries which satisfy the path predicate.<R,A> R readEntries(org.apache.maven.artifact.Artifact artifact, Predicate<Path> predicateOnPath, Collector<ArtifactContentReader.Entry, A, R> reader) Read the (compiled) content of the artifact entries which satisfy the path predicate.default voidreadEntry(org.apache.maven.artifact.Artifact artifact, Path entryPath, Consumer<InputStream> reader) Read the (compiled) content of the artifact entry at the given relative path.<T> Optional<T>readFirstEntry(org.apache.maven.artifact.Artifact artifact, Predicate<Path> predicateOnPath, Function<ArtifactContentReader.Entry, T> reader) Read the (compiled) content of the first artifact entry which satisfy the path predicate.
-
Method Details
-
appliesTo
default boolean appliesTo(org.apache.maven.artifact.Artifact artifact) Test whether the artifact is of the concerned file type.- Parameters:
artifact- the artifact to test- Returns:
- true when the artifact is of the concerned file type
-
getArtifactFileType
ArtifactContentReader.ArtifactFileType getArtifactFileType()Get the concerned artifact file type.- Returns:
- the artifact file type
-
findEntry
default Optional<Path> findEntry(org.apache.maven.artifact.Artifact artifact, Predicate<Path> predicateOnPath) Test whether the artifact has a content entry satisfying the predicate.- Parameters:
artifact- the artifact to test (with adequate file type)predicateOnPath- the predicate testing on entry path- Returns:
- relative path to a valid entry, empty when no valid entry was found
-
findEntryWithName
default Optional<Path> findEntryWithName(org.apache.maven.artifact.Artifact artifact, String entryName) Test whether the artifact has a content entry with the given name.- Parameters:
artifact- the artifact to test (with adequate file type)entryName- the simple name of the entry to test- Returns:
- relative path to a valid entry, empty when no valid entry was found
-
hasEntryWithPath
default boolean hasEntryWithPath(org.apache.maven.artifact.Artifact artifact, Predicate<Path> predicateOnPath) Test whether the artifact has a content entry satisfying the predicate.- Parameters:
artifact- the artifact to test (with adequate file type)predicateOnPath- the predicate testing on entry path- Returns:
- true when there is a valid entry
-
hasEntryWithPath
Test whether the artifact has a content entry at the given relative path.- Parameters:
artifact- the artifact to test (with adequate file type)entryPath- the relative path of the entry to test- Returns:
- true when there is a valid entry
-
readFirstEntry
<T> Optional<T> readFirstEntry(org.apache.maven.artifact.Artifact artifact, Predicate<Path> predicateOnPath, Function<ArtifactContentReader.Entry, T> reader) throws IOExceptionRead the (compiled) content of the first artifact entry which satisfy the path predicate.You must close the requested input stream in the reader.
- Parameters:
artifact- the artifact to read (with adequate file type)predicateOnPath- the predicate to test on the entry pathreader- the reading job which will eventually consume the valid entry content and transform it- Returns:
- the result of the reading job, empty when no valid entry was found
- Throws:
IOException- exception reading artifact content
-
readEntry
default void readEntry(org.apache.maven.artifact.Artifact artifact, Path entryPath, Consumer<InputStream> reader) throws IllegalArgumentException, IOException Read the (compiled) content of the artifact entry at the given relative path.The input stream is closed automatically, so you do not have to worry about it.
- Parameters:
artifact- the artifact to read (with adequate file type)entryPath- the relative path of the entry to readreader- the reading job which will consume the entry content- Throws:
IOException- exception reading artifact contentIllegalArgumentException- when entry not found
-
readEntries
<R,A> R readEntries(org.apache.maven.artifact.Artifact artifact, Predicate<Path> predicateOnPath, Collector<ArtifactContentReader.Entry, A, throws IOExceptionR> reader) Read the (compiled) content of the artifact entries which satisfy the path predicate.You must close the requested input stream in the reader.
- Parameters:
artifact- the artifact to read (with adequate file type)predicateOnPath- the predicate to test on the entry pathreader- the reading job which will eventually consume each valid entry content and collect the result- Returns:
- the result collected by the reader
- Throws:
IOException- exception reading artifact content
-
readEntries
default void readEntries(org.apache.maven.artifact.Artifact artifact, Predicate<Path> predicateOnPath, Consumer<ArtifactContentReader.Entry> reader) throws IOException Read the (compiled) content of the artifact entries which satisfy the path predicate.You must close the requested input stream in the reader.
- Parameters:
artifact- the artifact to read (with adequate file type)predicateOnPath- the predicate to test on the entry pathreader- the reading job which will eventually consume each valid entry content- Throws:
IOException- exception reading artifact content
-
logIOException
Log an IOException when reading the artifact content.- Parameters:
e- IO exceptionfile- the artifact fileentryPath- the relative path of the entry or null
-
detectImplementationHierarchy
Set<String> detectImplementationHierarchy(String className, org.apache.maven.artifact.Artifact artifact, Consumer<ClassNotFoundException> exceptionHandler) throws UnsupportedOperationException Detect the implementation hierarchy of a java class in the artifact.Some implementations may not support this method for their artifact file type.
- Parameters:
className- the name of the class to analyzeartifact- the artifact to read (with adequate file type)exceptionHandler- handles any ClassNotFoundException while loading classes- Returns:
- set of class names in the implementation's parent hierarchy
- Throws:
UnsupportedOperationException- when the implementation does not support this method
-