Class Utils

java.lang.Object
com.sap.cds.maven.plugin.util.Utils

public class Utils extends Object
A helper class providing utility methods.
  • Method Details

    • decryptServer

      public static org.apache.maven.settings.Server decryptServer(String serverId, org.apache.maven.execution.MavenSession mavenSession, org.apache.maven.settings.crypto.SettingsDecrypter decrypter, CdsMojoLogger logger)
    • parseCdsdkVersionOutput

      public static Map<String,String> parseCdsdkVersionOutput(String cdsdkVersionOutput)
      Parses the given cds version console output and returns a Map filled with cds component name as key and version information as value.
      Parameters:
      cdsdkVersionOutput - the console output of command line cds version
      Returns:
      a Map filled with component name as key and version information as value.
    • array

      @SafeVarargs public static <T> T[] array(T... arguments)
      Creates an array with given arguments
      Parameters:
      arguments - the array elements
      Returns:
      the string array containing given arguments
    • createDir

      public static File createDir(String dirPath) throws IOException
      Creates a directory including all parent directories.
      Parameters:
      dirPath - the directory path
      Returns:
      the created directory
      Throws:
      IOException - if the directory can’t be created or the file already exists but isn’t a directory
    • createFile

      public static File createFile(File file) throws IOException
      Creates a file including all parent directories.
      Parameters:
      file - the file to created
      Returns:
      the created file
      Throws:
      IOException - if the file can’t be created
    • findDirectory

      public static File findDirectory(String directoryName, Collection<File> roots) throws IOException
      Parameters:
      roots - start directories for finding the directory
      directoryName - the glob directory name pattern
      Returns:
      the file or null if not found
      Throws:
      IOException - if an I/O error occurred while finding the file
    • findExecutable

      public static File findExecutable(String execName, CdsMojoLogger logger) throws IOException
      Finds the location of given executable on local file-system.
      Parameters:
      execName - name of executable to find
      logger - a logger instance
      Returns:
      a File representing the found executable or null if not found
      Throws:
      IOException - if an I/O error occurred during search
      FileNotFoundException - if executable couldn't be found
    • findFile

      public static File findFile(String fileName, Collection<File> roots) throws IOException
      Parameters:
      roots - start directories for finding the directory
      fileName - the glob file name pattern
      Returns:
      the file or null if not found
      Throws:
      IOException - if an I/O error occurred while finding the file
    • getPackageDir

      public static File getPackageDir(File srcBaseDir, String packageName)
      Returns the directory for a given Java package.
      Parameters:
      srcBaseDir - the source base directory
      packageName - the package
      Returns:
      the package directory
    • getResourceDirs

      public static Stream<File> getResourceDirs(org.apache.maven.project.MavenProject project)
      Returns a stream with all resource directories of a given Maven project.
      Parameters:
      project - the Maven project
      Returns:
      a stream with all resource directories
    • parse

      public static Document parse(File file) throws ParserConfigurationException, SAXException, IOException
      Parses a given xml file into a Document.
      Parameters:
      file - the xml file to parse
      Returns:
      the parsed Document
      Throws:
      ParserConfigurationException - if a DocumentBuilder can’t be created which satisfies the configuration requested.
      IOException - If any IO errors occur.
      SAXException - If any parse errors occur.
    • prepareDestination

      public static File prepareDestination(File destination, boolean directory) throws IOException
      Parameters:
      destination - the destination to prepare
      directory - if given destination is a directory
      Returns:
      given destination file
      Throws:
      IOException - if preparing failed
    • runIfLockable

      public static void runIfLockable(File lockFile, Runnable runnable, int maxWait) throws IOException
      Runs the given Runnable if a lock could be acquired on given file.
      Parameters:
      lockFile - the File used for synchronisation
      runnable - the Runnable to execute when lock could be acquired
      maxWait - max. time to wait in seconds to acquire lock
      Throws:
      IOException - if lock couldn't be acquired in given max. wait time
    • setExecutionFlag

      public static void setExecutionFlag(File file) throws IOException
      Sets execution flag at given file.
      Parameters:
      file - the file
      Throws:
      IOException - if setting execution flag failed
      FileNotFoundException - if file wasn't found
    • setIfNotNull

      public static <T> void setIfNotNull(Consumer<T> setter, T value)
      Calls a given setter with given value, if value isn't null.
      Type Parameters:
      T - type of value to set
      Parameters:
      setter - the setter to call
      value - the value to set
    • splitByWhitespaces

      public static String[] splitByWhitespaces(String string)
      Splits the given string into tokens by using whitespace as delimiters.
      Parameters:
      string - the string to be split into tokens
      Returns:
      the tokens
    • store

      public static void store(File file, Document doc) throws TransformerFactoryConfigurationError, TransformerException
      Serializes a given Document into a file.
      Parameters:
      file - the target file
      doc - the Document to store
      Throws:
      TransformerFactoryConfigurationError - if the XML serializer can't be created
      TransformerException - if serialization to XML failed