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