View Javadoc
1   package org.apache.maven.scm.provider.clearcase.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.ScmFileSet;
24  import org.apache.maven.scm.ScmVersion;
25  import org.apache.maven.scm.command.changelog.ChangeLogCommand;
26  import org.apache.maven.scm.command.update.AbstractUpdateCommand;
27  import org.apache.maven.scm.command.update.UpdateScmResult;
28  import org.apache.maven.scm.provider.ScmProviderRepository;
29  import org.apache.maven.scm.provider.clearcase.command.ClearCaseCommand;
30  import org.apache.maven.scm.provider.clearcase.command.changelog.ClearCaseChangeLogCommand;
31  import org.codehaus.plexus.util.cli.CommandLineException;
32  import org.codehaus.plexus.util.cli.CommandLineUtils;
33  import org.codehaus.plexus.util.cli.Commandline;
34  
35  import java.io.File;
36  
37  /**
38   * @author <a href="mailto:wim.deblauwe@gmail.com">Wim Deblauwe</a>
39   * @author Olivier Lamy
40   *
41   */
42  public class ClearCaseUpdateCommand
43      extends AbstractUpdateCommand
44      implements ClearCaseCommand
45  {
46      /** {@inheritDoc} */
47      protected UpdateScmResult executeUpdateCommand( ScmProviderRepository repository, ScmFileSet fileSet,
48                                                      ScmVersion version )
49          throws ScmException
50      {
51          if ( getLogger().isDebugEnabled() )
52          {
53              getLogger().debug( "executing update command..." );
54          }
55          Commandline cl = createCommandLine( fileSet );
56  
57          ClearCaseUpdateConsumer consumer = new ClearCaseUpdateConsumer( getLogger() );
58  
59          CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
60  
61          int exitCode;
62  
63          try
64          {
65              if ( getLogger().isDebugEnabled() )
66              {
67                  getLogger().debug(
68                                     "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>"
69                                         + cl.toString() );
70              }
71              exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr );
72          }
73          catch ( CommandLineException ex )
74          {
75              throw new ScmException( "Error while executing clearcase command.", ex );
76          }
77  
78          if ( exitCode != 0 )
79          {
80              return new UpdateScmResult( cl.toString(), "The cleartool command failed.", stderr.getOutput(), false );
81          }
82  
83          return new UpdateScmResult( cl.toString(), consumer.getUpdatedFiles() );
84      }
85  
86      /** {@inheritDoc} */
87      protected ChangeLogCommand getChangeLogCommand()
88      {
89          ClearCaseChangeLogCommand changeLogCmd = new ClearCaseChangeLogCommand();
90  
91          changeLogCmd.setLogger( getLogger() );
92  
93          return changeLogCmd;
94      }
95  
96      // ----------------------------------------------------------------------
97      //
98      // ----------------------------------------------------------------------
99  
100     public static Commandline createCommandLine( ScmFileSet scmFileSet )
101     {
102         Commandline command = new Commandline();
103 
104         File workingDirectory = scmFileSet.getBasedir();
105 
106         command.setWorkingDirectory( workingDirectory.getAbsolutePath() );
107 
108         command.setExecutable( "cleartool" );
109 
110         command.createArg().setValue( "update" );
111 
112         command.createArg().setValue( "-f" );
113 
114         return command;
115     }
116 }