Package org.apache.rat.annotation
Class AbstractLicenseAppender
- java.lang.Object
-
- org.apache.rat.annotation.AbstractLicenseAppender
-
- Direct Known Subclasses:
ApacheV2LicenseAppender
public abstract class AbstractLicenseAppender extends java.lang.ObjectAdd a license header to a document. This appender does not check for the existence of an existing license header, it is assumed that either a second license header is intentional or that there is no license header present already.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringDOTprivate static int[]EXPECTS_AT_ECHOprivate static int[]EXPECTS_HASH_PLINGprivate static int[]EXPECTS_MSVSSF_HEADERprivate static int[]EXPECTS_PACKAGEprivate static int[]EXPECTS_PHP_PIprivate static int[]EXPECTS_XML_DECLprivate static java.util.Map<java.lang.String,java.lang.Integer>EXT2TYPEprivate static int[]FAMILY_APTprivate static int[]FAMILY_BATprivate static int[]FAMILY_Cprivate static int[]FAMILY_SGMLprivate static int[]FAMILY_SHprivate static int[]FAMILY_VELOCITYprivate booleanisForcedprivate static java.lang.StringLINE_SEPthe line separator for this OSprivate static intTYPE_APTprivate static intTYPE_BATprivate static intTYPE_BEANSHELLprivate static intTYPE_Cprivate static intTYPE_CPPprivate static intTYPE_CSHARPprivate static intTYPE_CSSprivate static intTYPE_FMLprivate static intTYPE_GOprivate static intTYPE_GROOVYprivate static intTYPE_Hprivate static intTYPE_HTMLprivate static intTYPE_JAVAprivate static intTYPE_JAVASCRIPTprivate static intTYPE_JSPprivate static intTYPE_PERLprivate static intTYPE_PHPprivate static intTYPE_PMprivate static intTYPE_PROPERTIESprivate static intTYPE_PYTHONprivate static intTYPE_RUBYprivate static intTYPE_SCALAprivate static intTYPE_SHprivate static intTYPE_TCLprivate static intTYPE_UNKNOWNprivate static intTYPE_VISUAL_STUDIO_SOLUTIONprivate static intTYPE_VMprivate static intTYPE_XML
-
Constructor Summary
Constructors Constructor Description AbstractLicenseAppender()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidappend(java.io.File document)Append the default license header to the supplied document.private booleanattachLicense(java.io.Writer writer, java.io.File document, boolean expectsHashPling, boolean expectsAtEcho, boolean expectsPackage, boolean expectsXMLDecl, boolean expectsPhpPI, boolean expectsMSVSSF)Write document's content to writer attaching the license using the given flags as hints for where to put it.private voiddoFirstLine(java.io.File document, java.io.Writer writer, java.lang.String line, java.lang.String lookfor)Check first line for specified text and process.private static booleanexpectsAtEcho(int type)private static booleanexpectsHashPling(int type)private static booleanexpectsMSVisualStudioSolutionFileHeader(int type)private static booleanexpectsPackage(int type)private static booleanexpectsPhpPI(int type)private static booleanexpectsXMLDecl(int type)protected java.lang.StringgetFirstLine(int type)Get the first line of the license header formatted for the given type of file.protected java.lang.StringgetLastLine(int type)Get the last line of the license header formatted for the given type of file.abstract java.lang.StringgetLicenseHeader(java.io.File document)protected java.lang.StringgetLine(int type, java.lang.String content)Get a line of the license header formatted for the given type of file.protected intgetType(java.io.File document)Detect the type of document.private static booleanisFamilyAPT(int type)private static booleanisFamilyBAT(int type)private static booleanisFamilyC(int type)private static booleanisFamilySGML(int type)private static booleanisFamilySH(int type)private static booleanisFamilyVelocity(int type)private static booleanisIn(int[] arr, int key)private java.lang.StringpassThroughReadNext(java.io.Writer writer, java.lang.String line, java.io.BufferedReader br)voidsetForce(boolean force)Set the force flag on this appender.
-
-
-
Field Detail
-
DOT
private static final java.lang.String DOT
- See Also:
- Constant Field Values
-
TYPE_UNKNOWN
private static final int TYPE_UNKNOWN
- See Also:
- Constant Field Values
-
TYPE_JAVA
private static final int TYPE_JAVA
- See Also:
- Constant Field Values
-
TYPE_XML
private static final int TYPE_XML
- See Also:
- Constant Field Values
-
TYPE_HTML
private static final int TYPE_HTML
- See Also:
- Constant Field Values
-
TYPE_CSS
private static final int TYPE_CSS
- See Also:
- Constant Field Values
-
TYPE_JAVASCRIPT
private static final int TYPE_JAVASCRIPT
- See Also:
- Constant Field Values
-
TYPE_APT
private static final int TYPE_APT
- See Also:
- Constant Field Values
-
TYPE_PROPERTIES
private static final int TYPE_PROPERTIES
- See Also:
- Constant Field Values
-
TYPE_PYTHON
private static final int TYPE_PYTHON
- See Also:
- Constant Field Values
-
TYPE_C
private static final int TYPE_C
- See Also:
- Constant Field Values
-
TYPE_H
private static final int TYPE_H
- See Also:
- Constant Field Values
-
TYPE_SH
private static final int TYPE_SH
- See Also:
- Constant Field Values
-
TYPE_BAT
private static final int TYPE_BAT
- See Also:
- Constant Field Values
-
TYPE_VM
private static final int TYPE_VM
- See Also:
- Constant Field Values
-
TYPE_SCALA
private static final int TYPE_SCALA
- See Also:
- Constant Field Values
-
TYPE_RUBY
private static final int TYPE_RUBY
- See Also:
- Constant Field Values
-
TYPE_PERL
private static final int TYPE_PERL
- See Also:
- Constant Field Values
-
TYPE_TCL
private static final int TYPE_TCL
- See Also:
- Constant Field Values
-
TYPE_CPP
private static final int TYPE_CPP
- See Also:
- Constant Field Values
-
TYPE_CSHARP
private static final int TYPE_CSHARP
- See Also:
- Constant Field Values
-
TYPE_PHP
private static final int TYPE_PHP
- See Also:
- Constant Field Values
-
TYPE_GROOVY
private static final int TYPE_GROOVY
- See Also:
- Constant Field Values
-
TYPE_VISUAL_STUDIO_SOLUTION
private static final int TYPE_VISUAL_STUDIO_SOLUTION
- See Also:
- Constant Field Values
-
TYPE_BEANSHELL
private static final int TYPE_BEANSHELL
- See Also:
- Constant Field Values
-
TYPE_JSP
private static final int TYPE_JSP
- See Also:
- Constant Field Values
-
TYPE_FML
private static final int TYPE_FML
- See Also:
- Constant Field Values
-
TYPE_GO
private static final int TYPE_GO
- See Also:
- Constant Field Values
-
TYPE_PM
private static final int TYPE_PM
- See Also:
- Constant Field Values
-
LINE_SEP
private static final java.lang.String LINE_SEP
the line separator for this OS
-
FAMILY_C
private static final int[] FAMILY_C
-
FAMILY_SGML
private static final int[] FAMILY_SGML
-
FAMILY_SH
private static final int[] FAMILY_SH
-
FAMILY_BAT
private static final int[] FAMILY_BAT
-
FAMILY_APT
private static final int[] FAMILY_APT
-
FAMILY_VELOCITY
private static final int[] FAMILY_VELOCITY
-
EXPECTS_HASH_PLING
private static final int[] EXPECTS_HASH_PLING
-
EXPECTS_AT_ECHO
private static final int[] EXPECTS_AT_ECHO
-
EXPECTS_PACKAGE
private static final int[] EXPECTS_PACKAGE
-
EXPECTS_XML_DECL
private static final int[] EXPECTS_XML_DECL
-
EXPECTS_PHP_PI
private static final int[] EXPECTS_PHP_PI
-
EXPECTS_MSVSSF_HEADER
private static final int[] EXPECTS_MSVSSF_HEADER
-
EXT2TYPE
private static final java.util.Map<java.lang.String,java.lang.Integer> EXT2TYPE
-
isForced
private boolean isForced
-
-
Method Detail
-
append
public void append(java.io.File document) throws java.io.IOExceptionAppend the default license header to the supplied document.- Parameters:
document- document to append to.- Throws:
java.io.IOException- if there is a problem while reading or writing the file
-
attachLicense
private boolean attachLicense(java.io.Writer writer, java.io.File document, boolean expectsHashPling, boolean expectsAtEcho, boolean expectsPackage, boolean expectsXMLDecl, boolean expectsPhpPI, boolean expectsMSVSSF) throws java.io.IOExceptionWrite document's content to writer attaching the license using the given flags as hints for where to put it.- Returns:
- whether the license has actually been written
- Throws:
java.io.IOException
-
doFirstLine
private void doFirstLine(java.io.File document, java.io.Writer writer, java.lang.String line, java.lang.String lookfor) throws java.io.IOExceptionCheck first line for specified text and process.- Throws:
java.io.IOException
-
getType
protected int getType(java.io.File document)
Detect the type of document.- Parameters:
document- to retrieve type from.- Returns:
- not null TODO use existing mechanism to detect the type of a file and record it in the report output, thus we will not need this duplication here.
-
setForce
public void setForce(boolean force)
Set the force flag on this appender. If this flag is set to true then files will be modified directly, otherwise new files will be created alongside the existing files.- Parameters:
force- force flag.
-
getLicenseHeader
public abstract java.lang.String getLicenseHeader(java.io.File document)
- Parameters:
document- document to extract from.- Returns:
- Get the license header of a document.
-
getFirstLine
protected java.lang.String getFirstLine(int type)
Get the first line of the license header formatted for the given type of file.- Parameters:
type- the type of file, see the TYPE_* constants- Returns:
- not null
-
getLastLine
protected java.lang.String getLastLine(int type)
Get the last line of the license header formatted for the given type of file.- Parameters:
type- the type of file, see the TYPE_* constants- Returns:
- not null
-
getLine
protected java.lang.String getLine(int type, java.lang.String content)Get a line of the license header formatted for the given type of file.- Parameters:
type- the type of file, see the TYPE_* constantscontent- the content for this line- Returns:
- not null
-
isFamilyC
private static boolean isFamilyC(int type)
-
isFamilySGML
private static boolean isFamilySGML(int type)
-
isFamilySH
private static boolean isFamilySH(int type)
-
isFamilyAPT
private static boolean isFamilyAPT(int type)
-
isFamilyBAT
private static boolean isFamilyBAT(int type)
-
isFamilyVelocity
private static boolean isFamilyVelocity(int type)
-
expectsHashPling
private static boolean expectsHashPling(int type)
-
expectsAtEcho
private static boolean expectsAtEcho(int type)
-
expectsPackage
private static boolean expectsPackage(int type)
-
expectsXMLDecl
private static boolean expectsXMLDecl(int type)
-
expectsPhpPI
private static boolean expectsPhpPI(int type)
-
expectsMSVisualStudioSolutionFileHeader
private static boolean expectsMSVisualStudioSolutionFileHeader(int type)
-
isIn
private static boolean isIn(int[] arr, int key)
-
passThroughReadNext
private java.lang.String passThroughReadNext(java.io.Writer writer, java.lang.String line, java.io.BufferedReader br) throws java.io.IOException- Throws:
java.io.IOException
-
-