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