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   * @since 1.6
46   */
47  public class IntegrityBranchCommand
48      extends AbstractBranchCommand
49  {
50      /**
51       * {@inheritDoc}
52       */
53      @Override
54      public BranchScmResult executeBranchCommand( ScmProviderRepository repository, ScmFileSet fileSet,
55                                                   String branchName, String message )
56          throws ScmException
57      {
58          BranchScmResult result;
59          IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
60          Project siProject = iRepo.getProject();
61          getLogger().info(
62              "Attempting to branch project " + siProject.getProjectName() + " using branch name '" + branchName + "'" );
63          try
64          {
65              Project.validateTag( branchName );
66              Response res = siProject.createDevPath( branchName );
67              int exitCode = res.getExitCode();
68              boolean success = ( exitCode == 0 ? true : false );
69              ScmResult scmResult = new ScmResult( res.getCommandString(), "", "Exit Code: " + exitCode, success );
70              result = new BranchScmResult( new ArrayList<ScmFile>(), scmResult );
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 BranchScmResult( eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false );
78          }
79          catch ( Exception e )
80          {
81              getLogger().error( "Failed to checkpoint project! " + e.getMessage() );
82              result = new BranchScmResult( "si createdevpath", e.getMessage(), "", false );
83          }
84  
85          return result;
86      }
87  
88  }