Class 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.
    • Constructor Detail

      • AbstractLicenseAppender

        public AbstractLicenseAppender()
    • 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_* constants
        content - 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