Class AbstractJLinkMojo

java.lang.Object
org.apache.maven.plugin.AbstractMojo
org.tentackle.maven.AbstractTentackleMojo
org.tentackle.maven.plugin.jlink.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 AbstractTentackleMojo
Base class for all mojos of the tentackle-jlink-maven-plugin.
Author:
harald
  • Field Details

    • DEST_CLASSPATH

      public static final String DEST_CLASSPATH
      Name of the destination subfolder containing the classpath artifacts.
      See Also:
    • DEST_MODULEPATH

      public static final String DEST_MODULEPATH
      Name of the destination subfolder containing the modulepath artifacts.
      See Also:
    • DEST_RESOURCES

      public static final String DEST_RESOURCES
      Name of the destination subfolder containing the resources.
      See Also:
    • ZIP_EXTENSION

      public static final String ZIP_EXTENSION
      File extension for ZIP files.
      See Also:
  • Constructor Details

    • AbstractJLinkMojo

      public AbstractJLinkMojo()
  • Method Details

    • getFinalName

      public 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 to mp folder
    • isModulePathOnly

      public boolean isModulePathOnly(String moduleName)
      Returns whether given module name should go to the module path and not the jimage file.
      Parameters:
      moduleName - the name of the full-blown module
      Returns:
      true if forced to mp folder
    • getZipDirectory

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

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

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

      public 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 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 File getJdepsTool()
      Gets the jdeps tool.
      Returns:
      the file, never null
    • getAddModules

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

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

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

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

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

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

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

      public 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 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 AbstractTentackleMojo
      Throws:
      org.apache.maven.plugin.MojoExecutionException
      org.apache.maven.plugin.MojoFailureException
    • getClassifier

      public 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 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 File createZipFile(File dir, 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 AbstractTentackleMojo
      Throws:
      org.apache.maven.plugin.MojoExecutionException
    • installTemplate

      protected void installTemplate(String pluginTemplate, 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