1 | |
package org.apache.maven.scm.provider.vss.commands.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.command.changelog.AbstractChangeLogCommand; |
26 | |
import org.apache.maven.scm.command.changelog.ChangeLogScmResult; |
27 | |
import org.apache.maven.scm.command.changelog.ChangeLogSet; |
28 | |
import org.apache.maven.scm.provider.ScmProviderRepository; |
29 | |
import org.apache.maven.scm.provider.vss.commands.VssCommandLineUtils; |
30 | |
import org.apache.maven.scm.provider.vss.commands.VssConstants; |
31 | |
import org.apache.maven.scm.provider.vss.repository.VssScmProviderRepository; |
32 | |
import org.codehaus.plexus.util.cli.CommandLineUtils; |
33 | |
import org.codehaus.plexus.util.cli.Commandline; |
34 | |
|
35 | |
import java.text.SimpleDateFormat; |
36 | |
import java.util.Date; |
37 | |
import java.util.Locale; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | 1 | public class VssHistoryCommand |
45 | |
extends AbstractChangeLogCommand |
46 | |
{ |
47 | |
|
48 | |
protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repository, ScmFileSet fileSet, |
49 | |
Date startDate, Date endDate, ScmBranch branch, |
50 | |
String datePattern ) |
51 | |
throws ScmException |
52 | |
{ |
53 | 0 | VssScmProviderRepository repo = (VssScmProviderRepository) repository; |
54 | |
|
55 | 0 | Commandline cl = buildCmdLine( repo, fileSet, startDate, endDate ); |
56 | |
|
57 | 0 | if ( getLogger().isInfoEnabled() ) |
58 | |
{ |
59 | 0 | getLogger().info( "Executing: " + cl ); |
60 | 0 | getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() ); |
61 | |
} |
62 | |
|
63 | 0 | VssChangeLogConsumer consumer = new VssChangeLogConsumer( repo, datePattern, getLogger() ); |
64 | |
|
65 | 0 | CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); |
66 | |
|
67 | 0 | int exitCode = VssCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() ); |
68 | |
|
69 | 0 | if ( exitCode != 0 ) |
70 | |
{ |
71 | 0 | return new ChangeLogScmResult( cl.toString(), "The vss command failed.", stderr.getOutput(), false ); |
72 | |
} |
73 | |
|
74 | 0 | return new ChangeLogScmResult( cl.toString(), |
75 | |
new ChangeLogSet( consumer.getModifications(), startDate, endDate ) ); |
76 | |
} |
77 | |
|
78 | |
public Commandline buildCmdLine( VssScmProviderRepository repo, ScmFileSet fileSet, Date startDate, Date endDate ) |
79 | |
throws ScmException |
80 | |
{ |
81 | 1 | Commandline command = new Commandline(); |
82 | |
|
83 | 1 | command.setWorkingDirectory( fileSet.getBasedir().getAbsolutePath() ); |
84 | |
|
85 | |
try |
86 | |
{ |
87 | 1 | command.addSystemEnvironment(); |
88 | |
} |
89 | 0 | catch ( Exception e ) |
90 | |
{ |
91 | 0 | throw new ScmException( "Can't add system environment.", e ); |
92 | 1 | } |
93 | |
|
94 | 1 | command.addEnvironment( "SSDIR", repo.getVssdir() ); |
95 | |
|
96 | 1 | String ssDir = VssCommandLineUtils.getSsDir(); |
97 | |
|
98 | 1 | command.setExecutable( ssDir + VssConstants.SS_EXE ); |
99 | |
|
100 | 1 | command.createArg().setValue( VssConstants.COMMAND_HISTORY ); |
101 | |
|
102 | 1 | command.createArg().setValue( VssConstants.PROJECT_PREFIX + repo.getProject() ); |
103 | |
|
104 | |
|
105 | 1 | if ( repo.getUserPassword() != null ) |
106 | |
{ |
107 | 1 | command.createArg().setValue( VssConstants.FLAG_LOGIN + repo.getUserPassword() ); |
108 | |
} |
109 | |
|
110 | |
|
111 | 1 | command.createArg().setValue( VssConstants.FLAG_RECURSION ); |
112 | |
|
113 | |
|
114 | 1 | command.createArg().setValue( VssConstants.FLAG_AUTORESPONSE_DEF ); |
115 | |
|
116 | |
|
117 | 1 | if ( startDate != null ) |
118 | |
{ |
119 | 1 | if ( endDate == null ) |
120 | |
{ |
121 | 0 | endDate = new Date(); |
122 | |
} |
123 | |
|
124 | 1 | SimpleDateFormat sdf = new SimpleDateFormat( "dd/MM/yyyy", Locale.ENGLISH ); |
125 | 1 | String dateRange = sdf.format( endDate ) + "~" + sdf.format( startDate ); |
126 | 1 | command.createArg().setValue( VssConstants.FLAG_VERSION_DATE + dateRange ); |
127 | |
} |
128 | 1 | return command; |
129 | |
} |
130 | |
} |