org.codehaus.mojo.license
Class UpdateFileHeaderMojo

java.lang.Object
  extended by org.apache.maven.plugin.AbstractMojo
      extended by org.codehaus.mojo.license.AbstractLicenseMojo
          extended by org.codehaus.mojo.license.AbstractLicenseNameMojo
              extended by org.codehaus.mojo.license.UpdateFileHeaderMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo, FileHeaderProcessorConfiguration

public class UpdateFileHeaderMojo
extends AbstractLicenseNameMojo
implements FileHeaderProcessorConfiguration

The goal to update (or add) the header on project source files.

This goal replace the update-header goal which can not deal with Copyright.

This goal use a specific project file descriptor project.xml to describe all files to update for a whole project.

Since:
1.0
Author:
tchemit

Field Summary
protected  boolean addSvnKeyWords
          A flag to add svn:keywords on new header.
protected  boolean canUpdateCopyright
          A flag to authorize update of the copyright part of the header.
protected  boolean canUpdateDescription
          A flag to authorize update of the description part of the header.
protected  boolean canUpdateLicense
          A flag to authorize update of the license part of the header.
protected  boolean clearAfterOperation
          A flag to clear everything after execution.
static String[] DEFAULT_EXCLUDES
           
static String[] DEFAULT_INCLUDES
           
static String[] DEFAULT_ROOTS
           
protected  boolean dryRun
          A flag to test plugin but modify no file.
protected  String[] excludes
          Specific files to excludes, separated by a comma.
protected  Map<String,String> extraExtensions
          To associate extra extension files to an existing comment style.
protected  String ignoreTag
          A tag to place on files that will be ignored by the plugin.
protected  String inceptionYear
          Inception year of the project.
protected  String[] includes
          Specific files to includes, separated by a comma.
protected  String organizationName
          Name of project's organization.
protected  String projectName
          Name of project (or module).
protected  String[] roots
          To specify the base dir from which we apply the license.
protected  boolean skipUpdateLicense
          A flag to skip the goal.
protected  boolean updateCopyright
          A flag to update copyright application time (change copyright last year if required) according to the last commit made on the processed file.
 
Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
 
Constructor Summary
UpdateFileHeaderMojo()
           
 
Method Summary
protected  FileHeader buildDefaultFileHeader(License license, String projectName, String inceptionYear, String copyrightHolder, boolean addSvnKeyWords, String encoding)
          Build a default header given the parameters.
protected  void clear()
           
 void doAction()
          Do plugin action.
protected  void finalize()
           
protected  void finalizeFile(File file, File processFile)
           
 FileHeader getFileHeader()
           
 Set<File> getFiles(org.codehaus.mojo.license.UpdateFileHeaderMojo.FileState state)
           
 Map<String,List<File>> getFilesToTreateByCommentStyle()
           
protected  void getFilesToTreateForRoots(String[] includes, String[] excludes, List<String> roots, Map<File,String[]> files)
          Collects some file.
 UpdateFileHeaderFilter getFilter()
           
 String getIgnoreTag()
           
 String getInceptionYear()
           
 String getOrganizationName()
           
 Set<File> getProcessedFiles()
           
 FileHeaderProcessor getProcessor()
           
 String getProjectName()
           
 EnumMap<org.codehaus.mojo.license.UpdateFileHeaderMojo.FileState,Set<File>> getResult()
           
 long getTimestamp()
           
 FileHeaderTransformer getTransformer()
           
 FileHeaderTransformer getTransformer(String transformerName)
           
 Map<String,FileHeaderTransformer> getTransformers()
           
 void init()
          Method to initialize the mojo before doing any concrete actions.
 boolean isAddSvnKeyWords()
           
 boolean isCanUpdateCopyright()
           
 boolean isCanUpdateDescription()
           
 boolean isCanUpdateLicense()
           
 boolean isClearAfterOperation()
           
 boolean isDryRun()
           
 boolean isSkip()
          When is sets to true, will skip execution.
 boolean isUpdateCopyright()
           
protected  Map<String,List<File>> obtainFilesToTreateByCommentStyle()
           
protected  void prepareProcessFile(File file)
           
protected  void processCommentStyle(String commentStyle, List<File> filesToTreat)
           
protected  boolean processFile(File file, File processFile)
          Process the given file and save the result in the given processFile.
