1 package org.apache.maven.scm.provider.jazz.command.update;
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.ScmException;
23 import org.apache.maven.scm.ScmFile;
24 import org.apache.maven.scm.ScmFileSet;
25 import org.apache.maven.scm.ScmVersion;
26 import org.apache.maven.scm.command.changelog.ChangeLogCommand;
27 import org.apache.maven.scm.command.update.AbstractUpdateCommand;
28 import org.apache.maven.scm.command.update.UpdateScmResult;
29 import org.apache.maven.scm.provider.ScmProviderRepository;
30 import org.apache.maven.scm.provider.jazz.command.JazzConstants;
31 import org.apache.maven.scm.provider.jazz.command.JazzScmCommand;
32 import org.apache.maven.scm.provider.jazz.command.changelog.JazzChangeLogCommand;
33 import org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer;
34
35 //
36 // The Maven SCM Plugin "update" goal is equivalent to the RTC "accept" command.
37 //
38 // NOTE: What is not clear from the docs, is that the accept command will also
39 // update the sandbox with the changes that have been accepted into the repository.
40 // However, I have checked with Rational Support, and this is indeed the expected
41 // behaviour. This may come from the fact that you can accept changes into a
42 // repository workspace, without having a sandbox loaded; though this makes no
43 // sense to us from a maven usage context (as we only work in a sandbox).
44 //
45 // See the following links for additional information on the RTC "create snapshot" command:
46 // RTC 2.0.0.2:
47 // http://publib.boulder.ibm.com/infocenter/rtc/v2r0m0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_accept.html
48 // RTC 3.0:
49 // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_accept.html
50 // RTC 3.0.1:
51 // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0m1/topic/com.ibm.team.scm.doc/topics/r_scm_cli_accept.html
52 //
53
54 /**
55 * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a>
56 */
57 public class JazzUpdateCommand
58 extends AbstractUpdateCommand
59 {
60 /**
61 * {@inheritDoc}
62 */
63 protected UpdateScmResult executeUpdateCommand( ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version )
64 throws ScmException
65 {
66 if ( getLogger().isDebugEnabled() )
67 {
68 getLogger().debug( "Executing update command..." );
69 }
70
71 JazzUpdateConsumer updateConsumer = new JazzUpdateConsumer( repo, getLogger() );
72 ErrorConsumer errConsumer = new ErrorConsumer( getLogger() );
73
74 JazzScmCommand updateCmd = createAcceptCommand( repo, fileSet );
75 int status = updateCmd.execute( updateConsumer, errConsumer );
76
77 if ( status != 0 )
78 {
79 return new UpdateScmResult( updateCmd.getCommandString(),
80 "Error code for Jazz SCM update command - " + status, errConsumer.getOutput(),
81 false );
82 }
83
84 if ( getLogger().isDebugEnabled() )
85 {
86 if ( !updateConsumer.getUpdatedFiles().isEmpty() )
87 {
88 getLogger().debug( "Iterating over \"Update\" results" );
89 for ( ScmFile file : updateConsumer.getUpdatedFiles() )
90 {
91 getLogger().debug( file.getPath() + " : " + file.getStatus() );
92 }
93 }
94 else
95 {
96 getLogger().debug( "There are no updated files" );
97 }
98 }
99
100 // Now, just (re)load the workspace into the sand box.
101 // We can use the checkout directory for this.
102 return new UpdateScmResult( updateCmd.getCommandString(), updateConsumer.getUpdatedFiles() );
103 }
104
105 public JazzScmCommand createAcceptCommand( ScmProviderRepository repo, ScmFileSet fileSet )
106 {
107 JazzScmCommand command = new JazzScmCommand( JazzConstants.CMD_ACCEPT, repo, fileSet, getLogger() );
108
109 command.addArgument( JazzConstants.ARG_FLOW_COMPONENTS );
110
111 return command;
112 }
113
114 /**
115 * {@inheritDoc}
116 */
117 protected ChangeLogCommand getChangeLogCommand()
118 {
119 JazzChangeLogCommand command = new JazzChangeLogCommand();
120
121 command.setLogger( getLogger() );
122
123 return command;
124 }
125
126 }