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  /**
31   * Ant task for running StatSVN.
32   * 
33   * @author Andy Glover
34   * @author Richard Cyganiak
35   * @author Benoit Xhenseval
36   * @author Jason Kealey
37   */
38  public class StatSvnTask extends StatCvsTask {
39  	private String cacheDirectory;
40  
41  	private String svnPassword;
42  
43  	private String svnUsername;
44  
45  	private int numberSvnDiffThreads;
46  
47  	private long thresholdInMsToUseConcurrency;
48  
49  	private boolean useLegacyDiff = false;
50  
51  	/**
52  	 * Constructor for StatSvnTask.
53  	 */
54  	public StatSvnTask() {
55  		super();
56  	}
57  
58  	/**
59  	 * Runs the task
60  	 * 
61  	 * @throws buildException
62  	 *             if an IO Error occurs
63  	 */
64  	public void execute() {
65  		try {
66  			this.initProperties();
67  
68  			Main.init();
69  
70  			// main usually builds checks the command line here but we will skip
71  			// that step as it is done in initProperties
72  
73  			Main.generate();
74  		} catch (final Exception e) {
75  			SvnConfigurationOptions.getTaskLogger().error(Main.printStackTrace(e));
76  		}
77  	}
78  
79  	/**
80  	 * method initializes the ConfigurationOptions object with received values.
81  	 */
82  	protected void initProperties() throws ConfigurationException {
83  		super.initProperties();
84  		if (this.cacheDirectory != null) {
85  			SvnConfigurationOptions.setCacheDir(this.cacheDirectory);
86  		} else {
87  			SvnConfigurationOptions.setCacheDirToDefault();
88  		}
89  
90  		if (this.svnPassword != null) {
91  			SvnConfigurationOptions.setSvnPassword(this.svnPassword);
92  		}
93  		if (this.svnUsername != null) {
94  			SvnConfigurationOptions.setSvnUsername(this.svnUsername);
95  		}
96  		if (this.numberSvnDiffThreads != 0) {
97  			SvnConfigurationOptions.setNumberSvnDiffThreads(this.numberSvnDiffThreads);
98  		}
99  		if (this.thresholdInMsToUseConcurrency != 0) {
100 			SvnConfigurationOptions.setThresholdInMsToUseConcurrency(this.thresholdInMsToUseConcurrency);
101 		}
102 		if (this.useLegacyDiff) { // only override if we don't want it. 
103 			SvnConfigurationOptions.setLegacyDiff(true);
104 		}
105 		SvnConfigurationOptions.setTaskLogger(new AntTaskLogger(this));
106 	}
107 
108 	/**
109 	 * @param cacheDirectory
110 	 *            String representing the cache directory of the program
111 	 */
112 	public void setCacheDir(final String cacheDir) {
113 		this.cacheDirectory = cacheDir;
114 	}
115 
116 	/**
117 	 * @param password
118 	 *            The svnPassword to set.
119 	 */
120 	public void setPassword(final String password) {
121 		this.svnPassword = password;
122 	}
123 
124 	/**
125 	 * @param username
126 	 *            The svnUsername to set.
127 	 */
128 	public void setUsername(final String username) {
129 		this.svnUsername = username;
130 	}
131 
132 	/**
133 	 * @param threads
134 	 *            the numberSvnDiffThreads to set
135 	 */
136 	public void setThreads(final int threads) {
137 		this.numberSvnDiffThreads = threads;
138 	}
139 
140 	/**
141 	 * @param thresholdInMsToUseConcurrency
142 	 *            the thresholdInMsToUseConcurrency to set
143 	 */
144 	public void setConcurrencyThreshold(final long thresholdToUseConcurrency) {
145 		this.thresholdInMsToUseConcurrency = thresholdToUseConcurrency;
146 	}
147 
148 	/**
149 	 * Should we use a one diff per-file-per-revision or should we use the newer one diff per-revision?
150 	 * 
151 	 * @param isLegacy true if the legacy diff should be used.  
152 	 */
153 	public void setLegacyDiff(final boolean isLegacy) {
154 		this.useLegacyDiff = isLegacy;
155 	}
156 }