View Javadoc

1   package org.apache.maven.scm.provider.clearcase.command.unedit;
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.ScmResult;
25  import org.apache.maven.scm.command.status.StatusScmResult;
26  import org.apache.maven.scm.command.unedit.AbstractUnEditCommand;
27  import org.apache.maven.scm.log.ScmLogger;
28  import org.apache.maven.scm.provider.ScmProviderRepository;
29  import org.apache.maven.scm.provider.clearcase.command.ClearCaseCommand;
30  import org.codehaus.plexus.util.cli.CommandLineException;
31  import org.codehaus.plexus.util.cli.CommandLineUtils;
32  import org.codehaus.plexus.util.cli.Commandline;
33  
34  import java.io.File;
35  
36  /**
37   * @author <a href="mailto:wim.deblauwe@gmail.com">Wim Deblauwe</a>
38   */
39  public class ClearCaseUnEditCommand
40      extends AbstractUnEditCommand
41      implements ClearCaseCommand
42  {
43      protected ScmResult executeUnEditCommand( ScmProviderRepository repository, ScmFileSet fileSet )
44          throws ScmException
45      {
46          getLogger().debug( "executing unedit command..." );
47          Commandline cl = createCommandLine( getLogger(), fileSet );
48  
49          ClearCaseUnEditConsumer consumer = new ClearCaseUnEditConsumer( getLogger() );
50  
51          CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
52  
53          int exitCode;
54  
55          try
56          {
57              getLogger().debug( "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString() );
58              exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr );
59          }
60          catch ( CommandLineException ex )
61          {
62              throw new ScmException( "Error while executing clearcase command.", ex );
63          }
64  
65          if ( exitCode != 0 )
66          {
67              return new StatusScmResult( cl.toString(), "The cleartool command failed.", stderr.getOutput(), false );
68          }
69  
70          return new StatusScmResult( cl.toString(), consumer.getUnEditFiles() );
71      }
72  
73      // ----------------------------------------------------------------------
74      //
75      // ----------------------------------------------------------------------
76  
77      public static Commandline createCommandLine( ScmLogger logger, ScmFileSet scmFileSet )
78      {
79          Commandline command = new Commandline();
80  
81          File workingDirectory = scmFileSet.getBasedir();
82  
83          command.setWorkingDirectory( workingDirectory.getAbsolutePath() );
84  
85          command.setExecutable( "cleartool" );
86  
87          command.createArgument().setValue( "unco" );
88          command.createArgument().setValue( "-keep" );
89  
90          File[] files = scmFileSet.getFiles();
91          for ( int i = 0; i < files.length; i++ )
92          {
93              File file = files[i];
94              command.createArgument().setValue( file.getName() );
95          }
96  
97          return command;
98      }
99  }