blob: 43c415f0de6c0e4c2f7b4865437a38c27f8d1914 [file] [log] [blame]
package org.apache.maven.scm.command.changelog;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.scm.CommandParameter;
import org.apache.maven.scm.CommandParameters;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFileSet;
import org.apache.maven.scm.ScmResult;
import org.apache.maven.scm.command.AbstractCommand;
import org.apache.maven.scm.provider.ScmProviderRepository;
import org.codehaus.plexus.util.StringUtils;
import java.util.Date;
/**
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
* @version $Id$
*/
public abstract class AbstractChangeLogCommand
extends AbstractCommand
implements ChangeLogCommand
{
protected abstract ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repository, ScmFileSet fileSet,
Date startDate, Date endDate, String branch,
String datePattern )
throws ScmException;
protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repository, ScmFileSet fileSet,
String startTag, String endTag, String datePattern )
throws ScmException
{
throw new ScmException( "Unsupported method for this provider." );
}
public ScmResult executeCommand( ScmProviderRepository repository, ScmFileSet fileSet,
CommandParameters parameters )
throws ScmException
{
Date startDate = parameters.getDate( CommandParameter.START_DATE, null );
Date endDate = parameters.getDate( CommandParameter.END_DATE, null );
int numDays = parameters.getInt( CommandParameter.NUM_DAYS, 0 );
String branch = parameters.getString( CommandParameter.BRANCH, null );
String startTag = parameters.getString( CommandParameter.START_TAG, null );
String endTag = parameters.getString( CommandParameter.END_TAG, null );
String datePattern = parameters.getString( CommandParameter.CHANGELOG_DATE_PATTERN, null );
if ( !StringUtils.isEmpty( startTag ) )
{
return executeChangeLogCommand( repository, fileSet, startTag, endTag, datePattern );
}
else
{
if ( numDays != 0 && ( startDate != null || endDate != null ) )
{
throw new ScmException( "Start or end date cannot be set if num days is set." );
}
if ( endDate != null && startDate == null )
{
throw new ScmException( "The end date is set but the start date isn't." );
}
if ( numDays > 0 )
{
startDate = new Date( System.currentTimeMillis() - (long) numDays * 24 * 60 * 60 * 1000 );
endDate = new Date( System.currentTimeMillis() + (long) 1 * 24 * 60 * 60 * 1000 );
}
return executeChangeLogCommand( repository, fileSet, startDate, endDate, branch, datePattern );
}
}
}