Exposed some synchronizer details for test purposes. Fixed serious bug in checkout -- infinite recursion while expanding modules.
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSFile.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSFile.java index ba90eda..6dac034 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSFile.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSFile.java
@@ -50,6 +50,11 @@ void setReadOnly(boolean readOnly) throws CVSException; /** + * Determines if a file is read only or not. + */ + boolean isReadOnly() throws CVSException; + + /** * Move the resource to another location. Does overwrite without * promting. */
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSProvider.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSProvider.java index 0eb4f7d..78eaafd 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSProvider.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSProvider.java
@@ -139,11 +139,5 @@ * Get the names of the registered connection methods. */ public String[] getSupportedConnectionMethods(); - - - /** - * Set the print stream to which command message and error output is sent - */ - public void setPrintStream(PrintStream out); }
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Checkout.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Checkout.java index 0af68f1..3932ec8 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Checkout.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Checkout.java
@@ -129,7 +129,7 @@ } } - return super.execute(session, globalOptions, localOptions, arguments, listener, Policy.subMonitorFor(monitor, 90)); + return super.doExecute(session, globalOptions, localOptions, arguments, listener, Policy.subMonitorFor(monitor, 90)); } /**
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Command.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Command.java index 84d4f68..25bc8e4 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Command.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Command.java
@@ -334,14 +334,14 @@ final IStatus[] status = new IStatus[1]; ICVSRunnable job = new ICVSRunnable() { public void run(IProgressMonitor monitor) throws CVSException { - status[0] = doExcecute(session, globalOptions, localOptions, arguments, listener, monitor); + status[0] = doExecute(session, globalOptions, localOptions, arguments, listener, monitor); } }; session.getLocalRoot().run(job, pm); return status[0]; } - protected IStatus doExcecute(Session session, GlobalOption[] globalOptions, + protected IStatus doExecute(Session session, GlobalOption[] globalOptions, LocalOption[] localOptions, String[] arguments, ICommandOutputListener listener, IProgressMonitor monitor) throws CVSException {
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Diff.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Diff.java index abe7a91..84f94d2 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Diff.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Diff.java
@@ -33,10 +33,10 @@ * Overwritten to throw the CVSDiffException if the server returns an error, because it just does * so when there is a difference between the checked files. */ - protected IStatus doExcecute(Session session, GlobalOption[] globalOptions, LocalOption[] localOptions, + protected IStatus doExecute(Session session, GlobalOption[] globalOptions, LocalOption[] localOptions, String[] arguments, ICommandOutputListener listener, IProgressMonitor monitor) throws CVSException { try { - return super.doExcecute(session, globalOptions, localOptions, arguments, listener, monitor); + return super.doExecute(session, globalOptions, localOptions, arguments, listener, monitor); } catch (CVSServerException e) { if (e.containsErrors()) throw e; return e.getStatus();
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ExpandModules.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ExpandModules.java index 8d2c135..2dfb14a 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ExpandModules.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ExpandModules.java
@@ -41,6 +41,6 @@ * Convenient execute method */ public IStatus execute(Session session, String[] modules, IProgressMonitor monitor) throws CVSException { - return execute(session, NO_GLOBAL_OPTIONS, NO_LOCAL_OPTIONS, modules, null, monitor); + return super.execute(session, NO_GLOBAL_OPTIONS, NO_LOCAL_OPTIONS, modules, null, monitor); } }
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RTag.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RTag.java index 0f6c513..9a2bb69 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RTag.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RTag.java
@@ -75,7 +75,7 @@ ICVSResource resource = resources[i]; arguments.add(resource.getRemoteLocation(null)); } - return execute(session, globalOptions, + return super.execute(session, globalOptions, (LocalOption[]) modifiedLocalOptions.toArray(new LocalOption[modifiedLocalOptions.size()]), (String[]) arguments.toArray(new String[arguments.size()]), null, monitor); }
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseFile.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseFile.java index a2d430a..2a04a31 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseFile.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseFile.java
@@ -193,6 +193,13 @@ public void setReadOnly(boolean readOnly) throws CVSException { getIFile().setReadOnly(readOnly); } + + /* + * @see ICVSFile#isReadOnly() + */ + public boolean isReadOnly() throws CVSException { + return getIFile().isReadOnly(); + } /* * Typecasting helper
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseResource.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseResource.java index 47118d6..2be2a08 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseResource.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseResource.java
@@ -19,7 +19,7 @@ import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo; import org.eclipse.team.internal.ccvs.core.util.Assert; import org.eclipse.team.internal.ccvs.core.util.FileNameMatcher; -import org.eclipse.team.internal.ccvs.core.util.SyncFileUtil; +import org.eclipse.team.internal.ccvs.core.util.SyncFileWriter; import org.eclipse.team.internal.ccvs.core.util.Util; /** @@ -116,7 +116,7 @@ // initialize matcher with global ignores, basic CVS ignore patterns, and ignore patterns // from the .cvsignore file. - FileNameMatcher matcher = new FileNameMatcher(SyncFileUtil.BASIC_IGNORE_PATTERNS); + FileNameMatcher matcher = new FileNameMatcher(SyncFileWriter.BASIC_IGNORE_PATTERNS); String[] cvsIgnorePatterns;; try { cvsIgnorePatterns = EclipseSynchronizer.getInstance().getIgnored(resource);
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseSynchronizer.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseSynchronizer.java index b91b8dc..ff5a8cc 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseSynchronizer.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseSynchronizer.java
@@ -478,7 +478,7 @@ } } - static private void flushAll(final IContainer root, final boolean purgeFromDisk) throws CVSException { + static public void flushAll(final IContainer root, final boolean purgeFromDisk) throws CVSException { if (! (root.exists() || root.isPhantom())) return; try { // purge sync information from children
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteFile.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteFile.java index 6ac193e..f1f9517 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteFile.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteFile.java
@@ -324,6 +324,10 @@ public void setReadOnly(boolean readOnly) throws CVSException { } + public boolean isReadOnly() throws CVSException { + return true; + } + /** * @see IManagedFile#getTimeStamp() */
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/SyncFileUtil.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/SyncFileUtil.java deleted file mode 100644 index e235330..0000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/SyncFileUtil.java +++ /dev/null
@@ -1,407 +0,0 @@ -package org.eclipse.team.internal.ccvs.core.util; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.team.ccvs.core.CVSTag; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.Policy; -import org.eclipse.team.internal.ccvs.core.resources.CVSEntryLineTag; -import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo; -import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo; - -public class SyncFileUtil { - - // All possible files available in the CVS subdir - - public static final String REPOSITORY = "Repository"; //$NON-NLS-1$ - public static final String ROOT = "Root"; //$NON-NLS-1$ - public static final String STATIC = "Entries.Static"; //$NON-NLS-1$ - public static final String TAG = "Tag"; //$NON-NLS-1$ - public static final String ENTRIES = "Entries"; //$NON-NLS-1$ - public static final String PERMISSIONS = "Permissions"; //$NON-NLS-1$ - public static final String ENTRIES_LOG="Entries.Log"; //$NON-NLS-1$ - - // the local workspace file that contains pattern for ignored resources - public static final String IGNORE_FILE = ".cvsignore"; //$NON-NLS-1$ - - // Some older CVS clients may of added a line to the entries file consisting - // of only a 'D'. It is safe to ingnore these entries. - private static final String FOLDER_TAG="D"; //$NON-NLS-1$ - - // Command characters found in the Entries.log file - private static final String ADD_TAG="A "; //$NON-NLS-1$ - private static final String REMOVE_TAG="R "; //$NON-NLS-1$ - - // file and folder patterns that are ignored by default by the CVS server on import. - public static final String[] PREDEFINED_IGNORE_PATTERNS = { - "CVS", ".#*", "#*", ",*", "_$*", "*~", "*$", "*.a", "*.bak", "*.BAK", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ - "*.elc", "*.exe", "*.ln", "*.o", "*.obj", "*.olb", "*.old", "*.orig", "*.rej", "*.so", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ - "*.Z", ".del-*", ".make.state", ".nse_depinfo", "CVS.adm", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ - "cvslog.*", "RCS", "RCSLOG", "SCCS", "tags", "TAGS"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ - - // file and folder patterns that are ignored by default by the CVS server on import. - public static final String[] BASIC_IGNORE_PATTERNS = {"CVS", ".#*"}; //$NON-NLS-1$ //$NON-NLS-2$ - - /** - * Reads the CVS/Entry and CVS/Permissions files for the given folder. If the folder does not have a - * CVS subdirectory then <code>null</code> is returned. - */ - public static ResourceSyncInfo[] readEntriesFile(File parent) throws CVSException { - - File cvsSubDir = getCVSSubdirectory(parent); - - if(!cvsSubDir.exists()) { - return null; - } - - // The Eclipse CVS client does not write to the Entries.log file. Thus - // merging is required for external command line client compatibility. - mergeEntriesLogFiles(parent); - - Map infos = new TreeMap(); - String[] entries = getContents(new File(cvsSubDir, ENTRIES)); - String[] permissions = getContents(new File(cvsSubDir, PERMISSIONS)); - - if (entries == null) { - return null; - } - - for (int i = 0; i < entries.length; i++) { - String line = entries[i]; - if(!FOLDER_TAG.equals(line) && !"".equals(line)) { //$NON-NLS-1$ - ResourceSyncInfo info = new ResourceSyncInfo(line, null, null); - infos.put(info.getName(), info); - } - } - - if (permissions != null) { - for (int i = 0; i < permissions.length; i++) { - if ("".equals(permissions[i])) { //$NON-NLS-1$ - continue; - } - String line = permissions[i]; - EmptyTokenizer tokenizer = new EmptyTokenizer(line,"/"); //$NON-NLS-1$ - String name = tokenizer.nextToken(); - String perms = tokenizer.nextToken(); - ResourceSyncInfo info = (ResourceSyncInfo) infos.get(name); - // Running the command line tool will update the Entries file and thus cause - // the Permissions to be out-of-sync. - if (info != null) { - infos.put(name, new ResourceSyncInfo(info.getEntryLine(true), perms, null)); - } - } - } - return (ResourceSyncInfo[])infos.values().toArray(new ResourceSyncInfo[infos.size()]); - } - - public static void writeResourceSync(File file, ResourceSyncInfo info) throws CVSException { - writeEntriesLog(file, info, ADD_TAG); - } - - /** - * Append to Entries.log file - */ - private static void writeEntriesLog(File file, ResourceSyncInfo info, String prefix) throws CVSException { - FileOutputStream out = null; - try { - File entriesLogFile = new File(getCVSSubdirectory(file.getParentFile()), ENTRIES_LOG); - if(!entriesLogFile.exists()) { - entriesLogFile.createNewFile(); - } - String line = prefix + info.getEntryLine(true) +"\n"; //$NON-NLS-1$ - out = new FileOutputStream(entriesLogFile.getAbsolutePath(), true); - out.write(line.getBytes()); - } catch(IOException e) { - throw new CVSException(IStatus.ERROR, 0, Policy.bind("SyncFileUtil_Error_writing_to_Entries.log_48"), e); //$NON-NLS-1$ - } finally { - try { - if(out!=null) { - out.close(); - } - } catch(IOException e) { - throw new CVSException(IStatus.ERROR, 0, Policy.bind("SyncFileUtil_Cannot_close_Entries.log_49"), e); //$NON-NLS-1$ - } - } - } - - /** - * Delete this file from Entries/Permissions file - */ - public static void deleteSync(File file) throws CVSException { - if(file.isDirectory()) { - writeEntriesLog(file, new ResourceSyncInfo(file.getName()), REMOVE_TAG); - } else { - writeEntriesLog(file, new ResourceSyncInfo(file.getName(), "0", "", "", null, ""), REMOVE_TAG); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - } - } - - public static boolean isMetaFile(File file) { - File parent = file.getParentFile(); - if(parent!=null&&parent.getName().equals("CVS")) { //$NON-NLS-1$ - return true; - } else { - return false; - } - } - - /** - * Writes the given resource sync infos into the CVS/Entry and CVS/Permissions files. - */ - public static void writeEntriesFile(File entryFile, ResourceSyncInfo[] infos) throws CVSException { - - String[] entries = new String[infos.length]; - List permissions = new ArrayList(infos.length); - - for(int i = 0; i < infos.length; i++){ - entries[i] = infos[i].getEntryLine(true); - if (!infos[i].isDirectory()) { - permissions.add(infos[i].getPermissionLine()); - } - } - writeLines(entryFile, entries); - writeLines(new File(entryFile.getParentFile(),PERMISSIONS), (String[])permissions.toArray(new String[permissions.size()])); - } - - /** - * Read folder sync info, returns <code>null</code> if the folder does not have - * a CVS subdirectory. - */ - public static FolderSyncInfo readFolderConfig(File folder) throws CVSException { - - File cvsSubDir = getCVSSubdirectory(folder); - - if(!cvsSubDir.exists()) { - return null; - } - - String staticDir = readLine(new File(cvsSubDir, STATIC)); - String repo = readLine(new File(cvsSubDir, REPOSITORY)); - String root = readLine(new File(cvsSubDir, ROOT)); - String tag = readLine(new File(cvsSubDir, TAG)); - - boolean isStatic = false; - if (staticDir != null) - isStatic = true; - - if(root == null || repo == null) { - return null; - } - - CVSTag cvsTag = null; - if(tag != null) { - cvsTag = new CVSEntryLineTag(tag); - } - - return new FolderSyncInfo(repo, root, cvsTag, isStatic); - } - - public static File[] getEntrySyncFiles(File folder) { - File cvsSubDir = getCVSSubdirectory(folder); - return new File[] { new File(cvsSubDir, ENTRIES), new File(cvsSubDir, PERMISSIONS) }; - } - - public static File[] getFolderSyncFiles(File folder) { - File cvsSubDir = getCVSSubdirectory(folder); - return new File[] { new File(cvsSubDir, ROOT), new File(cvsSubDir, REPOSITORY), new File(cvsSubDir, STATIC), new File(cvsSubDir, TAG) }; - } - - public static void writeFolderConfig(File parent, FolderSyncInfo info) throws CVSException { - - if(!getCVSSubdirectory(parent).exists()) { - getCVSSubdirectory(parent).mkdir(); - } - - writeLine(parent, ROOT, info.getRoot()); - if (info.getTag() != null) { - writeLine(parent, TAG, info.getTag().toEntryLineFormat(false)); - } else { - writeLine(parent, TAG, null); - } - if(info.getIsStatic()) { - writeLine(parent, STATIC, ""); // touch file //$NON-NLS-1$ - } else { - writeLine(parent, STATIC, null); - } - writeLine(parent, REPOSITORY, info.getRepository()); - } - - protected static void setContents(File parent, String filename, String[] contents) throws CVSException { - - File propertyFile = new File(getCVSSubdirectory(parent), filename); - - if (contents == null) { - propertyFile.delete(); - } else { - writeLines(propertyFile,contents); - } - } - - protected static void writeLine(File parent, String filename, String content) throws CVSException { - if (content == null) { - setContents(parent, filename, null); - } else { - setContents(parent, filename, new String[]{content}); - } - } - - protected static String readLine(File file) throws CVSException { - String[] contents = getContents(file); - if (contents == null) { - return null; - } else if (contents.length == 0) { - return ""; //$NON-NLS-1$ - } else { - return contents[0]; - } - } - - protected static String[] getContents(File file) throws CVSException { - - // If the property does not exsist we return null - // this is specified - if (file.exists()) { - return readLines(file); - } else { - return null; - } - } - - public static File getCVSSubdirectory(File folder) { - return new File(folder, "CVS"); //$NON-NLS-1$ - } - - public static void mergeEntriesLogFiles(File root) throws CVSException { - - File logEntriesFile = new File(getCVSSubdirectory(root), ENTRIES_LOG); - File entriesFile = new File(getCVSSubdirectory(root), ENTRIES); - - if (!logEntriesFile.exists()) { - // If we do not have an Entries.Log file we are done because there is nothing - // to merge (this includes the case where we do not have CVSDirectory) - return; - } - - // The map contains the name of the resource as the key and the entryLine as the - // value - // "new ResourceSyncInfo(entryLine,null)).getName()" ist used to parse the name - // out of the entryLine and shoud maybe be replaced sometime - - Map mergedEntries = new HashMap(); - - if(entriesFile.exists()) { - String[] entries = readLines(entriesFile); - for (int i = 0; i < entries.length; i++) { - if (!FOLDER_TAG.equals(entries[i])) { - mergedEntries.put((new ResourceSyncInfo(entries[i],null, null)).getName(),entries[i]); - } - } - } - - String[] logEntries = readLines(logEntriesFile); - for (int i = 0; i < logEntries.length; i++) { - - if (logEntries[i].startsWith(ADD_TAG)) { - String newEntry = logEntries[i].substring(ADD_TAG.length()); - mergedEntries.put((new ResourceSyncInfo(newEntry,null, null)).getName(),newEntry); - } else if (logEntries[i].startsWith(REMOVE_TAG)) { - String newEntry = logEntries[i].substring(REMOVE_TAG.length()); - mergedEntries.remove((new ResourceSyncInfo(newEntry,null, null)).getName()); - } - } - - writeLines(entriesFile,(String[]) mergedEntries.values().toArray(new String[mergedEntries.size()])); - logEntriesFile.delete(); - - // Refresh the CVS directory containing the files - IResource resource = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(new Path(getCVSSubdirectory(root).getAbsolutePath())); - try { - if(resource!=null) { - resource.refreshLocal(IResource.DEPTH_INFINITE, Policy.monitorFor(null)); - } - } catch(CoreException e) { - // XXX Should we throw or log? - throw new CVSException(IStatus.ERROR, 0, Policy.bind("SyncFileUtil_Error_reloading_sync_information_58"), e); //$NON-NLS-1$ - } - - } - - public static String[] readLines(File file) throws CVSException { - BufferedReader fileReader; - List fileContentStore = new ArrayList(); - String line; - - try { - fileReader = new BufferedReader(new FileReader(file)); - while ((line = fileReader.readLine()) != null) { - fileContentStore.add(line); - } - fileReader.close(); - } catch(FileNotFoundException e) { - return new String[0]; - } catch (IOException e) { - throw CVSException.wrapException(e); - } - - return (String[]) fileContentStore.toArray(new String[fileContentStore.size()]); - } - - /** - * To be compatible with other CVS clients meta files must be written with lines - * terminating with a carriage return only. - */ - private static void writeLines(File file, String[] content) throws CVSException { - - BufferedWriter fileWriter; - - try { - fileWriter = new BufferedWriter(new FileWriter(file)); - for (int i = 0; i<content.length; i++) { - fileWriter.write(content[i] + "\n"); //$NON-NLS-1$ - } - fileWriter.close(); - } catch (IOException e) { - throw CVSException.wrapException(e); - } - } - - public static void addCvsIgnoreEntry(File file, String pattern) throws CVSException { - FileOutputStream out = null; - try { - File cvsignore = new File(file.getParentFile(), IGNORE_FILE); - if(!cvsignore.exists()) { - cvsignore.createNewFile(); - } - String line = pattern == null ? file.getName() : pattern; - line += "\n"; //$NON-NLS-1$ - out = new FileOutputStream(cvsignore.getAbsolutePath(), true /*append*/); - out.write(line.getBytes()); - } catch(IOException e) { - throw new CVSException(IStatus.ERROR, 0, Policy.bind("SyncFileUtil_Error_writing_to_.cvsignore_61"), e); //$NON-NLS-1$ - } finally { - try { - if(out!=null) { - out.close(); - } - } catch(IOException e) { - throw new CVSException(IStatus.ERROR, 0, Policy.bind("SyncFileUtil_Cannot_close_.cvsignore_62"), e); //$NON-NLS-1$ - } - } - } -} \ No newline at end of file
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/Util.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/Util.java index 7c94be7..6f297ca 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/Util.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/Util.java
@@ -21,159 +21,6 @@ * Unsorted static helper-methods */ public class Util { - - private static final String AT = "@"; //$NON-NLS-1$ - private static final String COLON = ":"; //$NON-NLS-1$ - - - // private static final String newLine = System.getProperty("line.separator"); - - - /** - * @see Util#getOptions(String[],String,boolean) - */ - public static String getOption(String[] options, String key, boolean deleteOption) { - - String[] result; - - result = getOptions(options,key,deleteOption); - - if (result.length == 0) { - return null; - } else { - return result[0]; - } - } - - /** - * Get an option out of an array of options. It assumes, that - * the next field to the key contains the parameter to the - * option. - * - * @param options not null - * @param key not null - * @param deleteOption nulls both the option-tag and the information - * @return String[0] if the option could not be found - */ - public static String[] getOptions(String[] options, String key, boolean deleteOption) { - - String[] tmpResult; - String[] result; - int size = 0; - - Assert.isNotNull(options); - Assert.isNotNull(key); - - tmpResult = new String[options.length]; - - for (int i=0; i<options.length; i++) { - if (key.equals(options[i]) && i<options.length-1) { - tmpResult[size++] = options[i+1]; - - // This should be done in another way maybe we should - // have an options Object or give the array modified - // back. - // Maybe we are going to change that. - if (deleteOption) { - options[i] = null; - options[i+1] = null; - } - } - } - - result = new String[size]; - System.arraycopy(tmpResult,0,result,0,size); - return result; - } - - /** - * Checks wether the Array options contains the String - * key. - * @param options not null - * @param key not null - */ - public static boolean isOption(String[] options, String key) { - - Assert.isNotNull(options); - Assert.isNotNull(key); - - for (int i=0; i<options.length; i++) { - if (key.equals(options[i])) { - return true; - } - } - return false; - } - - /** - * Remove or get the password out of a repoString. - */ - // FIXME: This is only used for tests ... move it - private static String passwordHandle(String repoName, boolean remove) { - - int atPlace = -1; - int colonPlace = -1; - int colonCount = 0; - String currentChar; - - Assert.isTrue(repoName.indexOf(AT) != -1); - Assert.isTrue(repoName.indexOf(COLON) != -1); - - for (int i=0; i<repoName.length(); i++) { - - currentChar = repoName.substring(i,i+1); - - if (currentChar.equals(COLON)) { - colonCount++; - - if (colonCount == 3) { - colonPlace = i; - } - } - - if (currentChar.equals(AT)) { - if (colonPlace == -1) { - - // If the @ comes before the third colon, then - // we do not have a password and return with the - // same string - return repoName; - } else { - atPlace = i; - } - - } - } - - if (atPlace == -1) { - return repoName; - } - - if (remove) { - return repoName.substring(0,colonPlace) + repoName.substring(atPlace); - } else { - return repoName.substring(colonPlace + 1, atPlace); - } - } - - /** - * returns ":pserver:nkrambro@fiji:/home/nkrambro/repo" - * when you insert ":pserver:nkrambro:password@fiji:/home/nkrambro/repo" - */ - // FIXME: This is only used for tests ... move it - public static String removePassword(String root) { - return passwordHandle(root,true); - } - - /** - * - * returns "password" - * when you insert ":pserver:nkrambro:password@fiji:/home/nkrambro/repo" - */ - // FIXME: This is only used for tests ... move it - - // FIXME: This is only used for tests ... move it - /** * Get the extention of the path of resource * relative to the path of root @@ -212,12 +59,11 @@ else return prefix + Session.SERVER_SEPARATOR + suffix; } - - + public static void logError(String message, Throwable throwable) { CVSProviderPlugin.log(new Status(IStatus.ERROR, CVSProviderPlugin.ID, IStatus.ERROR, message, throwable)); } - + /** * If the number of segments in the relative path of <code>resource</code> to <code>root</code> is * greater than <code>split</code> then the returned path is truncated to <code>split</code> number