View Javadoc
1   package org.apache.maven.scm.provider.integrity.command.branch;
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.ScmFile;
26  import org.apache.maven.scm.ScmFileSet;
27  import org.apache.maven.scm.ScmResult;
28  import org.apache.maven.scm.command.branch.AbstractBranchCommand;
29  import org.apache.maven.scm.command.branch.BranchScmResult;
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.Project;
33  import org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository;
34  
35  import java.util.ArrayList;
36  
37  /**
38   * MKS Integrity implementation for Maven's AbstractBranchCommand
39   * <br>For a normal and variant configuration, a fresh checkpoint is executed
40   * prior to creating a Development Path (branch).  In the case of a build
41   * configuration, the specified checkpoint revision is used to create
42   * the Development Path
43   *
44   * @author <a href="mailto:cletus@mks.com">Cletus D'Souza</a>
45   * @version $Id: IntegrityBranchCommand.java 1.3 2011/08/22 13:06:17EDT Cletus D'Souza (dsouza) Exp  $
46   * @since 1.6
47   */
48  public class IntegrityBranchCommand
49      extends AbstractBranchCommand
50  {
51      /**
52       * {@inheritDoc}
53       */
54      @Override
55      public BranchScmResult executeBranchCommand( ScmProviderRepository repository, ScmFileSet fileSet,
56                                                   String branchName, String message )
57          throws ScmException
58      {
59          BranchScmResult result;
60          IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
61          Project siProject = iRepo.getProject();
62          getLogger().info(
63              "Attempting to branch project " + siProject.getProjectName() + " using branch name '" + branchName + "'" );
64          try
65          {
66              Project.validateTag( branchName );
67              Response res = siProject.createDevPath( branchName );
68              int exitCode = res.getExitCode();
69              boolean success = ( exitCode == 0 ? true : false );
70              ScmResult scmResult = new ScmResult( res.getCommandString(), "", "Exit Code: " + exitCode, success );
71              result = new BranchScmResult( new ArrayList<ScmFile>(), scmResult );
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 BranchScmResult( eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false );
79          }
80          catch ( Exception e )
81          {
82              getLogger().error( "Failed to checkpoint project! " + e.getMessage() );
83              result = new BranchScmResult( "si createdevpath", e.getMessage(), "", false );
84          }
85  
86          return result;
87      }
88  
89  }