
org.nuiton.license.plugin.HelpMojo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of maven-license-plugin Show documentation
Show all versions of maven-license-plugin Show documentation
Plugin pour switcher de license dans un module maven 2
The newest version!
package org.nuiton.license.plugin;
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 maven-license-plugin.
Call mvn license:help -Ddetail=true -Dgoal=<goal-name>
to display parameter details.
*
* @version generated on Thu Nov 18 22:21:37 CET 2010
* @author org.apache.maven.tools.plugin.generator.PluginHelpGenerator (version 2.5.1)
* @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, should be positive.
*
* @parameter expression="${lineLength}" default-value="80"
*/
private int lineLength;
/**
* The number of spaces per indentation level, should be positive.
*
* @parameter expression="${indentSize}" default-value="2"
*/
private int indentSize;
/** {@inheritDoc} */
public void execute()
throws MojoExecutionException
{
if ( lineLength <= 0 )
{
getLog().warn( "The parameter 'lineLength' should be positive, using '80' as default." );
lineLength = 80;
}
if ( indentSize <= 0 )
{
getLog().warn( "The parameter 'indentSize' should be positive, using '2' as default." );
indentSize = 2;
}
StringBuffer sb = new StringBuffer();
append( sb, "org.nuiton:maven-license-plugin:3.0", 0 );
append( sb, "", 0 );
append( sb, "Maven License Plugin", 0 );
append( sb, "Plugin de gestion des licenses (et en-t\u00eates) dans un project maven 2.", 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 || "add-third-party".equals( goal ) )
{
append( sb, "license:add-third-party", 0 );
append( sb, "The gola to generate the third-party file. This file contains for all dependencies of the project a line giving the license used by the dependency. It will also copy it in the class-path (says add the generated directory as a resource of the build).", 1 );
append( sb, "", 0 );
if ( detail )
{
append( sb, "Available parameters:", 1 );
append( sb, "", 0 );
append( sb, "bundleThirdPartyPath (Default: META-INF/${project.artifactId}-THIRD-PARTY.txt)", 2 );
append( sb, "The path of the bundled third party file to produce when generateBundle is on.\nNote: This option is not available for pom module types.\n", 3 );
append( sb, "", 0 );
append( sb, "encoding (Default: ${project.build.sourceEncoding})", 2 );
append( sb, "Encoding used to read and writes files.\nNote: If nothing is filled here, we will use the system property file.encoding.\n", 3 );
append( sb, "", 0 );
append( sb, "excludedArtifacts", 2 );
append( sb, "A filter to exclude some ArtifactsIds", 3 );
append( sb, "", 0 );
append( sb, "excludedGroups", 2 );
append( sb, "A filter to exclude some GroupIds", 3 );
append( sb, "", 0 );
append( sb, "failIfWarning (Default: false)", 2 );
append( sb, "A flag to fail the build if at least one dependency was detected without a license.", 3 );
append( sb, "", 0 );
append( sb, "force (Default: false)", 2 );
append( sb, "To force generation of the third-party file even if every thing is up to date.", 3 );
append( sb, "", 0 );
append( sb, "generateBundle (Default: false)", 2 );
append( sb, "A flag to copy a bundled version of the third-party file. This is usefull to avoid for a final application collision name of third party file. The file will be copied at the bundleThirdPartyPath location.", 3 );
append( sb, "", 0 );
append( sb, "groupByLicense (Default: false)", 2 );
append( sb, "A flag to change the grouping of the generated THIRD-PARTY file.\nBy default, group by dependecies.\n\nIf sets to true, the it will group by license type.\n", 3 );
append( sb, "", 0 );
append( sb, "includedArtifacts", 2 );
append( sb, "A filter to include only some ArtifactsIds", 3 );
append( sb, "", 0 );
append( sb, "includedGroups", 2 );
append( sb, "A filter to include only some GroupIds", 3 );
append( sb, "", 0 );
append( sb, "licenseMerges", 2 );
append( sb, "To merge licenses in final file.\nEach entry represents a merge (first license is main license to keep), licenses are separated by |.\n\nExample :\n\n\n\nThe\u00a0Apache\u00a0Software\u00a0License|Version\u00a02.0,Apache\u00a0License,\u00a0Version\u00a02.0 \n \n
\n", 3 );
append( sb, "", 0 );
append( sb, "missingFile (Default: src/license/THIRD-PARTY.properties)", 2 );
append( sb, "The file where to fill the license for dependencies with unknwon license.", 3 );
append( sb, "", 0 );
append( sb, "outputDirectory (Default: target/generated-sources/license)", 2 );
append( sb, "Directory where to generate files.", 3 );
append( sb, "", 0 );
append( sb, "project (Default: ${project})", 2 );
append( sb, "The reacted project.", 3 );
append( sb, "", 0 );
append( sb, "thirdPartyFilename (Default: THIRD-PARTY.txt)", 2 );
append( sb, "File where to wirte the third-party file.", 3 );
append( sb, "", 0 );
append( sb, "useMissingFile (Default: false)", 2 );
append( sb, "A flag to use the missing licenses file to consolidate the THID-PARTY file.", 3 );
append( sb, "", 0 );
append( sb, "verbose (Default: ${maven.verbose})", 2 );
append( sb, "Flag to activate verbose mode.\nNote: Verbose mode is always on if you starts a debug maven instance (says via -X).\n", 3 );
append( sb, "", 0 );
}
}
if ( goal == null || goal.length() <= 0 || "aggregate-add-third-party".equals( goal ) )
{
append( sb, "license:aggregate-add-third-party", 0 );
append( sb, "This aggregator goal (will be executed only once and only on pom projects) executed the add-third-party on all his modules (in a parellel build cycle) then aggreates all the third-party files in final one in the pom project.", 1 );
append( sb, "", 0 );
if ( detail )
{
append( sb, "Available parameters:", 1 );
append( sb, "", 0 );
append( sb, "bundleThirdPartyPath (Default: META-INF/${project.artifactId}-THIRD-PARTY.txt)", 2 );
append( sb, "The path of the bundled third party file to produce when generateBundle is on.\nNote: This option is not available for pom module types.\n", 3 );
append( sb, "", 0 );
append( sb, "encoding (Default: ${project.build.sourceEncoding})", 2 );
append( sb, "Encoding used to read and writes files.\nNote: If nothing is filled here, we will use the system property file.encoding.\n", 3 );
append( sb, "", 0 );
append( sb, "excludedArtifacts", 2 );
append( sb, "A filter to exclude some ArtifactsIds", 3 );
append( sb, "", 0 );
append( sb, "excludedGroups", 2 );
append( sb, "A filter to exclude some GroupIds", 3 );
append( sb, "", 0 );
append( sb, "failIfWarning (Default: false)", 2 );
append( sb, "A flag to fail the build if at least one dependency was detected without a license.", 3 );
append( sb, "", 0 );
append( sb, "force (Default: false)", 2 );
append( sb, "To force generation of the third-party file even if every thing is up to date.", 3 );
append( sb, "", 0 );
append( sb, "generateBundle (Default: false)", 2 );
append( sb, "A flag to copy a bundled version of the third-party file. This is usefull to avoid for a final application collision name of third party file. The file will be copied at the bundleThirdPartyPath location.", 3 );
append( sb, "", 0 );
append( sb, "groupByLicense (Default: false)", 2 );
append( sb, "A flag to change the grouping of the generated THIRD-PARTY file.\nBy default, group by dependecies.\n\nIf sets to true, the it will group by license type.\n", 3 );
append( sb, "", 0 );
append( sb, "includedArtifacts", 2 );
append( sb, "A filter to include only some ArtifactsIds", 3 );
append( sb, "", 0 );
append( sb, "includedGroups", 2 );
append( sb, "A filter to include only some GroupIds", 3 );
append( sb, "", 0 );
append( sb, "licenseMerges", 2 );
append( sb, "To merge licenses in final file.\nEach entry represents a merge (first license is main license to keep), licenses are separated by |.\n\nExample :\n\n\nRepeat a String n
times to form a new string.
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();
}
/**
* Append a description to the buffer by respecting the indentSize and lineLength parameters.
* Note: The last character is always a new line.
*
* @param sb The buffer to append the description, not null
.
* @param description The description, not null
.
* @param indent The base indentation level of each line, must not be negative.
*/
private void append( StringBuffer sb, String description, int indent )
{
for ( Iterator it = toLines( description, indent, indentSize, lineLength ).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.
* @param indentSize The size of each indentation, must not be negative.
* @param lineLength The length of the line, must not be negative.
* @return The sequence of display lines, never null
.
* @throws NegativeArraySizeException if indent < 0
*/
private static List toLines( String text, int indent, int indentSize, int lineLength )
{
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], indentSize, lineLength );
}
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
.
* @param indentSize The size of each indentation, must not be negative.
* @param lineLength The length of the line, must not be negative.
*/
private static void toLines( List lines, String line, int indentSize, int lineLength )
{
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 - 2025 Weber Informatics LLC | Privacy Policy