View Javadoc

1   package org.apache.maven.scm.provider.integrity.command.remove;
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.remove.AbstractRemoveCommand;
27  import org.apache.maven.scm.command.remove.RemoveScmResult;
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 for Maven's AbstractRemoveCommand
35   * <br>This command will remove the registry entry for the current Sandbox
36   *
37   * @author <a href="mailto:cletus@mks.com">Cletus D'Souza</a>
38   * @version $Id: IntegrityRemoveCommand.java 1.3 2011/08/22 13:06:35EDT Cletus D'Souza (dsouza) Exp  $
39   * @since 1.6
40   */
41  public class IntegrityRemoveCommand
42      extends AbstractRemoveCommand
43  {
44      /**
45       * {@inheritDoc}
46       */
47      @Override
48      public RemoveScmResult executeRemoveCommand( ScmProviderRepository repository, ScmFileSet fileSet, String message )
49          throws ScmException
50      {
51          getLogger().info( "Attempting to un-register sandbox in directory " + fileSet.getBasedir().getAbsolutePath() );
52          RemoveScmResult result;
53          IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
54          try
55          {
56              Sandbox siSandbox = iRepo.getSandbox();
57              Response res = siSandbox.drop();
58              int exitCode = res.getExitCode();
59              boolean success = ( exitCode == 0 ? true : false );
60              result = new RemoveScmResult( res.getCommandString(), "", "Exit Code: " + exitCode, success );
61          }
62          catch ( APIException aex )
63          {
64              ExceptionHandler eh = new ExceptionHandler( aex );
65              getLogger().error( "MKS API Exception: " + eh.getMessage() );
66              getLogger().info( eh.getCommand() + " exited with return code " + eh.getExitCode() );
67              result = new RemoveScmResult( eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false );
68          }
69  
70          return result;
71      }
72  
73  }