View Javadoc
1   package org.apache.maven.scm.provider.clearcase.command.status;
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.command.status.AbstractStatusCommand;
25  import org.apache.maven.scm.command.status.StatusScmResult;
26  import org.apache.maven.scm.provider.ScmProviderRepository;
27  import org.apache.maven.scm.provider.clearcase.command.ClearCaseCommand;
28  import org.codehaus.plexus.util.cli.CommandLineException;
29  import org.codehaus.plexus.util.cli.CommandLineUtils;
30  import org.codehaus.plexus.util.cli.Commandline;
31  
32  import java.io.File;
33  
34  /**
35   * @author <a href="mailto:wim.deblauwe@gmail.com">Wim Deblauwe</a>
36   *
37   */
38  public class ClearCaseStatusCommand
39      extends AbstractStatusCommand
40      implements ClearCaseCommand
41  {
42      /** {@inheritDoc} */
43      protected StatusScmResult executeStatusCommand( ScmProviderRepository scmProviderRepository, ScmFileSet scmFileSet )
44          throws ScmException
45      {
46          if ( getLogger().isDebugEnabled() )
47          {
48              getLogger().debug( "executing status command..." );
49          }
50          Commandline cl = createCommandLine( scmFileSet );
51  
52          ClearCaseStatusConsumer consumer = new ClearCaseStatusConsumer( getLogger(), scmFileSet.getBasedir() );
53  
54          CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
55  
56          int exitCode;
57  
58          try
59          {
60              if ( getLogger().isDebugEnabled() )
61              {
62                  getLogger().debug(
63                                     "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>"
64                                         + cl.toString() );
65              }
66              exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr );
67          }
68          catch ( CommandLineException ex )
69          {
70              throw new ScmException( "Error while executing clearcase command.", ex );
71          }
72  
73          if ( exitCode != 0 )
74          {
75              return new StatusScmResult( cl.toString(), "The cleartool command failed.", stderr.getOutput(), false );
76          }
77  
78          return new StatusScmResult( cl.toString(), consumer.getCheckedOutFiles() );
79      }
80  
81      // ----------------------------------------------------------------------
82      //
83      // ----------------------------------------------------------------------
84  
85      public static Commandline createCommandLine( ScmFileSet scmFileSet )
86      {
87          Commandline command = new Commandline();
88  
89          File workingDirectory = scmFileSet.getBasedir();
90  
91          command.setWorkingDirectory( workingDirectory.getAbsolutePath() );
92  
93          command.setExecutable( "cleartool" );
94  
95          command.createArg().setValue( "lscheckout" );
96          command.createArg().setValue( "-cview" );
97          command.createArg().setValue( "-r" );
98          command.createArg().setValue( "-fmt" );
99          command.createArg().setValue( "%n\\n" );
100 
101         return command;
102     }
103 }