001package org.apache.maven.scm.provider.integrity.command.remove;
002
003/**
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import com.mks.api.response.APIException;
023import com.mks.api.response.Response;
024import org.apache.maven.scm.ScmException;
025import org.apache.maven.scm.ScmFileSet;
026import org.apache.maven.scm.command.remove.AbstractRemoveCommand;
027import org.apache.maven.scm.command.remove.RemoveScmResult;
028import org.apache.maven.scm.provider.ScmProviderRepository;
029import org.apache.maven.scm.provider.integrity.ExceptionHandler;
030import org.apache.maven.scm.provider.integrity.Sandbox;
031import org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository;
032
033/**
034 * MKS Integrity implementation for Maven's AbstractRemoveCommand
035 * <br>This command will remove the registry entry for the current Sandbox
036 *
037 * @author <a href="mailto:cletus@mks.com">Cletus D'Souza</a>
038 * @version $Id: IntegrityRemoveCommand.java 1.3 2011/08/22 13:06:35EDT Cletus D'Souza (dsouza) Exp  $
039 * @since 1.6
040 */
041public class IntegrityRemoveCommand
042    extends AbstractRemoveCommand
043{
044    /**
045     * {@inheritDoc}
046     */
047    @Override
048    public RemoveScmResult executeRemoveCommand( ScmProviderRepository repository, ScmFileSet fileSet, String message )
049        throws ScmException
050    {
051        getLogger().info( "Attempting to un-register sandbox in directory " + fileSet.getBasedir().getAbsolutePath() );
052        RemoveScmResult result;
053        IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
054        try
055        {
056            Sandbox siSandbox = iRepo.getSandbox();
057            Response res = siSandbox.drop();
058            int exitCode = res.getExitCode();
059            boolean success = ( exitCode == 0 ? true : false );
060            result = new RemoveScmResult( res.getCommandString(), "", "Exit Code: " + exitCode, success );
061        }
062        catch ( APIException aex )
063        {
064            ExceptionHandler eh = new ExceptionHandler( aex );
065            getLogger().error( "MKS API Exception: " + eh.getMessage() );
066            getLogger().info( eh.getCommand() + " exited with return code " + eh.getExitCode() );
067            result = new RemoveScmResult( eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false );
068        }
069
070        return result;
071    }
072
073}