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   * @since 1.6
40   */
41  public class IntegrityEditCommand
42      extends AbstractEditCommand
43  {
44      /**
45       * {@inheritDoc}
46       */
47      @Override
48      public EditScmResult executeEditCommand( ScmProviderRepository repository, ScmFileSet fileSet )
49          throws ScmException
50      {
51          getLogger().info( "Attempting make files writeable in Sandbox " + fileSet.getBasedir().getAbsolutePath() );
52          EditScmResult result;
53          IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
54          try
55          {
56              Sandbox siSandbox = iRepo.getSandbox();
57              Response res = siSandbox.makeWriteable();
58              int exitCode = res.getExitCode();
59              boolean success = ( exitCode == 0 ? true : false );
60              result = new EditScmResult( 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 EditScmResult( eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false );
68          }
69  
70          return result;
71      }
72  
73  }