1 package org.apache.maven.scm.provider.jazz.command.add;
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 org.apache.maven.scm.ScmFile;
23 import org.apache.maven.scm.ScmFileStatus;
24 import org.apache.maven.scm.log.ScmLogger;
25 import org.apache.maven.scm.provider.ScmProviderRepository;
26 import org.apache.maven.scm.provider.jazz.command.consumer.AbstractRepositoryConsumer;
27
28 import java.io.File;
29 import java.util.ArrayList;
30 import java.util.List;
31
32 /**
33 * Consume the output of the scm command for the "add" operation.
34 *
35 * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a>
36 */
37 public class JazzAddConsumer
38 extends AbstractRepositoryConsumer
39 {
40 // A flag to indicate that we have seen the "Changes:" line in the output.
41 // After that, we have the files themselves.
42 private boolean haveSeenChanges = false;
43
44 protected String fCurrentDir = "";
45
46 // The list of files that we have checked in.
47 private List<ScmFile> fCheckedInFiles = new ArrayList<ScmFile>();
48
49 /**
50 * Construct the JazzAddCommand consumer.
51 *
52 * @param repository The repository we are working with.
53 * @param logger The logger to use.
54 */
55 public JazzAddConsumer( ScmProviderRepository repository, ScmLogger logger )
56 {
57 super( repository, logger );
58 }
59
60 /**
61 * Process one line of output from the execution of the "scm xxxx" command.
62 *
63 * @param line The line of output from the external command that has been pumped to us.
64 * @see org.codehaus.plexus.util.cli.StreamConsumer#consumeLine(java.lang.String)
65 */
66 public void consumeLine( String line )
67 {
68 super.consumeLine( line );
69 // The Jazz SCM "checkin" command does not output a list of each file that was checked in.
70 // An example output is shown below, perhaps in the future we may need to
71 // consume the "Workspace", "Component", Stream or "Change sets"
72
73 /*
74 Committing...
75 Workspace: (1004) "Release Repository Workspace" <-> (1005) "Maven Release Plugin Stream"
76 Component: (1006) "Release Component"
77 Outgoing:
78 Change sets:
79 (1008) --@ <No comment>
80
81 Or:
82
83 Committing...
84 Workspace: (1903) "MavenSCMTestWorkspace_1332908068770" <-> (1903) "MavenSCMTestWorkspace_1332908068770"
85 Component: (1768) "MavenSCMTestComponent"
86 Outgoing:
87 Change sets:
88 (1907) *--@ "Commit message"
89 Changes:
90 --a-- \src\main\java\Me.java
91 --a-- \src\main\java\Me1.java
92 --a-- \src\main\java\Me2.java
93 */
94
95 if ( haveSeenChanges )
96 {
97 // We have already seen the "Changes:" line, so we must now be processing files.
98 String trimmed = line.trim();
99 int spacePos = trimmed.indexOf( " " );
100 // NOTE: The second + 1 is to remove the leading slash
101 String path = trimmed.substring( spacePos + 1 + 1 );
102 fCheckedInFiles.add( new ScmFile( path, ScmFileStatus.CHECKED_OUT ) );
103 }
104 else
105 {
106 if ( "Changes:".equals( line.trim() ) )
107 {
108 haveSeenChanges = true;
109 }
110 }
111 }
112
113 protected ScmFile getScmFile( String filename )
114 {
115 return new ScmFile( new File( fCurrentDir, filename ).getAbsolutePath(), ScmFileStatus.CHECKED_OUT );
116 }
117
118 public List<ScmFile> getFiles()
119 {
120 return fCheckedInFiles;
121 }
122 }