protected  void reportType(org.codehaus.mojo.license.UpdateFileHeaderMojo.FileState state, StringBuilder buffer)
           
 void setAddSvnKeyWords(boolean addSvnKeyWords)
           
 void setCanUpdateCopyright(boolean canUpdateCopyright)
           
 void setCanUpdateDescription(boolean canUpdateDescription)
           
 void setCanUpdateLicense(boolean canUpdateLicense)
           
 void setClearAfterOperation(boolean clearAfterOperation)
           
 void setDryRun(boolean dryRun)
           
 void setExcludes(String excludes)
           
 void setExcludes(String[] excludes)
           
 void setFilesToTreateByCommentStyle(Map<String,List<File>> filesToTreateByCommentStyle)
           
 void setFilter(UpdateFileHeaderFilter filter)
           
 void setHeader(FileHeader header)
           
 void setIgnoreTag(String ignoreTag)
           
 void setInceptionYear(String inceptionYear)
           
 void setIncludes(String includes)
           
 void setIncludes(String[] includes)
           
 void setOrganizationName(String organizationName)
           
 void setProcessor(FileHeaderProcessor processor)
           
 void setProjectName(String projectName)
           
 void setRoots(String roots)
           
 void setRoots(String[] roots)
           
 void setSkip(boolean skipUpdateLicense)
          Changes internal state skip to execute (or not) goal.
 void setSkipUpdateLicense(boolean skipUpdateLicense)
           
 void setTimestamp(long timestamp)
           
 void setTransformer(FileHeaderTransformer transformer)
           
 void setTransformers(Map<String,FileHeaderTransformer> transformers)
           
 void setUpdateCopyright(boolean updateCopyright)
           
 
Methods inherited from class org.codehaus.mojo.license.AbstractLicenseNameMojo
checkSkip, getLicense, getLicense, getLicenseName, getLicenseResolver, getLicenseStore, isKeepBackup, setKeepBackup, setLicenseName, setLicenseResolver, setLicenseStore
 
Methods inherited from class org.codehaus.mojo.license.AbstractLicenseMojo
acceptPackaging, addResourceDir, afterExecute, checkEncoding, checkPackaging, execute, getBuildTimestamp, getEncoding, getProject, getSession, hasClassPath, isVerbose, rejectPackaging, setEncoding, setProject, setSession, setVerbose
 
Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.codehaus.mojo.license.header.FileHeaderProcessorConfiguration
getLog
 

Field Detail

projectName

protected String projectName
Name of project (or module).

Will be used as description section of new header.

Since:
1.0

organizationName

protected String organizationName
Name of project's organization.

Will be used as copyrigth's holder in new header.

Since:
1.0

inceptionYear

protected String inceptionYear
Inception year of the project.

Will be used as first year of copyright section in new header.

Since:
1.0

addSvnKeyWords

protected boolean addSvnKeyWords
A flag to add svn:keywords on new header.

Will add svn keywords :

Author, Id, Rev, URL and Date

Since:
1.0

canUpdateDescription

protected boolean canUpdateDescription
A flag to authorize update of the description part of the header.

Note: By default, do NOT authorize it since description can change on each file).

Since:
1.0

canUpdateCopyright

protected boolean canUpdateCopyright
A flag to authorize update of the copyright part of the header.

Note: By default, do NOT authorize it since copyright part should be handled by developpers (holder can change on each file for example).

Since:
1.0

canUpdateLicense

protected boolean canUpdateLicense
A flag to authorize update of the license part of the header.

Note: By default, authorize it since license part should always be generated by the plugin.

Since:
1.0

updateCopyright

protected boolean updateCopyright
A flag to update copyright application time (change copyright last year if required) according to the last commit made on the processed file.

Note that this functionnality is still not effective.

Since:
1.0

ignoreTag

protected String ignoreTag
A tag to place on files that will be ignored by the plugin.

Sometimes, it is necessary to do this when file is under a specific license.

Note: If no sets, will use the default tag %%Ignore-License

Since:
1.0

skipUpdateLicense

protected boolean skipUpdateLicense
A flag to skip the goal.

Since:
1.0

dryRun

protected boolean dryRun
A flag to test plugin but modify no file.

Since:
1.0

clearAfterOperation

