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).
  • 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

      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

      default boolean hasEntryWithPath(org.apache.maven.artifact.Artifact artifact, Path entryPath)
      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 IOException
      Read 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 path
      reader - 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 read
      reader - the reading job which will consume the entry content
      Throws:
      IOException - exception reading artifact content
      IllegalArgumentException - when entry not found
    • readEntries

      <R, A> R readEntries(org.apache.maven.artifact.Artifact artifact, Predicate<Path> predicateOnPath, Collector<ArtifactContentReader.Entry,A,R> 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 path
      reader - 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 path
      reader - the reading job which will eventually consume each valid entry content
      Throws:
      IOException - exception reading artifact content
    • logIOException

      default void logIOException(IOException e, File file, Path entryPath)
      Log an IOException when reading the artifact content.
      Parameters:
      e - IO exception
      file - the artifact file
      entryPath - 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 analyze
      artifact - 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