Class AbstractWarPackagingTask
- java.lang.Object
-
- org.apache.maven.plugins.war.packaging.AbstractWarPackagingTask
-
- All Implemented Interfaces:
WarPackagingTask
- Direct Known Subclasses:
ArtifactsPackagingTask
,ClassesPackagingTask
,CopyUserManifestTask
,OverlayPackagingTask
,WarProjectPackagingTask
public abstract class AbstractWarPackagingTask extends java.lang.Object implements WarPackagingTask
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CLASSES_PATH
Theclasses
path.static java.lang.String[]
DEFAULT_INCLUDES
The default list of includes.static java.lang.String
LIB_PATH
Thelib
path.static java.lang.String
META_INF_PATH
TheMETA-INF
path.static java.lang.String
WEB_INF_PATH
TheWEB-INF
path.
-
Constructor Summary
Constructors Constructor Description AbstractWarPackagingTask()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
copyFile(java.lang.String sourceId, WarPackagingContext context, java.io.File file, java.lang.String targetFilename)
Copy the specified file if the target location has not yet already been used.protected boolean
copyFile(WarPackagingContext context, java.io.File source, java.io.File destination, java.lang.String targetFilename, boolean onlyIfModified)
Copy file from source to destination.protected void
copyFiles(java.lang.String sourceId, WarPackagingContext context, java.io.File sourceBaseDir, PathSet sourceFilesSet, boolean filtered)
Copies the files if possible as is.protected void
copyFiles(java.lang.String sourceId, WarPackagingContext context, java.io.File sourceBaseDir, PathSet sourceFilesSet, java.lang.String targetPrefix, boolean filtered)
Copies the files if possible with an optional target prefix.protected boolean
copyFilteredFile(java.lang.String sourceId, WarPackagingContext context, java.io.File file, java.lang.String targetFilename)
Copy the specified file if the target location has not yet already been used and filter its content with the configured filter properties.protected void
doUnpack(WarPackagingContext context, java.io.File file, java.io.File unpackDirectory)
Unpacks the specified file to the specified directory.protected java.lang.String
getArtifactFinalName(WarPackagingContext context, org.apache.maven.artifact.Artifact artifact)
Returns the final name of the specified artifact.protected java.lang.String
getEncoding(java.io.File webXml)
Get the encoding from an XML-file.protected PathSet
getFilesToIncludes(java.io.File baseDir, java.lang.String[] includes, java.lang.String[] excludes)
Returns the file to copy.protected PathSet
getFilesToIncludes(java.io.File baseDir, java.lang.String[] includes, java.lang.String[] excludes, boolean includeDirectories)
Returns the file to copy.private boolean
isFileOfType(java.io.File file, java.lang.String extension)
Determine whether a file is of a certain type, by looking at the file extension.private boolean
isPropertiesFile(java.io.File file)
Determine whether a file is a properties file or not.private boolean
isXmlFile(java.io.File file)
Returnstrue
if theFile
-object is a file (not a directory) that is notnull
and has a file name that ends in ".xml".-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.maven.plugins.war.packaging.WarPackagingTask
performPackaging
-
-
-
-
Field Detail
-
DEFAULT_INCLUDES
public static final java.lang.String[] DEFAULT_INCLUDES
The default list of includes.
-
WEB_INF_PATH
public static final java.lang.String WEB_INF_PATH
TheWEB-INF
path.- See Also:
- Constant Field Values
-
META_INF_PATH
public static final java.lang.String META_INF_PATH
TheMETA-INF
path.- See Also:
- Constant Field Values
-
CLASSES_PATH
public static final java.lang.String CLASSES_PATH
Theclasses
path.- See Also:
- Constant Field Values
-
LIB_PATH
public static final java.lang.String LIB_PATH
Thelib
path.- See Also:
- Constant Field Values
-
-
Method Detail
-
copyFiles
protected void copyFiles(java.lang.String sourceId, WarPackagingContext context, java.io.File sourceBaseDir, PathSet sourceFilesSet, java.lang.String targetPrefix, boolean filtered) throws java.io.IOException, org.apache.maven.plugin.MojoExecutionException
Copies the files if possible with an optional target prefix. Copy uses a first-win strategy: files that have already been copied by previous tasks are ignored. This method makes sure to update the list of protected files which gives the list of files that have already been copied. If the structure of the source directory is not the same as the root of the webapp, use thetargetPrefix
parameter to specify in which particular directory the files should be copied. Usenull
to copy the files with the same structure- Parameters:
sourceId
- the source idcontext
- the context to usesourceBaseDir
- the base directory from which thesourceFilesSet
will be copiedsourceFilesSet
- the files to be copiedtargetPrefix
- the prefix to add to the target file namefiltered
- filter or not.- Throws:
java.io.IOException
- if an error occurred while copying the filesorg.apache.maven.plugin.MojoExecutionException
- if an error occurs.
-
copyFiles
protected void copyFiles(java.lang.String sourceId, WarPackagingContext context, java.io.File sourceBaseDir, PathSet sourceFilesSet, boolean filtered) throws java.io.IOException, org.apache.maven.plugin.MojoExecutionException
Copies the files if possible as is. Copy uses a first-win strategy: files that have already been copied by previous tasks are ignored. This method makes sure to update the list of protected files which gives the list of files that have already been copied.- Parameters:
sourceId
- the source idcontext
- the context to usesourceBaseDir
- the base directory from which thesourceFilesSet
will be copiedsourceFilesSet
- the files to be copiedfiltered
- filter or not.- Throws:
java.io.IOException
- if an error occurred while copying the filesorg.apache.maven.plugin.MojoExecutionException
- break the build.
-
copyFile
protected void copyFile(java.lang.String sourceId, WarPackagingContext context, java.io.File file, java.lang.String targetFilename) throws java.io.IOException
Copy the specified file if the target location has not yet already been used. ThetargetFileName
is the relative path according to the root of the generated web application.- Parameters:
sourceId
- the source idcontext
- the context to usefile
- the file to copytargetFilename
- the relative path according to the root of the webapp- Throws:
java.io.IOException
- if an error occurred while copying
-
copyFilteredFile
protected boolean copyFilteredFile(java.lang.String sourceId, WarPackagingContext context, java.io.File file, java.lang.String targetFilename) throws java.io.IOException, org.apache.maven.plugin.MojoExecutionException
Copy the specified file if the target location has not yet already been used and filter its content with the configured filter properties. ThetargetFileName
is the relative path according to the root of the generated web application.- Parameters:
sourceId
- the source idcontext
- the context to usefile
- the file to copytargetFilename
- the relative path according to the root of the webapp- Returns:
- true if the file has been copied, false otherwise
- Throws:
java.io.IOException
- if an error occurred while copyingorg.apache.maven.plugin.MojoExecutionException
- if an error occurred while retrieving the filter properties
-
doUnpack
protected void doUnpack(WarPackagingContext context, java.io.File file, java.io.File unpackDirectory) throws org.apache.maven.plugin.MojoExecutionException
Unpacks the specified file to the specified directory.- Parameters:
context
- the packaging contextfile
- the file to unpackunpackDirectory
- the directory to use for th unpacked file- Throws:
org.apache.maven.plugin.MojoExecutionException
- if an error occurred while unpacking the file
-
copyFile
protected boolean copyFile(WarPackagingContext context, java.io.File source, java.io.File destination, java.lang.String targetFilename, boolean onlyIfModified) throws java.io.IOException
Copy file from source to destination. The directories up todestination
will be created if they don't already exist. if theonlyIfModified
flag isfalse
,destination
will be overwritten if it already exists. If the flag istrue
destination will be overwritten if it's not up to date.- Parameters:
context
- the packaging contextsource
- an existing non-directoryFile
to copy bytes fromdestination
- a non-directoryFile
to write bytes to (possibly overwriting).targetFilename
- the relative path of the file from the webapp root directoryonlyIfModified
- if true, copy the file only if the source has changed, always copy otherwise- Returns:
- true if the file has been copied/updated, false otherwise
- Throws:
java.io.IOException
- ifsource
does not exist,destination
cannot be written to, or an IO error occurs during copying
-
getEncoding
protected java.lang.String getEncoding(java.io.File webXml) throws java.io.IOException
Get the encoding from an XML-file.- Parameters:
webXml
- the XML-file- Returns:
- The encoding of the XML-file, or UTF-8 if it's not specified in the file
- Throws:
java.io.IOException
- if an error occurred while reading the file
-
getFilesToIncludes
protected PathSet getFilesToIncludes(java.io.File baseDir, java.lang.String[] includes, java.lang.String[] excludes)
Returns the file to copy. If the includes arenull
or empty, the default includes are used.- Parameters:
baseDir
- the base directory to start fromincludes
- the includesexcludes
- the excludes- Returns:
- the files to copy
-
getFilesToIncludes
protected PathSet getFilesToIncludes(java.io.File baseDir, java.lang.String[] includes, java.lang.String[] excludes, boolean includeDirectories)
Returns the file to copy. If the includes arenull
or empty, the default includes are used.- Parameters:
baseDir
- the base directory to start fromincludes
- the includesexcludes
- the excludesincludeDirectories
- include directories yes or not.- Returns:
- the files to copy
-
getArtifactFinalName
protected java.lang.String getArtifactFinalName(WarPackagingContext context, org.apache.maven.artifact.Artifact artifact) throws org.codehaus.plexus.interpolation.InterpolationException
Returns the final name of the specified artifact. If theoutputFileNameMapping
is set, it is used, otherwise the standard naming scheme is used.- Parameters:
context
- the packaging contextartifact
- the artifact- Returns:
- the converted filename of the artifact
- Throws:
org.codehaus.plexus.interpolation.InterpolationException
- in case of interpolation problem.
-
isFileOfType
private boolean isFileOfType(java.io.File file, java.lang.String extension)
Determine whether a file is of a certain type, by looking at the file extension.- Parameters:
file
- The file to checkextension
- The extension for a file type, including the '.'- Returns:
true
if the file is a file of the specified type, otherwisefalse
- Since:
- 3.4.0
-
isPropertiesFile
private boolean isPropertiesFile(java.io.File file)
Determine whether a file is a properties file or not.- Parameters:
file
- The file to check- Returns:
true
if the file is a properties file, otherwisefalse
- Since:
- 3.4.0
-
isXmlFile
private boolean isXmlFile(java.io.File file)
Returnstrue
if theFile
-object is a file (not a directory) that is notnull
and has a file name that ends in ".xml".- Parameters:
file
- The file to check- Returns:
true
if the file is an xml-file, otherwisefalse
- Since:
- 2.3
-
-