View Javadoc
1   package org.apache.maven.scm.provider.accurev.cli;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *    http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.util.List;
24  import java.util.regex.Matcher;
25  import java.util.regex.Pattern;
26  
27  import org.codehaus.plexus.util.cli.StreamConsumer;
28  
29  /**
30   * 
31   */
32  class FileConsumer
33      implements StreamConsumer
34  {
35      private Pattern filePattern;
36  
37      public FileConsumer( List<File> matchedFilesAccumulator, Pattern filematcher )
38      {
39          this.matchedFiles = matchedFilesAccumulator;
40          this.filePattern = filematcher;
41      }
42  
43      private List<File> matchedFiles;
44  
45      // TODO make these an enum
46      public static final Pattern ADD_PATTERN = Pattern.compile( "Added and kept element [/\\\\]\\.[/\\\\](\\S+)\\s*" );
47  
48      public static final Pattern UPDATE_PATTERN = Pattern
49          .compile( "Updating element [/\\\\]\\.[/\\\\](\\S+)\\s*|Content.*of \"(.*)\".*" );
50  
51      public static final Pattern POPULATE_PATTERN = Pattern.compile( "Populating element [/\\\\]\\.[/\\\\](\\S+)\\s*" );
52  
53      public static final Pattern PROMOTE_PATTERN = Pattern.compile( "Promoted element [/\\\\]\\.[/\\\\](\\S+)\\s*" );
54  
55      public static final Pattern STAT_PATTERN = Pattern.compile( "[/\\\\]\\.[/\\\\](.*)" );
56  
57      /**
58       * TODO - The removed files are relative to the workspace top, not the basedir of the fileset
59       */
60      public static final Pattern DEFUNCT_PATTERN = Pattern.compile( "Removing \"(\\S+)\".*" );
61  
62      public void consumeLine( String line )
63      {
64  
65          Matcher m = filePattern.matcher( line );
66          if ( m.matches() )
67          {
68  
69              int i = 1;
70              String fileName = null;
71              while ( fileName == null && i <= m.groupCount() )
72              {
73                  fileName = m.group( i++ );
74              }
75  
76              if ( fileName != null )
77              {
78                  matchedFiles.add( new File( fileName ) );
79              }
80          }
81  
82      }
83  }