1 | |
package org.apache.maven.scm.provider.cvslib.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.ScmBranch; |
23 | |
import org.apache.maven.scm.ScmException; |
24 | |
import org.apache.maven.scm.ScmFileSet; |
25 | |
import org.apache.maven.scm.ScmVersion; |
26 | |
import org.apache.maven.scm.command.changelog.AbstractChangeLogCommand; |
27 | |
import org.apache.maven.scm.command.changelog.ChangeLogScmResult; |
28 | |
import org.apache.maven.scm.provider.ScmProviderRepository; |
29 | |
import org.apache.maven.scm.provider.cvslib.command.CvsCommand; |
30 | |
import org.apache.maven.scm.provider.cvslib.command.CvsCommandUtils; |
31 | |
import org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository; |
32 | |
import org.apache.maven.scm.provider.cvslib.util.CvsUtil; |
33 | |
import org.codehaus.plexus.util.Os; |
34 | |
import org.codehaus.plexus.util.StringUtils; |
35 | |
import org.codehaus.plexus.util.cli.Commandline; |
36 | |
|
37 | |
import java.text.SimpleDateFormat; |
38 | |
import java.util.Date; |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | 0 | public abstract class AbstractCvsChangeLogCommand |
46 | |
extends AbstractChangeLogCommand |
47 | |
implements CvsCommand |
48 | |
{ |
49 | |
|
50 | |
protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repo, ScmFileSet fileSet, |
51 | |
ScmVersion startVersion, ScmVersion endVersion, |
52 | |
String datePattern ) |
53 | |
throws ScmException |
54 | |
{ |
55 | 0 | return executeChangeLogCommand( repo, fileSet, null, null, null, startVersion, endVersion, datePattern ); |
56 | |
} |
57 | |
|
58 | |
|
59 | |
protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repo, ScmFileSet fileSet, |
60 | |
Date startDate, Date endDate, ScmBranch branch, |
61 | |
String datePattern ) |
62 | |
throws ScmException |
63 | |
{ |
64 | 0 | return executeChangeLogCommand( repo, fileSet, startDate, endDate, branch, null, null, datePattern ); |
65 | |
} |
66 | |
|
67 | |
private ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repo, ScmFileSet fileSet, Date startDate, |
68 | |
Date endDate, ScmBranch branch, ScmVersion startVersion, |
69 | |
ScmVersion endVersion, String datePattern ) |
70 | |
throws ScmException |
71 | |
{ |
72 | 0 | CvsScmProviderRepository repository = (CvsScmProviderRepository) repo; |
73 | |
|
74 | 0 | Commandline cl = CvsCommandUtils.getBaseCommand( "log", repository, fileSet ); |
75 | |
|
76 | 0 | if ( startDate != null ) |
77 | |
{ |
78 | 0 | SimpleDateFormat outputDate = new SimpleDateFormat( getDateFormat() ); |
79 | |
|
80 | |
String dateRange; |
81 | |
|
82 | 0 | if ( endDate == null ) |
83 | |
{ |
84 | 0 | dateRange = ">" + outputDate.format( startDate ); |
85 | |
} |
86 | |
else |
87 | |
{ |
88 | 0 | dateRange = outputDate.format( startDate ) + "<" + outputDate.format( endDate ); |
89 | |
} |
90 | |
|
91 | 0 | cl.createArg().setValue( "-d" ); |
92 | |
|
93 | 0 | addDateRangeParameter( cl, dateRange ); |
94 | |
} |
95 | |
|
96 | 0 | if ( branch != null && StringUtils.isNotEmpty( branch.getName() ) ) |
97 | |
{ |
98 | 0 | cl.createArg().setValue( "-r" + branch.getName() ); |
99 | |
} |
100 | |
|
101 | 0 | if ( startVersion != null || endVersion != null ) |
102 | |
{ |
103 | 0 | StringBuilder sb = new StringBuilder(); |
104 | 0 | sb.append( "-r" ); |
105 | 0 | if ( startVersion != null && StringUtils.isNotEmpty( startVersion.getName() ) ) |
106 | |
{ |
107 | 0 | sb.append( startVersion.getName() ); |
108 | |
} |
109 | 0 | sb.append( "::" ); |
110 | 0 | if ( endVersion != null && StringUtils.isNotEmpty( endVersion.getName() ) ) |
111 | |
{ |
112 | 0 | sb.append( endVersion.getName() ); |
113 | |
} |
114 | |
|
115 | 0 | cl.createArg().setValue( sb.toString() ); |
116 | |
} |
117 | |
|
118 | 0 | if ( getLogger().isInfoEnabled() ) |
119 | |
{ |
120 | 0 | getLogger().info( "Executing: " + cl ); |
121 | 0 | getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() ); |
122 | |
} |
123 | |
|
124 | 0 | return executeCvsCommand( cl, startDate, endDate, startVersion, endVersion, datePattern ); |
125 | |
} |
126 | |
|
127 | |
protected abstract ChangeLogScmResult executeCvsCommand( Commandline cl, Date startDate, Date endDate, |
128 | |
ScmVersion startVersion, ScmVersion endVersion, |
129 | |
String datePattern ) |
130 | |
throws ScmException; |
131 | |
|
132 | |
protected String getDateFormat() |
133 | |
{ |
134 | 0 | return CvsUtil.getSettings().getChangeLogCommandDateFormat(); |
135 | |
} |
136 | |
|
137 | |
protected void addDateRangeParameter( Commandline cl, String dateRange ) |
138 | |
{ |
139 | |
|
140 | |
|
141 | 0 | if ( Os.isFamily( "windows" ) ) |
142 | |
{ |
143 | 0 | cl.createArg().setValue( "\"" + dateRange + "\"" ); |
144 | |
} |
145 | |
else |
146 | |
{ |
147 | 0 | cl.createArg().setValue( dateRange ); |
148 | |
} |
149 | 0 | } |
150 | |
} |