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: SvnCommandLineParser.java,v $
21   Created on $Date: 2005/03/20 19:12:25 $ 
22   */
23  package net.sf.statsvn.output;
24  
25  import java.util.Locale;
26  
27  import net.sf.statcvs.output.CommandLineParser;
28  import net.sf.statcvs.output.ConfigurationException;
29  import net.sf.statcvs.output.ConfigurationOptions;
30  import net.sf.statcvs.output.CvswebIntegration;
31  import net.sf.statcvs.output.ViewCvsIntegration;
32  import net.sf.statcvs.output.ViewVcIntegration;
33  import net.sf.statcvs.output.WebRepositoryIntegration;
34  
35  /**
36   * Takes a command line, like given to the {@link net.sf.statsvn.Main#main}
37   * method, and turns it into a {@link ConfigurationOptions} object.
38   * 
39   * @author Richard Cyganiak <rcyg@gmx.de>
40   * @version $Id: SvnCommandLineParser.java,v 1.16 2005/03/20 19:12:25 squig Exp $
41   */
42  public class SvnCommandLineParser extends CommandLineParser {
43  	private boolean setCacheDir = false;
44  
45  	/**
46  	 * Constructor for SvnCommandLineParser
47  	 * 
48  	 * @param args
49  	 *            the command line parameters
50  	 */
51  	public SvnCommandLineParser(final String[] args) {
52  		super(args);
53  	}
54  
55  	protected boolean doChildrenSwitch(final String switchName) throws ConfigurationException {
56  		final String s = switchName.toLowerCase(Locale.getDefault());
57  		if (s.equals("cache-dir")) {
58  			if (isArgsEmpty()) {
59  				throw new ConfigurationException("Missing argument for -cache-dir");
60  			}
61  			SvnConfigurationOptions.setCacheDir(popNextArg());
62  			setCacheDir = true;
63  		} else if (s.equals("username")) {
64  			if (isArgsEmpty()) {
65  				throw new ConfigurationException("Missing argument for -username");
66  			}
67  			SvnConfigurationOptions.setSvnUsername(popNextArg());
68  		} else if (s.equals("password")) {
69  			if (isArgsEmpty()) {
70  				throw new ConfigurationException("Missing argument for -password");
71  			}
72  			SvnConfigurationOptions.setSvnPassword(popNextArg());
73  		} else if (s.equals("threads")) {
74  			if (isArgsEmpty()) {
75  				throw new ConfigurationException("Missing argument for -threads");
76  			}
77  			SvnConfigurationOptions.setNumberSvnDiffThreads(Integer.parseInt(popNextArg()));
78  		} else if (s.equals("concurrency-threshold")) {
79  			if (isArgsEmpty()) {
80  				throw new ConfigurationException("Missing argument for -concurrency-threshold");
81  			}
82  			SvnConfigurationOptions.setThresholdInMsToUseConcurrency(Integer.parseInt(popNextArg()));
83  		} else if (s.equals("tags-dir")) {
84  			if (isArgsEmpty()) {
85  				throw new ConfigurationException("Missing argument for -tags-dir");
86  			}
87  			SvnConfigurationOptions.setTagsDirectory(popNextArg());
88  		} else if (s.equals("dump")) {
89  			SvnConfigurationOptions.setDumpContent(true);
90  		} else if (s.equals("anonymize")) {
91  			SvnConfigurationOptions.setAnonymize(true);
92          } else if (s.equals("svnkit")) {
93              SvnConfigurationOptions.setUsingSvnKit(true);
94  		} else if (s.equals("force-legacy-diff")) {
95  			SvnConfigurationOptions.setLegacyDiff(true);
96  		} else {
97  			return false;
98  		}
99  		return true;
100 	}
101 
102 	/*
103 	 * (non-Javadoc)
104 	 * 
105 	 * @see net.sf.statcvs.output.CommandLineParser#checkForRequiredArgs()
106 	 */
107 	protected void checkForRequiredArgs() throws ConfigurationException {
108 		super.checkForRequiredArgs();
109 		if (!setCacheDir) {
110 			SvnConfigurationOptions.setCacheDirToDefault();
111 		}
112 		// now check if the user may have setup some WebIntegration that are not supported
113 		final WebRepositoryIntegration integration = ConfigurationOptions.getWebRepository();
114 		if (integration instanceof ViewCvsIntegration && !(integration instanceof ViewVcIntegration)) {
115 			throw new ConfigurationException("Sorry, ViewCvs is not supported by Subversion");
116 		} else if (integration instanceof CvswebIntegration) {
117 			throw new ConfigurationException("Sorry, CvsWeb is not supported by Subversion");
118 		}
119 	}
120 }