View Javadoc
1   package org.apache.maven.scm.provider.integrity.command.changelog;
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 org.apache.maven.scm.ScmBranch;
24  import org.apache.maven.scm.ScmException;
25  import org.apache.maven.scm.ScmFileSet;
26  import org.apache.maven.scm.ScmResult;
27  import org.apache.maven.scm.command.changelog.AbstractChangeLogCommand;
28  import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
29  import org.apache.maven.scm.provider.ScmProviderRepository;
30  import org.apache.maven.scm.provider.integrity.ExceptionHandler;
31  import org.apache.maven.scm.provider.integrity.Sandbox;
32  import org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository;
33  
34  import java.util.Date;
35  
36  /**
37   * MKS Integrity implementation for Maven's AbstractChangeLogCommand
38   * <br>Currently there is a limitation in the 'si rlog' command where changes
39   * can't be limited to a normal/variant/build configuration.  In other
40   * words all revisions modified within the date range will be picked up
41   * for the Change Log report.  By default the Change Log is grouped by
42   * Change Package ID.  However, if no Change Package is found or Change
43   * Packages are not in use, then all the changes are grouped in one big
44   * Change Log Set
45   *
46   * @author <a href="mailto:cletus@mks.com">Cletus D'Souza</a>
47   * @version $Id: IntegrityChangeLogCommand.java 1.3 2011/08/22 13:06:19EDT Cletus D'Souza (dsouza) Exp  $
48   * @since 1.6
49   */
50  public class IntegrityChangeLogCommand
51      extends AbstractChangeLogCommand
52  {
53      /**
54       * {@inheritDoc}
55       */
56      @Override
57      public ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repository, ScmFileSet fileSet,
58                                                         Date startDate, Date endDate, ScmBranch branch,
59                                                         String datePattern )
60          throws ScmException
61      {
62          // First lets validate the date range provided
63          if ( null == startDate || null == endDate )
64          {
65              throw new ScmException( "Both 'startDate' and 'endDate' must be specified!" );
66          }
67          if ( startDate.after( endDate ) )
68          {
69              throw new ScmException( "'stateDate' is not allowed to occur after 'endDate'!" );
70          }
71          getLogger().info(
72              "Attempting to obtain change log for date range: '" + Sandbox.RLOG_DATEFORMAT.format( startDate ) + "' to '"
73                  + Sandbox.RLOG_DATEFORMAT.format( endDate ) + "'" );
74          ChangeLogScmResult result;
75          IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
76          try
77          {
78              result = new ChangeLogScmResult( iRepo.getSandbox().getChangeLog( startDate, endDate ),
79                                               new ScmResult( "si rlog", "", "", true ) );
80          }
81          catch ( APIException aex )
82          {
83              ExceptionHandler eh = new ExceptionHandler( aex );
84              getLogger().error( "MKS API Exception: " + eh.getMessage() );
85              getLogger().info( eh.getCommand() + " exited with return code " + eh.getExitCode() );
86              result =
87                  new ChangeLogScmResult( eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false );
88          }
89  
90          return result;
91      }
92  
93  }