Class PomReader

java.lang.Object
de.oktoflow.platform.cmdTools.PomReader

public class PomReader extends Object
Implements some functions regarding pom files. Taken over from Qualimaster.
Author:
Patu
  • Constructor Details

    • PomReader

      public PomReader()
  • Method Details

    • getInfo

      public static PomReader.PomInfo getInfo(File file)
      Returns the full classpath from a pom file.
      Parameters:
      file - The pom file to read from.
      Returns:
      The full classpath or NULL if no classpath was available.
    • getInfo

      public static PomReader.PomInfo getInfo(File file, Consumer<String> errorConsumer)
      Returns the full classpath from a POM file.
      Parameters:
      file - The pom file to read from.
      errorConsumer - consumes fatal errors, may be null for none
      Returns:
      The full classpath or null if no classpath was available.
    • equalsSafe

      public static boolean equalsSafe(String s1, String s2)
      Checks the given strings for equality but only if none is null.
      Parameters:
      s1 - the first string
      s2 - the second string
      Returns:
      true if both are equal, false else
    • startsWithSafe

      private static boolean startsWithSafe(String s1, String s2)
      Checks whether s1 starts with s2 but only if none is null.
      Parameters:
      s1 - the containing string
      s2 - the prefix string
      Returns:
      true if s1 starts with s2, false else
    • readPom

      private static void readPom(File file, PomReader.PomHandler handler) throws IOException
      Reads a POM file and informs the handler. Writes back the POM to file if handler indicates a modification.
      Parameters:
      file - the file to read
      handler - the handler
      Throws:
      IOException - if reading fails
    • parseParent

      private static void parseParent(Node node, PomReader.PomHandler handler)
      Parses a POM parent information.
      Parameters:
      node - the node identified as parent
      handler - the POM handler
    • parseProperties

      private static void parseProperties(Node node, PomReader.PomHandler handler)
      Parses a POM property information.
      Parameters:
      node - the node identified as parent
      handler - the POM handler
    • replaceVersion

      public static PomReader.Result replaceVersion(File file, String oldPomVersion, String newPomVersion, String oldParentPomVersion, String newParentPomVersion, Set<String> properties) throws IOException
      Replaces POM versions.
      Parameters:
      file - the POM file
      oldPomVersion - the old POM version (may be null to ignore)
      newPomVersion - the new POM version (may be null to ignore)
      oldParentPomVersion - the old parent POM version (may be null to ignore)
      newParentPomVersion - the new parent POM version (may be null to ignore)
      properties - set of properties to be considered for POM version replacement
      Returns:
      whether/how file was modified
      Throws:
      IOException - if reading/writing fails
    • replaceVersion

      public static PomReader.Result replaceVersion(File file, String oldPomVersion, String newPomVersion, String oldParentPomVersion, String newParentPomVersion, Set<String> properties, Predicate<String> groupIdPattern) throws IOException
      Replaces POM versions.
      Parameters:
      file - the POM file
      oldPomVersion - the old POM version (may be null to ignore)
      newPomVersion - the new POM version (may be null to ignore)
      oldParentPomVersion - the old parent POM version (may be null to ignore)
      newParentPomVersion - the new parent POM version (may be null to ignore)
      properties - set of properties to be considered for POM version replacement
      groupIdPattern - optional pattern to match the group id (may be null to ignore)
      Returns:
      whether/how file was modified
      Throws:
      IOException - if reading/writing fails
    • toResult

      private static PomReader.Result toResult(PomReader.PomHandler handler)
      Turns handler results to a result constant.
      Parameters:
      handler - the handler
      Returns:
      the result