protected boolean clearAfterOperation
A flag to clear everything after execution.

Note: This property should ONLY be used for test purpose.

Since:
1.0

roots

protected String[] roots
To specify the base dir from which we apply the license.

Should be on form "root1,root2,rootn".

By default, the main roots are "src, target/generated-sources, target/processed-sources".

Note: If some of these roots do not exist, they will be simply ignored.

Note: This parameter is not useable if you are still using a project file descriptor.

Since:
1.0

includes

protected String[] includes
Specific files to includes, separated by a comma. By default, it is "** /*".

Note: This parameter is not useable if you are still using a project file descriptor.

Since:
1.0

excludes

protected String[] excludes
Specific files to excludes, separated by a comma. By default, thoses file type are excluded:

Note: This parameter is not useable if you are still using a project file descriptor.

Since:
1.0

extraExtensions

protected Map<String,String> extraExtensions
To associate extra extension files to an existing comment style.

Keys of the map are the extension of extra files to treate, and the value is the comment style you want to associate.

For example, to treate file with extensions java2 and jdata as java files (says using the java comment style, declare this in your plugin configuration :

 <extraExtensions>
 <java2>java</java2>
 <jdata>java</jdata>
 </extraExtensions>
 

Note: This parameter is not useable if you are still using a project file descriptor.

Since:
1.0

DEFAULT_INCLUDES

public static final String[] DEFAULT_INCLUDES

DEFAULT_EXCLUDES

public static final String[] DEFAULT_EXCLUDES

DEFAULT_ROOTS

public static final String[] DEFAULT_ROOTS
Constructor Detail

UpdateFileHeaderMojo

public UpdateFileHeaderMojo()
Method Detail

init

public void init()
          throws Exception
Description copied from class: AbstractLicenseMojo
Method to initialize the mojo before doing any concrete actions.

Note: The method is invoked before the AbstractLicenseMojo.doAction() method.

Overrides:
init in class AbstractLicenseNameMojo
Throws:
Exception - if any

obtainFilesToTreateByCommentStyle

protected Map<String,List<File>> obtainFilesToTreateByCommentStyle()

doAction

public void doAction()
              throws Exception
Description copied from class: AbstractLicenseMojo
Do plugin action.

The method AbstractLicenseMojo.execute() invoke this method only and only if :

Specified by:
doAction in class AbstractLicenseMojo
Throws:
Exception - if any

processCommentStyle

protected void processCommentStyle(String commentStyle,
                                   List<File> filesToTreat)
                            throws IOException
Throws:
IOException

prepareProcessFile

protected void prepareProcessFile(File file)
                           throws IOException
Throws:
IOException

processFile

protected boolean processFile(File file,
                              File processFile)
                       throws IOException
Process the given file and save the result in the given processFile.

Parameters:
file - the file to process
processFile - the ouput processed file
Returns:
true if prepareProcessFile can be finalize, otherwise need to be delete
Throws:
IOException - if any pb while treatment

finalizeFile

protected void finalizeFile(File file,
                            File processFile)
                     throws IOException
Throws:
IOException

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable

clear

protected void clear()

reportType

protected void reportType(org.codehaus.mojo.license.UpdateFileHeaderMojo.FileState state,
                          StringBuilder buffer)

buildDefaultFileHeader

protected FileHeader buildDefaultFileHeader(License license,
                                            String projectName,
                                            String inceptionYear,
                                            String copyrightHolder,
                                            boolean addSvnKeyWords,
                                            String encoding)
                                     throws IOException
Build a default header given the parameters.

Parameters:
license - the license type ot use in header
projectName - project name as header description
inceptionYear - first year of copyright
copyrightHolder - holder of copyright
encoding - encoding used to read or write files
addSvnKeyWords - a flag to add in description section svn keywords
Returns:
the new file header
Throws:
IOException - if any problem while creating file header

getTransformer

public FileHeaderTransformer getTransformer(String transformerName)
                                     throws IllegalArgumentException,
                                            IllegalStateException
Throws:
IllegalArgumentException
IllegalStateException

isClearAfterOperation

public boolean isClearAfterOperation()

getTimestamp

public long getTimestamp()

getProjectName

public String getProjectName()

getInceptionYear

public String getInceptionYear()

getOrganizationName

public String getOrganizationName()

isUpdateCopyright

public boolean isUpdateCopyright()

isCanUpdateDescription

public boolean isCanUpdateDescription()

isCanUpdateCopyright

public boolean isCanUpdateCopyright()

isCanUpdateLicense

public boolean isCanUpdateLicense()

getIgnoreTag

public String getIgnoreTag()

isDryRun

public boolean isDryRun()

getFilter

public UpdateFileHeaderFilter getFilter()

getFileHeader

public FileHeader getFileHeader()
Specified by:
getFileHeader in interface FileHeaderProcessorConfiguration
Returns:
the current file header to use

getTransformer

public FileHeaderTransformer getTransformer()
Specified by:
getTransformer in interface FileHeaderProcessorConfiguration
Returns:
the current file transformer to use

isSkip

public boolean isSkip()
Description copied from class: AbstractLicenseNameMojo
When is sets to true, will skip execution.

This will take effects in method AbstractLicenseNameMojo.checkSkip(). So the method AbstractLicenseMojo.doAction() will never be invoked.

Specified by:
isSkip in class AbstractLicenseNameMojo
Returns:
true if goal will not be executed

getProcessedFiles

public Set<File> getProcessedFiles()

getResult

public EnumMap<org.codehaus.mojo.license.UpdateFileHeaderMojo.FileState,Set<File>> getResult()

getFiles

public Set<File> getFiles(org.codehaus.mojo.license.UpdateFileHeaderMojo.FileState state)

isAddSvnKeyWords

public boolean isAddSvnKeyWords()

getProcessor

public FileHeaderProcessor getProcessor()

getTransformers

public Map<String,FileHeaderTransformer> getTransformers()

getFilesToTreateByCommentStyle

public Map<String,List<File>> getFilesToTreateByCommentStyle()

setSkip

public void setSkip(boolean skipUpdateLicense)
Description copied from class: AbstractLicenseNameMojo
Changes internal state skip to execute (or not) goal.

Specified by:
setSkip in class AbstractLicenseNameMojo
Parameters:
skipUpdateLicense - new state value

setDryRun

public void setDryRun(boolean dryRun)

setTimestamp

public void setTimestamp(long timestamp)

setProjectName

public void setProjectName(String projectName)

setSkipUpdateLicense

public void setSkipUpdateLicense(boolean skipUpdateLicense)

setInceptionYear

public void setInceptionYear(String inceptionYear)

setOrganizationName

public void setOrganizationName(String organizationName)

setUpdateCopyright

public void setUpdateCopyright(boolean updateCopyright)

setIgnoreTag

public void setIgnoreTag(String ignoreTag)

setAddSvnKeyWords

public void setAddSvnKeyWords(boolean addSvnKeyWords)

setClearAfterOperation

public void setClearAfterOperation(boolean clearAfterOperation)

setTransformer

public void setTransformer(FileHeaderTransformer transformer)

setHeader

public void setHeader(FileHeader header)

setProcessor

public void setProcessor(FileHeaderProcessor processor)

setFilter

public void setFilter(UpdateFileHeaderFilter filter)

setCanUpdateDescription

public void setCanUpdateDescription(boolean canUpdateDescription)

setCanUpdateCopyright

public void setCanUpdateCopyright(boolean canUpdateCopyright)

setCanUpdateLicense

public void setCanUpdateLicense(boolean canUpdateLicense)

setTransformers

public void setTransformers(Map<String,FileHeaderTransformer> transformers)

setFilesToTreateByCommentStyle

public void setFilesToTreateByCommentStyle(Map<String,List<File>> filesToTreateByCommentStyle)

setRoots

public void setRoots(String[] roots)

setRoots

public void setRoots(String roots)

setIncludes

public void setIncludes(String[] includes)

setIncludes

public void setIncludes(String includes)

setExcludes

public void setExcludes(String[] excludes)

setExcludes

public void setExcludes(String excludes)

getFilesToTreateForRoots

protected void getFilesToTreateForRoots(String[] includes,
                                        String[] excludes,
                                        List<String> roots,
                                        Map<File,String[]> files)
Collects some file.

Parameters:
includes - includes
excludes - excludes
roots - root directories to treate
files - cache of file detected indexed by their root directory


Copyright © 2010-2012 The Kuali Foundation. All Rights Reserved.