Package org.apache.maven.plugin.patch
Class ApplyMojo
java.lang.Object
org.apache.maven.plugin.AbstractMojo
org.apache.maven.plugin.patch.ApplyMojo
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo
@Mojo(name="apply",
defaultPhase=PROCESS_SOURCES)
public class ApplyMojo
extends org.apache.maven.plugin.AbstractMojo
Apply one or more patches to project sources.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanWhether to make backups of the original files before modding them.private booleanapply --binary option to patch command linestatic final Liststatic final Listprivate FileThe output file which is the original file, plus modifications from the patch.private booleanFlag beingtrueif the desired behavior is to fail the build on the first failed patch detected.private ListList of phrases to watch for in the command output from the patch tool.private ListWhen thestrictPatchingflag is set, this parameter is useful to mark certain contents of the patch-source directory that should be ignored without causing the build to fail.private booleanWhether to ignore whitespaces when applying the patches.private booleanSetting natural order processing totruewill cause all patches in a directory to be processed in a natural order alleviating the need to declare patches directly in the project file.private booleanFlag to enable/disable optimization file from being written.private FileThe original file which will be modified by the patch.static final Listprivate FileThe base directory for the file names specified by the parameterpatches.protected ListThe list of patch file names, supplying the order in which patches should be applied.private FileThe single patch file to apply.private FileThis is the tracking file used to maintain a list of the patches applied to the unpacked project sources which are currently in the target directory.private booleanWhen set totrue, the empty files resulting from the patching process are removed.private booleanWhether to treat these patches as having reversed source and dest in the patch syntax.private booleanWhether to skip this goal's execution.private booleanFlag that, when set totrue, will make sure that all patches included in thepatcheslist must be present and describe the full contents of the patch directory.private intThe number of directories to be stripped from patch file paths, before applying, starting from the leftmost, or root-est.private FileThe target directory for applying patches.private booleanWhether to exclude default ignored patch items, such as.svnorCVSdirectories.Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate StringapplyPatches(Map patchesApplied) private voidcheckForWatchPhrases(String output) private voidcheckStrictPatchCompliance(List foundPatchFiles) private org.codehaus.plexus.util.cli.CommandlinecreatePatchCommand(File patchFile) Add a new Patch task to the Ant calling mechanism.voidexecute()Apply the patches.private intexecuteCommandLine(org.codehaus.plexus.util.cli.Commandline cli, org.codehaus.plexus.util.cli.StreamConsumer out, org.codehaus.plexus.util.cli.StreamConsumer err) private MapfindPatchesToApply(List foundPatchFiles, File patchSourceDir) private voidwriteTrackingFile(Map patchesApplied) Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
PATCH_FAILURE_WATCH_PHRASES
-
DEFAULT_IGNORED_PATCHES
-
DEFAULT_IGNORED_PATCH_PATTERNS
-
useDefaultIgnores
@Parameter(defaultValue="true") private boolean useDefaultIgnoresWhether to exclude default ignored patch items, such as.svnorCVSdirectories. -
patches
The list of patch file names, supplying the order in which patches should be applied. The path names in this list must be relative to the base directory specified by the parameterpatchDirectory. This parameter is mutually exclusive with thepatchfileparameter. -
skipApplication
@Parameter(alias="patch.apply.skip", defaultValue="false") private boolean skipApplicationWhether to skip this goal's execution. -
optimizations
@Parameter(defaultValue="true") private boolean optimizationsFlag to enable/disable optimization file from being written. This file tracks the patches that were applied the last time this goal actually executed. It is required for cases where project-sources optimizations are enabled, since project-sources will not be re-unpacked if they are at least as fresh as the source archive. If we avoid re-unpacking project sources, we need to make sure we don't reapply patches.
Note: If the list of patches changes and this flag is enabled, a "mvn clean" must be executed before the next build, to remove the tracking file. -
patchTrackingFile
@Parameter(defaultValue="${project.build.directory}/optimization-files/patches-applied.txt") private File patchTrackingFileThis is the tracking file used to maintain a list of the patches applied to the unpacked project sources which are currently in the target directory. If this file is present, and project-source unpacking is optimized (meaning it won't re-unpack unless the project-sources archive is newer), this goal will not execute and no patches will be applied in the current build. -
targetDirectory
@Parameter(alias="patchTargetDir", defaultValue="${project.build.sourceDirectory}") private File targetDirectoryThe target directory for applying patches. Files in this directory will be modified. -
failFast
@Parameter(defaultValue="true") private boolean failFastFlag beingtrueif the desired behavior is to fail the build on the first failed patch detected. -
naturalOrderProcessing
@Parameter(defaultValue="false") private boolean naturalOrderProcessingSetting natural order processing totruewill cause all patches in a directory to be processed in a natural order alleviating the need to declare patches directly in the project file. -
ignoredPatches
When thestrictPatchingflag is set, this parameter is useful to mark certain contents of the patch-source directory that should be ignored without causing the build to fail. -
strictPatching
@Parameter(defaultValue="false") private boolean strictPatchingFlag that, when set totrue, will make sure that all patches included in thepatcheslist must be present and describe the full contents of the patch directory. IfstrictPatchingis set totrue, and thepatcheslist has a value that does not correspond to a file in the patch directory, the build will fail. IfstrictPatchingis set totrue, and the patch directory contains files not listed in thepatchesparameter, the build will fail. If set tofalse, only the patches listed in thepatchesparameter that have corresponding files will be applied; the rest will be ignored. -
strip
@Parameter(defaultValue="0") private int stripThe number of directories to be stripped from patch file paths, before applying, starting from the leftmost, or root-est. -
ignoreWhitespace
@Parameter(defaultValue="true") private boolean ignoreWhitespaceWhether to ignore whitespaces when applying the patches. -
reverse
@Parameter(defaultValue="false") private boolean reverseWhether to treat these patches as having reversed source and dest in the patch syntax. -
backups
@Parameter(defaultValue="false") private boolean backupsWhether to make backups of the original files before modding them. -
failurePhrases
List of phrases to watch for in the command output from the patch tool. If one is found, it will cause the build to fail. All phrases should be lower-case only. By default, the phrasesfail,skipandrejectare used. -
originalFile
The original file which will be modified by the patch. By default, the patch tool will automatically derive the original file from the header of the patch file. -
destFile
The output file which is the original file, plus modifications from the patch. By default, the file(s) will be patched inplace. -
patchFile
The single patch file to apply. This parameter is mutually exclusive with thepatchesparameter. -
patchDirectory
The base directory for the file names specified by the parameterpatches. -
removeEmptyFiles
@Parameter(defaultValue="false") private boolean removeEmptyFilesWhen set totrue, the empty files resulting from the patching process are removed. Empty ancestor directories are removed as well.- Since:
- 1.1
-
binary
@Parameter(defaultValue="false") private boolean binaryapply --binary option to patch command line- Since:
- 1.2
-
-
Constructor Details
-
ApplyMojo
public ApplyMojo()
-
-
Method Details
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureExceptionApply the patches. Give preference to patchFile over patchSourceDir/patches, and preference to originalFile over workDir.- Throws:
org.apache.maven.plugin.MojoExecutionExceptionorg.apache.maven.plugin.MojoFailureException
-
findPatchesToApply
private Map findPatchesToApply(List foundPatchFiles, File patchSourceDir) throws org.apache.maven.plugin.MojoFailureException - Throws:
org.apache.maven.plugin.MojoFailureException
-
checkStrictPatchCompliance
private void checkStrictPatchCompliance(List foundPatchFiles) throws org.apache.maven.plugin.MojoExecutionException - Throws:
org.apache.maven.plugin.MojoExecutionException
-
applyPatches
private String applyPatches(Map patchesApplied) throws org.apache.maven.plugin.MojoExecutionException - Throws:
org.apache.maven.plugin.MojoExecutionException
-
executeCommandLine
private int executeCommandLine(org.codehaus.plexus.util.cli.Commandline cli, org.codehaus.plexus.util.cli.StreamConsumer out, org.codehaus.plexus.util.cli.StreamConsumer err) throws org.codehaus.plexus.util.cli.CommandLineException - Throws:
org.codehaus.plexus.util.cli.CommandLineException
-
writeTrackingFile
private void writeTrackingFile(Map patchesApplied) throws org.apache.maven.plugin.MojoExecutionException - Throws:
org.apache.maven.plugin.MojoExecutionException
-
checkForWatchPhrases
private void checkForWatchPhrases(String output) throws org.apache.maven.plugin.MojoExecutionException - Throws:
org.apache.maven.plugin.MojoExecutionException
-
createPatchCommand
Add a new Patch task to the Ant calling mechanism. Give preference to originalFile/destFile, then workDir, and finally ${basedir}.
-