1 package org.apache.maven.clearcaselib;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import java.text.SimpleDateFormat;
22
23 import java.util.Date;
24 import java.util.Locale;
25
26
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.apache.maven.changelog.AbstractChangeLogGenerator;
30
31
32 import org.apache.tools.ant.types.Commandline;
33
34
35 /**
36 * A Clearcase implementation of the {@link org.apache.maven.changelog.ChangeLogGenerator}
37 * interface realized extending the {@link org.apache.maven.changelog.AbstractChangeLogGenerator}.
38 *
39 * The command line build by this class uses the <code>lshistory</code> clearcase command
40 * and formats the output in a way the ClearcaseChangeLogParser can understand. Due to this
41 * fact this implementations works only if used within a clearcase view.
42 *
43 * The command looks like this: <p>
44 * cleartool lshistory -recurse -nco -since SAMEDATE
45 * -fmt "NAME:%En\\nDATE:%Nd\\nCOMM:%-12.12o - %o - %c - Activity: %[activity]p\\nUSER:%-8.8u\\n"
46 *
47 * @author <a href="mailto:aldarion@virgilio.it">Simone Zorzetti</a>
48 */
49 public class ClearcaseChangeLogGenerator extends AbstractChangeLogGenerator
50 {
51 /** Log */
52 private static final Log LOG =
53 LogFactory.getLog( ClearcaseChangeLogGenerator.class );
54
55 /**
56 * Constructs the appropriate command line to execute the scm's
57 * log command. For Clearcase it's lshistory.
58 *
59 * @see org.apache.maven.changelog.AbstractChangeLogGenerator#getScmLogCommand()
60 * @return The command line to be executed.
61 */
62 protected Commandline getScmLogCommand()
63 {
64 Commandline command = new Commandline();
65
66 command.setExecutable( "cleartool" );
67 command.createArgument().setValue( "lshistory" );
68
69 StringBuffer format = new StringBuffer();
70
71 format.append( "NAME:%En\\n" );
72 format.append( "DATE:%Nd\\n" );
73 format.append( "COMM:%-12.12o - " );
74
75 String commentFormat = getCommentFormat();
76
77 if ( commentFormat == null )
78 {
79 format.append( "%Sn - %c - Activity: %[activity]p\\n" );
80 }
81 else
82 {
83 format.append( commentFormat );
84 }
85
86 format.append( "USER:%-8.8u\\n" );
87
88 command.createArgument().setValue( "-fmt" );
89 command.createArgument().setValue( format.toString() );
90 command.createArgument().setValue( "-recurse" );
91 command.createArgument().setValue( "-nco" );
92 command.createArgument().setValue( "-since" );
93 command.createArgument().setValue( dateRange );
94
95 return command;
96 }
97
98 /**
99 * Construct the command-line argument that is passed to the scm
100 * client to specify the appropriate date range.
101 *
102 * @param before The starting point.
103 * @param to The ending point.
104 * @return A string that can be used to specify a date to a scm
105 * system.
106 *
107 * @see org.apache.maven.changelog.AbstractChangeLogGenerator#getScmDateArgument(java.util.Date, java.util.Date)
108 */
109 protected String getScmDateArgument( Date before, Date to )
110 {
111 SimpleDateFormat sdf =
112 new SimpleDateFormat( "dd-MMM-yyyy", Locale.ENGLISH );
113 String argument = sdf.format( before );
114
115 return argument;
116 }
117
118 /**
119 * @see AbstractChangeLogGenerator#getScmTagArgument(String, String)
120 */
121 protected String getScmTagArgument( String tagStart, String tagEnd )
122 {
123 throw new UnsupportedOperationException(
124 "This plugin currently does not support generating logs from tags with Clearcase." );
125 }
126 }