View Javadoc

1   /*
2    StatCvs - CVS statistics generation 
3    Copyright (C) 2002  Lukasz Pekacki <lukasz@pekacki.de>
4    http://statcvs.sf.net/
5    
6    This library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
10  
11   This library is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   Lesser General Public License for more details.
15  
16   You should have received a copy of the GNU Lesser General Public
17   License along with this library; if not, write to the Free Software
18   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   
20   $RCSfile: StatSvnTask.java,v $
21   $Date: 2005/03/24 00:19:51 $ 
22   */
23  package net.sf.statsvn.ant;
24  
25  import net.sf.statcvs.ant.StatCvsTask;
26  import net.sf.statcvs.output.ConfigurationException;
27  import net.sf.statsvn.Main;
28  import net.sf.statsvn.output.SvnConfigurationOptions;
29  
30  import org.apache.tools.ant.BuildException;
31  
32  /**
33   * Ant task for running StatSVN.
34   * 
35   * @author Andy Glover
36   * @author Richard Cyganiak
37   * @author Benoit Xhenseval
38   * @author Jason Kealey
39   */
40  public class StatSvnTask extends StatCvsTask {
41  	private String cacheDirectory;
42  
43  	private String svnPassword;
44  
45  	private String svnUsername;
46  
47  	private int numberSvnDiffThreads;
48  
49  	private long thresholdInMsToUseConcurrency;
50  
51  	private boolean useLegacyDiff = false;
52  
53  	/**
54  	 * Constructor for StatSvnTask.
55  	 */
56  	public StatSvnTask() {
57  		super();
58  	}
59  
60  	/**
61  	 * Runs the task
62  	 * 
63  	 * @throws BuildException
64  	 *             if an IO Error occurs
65  	 */
66  	public void execute() {
67  		try {
68  			this.initProperties();
69  
70  			Main.init();
71  
72  			// main usually builds checks the command line here but we will skip
73  			// that step as it is done in initProperties
74  
75  			Main.generate();
76  		} catch (final Exception e) {
77  			SvnConfigurationOptions.getTaskLogger().error(Main.printStackTrace(e));
78  		}
79  	}
80  
81  	/**
82  	 * method initializes the ConfigurationOptions object with received values.
83  	 */
84  	protected void initProperties() throws ConfigurationException {
85  		super.initProperties();
86  		if (this.cacheDirectory != null) {
87  			SvnConfigurationOptions.setCacheDir(this.cacheDirectory);
88  		} else {
89  			SvnConfigurationOptions.setCacheDirToDefault();
90  		}
91  
92  		if (this.svnPassword != null) {
93  			SvnConfigurationOptions.setSvnPassword(this.svnPassword);
94  		}
95  		if (this.svnUsername != null) {
96  			SvnConfigurationOptions.setSvnUsername(this.svnUsername);
97  		}
98  		if (this.numberSvnDiffThreads != 0) {
99  			SvnConfigurationOptions.setNumberSvnDiffThreads(this.numberSvnDiffThreads);
100 		}
101 		if (this.thresholdInMsToUseConcurrency != 0) {
102 			SvnConfigurationOptions.setThresholdInMsToUseConcurrency(this.thresholdInMsToUseConcurrency);
103 		}
104 		if (this.useLegacyDiff) { // only override if we don't want it. 
105 			SvnConfigurationOptions.setLegacyDiff(true);
106 		}
107 		SvnConfigurationOptions.setTaskLogger(new AntTaskLogger(this));
108 	}
109 
110 	/**
111 	 * @param cacheDirectory
112 	 *            String representing the cache directory of the program
113 	 */
114 	public void setCacheDir(final String cacheDir) {
115 		this.cacheDirectory = cacheDir;
116 	}
117 
118 	/**
119 	 * @param password
120 	 *            The svnPassword to set.
121 	 */
122 	public void setPassword(final String password) {
123 		this.svnPassword = password;
124 	}
125 
126 	/**
127 	 * @param username
128 	 *            The svnUsername to set.
129 	 */
130 	public void setUsername(final String username) {
131 		this.svnUsername = username;
132 	}
133 
134 	/**
135 	 * @param threads
136 	 *            the numberSvnDiffThreads to set
137 	 */
138 	public void setThreads(final int threads) {
139 		this.numberSvnDiffThreads = threads;
140 	}
141 
142 	/**
143 	 * @param thresholdInMsToUseConcurrency
144 	 *            the thresholdInMsToUseConcurrency to set
145 	 */
146 	public void setConcurrencyThreshold(final long thresholdToUseConcurrency) {
147 		this.thresholdInMsToUseConcurrency = thresholdToUseConcurrency;
148 	}
149 
150 	/**
151 	 * Should we use a one diff per-file-per-revision or should we use the newer one diff per-revision?
152 	 * 
153 	 * @param isLegacy true if the legacy diff should be used.  
154 	 */
155 	public void setLegacyDiff(final boolean isLegacy) {
156 		this.useLegacyDiff = isLegacy;
157 	}
158 }