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.Object
Add 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.String
DOT
private static int[]
EXPECTS_AT_ECHO
private static int[]
EXPECTS_HASH_PLING
private static int[]
EXPECTS_MSVSSF_HEADER
private static int[]
EXPECTS_PACKAGE
private static int[]
EXPECTS_PHP_PI
private static int[]
EXPECTS_XML_DECL
private static java.util.Map<java.lang.String,java.lang.Integer>
EXT2TYPE
private static int[]
FAMILY_APT
private static int[]
FAMILY_BAT
private static int[]
FAMILY_C
private static int[]
FAMILY_SGML
private static int[]
FAMILY_SH
private static int[]
FAMILY_VELOCITY
private boolean
isForced
private static java.lang.String
LINE_SEP
the line separator for this OSprivate static int
TYPE_APT
private static int
TYPE_BAT
private static int
TYPE_BEANSHELL
private static int
TYPE_C
private static int
TYPE_CPP
private static int
TYPE_CSHARP
private static int
TYPE_CSS
private static int
TYPE_FML
private static int
TYPE_GO
private static int
TYPE_GROOVY
private static int
TYPE_H
private static int
TYPE_HTML
private static int
TYPE_JAVA
private static int
TYPE_JAVASCRIPT
private static int
TYPE_JSP
private static int
TYPE_PERL
private static int
TYPE_PHP
private static int
TYPE_PM
private static int
TYPE_PROPERTIES
private static int
TYPE_PYTHON
private static int
TYPE_RUBY
private static int
TYPE_SCALA
private static int
TYPE_SH
private static int
TYPE_TCL
private static int
TYPE_UNKNOWN
private static int
TYPE_VISUAL_STUDIO_SOLUTION
private static int
TYPE_VM
private static int
TYPE_XML
-
Constructor Summary
Constructors Constructor Description AbstractLicenseAppender()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
append(java.io.File document)
Append the default license header to the supplied document.private boolean
attachLicense(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 void
doFirstLine(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 boolean
expectsAtEcho(int type)
private static boolean
expectsHashPling(int type)
private static boolean
expectsMSVisualStudioSolutionFileHeader(int type)
private static boolean
expectsPackage(int type)
private static boolean
expectsPhpPI(int type)
private static boolean
expectsXMLDecl(int type)
protected java.lang.String
getFirstLine(int type)
Get the first line of the license header formatted for the given type of file.protected java.lang.String
getLastLine(int type)
Get the last line of the license header formatted for the given type of file.abstract java.lang.String
getLicenseHeader(java.io.File document)
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.protected int
getType(java.io.File document)
Detect the type of document.private static boolean
isFamilyAPT(int type)
private static boolean
isFamilyBAT(int type)
private static boolean
isFamilyC(int type)
private static boolean
isFamilySGML(int type)
private static boolean
isFamilySH(int type)
private static boolean
isFamilyVelocity(int type)
private static boolean
isIn(int[] arr, int key)
private java.lang.String
passThroughReadNext(java.io.Writer writer, java.lang.String line, java.io.BufferedReader br)
void
setForce(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.IOException
Append 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.IOException
Write 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.IOException
Check 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
-
-