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   * @since 1.6
44   */
45  public class IntegrityLockCommand
46      extends AbstractLockCommand
47  {
48      /**
49       * {@inheritDoc}
50       */
51      @Override
52      public ScmResult executeLockCommand( ScmProviderRepository repository, File workingDirectory, String filename )
53          throws ScmException
54      {
55          getLogger().info( "Attempting to lock file: " + filename );
56          if ( null == filename || filename.length() == 0 )
57          {
58              throw new ScmException( "A single filename is required to execute the lock command!" );
59          }
60  
61          ScmResult result;
62          IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
63          try
64          {
65              Sandbox siSandbox = iRepo.getSandbox();
66              File memberFile = new File( workingDirectory.getAbsoluteFile() + File.separator + filename );
67              Response res = siSandbox.lock( memberFile, filename );
68              int exitCode = res.getExitCode();
69              boolean success = ( exitCode == 0 ? true : false );
70              result = new ScmResult( res.getCommandString(), "", "Exit Code: " + exitCode, success );
71          }
72          catch ( APIException aex )
73          {
74              ExceptionHandler eh = new ExceptionHandler( aex );
75              getLogger().error( "MKS API Exception: " + eh.getMessage() );
76              getLogger().info( eh.getCommand() + " exited with return code " + eh.getExitCode() );
77              result = new ScmResult( eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false );
78          }
79  
80          return result;
81      }
82  
83      /**
84       * {@inheritDoc}
85       */
86      @Override
87      protected ScmResult executeCommand( ScmProviderRepository repository, ScmFileSet fileSet,
88                                          CommandParameters parameters )
89          throws ScmException
90      {
91          return executeLockCommand( repository, fileSet.getBasedir(), parameters.getString( CommandParameter.FILE ) );
92      }
93  
94  }