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