Class MessagesSourceCrawler


  • public class MessagesSourceCrawler
    extends Object
    This class takes care of crawling through the source code
    Author:
    matt
    • Constructor Detail

      • MessagesSourceCrawler

        public MessagesSourceCrawler​(org.pentaho.di.core.logging.LogChannelInterface log,
                                     List<String> sourceDirectories,
                                     String singleMessagesFile,
                                     List<SourceCrawlerXMLFolder> xmlFolders)
        Parameters:
        sourceDirectories - The source directories to crawl through
        singleMessagesFile - the messages file if there is only one, otherwise: null
    • Method Detail

      • addKeyOccurrence

        public void addKeyOccurrence​(KeyOccurrence occ)
        Add a key occurrence to the list of occurrences. The list is kept sorted on key and message package. If the key already exists, we increment the number of occurrences.
        Parameters:
        occ - The key occurrence to add
      • crawlSourceDirectories

        public void crawlSourceDirectories()
                                    throws Exception
        Throws:
        Exception
      • lookForOccurrencesInFile

        public void lookForOccurrencesInFile​(String sourceFolder,
                                             org.apache.commons.vfs2.FileObject javaFile)
                                      throws IOException
        Look for occurrences of keys in the specified file.
        Parameters:
        sourceFolder - The folder the java file and messages files live in
        javaFile - The java source file to examine
        Throws:
        IOException - In case there is a problem accessing the specified source file.
      • lookForOccurrencesInLine

        protected void lookForOccurrencesInLine​(String sourceFolder,
                                                org.apache.commons.vfs2.FileObject javaFile,
                                                String messagesPackage,
                                                int row,
                                                String line)
        Look for occurrences of keys in the specified line.
        Parameters:
        sourceFolder - the folder where the file that contains the line to examine exists
        javaFile - the java source file that contains the line to examine
        messagesPackage - the message package used
        row - the row number
        line - the line to examine
      • getSplitLinePhrases

        protected List<String> getSplitLinePhrases​(String scanPhrase)

        Returns all regex expressions to detect when the given scanPhrase is incomplete (existing over more than one source line).

        Parameters:
        scanPhrase - the scanPhrase to consider
        Returns:
        all regex expressions to detect when the given scanPhrase is incomplete
        See Also:
        getSplitLinePhrases(String[])
      • getWhitespacesSanitizeRegex

        protected String getWhitespacesSanitizeRegex​(String str)

        Calculates a regex to identify the given text considering all possible SPLIT_CHARACTERS can be surrounded by whitespaces.

        Parameters:
        str - the text to be used
        Returns:
        regex to identify the given text considering all possible SPLIT_CHARACTERS can be surrounded by whitespaces
      • getMessagesPackagesList

        public List<String> getMessagesPackagesList​(String sourceFolder)
        Returns:
        A sorted List of distinct occurrences of the used message package names
      • getOccurrencesForPackage

        public List<KeyOccurrence> getOccurrencesForPackage​(String messagesPackage)
        Get all the key occurrences for a certain messages package.
        Parameters:
        messagesPackage - the package to hunt for
        Returns:
        all the key occurrences for a certain messages package.
      • getKeyOccurrences

        public List<KeyOccurrence> getKeyOccurrences​(String sourceFolder)
        Get the unique package-key
        Parameters:
        sourceFolder -
      • getSourceDirectories

        public List<String> getSourceDirectories()
        Returns:
        the List of source directories to crawl through
      • setSourceDirectories

        public void setSourceDirectories​(List<String> sourceDirectories)
        Parameters:
        sourceDirectories - the List of source directories to crawl through
      • getFilesToAvoid

        public List<String> getFilesToAvoid()
        Returns:
        the List of files to avoid
      • setFilesToAvoid

        public void setFilesToAvoid​(List<String> filesToAvoid)
        Parameters:
        filesToAvoid - the List of files to avoid
      • getSingleMessagesFile

        public String getSingleMessagesFile()
        Returns:
        the singleMessagesFile
      • setSingleMessagesFile

        public void setSingleMessagesFile​(String singleMessagesFile)
        Parameters:
        singleMessagesFile - the singleMessagesFile to set
      • getScanPhrases

        public String[] getScanPhrases()
        Returns:
        the scanPhrases to search for
      • setScanPhrases

        public void setScanPhrases​(String[] scanPhrases)
        Parameters:
        scanPhrases - the scanPhrases to search for
      • setSourcePackageOccurrences

        public void setSourcePackageOccurrences​(Map<String,​Map<String,​List<KeyOccurrence>>> sourcePackageOccurrences)
        Parameters:
        sourcePackageOccurrences - the sourcePackageOccurrences to set