Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-vcm-dev] Patch: default user names for cvs

>>>>> "Michael" == Michael Valenta <Michael_Valenta@xxxxxxx> writes:

Michael> If you wrote the patch in such a way that obtaining the list
Michael> of known repositories was through a single method, I would be
Michael> happy to modify the method to suck in the repositories from
Michael> an extension point.

An offer I can't refuse!

I've appended what I currently have.  This is against 2.0.1.

It isn't completely polished yet.  I still have to fix the saving and
restoring of settings a bit.  Mostly I'm posting to make sure my
approach is ok.  I changed things so that I could extend
ConfigurationWizardMainPage; I don't know Eclipse style well enough to
know if this kind of ad hoc subclassing is considered ok.

As you can see there is a pretty simple object which is used to
represent a public repository.  Basically each repository has six
associated string properties.  Right now there's a hard-coded list of
the repositories I knew of off the top of my head (I'm still missing a
few important ones...).

Constructive criticism welcomed.  I can rewrite it again if need be.

Tom


Index: src/org/eclipse/team/internal/ccvs/ui/RepositoriesView.java
===================================================================
RCS file: /usr/cygnus/eclipse-cvsroot/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/RepositoriesView.java,v
retrieving revision 1.5
diff -u -r1.5 RepositoriesView.java
--- src/org/eclipse/team/internal/ccvs/ui/RepositoriesView.java 21 Oct 2002 21:04:26 -0000 1.5
+++ src/org/eclipse/team/internal/ccvs/ui/RepositoriesView.java 3 Dec 2002 05:52:10 -0000
@@ -133,7 +133,17 @@
 			}
 		};
 		WorkbenchHelp.setHelp(newAction, IHelpContextIds.NEW_REPOSITORY_LOCATION_ACTION);
