| 1 |
package org.apache.maven.scm.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 org.apache.maven.scm.CommandParameter; |
| 23 |
import org.apache.maven.scm.CommandParameters; |
| 24 |
import org.apache.maven.scm.ScmBranch; |
| 25 |
import org.apache.maven.scm.ScmException; |
| 26 |
import org.apache.maven.scm.ScmFileSet; |
| 27 |
import org.apache.maven.scm.ScmResult; |
| 28 |
import org.apache.maven.scm.ScmVersion; |
| 29 |
import org.apache.maven.scm.command.AbstractCommand; |
| 30 |
import org.apache.maven.scm.provider.ScmProviderRepository; |
| 31 |
|
| 32 |
import java.util.Date; |
| 33 |
|
| 34 |
/** |
| 35 |
* @author <a href="mailto:[email protected]">Trygve Laugstøl</a> |
| 36 |
* @author Olivier Lamy |
| 37 |
* |
| 38 |
*/ |
| 39 |
public abstract class AbstractChangeLogCommand |
| 40 |
extends AbstractCommand |
| 41 |
implements ChangeLogCommand |
| 42 |
{ |
| 43 |
@Deprecated |
| 44 |
protected abstract ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repository, ScmFileSet fileSet, |
| 45 |
Date startDate, Date endDate, ScmBranch branch, |
| 46 |
String datePattern ) |
| 47 |
throws ScmException; |
| 48 |
|
| 49 |
@Deprecated |
| 50 |
protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repository, ScmFileSet fileSet, |
| 51 |
ScmVersion startVersion, ScmVersion endVersion, |
| 52 |
String datePattern ) |
| 53 |
throws ScmException |
| 54 |
{ |
| 55 |
throw new ScmException( "Unsupported method for this provider." ); |
| 56 |
} |
| 57 |
|
| 58 |
@Deprecated |
| 59 |
protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repository, ScmFileSet fileSet, |
| 60 |
ScmVersion version, String datePattern ) |
| 61 |
throws ScmException |
| 62 |
{ |
| 63 |
throw new ScmException( "Unsupported method for this provider." ); |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* {@inheritDoc} |
| 68 |
*/ |
| 69 |
public ScmResult executeCommand( ScmProviderRepository repository, ScmFileSet fileSet, |
| 70 |
CommandParameters parameters ) |
| 71 |
throws ScmException |
| 72 |
{ |
| 73 |
Date startDate = parameters.getDate( CommandParameter.START_DATE, null ); |
| 74 |
|
| 75 |
Date endDate = parameters.getDate( CommandParameter.END_DATE, null ); |
| 76 |
|
| 77 |
int numDays = parameters.getInt( CommandParameter.NUM_DAYS, 0 ); |
| 78 |
|
| 79 |
Integer limit = parameters.getInt( CommandParameter.LIMIT, -1 ); |
| 80 |
if ( limit < 1 ) |
| 81 |
{ |
| 82 |
limit = null; |
| 83 |
} |
| 84 |
|
| 85 |
ScmBranch branch = (ScmBranch) parameters.getScmVersion( CommandParameter.BRANCH, null ); |
| 86 |
|
| 87 |
ScmVersion version = parameters.getScmVersion( CommandParameter.SCM_VERSION, null ); |
| 88 |
|
| 89 |
ScmVersion startVersion = parameters.getScmVersion( CommandParameter.START_SCM_VERSION, null ); |
| 90 |
|
| 91 |
ScmVersion endVersion = parameters.getScmVersion( CommandParameter.END_SCM_VERSION, null ); |
| 92 |
|
| 93 |
String datePattern = parameters.getString( CommandParameter.CHANGELOG_DATE_PATTERN, null ); |
| 94 |
|
| 95 |
boolean versionOnly = startVersion == null && endVersion == null && version != null; |
| 96 |
|
| 97 |
if ( versionOnly ) |
| 98 |
{ |
| 99 |
return executeChangeLogCommand( repository, fileSet, version, datePattern ); |
| 100 |
} |
| 101 |
else if ( startVersion != null || endVersion != null ) |
| 102 |
{ |
| 103 |
return executeChangeLogCommand( repository, fileSet, startVersion, endVersion, datePattern ); |
| 104 |
} |
| 105 |
else |
| 106 |
{ |
| 107 |
if ( numDays != 0 && ( startDate != null || endDate != null ) ) |
| 108 |
{ |
| 109 |
throw new ScmException( "Start or end date cannot be set if num days is set." ); |
| 110 |
} |
| 111 |
|
| 112 |
if ( endDate != null && startDate == null ) |
| 113 |
{ |
| 114 |
throw new ScmException( "The end date is set but the start date isn't." ); |
| 115 |
} |
| 116 |
|
| 117 |
if ( numDays > 0 ) |
| 118 |
{ |
| 119 |
@SuppressWarnings( "checkstyle:magicnumber" ) |
| 120 |
int day = 24 * 60 * 60 * 1000; |
| 121 |
startDate = new Date( System.currentTimeMillis() - (long) numDays * day ); |
| 122 |
|
| 123 |
endDate = new Date( System.currentTimeMillis() + (long) day ); |
| 124 |
} |
| 125 |
else if ( endDate == null ) |
| 126 |
{ |
| 127 |
endDate = new Date(); |
| 128 |
} |
| 129 |
|
| 130 |
return executeChangeLogCommand( repository, fileSet, startDate, endDate, branch, datePattern ); |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
protected ChangeLogScmResult executeChangeLogCommand( ChangeLogScmRequest request ) |
| 135 |
throws ScmException |
| 136 |
{ |
| 137 |
throw new ScmException( "Unsupported method for this provider." ); |
| 138 |
} |
| 139 |
} |