1 package org.apache.maven.scm.provider.starteam.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.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.starteam.command.StarteamCommand;
30 import org.apache.maven.scm.provider.starteam.command.StarteamCommandLineUtils;
31 import org.apache.maven.scm.provider.starteam.repository.StarteamScmProviderRepository;
32 import org.codehaus.plexus.util.StringUtils;
33 import org.codehaus.plexus.util.cli.CommandLineException;
34 import org.codehaus.plexus.util.cli.CommandLineUtils;
35 import org.codehaus.plexus.util.cli.Commandline;
36
37 import java.util.Date;
38
39
40
41
42
43
44 public class StarteamChangeLogCommand
45 extends AbstractChangeLogCommand
46 implements StarteamCommand
47 {
48
49
50
51
52
53 protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repo, ScmFileSet fileSet,
54 Date startDate, Date endDate, ScmBranch branch,
55 String datePattern )
56 throws ScmException
57 {
58 if ( ( branch != null || StringUtils.isNotEmpty( ( branch == null ) ? null : branch.getName() ) )
59 && ( getLogger().isWarnEnabled() ) )
60 {
61 getLogger().warn( "This provider doesn't support changelog with on a given branch." );
62 }
63
64 StarteamScmProviderRepository repository = (StarteamScmProviderRepository) repo;
65
66
67 Commandline cl = createCommandLine( repository, fileSet, startDate );
68
69 StarteamChangeLogConsumer consumer =
70 new StarteamChangeLogConsumer( fileSet.getBasedir(), getLogger(), startDate, endDate, datePattern );
71
72 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
73
74 int exitCode;
75
76 try
77 {
78 exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr );
79 }
80 catch ( CommandLineException ex )
81 {
82 throw new ScmException( "Error while executing command.", ex );
83 }
84
85 if ( exitCode != 0 )
86 {
87 return new ChangeLogScmResult( cl.toString(), "The 'stcmd' command failed.", stderr.getOutput(), false );
88 }
89
90 return new ChangeLogScmResult( cl.toString(),
91 new ChangeLogSet( consumer.getModifications(), startDate, endDate ) );
92 }
93
94
95
96
97
98 public static Commandline createCommandLine( StarteamScmProviderRepository repo, ScmFileSet workingDirectory,
99 Date startDate )
100 {
101
102
103 return StarteamCommandLineUtils.createStarteamCommandLine( "hist", null, workingDirectory, repo );
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121 }
122 }