Package org.tentackle.maven.plugin.jlink
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 thetentackle-jlink-maven-plugin.- Author:
- harald
-
-
Field Summary
Fields Modifier and Type Field Description static StringDEST_CLASSPATHName of the destination subfolder containing the classpath artifacts.static StringDEST_MODULEPATHName of the destination subfolder containing the modulepath artifacts.static StringDEST_RESOURCESName of the destination subfolder containing the resources.static StringZIP_EXTENSIONFile extension for ZIP files.-
Fields inherited from class org.tentackle.maven.AbstractTentackleMojo
charset, JDK_TOOLCHAIN, minLogLevel, resourceDirs, verbosity, verbosityLevel
-
-
Constructor Summary
Constructors Constructor Description AbstractJLinkMojo()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidcopyArtifacts(JLinkResolver.Result result)Copies artifacts not already in the created jlink image to module- or classpath.protected voidcopyExtraDirectories()Copies optional extra directories to the image directory.protected voidcopyResources(JLinkResolver.Result result)Copies the resources to theconfdirectory.protected voidcreateImage(JLinkResolver.Result result)Invokes the jlink tool and copies other artifacts and resources.protected voidcreateJLinkImage(JLinkResolver.Result result)Creates the jlink image.FilecreateZipFile(File dir, String name)Creates the zip file.
Invoked by theArtifactCreator.voidexecuteImpl()protected abstract voidgenerateFiles(JLinkResolver.Result result)Generates additional files such as shell scripts or command files.List<String>getAddModules()Gets extra jre or jdk modules to add to the image.StringgetClassifier()The zip file will be installed and deployed with an additional classifier showing the operating system and the platform.List<String>getExcludeModules()Gets the modules to exclude.StringgetExtraClassifier()Gets the optional extra deployment classifier.List<String>getExtraClasspathElements()Gets optional extra classpath elements.List<File>getExtraDirectories()Extra directories to copy to the image.StringgetFinalName()Gets the ZIP file's name without extension.
Invoked by theArtifactCreator.FilegetImageDirectory()Gets the directory created by jlink holding the image.StringgetImagePathPrefix()Gets the prefix to the jars and dirs in the runtime image.intgetJavaMajorRuntimeVersion()Gets the java major runtime version as a comparable integer.StringgetJavaRuntimeVersion()Gets the java runtime version used by the application.FilegetJdepsTool()Gets the jdeps tool.org.codehaus.plexus.languages.java.jpms.LocationManagergetLocationManager()Gets the location manager to extract module information.StringgetMainClass()Gets the name of the main class.StringgetMainModule()Gets the name of the module holding the main class.org.apache.maven.project.MavenProjectHelpergetProjectHelper()Gets the project helper to attach artifacts.FilegetTemplateDir()Gets the template directory.Map<String,Object>getVariables()Gets the extra variables for templates or artifact generation.StringgetVariablesPrecedence()Gets the order how properties and variables override each other.FilegetZipDirectory()Gets the directory where to store the ZIP-file.protected voidinstallTemplate(String pluginTemplate, String projectTemplate, boolean overwrite)Installs the template with the given name.protected abstract voidinstallTemplates(boolean overwrite)Copies the templates to the template directory.booleanisClasspathDependency(org.apache.maven.artifact.Artifact artifact)Returns whether an artifact should be moved to the classpath explicitly.booleanisModulePathOnly()Returns whether all application modules should go to the module path and not the jimage file.booleanisModulePathOnly(String moduleName)Returns whether given mudule name should go to the module path and not the jimage file.booleanisWithUpdater()Returns whether the update feature is enabled.protected voidlogToolOutput(org.tentackle.common.ToolRunner runner)Logs the toolrunner's output at info level.voidprepareExecute()protected booleanvalidate()-
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
-
-
-
-
Field Detail
-
DEST_CLASSPATH
public static final String DEST_CLASSPATH
Name of the destination subfolder containing the classpath artifacts.- See Also:
- Constant Field Values
-
DEST_MODULEPATH
public static final String DEST_MODULEPATH
Name of the destination subfolder containing the modulepath artifacts.- See Also:
- Constant Field Values
-
DEST_RESOURCES
public static final String DEST_RESOURCES
Name of the destination subfolder containing the resources.- See Also:
- Constant Field Values
-
ZIP_EXTENSION
public static final String ZIP_EXTENSION
File extension for ZIP files.- See Also:
- Constant Field Values
-
-
Method Detail
-
getFinalName
public String getFinalName()
Gets the ZIP file's name without extension.
Invoked by theArtifactCreator.- 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 mudule 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:
prepareExecutein classAbstractTentackleMojo- Throws:
org.apache.maven.plugin.MojoExecutionExceptionorg.apache.maven.plugin.MojoFailureException
-
executeImpl
public void executeImpl() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException- Specified by:
executeImplin classAbstractTentackleMojo- Throws:
org.apache.maven.plugin.MojoExecutionExceptionorg.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 theArtifactCreator.- Parameters:
dir- the directory to create a zip file fromname- 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.MojoExecutionExceptionCopies 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.MojoFailureExceptionorg.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 failedorg.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 theconfdirectory.- Parameters:
result- the resolver info- Throws:
org.apache.maven.plugin.MojoExecutionException- if copy failed
-
copyExtraDirectories
protected void copyExtraDirectories() throws org.apache.maven.plugin.MojoExecutionExceptionCopies 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:
validatein classAbstractTentackleMojo- 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 templateprojectTemplate- the project's name of the templateoverwrite- 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.MojoExecutionExceptionLogs the toolrunner's output at info level.- Parameters:
runner- the toolrunner- Throws:
org.apache.maven.plugin.MojoExecutionException- if runner not invoked so far
-
-