gerrithudsontrigger/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritDynamicUrlProcessor.java
/**
     * Read and parse the dynamic trigger configuration
     * @param reader stream from which to read the config
     * @return List of Gerrit projects
     * @throws ParseException when the fetched content couldn't be parsed
     * @throws IOException for all other kinds of fetch errors
     */
Read and parse the dynamic trigger configuration
@param reader stream from which to read the config
@return List of Gerrit projects
@throws ParseException when the fetched content couldn't be parsed
@throws IOException for all other kinds of fetch errors
Read and parse the dynamic trigger configuration @param reader stream from which to read the config @return List of Gerrit projects @throws ParseException when the fetched content couldn ' t be parsed @throws IOException for all other kinds of fetch errors
private static List<GerritProject> readAndParseTriggerConfig(BufferedReader reader)
            throws IOException, ParseException {
      Pattern linePattern = buildLinePattern();
      List<GerritProject> dynamicGerritProjects = new ArrayList<GerritProject>();
      List<Branch> branches = null;
      List<FilePath> filePaths = null;
      GerritProject dynamicGerritProject = null;
      String line = "";
      int lineNr = 0;
      while ((line = reader.readLine()) != null) {
        ++lineNr;
        int commentPos = line.indexOf('#');
        if (commentPos > -1) {
          line = line.substring(0, commentPos);
        }
        commentPos = line.indexOf(';');
        if (commentPos > -1) {
          line = line.substring(0, commentPos);
        }
        line = line.trim();
        if (line.isEmpty()) {
          continue;
        }
        Matcher matcher = linePattern.matcher(line);
        if (!matcher.matches()) {
          throw new ParseException("Line " + lineNr + ": cannot parse '" + line + "'", lineNr);
        }
        String item = matcher.group(1);
        String oper = matcher.group(2);
        String text = matcher.group(3);
        if (item == null || oper == null || text == null) {
          throw new ParseException("Line " + lineNr + ": cannot parse '" + line + "'", lineNr);
        }
        char operChar = oper.charAt(0);
        CompareType type = CompareType.findByOperator(operChar);
        logger.trace("==> item:({0}) oper:({1}) text:({2})", new Object[]{item, oper, text});
        if (SHORTNAME_PROJECT.equals(item)) { 
          if (dynamicGerritProject != null) {
            dynamicGerritProjects.add(dynamicGerritProject);
          }
          branches = new ArrayList<Branch>();
          filePaths = new ArrayList<FilePath>();
          dynamicGerritProject = new GerritProject(type, text, branches, filePaths);
        } else if (SHORTNAME_BRANCH.equals(item)) { 
          if (branches == null) {
            throw new ParseException("Line " + lineNr + ": attempt to use 'Branch' before 'Project'", lineNr);
          }
          Branch branch = new Branch(type, text);
          branches.add(branch);
          dynamicGerritProject.setBranches(branches);
        } else { 
          if (filePaths == null) {
            throw new ParseException("Line " + lineNr + ": attempt to use 'FilePath' before 'Project'", lineNr);
          }
          FilePath filePath = new FilePath(type, text);
          filePaths.add(filePath);
          dynamicGerritProject.setFilePaths(filePaths);
        }
      }
      if (dynamicGerritProject != null) {
        dynamicGerritProjects.add(dynamicGerritProject);
      }
      return dynamicGerritProjects;
    }
private static List < GerritProject > readAndParseTriggerConfig ( BufferedReader reader ) throws IOException , ParseException { Pattern linePattern = buildLinePattern ( ) ; List < GerritProject > dynamicGerritProjects = new ArrayList < GerritProject > ( ) ; List < Branch > branches = null ; List < FilePath > filePaths = null ; GerritProject dynamicGerritProject = null ; String line = "" ; int lineNr = 0 ; while ( ( line = reader . readLine ( ) ) != null ) { ++ lineNr ; int commentPos = line . indexOf ( '#' ) ; if ( commentPos > - 1 ) { line = line . substring ( 0 , commentPos ) ; } commentPos = line . indexOf ( ';' ) ; if ( commentPos > - 1 ) { line = line . substring ( 0 , commentPos ) ; } line = line . trim ( ) ; if ( line . isEmpty ( ) ) { continue ; } Matcher matcher = linePattern . matcher ( line ) ; if ( ! matcher . matches ( ) ) { throw new ParseException ( "Line " + lineNr + ": cannot parse '" + line + "'" , lineNr ) ; } String item = matcher . group ( 1 ) ; String oper = matcher . group ( 2 ) ; String text = matcher . group ( 3 ) ; if ( item == null || oper == null || text == null ) { throw new ParseException ( "Line " + lineNr + ": cannot parse '" + line + "'" , lineNr ) ; } char operChar = oper . charAt ( 0 ) ; CompareType type = CompareType . findByOperator ( operChar ) ; logger . trace ( "==> item:({0}) oper:({1}) text:({2})" , new Object [ ] { item , oper , text } ) ; if ( SHORTNAME_PROJECT . equals ( item ) ) { if ( dynamicGerritProject != null ) { dynamicGerritProjects . add ( dynamicGerritProject ) ; } branches = new ArrayList < Branch > ( ) ; filePaths = new ArrayList < FilePath > ( ) ; dynamicGerritProject = new GerritProject ( type , text , branches , filePaths ) ; } else if ( SHORTNAME_BRANCH . equals ( item ) ) { if ( branches == null ) { throw new ParseException ( "Line " + lineNr + ": attempt to use 'Branch' before 'Project'" , lineNr ) ; } Branch branch = new Branch ( type , text ) ; branches . add ( branch ) ; dynamicGerritProject . setBranches ( branches ) ; } else { if ( filePaths == null ) { throw new ParseException ( "Line " + lineNr + ": attempt to use 'FilePath' before 'Project'" , lineNr ) ; } FilePath filePath = new FilePath ( type , text ) ; filePaths . add ( filePath ) ; dynamicGerritProject . setFilePaths ( filePaths ) ; } } if ( dynamicGerritProject != null ) { dynamicGerritProjects . add ( dynamicGerritProject ) ; } return dynamicGerritProjects ; }
Read and parse the dynamic trigger configuration
 @param reader stream from which to read the config
 @return List of Gerrit projects
 @throws ParseException when the fetched content couldn't be parsed
 @throws IOException for all other kinds of fetch errors
Read and parse the dynamic trigger configuration @param reader stream from which to read the config @return List of Gerrit projects @throws ParseException when the fetched content couldn ' t be parsed @throws IOException for all other kinds of fetch errors
// Remove any comments starting with a # // Remove any comments starting with a ; // Trim leading and trailing whitespace // CS IGNORE MagicNumber FOR NEXT 3 LINES. REASON: ConstantsNotNeeded // Project // stash previous project to the list // Branch // FilePath (because it must be an 'f') // Finally stash the last project to the list