View Javadoc

1   package org.apache.maven.scm.provider.integrity.command.edit;
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.edit.AbstractEditCommand;
27  import org.apache.maven.scm.command.edit.EditScmResult;
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 AbstractEditCommand
35   * <br>Since it does not make sense to lock all files in the Sandbox,
36   * this command will make all of the working files writable in the Sandbox
37   *
38   * @author <a href="mailto:cletus@mks.com">Cletus D'Souza</a>
39   * @version $Id: IntegrityEditCommand.java 1.3 2011/08/22 13:06:25EDT Cletus D'Souza (dsouza) Exp  $
40   * @since 1.6
41   */
42  public class IntegrityEditCommand
43      extends AbstractEditCommand
44  {
45      /**
46       * {@inheritDoc}
47       */
48      @Override
49      public EditScmResult executeEditCommand( ScmProviderRepository repository, ScmFileSet fileSet )
50          throws ScmException
51      {
52          getLogger().info( "Attempting make files writeable in Sandbox " + fileSet.getBasedir().getAbsolutePath() );
53          EditScmResult result;
54          IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
55          try
56          {
57              Sandbox siSandbox = iRepo.getSandbox();
58              Response res = siSandbox.makeWriteable();
59              int exitCode = res.getExitCode();
60              boolean success = ( exitCode == 0 ? true : false );
61              result = new EditScmResult( 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 EditScmResult( eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false );
69          }
70  
71          return result;
72      }
73  
74  }