Class Maven

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static boolean AS_PROCESS  
      private static java.lang.String CLASSPATH  
      private static java.lang.String CLASSPATH_EXCLUDE  
      private static java.lang.String MAVEN_HOME  
      private static java.lang.String TMP_FOLDER  
    • Constructor Summary

      Constructors 
      Constructor Description
      Maven()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.lang.String addFilesToClasspath​(java.lang.String classpath, java.io.File base)
      Adds files in base to classpath.
      private static java.lang.String addToClasspath​(java.lang.String classpath, java.lang.String path)
      Adds path to classpath.
      private static Set<FileArtifact> build​(Path root, java.lang.String buildFilePath, boolean updateSnapshots, java.lang.String[] targets)
      Executes a specific MAVEN build specification.
      private static void copyResourceToFile​(java.lang.String resource, java.io.File target)
      Copies a resource to a target file.
      private static java.lang.String getClasspath()
      ANT is a bit different regarding its class loader...
      private static EASyLoggerFactory.EASyLogger getLogger()
      Returns the logger instance.
      static Set<FileArtifact> maven​(Path root)
      Executes a specific MAVEN build specification with "clean" and "install" targets.
      static Set<FileArtifact> maven​(Path root, boolean updateSnapshots)
      Executes a specific MAVEN build specification with "clean" and "install" targets.
      static Set<FileArtifact> maven​(Path root, boolean updateSnapshots, Sequence<java.lang.String> buildtargets)
      Executes a specific MAVEN build specification.
      static Set<FileArtifact> maven​(Path root, java.lang.String buildFilePath)
      Executes a specific MAVEN build specification with "clean" and "install" targets.
      static Set<FileArtifact> maven​(Path root, java.lang.String buildFilePath, boolean updateSnapshots)
      Executes a specific MAVEN build specification with "clean" and "install" targets.
      static Set<FileArtifact> maven​(Path root, java.lang.String buildFilePath, boolean updateSnapshots, Sequence<java.lang.String> buildtargets)
      Executes a specific MAVEN build specification.
      static Set<FileArtifact> maven​(Path root, java.lang.String buildFilePath, Sequence<java.lang.String> buildtargets)
      Executes a specific MAVEN build specification.
      static Set<FileArtifact> maven​(Path root, Sequence<java.lang.String> buildtargets)
      Executes a specific MAVEN build specification.
      private static java.lang.String obtainProcessClasspath​(java.lang.ClassLoader contextClassLoader)
      Obtains the classpath for running Maven as a process.
      private static java.lang.String rewriteIfUnbundled​(java.lang.String classpath)
      In case that we have the standalone and a classpath that does not contain any (expected) maven library, take either MAVEN_HOME, the easy-headless or the first jar as location into account and add the contents of the library folder in this location.
      private static int runAsProcess​(java.lang.String buildFilePath, boolean updateSnapshots, java.lang.String[] targets)
      Runs Maven as a separate process.
      private static java.lang.String[] toTargets​(Sequence<java.lang.String> buildtargets)
      Turns the given targets into an array.
      private static java.io.File tryUnpack​(java.lang.String classpath)
      Tries to unpack the Maven libraries to tmpDirTMP_FOLDER by reading lib/dir.list.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • AS_PROCESS

        private static final boolean AS_PROCESS
      • MAVEN_HOME

        private static final java.lang.String MAVEN_HOME
      • CLASSPATH

        private static final java.lang.String CLASSPATH
      • CLASSPATH_EXCLUDE

        private static final java.lang.String CLASSPATH_EXCLUDE
    • Constructor Detail

      • Maven

        public Maven()
    • Method Detail

      • maven

        public static Set<FileArtifact> maven​(Path root)
                                       throws VilException
        Executes a specific MAVEN build specification with "clean" and "install" targets.
        Parameters:
        root - the root-path
        Returns:
        the created artifacts
        Throws:
        VilException - in case of artifact / parameter problems
      • maven

        public static Set<FileArtifact> maven​(Path root,
                                              boolean updateSnapshots)
                                       throws VilException
        Executes a specific MAVEN build specification with "clean" and "install" targets.
        Parameters:
        root - the root-path
        updateSnapshots - whether snapshots shall be updated
        Returns:
        the created artifacts
        Throws:
        VilException - in case of artifact / parameter problems
      • maven

        public static Set<FileArtifact> maven​(Path root,
                                              java.lang.String buildFilePath)
                                       throws VilException
        Executes a specific MAVEN build specification with "clean" and "install" targets.
        Parameters:
        root - the root-path
        buildFilePath - the path where the MAVEN file is located
        Returns:
        the created artifacts
        Throws:
        VilException - in case of artifact / parameter problems
      • maven

        public static Set<FileArtifact> maven​(Path root,
                                              java.lang.String buildFilePath,
                                              boolean updateSnapshots)
                                       throws VilException
        Executes a specific MAVEN build specification with "clean" and "install" targets.
        Parameters:
        root - the root-path
        updateSnapshots - whether snapshots shall be updated
        buildFilePath - the path where the MAVEN file is located
        Returns:
        the created artifacts
        Throws:
        VilException - in case of artifact / parameter problems
      • maven

        public static Set<FileArtifact> maven​(Path root,
                                              Sequence<java.lang.String> buildtargets)
                                       throws VilException
        Executes a specific MAVEN build specification.
        Parameters:
        root - the root-path
        buildtargets - the targets to be executed
        Returns:
        the created artifacts
        Throws:
        VilException - in case of artifact / parameter problems
      • maven

        public static Set<FileArtifact> maven​(Path root,
                                              boolean updateSnapshots,
                                              Sequence<java.lang.String> buildtargets)
                                       throws VilException
        Executes a specific MAVEN build specification.
        Parameters:
        root - the root-path
        updateSnapshots - whether snapshots shall be updated
        buildtargets - the targets to be executed
        Returns:
        the created artifacts
        Throws:
        VilException - in case of artifact / parameter problems
      • maven

        public static Set<FileArtifact> maven​(Path root,
                                              java.lang.String buildFilePath,
                                              Sequence<java.lang.String> buildtargets)
                                       throws VilException
        Executes a specific MAVEN build specification.
        Parameters:
        root - the root-path
        buildFilePath - the path where the MAVEN file is located
        buildtargets - the targets to be executed
        Returns:
        the created artifacts
        Throws:
        VilException - in case of artifact / parameter problems
      • maven

        public static Set<FileArtifact> maven​(Path root,
                                              java.lang.String buildFilePath,
                                              boolean updateSnapshots,
                                              Sequence<java.lang.String> buildtargets)
                                       throws VilException
        Executes a specific MAVEN build specification.
        Parameters:
        root - the root-path
        buildFilePath - the path where the MAVEN file is located
        updateSnapshots - whether snapshots shall be updated
        buildtargets - the targets to be executed
        Returns:
        the created artifacts
        Throws:
        VilException - in case of artifact / parameter problems
      • toTargets

        private static java.lang.String[] toTargets​(Sequence<java.lang.String> buildtargets)
        Turns the given targets into an array.
        Parameters:
        buildtargets - the targets as VIL sequence
        Returns:
        the targets as string array
      • build

        private static Set<FileArtifact> build​(Path root,
                                               java.lang.String buildFilePath,
                                               boolean updateSnapshots,
                                               java.lang.String[] targets)
                                        throws VilException
        Executes a specific MAVEN build specification.
        Parameters:
        root - the root-path
        buildFilePath - the path where the MAVEN file is located
        updateSnapshots - whether snapshots shall be updated (-U)
        targets - the targets to be executed
        Returns:
        the created artifacts
        Throws:
        VilException - in case of artifact / parameter problems
      • getClasspath

        private static java.lang.String getClasspath()
        ANT is a bit different regarding its class loader...
        Returns:
        the classpath if available
      • rewriteIfUnbundled

        private static java.lang.String rewriteIfUnbundled​(java.lang.String classpath)
        In case that we have the standalone and a classpath that does not contain any (expected) maven library, take either MAVEN_HOME, the easy-headless or the first jar as location into account and add the contents of the library folder in this location.
        Parameters:
        classpath - the classpath
        Returns:
        the rewritten classpath
      • tryUnpack

        private static java.io.File tryUnpack​(java.lang.String classpath)
        Tries to unpack the Maven libraries to tmpDirTMP_FOLDER by reading lib/dir.list.
        Parameters:
        classpath - the classpath (assuming a single entry) as fallback result
        Returns:
        the folder with the unpacked libraries or the fallback folder based on classpath
      • copyResourceToFile

        private static void copyResourceToFile​(java.lang.String resource,
                                               java.io.File target)
        Copies a resource to a target file.
        Parameters:
        resource - the resource
        target - the target file
      • addToClasspath

        private static java.lang.String addToClasspath​(java.lang.String classpath,
                                                       java.lang.String path)
        Adds path to classpath.
        Parameters:
        classpath - the classpath the path shall be added to
        path - the file be added
        Returns:
        the augmented classpath
      • addFilesToClasspath

        private static java.lang.String addFilesToClasspath​(java.lang.String classpath,
                                                            java.io.File base)
        Adds files in base to classpath.
        Parameters:
        classpath - the classpath the file names shall be added to
        base - the base file/folder to list the file names from
        Returns:
        the augmented classpath if files were found
      • runAsProcess

        private static int runAsProcess​(java.lang.String buildFilePath,
                                        boolean updateSnapshots,
                                        java.lang.String[] targets)
                                 throws java.io.IOException,
                                        java.lang.InterruptedException
        Runs Maven as a separate process. This might be needed to avoid unnecessary file locks caused by Maven.
        Parameters:
        buildFilePath - the path where the MAVEN file is located
        updateSnapshots - whether snapshots shall be updated (-U)
        targets - the targets to be executed
        Returns:
        the command line execution code of Maven
        Throws:
        java.io.IOException - in case that execution or process creation fails
        java.lang.InterruptedException - in case that the created process was interrupted
      • obtainProcessClasspath

        private static java.lang.String obtainProcessClasspath​(java.lang.ClassLoader contextClassLoader)
        Obtains the classpath for running Maven as a process.
        Parameters:
        contextClassLoader - the context class loader to obtain the classpath from if possible at all
        Returns:
        the classpath