Class AbstractJLinkMojo

  • All Implemented Interfaces:
    org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
    Direct Known Subclasses:
    InitMojo, JLinkMojo, JPackageMojo

    public abstract class AbstractJLinkMojo
    extends org.tentackle.maven.AbstractTentackleMojo
    Base class for all mojos of the tentackle-jlink-maven-plugin.
    Author:
    harald
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String DEST_CLASSPATH
      Name of the destination subfolder containing the classpath artifacts.
      static java.lang.String DEST_MODULEPATH
      Name of the destination subfolder containing the modulepath artifacts.
      static java.lang.String DEST_RESOURCES
      Name of the destination subfolder containing the resources.
      static java.lang.String ZIP_EXTENSION
      File extension for ZIP files.
      • Fields inherited from class org.tentackle.maven.AbstractTentackleMojo

        charset, JDK_TOOLCHAIN, minLogLevel, resourceDirs, verbosity, verbosityLevel
      • Fields inherited from interface org.apache.maven.plugin.Mojo

        ROLE
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void copyArtifacts​(JLinkResolver.Result result)
      Copies artifacts not already in the created jlink image to module- or classpath.
      protected void copyExtraDirectories()
      Copies optional extra directories to the image directory.
      protected void copyResources​(JLinkResolver.Result result)
      Copies the resources to the conf directory.
      protected void createImage​(JLinkResolver.Result result)
      Invokes the jlink tool and copies other artifacts and resources.
      protected void createJLinkImage​(JLinkResolver.Result result)
      Creates the jlink image.
      java.io.File createZipFile​(java.io.File dir, java.lang.String name)
      Creates the zip file.
      Invoked by the ArtifactCreator.
      void executeImpl()  
      protected abstract void generateFiles​(JLinkResolver.Result result)
      Generates additional files such as shell scripts or command files.
      java.util.List<java.lang.String> getAddModules()
      Gets extra jre or jdk modules to add to the image.
      java.lang.String getClassifier()
      The zip file will be installed and deployed with an additional classifier showing the operating system and the platform.
      java.util.List<java.lang.String> getExcludeModules()
      Gets the modules to exclude.
      java.lang.String getExtraClassifier()
      Gets the optional extra deployment classifier.
      java.util.List<java.lang.String> getExtraClasspathElements()
      Gets optional extra classpath elements.
      java.util.List<java.io.File> getExtraDirectories()
      Extra directories to copy to the image.
      java.lang.String getFinalName()
      Gets the ZIP file's name without extension.
      Invoked by the ArtifactCreator.
      java.io.File getImageDirectory()
      Gets the directory created by jlink holding the image.
      java.lang.String getImagePathPrefix()
      Gets the prefix to the jars and dirs in the runtime image.
      int getJavaMajorRuntimeVersion()
      Gets the java major runtime version as a comparable integer.
      java.lang.String getJavaRuntimeVersion()
      Gets the java runtime version used by the application.
      java.io.File getJdepsTool()
      Gets the jdeps tool.
      org.codehaus.plexus.languages.java.jpms.LocationManager getLocationManager()
      Gets the location manager to extract module information.
      java.lang.String getMainClass()
      Gets the name of the main class.
      java.lang.String getMainModule()
      Gets the name of the module holding the main class.
      org.apache.maven.project.MavenProjectHelper getProjectHelper()
      Gets the project helper to attach artifacts.
      java.io.File getTemplateDir()
      Gets the template directory.
      java.util.Map<java.lang.String,​java.lang.Object> getVariables()
      Gets the extra variables for templates or artifact generation.
      java.lang.String getVariablesPrecedence()
      Gets the order how properties and variables override each other.
      java.io.File getZipDirectory()
      Gets the directory where to store the ZIP-file.
      protected void installTemplate​(java.lang.String pluginTemplate, java.lang.String projectTemplate, boolean overwrite)
      Installs the template with the given name.
      protected abstract void installTemplates​(boolean overwrite)
      Copies the templates to the template directory.
      boolean isClasspathDependency​(org.apache.maven.artifact.Artifact artifact)
      Returns whether an artifact should be moved to the classpath explicitly.
      boolean isModulePathOnly()
      Returns whether all application modules should go to the module path and not the jimage file.
      boolean isWithUpdater()
      Returns whether the update feature is enabled.
      protected void logToolOutput​(org.tentackle.common.ToolRunner runner)
      Logs the toolrunner's output at info level.
      void prepareExecute()  
      protected boolean validate()  
      • Methods inherited from class org.tentackle.maven.AbstractTentackleMojo

        createPackageMap, determineEncoding, determineJavaToolVersion, determineVerbosity, execute, findResourceDirs, finishExecute, getCanonicalPath, getHostName, getMajorVersion, getMavenProject, getMavenSession, getMojoExecution, getPathRelativeToBasedir, getResourceDirName, getSettings, getSettingsDecrypter, getToolchain, getToolchain, getToolchain, getToolchainManager, getToolFinder, installJavaLoggingHandler, isExecutionRecursive, isSkippedByDefault, loadResourceFileIntoString
      • Methods inherited from class org.apache.maven.plugin.AbstractMojo

        getLog, getPluginContext, setLog, setPluginContext
      • Methods inherited from class java.lang.Object

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

      • DEST_CLASSPATH

        public static final java.lang.String DEST_CLASSPATH
        Name of the destination subfolder containing the classpath artifacts.
        See Also:
        Constant Field Values
      • DEST_MODULEPATH

        public static final java.lang.String DEST_MODULEPATH
        Name of the destination subfolder containing the modulepath artifacts.
        See Also:
        Constant Field Values
      • DEST_RESOURCES

        public static final java.lang.String DEST_RESOURCES
        Name of the destination subfolder containing the resources.
        See Also:
        Constant Field Values
      • ZIP_EXTENSION

        public static final java.lang.String ZIP_EXTENSION
        File extension for ZIP files.
        See Also:
        Constant Field Values
    • Constructor Detail

      • AbstractJLinkMojo

        public AbstractJLinkMojo()
    • Method Detail

      • getFinalName

        public java.lang.String getFinalName()
        Gets the ZIP file's name without extension.
        Invoked by the ArtifactCreator.
        Returns:
        the final name
      • isWithUpdater

        public boolean isWithUpdater()
        Returns whether the update feature is enabled.
        Returns:
        true if generate artifacts with auto-update feature
      • isModulePathOnly

        public boolean isModulePathOnly()
        Returns whether all application modules should go to the module path and not the jimage file.
        Returns:
        true if forced
      • getZipDirectory

        public java.io.File getZipDirectory()
        Gets the directory where to store the ZIP-file.
        Returns:
        the ZIP target folder
      • getTemplateDir

        public java.io.File getTemplateDir()
        Gets the template directory.
        Returns:
        the directory holding the wizard templates
      • getImageDirectory

        public java.io.File getImageDirectory()
        Gets the directory created by jlink holding the image.
        Returns:
        the image dir, never null
      • getMainModule

        public java.lang.String getMainModule()
        Gets the name of the module holding the main class.
        Returns:
        the main module, null or empty string to build an application running on the classpath
      • getMainClass

        public java.lang.String getMainClass()
        Gets the name of the main class.
        Returns:
        the main class, never null
      • getLocationManager

        public org.codehaus.plexus.languages.java.jpms.LocationManager getLocationManager()
        Gets the location manager to extract module information.
        Returns:
        the JPMS manager
      • getProjectHelper

        public org.apache.maven.project.MavenProjectHelper getProjectHelper()
        Gets the project helper to attach artifacts.
        Returns:
        the project helper
      • getJdepsTool

        public java.io.File getJdepsTool()
        Gets the jdeps tool.
        Returns:
        the file, never null
      • getAddModules

        public java.util.List<java.lang.String> getAddModules()
        Gets extra jre or jdk modules to add to the image.
        Returns:
        extra module names, never null
      • getExcludeModules

        public java.util.List<java.lang.String> getExcludeModules()
        Gets the modules to exclude.
        Returns:
        excluded module names, never null
      • getVariables

        public java.util.Map<java.lang.String,​java.lang.Object> getVariables()
        Gets the extra variables for templates or artifact generation.
        Returns:
        the variables, never null
      • getVariablesPrecedence

        public java.lang.String getVariablesPrecedence()
        Gets the order how properties and variables override each other.
        Returns:
        default is system, maven, variables
      • getExtraClassifier

        public java.lang.String getExtraClassifier()
        Gets the optional extra deployment classifier.
        Returns:
        the extra classifier
      • getExtraClasspathElements

        public java.util.List<java.lang.String> getExtraClasspathElements()
        Gets optional extra classpath elements.
        Returns:
        pathnames relative to the image root, null if none
      • getExtraDirectories

        public java.util.List<java.io.File> getExtraDirectories()
        Extra directories to copy to the image.
        Returns:
        the directories, null if none
      • getJavaRuntimeVersion

        public java.lang.String getJavaRuntimeVersion()
        Gets the java runtime version used by the application.
        Returns:
        the java version
      • getJavaMajorRuntimeVersion

        public int getJavaMajorRuntimeVersion()
        Gets the java major runtime version as a comparable integer.
        Returns:
        the major version
      • prepareExecute

        public void prepareExecute()
                            throws org.apache.maven.plugin.MojoExecutionException,
                                   org.apache.maven.plugin.MojoFailureException
        Overrides:
        prepareExecute in class org.tentackle.maven.AbstractTentackleMojo
        Throws:
        org.apache.maven.plugin.MojoExecutionException
        org.apache.maven.plugin.MojoFailureException
      • executeImpl

        public void executeImpl()
                         throws org.apache.maven.plugin.MojoExecutionException,
                                org.apache.maven.plugin.MojoFailureException
        Specified by:
        executeImpl in class org.tentackle.maven.AbstractTentackleMojo
        Throws:
        org.apache.maven.plugin.MojoExecutionException
        org.apache.maven.plugin.MojoFailureException
      • getClassifier

        public java.lang.String getClassifier()
                                       throws org.apache.maven.plugin.MojoExecutionException
        The zip file will be installed and deployed with an additional classifier showing the operating system and the platform.
        Returns:
        the classifier
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if no os.name
      • getImagePathPrefix

        public java.lang.String getImagePathPrefix()
        Gets the prefix to the jars and dirs in the runtime image.
        Returns:
        the prefix, empty string if none (never null)
      • createZipFile

        public java.io.File createZipFile​(java.io.File dir,
                                          java.lang.String name)
                                   throws org.apache.maven.plugin.MojoExecutionException
        Creates the zip file.
        Invoked by the ArtifactCreator.
        Parameters:
        dir - the directory to create a zip file from
        name - the zip filename without extension
        Returns:
        the created zip file
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if some archiver or IO errors occurred
      • isClasspathDependency

        public boolean isClasspathDependency​(org.apache.maven.artifact.Artifact artifact)
        Returns whether an artifact should be moved to the classpath explicitly.
        Parameters:
        artifact - the artifact
        Returns:
        true if move to classpath, else modulepath
      • generateFiles

        protected abstract void generateFiles​(JLinkResolver.Result result)
                                       throws org.apache.maven.plugin.MojoExecutionException
        Generates additional files such as shell scripts or command files.
        Parameters:
        result - the resolver result
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if generation failed
      • installTemplates

        protected abstract void installTemplates​(boolean overwrite)
                                          throws org.apache.maven.plugin.MojoExecutionException
        Copies the templates to the template directory.
        Parameters:
        overwrite - true if overwrite existing templates, false if install only missing
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if installation failed
      • createImage

        protected void createImage​(JLinkResolver.Result result)
                            throws org.apache.maven.plugin.MojoFailureException,
                                   org.apache.maven.plugin.MojoExecutionException
        Invokes the jlink tool and copies other artifacts and resources.
        Parameters:
        result - the resolver result
        Throws:
        org.apache.maven.plugin.MojoFailureException
        org.apache.maven.plugin.MojoExecutionException
      • createJLinkImage

        protected void createJLinkImage​(JLinkResolver.Result result)
                                 throws org.apache.maven.plugin.MojoExecutionException,
                                        org.apache.maven.plugin.MojoFailureException
        Creates the jlink image.
        Parameters:
        result - the resolver info
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if building the JPMS info failed
        org.apache.maven.plugin.MojoFailureException - if jlink returned an error code
      • copyArtifacts

        protected void copyArtifacts​(JLinkResolver.Result result)
                              throws org.apache.maven.plugin.MojoExecutionException
        Copies artifacts not already in the created jlink image to module- or classpath.
        Parameters:
        result - the resolver info
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if copy failed
      • copyResources

        protected void copyResources​(JLinkResolver.Result result)
                              throws org.apache.maven.plugin.MojoExecutionException
        Copies the resources to the conf directory.
        Parameters:
        result - the resolver info
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if copy failed
      • copyExtraDirectories

        protected void copyExtraDirectories()
                                     throws org.apache.maven.plugin.MojoExecutionException
        Copies optional extra directories to the image directory.
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if failed
      • validate

        protected boolean validate()
                            throws org.apache.maven.plugin.MojoExecutionException
        Overrides:
        validate in class org.tentackle.maven.AbstractTentackleMojo
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • installTemplate

        protected void installTemplate​(java.lang.String pluginTemplate,
                                       java.lang.String projectTemplate,
                                       boolean overwrite)
                                throws org.apache.maven.plugin.MojoExecutionException
        Installs the template with the given name.
        Parameters:
        pluginTemplate - the plugin's name of the template
        projectTemplate - the project's name of the template
        overwrite - true if overwrite existing template, false if leave unchanged
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if installation failed
      • logToolOutput

        protected void logToolOutput​(org.tentackle.common.ToolRunner runner)
                              throws org.apache.maven.plugin.MojoExecutionException
        Logs the toolrunner's output at info level.
        Parameters:
        runner - the toolrunner
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if runner not invoked so far