001    package org.apache.maven.scm.provider.integrity.command.changelog;
002    
003    /**
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     * http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import com.mks.api.response.APIException;
023    import org.apache.maven.scm.ScmBranch;
024    import org.apache.maven.scm.ScmException;
025    import org.apache.maven.scm.ScmFileSet;
026    import org.apache.maven.scm.ScmResult;
027    import org.apache.maven.scm.command.changelog.AbstractChangeLogCommand;
028    import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
029    import org.apache.maven.scm.provider.ScmProviderRepository;
030    import org.apache.maven.scm.provider.integrity.ExceptionHandler;
031    import org.apache.maven.scm.provider.integrity.Sandbox;
032    import org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository;
033    
034    import java.util.Date;
035    
036    /**
037     * MKS Integrity implementation for Maven's AbstractChangeLogCommand
038     * <br>Currently there is a limitation in the 'si rlog' command where changes
039     * can't be limited to a normal/variant/build configuration.  In other
040     * words all revisions modified within the date range will be picked up
041     * for the Change Log report.  By default the Change Log is grouped by
042     * Change Package ID.  However, if no Change Package is found or Change
043     * Packages are not in use, then all the changes are grouped in one big
044     * Change Log Set
045     *
046     * @author <a href="mailto:cletus@mks.com">Cletus D'Souza</a>
047     * @version $Id: IntegrityChangeLogCommand.java 1.3 2011/08/22 13:06:19EDT Cletus D'Souza (dsouza) Exp  $
048     * @since 1.6
049     */
050    public class IntegrityChangeLogCommand
051        extends AbstractChangeLogCommand
052    {
053        /**
054         * {@inheritDoc}
055         */
056        @Override
057        public ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repository, ScmFileSet fileSet,
058                                                           Date startDate, Date endDate, ScmBranch branch,
059                                                           String datePattern )
060            throws ScmException
061        {
062            // First lets validate the date range provided
063            if ( null == startDate || null == endDate )
064            {
065                throw new ScmException( "Both 'startDate' and 'endDate' must be specified!" );
066            }
067            if ( startDate.after( endDate ) )
068            {
069                throw new ScmException( "'stateDate' is not allowed to occur after 'endDate'!" );
070            }
071            getLogger().info(
072                "Attempting to obtain change log for date range: '" + Sandbox.RLOG_DATEFORMAT.format( startDate ) + "' to '"
073                    + Sandbox.RLOG_DATEFORMAT.format( endDate ) + "'" );
074            ChangeLogScmResult result;
075            IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
076            try
077            {
078                result = new ChangeLogScmResult( iRepo.getSandbox().getChangeLog( startDate, endDate ),
079                                                 new ScmResult( "si rlog", "", "", true ) );
080            }
081            catch ( APIException aex )
082            {
083                ExceptionHandler eh = new ExceptionHandler( aex );
084                getLogger().error( "MKS API Exception: " + eh.getMessage() );
085                getLogger().info( eh.getCommand() + " exited with return code " + eh.getExitCode() );
086                result =
087                    new ChangeLogScmResult( eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false );
088            }
089    
090            return result;
091        }
092    
093    }