Package io.fabric8.maven.docker
Class AbstractDockerMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- io.fabric8.maven.docker.AbstractDockerMojo
-
- All Implemented Interfaces:
ConfigHelper.Customizer,org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo,org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable
- Direct Known Subclasses:
AbstractBuildSupportMojo,CopyMojo,LogsMojo,PushMojo,RemoveMojo,SaveMojo,StartMojo,StopMojo,TagMojo,VolumeCreateMojo,VolumeRemoveMojo
public abstract class AbstractDockerMojo extends org.apache.maven.plugin.AbstractMojo implements org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable, ConfigHelper.Customizer
Base class for this plugin.- Since:
- 26.03.14
- Author:
- roland
-
-
Field Summary
Fields Modifier and Type Field Description protected StringautoPullstatic StringCONTEXT_KEY_BUILD_TIMESTAMPstatic StringCONTEXT_KEY_LOG_DISPATCHERstatic StringCONTEXT_KEY_START_CALLEDstatic StringDOCKER_BUILD_TIMESTAMPprotected DockerAccessFactorydockerAccessFactoryprotected org.apache.maven.plugin.MojoExecutionexecutionprotected ImageConfigResolverimageConfigResolverprotected StringimagePullPolicybooleanjibStringjibImageFormatprotected booleankeepContainerprotected LoggerlogStringoutputDirectoryprotected org.apache.maven.project.MavenProjectprojectprotected Stringregistryprotected booleanremoveVolumesprotected ServiceHubFactoryserviceHubFactoryprotected org.apache.maven.execution.MavenSessionsessionprotected org.apache.maven.settings.Settingssettingsprotected booleanskipExtendedAuthSkip extended authenticationStringsourceDirectoryprotected booleanuseColorprotected Stringverbose
-
Constructor Summary
Constructors Constructor Description AbstractDockerMojo()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidcontextualize(org.codehaus.plexus.context.Context context)List<ImageConfiguration>customizeConfig(List<ImageConfiguration> imageConfigs)voidexecute()Entry point for this plugin.protected abstract voidexecuteInternal(ServiceHub serviceHub)Hook for subclass for doing the real jobprotected DategetBuildTimestamp()Get the current build timestamp.protected FilegetBuildTimestampFile()protected MatchergetContainerNameMatcher(String pattern, String configName)protected List<Container>getContainersForPattern(QueryService queryService, boolean all, Matcher imageNameMatcher, Matcher containerNameMatcher, String patternConfigName)protected DockerAccessFactory.DockerAccessContextgetDockerAccessContext()protected GavLabelgetGavLabel()protected MatchergetImageNameMatcher(String pattern, String configName)ImagePullManagergetImagePullManager(String imagePullPolicy, String autoPull)protected LogDispatchergetLogDispatcher(ServiceHub hub)protected StringgetLogPrefix()Log prefix to use when doing the logsprotected DategetReferenceDate()protected RegistryService.RegistryConfiggetRegistryConfig(String specificRegistry)protected List<ImageConfiguration>getResolvedImages()Get all images to use.protected List<VolumeConfiguration>getVolumes()Get all volumes which are defined separately from the imagesprotected booleaninvokedTogetherWithDockerStart()protected booleanisDockerAccessRequired()Override this if your mojo doesnt require access to a Docker host (like creating and attaching docker tar archives)protected voidpullImage(QueryService queryService, RegistryService registryService, ImageConfiguration imageConfig, String pullRegistry)
-
-
-
Field Detail
-
CONTEXT_KEY_START_CALLED
public static final String CONTEXT_KEY_START_CALLED
- See Also:
- Constant Field Values
-
CONTEXT_KEY_LOG_DISPATCHER
public static final String CONTEXT_KEY_LOG_DISPATCHER
- See Also:
- Constant Field Values
-
CONTEXT_KEY_BUILD_TIMESTAMP
public static final String CONTEXT_KEY_BUILD_TIMESTAMP
- See Also:
- Constant Field Values
-
DOCKER_BUILD_TIMESTAMP
public static final String DOCKER_BUILD_TIMESTAMP
- See Also:
- Constant Field Values
-
project
@Parameter(defaultValue="${project}", readonly=true) protected org.apache.maven.project.MavenProject project
-
settings
@Parameter(defaultValue="${settings}", readonly=true) protected org.apache.maven.settings.Settings settings
-
session
@Parameter(property="session") protected org.apache.maven.execution.MavenSession session
-
execution
@Parameter(property="mojoExecution") protected org.apache.maven.plugin.MojoExecution execution
-
imageConfigResolver
@Component protected ImageConfigResolver imageConfigResolver
-
serviceHubFactory
@Component protected ServiceHubFactory serviceHubFactory
-
dockerAccessFactory
@Component protected DockerAccessFactory dockerAccessFactory
-
autoPull
@Parameter(property="docker.autoPull") protected String autoPull
-
imagePullPolicy
@Parameter(property="docker.imagePullPolicy") protected String imagePullPolicy
-
keepContainer
@Parameter(property="docker.keepContainer", defaultValue="false") protected boolean keepContainer
-
removeVolumes
@Parameter(property="docker.removeVolumes", defaultValue="false") protected boolean removeVolumes
-
useColor
@Parameter(property="docker.useColor", defaultValue="true") protected boolean useColor
-
verbose
@Parameter(property="docker.verbose") protected String verbose
-
registry
@Parameter(property="docker.registry") protected String registry
-
skipExtendedAuth
@Parameter(property="docker.skip.extendedAuth", defaultValue="false") protected boolean skipExtendedAuthSkip extended authentication
-
jib
@Parameter(property="docker.build.jib", defaultValue="false") public boolean jib
-
jibImageFormat
@Parameter(property="docker.build.jib.imageFormat", defaultValue="docker") public String jibImageFormat
-
sourceDirectory
@Parameter(property="docker.source.dir", defaultValue="src/main/docker") public String sourceDirectory
-
outputDirectory
@Parameter(property="docker.target.dir", defaultValue="target/docker") public String outputDirectory
-
log
protected Logger log
-
-
Method Detail
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureExceptionEntry point for this plugin. It will set up the helper class and then callsexecuteInternal(ServiceHub)which must be implemented by subclass.- Specified by:
executein interfaceorg.apache.maven.plugin.Mojo- Throws:
org.apache.maven.plugin.MojoExecutionExceptionorg.apache.maven.plugin.MojoFailureException
-
getDockerAccessContext
protected DockerAccessFactory.DockerAccessContext getDockerAccessContext()
-
getRegistryConfig
protected RegistryService.RegistryConfig getRegistryConfig(String specificRegistry) throws org.apache.maven.plugin.MojoExecutionException
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
getBuildTimestamp
protected Date getBuildTimestamp() throws IOException
Get the current build timestamp. this has either already been created by a previous call or a new current date is created- Returns:
- timestamp to use
- Throws:
IOException
-
getReferenceDate
protected Date getReferenceDate() throws IOException
- Throws:
IOException
-
getBuildTimestampFile
protected File getBuildTimestampFile()
-
getLogPrefix
protected String getLogPrefix()
Log prefix to use when doing the logs- Returns:
-
customizeConfig
public List<ImageConfiguration> customizeConfig(List<ImageConfiguration> imageConfigs)
- Specified by:
customizeConfigin interfaceConfigHelper.Customizer
-
isDockerAccessRequired
protected boolean isDockerAccessRequired()
Override this if your mojo doesnt require access to a Docker host (like creating and attaching docker tar archives)- Returns:
trueas the default value
-
executeInternal
protected abstract void executeInternal(ServiceHub serviceHub) throws IOException, ExecException, org.apache.maven.plugin.MojoExecutionException
Hook for subclass for doing the real job- Parameters:
serviceHub- context for accessing backends- Throws:
IOExceptionExecExceptionorg.apache.maven.plugin.MojoExecutionException
-
getResolvedImages
protected List<ImageConfiguration> getResolvedImages()
Get all images to use. Can be restricted via -Ddocker.filter to pick a one or more images. The values are taken as comma separated list.- Returns:
- list of image configuration to be use. Can be empty but never null.
-
getVolumes
protected List<VolumeConfiguration> getVolumes()
Get all volumes which are defined separately from the images- Returns:
- defined volumes
-
contextualize
public void contextualize(org.codehaus.plexus.context.Context context) throws org.codehaus.plexus.context.ContextException- Specified by:
contextualizein interfaceorg.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable- Throws:
org.codehaus.plexus.context.ContextException
-
getGavLabel
protected GavLabel getGavLabel()
-
getLogDispatcher
protected LogDispatcher getLogDispatcher(ServiceHub hub)
-
getImagePullManager
public ImagePullManager getImagePullManager(String imagePullPolicy, String autoPull)
-
invokedTogetherWithDockerStart
protected boolean invokedTogetherWithDockerStart()
-
getImageNameMatcher
protected Matcher getImageNameMatcher(String pattern, String configName) throws org.apache.maven.plugin.MojoExecutionException
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
getContainerNameMatcher
protected Matcher getContainerNameMatcher(String pattern, String configName) throws org.apache.maven.plugin.MojoExecutionException
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
getContainersForPattern
protected List<Container> getContainersForPattern(QueryService queryService, boolean all, Matcher imageNameMatcher, Matcher containerNameMatcher, String patternConfigName) throws IOException
- Throws:
IOException
-
pullImage
protected void pullImage(QueryService queryService, RegistryService registryService, ImageConfiguration imageConfig, String pullRegistry) throws org.apache.maven.plugin.MojoExecutionException, DockerAccessException
- Throws:
org.apache.maven.plugin.MojoExecutionExceptionDockerAccessException
-
-