1 package org.apache.maven.scm.provider.cvslib.cvsjava.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.ScmException;
23 import org.apache.maven.scm.ScmVersion;
24 import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
25 import org.apache.maven.scm.command.changelog.ChangeLogSet;
26 import org.apache.maven.scm.provider.cvslib.command.changelog.AbstractCvsChangeLogCommand;
27 import org.apache.maven.scm.provider.cvslib.command.changelog.CvsChangeLogConsumer;
28 import org.apache.maven.scm.provider.cvslib.cvsjava.util.CvsConnection;
29 import org.apache.maven.scm.provider.cvslib.cvsjava.util.CvsLogListener;
30 import org.codehaus.plexus.util.cli.Commandline;
31
32 import java.io.BufferedReader;
33 import java.io.ByteArrayInputStream;
34 import java.io.InputStreamReader;
35 import java.util.Date;
36
37
38
39
40
41 public class CvsJavaChangeLogCommand
42 extends AbstractCvsChangeLogCommand
43 {
44
45 protected ChangeLogScmResult executeCvsCommand( Commandline cl, Date startDate, Date endDate,
46 ScmVersion startVersion, ScmVersion endVersion, String datePattern )
47 throws ScmException
48 {
49 CvsLogListener logListener = new CvsLogListener();
50
51 CvsChangeLogConsumer consumer = new CvsChangeLogConsumer( getLogger(), datePattern );
52
53 try
54 {
55 boolean isSuccess = CvsConnection.processCommand( cl.getArguments(),
56 cl.getWorkingDirectory().getAbsolutePath(), logListener,
57 getLogger() );
58
59 if ( !isSuccess )
60 {
61 return new ChangeLogScmResult( cl.toString(), "The cvs command failed.",
62 logListener.getStderr().toString(), false );
63 }
64 BufferedReader stream = new BufferedReader(
65 new InputStreamReader( new ByteArrayInputStream( logListener.getStdout().toString().getBytes() ) ) );
66
67 String line;
68
69 while ( ( line = stream.readLine() ) != null )
70 {
71 consumer.consumeLine( line );
72 }
73 }
74 catch ( Exception e )
75 {
76 e.printStackTrace();
77 return new ChangeLogScmResult( cl.toString(), "The cvs command failed.", logListener.getStdout().toString(),
78 false );
79 }
80
81 ChangeLogSet changeLogSet = new ChangeLogSet( consumer.getModifications(), startDate, endDate );
82 changeLogSet.setStartVersion( startVersion );
83 changeLogSet.setEndVersion( endVersion );
84
85 return new ChangeLogScmResult( cl.toString(), changeLogSet );
86 }
87
88 protected void addDateRangeParameter( Commandline cl, String dateRange )
89 {
90 cl.createArg().setValue( dateRange );
91 }
92 }