1 package org.apache.maven.scm.provider.clearcase.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.clearcase.command.ClearCaseCommand;
30 import org.apache.maven.scm.provider.clearcase.util.ClearCaseUtil;
31 import org.apache.maven.scm.providers.clearcase.settings.Settings;
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.io.File;
38 import java.text.SimpleDateFormat;
39 import java.util.Date;
40 import java.util.Locale;
41
42
43
44
45
46
47
48
49
50 public class ClearCaseChangeLogCommand
51 extends AbstractChangeLogCommand
52 implements ClearCaseCommand
53 {
54
55
56
57
58
59 protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repository, ScmFileSet fileSet,
60 Date startDate, Date endDate, ScmBranch branch,
61 String datePattern )
62 throws ScmException
63 {
64 if ( getLogger().isDebugEnabled() )
65 {
66 getLogger().debug( "executing changelog command..." );
67 }
68 Commandline cl = createCommandLine( fileSet.getBasedir(), branch, startDate );
69
70 ClearCaseChangeLogConsumer consumer = new ClearCaseChangeLogConsumer( getLogger(), datePattern );
71
72 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
73
74 int exitCode;
75
76 try
77 {
78 if ( getLogger().isDebugEnabled() )
79 {
80 getLogger().debug(
81 "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>"
82 + cl.toString() );
83 }
84 exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr );
85 }
86 catch ( CommandLineException ex )
87 {
88 throw new ScmException( "Error while executing cvs command.", ex );
89 }
90
91 if ( exitCode != 0 )
92 {
93 return new ChangeLogScmResult( cl.toString(), "The cleartool command failed.", stderr.getOutput(), false );
94 }
95
96 return new ChangeLogScmResult( cl.toString(),
97 new ChangeLogSet( consumer.getModifications(), startDate, endDate ) );
98 }
99
100
101
102
103
104
105
106
107
108
109
110
111
112 public static Commandline createCommandLine( File workingDirectory, ScmBranch branch, Date startDate )
113 {
114 Commandline command = new Commandline();
115 command.setExecutable( "cleartool" );
116 command.createArg().setValue( "lshistory" );
117
118 command.setWorkingDirectory( workingDirectory.getAbsolutePath() );
119
120 Settings settings = ClearCaseUtil.getSettings();
121 String userFormat =
122 StringUtils.isEmpty( settings.getChangelogUserFormat() ) ? "" : settings.getChangelogUserFormat();
123
124 StringBuilder format = new StringBuilder();
125 format.append( "NAME:%En\\n" );
126 format.append( "DATE:%Nd\\n" );
127 format.append( "COMM:%-12.12o - %o - %c - Activity: %[activity]p\\n" );
128 format.append( "USER:%" + userFormat + "u\\n" );
129 format.append( "REVI:%Ln\\n" );
130
131 command.createArg().setValue( "-fmt" );
132 command.createArg().setValue( format.toString() );
133 command.createArg().setValue( "-recurse" );
134 command.createArg().setValue( "-nco" );
135
136 if ( startDate != null )
137 {
138 SimpleDateFormat sdf = new SimpleDateFormat( "dd-MMM-yyyy", Locale.ENGLISH );
139
140 String start = sdf.format( startDate );
141
142 command.createArg().setValue( "-since" );
143
144 command.createArg().setValue( start );
145 }
146
147
148
149 if ( branch != null && StringUtils.isNotEmpty( branch.getName() ) )
150 {
151 command.createArg().setValue( "-branch" );
152
153 command.createArg().setValue( branch.getName() );
154 }
155
156 return command;
157 }
158 }