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