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   * @since 1.6
48   */
49  public class IntegrityChangeLogCommand
50      extends AbstractChangeLogCommand
51  {
52      /**
53       * {@inheritDoc}
54       */
55      @Override
56      public ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repository, ScmFileSet fileSet,
57                                                         Date startDate, Date endDate, ScmBranch branch,
58                                                         String datePattern )
59          throws ScmException
60      {
61          // First lets validate the date range provided
62          if ( null == startDate || null == endDate )
63          {
64              throw new ScmException( "Both 'startDate' and 'endDate' must be specified!" );
65          }
66          if ( startDate.after( endDate ) )
67          {
68              throw new ScmException( "'stateDate' is not allowed to occur after 'endDate'!" );
69          }
70          getLogger().info(
71              "Attempting to obtain change log for date range: '" + Sandbox.RLOG_DATEFORMAT.format( startDate ) + "' to '"
72                  + Sandbox.RLOG_DATEFORMAT.format( endDate ) + "'" );
73          ChangeLogScmResult result;
74          IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
75          try
76          {
77              result = new ChangeLogScmResult( iRepo.getSandbox().getChangeLog( startDate, endDate ),
78                                               new ScmResult( "si rlog", "", "", true ) );
79          }
80          catch ( APIException aex )
81          {
82              ExceptionHandler eh = new ExceptionHandler( aex );
83              getLogger().error( "MKS API Exception: " + eh.getMessage() );
84              getLogger().info( eh.getCommand() + " exited with return code " + eh.getExitCode() );
85              result =
86                  new ChangeLogScmResult( eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false );
87          }
88  
89          return result;
90      }
91  
92  }