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  class FileConsumer
30      implements StreamConsumer
31  {
32      private Pattern filePattern;
33  
34      public FileConsumer( List<File> matchedFilesAccumulator, Pattern filematcher )
35      {
36          this.matchedFiles = matchedFilesAccumulator;
37          this.filePattern = filematcher;
38      }
39  
40      public List<File> matchedFiles;
41  
42      // TODO make these an enum
43      public static final Pattern ADD_PATTERN = Pattern.compile( "Added and kept element [/\\\\]\\.[/\\\\](\\S+)\\s*" );
44  
45      public static final Pattern UPDATE_PATTERN = Pattern
46          .compile( "Updating element [/\\\\]\\.[/\\\\](\\S+)\\s*|Content.*of \"(.*)\".*" );
47  
48      public static final Pattern POPULATE_PATTERN = Pattern.compile( "Populating element [/\\\\]\\.[/\\\\](\\S+)\\s*" );
49  
50      public static final Pattern PROMOTE_PATTERN = Pattern.compile( "Promoted element [/\\\\]\\.[/\\\\](\\S+)\\s*" );
51  
52      public static final Pattern STAT_PATTERN = Pattern.compile( "[/\\\\]\\.[/\\\\](.*)" );
53  
54      /**
55       * TODO - The removed files are relative to the workspace top, not the basedir of the fileset
56       */
57      public static final Pattern DEFUNCT_PATTERN = Pattern.compile( "Removing \"(\\S+)\".*" );
58  
59      public void consumeLine( String line )
60      {
61  
62          Matcher m = filePattern.matcher( line );
63          if ( m.matches() )
64          {
65  
66              int i = 1;
67              String fileName = null;
68              while ( fileName == null && i <= m.groupCount() )
69              {
70                  fileName = m.group( i++ );
71              }
72  
73              if ( fileName != null )
74              {
75                  matchedFiles.add( new File( fileName ) );
76              }
77          }
78  
79      }
80  }