All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.codehaus.mojo.patch.HelpMojo Maven / Gradle / Ivy

There is a newer version: 1.0-beta-1
Show newest version
package org.codehaus.mojo.patch;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;

/**
 * Display help information on patch-maven-plugin. Call 
  mvn patch:help -Ddetail=true -Dgoal=<goal-name>
to display parameter details. * * @version generated on Thu Nov 06 17:03:45 EST 2008 * @goal help * @requiresProject false */ public class HelpMojo extends AbstractMojo { /** * If true, display all settable properties for each goal. * * @parameter expression="${detail}" default-value="false" */ private boolean detail; /** * The name of the goal for which to show help. If unspecified, all goals will be displayed. * * @parameter expression="${goal}" */ private java.lang.String goal; /** * The maximum length of a display line. * * @parameter expression="${lineLength}" default-value="80" */ private int lineLength; /** * The number of spaces per indentation level. * * @parameter expression="${indentSize}" default-value="2" */ private int indentSize; /** {@inheritDoc} */ public void execute() throws MojoExecutionException { StringBuffer sb = new StringBuffer(); append( sb, "org.codehaus.mojo:patch-maven-plugin:1.0-alpha-5", 0 ); append( sb, "", 0 ); append( sb, "Patch Plugin 1.0-alpha-5", 0 ); append( sb, "These plugins are designed to convert tarballs of typical non-java open source project and with patch/autoconf/configure/make/install prepare a directory for packaging with RPM. Stuffing a java project into an RPM is also supported.", 1 ); append( sb, "", 0 ); if ( goal == null || goal.length() <= 0 ) { append( sb, "This plugin has 7 goals:", 0 ); append( sb, "", 0 ); } if ( goal == null || goal.length() <= 0 || "apply".equals( goal ) ) { append( sb, "patch:apply", 0 ); append( sb, "Apply a set of patches to project sources.", 1 ); append( sb, "", 0 ); if ( detail ) { append( sb, "Available parameters:", 1 ); append( sb, "", 0 ); append( sb, "backups", 2 ); append( sb, "Whether to make backups of the original files before modding them.", 3 ); append( sb, "", 0 ); append( sb, "destFile", 2 ); append( sb, "The file which is the original file, plus modifications from the patch. Mutually exclusive with workDir.", 3 ); append( sb, "", 0 ); append( sb, "ignoreWhitespace", 2 ); append( sb, "Whether to ignore whitespaces when applying the patches.", 3 ); append( sb, "", 0 ); append( sb, "originalFile", 2 ); append( sb, "The original file which will be modified by the patch. Mutually exclusive with workDir.", 3 ); append( sb, "", 0 ); append( sb, "patchFile", 2 ); append( sb, "The single patch file to apply. Mutually exclusive with \'patches\'.", 3 ); append( sb, "", 0 ); append( sb, "patchSourceDir (Default: ${project.build.directory}/patches)", 2 ); append( sb, "The source directory from which to find patch files.", 3 ); append( sb, "", 0 ); append( sb, "patches", 2 ); append( sb, "The list of patch files (relative to \'patchSourceDir\') which should be applied.", 3 ); append( sb, "", 0 ); append( sb, "reverse", 2 ); append( sb, "Whether to treat these patches as having reversed source and dest in the patch syntax.", 3 ); append( sb, "", 0 ); append( sb, "skipApplication (Default: false)", 2 ); append( sb, "Whether to skip this mojo\'s execution.", 3 ); append( sb, "", 0 ); append( sb, "strip (Default: 0)", 2 ); append( sb, "The number of directories to be stripped from patch file paths, before applying, starting from the leftmost, or root-est.", 3 ); append( sb, "", 0 ); append( sb, "useDefaultIgnores (Default: true)", 2 ); append( sb, "Whether to exclude default ignored patch items, such as .svn or CVS directories.", 3 ); append( sb, "", 0 ); append( sb, "workDir (Default: ${project.build.directory})", 2 ); append( sb, "The target directory for applying patches. Files in this directory will be modified.", 3 ); append( sb, "", 0 ); } } if ( goal == null || goal.length() <= 0 || "apply-directory".equals( goal ) ) { append( sb, "patch:apply-directory", 0 ); append( sb, "Apply a set of patches to project sources.", 1 ); append( sb, "", 0 ); if ( detail ) { append( sb, "Available parameters:", 1 ); append( sb, "", 0 ); append( sb, "backups", 2 ); append( sb, "Whether to make backups of the original files before modding them.", 3 ); append( sb, "", 0 ); append( sb, "ignoreWhitespace", 2 ); append( sb, "Whether to ignore whitespaces when applying the patches.", 3 ); append( sb, "", 0 ); append( sb, "ignoredPatches", 2 ); append( sb, "When the strictPatching flag 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.", 3 ); append( sb, "", 0 ); append( sb, "optimizations (Default: true)", 2 ); append( sb, "Flag to enable/disable optimization file from being written. This file tracks the patches that were applied the last time this mojo 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. This flag is true by default.\nNOTE: 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.", 3 ); append( sb, "", 0 ); append( sb, "patchFailureWatchPhrases", 2 ); append( sb, "List of phrases to watch for in patch-command output. If one is found, it will cause the build to fail. All phrases should be lower-case ONLY.", 3 ); append( sb, "", 0 ); append( sb, "patchTrackingFile (Default: ${project.build.directory}/optimization-files/patches-applied.txt)", 2 ); append( sb, "This 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 mojo will not execute and no patches will be applied in the current build.", 3 ); append( sb, "", 0 ); append( sb, "patches", 2 ); append( sb, "The list of patch file names (without directory information), supplying the order in which patches should be applied.", 3 ); append( sb, "", 0 ); append( sb, "reverse", 2 ); append( sb, "Whether to treat these patches as having reversed source and dest in the patch syntax.", 3 ); append( sb, "", 0 ); append( sb, "skipApplication (Default: false)", 2 ); append( sb, "Whether to skip this mojo\'s execution.", 3 ); append( sb, "", 0 ); append( sb, "strictPatching (Default: false)", 2 ); append( sb, "Flag that, when set to true, will make sure that all patches included in the \'patches\' list must be present and describe the full contents of the patch directory. If strictPatching is set to true, and the patches list has a value that does not correspond to a file in the patch directory, the build will fail. If strictPatching is set to true, and the patch directory contains files not listed in the patches parameter, the build will fail. If set to false, only the patches listed in the patches parameter that have corresponding files will be applied; the rest will be ignored. Default value for this parameter is false.", 3 ); append( sb, "", 0 ); append( sb, "strip", 2 ); append( sb, "The number of directories to be stripped from patch file paths, before applying, starting from the leftmost, or root-est.", 3 ); append( sb, "", 0 ); append( sb, "targetDirectory (Default: ${project.build.sourceDirectory})", 2 ); append( sb, "The target directory for applying patches. Files in this directory will be modified.", 3 ); append( sb, "", 0 ); append( sb, "useDefaultIgnores (Default: true)", 2 ); append( sb, "Whether to exclude default ignored patch items, such as .svn or CVS directories.", 3 ); append( sb, "", 0 ); } } if ( goal == null || goal.length() <= 0 || "get".equals( goal ) ) { append( sb, "patch:get", 0 ); append( sb, "Retrieve patch files from remote URLs", 1 ); append( sb, "", 0 ); if ( detail ) { append( sb, "Available parameters:", 1 ); append( sb, "", 0 ); append( sb, "patchSourceDir (Default: ${project.build.directory}/patches)", 2 ); append( sb, "The directory into which to store downloaded patch files.", 3 ); append( sb, "", 0 ); append( sb, "skipRetrieval (Default: false)", 2 ); append( sb, "Whether to skip this mojo\'s execution.", 3 ); append( sb, "", 0 ); append( sb, "urls", 2 ); append( sb, "URLs from which to retrieve the patch files.", 3 ); append( sb, "", 0 ); } } if ( goal == null || goal.length() <= 0 || "help".equals( goal ) ) { append( sb, "patch:help", 0 ); append( sb, "Display help information on patch-maven-plugin. Call\n\u00a0\u00a0mvn\u00a0patch:help\u00a0-Ddetail=true\u00a0-Dgoal=\nto display parameter details.", 1 ); append( sb, "", 0 ); if ( detail ) { append( sb, "Available parameters:", 1 ); append( sb, "", 0 ); append( sb, "detail (Default: false)", 2 ); append( sb, "If true, display all settable properties for each goal.", 3 ); append( sb, "", 0 ); append( sb, "goal", 2 ); append( sb, "The name of the goal for which to show help. If unspecified, all goals will be displayed.", 3 ); append( sb, "", 0 ); append( sb, "lineLength (Default: 80)", 2 ); append( sb, "The maximum length of a display line.", 3 ); append( sb, "", 0 ); append( sb, "indentSize (Default: 2)", 2 ); append( sb, "The number of spaces per indentation level.", 3 ); append( sb, "", 0 ); } } if ( goal == null || goal.length() <= 0 || "package-patches".equals( goal ) ) { append( sb, "patch:package-patches", 0 ); append( sb, "(no description available)", 1 ); append( sb, "", 0 ); if ( detail ) { append( sb, "Available parameters:", 1 ); append( sb, "", 0 ); append( sb, "patchArtifactClassifier (Default: patches)", 2 ); append( sb, "Classifier is a suffix in the filename, but it is before the filename externsion.", 3 ); append( sb, "", 0 ); append( sb, "patchArtifactType (Default: zip)", 2 ); append( sb, "The filename extension, typically \'.zip\'", 3 ); append( sb, "", 0 ); append( sb, "patches", 2 ); append( sb, "The list of patch file names (without directory information), supplying the order in which patches should be applied.", 3 ); append( sb, "", 0 ); append( sb, "tarLongFileMode (Default: gnu)", 2 ); append( sb, "Handling mode for long file paths.", 3 ); append( sb, "", 0 ); append( sb, "useDefaultIgnores (Default: true)", 2 ); append( sb, "Whether to exclude default ignored patch items, such as .svn or CVS directories.", 3 ); append( sb, "", 0 ); } } if ( goal == null || goal.length() <= 0 || "purge-local-patch-artifact".equals( goal ) ) { append( sb, "patch:purge-local-patch-artifact", 0 ); append( sb, "(no description available)", 1 ); append( sb, "", 0 ); if ( detail ) { append( sb, "Available parameters:", 1 ); append( sb, "", 0 ); append( sb, "patches", 2 ); append( sb, "The list of patch file names (without directory information), supplying the order in which patches should be applied.", 3 ); append( sb, "", 0 ); append( sb, "useDefaultIgnores (Default: true)", 2 ); append( sb, "Whether to exclude default ignored patch items, such as .svn or CVS directories.", 3 ); append( sb, "", 0 ); } } if ( goal == null || goal.length() <= 0 || "resolve-patches".equals( goal ) ) { append( sb, "patch:resolve-patches", 0 ); append( sb, "(no description available)", 1 ); append( sb, "", 0 ); if ( detail ) { append( sb, "Available parameters:", 1 ); append( sb, "", 0 ); append( sb, "optimizations (Default: true)", 2 ); append( sb, "If set to false, don\'t attempt to optimize the unpack step based on the pre-existence of the unpack directory and its contents. By default, optimizations are enabled.", 3 ); append( sb, "", 0 ); append( sb, "patchArtifactClassifier (Default: patches)", 2 ); append( sb, "Classifier is a suffix in the filename, but it is before the filename externsion.", 3 ); append( sb, "", 0 ); append( sb, "patchArtifactType (Default: zip)", 2 ); append( sb, "The filename extension, typically \'.zip\'", 3 ); append( sb, "", 0 ); append( sb, "patchArtifactUnpackDirectory (Default: ${project.build.directory}/unpacked-patches)", 2 ); append( sb, "Scratch directory used to unpack the patches prior to application of the patch.", 3 ); append( sb, "", 0 ); append( sb, "patchArtifactUnpackSubpath", 2 ); append( sb, "This is the subpath within the unpacked patch-archive, where patches should reside.", 3 ); append( sb, "", 0 ); append( sb, "patchDirectory (Default: src/patches)", 2 ); append( sb, "Where to find the patches for this project", 3 ); append( sb, "", 0 ); append( sb, "patches", 2 ); append( sb, "The list of patch file names (without directory information), supplying the order in which patches should be applied.", 3 ); append( sb, "", 0 ); append( sb, "useDefaultIgnores (Default: true)", 2 ); append( sb, "Whether to exclude default ignored patch items, such as .svn or CVS directories.", 3 ); append( sb, "", 0 ); } } if ( getLog().isInfoEnabled() ) { getLog().info( sb.toString() ); } } /** *

Repeat a String n times to form a new string.

* * @param str String to repeat * @param repeat number of times to repeat str * @return String with repeated String * @throws NegativeArraySizeException if repeat < 0 * @throws NullPointerException if str is null */ private static String repeat( String str, int repeat ) { StringBuffer buffer = new StringBuffer( repeat * str.length() ); for ( int i = 0; i < repeat; i++ ) { buffer.append( str ); } return buffer.toString(); } private void append( StringBuffer sb, String description, int indent ) { for ( Iterator it = toLines( description, indent ).iterator(); it.hasNext(); ) { sb.append( it.next().toString() ).append( '\n' ); } } /** * Splits the specified text into lines of convenient display length. * * @param text The text to split into lines, must not be null. * @param indent The base indentation level of each line, must not be negative. * @return The sequence of display lines, never null. */ private List toLines( String text, int indent ) { List lines = new ArrayList(); String ind = repeat( "\t", indent ); String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" ); for ( int i = 0; i < plainLines.length; i++ ) { toLines( lines, ind + plainLines[i] ); } return lines; } /** * Adds the specified line to the output sequence, performing line wrapping if necessary. * * @param lines The sequence of display lines, must not be null. * @param line The line to add, must not be null. */ private void toLines( List lines, String line ) { int lineIndent = getIndentLevel( line ); StringBuffer buf = new StringBuffer( 256 ); String[] tokens = line.split( " +" ); for ( int i = 0; i < tokens.length; i++ ) { String token = tokens[i]; if ( i > 0 ) { if ( buf.length() + token.length() >= lineLength ) { lines.add( buf.toString() ); buf.setLength( 0 ); buf.append( repeat( " ", lineIndent * indentSize ) ); } else { buf.append( ' ' ); } } for ( int j = 0; j < token.length(); j++ ) { char c = token.charAt( j ); if ( c == '\t' ) { buf.append( repeat( " ", indentSize - buf.length() % indentSize ) ); } else if ( c == '\u00A0' ) { buf.append( ' ' ); } else { buf.append( c ); } } } lines.add( buf.toString() ); } /** * Gets the indentation level of the specified line. * * @param line The line whose indentation level should be retrieved, must not be null. * @return The indentation level of the line. */ private static int getIndentLevel( String line ) { int level = 0; for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ ) { level++; } for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ ) { if ( line.charAt( i ) == '\t' ) { level++; break; } } return level; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy