View Javadoc
1   package org.apache.maven.scm.provider.integrity.command.lock;
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.CommandParameter;
25  import org.apache.maven.scm.CommandParameters;
26  import org.apache.maven.scm.ScmException;
27  import org.apache.maven.scm.ScmFileSet;
28  import org.apache.maven.scm.ScmResult;
29  import org.apache.maven.scm.command.lock.AbstractLockCommand;
30  import org.apache.maven.scm.provider.ScmProviderRepository;
31  import org.apache.maven.scm.provider.integrity.ExceptionHandler;
32  import org.apache.maven.scm.provider.integrity.Sandbox;
33  import org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository;
34  
35  import java.io.File;
36  
37  /**
38   * MKS Integrity implementation of Maven's AbstractLockCommand
39   * <br>This command will execute a 'si lock' on the specified member,
40   * which assumes the user has a valid Sandbox to work with.
41   *
42   * @author <a href="mailto:cletus@mks.com">Cletus D'Souza</a>
43   * @version $Id: IntegrityLockCommand.java 1.3 2011/08/22 13:06:31EDT Cletus D'Souza (dsouza) Exp  $
44   * @since 1.6
45   */
46  public class IntegrityLockCommand
47      extends AbstractLockCommand
48  {
49      /**
50       * {@inheritDoc}
51       */
52      @Override
53      public ScmResult executeLockCommand( ScmProviderRepository repository, File workingDirectory, String filename )
54          throws ScmException
55      {
56          getLogger().info( "Attempting to lock file: " + filename );
57          if ( null == filename || filename.length() == 0 )
58          {
59              throw new ScmException( "A single filename is required to execute the lock command!" );
60          }
61  
62          ScmResult result;
63          IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
64          try
65          {
66              Sandbox siSandbox = iRepo.getSandbox();
67              File memberFile = new File( workingDirectory.getAbsoluteFile() + File.separator + filename );
68              Response res = siSandbox.lock( memberFile, filename );
69              int exitCode = res.getExitCode();
70              boolean success = ( exitCode == 0 ? true : false );
71              result = new ScmResult( res.getCommandString(), "", "Exit Code: " + exitCode, success );
72          }
73          catch ( APIException aex )
74          {
75              ExceptionHandler eh = new ExceptionHandler( aex );
76              getLogger().error( "MKS API Exception: " + eh.getMessage() );
77              getLogger().info( eh.getCommand() + " exited with return code " + eh.getExitCode() );
78              result = new ScmResult( eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false );
79          }
80  
81          return result;
82      }
83  
84      /**
85       * {@inheritDoc}
86       */
87      @Override
88      protected ScmResult executeCommand( ScmProviderRepository repository, ScmFileSet fileSet,
89                                          CommandParameters parameters )
90          throws ScmException
91      {
92          return executeLockCommand( repository, fileSet.getBasedir(), parameters.getString( CommandParameter.FILE ) );
93      }
94  
95  }