Class PGXSUtils


  • public final class PGXSUtils
    extends Object
    Utility methods to simplify and hide the bland implementation details for writing JavaScript snippets.
    • Constructor Detail

      • PGXSUtils

        public PGXSUtils​(org.apache.maven.project.MavenProject project,
                         org.apache.maven.plugin.logging.Log log)
    • Method Detail

      • quoteStringForC

        public String quoteStringForC​(String s)
        Returns the input wrapped in double quotes and with internal characters escaped where appropriate using the C conventions.
        Parameters:
        s - string to be escaped
        Returns:
        a C compatible String enclosed in double quotes
      • defaultCharsetDecodeStrict

        public String defaultCharsetDecodeStrict​(byte[] bytes)
                                          throws CharacterCodingException
        Returns the string decoded from input bytes using default platform charset.
        Parameters:
        bytes - byte array to be decoded
        Returns:
        string decoded from input bytes
        Throws:
        CharacterCodingException - if unable to decode bytes using default platform charset
      • getPgConfigProperty

        public String getPgConfigProperty​(String pgConfigCommand,
                                          String pgConfigArgument)
                                   throws IOException,
                                          InterruptedException
        Returns the output, decoded using default platform charset, of the input command executed with the input argument.

        If the input parameter pgConfigCommand is empty or null, pg_config is used as the default value. If multiple version of pg_config are available or pg_config is not present on the path, consider passing an absolute path to pg_config. It is also recommended that only a single property be passed at a time.

        Parameters:
        pgConfigCommand - pg_config command to execute
        pgConfigArgument - argument to be passed to the command
        Returns:
        output of the input command executed with the input argument
        Throws:
        IOException - if unable to read output of the command
        InterruptedException - if command does not complete successfully
      • processBuilder

        public ProcessBuilder processBuilder​(Consumer<List<String>> consumer)
        Returns a ProcessBuilder with suitable defaults and arguments added from input function.
        Parameters:
        consumer - function which adds arguments to the ProcessBuilder
        Returns:
        ProcessBuilder with input arguments and suitable defaults
      • runCommand

        public int runCommand​(ProcessBuilder processBuilder)
        Executes a ProcessBuilder and returns the exit code of the process.
        Parameters:
        processBuilder - to execute
        Returns:
        exit code of the executed process or -1 if an exception occurs during execution
      • isProfileActive

        public boolean isProfileActive​(String profileName)
        Returns true if the profile with given name exists and is active, false otherwise.

        A warning is logged if the no profile with the input name exists in the current project.

        Parameters:
        profileName - name of profile to check
        Returns:
        true if profile exists and is active, false otherwise
      • buildPaths

        public Map<String,​String> buildPaths​(List<String> elements)
        Returns a map with two elements with classpath and modulepath as keys and their joined string paths as the respective values.
        Parameters:
        elements - list of elements to build classpath and modulepath from
        Returns:
        a map containing the classpath and modulepath as separate elements
      • shouldPlaceOnModulepath

        public boolean shouldPlaceOnModulepath​(String filePath)
                                        throws IOException
        Returns true if the element should be placed on the module path.

        An file path element should be placed on the module path if it points to 1) a directory with a top level module-info.class file 2) a JAR file having a module-info.class entry or the Automatic-Module-Name as a manifest attribute

        Parameters:
        filePath - the filepath to check whether is a module
        Returns:
        true if input path should go on modulepath, false otherwise
        Throws:
        IOException - any thrown by the underlying file operations
      • getFilesWithExtension

        public List<String> getFilesWithExtension​(Path sourceDirectory,
                                                  String extension)
        Returns the list of files with given extension in the input directory.
        Parameters:
        sourceDirectory - to list files inside
        extension - to filter files to be selected
        Returns:
        list of strings of absolute paths of files
      • forWindowsCRuntime

        public ProcessBuilder forWindowsCRuntime​(ProcessBuilder pb)
        Adjust the command arguments of a ProcessBuilder so that they will be recovered correctly on Windows by a target C/C++ program using the argument parsing algorithm of the usual C run-time code, when it is known that the command will not be handled first by cmd.

        This transformation must account for the way the C runtime will ultimately parse the parameters apart, and also for the behavior of Java's runtime in assembling the command line that the invoked process will receive.

        Parameters:
        pb - a ProcessBuilder whose command has been set to an executable that parses parameters using the C runtime rules, and arguments as they should result from parsing.
        Returns:
        The same ProcessBuilder, with the argument list rewritten as necessary to produce the original list as a result of Windows C runtime parsing,
        Throws:
        IllegalArgumentException - if the ProcessBuilder does not have at least the first command element (the executable to run)
        UnsupportedOperationException - if the arguments passed, or system properties in effect, produce a case this transformation cannot handle