View Javadoc

1   package org.apache.maven.scm.provider.integrity.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 com.mks.api.response.APIException;
23  import com.mks.api.response.Response;
24  import org.apache.maven.scm.ScmException;
25  import org.apache.maven.scm.ScmFileSet;
26  import org.apache.maven.scm.command.unedit.AbstractUnEditCommand;
27  import org.apache.maven.scm.command.unedit.UnEditScmResult;
28  import org.apache.maven.scm.provider.ScmProviderRepository;
29  import org.apache.maven.scm.provider.integrity.ExceptionHandler;
30  import org.apache.maven.scm.provider.integrity.Sandbox;
31  import org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository;
32  
33  /**
34   * MKS Integrity implementation of Maven's AbstractUnEditCommand
35   * <br>This command will execute a 'si revert' command which will revert
36   * any modified working files back to their server versions
37   *
38   * @author <a href="mailto:cletus@mks.com">Cletus D'Souza</a>
39   * @version $Id: IntegrityUnEditCommand.java 1.4 2011/08/22 13:06:39EDT Cletus D'Souza (dsouza) Exp  $
40   * @since 1.6
41   */
42  public class IntegrityUnEditCommand
43      extends AbstractUnEditCommand
44  {
45      /**
46       * {@inheritDoc}
47       */
48      @Override
49      public UnEditScmResult executeUnEditCommand( ScmProviderRepository repository, ScmFileSet fileSet )
50          throws ScmException
51      {
52          getLogger().info( "Attempting to revert members in sandbox " + fileSet.getBasedir().getAbsolutePath() );
53          IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
54          UnEditScmResult result;
55          try
56          {
57              Sandbox siSandbox = iRepo.getSandbox();
58              Response res = siSandbox.revertMembers();
59              int exitCode = res.getExitCode();
60              boolean success = ( exitCode == 0 ? true : false );
61              result = new UnEditScmResult( res.getCommandString(), "", "Exit Code: " + exitCode, success );
62          }
63          catch ( APIException aex )
64          {
65              ExceptionHandler eh = new ExceptionHandler( aex );
66              getLogger().error( "MKS API Exception: " + eh.getMessage() );
67              getLogger().info( eh.getCommand() + " exited with return code " + eh.getExitCode() );
68              result = new UnEditScmResult( eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false );
69          }
70  
71          return result;
72      }
73  }