1 package org.apache.maven.scm.command.changelog;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
36
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
59
60
61 public ScmResult executeCommand( ScmProviderRepository repository, ScmFileSet fileSet,
62 CommandParameters parameters )
63 throws ScmException
64 {
65 Date startDate = parameters.getDate( CommandParameter.START_DATE, null );
66
67 Date endDate = parameters.getDate( CommandParameter.END_DATE, null );
68
69 int numDays = parameters.getInt( CommandParameter.NUM_DAYS, 0 );
70
71 Integer limit = parameters.getInt( CommandParameter.LIMIT, -1 );
72 if ( limit < 1 )
73 {
74 limit = null;
75 }
76
77 ScmBranch branch = (ScmBranch) parameters.getScmVersion( CommandParameter.BRANCH, null );
78
79 ScmVersion startVersion = parameters.getScmVersion( CommandParameter.START_SCM_VERSION, null );
80
81 ScmVersion endVersion = parameters.getScmVersion( CommandParameter.END_SCM_VERSION, null );
82
83 String datePattern = parameters.getString( CommandParameter.CHANGELOG_DATE_PATTERN, null );
84
85 if ( startVersion != null || endVersion != null )
86 {
87 return executeChangeLogCommand( repository, fileSet, startVersion, endVersion, datePattern );
88 }
89 else
90 {
91 if ( numDays != 0 && ( startDate != null || endDate != null ) )
92 {
93 throw new ScmException( "Start or end date cannot be set if num days is set." );
94 }
95
96 if ( endDate != null && startDate == null )
97 {
98 throw new ScmException( "The end date is set but the start date isn't." );
99 }
100
101 if ( numDays > 0 )
102 {
103 @SuppressWarnings( "checkstyle:magicnumber" )
104 int day = 24 * 60 * 60 * 1000;
105 startDate = new Date( System.currentTimeMillis() - (long) numDays * day );
106
107 endDate = new Date( System.currentTimeMillis() + (long) day );
108 }
109 else if ( endDate == null )
110 {
111 endDate = new Date();
112 }
113
114 return executeChangeLogCommand( repository, fileSet, startDate, endDate, branch, datePattern );
115 }
116 }
117
118 protected ChangeLogScmResult executeChangeLogCommand( ChangeLogScmRequest request )
119 throws ScmException
120 {
121 throw new ScmException( "Unsupported method for this provider." );
122 }
123 }