Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2002-01-30 16:32:04 +0000
committerMichael Valenta2002-01-30 16:32:04 +0000
commit2cc7da51a7a66fd6585e2ddbc1d99050b1389c92 (patch)
tree227dd6932a7b7440bcfc0c304e6ea6bed0a438ad
parent8f064634da5193b0d31ed4c4dfa357f5e544a1d1 (diff)
downloadeclipse.platform.team-2cc7da51a7a66fd6585e2ddbc1d99050b1389c92.tar.gz
eclipse.platform.team-2cc7da51a7a66fd6585e2ddbc1d99050b1389c92.tar.xz
eclipse.platform.team-2cc7da51a7a66fd6585e2ddbc1d99050b1389c92.zip
Module support
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/ModuleDefinitionsListener.java139
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/ModuleExpansion.java120
2 files changed, 259 insertions, 0 deletions
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/ModuleDefinitionsListener.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/ModuleDefinitionsListener.java
new file mode 100644
index 000000000..bffa517a1
--- /dev/null
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/ModuleDefinitionsListener.java
@@ -0,0 +1,139 @@
+package org.eclipse.team.internal.ccvs.core.client.listeners;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2002.
+ * All Rights Reserved.
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.team.internal.ccvs.core.client.Checkout;
+import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
+
+/*
+ * This class pares the output of the "cvs checkout -c" command which returns the list of modules
+ * defined in the CVSROOT/modules file.
+ */
+public class ModuleDefinitionsListener implements ICommandOutputListener {
+
+ // the last line read from the context (used to accumulate multi-line definitions)
+ private String lastLine = "";
+
+ private Map moduleMap;
+
+ public ModuleDefinitionsListener() {
+ reset();
+ }
+
+ /*
+ * @see ICommandOutputListener#messageLine(String, ICVSFolder, IProgressMonitor)
+ */
+ public IStatus messageLine(
+ String line,
+ ICVSFolder commandRoot,
+ IProgressMonitor monitor) {
+
+ // Lines that start with a space indicate a multi line entry
+ if( line.charAt(0) == ' ' ) {
+ lastLine += line;
+ line = lastLine;
+ }
+ else
+ lastLine = line;
+
+ StringTokenizer tokenizer = new StringTokenizer(line);
+
+ String module = tokenizer.nextToken();
+
+ List expansions = new ArrayList(10);
+
+ // Read the options associated with the module
+ List localOptionsList = new ArrayList();
+ String next = tokenizer.nextToken();
+ while (next.charAt(0) == '-') {
+ switch (next.charAt(1)) {
+ case 'a': // alias
+ localOptionsList.add(Checkout.ALIAS);
+ break;
+ case 'l': // don't recurse
+ localOptionsList.add(Checkout.DO_NOT_RECURSE);
+ break;
+ case 'd': // directory
+ localOptionsList.add(Checkout.makeDirectoryNameOption(tokenizer.nextToken()));
+ break;
+ case 'e':
+ case 'i':
+ case 'o':
+ case 't':
+ case 'u': // Ignore any programs
+ tokenizer.nextToken();
+ break;
+ case 's': // status
+ localOptionsList.add(Checkout.makeStatusOption(tokenizer.nextToken()));
+ break;
+ default: // unanticipated option. Ignore it and go on
+ }
+ next = tokenizer.nextToken();
+ }
+ LocalOption[] localOptions = (LocalOption[]) localOptionsList.toArray(new LocalOption[localOptionsList.size()]);
+
+ if (Checkout.ALIAS.isElementOf(localOptions)) {
+ // An alias expands to one or more projects or modules
+ expansions.add(next);
+ while (tokenizer.hasMoreTokens())
+ expansions.add(tokenizer.nextToken());
+ } else {
+ // The module definition can have a leading directory followed by some files
+ if (!(next.charAt(0) == '&')) {
+ String directory = next;
+ List files = new ArrayList();
+ while (tokenizer.hasMoreTokens() && (next.charAt(0) != '&')) {
+ next = tokenizer.nextToken() ;
+ if ((next.charAt(0) != '&'))
+ files.add(next);
+ }
+ if (files.size() > 0) {
+ for (int i=0;i<files.size();i++)
+ expansions.add(directory + "/" + (String)files.get(i));
+ }
+ else
+ expansions.add(directory);
+ }
+ // It can also have one or more module references
+ if (next.charAt(0) == '&') {
+ expansions.add(next);
+ while (tokenizer.hasMoreTokens())
+ expansions.add(tokenizer.nextToken());
+ }
+ }
+ moduleMap.put(module, new ModuleExpansion(module, (String[])expansions.toArray(new String[expansions.size()]), localOptions));
+ return OK;
+ }
+
+ /*
+ * @see ICommandOutputListener#errorLine(String, ICVSFolder, IProgressMonitor)
+ */
+ public IStatus errorLine(
+ String line,
+ ICVSFolder commandRoot,
+ IProgressMonitor monitor) {
+
+ // XXX We should get any errors!!!
+ return OK;
+ }
+
+ public ModuleExpansion[] getModuleExpansions() {
+ return (ModuleExpansion[])moduleMap.values().toArray(new ModuleExpansion[moduleMap.size()]);
+ }
+
+ public void reset() {
+ this.moduleMap = new HashMap();
+ }
+}
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/ModuleExpansion.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/ModuleExpansion.java
new file mode 100644
index 000000000..07464b460
--- /dev/null
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/ModuleExpansion.java
@@ -0,0 +1,120 @@
+package org.eclipse.team.internal.ccvs.core.client.listeners;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2002.
+ * All Rights Reserved.
+ */
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.Policy;
+import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption;
+
+/**
+ *
+ */
+public class ModuleExpansion {
+
+ /** Name of the CVS module as found in the CVSROOT/modules file */
+ private String moduleName;
+
+ /** Expansion of the module name returned by the CVS server */
+ private String[] expansions;
+
+ private LocalOption[] options;
+
+ ModuleExpansion(String moduleName, String[] expansions, LocalOption[] options) {
+ this.moduleName = moduleName;
+ this.expansions = expansions;
+ this.options = options;
+ }
+
+ /**
+ * @see IModuleExpansion#getModuleName()
+ */
+ public String getModuleName() {
+ return moduleName;
+ }
+
+ /**
+ * @see IModuleExpansion#getModuleExpansionString()
+ */
+ public String getModuleExpansionString() {
+ String result = expansions[0];
+ for (int i=1;i<expansions.length; i++)
+ result = result + ", " + expansions[i];
+ return result;
+ }
+
+ /**
+ * @see IModuleExpansion#getExpansions()
+ */
+ public String[] getExpansions() {
+ return expansions;
+ }
+
+ public LocalOption[] getOptions() {
+ return options;
+ }
+
+ /**
+ * Translate an array of module names to their expansions.
+ * The resulting List of Strings may be bigger than the original
+ */
+ private List getExpansionsFor(String[] possibleModules, Map moduleMappings, int depth) throws CVSException {
+ List result = new ArrayList();
+ for (int i=0;i<possibleModules.length;i++) {
+ // Is it a module?
+ if (possibleModules[i].charAt(0) == '&')
+ result.addAll(getExpansionsFor(possibleModules[i].substring(1), moduleMappings, depth));
+ else
+ result.add(possibleModules[i]);
+ }
+ return result;
+ }
+
+ /**
+ * Translate a module name to its expansion.
+ * The resulting List may contain one or more Strings
+ */
+ private List getExpansionsFor(String module, Map moduleMappings, int depth) throws CVSException {
+ if (depth > moduleMappings.size()) {
+ // Indicate that a circular reference exists
+ throw new CVSException(Policy.bind("ModuleExpansion.circular", module));
+ }
+ Object mappings = moduleMappings.get(module);
+ if (mappings == null) {
+ // If there's no mapping assume it is a project name
+ List result = new ArrayList();
+ result.add(module);
+ return result;
+ } else {
+ // Follow any expansion chains
+ return getExpansionsFor(((ModuleExpansion)mappings).expansions, moduleMappings, depth + 1);
+ }
+ }
+
+ /**
+ * Resolve the module mappings using moduleMappings which maps
+ * module names to their ModuleExpansion
+ */
+ public void resolveModuleReferencesUsing(Map moduleMappings) {
+ try {
+ List result = getExpansionsFor(expansions, moduleMappings, 0);
+ expansions = (String[])result.toArray(new String[result.size()]);
+ } catch (CVSException e) {
+ // Is this the best way to show the circular reference problem?
+ // Or should we just leave the expansions untouched?
+ List result = new ArrayList();
+ result.add(e.getStatus().getMessage());
+ result.addAll(Arrays.asList(expansions));
+ expansions = (String[])result.toArray(new String[result.size()]);
+ }
+ }
+}
+
+

Back to the top