-		
+
+		// New Standard Repository (popup)
+		final Action newStdAction = new Action(Policy.bind("RepositoriesView.newStd"), CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_NEWLOCATION)) { //$NON-NLS-1$
+			public void run() {
+				NewLocationWizard wizard = new NewLocationWizard(NewLocationWizard.STANDARD);
+				WizardDialog dialog = new WizardDialog(shell, wizard);
+				dialog.open();
+			}
+		};
+		WorkbenchHelp.setHelp(newStdAction, IHelpContextIds.NEW_REPOSITORY_LOCATION_ACTION);
+
 /*		final Action newAnonAction = new Action(Policy.bind("RepositoriesView.newAnonCVS"), CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_NEWLOCATION)) { //$NON-NLS-1$
 			public void run() {
 				Properties p = new Properties();
@@ -192,6 +202,7 @@
 					manager.add(propertiesAction);
 				}
 				sub.add(newAction);
+				sub.add(newStdAction);
 				//sub.add(newAnonAction);
 			}
 		});
@@ -321,4 +332,4 @@
 	public void setFocus() {
 		viewer.getControl().setFocus();
 	}
-}
\ No newline at end of file
+}
Index: src/org/eclipse/team/internal/ccvs/ui/messages.properties
===================================================================
RCS file: /usr/cygnus/eclipse-cvsroot/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties,v
retrieving revision 1.5
diff -u -r1.5 messages.properties
--- src/org/eclipse/team/internal/ccvs/ui/messages.properties 21 Oct 2002 21:04:26 -0000 1.5
+++ src/org/eclipse/team/internal/ccvs/ui/messages.properties 3 Dec 2002 05:52:12 -0000
@@ -268,6 +268,8 @@
 ConfigurationWizardMainPage.useDefaultPort=Use &Default Port
 ConfigurationWizardMainPage.usePort=Use Por&t:
 ConfigurationWizardMainPage.repositoryPath=&Repository path:
+ConfigurationWizardMainPage.project=&Project:
+ConfigurationWizardMainPage.invalidProjectName=Invalid Project Name
 ConfigurationWizardMainPage.invalidUserName=Invalid User Name
 ConfigurationWizardMainPage.invalidHostName=Invalid Host Name
 ConfigurationWizardMainPage.invalidPort=Invalid Port
@@ -421,6 +423,7 @@
 RepositoriesView.refresh=&Refresh View
 RepositoriesView.refreshTooltip=Refresh View
 RepositoriesView.new=&Repository Location...
+RepositoriesView.newStd=&Standard Public Repository Location...
 RepositoriesView.newSubmenu=&New
 RepositoriesView.Show_Folders_6=Show Folders
 RepositoriesView.Show_Modules_7=Show Modules
Index: src/org/eclipse/team/internal/ccvs/ui/wizards/ConfigurationWizardMainPage.java
===================================================================
RCS file: /usr/cygnus/eclipse-cvsroot/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/ConfigurationWizardMainPage.java,v
retrieving revision 1.5
diff -u -r1.5 ConfigurationWizardMainPage.java
--- src/org/eclipse/team/internal/ccvs/ui/wizards/ConfigurationWizardMainPage.java 21 Oct 2002 21:04:27 -0000 1.5
+++ src/org/eclipse/team/internal/ccvs/ui/wizards/ConfigurationWizardMainPage.java 3 Dec 2002 05:52:13 -0000
@@ -36,44 +36,44 @@
  * Wizard page for entering information about a CVS repository location.
  */
 public class ConfigurationWizardMainPage extends CVSWizardPage {
-	private boolean showValidate;
-	private boolean validate;
+	protected boolean showValidate;
+	protected boolean validate;
 	
 	// Widgets
 	
 	// Connection Method
-	private Combo connectionMethodCombo;
+	protected Combo connectionMethodCombo;
 	// User
-	private Combo userCombo;
+	protected Combo userCombo;
 	// Password
-	private Text passwordText;
+	protected Text passwordText;
 	// Port
-	private Text portText;
-	private Button useDefaultPort;
-	private Button useCustomPort;
+	protected Text portText;
+	protected Button useDefaultPort;
+	protected Button useCustomPort;
 	// Host
-	private Combo hostCombo;
+	protected Combo hostCombo;
 	// Repository Path
-	private Combo repositoryPathCombo;
+	protected Combo repositoryPathCombo;
 	// Validation
-	private Button validateButton;
+	protected Button validateButton;
 	
-	private static final int COMBO_HISTORY_LENGTH = 5;
+	protected static final int COMBO_HISTORY_LENGTH = 5;
 	
-	private Properties properties = null;
+	protected Properties properties = null;
 	
 	// Dialog store id constants
-	private static final String STORE_USERNAME_ID =
+	protected static final String STORE_USERNAME_ID =
 		"ConfigurationWizardMainPage.STORE_USERNAME_ID";//$NON-NLS-1$
-	private static final String STORE_HOSTNAME_ID =
+	protected static final String STORE_HOSTNAME_ID =
 		"ConfigurationWizardMainPage.STORE_HOSTNAME_ID";//$NON-NLS-1$
-	private static final String STORE_PATH_ID =
+	protected static final String STORE_PATH_ID =
 		"ConfigurationWizardMainPage.STORE_PATH_ID";//$NON-NLS-1$
-	private static final String STORE_DONT_VALIDATE_ID =
+	protected static final String STORE_DONT_VALIDATE_ID =
 		"ConfigurationWizardMainPage.STORE_DONT_VALIDATE_ID";//$NON-NLS-1$
 	
 	// In case the page was launched from a different wizard	
-	private IDialogSettings settings;
+	protected IDialogSettings settings;
 	
 	/**
 	 * ConfigurationWizardMainPage constructor.
@@ -94,7 +94,7 @@
 	 * @param newEntry the entry to add to the history
 	 * @return the history with the new entry appended
 	 */
-	private String[] addToHistory(String[] history, String newEntry) {
+	protected String[] addToHistory(String[] history, String newEntry) {
 		ArrayList l = new ArrayList(Arrays.asList(history));
 		addToHistory(l, newEntry);
 		String[] r = new String[l.size()];
@@ -115,7 +115,7 @@
 	 * @param history the current history
 	 * @param newEntry the entry to add to the history
 	 */
-	private void addToHistory(List history, String newEntry) {
+	protected void addToHistory(List history, String newEntry) {
 		history.remove(newEntry);
 		history.add(0,newEntry);
 	
@@ -272,7 +272,7 @@
 	/**
 	 * Initializes states of the controls.
 	 */
-	private void initializeValues() {
+	protected void initializeValues() {
 		// Set remembered values
 		IDialogSettings settings = getDialogSettings();
 		if (settings != null) {
@@ -347,7 +347,7 @@
 	/**
 	 * Saves the widget values
 	 */
-	private void saveWidgetValues() {
+	protected void saveWidgetValues() {
 		// Update history
 		IDialogSettings settings = getDialogSettings();
 		if (settings != null) {
@@ -401,7 +401,7 @@
 	 * Validates the contents of the editable fields and set page completion 
 	 * and error messages appropriately.
 	 */
-	private void validateFields() {
+	protected void validateFields() {
 		String user = userCombo.getText();
 		if (user.length() == 0) {
 			setErrorMessage(null);
Index: src/org/eclipse/team/internal/ccvs/ui/wizards/NewLocationWizard.java
===================================================================
RCS file: /usr/cygnus/eclipse-cvsroot/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/NewLocationWizard.java,v
retrieving revision 1.5
diff -u -r1.5 NewLocationWizard.java
--- src/org/eclipse/team/internal/ccvs/ui/wizards/NewLocationWizard.java 21 Oct 2002 21:04:27 -0000 1.5
+++ src/org/eclipse/team/internal/ccvs/ui/wizards/NewLocationWizard.java 3 Dec 2002 05:52:13 -0000
@@ -30,7 +30,22 @@
 
 	private Properties properties = null;
 	
+	// Type of wizard, whether GENERIC or STANDARD.
+	private int type;
+
+	/** Type used when creating a dialog that can find an arbitrary
+		cvs repository.  */
+	public static final int GENERIC = 0;
+	/** Type used when creating a dialog that knows about the standard
+		public repositories.  */
+	public static final int STANDARD = 1;
+
 	public NewLocationWizard() {
+		this(GENERIC);
+	}
+
+	public NewLocationWizard(int type) {
+		this.type = type;
 		IDialogSettings workbenchSettings = CVSUIPlugin.getPlugin().getDialogSettings();
 		IDialogSettings section = workbenchSettings.getSection("NewLocationWizard");//$NON-NLS-1$
 		if (section == null) {
@@ -49,7 +64,11 @@
 	 * Creates the wizard pages
 	 */
 	public void addPages() {
-		mainPage = new ConfigurationWizardMainPage("repositoryPage1", Policy.bind("NewLocationWizard.heading"), CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_WIZBAN_NEW_LOCATION)); //$NON-NLS-1$ //$NON-NLS-2$
+		if (type == GENERIC) {
+			mainPage = new ConfigurationWizardMainPage("repositoryPage1", Policy.bind("NewLocationWizard.heading"), CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_WIZBAN_NEW_LOCATION)); //$NON-NLS-1$ //$NON-NLS-2$
+		} else {
+			mainPage = new StandardWizardMainPage("repositoryPage1", Policy.bind("NewLocationWizard.heading"), CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_WIZBAN_NEW_LOCATION)); //$NON-NLS-1$ //$NON-NLS-2$
+		}
 		if (properties != null) {
 			mainPage.setProperties(properties);
 		}
Index: src/org/eclipse/team/internal/ccvs/ui/wizards/StandardWizardMainPage.java
===================================================================
RCS file: src/org/eclipse/team/internal/ccvs/ui/wizards/StandardWizardMainPage.java
diff -N src/org/eclipse/team/internal/ccvs/ui/wizards/StandardWizardMainPage.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/team/internal/ccvs/ui/wizards/StandardWizardMainPage.java 3 Dec 2002 05:52:13 -0000
@@ -0,0 +1,405 @@
+package org.eclipse.team.internal.ccvs.ui.wizards;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2002.
+ * All Rights Reserved.
+ */
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+
+import java.text.MessageFormat;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin;
+import org.eclipse.team.internal.ccvs.ui.IHelpContextIds;
+import org.eclipse.team.internal.ccvs.ui.Policy;
+import org.eclipse.ui.help.WorkbenchHelp;
+
+/**
+ * Wizard page for entering information about a standard CVS
+ * repository location.
+ */
+public class StandardWizardMainPage extends ConfigurationWizardMainPage {
+	// The standard repositories we know about.
+	protected StandardRepository[] standardRepositories;
+
+	/**
+	 * ConfigurationWizardMainPage constructor.
+	 * 
+	 * @param pageName  the name of the page
+	 * @param title  the title of the page
+	 * @param titleImage  the image for the page
+	 */
+	public StandardWizardMainPage(String pageName, String title, ImageDescriptor titleImage) {
+		super(pageName, title, titleImage);
+	}
+
+	/**
+	 * Creates the UI part of the page.
+	 * 
+	 * @param parent  the parent of the created widgets
+	 */
+	public void createControl(Composite parent) {
+		Composite composite = createComposite(parent, 2);
+		// set F1 help
+		WorkbenchHelp.setHelp(composite, IHelpContextIds.SHARING_NEW_REPOSITORY_PAGE);
+
+		Listener listener = new Listener() {
+			public void handleEvent(Event event) {
+				updateWidgetEnablements();
+			}
+		};
+		
+		Group g = createGroup(composite, Policy.bind("ConfigurationWizardMainPage.Location_1")); //$NON-NLS-1$
+		
+		// Standard cvs repository.
+		createLabel(g, Policy.bind("ConfigurationWizardMainPage.host")); //$NON-NLS-1$
+		hostCombo = createCombo(g);
+		hostCombo.addListener(SWT.Selection, listener);
+
+		createLabel(g, Policy.bind("ConfigurationWizardMainPage.project")); //$NON-NLS-1$
+		repositoryPathCombo = createEditableCombo(g);
+		repositoryPathCombo.addListener(SWT.Selection, listener);
+		repositoryPathCombo.addListener(SWT.Modify, listener);
+
+		g = createGroup(composite, Policy.bind("ConfigurationWizardMainPage.Authentication_2")); //$NON-NLS-1$
+		
+		// User name
+		createLabel(g, Policy.bind("ConfigurationWizardMainPage.userName")); //$NON-NLS-1$
+		userCombo = createEditableCombo(g);
+		userCombo.addListener(SWT.Selection, listener);
+		userCombo.addListener(SWT.Modify, listener);
+		
+		// Password
+		createLabel(g, Policy.bind("ConfigurationWizardMainPage.password")); //$NON-NLS-1$
+		passwordText = createTextField(g);
+		passwordText.setEchoChar('*');
+
+		g = createGroup(composite, Policy.bind("ConfigurationWizardMainPage.Connection_3")); //$NON-NLS-1$
+		
+		// Connection type
+		createLabel(g, Policy.bind("ConfigurationWizardMainPage.connection")); //$NON-NLS-1$
+		connectionMethodCombo = createCombo(g);
+
+		// create a composite to ensure the validate button is in its own tab group
+		if (showValidate) {
+			Composite validateButtonTabGroup = new Composite(composite, SWT.NONE);
+			GridData data = new GridData();
+			data.horizontalSpan = 2;
+			validateButtonTabGroup.setLayoutData(data);
+			validateButtonTabGroup.setLayout(new FillLayout());
+
+			validateButton = new Button(validateButtonTabGroup, SWT.CHECK);
+			validateButton.setText(Policy.bind("ConfigurationWizardAutoconnectPage.validate")); //$NON-NLS-1$
+			validateButton.addListener(SWT.Selection, new Listener() {
+				public void handleEvent(Event e) {
+					validate = validateButton.getSelection();
+				}
+			});
+		}
+		
+		initializeValues();
+		updateWidgetEnablements();
+		hostCombo.setFocus();
+		
+		setControl(composite);
+	}
+
+	/**
+	 * @see CVSWizardPage#finish
+	 */
+	public boolean finish(IProgressMonitor monitor) {
+		// Set the result to be the current values
+		Properties result = new Properties();
+
+		StandardRepository repo = getCurrentRepository(hostCombo.getText());
+
+		String user = userCombo.getText();
+		boolean anon = isAnonymous(user);
+
+		if (anon) {
+			result.setProperty("connection", "pserver");
+			user = repo.anonymousUserName;
+			result.setProperty("password", repo.anonymousPassword);
+		} else {
+			result.setProperty("connection", connectionMethodCombo.getText()); //$NON-NLS-1$
+			result.setProperty("password", passwordText.getText()); //$NON-NLS-1$
+		}
+		result.setProperty("user", user);
+
+		String hostPlusPath = repo.computeCvsroot(repositoryPathCombo.getText(), user);
+		int index = hostPlusPath.indexOf(':');
+
+		result.setProperty("host", hostPlusPath.substring(0, index)); //$NON-NLS-1$
+		result.setProperty("root", hostPlusPath.substring(index + 1)); //$NON-NLS-1$
+		this.properties = result;
+		
+		saveWidgetValues();
+		
+		return true;
+	}
+
+	/**
+	 * Initializes states of the controls.
+	 */
+	protected void initializeValues() {
+		// Set remembered values
+		IDialogSettings settings = getDialogSettings();
+
+		standardRepositories = getStandardRepositories();
+		for (int i = 0; i < standardRepositories.length; i++) {
+			hostCombo.add(standardRepositories[i].repositoryName);
+		}
+
+		if (settings != null) {
+			// FIXME: setting should be specific to us, and store the
+			// project name.
+			String[] paths = settings.getArray(STORE_PATH_ID);
+			if (paths != null) {
+				for (int i = 0; i < paths.length; i++) {
+					repositoryPathCombo.add(paths[i]);
+				}
+			}
+			String[] userNames = settings.getArray(STORE_USERNAME_ID);
+			if (userNames == null) {
+				userNames = new String[] {
+					System.getProperty("user.name"),
+					"anonymous",
+					"anoncvs",
+					"cvs"
+				};
+				settings.put(STORE_USERNAME_ID, userNames);
+			}
+			if (userNames != null) {
+				for (int i = 0; i < userNames.length; i++) {
+					userCombo.add(userNames[i]);
+				}
+			}
+			if (showValidate) {
+				validate = !settings.getBoolean(STORE_DONT_VALIDATE_ID);
+				validateButton.setSelection(validate);
+			}
+		}
+		
+		// Initialize other values and widget states
+		String[] methods = CVSProviderPlugin.getProvider().getSupportedConnectionMethods();
+		for (int i = 0; i < methods.length; i++) {
+			connectionMethodCombo.add(methods[i]);
+		}
+		
+		connectionMethodCombo.select(0);
+		
+		if(properties != null) {
+			String method = (String)properties.getProperty("connection"); //$NON-NLS-1$
+			if (method == null) {
+				connectionMethodCombo.select(0);
+			} else {
+				connectionMethodCombo.select(connectionMethodCombo.indexOf(method));
+			}
+	
+			String user = (String)properties.getProperty("user"); //$NON-NLS-1$
+			if (user != null) {
+				userCombo.setText(user);
+			}
+	
+			String password = (String)properties.getProperty("password"); //$NON-NLS-1$
+			if (password != null) {
+				passwordText.setText(password);
+			}
+		}
+	}
+
+	/**
+	 * Saves the widget values
+	 */
+	protected void saveWidgetValues() {
+		// Update history
+		IDialogSettings settings = getDialogSettings();
+		if (settings != null) {
+			String[] userNames = settings.getArray(STORE_USERNAME_ID);
+			if (userNames == null) userNames = new String[0];
+			userNames = addToHistory(userNames, userCombo.getText());
+			settings.put(STORE_USERNAME_ID, userNames);
+
+			// FIXME: specific to us again.
+			String[] paths = settings.getArray(STORE_PATH_ID);
+			if (paths == null) paths = new String[0];
+			paths = addToHistory(paths, repositoryPathCombo.getText());
+			settings.put(STORE_PATH_ID, paths);
+
+			if (showValidate) {
+				settings.put(STORE_DONT_VALIDATE_ID, !validate);
+			}
+		}
+	}
+
+	/**
+	 * Find the current standard repository object, given the host
+	 * name.
+	 */
+	protected StandardRepository getCurrentRepository(String name) {
+		for (int i = 0; i < standardRepositories.length; i++) {
+			if (name.equals(standardRepositories[i].repositoryName))
+				return standardRepositories[i];
+		}
+		return null;
+	}
+
+	/**
+	 * Return true if user name is an anonymous user.
+	 */
+	protected boolean isAnonymous(String name) {
+		return "cvs".equals(name) || "anonymous".equals(name) || "anoncvs".equals(name);
+	}
+
+	/**
+	 * Updates widget enablements and sets error message if appropriate.
+	 */
+	protected void updateWidgetEnablements() {
+		StandardRepository repo = getCurrentRepository(hostCombo.getText());
+		if (repo == null || repo.soleProjectName != null)
+			repositoryPathCombo.setEnabled(false);
+		else
+			repositoryPathCombo.setEnabled(true);
+
+		boolean isanon = isAnonymous(userCombo.getText());
+		passwordText.setEnabled(!isanon);
+		connectionMethodCombo.setEnabled(!isanon);
+
+		validateFields();
+	}
+
+	/**
+	 * Validates the contents of the editable fields and set page completion 
+	 * and error messages appropriately.
+	 */
+	protected void validateFields() {
+		String user = userCombo.getText();
+		if (user.length() == 0) {
+			setErrorMessage(null);
+			setPageComplete(false);
+			return;
+		}
+		if ((user.indexOf('@') != -1) || (user.indexOf(':') != -1)) {
+			setErrorMessage(Policy.bind("ConfigurationWizardMainPage.invalidUserName")); //$NON-NLS-1$
+			setPageComplete(false);
+			return;
+		}
+
+		String host = hostCombo.getText();
+		if (getCurrentRepository(host) == null) {
+			setErrorMessage(null);
+			setPageComplete(false);
+			return;
+		}
+		if (host.indexOf(':') != -1) {
+			setErrorMessage(Policy.bind("ConfigurationWizardMainPage.invalidHostName")); //$NON-NLS-1$
+			setPageComplete(false);
+			return;
+		}
+
+		if (!repositoryPathCombo.isEnabled()) {
+			// Nothing.
+		} else if (repositoryPathCombo.getText().length() == 0) {
+			setErrorMessage(null);
+			setPageComplete(false);
+			return;
+		} else {
+			// The standard repositories use a single word specifying
+			// the project name.  So disallow `/'.
+			String pathString = repositoryPathCombo.getText();
+			if (pathString.indexOf("/") != -1) { //$NON-NLS-1$
+				setErrorMessage(Policy.bind("ConfigurationWizardMainPage.invalidProjectName"));
+				setPageComplete(false);
+				return;
+			}
+		}
+		setErrorMessage(null);
+		setPageComplete(true);
+	}
+
+	// This holds information about a given standard repository.
+	public static final class StandardRepository {
+		// Name of repository as presented to user.
+		public String repositoryName;
+
+		// Name of the anonymous user.
+		public String anonymousUserName;
+
+		// The name of the only project available at that repository.
+		// If null, then the user must enter a project name.
+		public String soleProjectName;
+
+		// Used to construct the CVSROOT for anonymous access.
+		// The name of the project is passed as argument {0}.
+		public MessageFormat anonymousCvsrootFormat;
+
+		// Used to construct the CVSROOT for non-anonymous access.
+		// The name of the project is passed as argument {0}.
+		public MessageFormat userCvsrootFormat;
+
+		// Password for anonymous user.
+		public String anonymousPassword;
+
+		public StandardRepository(String repositoryName, String anonymousUserName, String anonymousCvsroot, String userCvsroot) {
+			this(repositoryName, anonymousUserName, null, anonymousCvsroot, userCvsroot, "");
+		}
+
+		public StandardRepository(String repositoryName, String anonymousUserName, String soleProjectName, String anonymousCvsroot, String userCvsroot) {
+			this(repositoryName, anonymousUserName, soleProjectName, anonymousCvsroot, userCvsroot, "");
+		}
+
+		public StandardRepository(String repositoryName, String anonymousUserName, String soleProjectName, String anonymousCvsroot, String userCvsroot, String anonymousPassword) {
+			this.repositoryName = repositoryName;
+			this.anonymousUserName = anonymousUserName;
+			this.soleProjectName = soleProjectName;
+			this.anonymousCvsrootFormat = new MessageFormat(anonymousCvsroot);
+			this.userCvsrootFormat = new MessageFormat(userCvsroot);
+			this.anonymousPassword = anonymousPassword;
+		}
+
+		public String computeCvsroot(String project, String userName) {
+			MessageFormat format;
+			if (soleProjectName != null) {
+				project = soleProjectName;
+			}
+			if (userName.equals(anonymousUserName)) {
+				format = anonymousCvsrootFormat;
+			} else {
+				format = userCvsrootFormat;
+			}
+			return format.format(new String[] { project });
+		}
+	}
+
+	public static StandardRepository[] getStandardRepositories () {
+		return new StandardRepository[] {
+			new StandardRepository("sourceforge.net", "anonymous", "cvs.{0}.sourceforge.net:/cvsroot/{0}", "cvs.{0}.sourceforge.net:/cvsroot/{0}"),
+			new StandardRepository("sources.redhat.com", "anoncvs", null, "sources.redhat.com:/cvs/{0}", "sources.redhat.com:/cvs/{0}", "anoncvs"),
+			new StandardRepository("gcc.gnu.org", "anoncvs", "gcc", "anoncvs.gnu.org:/cvsroot/{0}", "gcc.gnu.org:/cvs/{0}"),
+			new StandardRepository("subversions.gnu.org", "anoncvs", "anoncvs.gnu.org:/cvsroot/{0}", "subversions.gnu.org:/cvsroot/{0}"),
+			new StandardRepository("cvs.gnome.org", "anonymous", "gnome", "anoncvs.gnome.org:/cvs/{0}", "cvs.gnome.org:/cvs/{0}"),
+			new StandardRepository("cvs.kde.org", "anonymous", "kde", "anoncvs.kde.org:/home/{0}", "cvs.kde.org:/home/{0}"),
+			new StandardRepository("dev.eclipse.org", "anonymous", "dev.eclipse.org:/home/{0}", "dev.eclipse.org:/home/{0}"),
+		};
+	}
+}


Back to the top