001    package org.apache.maven.scm.provider.integrity.command.unedit;
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    
022    import com.mks.api.response.APIException;
023    import com.mks.api.response.Response;
024    import org.apache.maven.scm.ScmException;
025    import org.apache.maven.scm.ScmFileSet;
026    import org.apache.maven.scm.command.unedit.AbstractUnEditCommand;
027    import org.apache.maven.scm.command.unedit.UnEditScmResult;
028    import org.apache.maven.scm.provider.ScmProviderRepository;
029    import org.apache.maven.scm.provider.integrity.ExceptionHandler;
030    import org.apache.maven.scm.provider.integrity.Sandbox;
031    import org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository;
032    
033    /**
034     * MKS Integrity implementation of Maven's AbstractUnEditCommand
035     * <br>This command will execute a 'si revert' command which will revert
036     * any modified working files back to their server versions
037     *
038     * @author <a href="mailto:cletus@mks.com">Cletus D'Souza</a>
039     * @version $Id: IntegrityUnEditCommand.java 1.4 2011/08/22 13:06:39EDT Cletus D'Souza (dsouza) Exp  $
040     * @since 1.6
041     */
042    public class IntegrityUnEditCommand
043        extends AbstractUnEditCommand
044    {
045        /**
046         * {@inheritDoc}
047         */
048        @Override
049        public UnEditScmResult executeUnEditCommand( ScmProviderRepository repository, ScmFileSet fileSet )
050            throws ScmException
051        {
052            getLogger().info( "Attempting to revert members in sandbox " + fileSet.getBasedir().getAbsolutePath() );
053            IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
054            UnEditScmResult result;
055            try
056            {
057                Sandbox siSandbox = iRepo.getSandbox();
058                Response res = siSandbox.revertMembers();
059                int exitCode = res.getExitCode();
060                boolean success = ( exitCode == 0 ? true : false );
061                result = new UnEditScmResult( res.getCommandString(), "", "Exit Code: " + exitCode, success );
062            }
063            catch ( APIException aex )
064            {
065                ExceptionHandler eh = new ExceptionHandler( aex );
066                getLogger().error( "MKS API Exception: " + eh.getMessage() );
067                getLogger().info( eh.getCommand() + " exited with return code " + eh.getExitCode() );
068                result = new UnEditScmResult( eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false );
069            }
070    
071            return result;
072        }
073    }