1 package org.apache.maven.svnlib;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import java.io.IOException;
22
23 import java.text.SimpleDateFormat;
24
25 import java.util.Date;
26
27
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30
31
32 import org.apache.maven.changelog.AbstractChangeLogGenerator;
33
34
35 import org.apache.tools.ant.types.Commandline;
36
37
38 /**
39 * A Subversion implementation of the {@link org.apache.maven.changelog.ChangeLog}
40 * interface.
41 *
42 * @author Glenn McAllister
43 * @author <a href="mailto:jeff.martin@synamic.co.uk">Jeff Martin</a>
44 * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
45 * @author <a href="mailto:dion@multitask.com.au">dIon Gillard</a>
46 * @author <a href="mailto:bodewig@apache.org">Stefan Bodewig</a>
47 * @author <a href="mailto:peter@apache.org">Peter Donald</a>
48 * @author <a href="mailto:pete-apache-dev@kazmier.com">Pete Kazmier</a>
49 * @author Daniel Rall
50 * @version
51 * $Id: SvnChangeLogGenerator.java 532339 2007-04-25 12:28:56Z ltheussl $
52 */
53 public class SvnChangeLogGenerator extends AbstractChangeLogGenerator
54 {
55 /** Log */
56 private static final Log LOG =
57 LogFactory.getLog( SvnChangeLogGenerator.class );
58
59 /**
60 * Constructs the appropriate command line to execute the subversion
61 * log command whose output is then later parsed.
62 *
63 * @return the cvs command line to be executed.
64 */
65 protected Commandline getScmLogCommand()
66 {
67 Commandline command = new Commandline();
68
69 command.setExecutable( "svn" );
70 command.createArgument().setValue( "log" );
71 command.createArgument().setValue( "-v" );
72
73 if ( dateRange != null )
74 {
75 command.createArgument().setValue( dateRange );
76 }
77
78 return command;
79 }
80
81 /**
82 * Construct the svn command-line argument that is used to specify
83 * the appropriate date range. This date option takes the format
84 * of <code>-r{start}:{end}</code> in the case of Subversion.
85 *
86 * @param before The starting point.
87 * @param to The ending point.
88 * @return A string that can be used to specify a date to a scm
89 * system.
90 */
91 protected String getScmDateArgument( Date before, Date to )
92 {
93 SimpleDateFormat outputDate = new SimpleDateFormat( "yyyy-MM-dd" );
94
95
96 String cmd =
97 "-r{" + outputDate.format( to ) + "}:{"
98 + outputDate.format( before ) + "}";
99
100 if ( System.getProperty( "os.name" ).startsWith( "Windows" ) )
101 {
102 cmd = "\"" + cmd + "\"";
103 }
104
105 return cmd;
106 }
107
108 /**
109 * @see AbstractChangeLogGenerator#getScmTagArgument(String, String)
110 */
111 protected String getScmTagArgument( String tagStart, String tagEnd )
112 {
113 throw new UnsupportedOperationException(
114 "This plugin currently does not support generating logs from tags with Subversion." );
115 }
116
117 /**
118 * Handle ChangeLogParser IOExceptions.
119 *
120 * @param ioe The IOException thrown.
121 * @throws IOException If the handler doesn't wish to handle the
122 * exception.
123 */
124 protected void handleParserException( IOException ioe )
125 throws IOException
126 {
127 if ( ( ioe.getMessage().indexOf( "CreateProcess" ) != -1 )
128 || ( ioe.getMessage().indexOf( "svn: not found" ) != -1 ) )
129 {
130
131 LOG.error( "Unable to find svn executable. Changelog will be empty" );
132 }
133 else
134 {
135 throw ioe;
136 }
137 }
138 }