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 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 VssScmProviderRepository repo = (VssScmProviderRepository) repository;
54
55 Commandline cl = buildCmdLine( repo, fileSet, startDate, endDate );
56
57 if ( getLogger().isInfoEnabled() )
58 {
59 getLogger().info( "Executing: " + cl );
60 getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() );
61 }
62
63 VssChangeLogConsumer consumer = new VssChangeLogConsumer( repo, datePattern, getLogger() );
64
65 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
66
67 int exitCode = VssCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );
68
69 if ( exitCode != 0 )
70 {
71 return new ChangeLogScmResult( cl.toString(), "The vss command failed.", stderr.getOutput(), false );
72 }
73
74 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 Commandline command = new Commandline();
82
83 command.setWorkingDirectory( fileSet.getBasedir().getAbsolutePath() );
84
85 try
86 {
87 command.addSystemEnvironment();
88 }
89 catch ( Exception e )
90 {
91 throw new ScmException( "Can't add system environment.", e );
92 }
93
94 command.addEnvironment( "SSDIR", repo.getVssdir() );
95
96 String ssDir = VssCommandLineUtils.getSsDir();
97
98 command.setExecutable( ssDir + VssConstants.SS_EXE );
99
100 command.createArg().setValue( VssConstants.COMMAND_HISTORY );
101
102 command.createArg().setValue( VssConstants.PROJECT_PREFIX + repo.getProject() );
103
104
105 if ( repo.getUserPassword() != null )
106 {
107 command.createArg().setValue( VssConstants.FLAG_LOGIN + repo.getUserPassword() );
108 }
109
110
111 command.createArg().setValue( VssConstants.FLAG_RECURSION );
112
113
114 command.createArg().setValue( VssConstants.FLAG_AUTORESPONSE_DEF );
115
116
117 if ( startDate != null )
118 {
119 if ( endDate == null )
120 {
121 endDate = new Date();
122 }
123
124 SimpleDateFormat sdf = new SimpleDateFormat( "dd/MM/yyyy", Locale.ENGLISH );
125 String dateRange = sdf.format( endDate ) + "~" + sdf.format( startDate );
126 command.createArg().setValue( VssConstants.FLAG_VERSION_DATE + dateRange );
127 }
128 return command;
129 }
130 }