diff options
Diffstat (limited to 'bundles/org.eclipse.team.core/src/org/eclipse')
44 files changed, 0 insertions, 6636 deletions
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/IFileTypeInfo.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/IFileTypeInfo.java deleted file mode 100644 index e78cbbabf..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/IFileTypeInfo.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial API and implementation - ******************************************************************************/ -package org.eclipse.team.core; - -/** - * A file type info specifies both the file extension and the - * corresponding file type. - * - * @since 2.0 - */ -public interface IFileTypeInfo { - /** - * Returns the string specifying the file extension - * - * @return the file extension - */ - public String getExtension(); - - /** - * Returns the file type for files ending with the corresponding - * extension. - * - * Valid values are: - * Team.UNKNOWN - * Team.TEXT - * Team.BINARY - * - * @return the file type - */ - public int getType(); -} diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/IIgnoreInfo.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/IIgnoreInfo.java deleted file mode 100644 index 9c5c8260f..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/IIgnoreInfo.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial API and implementation - ******************************************************************************/ -package org.eclipse.team.core; - -/** - * An ignore info specifies both the pattern and the enabled state - * of a globally ignored pattern. - * - * @since 2.0 - */ -public interface IIgnoreInfo { - /** - * Return the string specifying the pattern of this ignore. The string - * may include the wildcard characters '*' and '?'. If you wish to - * include either of these characters verbatim (i.e. you do not wish - * them to expand to wildcards), you must escape them with a backslash '\'. - * <p> - * If you are using string literals in Java to represent the patterns, don't - * forget escape characters are represented by "\\". - * - * @return the pattern represented by this ignore info - */ - public String getPattern(); - /** - * Return whether or not this ignore info is enabled. A disabled ignore - * info remains in the global ignore list, but no attempt is made to match - * against it to determine resource ignore state. - * - * @return whether the ignore info is enabled - */ - public boolean getEnabled(); -} diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/IProjectSetSerializer.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/IProjectSetSerializer.java deleted file mode 100644 index bf1dbf358..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/IProjectSetSerializer.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial API and implementation - ******************************************************************************/ -package org.eclipse.team.core; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IProgressMonitor; - -/** - * IProjectSetSerializer manages the serializing and deserializing - * of references to projects. Given a project, it can produce a - * UTF-8 encoded String which can be stored in a file. - * Given this String, it can create in the workspace an IProject. - */ - -public interface IProjectSetSerializer { - - /** - * For every IProject in providerProjects, return an opaque - * UTF-8 encoded String to act as a reference to that project. - * The format of the String is specific to the provider. - * The format of the String must be such that - * IProjectSetSerializer.addToWorskpace() will be able to - * consume it and recreate a corresponding project. - * @see IProjectSetSerializer.addToWorkspace() - * - * @param providerProjects an array of projects that the serializer should create - * text references for - * @param context a UI context object. This object will either be a - * com.ibm.swt.widgets.Shell or it will be null. - * @param monitor a progress monitor - * @return an array of serialized reference strings uniquely identifying the projects - */ - public String[] asReference(IProject[] providerProjects, Object context, IProgressMonitor monitor) throws TeamException; - - /** - * For every String in referenceStrings, create in the workspace a - * corresponding IProject. Return an Array of the resulting IProjects. - * Result is unspecified in the case where an IProject of that name - * already exists. In the case of failure, a TeamException must be thrown. - * The opaque strings in referenceStrings are guaranteed to have been previously - * produced by IProjectSetSerializer.asReference(). - * @see IProjectSetSerializer.asReference() - * - * @param referenceStrings an array of referene strings uniquely identifying the projects - * @param filename the name of the file that the references were read from. This is included - * in case the provider needs to deduce relative paths - * @param context a UI context object. This object will either be a - * com.ibm.swt.widgets.Shell or it will be null. - * @param monitor a progress monitor - * @return an array of projects that were created - */ - public IProject[] addToWorkspace(String[] referenceStrings, String filename, Object context, IProgressMonitor monitor) throws TeamException; -} diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/RepositoryProvider.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/RepositoryProvider.java deleted file mode 100644 index f8ec74521..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/RepositoryProvider.java +++ /dev/null @@ -1,267 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial API and implementation - ******************************************************************************/ -package org.eclipse.team.core; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IFileModificationValidator; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.resources.IProjectNature; -import org.eclipse.core.resources.IProjectNatureDescriptor; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.resources.team.IMoveDeleteHook; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.team.internal.core.*; -import org.eclipse.team.internal.core.Policy; -import org.eclipse.team.internal.core.simpleAccess.SimpleAccessOperations; - -/** - * A concrete subclass of <code>RepositoryProvider</code> is created for each - * project that is associated with a repository provider. The lifecycle of these - * instances is managed by the platform's 'nature' mechanism. - * <p> - * To create a repository provider and have it registered with the platform a client - * must minimally: - * <ol> - * <li>extend <code>RepositoryProvider<code> - * <li>define a nature extension in <code>plugin.xml</code> that is - * part of the "org.eclipse.team.repository-provider" set. Having the repository nature - * assigned to the team set allows cardinality restrictions to be inforced by the platform - * (e.g. one repository provider can assigned to a project at a time). Here is an - * example extension point definition: - * <code> - * <extension point="org.eclipse.core.resources.natures" id="myprovidernature" name="MyRepositoryType"> - * <runtime> - * <run class="org.eclipse.myprovider.MyRepositoryProvider"/> - * </runtime> - * <one-of-nature id="org.eclipse.team.repository-provider"/> - * </extension> - * </p> - * </code> - * </ol></p> - * <p> - * Once a repository provider is registered as a nature and is in the team set, then you - * can associate a repository provider with a project by assigning to the project the - * nature id of the repository provider. - * </p> - * @see IProjectNature - * @see RepositoryProviderType - * - * @since 2.0 - */ -public abstract class RepositoryProvider implements IProjectNature { - - private final static String TEAM_SETID = "org.eclipse.team.repository-provider"; //$NON-NLS-1$ - - // the project instance that this nature is assigned to - private IProject project; - - /** - * Default constructor required for the resources plugin to instantiate this class from - * the nature extension definition. - */ - public RepositoryProvider() { - } - - /** - * Configures the nature for the given project. This method is called after <code>setProject</code> - * and before the nature is added to the project. If an exception is generated during configuration - * of the project, the nature will not be assigned to the project. - * - * @throws CoreException if the configuration fails. - */ - abstract public void configureProject() throws CoreException; - - /** - * Configures the nature for the given project. This is called by the platform when a nature is assigned - * to a project. It is not intended to be called by clients. - * - * @throws CoreException if this method fails. If the configuration fails the nature will not be added - * to the project. - * - * @see IProjectNature#configure - */ - final public void configure() throws CoreException { - try { - configureProject(); - } catch(CoreException e) { - try { - Team.removeNatureFromProject(getProject(), getID(), null); - } catch(TeamException e2) { - throw new CoreException(new Status(IStatus.ERROR, TeamPlugin.ID, 0, Policy.bind("RepositoryProvider_Error_removing_nature_from_project___1") + getID(), e2)); //$NON-NLS-1$ - } - throw e; - } - } - - /** - * Answer the id of this provider instance. The id should be the repository provider's - * nature id. - * - * @return the nature id of this provider - */ - abstract public String getID(); - - /** - * Returns an <code>IFileModificationValidator</code> for pre-checking operations - * that modify the contents of files. - * Returns <code>null</code> if the provider does not wish to participate in - * file modification validation. - * - * @see org.eclipse.core.resources.IFileModificationValidator - */ - - public IFileModificationValidator getFileModificationValidator() { - return null; - } - - /** - * Returns an <code>IMoveDeleteHook</code> for handling moves and deletes - * that occur withing projects managed by the provider. This allows providers - * to control how moves and deletes occur and includes the ability to prevent them. - * <p> - * Returning <code>null</code> signals that the default move and delete behavior is desired. - * - * @see org.eclipse.core.resources.IMoveDeleteHook - */ - public IMoveDeleteHook getMoveDeleteHook() { - return null; - } - - /** - * Returns a brief description of this provider. The exact details of the - * representation are unspecified and subject to change, but the following - * may be regarded as typical: - * - * "SampleProject:org.eclipse.team.cvs.provider" - * - * @return a string description of this provider - */ - public String toString() { - return getProject().getName() + ":" + getID(); //$NON-NLS-1$ - } - - /** - * Returns all known (registered) RepositoryProvider ids. - * - * @return an array of registered repository provider ids. - */ - final public static String[] getAllProviderTypeIds() { - IProjectNatureDescriptor[] desc = ResourcesPlugin.getWorkspace().getNatureDescriptors(); - List teamSet = new ArrayList(); - for (int i = 0; i < desc.length; i++) { - String[] setIds = desc[i].getNatureSetIds(); - for (int j = 0; j < setIds.length; j++) { - if(setIds[j].equals(TEAM_SETID)) { - teamSet.add(desc[i].getNatureId()); - } - } - } - return (String[]) teamSet.toArray(new String[teamSet.size()]); - } - - /** - * Returns the provider for a given IProject or <code>null</code> if a provider is not associated with - * the project or if the project is closed or does not exist. This method should be called if the caller - * is looking for <b>any</b> repository provider. Otherwise call <code>getProvider(project, id)</code> - * yo look for a specific repository provider type. - * </p> - * @param project the project to query for a provider - * @return the repository provider associated with the project - */ - final public static RepositoryProvider getProvider(IProject project) { - try { - if(project.isAccessible()) { - IProjectDescription projectDesc = project.getDescription(); - String[] natureIds = projectDesc.getNatureIds(); - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - // for every nature id on this project, find it's natures sets and check if it is - // in the team set. - for (int i = 0; i < natureIds.length; i++) { - IProjectNatureDescriptor desc = workspace.getNatureDescriptor(natureIds[i]); - // The descriptor can be null if the nature doesn't exist - if (desc != null) { - String[] setIds = desc.getNatureSetIds(); - for (int j = 0; j < setIds.length; j++) { - if(setIds[j].equals(TEAM_SETID)) { - return getProvider(project, natureIds[i]); - } - } - } - } - } - } catch(CoreException e) { - TeamPlugin.log(new Status(IStatus.ERROR, TeamPlugin.ID, 0, Policy.bind(""), e)); //$NON-NLS-1$ - } - return null; - } - - /** - * Returns a provider of type with the given id if associated with the given project - * or <code>null</code> if the project is not associated with a provider of that type - * or the nature id is that of a non-team repository provider nature. - * - * @param project the project to query for a provider - * @param id the repository provider id - * @return the repository provider - */ - final public static RepositoryProvider getProvider(IProject project, String id) { - try { - if(project.isAccessible()) { - // if the nature id given is not in the team set then return - // null. - IProjectNatureDescriptor desc = ResourcesPlugin.getWorkspace().getNatureDescriptor(id); - String[] setIds = desc.getNatureSetIds(); - for (int i = 0; i < setIds.length; i++) { - if(setIds[i].equals(TEAM_SETID)) { - return (RepositoryProvider)project.getNature(id); - } - } - } - } catch(CoreException ex) { - // would happen if provider nature id is not registered with the resources plugin - TeamPlugin.log(new Status(IStatus.WARNING, TeamPlugin.ID, 0, Policy.bind("RepositoryProviderTypeRepositoryProvider_not_registered_as_a_nature_id___3") + id, ex)); //$NON-NLS-1$ - } - return null; - } - - /* - * Provisional. - * Returns an object which implements a set of provider neutral operations for this - * provider. Answers <code>null</code> if the provider does not wish to support these - * operations. - * - * @return the repository operations or <code>null</code> if the provider does not - * support provider neutral operations. - */ - public SimpleAccessOperations getSimpleAccess() { - return null; - } - - /* - * @see IProjectNature#getProject() - */ - public IProject getProject() { - return project; - } - - /* - * @see IProjectNature#setProject(IProject) - */ - public void setProject(IProject project) { - this.project = project; - } -} diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/Team.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/Team.java deleted file mode 100644 index b0ae40ba7..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/Team.java +++ /dev/null @@ -1,561 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial API and implementation - ******************************************************************************/ -package org.eclipse.team.core; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.EOFException; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.team.internal.core.*; -import org.eclipse.team.internal.core.Policy; -import org.eclipse.team.internal.core.StringMatcher; - -/** - * The Team class provides a global point of reference for the global ignore set - * and the text/binary registry. - */ -public final class Team { - // File type constants - public static final int UNKNOWN = 0; - public static final int TEXT = 1; - public static final int BINARY = 2; - - // File name of the persisted file type information - private static final String STATE_FILE = ".fileTypes"; //$NON-NLS-1$ - - // File name of the persisted global ignore patterns - private final static String GLOBALIGNORE_FILE = ".globalIgnores"; //$NON-NLS-1$ - - // Keys: file extensions. Values: Integers - private static Hashtable table; - - // The ignore list that is read at startup from the persisted file - private static Map globalIgnore = new HashMap(11); - - private static class FileTypeInfo implements IFileTypeInfo { - private String extension; - private int type; - - public FileTypeInfo(String extension, int type) { - this.extension = extension; - this.type = type; - } - public String getExtension() { - return extension; - } - public int getType() { - return type; - } - } - - private static class IgnoreInfo implements IIgnoreInfo { - private String pattern; - private boolean enabled; - - public IgnoreInfo(String pattern, boolean enabled) { - this.pattern = pattern; - this.enabled = enabled; - } - public String getPattern() { - return pattern; - } - public boolean getEnabled() { - return enabled; - } - }; - - /** - * Return the type of the given file. - * - * Valid return values are: - * Team.TEXT - * Team.BINARY - * Team.UNKNOWN - * - * @param file the file - * @return whether files with the given extension are TEXT, BINARY, or UNKNOWN - */ - public static int getType(IFile file) { - String extension = file.getFileExtension(); - if (extension == null) return UNKNOWN; - Integer integer = (Integer)table.get(extension); - if (integer == null) return UNKNOWN; - return integer.intValue(); - } - - /** - * Returns whether the given file should be ignored. - * - * This method answers true if the file matches one of the global ignore - * patterns, or if the file is marked as derived. - * - * @param file the file - * @return whether the file should be ignored - */ - public static boolean isIgnoredHint(IFile file) { - if (file.isDerived()) return true; - IIgnoreInfo[] ignorePatterns = getAllIgnores(); - StringMatcher matcher; - for (int i = 0; i < ignorePatterns.length; i++) { - IIgnoreInfo info = ignorePatterns[i]; - if (info.getEnabled()) { - matcher = new StringMatcher(info.getPattern(), true, false); - if (matcher.match(file.getName())) return true; - } - } - return false; - } - - /** - * Returns whether the given file should be ignored. - * @deprecated use isIgnoredHint instead - */ - public static boolean isIgnored(IFile file) { - IIgnoreInfo[] ignorePatterns = getAllIgnores(); - StringMatcher matcher; - for (int i = 0; i < ignorePatterns.length; i++) { - IIgnoreInfo info = ignorePatterns[i]; - if (info.getEnabled()) { - matcher = new StringMatcher(info.getPattern(), true, false); - if (matcher.match(file.getName())) return true; - } - } - return false; - } - - /** - * Return all known file types. - * - * @return all known file types - */ - public static IFileTypeInfo[] getAllTypes() { - List result = new ArrayList(); - Enumeration e = table.keys(); - while (e.hasMoreElements()) { - String string = (String)e.nextElement(); - int type = ((Integer)table.get(string)).intValue(); - result.add(new FileTypeInfo(string, type)); - } - return (IFileTypeInfo[])result.toArray(new IFileTypeInfo[result.size()]); - } - - /** - * Returns the list of global ignores. - */ - public static IIgnoreInfo[] getAllIgnores() { - IIgnoreInfo[] result = new IIgnoreInfo[globalIgnore.size()]; - Iterator e = globalIgnore.keySet().iterator(); - int i = 0; - while (e.hasNext() ) { - final String pattern = (String)e.next(); - final boolean enabled = ((Boolean)globalIgnore.get(pattern)).booleanValue(); - result[i++] = new IIgnoreInfo() { - private String p = pattern; - private boolean e = enabled; - public String getPattern() { - return p; - } - public boolean getEnabled() { - return e; - } - }; - } - return result; - } - - /** - * Set the file type for the give extension to the given type. - * - * Valid types are: - * Team.TEXT - * Team.BINARY - * Team.UNKNOWN - * - * @param extension the file extension - * @param type the file type - */ - public static void setAllTypes(String[] extensions, int[] types) { - table = new Hashtable(11); - for (int i = 0; i < extensions.length; i++) { - table.put(extensions[i], new Integer(types[i])); - } - } - - /** - * Add patterns to the list of global ignores. - */ - public static void setAllIgnores(String[] patterns, boolean[] enabled) { - globalIgnore = new Hashtable(11); - for (int i = 0; i < patterns.length; i++) { - globalIgnore.put(patterns[i], new Boolean(enabled[i])); - } - } - - /** - * Utility method for removing a project nature from a project. - * - * @param proj the project to remove the nature from - * @param natureId the nature id to remove - * @param monitor a progress monitor to indicate the duration of the operation, or - * <code>null</code> if progress reporting is not required. - */ - public static void removeNatureFromProject(IProject proj, String natureId, IProgressMonitor monitor) throws TeamException { - try { - IProjectDescription description = proj.getDescription(); - String[] prevNatures= description.getNatureIds(); - List newNatures = new ArrayList(Arrays.asList(prevNatures)); - newNatures.remove(natureId); - description.setNatureIds((String[])newNatures.toArray(new String[newNatures.size()])); - proj.setDescription(description, monitor); - } catch(CoreException e) { - throw wrapException(Policy.bind("manager.errorRemovingNature", proj.getName(), natureId), e); //$NON-NLS-1$ - } - } - - /** - * Utility method for adding a nature to a project. - * - * @param proj the project to add the nature - * @param natureId the id of the nature to assign to the project - * @param monitor a progress monitor to indicate the duration of the operation, or - * <code>null</code> if progress reporting is not required. - * - * @exception TeamException if a problem occured setting the nature - */ - public static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws TeamException { - try { - IProjectDescription description = proj.getDescription(); - String[] prevNatures= description.getNatureIds(); - String[] newNatures= new String[prevNatures.length + 1]; - System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length); - newNatures[prevNatures.length]= natureId; - description.setNatureIds(newNatures); - proj.setDescription(description, monitor); - } catch(CoreException e) { - throw wrapException(Policy.bind("manager.errorSettingNature", proj.getName(), natureId), e); //$NON-NLS-1$ - } - } - - /* - * TEXT - * - * Reads the text patterns currently defined by extensions. - */ - private static void initializePluginPatterns() { - TeamPlugin plugin = TeamPlugin.getPlugin(); - if (plugin != null) { - IExtensionPoint extension = plugin.getDescriptor().getExtensionPoint(TeamPlugin.FILE_TYPES_EXTENSION); - if (extension != null) { - IExtension[] extensions = extension.getExtensions(); - for (int i = 0; i < extensions.length; i++) { - IConfigurationElement[] configElements = extensions[i].getConfigurationElements(); - for (int j = 0; j < configElements.length; j++) { - String ext = configElements[j].getAttribute("extension"); //$NON-NLS-1$ - if (ext != null) { - String type = configElements[j].getAttribute("type"); //$NON-NLS-1$ - // If the extension doesn't already exist, add it. - if (!table.containsKey(ext)) { - if (type.equals("text")) { //$NON-NLS-1$ - table.put(ext, new Integer(TEXT)); - } else if (type.equals("binary")) { //$NON-NLS-1$ - table.put(ext, new Integer(BINARY)); - } - } - } - } - } - } - } - } - - /* - * TEXT - * - * Read the saved file type state from the given input stream. - * - * @param dis the input stream to read the saved state from - * @throws IOException if an I/O problem occurs - */ - private static void readTextState(DataInputStream dis) throws IOException { - table = new Hashtable(11); - int extensionCount = 0; - try { - extensionCount = dis.readInt(); - } catch (EOFException e) { - // Ignore the exception, it will occur if there are no - // patterns stored in the state file. - return; - } - for (int i = 0; i < extensionCount; i++) { - String extension = dis.readUTF(); - int type = dis.readInt(); - table.put(extension, new Integer(type)); - } - } - - /* - * TEXT - * - * Write the current state to the given output stream. - * - * @param dos the output stream to write the saved state to - * @throws IOException if an I/O problem occurs - */ - private static void writeTextState(DataOutputStream dos) throws IOException { - dos.writeInt(table.size()); - Iterator it = table.keySet().iterator(); - while (it.hasNext()) { - String extension = (String)it.next(); - dos.writeUTF(extension); - Integer integer = (Integer)table.get(extension); - dos.writeInt(integer.intValue()); - } - } - - /* - * TEXT - * - * Load the file type registry saved state. This loads the previously saved - * contents, as well as discovering any values contributed by plug-ins. - */ - private static void loadTextState() { - IPath pluginStateLocation = TeamPlugin.getPlugin().getStateLocation().append(STATE_FILE); - File f = pluginStateLocation.toFile(); - if (f.exists()) { - try { - DataInputStream dis = new DataInputStream(new FileInputStream(f)); - readTextState(dis); - dis.close(); - } catch (IOException ex) { - TeamPlugin.log(Status.ERROR, ex.getMessage(), ex); - } - } - // Read values contributed by plugins - initializePluginPatterns(); - } - - /* - * TEXT - * - * Save the file type registry state. - */ - private static void saveTextState() { - IPath pluginStateLocation = TeamPlugin.getPlugin().getStateLocation(); - File tempFile = pluginStateLocation.append(STATE_FILE + ".tmp").toFile(); //$NON-NLS-1$ - File stateFile = pluginStateLocation.append(STATE_FILE).toFile(); - try { - DataOutputStream dos = new DataOutputStream(new FileOutputStream(tempFile)); - writeTextState(dos); - dos.close(); - if (stateFile.exists() && !stateFile.delete()) { - TeamPlugin.log(Status.ERROR, Policy.bind("Team.Could_not_delete_state_file_1"), null); //$NON-NLS-1$ - return; - } - boolean renamed = tempFile.renameTo(stateFile); - if (!renamed) { - TeamPlugin.log(Status.ERROR, Policy.bind("Team.Could_not_rename_state_file_2"), null); //$NON-NLS-1$ - return; - } - } catch (Exception e) { - TeamPlugin.log(Status.ERROR, e.getMessage(), e); - } - } - - /* - * IGNORE - * - * Reads the ignores currently defined by extensions. - */ - private static void initializePluginIgnores() { - TeamPlugin plugin = TeamPlugin.getPlugin(); - if (plugin != null) { - IExtensionPoint extension = plugin.getDescriptor().getExtensionPoint(TeamPlugin.IGNORE_EXTENSION); - if (extension != null) { - IExtension[] extensions = extension.getExtensions(); - for (int i = 0; i < extensions.length; i++) { - IConfigurationElement [] configElements = extensions[i].getConfigurationElements(); - for (int j = 0; j < configElements.length; j++) { - String pattern = configElements[j].getAttribute("pattern"); //$NON-NLS-1$ - if (pattern != null) { - String selected = configElements[j].getAttribute("selected"); //$NON-NLS-1$ - boolean enabled = selected != null && selected.equalsIgnoreCase("true"); //$NON-NLS-1$ - // if this ignore doesn't already exist, add it to the global list - if (!globalIgnore.containsKey(pattern)) { - globalIgnore.put(pattern, new Boolean(enabled)); - } - } - } - } - } - } - } - - /* - * IGNORE - * - * Save global ignore file - */ - private static void saveIgnoreState() throws TeamException { - // save global ignore list to disk - IPath pluginStateLocation = TeamPlugin.getPlugin().getStateLocation(); - File tempFile = pluginStateLocation.append(GLOBALIGNORE_FILE + ".tmp").toFile(); //$NON-NLS-1$ - File stateFile = pluginStateLocation.append(GLOBALIGNORE_FILE).toFile(); - try { - DataOutputStream dos = new DataOutputStream(new FileOutputStream(tempFile)); - writeIgnoreState(dos); - dos.close(); - if (stateFile.exists()) - stateFile.delete(); - boolean renamed = tempFile.renameTo(stateFile); - if (!renamed) - throw new TeamException(new Status(IStatus.ERROR, TeamPlugin.ID, 0, Policy.bind("TeamPlugin_renaming_21"), null)); //$NON-NLS-1$ - } catch (IOException ex) { - throw new TeamException(new Status(IStatus.ERROR, TeamPlugin.ID, 0, Policy.bind("TeamPlugin_closing_stream_22"), ex)); //$NON-NLS-1$ - } - } - - /* - * IGNORE - * - * Write the global ignores to the stream - */ - private static void writeIgnoreState(DataOutputStream dos) throws IOException { - // write the global ignore list - int ignoreLength = globalIgnore.size(); - dos.writeInt(ignoreLength); - Iterator e = globalIgnore.keySet().iterator(); - while (e.hasNext()) { - String pattern = (String)e.next(); - boolean enabled = ((Boolean)globalIgnore.get(pattern)).booleanValue(); - dos.writeUTF(pattern); - dos.writeBoolean(enabled); - } - } - - /* - * IGNORE - * - * Reads the global ignore file - */ - private static void readIgnoreState() throws TeamException { - // read saved repositories list and ignore list from disk, only if the file exists - IPath pluginStateLocation = TeamPlugin.getPlugin().getStateLocation().append(GLOBALIGNORE_FILE); - File f = pluginStateLocation.toFile(); - if(f.exists()) { - try { - DataInputStream dis = new DataInputStream(new FileInputStream(f)); - globalIgnore = new Hashtable(11); - int ignoreCount = 0; - try { - ignoreCount = dis.readInt(); - } catch (EOFException e) { - // Ignore the exception, it will occur if there are no ignore - // patterns stored in the provider state file. - return; - } - for (int i = 0; i < ignoreCount; i++) { - String pattern = dis.readUTF(); - boolean enabled = dis.readBoolean(); - globalIgnore.put(pattern, new Boolean(enabled)); - } - } catch (FileNotFoundException e) { - // not a fatal error, there just happens not to be any state to read - } catch (IOException ex) { - throw new TeamException(new Status(IStatus.ERROR, TeamPlugin.ID, 0, Policy.bind("TeamPlugin_closing_stream_23"), ex)); //$NON-NLS-1$ - } - } - } - - /** - * Initialize the registry, restoring its state. - * - * This method is called by the plug-in upon startup, clients should not call this method - */ - public static void startup() throws CoreException { - try { - table = new Hashtable(11); - loadTextState(); - readIgnoreState(); - initializePluginIgnores(); - } catch (TeamException e) { - throw new CoreException(e.getStatus()); - } - } - - /** - * Shut down the registry, persisting its state. - * - * This method is called by the plug-in upon shutdown, clients should not call this method - */ - public static void shutdown() { - saveTextState(); - try { - // make sure that we update our state on disk - saveIgnoreState(); - } catch (TeamException ex) { - TeamPlugin.log(IStatus.WARNING, Policy.bind("TeamPlugin_setting_global_ignore_7"), ex); //$NON-NLS-1$ - } - } - public static IProjectSetSerializer getProjectSetSerializer(String id) { - TeamPlugin plugin = TeamPlugin.getPlugin(); - if (plugin != null) { - IExtensionPoint extension = plugin.getDescriptor().getExtensionPoint(TeamPlugin.PROJECT_SET_EXTENSION); - if (extension != null) { - IExtension[] extensions = extension.getExtensions(); - for (int i = 0; i < extensions.length; i++) { - IConfigurationElement [] configElements = extensions[i].getConfigurationElements(); - for (int j = 0; j < configElements.length; j++) { - String extensionId = configElements[j].getAttribute("id"); //$NON-NLS-1$ - if (extensionId != null && extensionId.equals(id)) { - try { - return (IProjectSetSerializer)configElements[j].createExecutableExtension("class"); //$NON-NLS-1$ - } catch (CoreException e) { - TeamPlugin.log(e.getStatus()); - return null; - } - } - } - } - } - } - return null; - } - private static TeamException wrapException(String message, CoreException e) { - MultiStatus status = new MultiStatus(TeamPlugin.ID, 0, message, e); - status.merge(e.getStatus()); - return new TeamException(status); - } -} diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/TeamException.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/TeamException.java deleted file mode 100644 index 78b29ef75..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/TeamException.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial API and implementation - ******************************************************************************/ -package org.eclipse.team.core; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.team.internal.core.TeamPlugin; - -/** - * This exception is thrown by the team provider API. It represents a failure in an API call. - * Since some API calls take multiple arguments, the exception is capable of returning multiple - * statuses. The API definition determinies if the exception represents a single or multiple status - * response; this can also be tested on the exception instance itself. - * <p> - * To determine the exact cause of the failure the caller should look at each status in detail.</p> - * - * @since 2.0 - */ -public class TeamException extends Exception { - - protected IStatus status = null; - - // The operation completed successfully. - public static final int OK = 0; - - // The operation failed because the resource is not checked-in. - public static final int NOT_CHECKED_IN = -1; - - // The operation failed because the resource is not checked-out. - public static final int NOT_CHECKED_OUT = -2; - - // The corresponding remote resource no longer exists or was never created. - public static final int NO_REMOTE_RESOURCE = -3; - - // The provider suffered an IO failure, the operation may be retried. - public static final int IO_FAILED = -4; - - // The user is not authorized to execute the attempted operation. - public static final int NOT_AUTHORIZED = -5; - - // The provider was unable to complete the operation for an unspecified reason. - public static final int UNABLE = -6; - - // The operation cannot be performed due to a conflict with other work. - public static final int CONFLICT = -7; - - /** - * Single status constructor for a <code>TeamProviderException</code>. - */ - public TeamException(IStatus status) { - super(status.getMessage()); - this.status = status; - } - - /** - * Answer the single status resulting from the attempted API call. - * - * @return the single status of the result, or <code>null</code> if this is a multi-status - * response. - */ - public IStatus getStatus() { - return status; - } - - public TeamException(String message, Exception e) { - super(e.getMessage()); - this.status = new Status(IStatus.ERROR, TeamPlugin.ID, 0, message, e); - } - - public TeamException(String message) { - super(message); - this.status = new Status(IStatus.ERROR, TeamPlugin.ID, 0, message, null); - } -} diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/sync/ILocalSyncElement.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/sync/ILocalSyncElement.java deleted file mode 100644 index f3855f862..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/sync/ILocalSyncElement.java +++ /dev/null @@ -1,206 +0,0 @@ -package org.eclipse.team.core.sync; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.core.TeamException; - -/** - * A <code>ILocalSyncElement</code> describes the relative synchronization of a <b>local</b> - * resource using a <b>base</b> resource for comparison. - * <p> - * Differences between the base and local resources are classified as <b>outgoing changes</b>; - * if there is a difference, the local resource is considered the <b>outgoing resource</b>. </p> - * - * @see IRemoteSyncElement - */ -public interface ILocalSyncElement { - - /*==================================================================== - * Constants defining synchronization types: - *====================================================================*/ - - /** - * Sync constant (value 0) indicating element is in sync. - */ - public static final int IN_SYNC = 0; - - /** - * Sync constant (value 1) indicating that one side was added. - */ - public static final int ADDITION = 1; - - /** - * Sync constant (value 2) indicating that one side was deleted. - */ - public static final int DELETION = 2; - - /** - * Sync constant (value 3) indicating that one side was changed. - */ - public static final int CHANGE = 3; - - /** - * Bit mask for extracting the change type. - */ - public static final int CHANGE_MASK = CHANGE; - - /*==================================================================== - * Constants defining synchronization direction: - *====================================================================*/ - - /** - * Sync constant (value 4) indicating a change to the local resource. - */ - public static final int OUTGOING = 4; - - /** - * Sync constant (value 8) indicating a change to the remote resource. - */ - public static final int INCOMING = 8; - - /** - * Sync constant (value 12) indicating a change to both the remote and local resources. - */ - public static final int CONFLICTING = 12; - - /** - * Bit mask for extracting the synchronization direction. - */ - public static final int DIRECTION_MASK = CONFLICTING; - - /*==================================================================== - * Constants defining synchronization conflict types: - *====================================================================*/ - - /** - * Sync constant (value 16) indication that both the local and remote resources have changed - * relative to the base but their contents are the same. - */ - public static final int PSEUDO_CONFLICT = 16; - - /** - * Sync constant (value 32) indicating that both the local and remote resources have changed - * relative to the base but their content changes do not conflict (e.g. source file changes on different - * lines). These conflicts could be merged automatically. - */ - public static final int AUTOMERGE_CONFLICT = 32; - - /** - * Sync constant (value 64) indicating that both the local and remote resources have changed relative - * to the base and their content changes conflict (e.g. local and remote resource have changes on - * same lines). These conflicts can only be correctly resolved by the user. - */ - public static final int MANUAL_CONFLICT = 64; - - /*==================================================================== - * Constants defining synchronization granularity: - *====================================================================*/ - - /** - * Constant (value 1) to only consider timestamp comparisons (e.g. isDirty) when - * calculating the synchronization kind. This is the faster sync compare option but it can result in false - * conflicts. - */ - public static final int GRANULARITY_TIMESTAMP = 1; - - /** - * Constant (value 2) indicating to consider file contents when calculating the synchronization kind. This - * synchronization mode will perform a content comparison only after timestamp operations (isDirty) - * indicate a change. This mode allows conflicts types to be correctly identified. - */ - public static final int GRANULARITY_CONTENTS = 2; - - /** - * Answer a string that describes the simple name of the sync node, which is suitable - * for display to a user. The name will be used in UI operations, so it is expected that - * implementations will cache this value. - * - * @return the simple name that identifies the resource within its parent container. - */ - public String getName(); - - /** - * Answer if the sync node is a container and may have children. - * - * @return <code>true</code> if the remote resource is a container, and <code> - * false</code> if it is not. - */ - public boolean isContainer(); - - /** - * Answers the local sync element of this node. Returns a non-existing local - * resource handle if the local resource does not exist in the workspace. - * - * @return the local resource handle in this node. There should always be a local - * resource available, however the resource may not exist. - */ - public IResource getLocal(); - - /** - * Answers the base sync element of this node. Returns <code>null</code> - * if there is no base (e.g. conflicting add). - * - * @return the base resource in this node, or <code>null</code> is there - * is none. - */ - public IRemoteResource getBase(); - - /** - * Answers if the remote resource state is checked-out. If the resource has never been checked in this - * method will return <code>true</code>. - * <p> - * It is undefined whether this method tests for a resource being checked out to this workspace - * or any workspace.</p> - * - * @param resource the local resource to test. - * @return <code>true</code> if the resource is checked-out and <code>false</code> if it is not. - * @see checkout(IResource[], int, IProgressMonitor) - * @see refreshState(IResource[], int, IProgressMonitor) - */ - public boolean isCheckedOut(); - - /** - * Answers whether the resource has a corresponding remote resource. - * <p> - * Before a resource is checked-in, the resource will occur locally but not remotely, and calls to this - * method will return <code>false</code>. Once a local resource is checked in (and assuming the local - * local resource is not moved or the remote resource deleted) there will be a corresponding remote - * resource and this method returns <code>true</code>.</p> - * - * @param resource the local resource to test. - * @return <code>true</code> if the local resource has a corresponding remote resource, - * and <code>false</code> otherwise. - */ - public boolean hasRemote(); - - /** - * Answers and array of <code>ILocalSyncElement</code> elements that are immediate - * children of this sync element, in no particular order. The returned sync nodes are - * a combination of the nodes represented by the sync element (e.g. local, base, remote). - * - * @param progress a progress monitor to indicate the duration of the operation, or - * <code>null</code> if progress reporting is not required. - * - * @return array of immediate children of this sync node. - */ - public ILocalSyncElement[] members(IProgressMonitor monitor) throws TeamException; - - /** - * Performs a synchronization calculation on the given element based on the local and base - * resources. Returns an integer describing the synchronization state of this element. - * - * @param granularity the granularity at which the elements of this sync element - * should be compared. On of <code>GRANULARITY_TIMESTAMP</code>, or - * <code>GRANULARITY_CONTENTS</code>. - * @param progress a progress monitor to indicate the duration of the operation, or - * <code>null</code> if progress reporting is not required. - * - * @return an integer describing the synchronization state of this element. - */ - public int getSyncKind(int granularity, IProgressMonitor progress); -}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/sync/IRemoteResource.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/sync/IRemoteResource.java deleted file mode 100644 index 1bfd5d90f..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/sync/IRemoteResource.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial API and implementation - ******************************************************************************/ -package org.eclipse.team.core.sync; - -import java.io.InputStream; - -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.core.TeamException; - -/** - * Interface for resources that are not local. - */ -public interface IRemoteResource extends IAdaptable { - - /** - * Answers a string that describes the name of the remote resource. The name may be - * displayed to the user. - * - * @return name of the remote resource. - */ - public String getName(); - - /** - * Answers and array of <code>IRemoteResource</code> elements that are immediate - * children of this remote resource, in no particular order. - * - * @param progress a progress monitor to indicate the duration of the operation, or - * <code>null</code> if progress reporting is not required. - * - * @return array of immediate children of this remote resource. - */ - public IRemoteResource[] members(IProgressMonitor progress) throws TeamException; - - /** - * Returns a stream over the contents of this remote element. - * - * @param progress a progress monitor to indicate the duration of the operation, or - * <code>null</code> if progress reporting is not required. - */ - public InputStream getContents(IProgressMonitor progress) throws TeamException; - - /** - * Answers if the remote element may have children. - * - * @return <code>true</code> if the remote element may have children and - * <code>false</code> otherwise. - */ - public boolean isContainer(); -} - diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/sync/IRemoteSyncElement.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/sync/IRemoteSyncElement.java deleted file mode 100644 index 3089f8d18..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/sync/IRemoteSyncElement.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.eclipse.team.core.sync; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.team.core.TeamException; - -/** - * A <code>ILocalSyncElement</code> describes the relative synchronization of a <b>local</b> - * and <b>remote</b> resource using a <b>base</b> resource for comparison. - * <p> - * Differences between the base and remote resources are classified as <b>incoming changes</b>; - * if there is a difference, the remote resource is considered the <b>incoming resource</b>. </p> - * - * @see ILocalSyncElement - * @see ISyncProvider - */ -public interface IRemoteSyncElement extends ILocalSyncElement { - - /** - * Answer the remote sync element of this node. Returns <code>null</code> - * if there is no remote. - * - * @return the remote resource in this sync element, or <code>null</code> is there - * is none. - */ - public IRemoteResource getRemote(); - - /** - * Answers <code>true</code> if the base tree is not to be considered during sync - * comparisons and <code>false</code> if it should. If the base tree is ignored the - * sync comparison can be based on isOutOfDate and isDirty methods only. - */ - public boolean isThreeWay(); -}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/sync/LocalSyncElement.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/sync/LocalSyncElement.java deleted file mode 100644 index 7df9ea35e..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/sync/LocalSyncElement.java +++ /dev/null @@ -1,104 +0,0 @@ -package org.eclipse.team.core.sync; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.IOException; -import java.io.InputStream; - -import java.util.ArrayList; -import java.util.List; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.core.TeamException; - -/** - * A standard abstract class that provides implementations for <code>ILocalSyncElement</code> - * methods. - */ -public abstract class LocalSyncElement implements ILocalSyncElement { - - /** - * Creates a client specific sync element from a <b>local</b> and <b>base</b> - * resources. The <b>base</b> resource may be <code>null</code> and should be - * intialized by the client if available. - * - * @param local the local resource in the workbench. Will never be <code>null</code>. - * @param base the base resource, may me <code>null</code>. - * @param data client specific data. - * - * @return a client specific sync element. - */ - public abstract ILocalSyncElement create(IResource local, IRemoteResource base, Object data); - - /** - * Client data that is passed to every <code>create()</code> call. - * - * @return client specific data that will be passed to create. - */ - protected abstract Object getData(); - - /** - * Client can decide is a specific element should be ignored from this sync element's - * children. - * - * @param resource the resource to be queried. - * - * @return <code>true</code> if this element should be ignored and not considered an - * immediate child of this element, and <code>false</code> otherwise. - */ - protected abstract boolean isIgnored(IResource resource); - - /* - * @see ILocalSyncElement#getSyncKind(int, IProgressMonitor) - */ - public int getSyncKind(int granularity, IProgressMonitor progress) { - - // XXX not sure how local sync will be used? - int sync = IN_SYNC; - return sync; - } - - /* - * @see ILocalSyncElement#getName() - */ - public String getName() { - return getLocal().getName(); - } - - /* - * @see ILocalSyncElement#isContainer() - */ - public boolean isContainer() { - return getLocal().getType() != IResource.FILE; - } - - /* - * @see ILocalSyncElement#members(IProgressMonitor) - */ - public ILocalSyncElement[] members(IProgressMonitor monitor) throws TeamException { - try { - if(getLocal().getType() != IResource.FILE) { - IResource[] members = ((IContainer)getLocal()).members(); - List syncElements = new ArrayList(5); - for (int i = 0; i < members.length; i++) { - IResource iResource = members[i]; - // the base is initialy set to null, however the concrete subclass should - // initialize the base if one is available. - if(!isIgnored(iResource)) { - syncElements.add(create(iResource, null, getData())); - } - } - return (ILocalSyncElement[]) syncElements.toArray(new ILocalSyncElement[syncElements.size()]); - } else { - return new ILocalSyncElement[0]; - } - } catch(CoreException e) { - throw new TeamException(e.getStatus()); - } - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/sync/RemoteSyncElement.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/sync/RemoteSyncElement.java deleted file mode 100644 index 2acab24cc..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/sync/RemoteSyncElement.java +++ /dev/null @@ -1,405 +0,0 @@ -package org.eclipse.team.core.sync; - -/* - * (c) Copyright IBM Corp. 2000, 2002. - * All Rights Reserved. - */ - -import java.io.BufferedInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IStorage; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Path; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.internal.core.Assert; -import org.eclipse.team.internal.core.Policy; - -/** - * A standard abstract class that provides implementations for interesting - * <code>IRemoteSyncElement</code> methods. The <code>members</code> method - * provided will create a unified tree based on the local, base, and remote - * children. The <code>getSyncKind</code> method will calculate the relative - * sync kind of the remote node. - */ -public abstract class RemoteSyncElement extends LocalSyncElement implements IRemoteSyncElement { - - /** - * Creates a client specific sync element from a <b>local</b>, <b>base</b>, and - * <b>remote</b> resources. The <b>base</b> and <b>remote</b> resource may be - * <code>null</code>. - * - * @param local the local resource in the workbench. Will never be <code>null</code>. - * @param base the base resource, may me <code>null</code>. - * @param remote the remote resource, may be <code>null</code>. - * @param data client specific data. - * - * @return a client specific sync element. - */ - public abstract IRemoteSyncElement create(boolean isThreeWay, IResource local, IRemoteResource base, IRemoteResource remote, Object data); - - /* - * @see ILocalSyncElement#members() - */ - public ILocalSyncElement[] members(IProgressMonitor progress) throws TeamException { - // create union of the local, base, and remote trees - IRemoteResource remote = getRemote(); - IRemoteResource base = getBase(); - IResource local = getLocal(); - - IRemoteResource[] remoteChildren = - remote != null ? remote.members(progress) : new IRemoteResource[0]; - - IRemoteResource[] baseChildren = - base != null ? base.members(progress) : new IRemoteResource[0]; - - IResource[] localChildren; - try { - if( local.getType() != IResource.FILE && local.exists() ) { - localChildren = ((IContainer)local).members(); - } else { - localChildren = new IResource[0]; - } - } catch(CoreException e) { - throw new TeamException(e.getStatus()); - } - - if (remoteChildren.length > 0 || localChildren.length > 0) { - List syncChildren = new ArrayList(10); - Set allSet = new HashSet(20); - Map localSet = null; - Map remoteSet = null; - Map baseSet = null; - - if (localChildren.length > 0) { - localSet = new HashMap(10); - for (int i = 0; i < localChildren.length; i++) { - IResource localChild = localChildren[i]; - String name = localChild.getName(); - localSet.put(name, localChild); - allSet.add(name); - } - } - - if (remoteChildren.length > 0) { - remoteSet = new HashMap(10); - for (int i = 0; i < remoteChildren.length; i++) { - IRemoteResource remoteChild = remoteChildren[i]; - String name = remoteChild.getName(); - remoteSet.put(name, remoteChild); - allSet.add(name); - } - } - - if (baseChildren.length > 0) { - baseSet = new HashMap(10); - for (int i = 0; i < baseChildren.length; i++) { - IRemoteResource baseChild = baseChildren[i]; - String name = baseChild.getName(); - baseSet.put(name, baseChild); - allSet.add(name); - } - } - - Iterator e = allSet.iterator(); - while (e.hasNext()) { - String keyChildName = (String) e.next(); - - if (progress != null) { - if (progress.isCanceled()) { - throw new OperationCanceledException(); - } - // XXX show some progress? - } - - IResource localChild = - localSet != null ? (IResource) localSet.get(keyChildName) : null; - - IRemoteResource remoteChild = - remoteSet != null ? (IRemoteResource) remoteSet.get(keyChildName) : null; - - IRemoteResource baseChild = - baseSet != null ? (IRemoteResource) baseSet.get(keyChildName) : null; - - - if (localChild == null) { - // there has to be a remote resource available if we got this far - Assert.isTrue(remoteChild != null || baseChild != null); - boolean isContainer = remoteChild != null ? remoteChild.isContainer() : baseChild.isContainer(); - - localChild = getResourceChild(local /* parent */, keyChildName, isContainer); - } - - if(!localChild.exists() || !isIgnored(localChild)) { - syncChildren.add(create(isThreeWay(), localChild, baseChild, remoteChild, getData())); - } - } - return (IRemoteSyncElement[]) syncChildren.toArray(new IRemoteSyncElement[syncChildren.size()]); - } - else { - return new IRemoteSyncElement[0]; - } - } - - /* - * @see ILocalSyncElement#getSyncKind(int, IProgressMonitor) - */ - public int getSyncKind(int granularity, IProgressMonitor progress) { - int description = IN_SYNC; - - IResource local = getLocal(); - IRemoteResource remote = getRemote(); - IRemoteResource base = getBase(); - - boolean localExists = getLocal().exists(); - - if (isThreeWay()) { - if (base == null) { - if (remote == null) { - if (!localExists) { - Assert.isTrue(false); - } else { - description = OUTGOING | ADDITION; - } - } else { - if (!localExists) { - description = INCOMING | ADDITION; - } else { - description = CONFLICTING | ADDITION; - try { - progress.beginTask(null, 60); - if (granularity == RemoteSyncElement.GRANULARITY_CONTENTS && - compare(granularity, true, local, remote, Policy.subMonitorFor(progress, 30))) { - description |= PSEUDO_CONFLICT; - } - } finally { - progress.done(); - } - } - } - } else { - if (!localExists) { - if (remote == null) { - description = CONFLICTING | DELETION | PSEUDO_CONFLICT; - } else { - if (compare(granularity, false, base, remote, progress)) - description = OUTGOING | DELETION; - else - description = CONFLICTING | CHANGE; - } - } else { - if (remote == null) { - if (compare(granularity, false, local, base, progress)) - description = INCOMING | DELETION; - else - description = CONFLICTING | CHANGE; - } else { - progress.beginTask(null, 90); - boolean ay = compare(granularity, false, local, base, Policy.subMonitorFor(progress, 30)); - boolean am = compare(granularity, false, base, remote, Policy.subMonitorFor(progress, 30)); - if (ay && am) { - ; - } else if (ay && !am) { - description = INCOMING | CHANGE; - } else if (!ay && am) { - description = OUTGOING | CHANGE; - } else { - description = CONFLICTING | CHANGE; - if (granularity == RemoteSyncElement.GRANULARITY_CONTENTS && - compare(granularity, true, local, remote, Policy.subMonitorFor(progress, 30))) { - description |= PSEUDO_CONFLICT; - } - } - progress.done(); - } - } - } - } else { // two compare without access to base contents - if (remote == null) { - if (!localExists) { - Assert.isTrue(false); - // shouldn't happen - } else { - description= DELETION; - } - } else { - if (!localExists) { - description= ADDITION; - } else { - if (! compare(granularity, false, local, remote, Policy.subMonitorFor(progress, 30))) - description= CHANGE; - } - } - } - return description; - } - - /** - * Helper methods for comparisons that returns true if the resource contents are the same. - * - * If timestampDiff is true then the timestamps don't differ and there's no point checking the - * contents. - */ - protected boolean compare(int granularity, boolean force, IResource e1, IRemoteResource e2, IProgressMonitor monitor) { - boolean timestampEquals; - if (force) { - timestampEquals = false; - } else { - timestampEquals = timestampEquals(e1, e2); - } - if (!timestampEquals && (granularity == GRANULARITY_CONTENTS)) { - try { - monitor.beginTask(null, 100); - return contentsEqual(getContents(e1, Policy.subMonitorFor(monitor, 50)), getContents(e2, Policy.subMonitorFor(monitor, 50))); - } finally { - monitor.done(); - } - } else { - return timestampEquals; - } - } - - protected boolean compare(int granularity, boolean force, IRemoteResource e1, IRemoteResource e2, IProgressMonitor monitor) { - boolean timestampEquals; - if (force) { - timestampEquals = false; - } else { - timestampEquals = timestampEquals(e1, e2); - } - if (!timestampEquals && (granularity == GRANULARITY_CONTENTS)) { - try { - monitor.beginTask(null, 100); - return contentsEqual(getContents(e1, Policy.subMonitorFor(monitor, 50)), getContents(e2, Policy.subMonitorFor(monitor, 50))); - } finally { - monitor.done(); - } - } else { - return timestampEquals; - } - } - - protected abstract boolean timestampEquals(IResource e1, IRemoteResource e2); - protected abstract boolean timestampEquals(IRemoteResource e1, IRemoteResource e2); - - private InputStream getContents(IResource resource, IProgressMonitor monitor) { - try { - if (resource instanceof IStorage) - return new BufferedInputStream(((IStorage) resource).getContents()); - return null; - } catch (CoreException e) { - return null; - } - } - - private InputStream getContents(IRemoteResource remote, IProgressMonitor monitor) { - try { - if (!remote.isContainer()) - return new BufferedInputStream(remote.getContents(monitor)); - return null; - } catch (TeamException exception) { - // The remote node has gone away . - return null; - } - } - - /** - * Returns <code>true</code> if both input streams byte contents is identical. - * - * @param input1 first input to contents compare - * @param input2 second input to contents compare - * @return <code>true</code> if content is equal - */ - private boolean contentsEqual(InputStream is1, InputStream is2) { - if (is1 == is2) - return true; - - if (is1 == null && is2 == null) // no byte contents - return true; - - try { - if (is1 == null || is2 == null) // only one has contents - return false; - - while (true) { - int c1 = is1.read(); - int c2 = is2.read(); - if (c1 == -1 && c2 == -1) - return true; - if (c1 != c2) - break; - - } - } catch (IOException ex) { - } finally { - if (is1 != null) { - try { - is1.close(); - } catch (IOException ex) { - } - } - if (is2 != null) { - try { - is2.close(); - } catch (IOException ex) { - } - } - } - return false; - } - - /* - * Returns a handle to a non-existing resource. - */ - private IResource getResourceChild(IResource parent, String childName, boolean isContainer) { - if (parent.getType() == IResource.FILE) { - return null; - } - if (isContainer) { - return ((IContainer) parent).getFolder(new Path(childName)); - } else { - return ((IContainer) parent).getFile(new Path(childName)); - } - } - - /* - * @see Object#toString() - */ - public String toString() { - return getName() + kindToString(getSyncKind(GRANULARITY_TIMESTAMP, null)); - } - - static public String kindToString(int kind) { - StringBuffer buffer = new StringBuffer(); - buffer.append("["); //$NON-NLS-1$ - if(kind==IN_SYNC) { - buffer.append("in-sync"); //$NON-NLS-1$ - } else { - switch(kind & DIRECTION_MASK) { - case CONFLICTING: buffer.append("conflicting"); break; //$NON-NLS-1$ - case OUTGOING: buffer.append("outgoing"); break; //$NON-NLS-1$ - case INCOMING: buffer.append("incoming"); break; //$NON-NLS-1$ - } - switch(kind & CHANGE_MASK) { - case CHANGE: buffer.append("change"); break; //$NON-NLS-1$ - case ADDITION: buffer.append("addition"); break; //$NON-NLS-1$ - case DELETION: buffer.append("deletion"); break; //$NON-NLS-1$ - } - if((kind & MANUAL_CONFLICT) != 0) buffer.append("{manual}"); //$NON-NLS-1$ - if((kind & AUTOMERGE_CONFLICT) != 0) buffer.append("{auto}"); //$NON-NLS-1$ - } - buffer.append("]"); //$NON-NLS-1$ - return buffer.toString(); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/target/IRemoteTargetResource.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/target/IRemoteTargetResource.java deleted file mode 100644 index a8495b7b7..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/target/IRemoteTargetResource.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial API and implementation - ******************************************************************************/ -package org.eclipse.team.core.target; - -import java.net.URL; - -import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.sync.IRemoteResource; - -/** - * Interface for target resources that are not local. This is a handle to a - * clients-side 'proxy' for the server resource. There are no guarantees that - * the handle is not stale or invalid. - * <p> - * Use <code>exists()</code> to verify is the associated server resource - * exists. - * </p> - * - * @see IRemoteResource - */ -public interface IRemoteTargetResource extends IRemoteResource { - /** - * Returns the URL of this remote resource. - */ - public URL getURL() throws TeamException; - - /** - * Returns the size of the resource. - */ - public int getSize() throws TeamException; - - /** - * Returns the last modified time - */ - public String getLastModified() throws TeamException; - - /** - * Return a boolean value indicating whether or not this resource exists on the - * remote server. - */ - public boolean exists() throws TeamException; -} diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/target/ISiteFactory.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/target/ISiteFactory.java deleted file mode 100644 index 9b9d05dc0..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/target/ISiteFactory.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial API and implementation - ******************************************************************************/ -package org.eclipse.team.core.target; - -import java.io.ObjectInputStream; -import java.util.Properties; - -/** - * The <code>ISiteFactory</code> interface must be implemented by any plug-in - * that is providing target management. It provides mechanisms for creating - * concrete <code>Site</code> instances for it's target type. - * - * @see Site - */ -public interface ISiteFactory { - /** - * Responsible for reading from the stream and restoring the classes fields - * then returning a new <code>Site</code> instance. The <code>Site</code> - * instances are written using the <code>Site#writeObject</code> method. - * - * @param is the input stream that contains the output of Site#writeObject - * @return a new target site - */ - public Site newSite(ObjectInputStream is); - - /** - * Returns a new target site for the given target specific properties. This - * is mainly used for testing purposes. - * - * @param properties the target specific location encoded in properties - * @return a new target site - */ - public Site newSite(Properties properties); -}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/target/ISiteListener.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/target/ISiteListener.java deleted file mode 100644 index 44d95e113..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/target/ISiteListener.java +++ /dev/null @@ -1,16 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial API and implementation - ******************************************************************************/ -package org.eclipse.team.core.target; - -public interface ISiteListener { - public void siteAdded(Site site); - public void siteRemoved(Site site); -}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/target/Site.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/target/Site.java deleted file mode 100644 index d65818bc2..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/target/Site.java +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial API and implementation - ******************************************************************************/ -package org.eclipse.team.core.target; - -import java.io.ObjectOutputStream; -import java.net.URL; -import java.security.Provider; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.sync.IRemoteResource; - -/** - * A <code>Site</code> is a place where resources can be deployed and - * retrieved via a target provider. - * - * @see ISiteFactory - */ -public abstract class Site { - - /** - * Answers a <code>TargetProvider</code> instance for the given path at - * this site. - */ - public abstract TargetProvider newProvider(IPath intrasitePath) - throws TeamException; - - /** - * Answers the type identifier for this site. For example: - * <blockquote><pre> - * org.eclipse.team.target.webdav - * </pre></blockquote> - * - * @return string identifier for this site - */ - public abstract String getType(); - - /** - * Answers the location of this site as a URL. For example: - * <blockquote><pre> - * http://www.mysite.com:14356/dav - * </pre></blockquote> - * - * @return URL location of this site - */ - public abstract URL getURL(); - - /** - * Answers a string that can be displayed to the user that represents - * this site. For example: - * <blockquote><pre> - * http://usename@www.mysite.com/dav (WebDav) - * </pre></blockquote> - */ - public abstract String getDisplayName(); - - /** - * Writes the state of this site such that the corresponding concrete - * <code>ISiteFactory</code> class can restore the site. - * - * @param os the object stream into which to write it's state - */ - public abstract void writeObject(ObjectOutputStream os); - - /** - * Returns a handle to the remote resource that represents this site - * on the server. - * - * @return a remote handle to this site that may or may not exist - */ - public IRemoteTargetResource getRemoteResource() throws TeamException { - return newProvider(Path.EMPTY).getRemoteResource(); - } - - /** - * Compares two Sites. The result is <code>true</code> if and only if - * the argument is not <code>null</code> and is a Site object that - * represents the same Site as this object. Two Site objects are equal - * if they have the same types and URLs. - * - * @param other the Site to compare against - * - * @return <code>true</code> if the Sites are the same; <code>false</code> - * otherwise - * - * @see Object#equals(Object) - */ - public boolean equals(Object other) { - if(this == other) return true; - if(! (other instanceof Site)) return false; - Site location = (Site)other; - return getType().equals(location.getType()) && - getURL().equals(location.getURL()); - } - - /** - * Debugging helper - * - * @see Object#toString() - */ - public String toString() { - return getDisplayName(); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/target/TargetManager.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/target/TargetManager.java deleted file mode 100644 index bcb4e3482..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/target/TargetManager.java +++ /dev/null @@ -1,257 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial API and implementation - ******************************************************************************/ -package org.eclipse.team.core.target; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.net.URL; -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ISynchronizer; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.core.runtime.Status; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.internal.core.Policy; -import org.eclipse.team.internal.core.TeamPlugin; -import org.eclipse.team.internal.core.target.LocationMapping; - -public class TargetManager { - private static final String TARGET_SITES_FILE = ".targetSites"; //$NON-NLS-1$ - - private static QualifiedName TARGET_MAPPINGS = - new QualifiedName("org.eclipse.team.core.target", "mappings"); //$NON-NLS-1$ //$NON-NLS-2$ - - private static Map factories = new Hashtable(); - private static List sites = new ArrayList(); - private static List listeners = new ArrayList(); - - public static void startup() { - ResourcesPlugin.getWorkspace().getSynchronizer().add(TARGET_MAPPINGS); - readLocations(); - } - - public static Site[] getSites() { - return (Site[]) sites.toArray( - new Site[sites.size()]); - } - - public static void addSite(Site site) { - sites.add(site); - save(); - for (Iterator it = listeners.iterator(); it.hasNext();) { - ISiteListener element = (ISiteListener) it.next(); - element.siteAdded(site); - } - } - - /** - * @see TargetProvider#map(IProject) - */ - public static void map(IProject project, Site site, IPath path) throws TeamException { - try { - ISynchronizer s = ResourcesPlugin.getWorkspace().getSynchronizer(); - byte[] mappingBytes = s.getSyncInfo(TARGET_MAPPINGS, project); - if (mappingBytes != null) { - throw new TeamException(Policy.bind("TargetManager.Problems_mapping_project._Project_is_already_mapped._4")); //$NON-NLS-1$ - } - LocationMapping mapping = new LocationMapping(site, path); - s.setSyncInfo( - TARGET_MAPPINGS, - project, - mapping.encode()); - } catch (CoreException e) { - throw new TeamException(Policy.bind("TargetManager.Problems_mapping_project", project.getName()), e); //$NON-NLS-1$ - } catch (IOException e) { - throw new TeamException(Policy.bind("TargetManager.Problems_mapping_project", project.getName()), e); //$NON-NLS-1$ - } - } - - /** - * @see TargetProvider#unmap(IProject) - */ - public static void unmap(IProject project) throws TeamException { - try { - ISynchronizer s = ResourcesPlugin.getWorkspace().getSynchronizer(); - byte[] mappingBytes = s.getSyncInfo(TARGET_MAPPINGS, project); - if (mappingBytes == null) { - throw new TeamException(Policy.bind("TargetManager.unableToUnmap", project.getName()), null); //$NON-NLS-1$ - } else { - TargetProvider provider = getProvider(project); - provider.deregister(project); - s.flushSyncInfo(TARGET_MAPPINGS, project, IResource.DEPTH_ZERO); - } - } catch (CoreException e) { - throw new TeamException(Policy.bind("TargetManager.problemsUnmapping", project.getName()), e); //$NON-NLS-1$ - } - } - - public static TargetProvider getProvider(IProject project) throws TeamException { - try { - ISynchronizer s = ResourcesPlugin.getWorkspace().getSynchronizer(); - byte[] mappingBytes = s.getSyncInfo(TARGET_MAPPINGS, project); - if (mappingBytes == null) { - return null; - } else { - LocationMapping mapping = new LocationMapping(mappingBytes); - Site site = - getSite(mapping.getType(), mapping.getURL()); - if (site != null) { - return site.newProvider(mapping.getPath()); - } - } - return null; - } catch (CoreException e) { - throw new TeamException(Policy.bind("TargetManager.problemsGettingProvider", project.getName()), e); //$NON-NLS-1$ - } catch (IOException e) { - throw new TeamException(Policy.bind("TargetManager.problemsGettingProvider", project.getName()), e); //$NON-NLS-1$ - } - } - - public static Site getSite(String type, URL url) { - return getSite(type, url.toExternalForm()); - } - - public static Site getSite(String type, String urlID) { - for (Iterator it = sites.iterator(); it.hasNext();) { - Site element = (Site) it.next(); - if (element.getType().equals(type) - && element.getURL().toExternalForm().equals(urlID)) { - return element; - } - } - return null; - } - - public static void addSiteListener(ISiteListener listener) { - listeners.add(listener); - } - - public static void removeSiteListener(ISiteListener listener) { - listeners.remove(listener); - } - - private static void readLocations() { - // read saved locations list from disk, only if the file exists - IPath pluginStateLocation = - TeamPlugin.getPlugin().getStateLocation().append( - TARGET_SITES_FILE); - File f = pluginStateLocation.toFile(); - if (f.exists()) { - try { - DataInputStream dis = - new DataInputStream(new FileInputStream(f)); - readLocations(dis); - } catch (IOException e) { - TeamPlugin.log(new Status(Status.ERROR, TeamPlugin.ID, 0, Policy.bind("Config.error"), e)); //$NON-NLS-1$ - } - } - } - - private static void writeLocations() { - // save repositories to disk - IPath pluginStateLocation = TeamPlugin.getPlugin().getStateLocation(); - File tempFile = pluginStateLocation.append(TARGET_SITES_FILE + ".tmp").toFile(); //$NON-NLS-1$ - File stateFile = - pluginStateLocation.append(TARGET_SITES_FILE).toFile(); - try { - DataOutputStream dos = - new DataOutputStream(new FileOutputStream(tempFile)); - writeLocations(dos); - dos.close(); - if (stateFile.exists()) - stateFile.delete(); - boolean renamed = tempFile.renameTo(stateFile); - if (!renamed) { - //todo: log the error - } - } catch (IOException e) { - TeamPlugin.log(new Status(Status.ERROR, TeamPlugin.ID, 0, Policy.bind("Config.error"), e)); //$NON-NLS-1$ - } - } - - private static void save() { - writeLocations(); - } - - private static void readLocations(DataInputStream dis) throws IOException { - int repoCount = dis.readInt(); - for (int i = 0; i < repoCount; i++) { - String id = dis.readUTF(); - ISiteFactory factory = - (ISiteFactory) getSiteFactory(id); - if (factory == null) { - //todo: log error - return; - } - Site site = factory.newSite(new ObjectInputStream(dis)); - sites.add(site); - } - } - - private static void writeLocations(DataOutputStream dos) - throws IOException { - dos.writeInt(sites.size()); - Iterator iter = sites.iterator(); - while (iter.hasNext()) { - Site site = (Site) iter.next(); - dos.writeUTF(site.getType()); - site.writeObject(new ObjectOutputStream(dos)); - } - dos.flush(); - dos.close(); - } - - public static ISiteFactory getSiteFactory(String id) { - TeamPlugin plugin = TeamPlugin.getPlugin(); - if (plugin != null) { - IExtensionPoint extension = - plugin.getDescriptor().getExtensionPoint( - TeamPlugin.TARGETS_EXTENSION); - if (extension != null) { - IExtension[] extensions = extension.getExtensions(); - for (int i = 0; i < extensions.length; i++) { - IConfigurationElement[] configElements = - extensions[i].getConfigurationElements(); - for (int j = 0; j < configElements.length; j++) { - String extensionId = configElements[j].getAttribute("id"); //$NON-NLS-1$ - if (extensionId != null && extensionId.equals(id)) { - try { - return (ISiteFactory) configElements[j].createExecutableExtension("class"); //$NON-NLS-1$ - } catch (CoreException e) { - TeamPlugin.log(e.getStatus()); - return null; - } - } - } - } - } - } - return null; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/target/TargetProvider.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/target/TargetProvider.java deleted file mode 100644 index 7f4aa453b..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/target/TargetProvider.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial API and implementation - ******************************************************************************/ -package org.eclipse.team.core.target; - -import java.net.URL; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.sync.IRemoteResource; - -public abstract class TargetProvider { - /** - * Answers the site which this target is associated with - * @return a printable string - */ - public abstract Site getSite(); - - /** - * Answers the full path where the provider stores/retrieves to/from. - * @return a printable string - */ - public abstract URL getURL(); - - /** - * Updates the local resource to have the same content as the corresponding remote - * resource. Where the local resource does not exist, this method will create it. - * <p> - * If the remote resource is a container (e.g. folder or project) this operation is equivalent - * to getting each non-container member of the remote resource, thereby updating the - * content of existing local members, creating local members to receive new remote resources, - * and deleting local members that no longer have a corresponding remote resource.</p> - * <p> - * Interrupting the method (via the progress monitor) may lead to partial, but consistent, results.</p> - * - * @param resources an array of local resources to update from the corresponding remote - * resources. - * @param progress a progress monitor to indicate the duration of the operation, or - * <code>null</code> if progress reporting is not required. - * @throws TeamException if there is a problem getting one or more of the resources. The - * exception will contain multiple statuses, one for each resource in the <code>resources</code> - * array. - */ - public abstract void get(IResource[] resources, IProgressMonitor progress) throws TeamException; - - /** - * Transfers the content of the local resource to the corresponding remote resource. - * <p> - * If a remote resource does not exist this method creates a new remote resource with the same content - * as the given local resource. The local resource is said to <i>correspond</i> to the new remote resource.</p> - * <p> - * @param resources an array of local resources to be put. - * @param progress a progress monitor to indicate the duration of the operation, or - * <code>null</code> if progress reporting is not required. - * @throws TeanException if there is a problem put'ing one or more of the resources. - * The exception will contain multiple status', one for each resource in the <code>resources</code> - * array. - */ - public abstract void put(IResource[] resources, IProgressMonitor progress) throws TeamException; - - /** - * Returns a remote resource handle at the path of the given local resource. The remote - * resource handles URL will be: - * <blockquote><pre> - * getURL() + resource.getProjectRelativePath() - * </pre></blockquote> - * - * @param resource local resource path to be used to construct the remote handle's path - * @return a handle to a remote resource that may or may not exist - */ - public abstract IRemoteTargetResource getRemoteResourceFor(IResource resource); - - /** - *Returns a remote resource handle at the path of this target provider's URL. - * @return a handle to a remote resource that may or may not exist - */ - public abstract IRemoteTargetResource getRemoteResource(); - - /** - * Replies true if its believed possible to get the given resource. - * This intended to be a relatively quick operation, presumably based on local state of the provider. - */ - public boolean canGet(IResource resource) { - return true; - } - - /** - * Replies true if its believed possible to put the given resource. - * This intended to be a relatively quick operation, presumably based on local state of the provider. - */ - public boolean canPut(IResource resource) { - return true; - } - - /** - * Answers true if the base identifier of the given resource is different to the - * current released state of the resource. - */ - public abstract boolean isOutOfDate(IResource resource); - - /** - * Answer if the local resource currently has a different timestamp to the - * base timestamp for this resource. - */ - public abstract boolean isDirty(IResource resource); - - public abstract void deregister(IProject project); -} diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/Assert.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/Assert.java deleted file mode 100644 index 5b73a8353..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/Assert.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.eclipse.team.internal.core; - -/* - * (c) Copyright IBM Corp. 2000, 2002. - * All Rights Reserved. - */ - -import org.eclipse.team.core.*; - -public final class Assert { - public static class AssertionFailedException extends RuntimeException { - public AssertionFailedException() { - } - public AssertionFailedException(String detail) { - super(Policy.bind("Assert.assertionFailed", detail)); //$NON-NLS-1$ - } - } -/* This class is not intended to be instantiated. */ -private Assert() { -} -/** Asserts that an argument is legal. If the given boolean is - * not <code>true</code>, an <code>IllegalArgumentException</code> - * is thrown. - * - * @param expression the outcode of the check - * @return <code>true</code> if the check passes (does not return - * if the check fails) - * @exception IllegalArgumentException if the legality test failed - */ -public static boolean isLegal(boolean expression) { - return isLegal(expression, ""); //$NON-NLS-1$ -} -/** Asserts that an argument is legal. If the given boolean is - * not <code>true</code>, an <code>IllegalArgumentException</code> - * is thrown. - * The given message is included in that exception, to aid debugging. - * - * @param expression the outcode of the check - * @param message the message to include in the exception - * @return <code>true</code> if the check passes (does not return - * if the check fails) - * @exception IllegalArgumentException if the legality test failed - */ -public static boolean isLegal(boolean expression, String message) { - if (!expression) - throw new IllegalArgumentException(message); - return expression; -} -/** Asserts that the given object is not <code>null</code>. If this - * is not the case, some kind of unchecked exception is thrown. - * - * @param object the value to test - * @exception IllegalArgumentException if the object is <code>null</code> - */ -public static void isNotNull(Object object) { - if (object == null) - throw new AssertionFailedException("null argument"); //$NON-NLS-1$ -} -/** Asserts that the given object is not <code>null</code>. If this - * is not the case, some kind of unchecked exception is thrown. - * The given message is included in that exception, to aid debugging. - * - * @param object the value to test - * @param message the message to include in the exception - * @exception IllegalArgumentException if the object is <code>null</code> - */ -public static void isNotNull(Object object, String message) { - if (object == null) - throw new AssertionFailedException("null argument:" /*non NLS*/ + message); //$NON-NLS-1$ -} -/** Asserts that the given boolean is <code>true</code>. If this - * is not the case, some kind of unchecked exception is thrown. - * - * @param expression the outcode of the check - * @return <code>true</code> if the check passes (does not return - * if the check fails) - */ -public static boolean isTrue(boolean expression) { - return isTrue(expression, ""/*nonNLS*/); //$NON-NLS-1$ -} -/** Asserts that the given boolean is <code>true</code>. If this - * is not the case, some kind of unchecked exception is thrown. - * The given message is included in that exception, to aid debugging. - * - * @param expression the outcode of the check - * @param message the message to include in the exception - * @return <code>true</code> if the check passes (does not return - * if the check fails) - */ -public static boolean isTrue(boolean expression, String message) { - if (!expression) - throw new AssertionFailedException("assert failed:" /*non NLS*/ + message); //$NON-NLS-1$ - return expression; -} -/** - * Indicates that the caller has not implemented the method. - * Usually this is a temporary condition. - */ -public static void notYetImplemented() { -} -} diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/DefaultFileModificationValidator.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/DefaultFileModificationValidator.java deleted file mode 100644 index 7576010e5..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/DefaultFileModificationValidator.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial API and implementation - ******************************************************************************/ -package org.eclipse.team.internal.core; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFileModificationValidator; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.Status; - -public class DefaultFileModificationValidator implements IFileModificationValidator { - private static final Status OK = new Status(Status.OK, TeamPlugin.ID, Status.OK, Policy.bind("FileModificationValidator.ok"), null); //$NON-NLS-1$ - - private IStatus getDefaultStatus(IFile file) { - return file.isReadOnly() - ? new Status(Status.ERROR, TeamPlugin.ID, Status.ERROR, Policy.bind("FileModificationValidator.fileIsReadOnly", file.getFullPath().toString()), null) //$NON-NLS-1$ - : OK; - } - - /** - * @see IFileModificationValidator#validateEdit(IFile[], Object) - */ - public IStatus validateEdit(IFile[] files, Object context) { - if (files.length == 1) { - return getDefaultStatus(files[0]); - } - - IStatus[] stati = new Status[files.length]; - boolean allOK = true; - - for (int i = 0; i < files.length; i++) { - stati[i] = getDefaultStatus(files[i]); - if(! stati[i].isOK()) - allOK = false; - } - - return new MultiStatus(TeamPlugin.ID, - 0, stati, - Policy.bind( - allOK - ? "FileModificationValidator.ok" //$NON-NLS-1$ - : "FileModificationValidator.someReadOnly" ), //$NON-NLS-1$ - null); - } - - /** - * @see IFileModificationValidator#validateSave(IFile) - */ - public IStatus validateSave(IFile file) { - return getDefaultStatus(file); - } -} diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/DefaultMoveDeleteHook.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/DefaultMoveDeleteHook.java deleted file mode 100644 index b35fa8136..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/DefaultMoveDeleteHook.java +++ /dev/null @@ -1,95 +0,0 @@ -package org.eclipse.team.internal.core; - -/* - * (c) Copyright IBM Corp. 2000, 2002. - * All Rights Reserved. - */ - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.resources.team.IMoveDeleteHook; -import org.eclipse.core.resources.team.IResourceTree; -import org.eclipse.core.runtime.IProgressMonitor; - -/** - * A class which provides the default behavior for resource deletions and moves. - * This class can be overridden by providers to change some or all of the behavior - * related to resources deletions or moves. - * - * @see org.eclipse.team.core.ResourceProvider#getMoveDeleteHook() - */ - -public class DefaultMoveDeleteHook implements IMoveDeleteHook { - - /** - * @see IMoveDeleteHook#deleteFile(IResourceTree, IFile, int, IProgressMonitor) - */ - public boolean deleteFile( - IResourceTree tree, - IFile file, - int updateFlags, - IProgressMonitor monitor) { - return false; - } - - /** - * @see IMoveDeleteHook#deleteFolder(IResourceTree, IFolder, int, IProgressMonitor) - */ - public boolean deleteFolder( - IResourceTree tree, - IFolder folder, - int updateFlags, - IProgressMonitor monitor) { - return false; - } - - /** - * @see IMoveDeleteHook#deleteProject(IResourceTree, IProject, int, IProgressMonitor) - */ - public boolean deleteProject( - IResourceTree tree, - IProject project, - int updateFlags, - IProgressMonitor monitor) { - return false; - } - - /** - * @see IMoveDeleteHook#moveFile(IResourceTree, IFile, IFile, int, IProgressMonitor) - */ - public boolean moveFile( - IResourceTree tree, - IFile source, - IFile destination, - int updateFlags, - IProgressMonitor monitor) { - return false; - } - - /** - * @see IMoveDeleteHook#moveFolder(IResourceTree, IFolder, IFolder, int, IProgressMonitor) - */ - public boolean moveFolder( - IResourceTree tree, - IFolder source, - IFolder destination, - int updateFlags, - IProgressMonitor monitor) { - return false; - } - - /** - * @see IMoveDeleteHook#moveProject(IResourceTree, IProject, IProjectDescription, int, IProgressMonitor) - */ - public boolean moveProject( - IResourceTree tree, - IProject source, - IProjectDescription description, - int updateFlags, - IProgressMonitor monitor) { - return false; - } - -} diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/FileModificationValidatorManager.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/FileModificationValidatorManager.java deleted file mode 100644 index 9e5ddc619..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/FileModificationValidatorManager.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.eclipse.team.internal.core; - -/* - * (c) Copyright IBM Corp. 2000, 2002. - * All Rights Reserved. - */ - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFileModificationValidator; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.team.core.RepositoryProvider; - -public class FileModificationValidatorManager implements IFileModificationValidator { - private static final IFileModificationValidator DEFAULT_VALIDATOR = - new DefaultFileModificationValidator(); - - /* - * @see IFileModificationValidator#validateEdit(IFile[], Object) - * For all files, determine which provider. - * Ask each provider once for its files. - * Collect the resulting status' and return a MultiStatus. - */ - public IStatus validateEdit(IFile[] files, Object context) { - ArrayList returnStati = new ArrayList(); - - //map provider to the files under that provider's control - Map providersToFiles = new HashMap(files.length); - - //for each file, determine which provider, map providers to files - for (int i = 0; i < files.length; i++) { - IFile file = files[i]; - RepositoryProvider provider = RepositoryProvider.getProvider(file.getProject()); - - if (!providersToFiles.containsKey(provider)) { - providersToFiles.put(provider, new ArrayList()); - } - - ((ArrayList)providersToFiles.get(provider)).add(file); - } - - Iterator providersIterator = providersToFiles.keySet().iterator(); - - boolean allOK = true; - - //for each provider, validate its files - while(providersIterator.hasNext()) { - RepositoryProvider provider = (RepositoryProvider)providersIterator.next(); - ArrayList filesList = (ArrayList)providersToFiles.get(provider); - IFile[] filesArray = (IFile[])filesList.toArray(new IFile[filesList.size()]); - IFileModificationValidator validator = DEFAULT_VALIDATOR; - - //if no provider or no validator use the default validator - if (provider != null) { - IFileModificationValidator v = provider.getFileModificationValidator(); - if (v != null) validator = v; - } - - IStatus status = validator.validateEdit(filesArray, context); - if(!status.isOK()) - allOK = false; - - returnStati.add(status); - } - - if (returnStati.size() == 1) { - return (IStatus)returnStati.get(0); - } - - return new MultiStatus(TeamPlugin.ID, - 0, - (IStatus[])returnStati.toArray(new IStatus[returnStati.size()]), - Policy.bind( - allOK - ? "FileModificationValidator.ok" //$NON-NLS-1$ - : "FileModificationValidator.editFailed"), //$NON-NLS-1$ - null); //$NON-NLS-1$ - } - - /* - * @see IFileModificationValidator#validateSave(IFile) - */ - public IStatus validateSave(IFile file) { - RepositoryProvider provider = RepositoryProvider.getProvider(file.getProject()); - IFileModificationValidator validator = DEFAULT_VALIDATOR; - - //if no provider or no validator use the default validator - if (provider != null) { - IFileModificationValidator v = provider.getFileModificationValidator(); - if (v != null) validator = v; - } - - return validator.validateSave(file); - } -} diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/MoveDeleteManager.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/MoveDeleteManager.java deleted file mode 100644 index ef1e1eea6..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/MoveDeleteManager.java +++ /dev/null @@ -1,110 +0,0 @@ -package org.eclipse.team.internal.core; - -/* - * (c) Copyright IBM Corp. 2000, 2002. - * All Rights Reserved. - */ - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.team.IMoveDeleteHook; -import org.eclipse.core.resources.team.IResourceTree; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.core.RepositoryProvider; - -public class MoveDeleteManager implements IMoveDeleteHook { - - private static final IMoveDeleteHook DEFAULT_HOOK = new DefaultMoveDeleteHook(); - - private IMoveDeleteHook getHookFor(IResource resource) { - IProject project = resource.getProject(); - RepositoryProvider provider = RepositoryProvider.getProvider(project); - if(provider==null) { - return DEFAULT_HOOK; - } - IMoveDeleteHook hook = provider.getMoveDeleteHook(); - if (hook == null) { - return DEFAULT_HOOK; - } - return hook; - } - - /* - * @see IMoveDeleteHook#deleteFile(IResourceTree, IFile, int, IProgressMonitor) - */ - public boolean deleteFile( - IResourceTree tree, - IFile file, - int updateFlags, - IProgressMonitor monitor) { - - return getHookFor(file).deleteFile(tree, file, updateFlags, monitor); - } - - /* - * @see IMoveDeleteHook#deleteFolder(IResourceTree, IFolder, int, IProgressMonitor) - */ - public boolean deleteFolder( - IResourceTree tree, - IFolder folder, - int updateFlags, - IProgressMonitor monitor) { - - return getHookFor(folder).deleteFolder(tree, folder, updateFlags, monitor); - } - - /* - * @see IMoveDeleteHook#deleteProject(IResourceTree, IProject, int, IProgressMonitor) - */ - public boolean deleteProject( - IResourceTree tree, - IProject project, - int updateFlags, - IProgressMonitor monitor) { - - return getHookFor(project).deleteProject(tree, project, updateFlags, monitor); - } - - /* - * @see IMoveDeleteHook#moveFile(IResourceTree, IFile, IFile, int, IProgressMonitor) - */ - public boolean moveFile( - IResourceTree tree, - IFile source, - IFile destination, - int updateFlags, - IProgressMonitor monitor) { - - return getHookFor(source).moveFile(tree, source, destination, updateFlags, monitor); - } - - /* - * @see IMoveDeleteHook#moveFolder(IResourceTree, IFolder, IFolder, int, IProgressMonitor) - */ - public boolean moveFolder( - IResourceTree tree, - IFolder source, - IFolder destination, - int updateFlags, - IProgressMonitor monitor) { - - return getHookFor(source).moveFolder(tree, source, destination, updateFlags, monitor); - } - - /* - * @see IMoveDeleteHook#moveProject(IResourceTree, IProject, IProjectDescription, int, IProgressMonitor) - */ - public boolean moveProject( - IResourceTree tree, - IProject source, - IProjectDescription description, - int updateFlags, - IProgressMonitor monitor) { - - return getHookFor(source).moveProject(tree, source, description, updateFlags, monitor); - } - -} diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/Policy.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/Policy.java deleted file mode 100644 index 7d63beedb..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/Policy.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial API and implementation - ******************************************************************************/ -package org.eclipse.team.internal.core; - -import java.text.MessageFormat; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.SubProgressMonitor; - -public class Policy { - protected static ResourceBundle bundle = null; - - //debug constants - public static boolean DEBUG_STREAMS = false; - - static { - //init debug options - if (TeamPlugin.getPlugin().isDebugging()) { - DEBUG_STREAMS = "true".equalsIgnoreCase(Platform.getDebugOption(TeamPlugin.ID + "/streams"));//$NON-NLS-1$ //$NON-NLS-2$ - } - } - - /** - * Creates a NLS catalog for the given locale. - */ - public static void localize(String bundleName) { - bundle = ResourceBundle.getBundle(bundleName); - } - - /** - * Lookup the message with the given ID in this catalog and bind its - * substitution locations with the given string. - */ - public static String bind(String id, String binding) { - return bind(id, new String[] { binding }); - } - - /** - * Lookup the message with the given ID in this catalog and bind its - * substitution locations with the given strings. - */ - public static String bind(String id, String binding1, String binding2) { - return bind(id, new String[] { binding1, binding2 }); - } - - /** - * Gets a string from the resource bundle. We don't want to crash because of a missing String. - * Returns the key if not found. - */ - public static String bind(String key) { - try { - return bundle.getString(key); - } catch (MissingResourceException e) { - return key; - } catch (NullPointerException e) { - return "!" + key + "!"; //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - /** - * Gets a string from the resource bundle and binds it with the given arguments. If the key is - * not found, return the key. - */ - public static String bind(String key, Object[] args) { - try { - return MessageFormat.format(bind(key), args); - } catch (MissingResourceException e) { - return key; - } catch (NullPointerException e) { - return "!" + key + "!"; //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - /** - * Progress monitor helpers - */ - public static void checkCanceled(IProgressMonitor monitor) { - if (monitor.isCanceled()) - throw new OperationCanceledException(); - } - public static IProgressMonitor monitorFor(IProgressMonitor monitor) { - if (monitor == null) - return new NullProgressMonitor(); - return monitor; - } - - public static IProgressMonitor subMonitorFor(IProgressMonitor monitor, int ticks) { - if (monitor == null) - return new NullProgressMonitor(); - if (monitor instanceof NullProgressMonitor) - return monitor; - return new SubProgressMonitor(monitor, ticks); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/StringMatcher.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/StringMatcher.java deleted file mode 100644 index 015a2ae15..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/StringMatcher.java +++ /dev/null @@ -1,389 +0,0 @@ -package org.eclipse.team.internal.core; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.util.*; - -/** - * A string pattern matcher, suppporting * and ? wildcards. - * Note: code copied from org.eclipse.jdt.internal.core.util.StringMatcher on April 3, 2001 - * (version 0.1 - 010901H18 [rename jbl]). - */ -public class StringMatcher { - protected String fPattern; - protected int fLength; // pattern length - protected boolean fIgnoreWildCards; - protected boolean fIgnoreCase; - protected boolean fHasLeadingStar; - protected boolean fHasTrailingStar; - protected String fSegments[]; //the given pattern is split into * separated segments - - /* boundary value beyond which we don't need to search in the text */ - protected int fBound = 0; - - - protected static final char fSingleWildCard = '\u0000'; - - public static class Position { - int start; //inclusive - int end; //exclusive - public Position(int start, int end) { - this.start = start; - this.end = end; - } - public int getStart() { - return start; - } - public int getEnd() { - return end; - } - } - /** - * Find the first occurrence of the pattern between <code>start</code)(inclusive) - * and <code>end</code>(exclusive). - * @param <code>text</code>, the String object to search in - * @param <code>start</code>, the starting index of the search range, inclusive - * @param <code>end</code>, the ending index of the search range, exclusive - * @return an <code>StringMatcher.Position</code> object that keeps the starting - * (inclusive) and ending positions (exclusive) of the first occurrence of the - * pattern in the specified range of the text; return null if not found or subtext - * is empty (start==end). A pair of zeros is returned if pattern is empty string - * Note that for pattern like "*abc*" with leading and trailing stars, position of "abc" - * is returned. For a pattern like"*??*" in text "abcdf", (1,3) is returned - */ - - public StringMatcher.Position find(String text, int start, int end) { - if (fPattern == null|| text == null) - throw new IllegalArgumentException(); - - int tlen = text.length(); - if (start < 0) - start = 0; - if (end > tlen) - end = tlen; - if (end < 0 ||start >= end ) - return null; - if (fLength == 0) - return new Position(start, start); - if (fIgnoreWildCards) { - int x = posIn(text, start, end); - if (x < 0) - return null; - return new Position(x, x+fLength); - } - - int segCount = fSegments.length; - if (segCount == 0)//pattern contains only '*'(s) - return new Position (start, end); - - int curPos = start; - int matchStart = -1; - int i; - for (i = 0; i < segCount && curPos < end; ++i) { - String current = fSegments[i]; - int nextMatch = regExpPosIn(text, curPos, end, current); - if (nextMatch < 0 ) - return null; - if(i == 0) - matchStart = nextMatch; - curPos = nextMatch + current.length(); - } - if (i < segCount) - return null; - return new Position(matchStart, curPos); - } - /** - * StringMatcher constructor takes in a String object that is a simple - * pattern which may contain * for 0 and many characters and - * ? for exactly one character. - * - * Literal '*' and '?' characters must be escaped in the pattern - * e.g., "\*" means literal "*", etc. - * - * Escaping any other character (including the escape character itself), - * just results in that character in the pattern. - * e.g., "\a" means "a" and "\\" means "\" - * - * If invoking the StringMatcher with string literals in Java, don't forget - * escape characters are represented by "\\". - * - * @param aPattern the pattern to match text against - * @param ignoreCase if true, case is ignored - * @param ignoreWildCards if true, wild cards and their escape sequences are ignored - * (everything is taken literally). - */ - public StringMatcher(String aPattern, boolean ignoreCase, boolean ignoreWildCards) { - fIgnoreCase = ignoreCase; - fIgnoreWildCards = ignoreWildCards; - fLength = aPattern.length(); - - /* convert case */ - if (fIgnoreCase) { - fPattern = aPattern.toUpperCase(); - } else { - fPattern = aPattern; - } - - if (fIgnoreWildCards) { - parseNoWildCards(); - } else { - parseWildCards(); - } - } - /** - * Given the starting (inclusive) and the ending (exclusive) poisitions in the - * <code>text</code>, determine if the given substring matches with aPattern - * @return true if the specified portion of the text matches the pattern - * @param String <code>text</code>, a String object that contains the substring to match - * @param int <code>start<code> marks the starting position (inclusive) of the substring - * @param int <code>end<code> marks the ending index (exclusive) of the substring - */ - public boolean match(String text, int start, int end) { - if (null == fPattern || null == text) - throw new IllegalArgumentException(); - - if (start >= end) - return false; - - if (fIgnoreWildCards) - return fPattern.regionMatches(fIgnoreCase, 0, text, start, fLength); - int segCount = fSegments.length; - if (segCount == 0)//pattern contains only '*'(s) or empty pattern - return true; - if (start == end) - return fLength == 0; - if (fLength == 0) - return start == end; - - int tlen = text.length(); - if (start < 0) - start = 0; - if (end > tlen) - end = tlen; - - int tCurPos = start; - int bound = end - fBound; - if ( bound < 0) - return false; - int i=0; - String current = fSegments[i]; - int segLength = current.length(); - - /* process first segment */ - if (!fHasLeadingStar){ - if(!regExpRegionMatches(text, start, current, 0, segLength)) { - return false; - } else { - ++i; - tCurPos = tCurPos + segLength; - } - } - - /* process middle segments */ - while ( i < segCount) { - current = fSegments[i]; - int currentMatch; - int k = current.indexOf(fSingleWildCard); - if (k < 0) { - currentMatch = textPosIn(text, tCurPos, end, current); - if (currentMatch < 0) - return false; - } else { - currentMatch = regExpPosIn(text, tCurPos, end, current); - if (currentMatch < 0) - return false; - } - tCurPos = currentMatch + current.length(); - i++; - } - - /* process final segment */ - if (!fHasTrailingStar && tCurPos != end) { - int clen = current.length(); - return regExpRegionMatches(text, end - clen, current, 0, clen); - } - return i == segCount ; - } - /** - * match the given <code>text</code> with the pattern - * @return true if matched eitherwise false - * @param <code>text</code>, a String object - */ - public boolean match(String text) { - return match(text, 0, text.length()); - } - /** - * This method parses the given pattern into segments seperated by wildcard '*' characters. - * Since wildcards are not being used in this case, the pattern consists of a single segment. - */ - private void parseNoWildCards() { - fSegments = new String[1]; - fSegments[0] = fPattern; - fBound = fLength; - } - /** - * This method parses the given pattern into segments seperated by wildcard '*' characters. - * @param p, a String object that is a simple regular expression with * and/or ? - */ - private void parseWildCards() { - if(fPattern.startsWith("*"))//$NON-NLS-1$ - fHasLeadingStar = true; - if(fPattern.endsWith("*")) {//$NON-NLS-1$ - /* make sure it's not an escaped wildcard */ - if (fLength > 1 && fPattern.charAt(fLength - 2) != '\\') { - fHasTrailingStar = true; - } - } - - Vector temp = new Vector(); - - int pos = 0; - StringBuffer buf = new StringBuffer(); - while (pos < fLength) { - char c = fPattern.charAt(pos++); - switch (c) { - case '\\': - if (pos >= fLength) { - buf.append(c); - } else { - char next = fPattern.charAt(pos++); - /* if it's an escape sequence */ - if (next == '*' || next == '?' || next == '\\') { - buf.append(next); - } else { - /* not an escape sequence, just insert literally */ - buf.append(c); - buf.append(next); - } - } - break; - case '*': - if (buf.length() > 0) { - /* new segment */ - temp.addElement(buf.toString()); - fBound += buf.length(); - buf.setLength(0); - } - break; - case '?': - /* append special character representing single match wildcard */ - buf.append(fSingleWildCard); - break; - default: - buf.append(c); - } - } - - /* add last buffer to segment list */ - if (buf.length() > 0) { - temp.addElement(buf.toString()); - fBound += buf.length(); - } - - fSegments = new String[temp.size()]; - temp.copyInto(fSegments); - } - /** - * @param <code>text</code>, a string which contains no wildcard - * @param <code>start</code>, the starting index in the text for search, inclusive - * @param <code>end</code>, the stopping point of search, exclusive - * @return the starting index in the text of the pattern , or -1 if not found - */ - protected int posIn(String text, int start, int end) {//no wild card in pattern - int max = end - fLength; - - if (!fIgnoreCase) { - int i = text.indexOf(fPattern, start); - if (i == -1 || i > max) - return -1; - return i; - } - - for (int i = start; i <= max; ++i) { - if (text.regionMatches(true, i, fPattern, 0, fLength)) - return i; - } - - return -1; - } - /** - * @param <code>text</code>, a simple regular expression that may only contain '?'(s) - * @param <code>start</code>, the starting index in the text for search, inclusive - * @param <code>end</code>, the stopping point of search, exclusive - * @param <code>p</code>, a simple regular expression that may contains '?' - * @param <code>caseIgnored</code>, wether the pattern is not casesensitive - * @return the starting index in the text of the pattern , or -1 if not found - */ - protected int regExpPosIn(String text, int start, int end, String p) { - int plen = p.length(); - - int max = end - plen; - for (int i = start; i <= max; ++i) { - if (regExpRegionMatches(text, i, p, 0, plen)) - return i; - } - return -1; - } - /** - * - * @return boolean - * @param <code>text</code>, a String to match - * @param <code>start</code>, int that indicates the starting index of match, inclusive - * @param <code>end</code> int that indicates the ending index of match, exclusive - * @param <code>p</code>, String, String, a simple regular expression that may contain '?' - * @param <code>ignoreCase</code>, boolean indicating wether code>p</code> is case sensitive - */ - protected boolean regExpRegionMatches(String text, int tStart, String p, int pStart, int plen) { - while (plen-- > 0) { - char tchar = text.charAt(tStart++); - char pchar = p.charAt(pStart++); - - /* process wild cards */ - if (!fIgnoreWildCards) { - /* skip single wild cards */ - if (pchar == fSingleWildCard) { - continue; - } - } - if (pchar == tchar) - continue; - if (fIgnoreCase) { - char tc = Character.toUpperCase(tchar); - if (tc == pchar) - continue; - } - return false; - } - return true; - } - /** - * @param <code>text</code>, the string to match - * @param <code>start</code>, the starting index in the text for search, inclusive - * @param <code>end</code>, the stopping point of search, exclusive - * @param code>p</code>, a string that has no wildcard - * @param <code>ignoreCase</code>, boolean indicating wether code>p</code> is case sensitive - * @return the starting index in the text of the pattern , or -1 if not found - */ - protected int textPosIn(String text, int start, int end, String p) { - - int plen = p.length(); - int max = end - plen; - - if (!fIgnoreCase) { - int i = text.indexOf(p, start); - if (i == -1 || i > max) - return -1; - return i; - } - - for (int i = start; i <= max; ++i) { - if (text.regionMatches(true, i, p, 0, plen)) - return i; - } - - return -1; - } -} diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/TeamPlugin.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/TeamPlugin.java deleted file mode 100644 index 83bb6ff7f..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/TeamPlugin.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial API and implementation - ******************************************************************************/ -package org.eclipse.team.internal.core; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPluginDescriptor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Plugin; -import org.eclipse.core.runtime.Status; -import org.eclipse.team.core.Team; -import org.eclipse.team.core.target.TargetManager; - -/** - * <code>TeamPlugin</code> is the plug-in runtime class for the Team - * resource management plugin. - * <p> - * - * @see Team - * @see RepositoryProvider - * - * @since 2.0 - */ -final public class TeamPlugin extends Plugin { - - // The id of the core team plug-in - public static final String ID = "org.eclipse.team.core"; //$NON-NLS-1$ - - // The id of the providers extension point - public static final String PROVIDER_EXTENSION = "repository-provider-type"; //$NON-NLS-1$ - - // The id of the file types extension point - public static final String FILE_TYPES_EXTENSION = "fileTypes"; //$NON-NLS-1$ - - // The id of the global ignore extension point - public static final String IGNORE_EXTENSION = "ignore"; //$NON-NLS-1$ - // The id of the project set extension point - public static final String PROJECT_SET_EXTENSION = "projectSets"; //$NON-NLS-1$ - // The id of the targets extension point - public static final String TARGETS_EXTENSION = "targets"; //$NON-NLS-1$ - - - // The one and only plug-in instance - private static TeamPlugin plugin; - - /** - * Constructs a plug-in runtime class for the given plug-in descriptor. - */ - public TeamPlugin(IPluginDescriptor pluginDescriptor) { - super(pluginDescriptor); - plugin = this; - } - - /** - * @see Plugin#startup() - */ - public void startup() throws CoreException { - Policy.localize("org.eclipse.team.internal.core.messages"); //$NON-NLS-1$ - Team.startup(); - TargetManager.startup(); - } - - /** - * @see Plugin#shutdown() - */ - public void shutdown() { - Team.shutdown(); - } - - /** - * Returns the Team plug-in. - * - * @return the single instance of this plug-in runtime class - */ - public static TeamPlugin getPlugin() { - return plugin; - } - - /** - * Returns the plug-in's log - */ - public static void log(int severity, String message, Throwable e) { - plugin.getLog().log(new Status(severity, ID, 0, message, e)); - } - - /** - * Returns the plug-in's log - */ - public static void log(IStatus status) { - plugin.getLog().log(status); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/messages.properties b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/messages.properties deleted file mode 100644 index 4694bd864..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/messages.properties +++ /dev/null @@ -1,67 +0,0 @@ - -Assert.assertionFailed=Assertion failed: {0} - -manager.providerAlreadyMapped=Error associating {0} with provider named {1}. The project is already associated with a provider. -manager.errorFlushSync=Error flushing provider mapping information for {0}. -manager.errorDeconfigure=Error deconfiguring provider named {0} from project {1}. -manager.providerTypeInvalid=The provider type is not registered: {0}. -manager.providerExtensionNotFound=TeamPlugin provider extension not found. -manager.providerNoConfigElems=No configuration elements found for extension: {0}. -manager.cannotInstantiateExt=Cannot instantiate extension: {0}. -manager.errorSerialize=Error serializing provider mappings for {0}. -manager.errorUnserializeProvider=Cannot unserialize association of {0} with provider of type: {1}. It is no longer a registered provider type. -manager.errorUnserialize=Error un-serializing provider mappings {0}. -manager.notTeamNature=Error setting nature: {0} is not a registered team nature. -manager.errorSettingNature=Error setting nature {1} on project {0}. -manager.errorRemovingNature=Error removing nature {1} on project {0}. - -manager.badClassType=Error creating validator decorator: bad class type -manager.coreException=Error creating validator decorator: core exception - -FileModificationValidator.someReadOnly=Some files are read-only. -FileModificationValidator.fileIsReadOnly=File {0} is read-only. -FileModificationValidator.editFailed=Files are read-only. -FileModificationValidator.ok=OK - -RepositoryProvider_Error_removing_nature_from_project___1=Error removing nature from project: -RepositoryProvider_Too_many_providers_associated_with_project___2=Too many providers associated with project: -RepositoryProviderTypeduplicate_provider_found_in_plugin.xml___1=duplicate provider found in plugin.xml: -RepositoryProviderTypeRepositoryProvider_assigned_to_the_project_must_be_a_subclass_of_RepositoryProvider___2=RepositoryProvider assigned to the project must be a subclass of RepositoryProvider: -RepositoryProviderTypeRepositoryProvider_not_registered_as_a_nature_id___3=RepositoryProvider not registered as a nature id: - -RepositoryProvider_providerTypeIdNotRegistered=Error configuring the RepositoryProvider the nature id is not registered as a valid RepositoryProviderType id. - -TeamPlugin_setting_global_ignore_7=setting global ignore -TeamPlugin_renaming_21=renaming -TeamPlugin_closing_stream_22=closing stream -TeamPlugin_closing_stream_23=closing stream - -Team.Could_not_delete_state_file_1=Could not delete state file -Team.Could_not_rename_state_file_2=Could not rename state file - -PollingInputStream.readTimeout=Timeout while reading from input stream -PollingInputStream.closeTimeout=Timeout while closing input stream -PollingOutputStream.writeTimeout=Timeout while writing to output stream -PollingOutputStream.closeTimeout=Timeout while closing output stream -TimeoutOutputStream.cannotWriteToStream=Cannot write to output stream - -TargetManager.Problems_mapping_project._Project_is_already_mapped._4=Problems mapping project. Project is already mapped. -TargetManager.Problems_mapping_project=Problems mapping project {0} -TargetManager.unableToUnmap=Unable to unmap project. It wasn't mapped to the location. {0} -TargetManager.problemsUnmapping=Problems unmapping project {0} -TargetManager.problemsGettingProvider=Problems getting default target provider for {0} - -Config.error=Error configuring the provider - -teamStatus.notCheckedOut=Not checked out. -teamStatus.notCheckedIn=Not checked in. -teamStatus.unmanagedResource=Unmanaged resource. -teamStatus.noRemoteResource=Remote resource does not exist. -teamStatus.ioFailed=An IO error occurred. -teamStatus.conflict=A conflict occurred. - -multiStatus.errorsOccurred=Errors occurred. -provider.configuration.missing=Required configuration value missing. -provider.configuration.invalid=Configuration value is invalid. -filetransfer.monitor={0} ({1}K of {2}K bytes) -OK_1=OK diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/simpleAccess/SimpleAccessOperations.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/simpleAccess/SimpleAccessOperations.java deleted file mode 100644 index 8373e0f14..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/simpleAccess/SimpleAccessOperations.java +++ /dev/null @@ -1,269 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial API and implementation - ******************************************************************************/ -package org.eclipse.team.internal.core.simpleAccess; - -import org.eclipse.team.core.*; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; - -/* - * This class represents provisional API. Its here to allow experimentation with 3rd party tools - * calling providers in a repository neutral manner. - * - * A provider is not required to implement this API. - * Implementers, and those who reference it, do so with the awareness that this class may be - * removed or substantially changed at future times without warning. - * - * The <code>SimpleAccessOperations</code> class exposes a basic repository model that - * providers may implement to allow third-party plugins to perform repository operations - * programmatically. For example, a code generation tool may want to get source - * files before generating the code, and check-in the results. If a provider plugin does - * not adhere to the <i>semantics</i> of the <code>SimpleAccessOperations</code> class - * as described, they are free to opt out of implementing it. - * - * @since 2.0 - */ -public interface SimpleAccessOperations { - /* - * Updates the local resource to have the same content as the corresponding remote - * resource. Where the local resource does not exist, this method will create it. - * <p> - * If the remote resource is a container (e.g. folder or project) this operation is equivalent - * to getting each non-container member of the remote resource, thereby updating the - * content of existing local members, creating local members to receive new remote resources, - * and deleting local members that no longer have a corresponding remote resource.</p> - * <p> - * The method is applied to all resources satisfying the depth parameter, described above.</p> - * <p> - * Interrupting the method (via the progress monitor) may lead to partial, but consistent, results.</p> - * - * @param resources an array of local resources to update from the corresponding remote - * resources. - * @param depth the depth to traverse the given resources, taken from <code>IResource</code> - * static constants. - * @param progress a progress monitor to indicate the duration of the operation, or - * <code>null</code> if progress reporting is not required. - * @throws TeamException if there is a problem getting one or more of the resources. The - * exception will contain multiple statuses, one for each resource in the <code>resources</code> - * array. Possible status codes include: - * <ul> - * <li>NO_REMOTE_RESOURCE</li> - * <li>IO_FAILED</li> - * <li>NOT_AUTHORIZED</li> - * <li>UNABLE</li> - * </ul> - */ - public void get(IResource[] resources, int depth, IProgressMonitor progress) throws TeamException; - - /* - * Changes the state of the local resource from checked-in to checked-out and transfers the content - * of the remote resource to the local resource. - * <p> - * Where no corresponding local resource exists in the workspace, one is created (including any - * intermediate parent containers) to receive the contents of the remote resource.</p> - * <p> - * Implementations may optimistically only flag the state change locally and rely on resolving conflicts - * during check-in, or they may pessimistically also checkout or lock the remote resource during a - * local resource checkout to avoid conflicts. The provider API does not subscribe to either model - * and supports each equally.</p> - * <p> - * Where checkout is applied to a resource that is already checked-out the method has no - * effect.</p> - * - * @param resources the array of local resources to be checked-out. - * @param depth the depth to traverse the given resources, taken from <code>IResource</code> - * constants. - * @param progress a progress monitor to indicate the duration of the operation, or - * <code>null</code> if progress reporting is not required. - * @throws TeamProviderException if there is a problem checking-out one or more of the resources. - * The exception will contain multiple statuses, one for each resource in the <code>resources</code> - * array. Possible status codes include: - * <ul> - * <li>NOT_CHECKED_IN</li> - * <li>NO_REMOTE_RESOURCE</li> - * <li>IO_FAILED</li> - * <li>NOT_AUTHORIZED</li> - * <li>UNABLE</li> - * </ul> - * @see checkin(IResource[], int, IProgressMonitor) - */ - public void checkout(IResource[] resources, int depth, IProgressMonitor progress) throws TeamException; - - /* - * Transfers the content of the local resource to the corresponding remote resource, and changes the - * state of the local resource from checked-out to checked-in. - * <p> - * If a remote resource does not exist this method creates a new remote resource with the same content - * as the given local resource. The local resource is said to <i>correspond</i> to the new remote resource.</p> - * <p> - * Where providers deal with stores that check-out or lock resources this method is an opportunity - * to transfer the content and make the corresponding remote check-in or unlock. It is envisaged that - * where the server maintains resource versions, checkin creates a new version of the remote resource.</p> - * <p> - * Note that some providers may <em>require</em> that a resource is checked-out before it can be - * checked-in. However, all providers must support the explicit checking out a resource before checking - * it in (e.g., even if the check out is a no-op).</p> - * - * @param resources an array of local resources to be checked-in. - * @param the depth to traverse the given resources, taken from <code>IResource</code> - * constants. - * @param progress a progress monitor to indicate the duration of the operation, or - * <code>null</code> if progress reporting is not required. - * @throws TeamException if there is a problem checking-in one or more of the resources. - * The exception will contain multiple statuses, one for each resource in the <code>resources</code> - * array. Possible status codes include: - * <ul> - * <li>NOT_CHECKED_OUT</li> - * <li>IO_FAILED</li> - * <li>NOT_AUTHORIZED</li> - * <li>UNABLE</li> - * </ul> - * @see checkout(IResource[], int, IProgressMonitor) - */ - public void checkin(IResource[] resources, int depth, IProgressMonitor progress) throws TeamException; - - /* - * Changes the state of the local resource from checked-out to checked-in without updating the contents - * of the remote resource. - * <p> - * Note that where the provider is a versioning provider, it is envisaged (though not required) that the - * uncheckout operation does not create a new version.</p> - * <p> - * Note also that <code>uncheckout()</code> does not affect the content of the local resource. The - * caller is required to perform a <code>get()</code> to revert the local resource if that is required - * (otherwise the local resource will be left with the changes that were made while the remote resource - * was checked-out. Furthermore, it is valid to call <code>uncheckout()</code> with an - * <code>IResource</code> that does not exist locally.</p> - * - * @param resources an array of the local resources that are to be unchecked-out. - * @param depth the depth to traverse the given resources, taken from <code>IResource</code> - * constants. - * @param progress a progress monitor to indicate the duration of the operation, or - * <code>null</code> if progress reporting is not required. - * @throws TeamProviderException if there is a problem undoing the check-out of one or more of - * the resources. The exception will contain multiple statuses, one for each resource in the - * <code>resources</code> array. Possible status codes include: - * <ul> - * <li>NOT_CHECKED_OUT</li> - * <li>IO_FAILED</li> - * <li>NOT_AUTHORIZED</li> - * <li>UNABLE</li> - * </ul> - * @see checkin(IResource) - * @see uncheckout(IResource) - */ - public void uncheckout(IResource[] resources, int depth, IProgressMonitor progress) throws TeamException; - - /* - * Deletes the remote resource corresponding to the given local resource. - * <p> - * The notion of delete is simply to make the remote resource unavailable. Where the provider - * supports versioning it is not specified whether the delete operation makes the version - * temporarily or forever unavailable, or indeed whether the entire history is made unavailable.</p> - * <p> - * Note that the <code>IResource</code>'s passed as arguments may be non-existant in the - * workbench, the typical case is when such a resource has been received in a core callback.</p> - * <p> - * The resource may be checked-in or checked-out prior to deletion. The local resource is not - * deleted by this method.</p> - * <p> - * Resource deletions are inherently deep.</p> - * - * @param resources the array of resources whose corresponding remote resources are to be deleted. - * @param progress a progress monitor to indicate the duration of the operation, or - * <code>null</code> if progress reporting is not required. - * @throws TeamProviderException if there is a problem deleting one or more of - * the resources. The exception will contain multiple statuses, one for each resource in the - * <code>resources</code> array. Possible status codes include: - * <ul> - * <li>NO_REMOTE_RESOURCE</li> - * <li>IO_FAILED</li> - * <li>NOT_AUTHORIZED</li> - * <li>UNABLE</li> - * </ul> - */ - public void delete(IResource[] resources, IProgressMonitor progress) throws TeamException; - - /* - * Informs the provider that a local resource's name or path has changed. - * <p> - * Some providers, such as versioning providers, may require this information to track the resource - * across name changes.</p> - * <p> - * Note that this method is always called <em>after</em> the local resource has been moved.</p> - * - * @param source the full name of the resource before it was moved. - * @param target the resource that was moved. - * @param progress a progress monitor to indicate the duration of the operation, or - * <code>null</code> if progress reporting is not required. - * @throws TeamProviderException if there is a problem recording the move. The exception will - * contain a single status. Possible status codes are: - * <ul> - * <li>NO_REMOTE_RESOURCE</li> - * <li>IO_FAILED</li> - * <li>NOT_AUTHORIZED</li> - * <li>UNABLE</li> - * </ul> - */ - public void moved(IPath source, IResource target, IProgressMonitor progress) throws TeamException; - - /* - * Implementor's Note: - * The following methods are required to return promptly (i.e., they may be used to determine the state of - * a resource in a UI where long delays are unacceptable). Implementations may cache these values - * and update the cache on an explicit call to #refreshState(). - * - * They are currently listed in the provider API, however, they may be moved to a new or different - * interface in the future to better reflect their UI-orientation. - */ - - /* - * Answers if the remote resource state is checked-out. If the resource has never been checked in this - * method will return <code>true</code>. - * <p> - * It is undefined whether this method tests for a resource being checked out to this workspace - * or any workspace.</p> - * - * @param resource the local resource to test. - * @return <code>true</code> if the resource is checked-out and <code>false</code> if it is not. - * @see checkout(IResource[], int, IProgressMonitor) - */ - public boolean isCheckedOut(IResource resource); - - /* - * Answers whether the resource has a corresponding remote resource. - * <p> - * Before a resource is checked-in, the resource will occur locally but not remotely, and calls to this - * method will return <code>false</code>. Once a local resource is checked in (and assuming the local - * local resource is not moved or the remote resource deleted) there will be a corresponding remote - * resource and this method returns <code>true</code>.</p> - * - * @param resource the local resource to test. - * @return <code>true</code> if the local resource has a corresponding remote resource, - * and <code>false</code> otherwise. - * @see checkin(IResource[], int, IProgressMonitor) - * @see refreshState(IResource[], int, IProgressMonitor) - */ - public boolean hasRemote(IResource resource); - - /* - * Answer if the local resource currently has a different timestamp to the base timestamp - * for this resource. - * - * @param resource the resource to test. - * @return <code>true</code> if the resource has a different modification - * timestamp, and <code>false</code> otherwise. - */ - public boolean isDirty(IResource resource); -}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/streams/CRLFtoLFInputStream.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/streams/CRLFtoLFInputStream.java deleted file mode 100644 index 0719a99c1..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/streams/CRLFtoLFInputStream.java +++ /dev/null @@ -1,155 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial API and implementation - ******************************************************************************/ -package org.eclipse.team.internal.core.streams; - -import java.io.FilterInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InterruptedIOException; - -/** - * Converts CR/LFs in the underlying input stream to LF. - * - * Supports resuming partially completed operations after an InterruptedIOException - * if the underlying stream does. Check the bytesTransferred field to determine how - * much of the operation completed; conversely, at what point to resume. - */ -public class CRLFtoLFInputStream extends FilterInputStream { - private boolean pendingByte = false; - private int lastByte = -1; - - /** - * Creates a new filtered input stream. - * @param in the underlying input stream - */ - public CRLFtoLFInputStream(InputStream in) { - super(in); - } - - /** - * Wraps the underlying stream's method. - * Translates CR/LF sequences to LFs transparently. - * @throws InterruptedIOException if the operation was interrupted before all of the - * bytes specified have been skipped, bytesTransferred will be zero - * @throws IOException if an i/o error occurs - */ - public int read() throws IOException { - if (! pendingByte) { - lastByte = in.read(); // ok if this throws - pendingByte = true; // remember the byte in case we throw an exception later on - } - if (lastByte == '\r') { - lastByte = in.read(); // ok if this throws - if (lastByte != '\n') { - if (lastByte == -1) pendingByte = false; - return '\r'; // leaves the byte pending for later - } - } - pendingByte = false; - return lastByte; - } - - /** - * Wraps the underlying stream's method. - * Translates CR/LF sequences to LFs transparently. - * @throws InterruptedIOException if the operation was interrupted before all of the - * bytes specified have been skipped, bytesTransferred may be non-zero - * @throws IOException if an i/o error occurs - */ - public int read(byte[] buffer, int off, int len) throws IOException { - // handle boundary cases cleanly - if (len == 0) { - return 0; - } else if (len == 1) { - int b = read(); - if (b == -1) return -1; - buffer[off] = (byte) b; - return 1; - } - // read some bytes from the stream - // prefix with pending byte from last read if any - int count = 0; - if (pendingByte) { - buffer[off] = (byte) lastByte; - pendingByte = false; - count = 1; - } - InterruptedIOException iioe = null; - try { - len = in.read(buffer, off + count, len - count); - if (len == -1) { - return (count == 0) ? -1 : count; - } - } catch (InterruptedIOException e) { - len = e.bytesTransferred; - iioe = e; - } - count += len; - // strip out CR's in CR/LF pairs - // pendingByte will be true iff previous byte was a CR - int j = off; - for (int i = off; i < off + count; ++i) { // invariant: j <= i - lastByte = buffer[i]; - if (lastByte == '\r') { - if (pendingByte) { - buffer[j++] = '\r'; // write out orphan CR - } else { - pendingByte = true; - } - } else { - if (pendingByte) { - if (lastByte != '\n') buffer[j++] = '\r'; // if LF, don't write the CR - pendingByte = false; - } - buffer[j++] = (byte) lastByte; - } - } - if (iioe != null) { - iioe.bytesTransferred = j - off; - throw iioe; - } - return j - off; - } - - /** - * Calls read() to skip the specified number of bytes - * @throws InterruptedIOException if the operation was interrupted before all of the - * bytes specified have been skipped, bytesTransferred may be non-zero - * @throws IOException if an i/o error occurs - */ - public long skip(long count) throws IOException { - int actualCount = 0; // assumes count < Integer.MAX_INT - try { - while (count-- > 0 && read() != -1) actualCount++; // skip the specified number of bytes - return actualCount; - } catch (InterruptedIOException e) { - e.bytesTransferred = actualCount; - throw e; - } - } - - /** - * Wraps the underlying stream's method. - * Returns the number of bytes that can be read without blocking; accounts for - * possible translation of CR/LF sequences to LFs in these bytes. - * @throws IOException if an i/o error occurs - */ - public int available() throws IOException { - return in.available() / 2; // we can guarantee at least this amount after contraction - } - - /** - * Mark is not supported by the wrapper even if the underlying stream does, returns false. - */ - public boolean markSupported() { - return false; - } -} diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/streams/LFtoCRLFInputStream.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/streams/LFtoCRLFInputStream.java deleted file mode 100644 index 60e4ba561..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/streams/LFtoCRLFInputStream.java +++ /dev/null @@ -1,146 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial API and implementation - ******************************************************************************/ -package org.eclipse.team.internal.core.streams; - -import java.io.FilterInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InterruptedIOException; - -/** - * Converts LFs in the underlying input stream to CR/LF. - * - * Supports resuming partially completed operations after an InterruptedIOException - * if the underlying stream does. Check the bytesTransferred field to determine how - * much of the operation completed; conversely, at what point to resume. - */ -public class LFtoCRLFInputStream extends FilterInputStream { - private boolean mustReturnLF = false; - - /** - * Creates a new filtered input stream. - * @param in the underlying input stream - */ - public LFtoCRLFInputStream(InputStream in) { - super(in); - } - - /** - * Wraps the underlying stream's method. - * Translates LFs to CR/LF sequences transparently. - * @throws InterruptedIOException if the operation was interrupted before all of the - * bytes specified have been skipped, bytesTransferred will be zero - * @throws IOException if an i/o error occurs - */ - public int read() throws IOException { - if (mustReturnLF) { - mustReturnLF = false; - return '\n'; - } - int b = in.read(); // ok if this throws - if (b == '\n') { - mustReturnLF = true; - b = '\r'; - } - return b; - } - - /** - * Wraps the underlying stream's method. - * Translates LFs to CR/LF sequences transparently. - * @throws InterruptedIOException if the operation was interrupted before all of the - * bytes specified have been skipped, bytesTransferred may be non-zero - * @throws IOException if an i/o error occurs - */ - public int read(byte[] buffer, int off, int len) throws IOException { - // handle boundary cases cleanly - if (len == 0) { - return 0; - } else if (len == 1) { - int b = read(); - if (b == -1) return -1; - buffer[off] = (byte) b; - return 1; - } - // prefix with remembered \n from last read, but don't expand it a second time - int count = 0; - if (mustReturnLF) { - mustReturnLF = false; - buffer[off++] = '\n'; - --len; - count = 1; - if (len < 2) return count; // is there still enough room to expand more? - } - // read some bytes from the stream into the back half of the buffer - // this guarantees that there is always room to expand - len /= 2; - int j = off + len; - InterruptedIOException iioe = null; - try { - len = in.read(buffer, j, len); - if (len == -1) { - return (count == 0) ? -1 : count; - } - } catch (InterruptedIOException e) { - len = e.bytesTransferred; - iioe = e; - } - count += len; - // copy bytes from the middle to the front of the array, expanding LF->CR/LF - while (len-- > 0) { - byte b = buffer[j++]; - if (b == '\n') { - buffer[off++] = '\r'; - count++; - } - buffer[off++] = b; - } - if (iioe != null) { - iioe.bytesTransferred = count; - throw iioe; - } - return count; - } - - /** - * Calls read() to skip the specified number of bytes - * @throws InterruptedIOException if the operation was interrupted before all of the - * bytes specified have been skipped, bytesTransferred may be non-zero - * @throws IOException if an i/o error occurs - */ - public long skip(long count) throws IOException { - int actualCount = 0; // assumes count < Integer.MAX_INT - try { - while (count-- > 0 && read() != -1) actualCount++; // skip the specified number of bytes - return actualCount; - } catch (InterruptedIOException e) { - e.bytesTransferred = actualCount; - throw e; - } - } - - /** - * Wraps the underlying stream's method. - * Returns the number of bytes that can be read without blocking; accounts for - * possible translation of LFs to CR/LF sequences in these bytes. - * @throws IOException if an i/o error occurs - */ - public int available() throws IOException { - return in.available(); // we can guarantee at least this amount after expansion - } - - /** - * Mark is not supported by the wrapper even if the underlying stream does, returns false. - */ - public boolean markSupported() { - return false; - } -} diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/streams/PollingInputStream.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/streams/PollingInputStream.java deleted file mode 100644 index 0bdcbb38e..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/streams/PollingInputStream.java +++ /dev/null @@ -1,163 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial API and implementation - ******************************************************************************/ -package org.eclipse.team.internal.core.streams; - -import java.io.FilterInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InterruptedIOException; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Status; -import org.eclipse.team.internal.core.Policy; -import org.eclipse.team.internal.core.TeamPlugin; - -/** - * Polls a progress monitor periodically and handles timeouts over extended durations. - * For this class to be effective, a high numAttempts should be specified, and the - * underlying stream should time out frequently on reads (every second or so). - * - * Supports resuming partially completed operations after an InterruptedIOException - * if the underlying stream does. Check the bytesTransferred field to determine how - * much of the operation completed; conversely, at what point to resume. - */ -public class PollingInputStream extends FilterInputStream { - private static final boolean DEBUG = Policy.DEBUG_STREAMS; - private int numAttempts; - private IProgressMonitor monitor; - - /** - * Creates a new polling input stream. - * @param in the underlying input stream - * @param numAttempts the number of attempts before issuing an InterruptedIOException, - * if 0, retries indefinitely until canceled - * @param monitor the progress monitor to be polled for cancellation - */ - public PollingInputStream(InputStream in, int numAttempts, IProgressMonitor monitor) { - super(in); - this.numAttempts = numAttempts; - this.monitor = monitor; - } - - /** - * Wraps the underlying stream's method. - * It may be important to wait for an input stream to be closed because it - * holds an implicit lock on a system resoure (such as a file) while it is - * open. Closing a stream may take time if the underlying stream is still - * servicing a previous request. - * @throws OperationCanceledException if the progress monitor is canceled - * @throws InterruptedIOException if the underlying operation times out numAttempts times - * @throws IOException if an i/o error occurs - */ - public void close() throws IOException { - int attempts = 0; - try { - readPendingInput(); - } catch (IOException e) { - // We shouldn't get an exception when we're getting the available input. - // If we do, just log it so we can close. - TeamPlugin.log(new Status(IStatus.ERROR, TeamPlugin.ID, 0, e.getMessage(), e)); - } finally { - for (;;) { - try { - in.close(); - return; - } catch (InterruptedIOException e) { - if (monitor.isCanceled()) throw new OperationCanceledException(); - if (++attempts == numAttempts) - throw new InterruptedIOException(Policy.bind("PollingInputStream.closeTimeout")); //$NON-NLS-1$ - if (DEBUG) System.out.println("close retry=" + attempts); //$NON-NLS-1$ - } - } - } - } - - /** - * Wraps the underlying stream's method. - * @throws OperationCanceledException if the progress monitor is canceled - * @throws InterruptedIOException if the underlying operation times out numAttempts times - * and no data was received, bytesTransferred will be zero - * @throws IOException if an i/o error occurs - */ - public int read() throws IOException { - int attempts = 0; - for (;;) { - if (monitor.isCanceled()) throw new OperationCanceledException(); - try { - return in.read(); - } catch (InterruptedIOException e) { - if (++attempts == numAttempts) - throw new InterruptedIOException(Policy.bind("PollingInputStream.readTimeout")); //$NON-NLS-1$ - if (DEBUG) System.out.println("read retry=" + attempts); //$NON-NLS-1$ - } - } - } - - /** - * Wraps the underlying stream's method. - * @throws OperationCanceledException if the progress monitor is canceled - * @throws InterruptedIOException if the underlying operation times out numAttempts times - * and no data was received, bytesTransferred will be zero - * @throws IOException if an i/o error occurs - */ - public int read(byte[] buffer, int off, int len) throws IOException { - int attempts = 0; - for (;;) { - if (monitor.isCanceled()) throw new OperationCanceledException(); - try { - return in.read(buffer, off, len); - } catch (InterruptedIOException e) { - if (e.bytesTransferred != 0) return e.bytesTransferred; // keep partial transfer - if (++attempts == numAttempts) - throw new InterruptedIOException(Policy.bind("PollingInputStream.readTimeout")); //$NON-NLS-1$ - if (DEBUG) System.out.println("read retry=" + attempts); //$NON-NLS-1$ - } - } - } - - /** - * Wraps the underlying stream's method. - * @throws OperationCanceledException if the progress monitor is canceled - * @throws InterruptedIOException if the underlying operation times out numAttempts times - * and no data was received, bytesTransferred will be zero - * @throws IOException if an i/o error occurs - */ - public long skip(long count) throws IOException { - int attempts = 0; - for (;;) { - if (monitor.isCanceled()) throw new OperationCanceledException(); - try { - return in.skip(count); - } catch (InterruptedIOException e) { - if (e.bytesTransferred != 0) return e.bytesTransferred; // keep partial transfer - if (++attempts == numAttempts) - throw new InterruptedIOException(Policy.bind("PollingInputStream.readTimeout")); //$NON-NLS-1$ - if (DEBUG) System.out.println("read retry=" + attempts); //$NON-NLS-1$ - } - } - } - - /** - * Reads any pending input from the input stream so that - * the stream can savely be closed. - */ - protected void readPendingInput() throws IOException { - byte[] buffer= new byte[2048]; - while (true) { - int available = in.available(); - if (available < 1) break; - if (available > buffer.length) available = buffer.length; - if (in.read(buffer, 0, available) < 1) break; - } - } -} diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/streams/PollingOutputStream.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/streams/PollingOutputStream.java deleted file mode 100644 index 9d0dd4755..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/streams/PollingOutputStream.java +++ /dev/null @@ -1,162 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial API and implementation - ******************************************************************************/ -package org.eclipse.team.internal.core.streams; - -import java.io.FilterOutputStream; -import java.io.IOException; -import java.io.InterruptedIOException; -import java.io.OutputStream; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.team.internal.core.Policy; - -/** - * Polls a progress monitor periodically and handles timeouts over extended durations. - * For this class to be effective, a high numAttempts should be specified, and the - * underlying stream should time out frequently on writes (every second or so). - * - * Supports resuming partially completed operations after an InterruptedIOException - * if the underlying stream does. Check the bytesTransferred field to determine how - * much of the operation completed; conversely, at what point to resume. - */ -public class PollingOutputStream extends FilterOutputStream { - private static final boolean DEBUG = Policy.DEBUG_STREAMS; - private int numAttempts; - private IProgressMonitor monitor; - - /** - * Creates a new polling output stream. - * @param in the underlying output stream - * @param numAttempts the number of attempts before issuing an InterruptedIOException, - * if 0, retries indefinitely until canceled - * @param monitor the progress monitor to be polled for cancellation - */ - public PollingOutputStream(OutputStream out, int numAttempts, IProgressMonitor monitor) { - super(out); - this.numAttempts = numAttempts; - this.monitor = monitor; - } - - /** - * Wraps the underlying stream's method. - * @throws OperationCanceledException if the progress monitor is canceled - * @throws InterruptedIOException if the underlying operation times out numAttempts times - * and no data was sent, bytesTransferred will be zero - * @throws IOException if an i/o error occurs - */ - public void write(int b) throws IOException { - int attempts = 0; - for (;;) { - if (monitor.isCanceled()) throw new OperationCanceledException(); - try { - out.write(b); - return; - } catch (InterruptedIOException e) { - if (++attempts == numAttempts) - throw new InterruptedIOException(Policy.bind("PollingOutputStream.writeTimeout")); //$NON-NLS-1$ - if (DEBUG) System.out.println("write retry=" + attempts); //$NON-NLS-1$ - } - } - } - - /** - * Wraps the underlying stream's method. - * @throws OperationCanceledException if the progress monitor is canceled - * @throws InterruptedIOException if the underlying operation times out numAttempts times, - * bytesTransferred will reflect the number of bytes sent - * @throws IOException if an i/o error occurs - */ - public void write(byte[] buffer, int off, int len) throws IOException { - int count = 0; - int attempts = 0; - for (;;) { - if (monitor.isCanceled()) throw new OperationCanceledException(); - try { - out.write(buffer, off, len); - return; - } catch (InterruptedIOException e) { - int amount = e.bytesTransferred; - if (amount != 0) { // keep partial transfer - len -= amount; - if (len <= 0) return; - off += amount; - count += amount; - attempts = 0; // made some progress, don't time out quite yet - } - if (++attempts == numAttempts) { - e = new InterruptedIOException(Policy.bind("PollingOutputStream.writeTimeout")); //$NON-NLS-1$ - e.bytesTransferred = count; - throw e; - } - if (DEBUG) System.out.println("write retry=" + attempts); //$NON-NLS-1$ - } - } - } - - /** - * Wraps the underlying stream's method. - * @throws OperationCanceledException if the progress monitor is canceled - * @throws InterruptedIOException if the underlying operation times out numAttempts times, - * bytesTransferred will reflect the number of bytes sent - * @throws IOException if an i/o error occurs - */ - public void flush() throws IOException { - int count = 0; - int attempts = 0; - for (;;) { - if (monitor.isCanceled()) throw new OperationCanceledException(); - try { - out.flush(); - return; - } catch (InterruptedIOException e) { - int amount = e.bytesTransferred; - if (amount != 0) { // keep partial transfer - count += amount; - attempts = 0; // made some progress, don't time out quite yet - } - if (++attempts == numAttempts) { - e = new InterruptedIOException(Policy.bind("PollingOutputStream.writeTimeout")); //$NON-NLS-1$ - e.bytesTransferred = count; - throw e; - } - if (DEBUG) System.out.println("write retry=" + attempts); //$NON-NLS-1$ - } - } - } - - /** - * Calls flush() then close() on the underlying stream. - * @throws OperationCanceledException if the progress monitor is canceled - * @throws InterruptedIOException if the underlying operation times out numAttempts times, - * bytesTransferred will reflect the number of bytes sent during the flush() - * @throws IOException if an i/o error occurs - */ - public void close() throws IOException { - int attempts = numAttempts - 1; // fail fast if flush() does times out - try { - out.flush(); - attempts = 0; - } finally { - for (;;) { - try { - out.close(); - return; - } catch (InterruptedIOException e) { - if (monitor.isCanceled()) throw new OperationCanceledException(); - if (++attempts == numAttempts) - throw new InterruptedIOException(Policy.bind("PollingOutputStream.closeTimeout")); //$NON-NLS-1$ - if (DEBUG) System.out.println("close retry=" + attempts); //$NON-NLS-1$ - } - } - } - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/streams/ProgressMonitorInputStream.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/streams/ProgressMonitorInputStream.java deleted file mode 100644 index 4febffd04..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/streams/ProgressMonitorInputStream.java +++ /dev/null @@ -1,140 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial implementation - ******************************************************************************/ -package org.eclipse.team.internal.core.streams; - -import java.io.FilterInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InterruptedIOException; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; - -/** - * Updates a progress monitor as bytes are read from the input stream. - * Also starts a background thread to provide responsive cancellation on read(). - * - * Supports resuming partially completed operations after an InterruptedIOException - * if the underlying stream does. Check the bytesTransferred field to determine how - * much of the operation completed; conversely, at what point to resume. - */ -public abstract class ProgressMonitorInputStream extends FilterInputStream { - private IProgressMonitor monitor; - private int updateIncrement; - private long bytesTotal; - private long bytesRead = 0; - private long lastUpdate = -1; - private long nextUpdate = 0; - - /** - * Creates a progress monitoring input stream. - * @param in the underlying input stream - * @param bytesTotal the number of bytes to read in total (passed to updateMonitor()) - * @param updateIncrement the number of bytes read between updates - * @param monitor the progress monitor - */ - public ProgressMonitorInputStream(InputStream in, long bytesTotal, int updateIncrement, IProgressMonitor monitor) { - super(in); - this.bytesTotal = bytesTotal; - this.updateIncrement = updateIncrement; - this.monitor = monitor; - update(true); - } - - protected abstract void updateMonitor(long bytesRead, long size, IProgressMonitor monitor); - - /** - * Wraps the underlying stream's method. - * Updates the progress monitor to the final number of bytes read. - * @throws IOException if an i/o error occurs - */ - public void close() throws IOException { - try { - in.close(); - } finally { - update(true); - } - } - - /** - * Wraps the underlying stream's method. - * Updates the progress monitor if the next update increment has been reached. - * @throws InterruptedIOException if the operation was interrupted before all of the - * bytes specified have been skipped, bytesTransferred will be zero - * @throws IOException if an i/o error occurs - */ - public int read() throws IOException { - int b = in.read(); - if (b != -1) { - bytesRead += 1; - update(false); - } - return b; - } - - /** - * Wraps the underlying stream's method. - * Updates the progress monitor if the next update increment has been reached. - * @throws InterruptedIOException if the operation was interrupted before all of the - * bytes specified have been skipped, bytesTransferred may be non-zero - * @throws IOException if an i/o error occurs - */ - public int read(byte[] buffer, int offset, int length) throws IOException { - try { - int count = in.read(buffer, offset, length); - if (count != -1) { - bytesRead += count; - update(false); - } - return count; - } catch (InterruptedIOException e) { - bytesRead += e.bytesTransferred; - update(false); - throw e; - } - } - - /** - * Wraps the underlying stream's method. - * Updates the progress monitor if the next update increment has been reached. - * @throws InterruptedIOException if the operation was interrupted before all of the - * bytes specified have been skipped, bytesTransferred may be non-zero - * @throws IOException if an i/o error occurs - */ - public long skip(long amount) throws IOException { - try { - long count = in.skip(amount); - bytesRead += count; - update(false); - return count; - } catch (InterruptedIOException e) { - bytesRead += e.bytesTransferred; - update(false); - throw e; - } - } - - /** - * Mark is not supported by the wrapper even if the underlying stream does, returns false. - */ - public boolean markSupported() { - return false; - } - - private void update(boolean now) { - if (bytesRead >= nextUpdate || now) { - nextUpdate = bytesRead - (bytesRead % updateIncrement); - if (nextUpdate != lastUpdate) updateMonitor(nextUpdate, bytesTotal, monitor); - lastUpdate = nextUpdate; - nextUpdate += updateIncrement; - } - } -} diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/streams/SizeConstrainedInputStream.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/streams/SizeConstrainedInputStream.java deleted file mode 100644 index 2781e8425..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/streams/SizeConstrainedInputStream.java +++ /dev/null @@ -1,138 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial implementation - ******************************************************************************/ -package org.eclipse.team.internal.core.streams; - -import java.io.FilterInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InterruptedIOException; - -import org.eclipse.core.runtime.OperationCanceledException; - -/** - * Simulates a stream that represents only a portion of the underlying stream. - * Will report EOF when this portion has been fully read and prevent further reads. - * The underlying stream is not closed on close(), but the remaining unread input - * may optionally be skip()'d. - * - * Supports resuming partially completed operations after an InterruptedIOException - * if the underlying stream does. Check the bytesTransferred field to determine how - * much of the operation completed; conversely, at what point to resume. - */ -public class SizeConstrainedInputStream extends FilterInputStream { - private boolean discardOnClose; - private long bytesRemaining; - - /** - * Creates a size contrained input stream. - * @param in the underlying input stream, never actually closed by this filter - * @param size the maximum number of bytes of the underlying input stream that - * can be read through this filter - * @param discardOnClose if true, discards remaining unread bytes on close() - */ - public SizeConstrainedInputStream(InputStream in, long size, boolean discardOnClose) { - super(in); - this.bytesRemaining = size; - this.discardOnClose = discardOnClose; - } - - /** - * Prevents further reading from the stream but does not close the underlying stream. - * If discardOnClose, skip()'s over any remaining unread bytes in the constrained region. - * @throws IOException if an i/o error occurs - */ - public void close() throws IOException { - try { - if (discardOnClose) { - while (bytesRemaining != 0 && skip(bytesRemaining) != 0); - } - } catch (OperationCanceledException e) { - // The receiver is likely wrapping a PollingInputStream which could throw - // an OperationCanceledException on a skip. - // Since we're closing, just ignore the cancel and let the caller check the monitor - } finally { - bytesRemaining = 0; - } - } - - /** - * Wraps the underlying stream's method. - * Simulates an end-of-file condition if the end of the constrained region has been reached. - * @throws IOException if an i/o error occurs - */ - public int available() throws IOException { - int amount = in.available(); - if (amount > bytesRemaining) amount = (int) bytesRemaining; - return amount; - } - - /** - * Wraps the underlying stream's method. - * Simulates an end-of-file condition if the end of the constrained region has been reached. - * @throws InterruptedIOException if the operation was interrupted before all of the - * bytes specified have been skipped, bytesTransferred will be zero - * @throws IOException if an i/o error occurs - */ - public int read() throws IOException { - if (bytesRemaining == 0) return -1; - int b = in.read(); - if (b != -1) bytesRemaining -= 1; - return b; - } - - /** - * Wraps the underlying stream's method. - * Simulates an end-of-file condition if the end of the constrained region has been reached. - * @throws InterruptedIOException if the operation was interrupted before all of the - * bytes specified have been skipped, bytesTransferred may be non-zero - * @throws IOException if an i/o error occurs - */ - public int read(byte[] buffer, int offset, int length) throws IOException { - if (length > bytesRemaining) { - if (bytesRemaining == 0) return -1; - length = (int) bytesRemaining; - } - try { - int count = in.read(buffer, offset, length); - if (count != -1) bytesRemaining -= count; - return count; - } catch (InterruptedIOException e) { - bytesRemaining -= e.bytesTransferred; - throw e; - } - } - - /** - * Wraps the underlying stream's method. - * Simulates an end-of-file condition if the end of the constrained region has been reached. - * @throws InterruptedIOException if the operation was interrupted before all of the - * bytes specified have been skipped, bytesTransferred may be non-zero - * @throws IOException if an i/o error occurs - */ - public long skip(long amount) throws IOException { - if (amount > bytesRemaining) amount = bytesRemaining; - try { - long count = in.skip(amount); - bytesRemaining -= count; - return count; - } catch (InterruptedIOException e) { - bytesRemaining -= e.bytesTransferred; - throw e; - } - } - - /** - * Mark is not supported by the wrapper even if the underlying stream does, returns false. - */ - public boolean markSupported() { - return false; - } -} diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/streams/TimeoutInputStream.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/streams/TimeoutInputStream.java deleted file mode 100644 index b82a6134e..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/streams/TimeoutInputStream.java +++ /dev/null @@ -1,277 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial API and implementation - ******************************************************************************/ -package org.eclipse.team.internal.core.streams; - -import java.io.FilterInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InterruptedIOException; - -/** - * Wraps an input stream that blocks indefinitely to simulate timeouts on read(), - * skip(), and close(). The resulting input stream is buffered and supports - * retrying operations that failed due to an InterruptedIOException. - * - * Supports resuming partially completed operations after an InterruptedIOException - * REGARDLESS of whether the underlying stream does unless the underlying stream itself - * generates InterruptedIOExceptions in which case it must also support resuming. - * Check the bytesTransferred field to determine how much of the operation completed; - * conversely, at what point to resume. - */ -public class TimeoutInputStream extends FilterInputStream { - // unsynchronized variables - private final long readTimeout; // read() timeout in millis - private final long closeTimeout; // close() timeout in millis, or -1 - - // requests for the thread (synchronized) - private boolean closeRequested = false; // if true, close requested - - // responses from the thread (synchronized) - private Thread thread; // if null, thread has terminated - private byte[] iobuffer; // circular buffer - private int head = 0; // points to first unread byte - private int length = 0; // number of remaining unread bytes - private IOException ioe = null; // if non-null, contains a pending exception - private boolean waitingForClose = false; // if true, thread is waiting for close() - - /** - * Creates a timeout wrapper for an input stream. - * @param in the underlying input stream - * @param bufferSize the buffer size in bytes; should be large enough to mitigate - * Thread synchronization and context switching overhead - * @param readTimeout the number of milliseconds to block for a read() or skip() before - * throwing an InterruptedIOException; 0 blocks indefinitely - * @param closeTimeout the number of milliseconds to block for a close() before throwing - * an InterruptedIOException; 0 blocks indefinitely, -1 closes the stream in the background - */ - public TimeoutInputStream(InputStream in, int bufferSize, long readTimeout, long closeTimeout) { - super(in); - this.readTimeout = readTimeout; - this.closeTimeout = closeTimeout; - this.iobuffer = new byte[bufferSize]; - thread = new Thread(new Runnable() { - public void run() { - runThread(); - } - }, "TimeoutInputStream");//$NON-NLS-1$ - thread.setDaemon(true); - thread.start(); - } - - /** - * Wraps the underlying stream's method. - * It may be important to wait for a stream to actually be closed because it - * holds an implicit lock on a system resoure (such as a file) while it is - * open. Closing a stream may take time if the underlying stream is still - * servicing a previous request. - * @throws InterruptedIOException if the timeout expired - * @throws IOException if an i/o error occurs - */ - public void close() throws IOException { - Thread oldThread; - synchronized (this) { - if (thread == null) return; - oldThread = thread; - closeRequested = true; - thread.interrupt(); - checkError(); - } - if (closeTimeout == -1) return; - try { - oldThread.join(closeTimeout); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); // we weren't expecting to be interrupted - } - synchronized (this) { - checkError(); - if (thread != null) throw new InterruptedIOException(); - } - } - - /** - * Returns the number of unread bytes in the buffer. - * @throws IOException if an i/o error occurs - */ - public synchronized int available() throws IOException { - if (length == 0) checkError(); - return length > 0 ? length : 0; - } - - /** - * Reads a byte from the stream. - * @throws InterruptedIOException if the timeout expired and no data was received, - * bytesTransferred will be zero - * @throws IOException if an i/o error occurs - */ - public synchronized int read() throws IOException { - if (! syncFill()) return -1; // EOF reached - int b = iobuffer[head++] & 255; - if (head == iobuffer.length) head = 0; - length--; - notify(); - return b; - } - - /** - * Reads multiple bytes from the stream. - * @throws InterruptedIOException if the timeout expired and no data was received, - * bytesTransferred will be zero - * @throws IOException if an i/o error occurs - */ - public synchronized int read(byte[] buffer, int off, int len) throws IOException { - if (! syncFill()) return -1; // EOF reached - int pos = off; - if (len > length) len = length; - while (len-- > 0) { - buffer[pos++] = iobuffer[head++]; - if (head == iobuffer.length) head = 0; - length--; - } - notify(); - return pos - off; - } - - /** - * Skips multiple bytes in the stream. - * @throws InterruptedIOException if the timeout expired before all of the - * bytes specified have been skipped, bytesTransferred may be non-zero - * @throws IOException if an i/o error occurs - */ - public synchronized long skip(long count) throws IOException { - long amount = 0; - try { - do { - if (! syncFill()) break; // EOF reached - int skip = (int) Math.min(count - amount, length); - head = (head + skip) % iobuffer.length; - length -= skip; - amount += skip; - } while (amount < count); - } catch (InterruptedIOException e) { - e.bytesTransferred = (int) amount; // assumes amount < Integer.MAX_INT - throw e; - } - notify(); - return amount; - } - - /** - * Mark is not supported by the wrapper even if the underlying stream does, returns false. - */ - public boolean markSupported() { - return false; - } - - /** - * Waits for the buffer to fill if it is empty and the stream has not reached EOF. - * @return true if bytes are available, false if EOF has been reached - * @throws InterruptedIOException if EOF not reached but no bytes are available - */ - private boolean syncFill() throws IOException { - if (length != 0) return true; - checkError(); // check errors only after we have read all remaining bytes - if (waitingForClose) return false; - notify(); - try { - wait(readTimeout); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); // we weren't expecting to be interrupted - } - if (length != 0) return true; - checkError(); // check errors only after we have read all remaining bytes - if (waitingForClose) return false; - throw new InterruptedIOException(); - } - - /** - * If an exception is pending, throws it. - */ - private void checkError() throws IOException { - if (ioe != null) { - IOException e = ioe; - ioe = null; - throw e; - } - } - - /** - * Runs the thread in the background. - */ - private void runThread() { - try { - readUntilDone(); - } catch (IOException e) { - synchronized (this) { ioe = e; } - } finally { - waitUntilClosed(); - try { - in.close(); - } catch (IOException e) { - synchronized (this) { ioe = e; } - } finally { - synchronized (this) { - thread = null; - notify(); - } - } - } - } - - /** - * Waits until we have been requested to close the stream. - */ - private synchronized void waitUntilClosed() { - waitingForClose = true; - notify(); - while (! closeRequested) { - try { - wait(); - } catch (InterruptedException e) { - closeRequested = true; // alternate quit signal - } - } - } - - /** - * Reads bytes into the buffer until EOF, closed, or error. - */ - private void readUntilDone() throws IOException { - for (;;) { - int off, len; - synchronized (this) { - for (;;) { - if (closeRequested) return; // quit signal - if (length != iobuffer.length) break; - try { - wait(); - } catch (InterruptedException e) { - closeRequested = true; // alternate quit signal - } - } - off = (head + length) % iobuffer.length; - len = ((head > off) ? head : iobuffer.length) - off; - } - int count; - try { - // the i/o operation might block without releasing the lock, - // so we do this outside of the synchronized block - count = in.read(iobuffer, off, len); - if (count == -1) return; // EOF encountered - } catch (InterruptedIOException e) { - count = e.bytesTransferred; // keep partial transfer - } - synchronized (this) { - length += count; - notify(); - } - } - } -} diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/streams/TimeoutOutputStream.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/streams/TimeoutOutputStream.java deleted file mode 100644 index 99a91fdf1..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/streams/TimeoutOutputStream.java +++ /dev/null @@ -1,280 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial API and implementation - ******************************************************************************/ -package org.eclipse.team.internal.core.streams; - -import java.io.FilterOutputStream; -import java.io.IOException; -import java.io.InterruptedIOException; -import java.io.OutputStream; - -import org.eclipse.team.internal.core.Policy; - -/** - * Wraps an output stream that blocks indefinitely to simulate timeouts on write(), - * flush(), and close(). The resulting output stream is buffered and supports - * retrying operations that failed due to an InterruptedIOException. - * - * Supports resuming partially completed operations after an InterruptedIOException - * REGARDLESS of whether the underlying stream does unless the underlying stream itself - * generates InterruptedIOExceptions in which case it must also support resuming. - * Check the bytesTransferred field to determine how much of the operation completed; - * conversely, at what point to resume. - */ -public class TimeoutOutputStream extends FilterOutputStream { - // unsynchronized variables - private final long writeTimeout; // write() timeout in millis - private final long closeTimeout; // close() timeout in millis, or -1 - - // requests for the thread (synchronized) - private byte[] iobuffer; // circular buffer - private int head = 0; // points to first unwritten byte - private int length = 0; // number of remaining unwritten bytes - private boolean closeRequested = false; // if true, close requested - private boolean flushRequested = false; // if true, flush requested - - // responses from the thread (synchronized) - private Thread thread; - private boolean waitingForClose = false; // if true, the thread is waiting for close() - private IOException ioe = null; - - /** - * Creates a timeout wrapper for an output stream. - * @param out the underlying input stream - * @param bufferSize the buffer size in bytes; should be large enough to mitigate - * Thread synchronization and context switching overhead - * @param writeTimeout the number of milliseconds to block for a write() or flush() before - * throwing an InterruptedIOException; 0 blocks indefinitely - * @param closeTimeout the number of milliseconds to block for a close() before throwing - * an InterruptedIOException; 0 blocks indefinitely, -1 closes the stream in the background - */ - public TimeoutOutputStream(OutputStream out, int bufferSize, long writeTimeout, long closeTimeout) { - super(out); - this.writeTimeout = writeTimeout; - this.closeTimeout = closeTimeout; - this.iobuffer = new byte[bufferSize]; - thread = new Thread(new Runnable() { - public void run() { - runThread(); - } - }, "TimeoutOutputStream");//$NON-NLS-1$ - thread.setDaemon(true); - thread.start(); - } - - /** - * Wraps the underlying stream's method. - * It may be important to wait for a stream to actually be closed because it - * holds an implicit lock on a system resoure (such as a file) while it is - * open. Closing a stream may take time if the underlying stream is still - * servicing a previous request. - * @throws InterruptedIOException if the timeout expired, bytesTransferred will - * reflect the number of bytes flushed from the buffer - * @throws IOException if an i/o error occurs - */ - public void close() throws IOException { - Thread oldThread; - synchronized (this) { - if (thread == null) return; - oldThread = thread; - closeRequested = true; - thread.interrupt(); - checkError(); - } - if (closeTimeout == -1) return; - try { - oldThread.join(closeTimeout); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); // we weren't expecting to be interrupted - } - synchronized (this) { - checkError(); - if (thread != null) throw new InterruptedIOException(); - } - } - - /** - * Writes a byte to the stream. - * @throws InterruptedIOException if the timeout expired and no data was sent, - * bytesTransferred will be zero - * @throws IOException if an i/o error occurs - */ - public synchronized void write(int b) throws IOException { - syncCommit(true); - iobuffer[(head + length) % iobuffer.length] = (byte) b; - length++; - notify(); - } - - /** - * Writes multiple bytes to the stream. - * @throws InterruptedIOException if the timeout expired, bytesTransferred will - * reflect the number of bytes sent - * @throws IOException if an i/o error occurs - */ - public synchronized void write(byte[] buffer, int off, int len) throws IOException { - int amount = 0; - try { - do { - syncCommit(true); - while (amount < len && length != iobuffer.length) { - iobuffer[(head + length) % iobuffer.length] = buffer[off++]; - length++; - amount++; - } - } while (amount < len); - } catch (InterruptedIOException e) { - e.bytesTransferred = amount; - throw e; - } - notify(); - } - - /** - * Flushes the stream. - * @throws InterruptedIOException if the timeout expired, bytesTransferred will - * reflect the number of bytes flushed from the buffer - * @throws IOException if an i/o error occurs - */ - public synchronized void flush() throws IOException { - int oldLength = length; - flushRequested = true; - try { - syncCommit(false); - } catch (InterruptedIOException e) { - e.bytesTransferred = oldLength - length; - throw e; - } - notify(); - } - - /** - * Waits for the buffer to drain if it is full. - * @param partial if true, waits until the buffer is partially empty, else drains it entirely - * @throws InterruptedIOException if the buffer could not be drained as requested - */ - private void syncCommit(boolean partial) throws IOException { - checkError(); // check errors before allowing the addition of new bytes - if (partial && length != iobuffer.length || length == 0) return; - if (waitingForClose) throw new IOException(Policy.bind("TimeoutOutputStream.cannotWriteToStream")); //$NON-NLS-1$ - notify(); - try { - wait(writeTimeout); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); // we weren't expecting to be interrupted - } - checkError(); // check errors before allowing the addition of new bytes - if (partial && length != iobuffer.length || length == 0) return; - throw new InterruptedIOException(); - } - - /** - * If an exception is pending, throws it. - */ - private void checkError() throws IOException { - if (ioe != null) { - IOException e = ioe; - ioe = null; - throw e; - } - } - - /** - * Runs the thread in the background. - */ - private void runThread() { - try { - writeUntilDone(); - } catch (IOException e) { - synchronized (this) { ioe = e; } - } finally { - waitUntilClosed(); - try { - out.close(); - } catch (IOException e) { - synchronized (this) { ioe = e; } - } finally { - synchronized (this) { - thread = null; - notify(); - } - } - } - } - - /** - * Waits until we have been requested to close the stream. - */ - private synchronized void waitUntilClosed() { - waitingForClose = true; - notify(); - while (! closeRequested) { - try { - wait(); - } catch (InterruptedException e) { - closeRequested = true; // alternate quit signal - } - } - } - - /** - * Writes bytes from the buffer until closed and buffer is empty - */ - private void writeUntilDone() throws IOException { - int bytesUntilFlush = -1; // if > 0, then we will flush after that many bytes have been written - for (;;) { - int off, len; - synchronized (this) { - for (;;) { - if (closeRequested && length == 0) return; // quit signal - if (length != 0 || flushRequested) break; - try { - wait(); - } catch (InterruptedException e) { - closeRequested = true; // alternate quit signal - } - } - off = head; - len = iobuffer.length - head; - if (len > length) len = length; - if (flushRequested && bytesUntilFlush < 0) { - flushRequested = false; - bytesUntilFlush = length; - } - } - if (len != 0) { - // write out all remaining bytes from the buffer before flushing - try { - // the i/o operation might block without releasing the lock, - // so we do this outside of the synchronized block - out.write(iobuffer, off, len); - } catch (InterruptedIOException e) { - len = e.bytesTransferred; - } - synchronized (this) { - head = (head + len) % iobuffer.length; - length -= len; - notify(); - } - } - if (bytesUntilFlush >= 0) { - bytesUntilFlush -= len; - if (bytesUntilFlush <= 0) { - // flush the buffer now - try { - out.flush(); - } catch (InterruptedIOException e) { - } - bytesUntilFlush = -1; // might have been 0 - } - } - } - } -} diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/target/BaseIdentifierNotInitializedException.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/target/BaseIdentifierNotInitializedException.java deleted file mode 100644 index be6b5cc7f..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/target/BaseIdentifierNotInitializedException.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial implementation - ******************************************************************************/ -package org.eclipse.team.internal.core.target; - -public class BaseIdentifierNotInitializedException extends Exception { - /** - * Default constructor for a <code>TeamProviderException</code>. - */ - public BaseIdentifierNotInitializedException() { - super(); - } - - /** - * Constructor for a <code>TeamProviderException</code> that takes - * a string description of the cause of the exception. - * - * @param message a message describing the cause of the exception. - */ - public BaseIdentifierNotInitializedException(String message) { - super(message); - } -} - diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/target/ITeamStatusConstants.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/target/ITeamStatusConstants.java deleted file mode 100644 index e6500a226..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/target/ITeamStatusConstants.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial implementation - ******************************************************************************/ -package org.eclipse.team.internal.core.target; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.internal.core.Policy; -import org.eclipse.team.internal.core.TeamPlugin; - -public interface ITeamStatusConstants { - - public static final IStatus OK_STATUS = - new Status(IStatus.OK, TeamPlugin.ID, TeamException.OK, Policy.bind("OK_1"), null); //$NON-NLS-1$ - - public static final IStatus NOT_CHECKED_OUT_STATUS = - new Status( - IStatus.ERROR, - TeamPlugin.ID, - TeamException.NOT_CHECKED_OUT, - Policy.bind("teamStatus.notCheckedOut"), //$NON-NLS-1$ - null); - - public static final IStatus NOT_CHECKED_IN_STATUS = - new Status( - IStatus.ERROR, - TeamPlugin.ID, - TeamException.NOT_CHECKED_IN, - Policy.bind("teamStatus.notCheckedIn"), //$NON-NLS-1$ - null); - - public static final IStatus NO_REMOTE_RESOURCE_STATUS = - new Status( - IStatus.ERROR, - TeamPlugin.ID, - TeamException.NO_REMOTE_RESOURCE, - Policy.bind("teamStatus.noRemoteResource"), //$NON-NLS-1$ - null); - - public static final IStatus IO_FAILED_STATUS = - new Status( - IStatus.ERROR, - TeamPlugin.ID, - TeamException.IO_FAILED, - Policy.bind("teamStatus.ioFailed"), //$NON-NLS-1$ - null); - - public static final IStatus CONFLICT_STATUS = - new Status( - IStatus.ERROR, - TeamPlugin.ID, - TeamException.CONFLICT, - Policy.bind("teamStatus.conflict"), //$NON-NLS-1$ - null); - - public static final IStatus REQUIRED_CONFIGURATION_MISSING = - new Status( - IStatus.ERROR, - TeamPlugin.ID, - -100, - Policy.bind("provider.configuration.missing"), //$NON-NLS-1$ - null); - - public static final IStatus INVALID_CONFIGURATION = - new Status( - IStatus.ERROR, - TeamPlugin.ID, - -101, - Policy.bind("provider.configuration.invalid"), //$NON-NLS-1$ - null); -}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/target/LocationMapping.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/target/LocationMapping.java deleted file mode 100644 index 834777b8f..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/target/LocationMapping.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial implementation - ******************************************************************************/ -package org.eclipse.team.internal.core.target; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.net.URL; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.team.core.target.Site; - -public class LocationMapping { - - private final long SERIAL_ID = 1; - - private String type; - private URL url; - private IPath path; - - public LocationMapping(Site site, IPath path) { - this.type = site.getType(); - this.url = site.getURL(); - this.path = path; - } - - public LocationMapping(String type, URL url, IPath path) { - this.type = type; - this.url = url; - this.path = path; - } - - public LocationMapping(byte[] bytes) throws IOException { - ByteArrayInputStream bis = new ByteArrayInputStream(bytes); - DataInputStream is = new DataInputStream(bis); - long id = is.readLong(); - this.type = is.readUTF(); - this.url = new URL(is.readUTF()); - this.path = new Path(is.readUTF()); - } - - - /** - * Gets the type. - * @return Returns a String - */ - public String getType() { - return type; - } - - /** - * Gets the locationId. - * @return Returns a String - */ - public URL getURL() { - return url; - } - - /** - * @see Object#equals(Object) - */ - public boolean equals(Object other) { - if(this == other) return true; - if(! (other instanceof LocationMapping)) return false; - LocationMapping location = (LocationMapping)other; - return getType().equals(location.getType()) && - getURL().equals(location.getURL()) && - getPath().equals(location.getPath()); - } - /** - * Gets the path. - * @return Returns a IPath - */ - public IPath getPath() { - return path; - } - - - public byte[] encode() throws IOException { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - DataOutputStream os = new DataOutputStream(bos); - os.writeLong(SERIAL_ID); - os.writeUTF(getType()); - os.writeUTF(getURL().toExternalForm()); - os.writeUTF(getPath().toString()); - return bos.toByteArray(); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/target/ResourceState.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/target/ResourceState.java deleted file mode 100644 index ef182c0a1..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/target/ResourceState.java +++ /dev/null @@ -1,453 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial implementation - ******************************************************************************/ -package org.eclipse.team.internal.core.target; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.IOException; -import java.net.URL; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.target.Site; - -/** - * This abstract class implements the state of a local and corresponding remote resource, - * and behavior of those resources. - * <p> - * Common state for all 'managed' resources includes: - * <ul> - * <li>the local resource and corresponding remote resource objects</li> - * <li>the timestamp of the local resource as it was last in synch with the provider</li> - * <li>an identifier for the remote resource as it was last in synch with the provider</li> - */ -public abstract class ResourceState { - - /* - * Serialization format identifier. - * see toBytes() and fromBytes() - */ - private static final int BYTES_FORMAT = 0; - - /* - * These constants are used to indicate uninitialized values for the local - * base timestamp and remote base identifier. - */ - protected static final long EMPTY_LOCALBASETS = -1L; - protected static final String EMPTY_REMOTEBASEID = "Undefined:"; //$NON-NLS-1$ - - /* - * The base state of the resource. The 'base' is the state of the resource - * state that was fetched from (or put in) the provider. - */ - protected long localBaseTimestamp = EMPTY_LOCALBASETS; - protected String remoteBaseIdentifier = EMPTY_REMOTEBASEID; - - protected boolean checkedOut = true; - - /* - * This is the local resource that the receiver represents. It is initialized by - * the constructor. (The remote resource is maintained by specific subclasses - * as it is type-dependent.) - */ - protected IResource localResource; - - protected QualifiedName stateKey = new QualifiedName("org.eclipse.team.target", "state_info"); //$NON-NLS-1$ //$NON-NLS-2$ - - protected URL rootUrl; - - /** - * Constructor for a resource state given a local resource. - * Remember which local resource this state represents. - * - * @param localResource the local part of a synchronized pair of resources. - */ - public ResourceState(IResource localResource, URL rootUrl) { - super(); - this.rootUrl = rootUrl; - SynchronizedTargetProvider.getSynchronizer().add(stateKey); - this.localResource = localResource; - } - - /** - * Get the timestamp that represents the base state of the local resource, that is - * the state that the local resource had when it was initially fetched from the repository. - * - * @return the timestamp of the local state of the resource (as reported by - * java.io.File.getLastModified()) at the point the resource was downloaded to the - * workspace. - * @throws BaseIdentifierNotInitializedException if the resource has not yet been - * downloaded. - */ - public long getLocalBaseTimestamp() - throws BaseIdentifierNotInitializedException { - if (localBaseTimestamp == EMPTY_LOCALBASETS) - throw new BaseIdentifierNotInitializedException(); - return localBaseTimestamp; - } - - - /** - * Get the identifier that represents the base state of the remote resource, that is - * the state of the remote resource when it was fetched as the base state of the - * local resource. - * <p> - * In general, repositories have arbitrary ways to distinguish resource states. - * The result should only be used for equality comparison, there should be no - * ordering or other information implied from the value returned. For example, - * the value may be a version identifier, timestamp, ETag, etc. To ensure - * schemes do not inadvertantly test equal it is recommended that the identifier - * be a URI where the scheme denotes the value type, - * e.g., date-rfc1123:Fri, 16 Nov 2001 06:25:24 GMT</p> - * - * @return an opaque identifier to the base state of the resource in the provider. - * @throws BaseIdentifierNotInitializedException if the resource has not yet been - * downloaded. - */ - public String getRemoteBaseIdentifier() - throws BaseIdentifierNotInitializedException { - if (remoteBaseIdentifier.equals(EMPTY_REMOTEBASEID)) - throw new BaseIdentifierNotInitializedException(); - return remoteBaseIdentifier; - } - - - /** - * Get the identifier that represents the released state of the resource, - * that is the state that it currently has in the repository. - * <p> - * In general, repositories have arbitrary ways to distinguish resource states. - * The result should only be used for equality comparison, there should be no - * ordering or other information implied from the value returned. For example, - * the value may be a version identifier, timestamp, ETag, etc. To ensure - * schemes do not inadvertantly test equal it is recommended that the identifier - * be a URI where the scheme denotes the value type, - * e.g., date-rfc1123:Fri, 16 Nov 2001 06:25:24 GMT</p> - * - * @param progress a progress monitor to indicate the duration of the operation, or - * <code>null</code> if progress reporting is not required. - * @return an opaque identifier to the current released state of the resource in - * the provider. - * @throws TeamException if there is a problem getting the released state - * identifier from the provider. Valid exception status codes include: - * <ul> - * <li>IO_FAILED</li> - * <li>NO_REMOTE_RESOURCE</li> - * </ul></p> - */ - public abstract String getReleasedIdentifier() throws TeamException; - - /** - * Check out the receiver. - * - * @see ITeamProvider#checkout(IResource[], int, IProgressMonitor) - */ - public IStatus checkout(IProgressMonitor progress) { - // Not going to allow branching. - if (isOutOfDate()) - return ITeamStatusConstants.CONFLICT_STATUS; - - // Sanity check. - if (!hasRemote()) - return ITeamStatusConstants.NO_REMOTE_RESOURCE_STATUS; - - // Legally, the resource must be checked in before it can be checked out. - if (isCheckedOut()) - return ITeamStatusConstants.NOT_CHECKED_IN_STATUS; - - // Do the provider specific action for check-out. - return basicCheckout(progress); - } - - /** - * A basic checkout is provider specific. - * Unless overridden, work in an optimistic mode. - */ - protected IStatus basicCheckout(IProgressMonitor progress) { - checkedOut = true; - return ITeamStatusConstants.OK_STATUS; - } - - /** - * Check in the receiver. - * - * @see ITeamProvider#checkin(IResource[], int, IProgressMonitor) - */ - public IStatus checkin(IProgressMonitor progress) { - // The resource must be checked out before it can be checked in. - if (!isCheckedOut()) - return ITeamStatusConstants.NOT_CHECKED_OUT_STATUS; - - // Check to see if we can do this without conflict. - if (isOutOfDate()) - return ITeamStatusConstants.CONFLICT_STATUS; - - // Copy from the local resource to the repository. - IStatus uploadStatus = upload(progress); - if (uploadStatus.isOK()) - checkedOut = false; - - return uploadStatus; - } - - /** - * Uncheckout the receiver. - * - * @see ITeamProvider#uncheckout(IResource[], int, IProgressMonitor) - */ - public IStatus uncheckout(IProgressMonitor progress) { - // Has to be checked-out before it can be reversed. - if (!isCheckedOut()) - return ITeamStatusConstants.NOT_CHECKED_OUT_STATUS; - - // Nothing interesting to do since the API spec. requires that we do not reverse - // any local changes. - checkedOut = false; - return ITeamStatusConstants.OK_STATUS; - } - - /** - * Answer whether the receiver is checked out or not. - * <p> - * Note that this is a quick operation that will be called from the UI, so providers are required - * to cache information that is expensive to compute. Where the cache may get stale users - * have the opportunity to force a refresh using ITeamProvider.refreshState(). - * - * @return <code>true</code> if the receiver is checked in, and <code>false</code> - * if it is not. - * @see ITeamProvider#isCheckedOut(IResource) - * @see ITeamProvider#refreshState(IResource[], int, IProgressMonitor) - */ - public boolean isCheckedOut() { - return checkedOut; - } - - /** - * Answer if the local resource currently has a different timestamp to the - * base timestamp for this resource. - * - * @param resource the resource to test. - * @return <code>true</code> if the resource has a different modification - * timestamp, and <code>false</code> otherwise. - * @see ITeamProvider#isDirty(IResource) - */ - public boolean isDirty(IResource resource) { - if (!hasLocal()) - return false; // by API definition. - if (localBaseTimestamp == EMPTY_LOCALBASETS) - return false; // by API definition. - return localBaseTimestamp != resource.getModificationStamp(); - } - - /** - * Answers true if the base identifier of the given resource is different to the - * current released state of the resource. - */ - public boolean isOutOfDate() { - if (remoteBaseIdentifier.equals(EMPTY_REMOTEBASEID)) - return false; // by definition. - - String releasedIdentifier = null; - try { - releasedIdentifier = getReleasedIdentifier(); - } catch (TeamException exception) { - // XXX This exception should be propogated out to the caller, requires an API change. - throw new RuntimeException(exception.getMessage()); - } - return !remoteBaseIdentifier.equals(releasedIdentifier); - } - - /** - * Download the remote resource represented by the receiver state to the location - * represented by the local resource (i.e., resource.getLocation().toFile()). - * This copies from the provider to the workspace, <em>and</em> sets the local - * base timestamp and remote base identifier. - * The provider may (and should wherever possible) optimize the case where it - * knows the local resource is identical to the remote resource. - */ - public abstract IStatus download(IProgressMonitor progress); - - /** - * Upload the resource represented by the local resource to the remote - * resource represented by the receiver. This copies from the workspace to - * the provider <em>and</em> sets the local base timestamp and remote base - * identifier. - */ - public abstract IStatus upload(IProgressMonitor progress); - - /** - * Delete the remote resource. - */ - public abstract IStatus delete(IProgressMonitor progress); - - /** - * Answer if the remote resource exists. - */ - public abstract boolean hasRemote(); - - /** - * Answer the type of the remote resource (if it exists). - * The type should correspond to the IResource enumerated types. - */ - public abstract int getRemoteType(); - - /** - * Answer the array of resource states for each member of the receiver. - * If the receiver has no members (or is incapable of having members) - * answer an empty array. - */ - public abstract ResourceState[] getRemoteChildren() throws TeamException; - - /** - */ - public IResource getLocal() { - return localResource; - } - - /** - * Get the file underlying the local resource. - */ - protected File getLocalFile() { - return localResource.getLocation().toFile(); - } - - /** - * Answer if the local resource exists. - */ - public boolean hasLocal() { - return localResource.exists(); - } - - /** - * Initializes the resource state instance from the given serialized state. - * The format of the serialized state is that produced by <code>toBytes()</code>. - * - * @param bytes the serialized resource state. - */ - public final void loadState() { - try { - byte[] storedState = - SynchronizedTargetProvider.getSynchronizer().getSyncInfo(stateKey, localResource); - if (storedState != null) - fromBytes(storedState); - } catch (CoreException e) { - // Problem loading the stored state. - e.printStackTrace(); - throw new RuntimeException(); - } - } - - /** - * Initializes the resource state instance from the given serialized state. - * The format of the serialized state is that produced by <code>toBytes()</code>. - * - * @param bytes the serialized resource state. - */ - protected void fromBytes(byte[] bytes) { - try { - DataInputStream dataStream = - new DataInputStream(new ByteArrayInputStream(bytes)); - if (BYTES_FORMAT != dataStream.readByte()) - return; - - // Restore common resource state values. - remoteBaseIdentifier = dataStream.readUTF(); - localBaseTimestamp = dataStream.readLong(); - - } catch (IOException e) { - // Problem parsing the stored state. - e.printStackTrace(); - throw new RuntimeException(); - } - }; - - public final void storeState() { - try { - SynchronizedTargetProvider.getSynchronizer().setSyncInfo( - stateKey, - localResource, - toBytes()); - ResourcesPlugin.getWorkspace().save(false, null); - } catch (CoreException e) { - e.printStackTrace(); - throw new RuntimeException(); - } - } - - /** - * Answer the resource state as a sequence of bytes, in a format that can be used to - * reconstruct an equivalent resource state using the <code>fromBytes(byte[])</code> - * method. - * <p> - * Subclasses should implement <code>storeState(DataOutputStream)</code> to - * store provider specific state information.</p> - * - * @return the resource state as a byte array. - * @see #storeState(DataOutputStream) - * @see fromBytes(byte[]) - */ - protected byte[] toBytes() { - try { - // Create a stream to store the byte representation of the receiver's state. - ByteArrayOutputStream byteStream = new ByteArrayOutputStream(32); - // Guess ~32 bytes - DataOutputStream dataStream = new DataOutputStream(byteStream); - dataStream.writeByte(BYTES_FORMAT); - - // Store data common to all resource states. - dataStream.writeUTF(remoteBaseIdentifier); - dataStream.writeLong(localBaseTimestamp); - - dataStream.close(); - return byteStream.toByteArray(); - } catch (IOException e) { - e.printStackTrace(); - throw new RuntimeException(); - } - } - - final public void removeState() { - try { - SynchronizedTargetProvider.getSynchronizer().flushSyncInfo( - stateKey, - localResource, - IResource.DEPTH_INFINITE); - } catch (CoreException e) { - e.printStackTrace(); - throw new RuntimeException(); - } - } - - /** - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class) - */ - public Object getAdapter(Class adapter) { - return Platform.getAdapterManager().getAdapter(this, adapter); - } - - /** - * Method getRoot. - * @return URL of this resource's parent - */ - public URL getRoot() { - return rootUrl; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/target/StreamUtil.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/target/StreamUtil.java deleted file mode 100644 index 87c4d4566..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/target/StreamUtil.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial implementation - ******************************************************************************/ -package org.eclipse.team.internal.core.target; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import org.eclipse.team.internal.core.Policy; -import org.eclipse.core.runtime.IProgressMonitor; - -public class StreamUtil { - - protected final static byte[] COPY_BUFFER = new byte[4096]; - - /* - * - */ - public static void pipe( - InputStream in, - OutputStream out, - long sizeEstimate, - IProgressMonitor progress, - String title) - throws IOException { - - // Only show progress for files larger than 25Kb. - Long kilobytesEstimate = new Long(sizeEstimate / 1024); - boolean showProgress = (progress != null) && (sizeEstimate > 25000); - long bytesCopied = 0; - - synchronized (COPY_BUFFER) { - // Read the initial chunk. - int read = in.read(COPY_BUFFER, 0, COPY_BUFFER.length); - - while (read != -1) { - out.write(COPY_BUFFER, 0, read); - - // Report progress - if (showProgress) { - bytesCopied = bytesCopied + read; - progress.subTask( - Policy.bind( - "filetransfer.monitor", //$NON-NLS-1$ - new Object[] { title, new Long(bytesCopied / 1024), kilobytesEstimate })); - } - - // Read the next chunk. - read = in.read(COPY_BUFFER, 0, COPY_BUFFER.length); - } // end while - } // end synchronized - } - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/target/Symmetria.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/target/Symmetria.java deleted file mode 100644 index 5d3b5e528..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/target/Symmetria.java +++ /dev/null @@ -1,257 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial implementation - ******************************************************************************/ -package org.eclipse.team.internal.core.target; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.internal.core.Assert; - -/** - * Synchronizes the given folder between the workspace and provider. - */ -public class Symmetria { - - /** - * Remote knows best. - */ - public IStatus get( - ResourceState resourceState, - int depth, - IProgressMonitor progress) { - - IResource localResource = resourceState.getLocal(); - - // If remote does not exist then simply ensure no local resource exists. - if (!resourceState.hasRemote()) - return deleteLocal(localResource, progress); - - // If the remote resource is a file. - if (resourceState.getRemoteType() == IResource.FILE) { - // Replace any existing local resource with a copy of the remote file. - IStatus deleteStatus = deleteLocal(localResource, progress); - if (!deleteStatus.isOK()) - return deleteStatus; - return resourceState.download(progress); - } - - // The remote resource is a container. - - // If the local resource is a file, we must remove it first. - if (localResource.getType() == IResource.FILE) { - IStatus deleteStatus = deleteLocal(localResource, progress); // May not exist. - if (!deleteStatus.isOK()) - return deleteStatus; - } - - // If the local resource does not exist then it is created as a container. - if (!localResource.exists()) { - // Create a corresponding local directory. - IStatus mkdirsStatus = mkLocalDirs(localResource, progress); - if (!mkdirsStatus.isOK()) - return mkdirsStatus; - } - - // Finally, resolve the collection membership based upon the depth parameter. - switch (depth) { - case IResource.DEPTH_ZERO : - // If we are not considering members of the collection then we are done. - return ITeamStatusConstants.OK_STATUS; - case IResource.DEPTH_ONE : - // If we are considering only the immediate members of the collection - try { - getFolderShallow(resourceState, progress); - } catch (TeamException exception) { - return exception.getStatus(); - } - return ITeamStatusConstants.OK_STATUS; - case IResource.DEPTH_INFINITE : - // We are going in deep. - return getFolderDeep(resourceState, progress); - default : - // We have covered all the legal cases. - Assert.isLegal(false); - return null; // Never reached. - } // end switch - } - - /** - * Synch the remote and local folder to depth. - */ - protected IStatus getFolderDeep( - ResourceState collection, - IProgressMonitor progress) { - - ResourceState[] childFolders; - try { - childFolders = getFolderShallow(collection, progress); - } catch (TeamException exception) { - // Problem getting the folder at this level. - return exception.getStatus(); - } - - // If there are no further children then we are done. - if (childFolders.length == 0) - return ITeamStatusConstants.OK_STATUS; - - // There are children and we are going deep, the response will be a multi-status. - MultiStatus multiStatus = - new MultiStatus( - ITeamStatusConstants.OK_STATUS.getPlugin(), - ITeamStatusConstants.OK_STATUS.getCode(), - ITeamStatusConstants.OK_STATUS.getMessage(), - ITeamStatusConstants.OK_STATUS.getException()); - - // Collect the responses in the multistatus. - for (int i = 0; i < childFolders.length; i++) - multiStatus.add(get(childFolders[i], IResource.DEPTH_INFINITE, progress)); - - return multiStatus; - } - - /** - * Synchronize from the remote provider to the workspace. - * Assume that the 'remote' folder is correct, and change the local - * folder to look like the remote folder. - * - * returns an array of children of the remote resource that are themselves - * collections. - */ - protected ResourceState[] getFolderShallow( - ResourceState containerState, - IProgressMonitor progress) throws TeamException { - - // We are assuming that the resource is a container. - Assert.isLegal(containerState.getLocal() instanceof IContainer); - IContainer localContainer = (IContainer)containerState.getLocal(); - - // Get list of all _remote_ children. - ResourceState[] remoteChildren = containerState.getRemoteChildren(); - - // This will be the list of remote children that are themselves containers. - Set remoteChildFolders = new HashSet(); - - // Make a list of _local_ children that have not yet been processed, - IResource[] localChildren = getLocalChildren(localContainer); - Set surplusLocalChildren = new HashSet(localChildren.length); - surplusLocalChildren.addAll(Arrays.asList(localChildren)); - - // For each remote child that is a file, make the local file content equivalent. - for (int i = 0; i < remoteChildren.length; i++) { - ResourceState remoteChildState = remoteChildren[i]; - // If the remote child is a container add it to the list, and ensure that the local child - // is a folder if it exists. - if (remoteChildState.getRemoteType() == IResource.FILE) { - // The remote resource is a file. Copy the content of the remote file - // to the local file, overwriting any existing content that may exist, and - // creating the file if it doesn't. - IStatus downloadStatus = remoteChildState.download(progress); - if (!downloadStatus.isOK()) - throw new TeamException(downloadStatus); - // Remember that we have processed this child. - surplusLocalChildren.remove(remoteChildState.getLocal()); - } else { - // The remote resource is a container. - remoteChildFolders.add(remoteChildState); - // If the local child is not a container then it must be deleted. - IResource localChild = remoteChildState.getLocal(); - if (localChild.exists() && (!(localChild instanceof IContainer))) - checkedDeleteLocal(localChild, progress); - } // end if - } // end for - - // Remove each local child that does not have a corresponding remote resource. - Iterator childrenItr = surplusLocalChildren.iterator(); - while (childrenItr.hasNext()) { - IResource unseenChild = (IResource) childrenItr.next(); - checkedDeleteLocal(unseenChild, progress); - } // end-while - - // Answer the array of children seen on the remote collection that are - // themselves collections (to support depth operations). - return (ResourceState[]) remoteChildFolders.toArray( - new ResourceState[remoteChildFolders.size()]); - } - - /** - * Calls delete local and throws an exceptionif a problem arises. - */ - protected void checkedDeleteLocal( - IResource resource, - IProgressMonitor progress) throws TeamException { - - IStatus deleteStatus = deleteLocal(resource, progress); - if (!deleteStatus.isOK()) - throw new TeamException(ITeamStatusConstants.CONFLICT_STATUS); - } - - /** - * Delete the local resource represented by the resource state. Do not complain if the resource does not exist. - */ - protected IStatus deleteLocal( - IResource resource, - IProgressMonitor progress) { - - try { - resource.delete(true, progress); - } catch (CoreException exception) { - //todo: we need to return the real exception - return ITeamStatusConstants.IO_FAILED_STATUS; - } - - // The delete succeeded. - return ITeamStatusConstants.OK_STATUS; - } - - /** - * Make local directories matching the description of the local resource state. - * XXX There has to be a better way. - */ - protected IStatus mkLocalDirs(IResource resource, IProgressMonitor progress) { - - IContainer project = resource.getProject(); - IPath path = resource.getProjectRelativePath(); - IFolder folder = project.getFolder(path); - - try { - folder.create(false, true, progress); // No force, yes make local. - } catch (CoreException exception) { - // The creation failed. - return ITeamStatusConstants.IO_FAILED_STATUS; - } - return ITeamStatusConstants.OK_STATUS; - } - - /** - * Get an array of local children of the given container, or an empty array if the - * container does not exist or has no children. - */ - protected IResource[] getLocalChildren(IContainer container) throws TeamException { - if (container.exists()) - try { - return container.members(); - } catch (CoreException exception) { - throw new TeamException(ITeamStatusConstants.IO_FAILED_STATUS); - } - return new IResource[0]; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/target/SynchronizedTargetProvider.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/target/SynchronizedTargetProvider.java deleted file mode 100644 index 5cac0628e..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/target/SynchronizedTargetProvider.java +++ /dev/null @@ -1,281 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial implementation - ******************************************************************************/ -package org.eclipse.team.internal.core.target; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.Properties; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceStatus; -import org.eclipse.core.resources.ISynchronizer; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.core.runtime.Status; -import org.eclipse.team.core.*; -import org.eclipse.team.core.sync.IRemoteResource; -import org.eclipse.team.core.target.*; -import org.eclipse.team.internal.core.Policy; -import org.eclipse.team.internal.core.Assert; -import org.eclipse.team.internal.core.TeamPlugin; - -public abstract class SynchronizedTargetProvider extends TargetProvider { - - private static final int CONFIG_FORMAT_VERSION = 2; - - private final int depth = IResource.DEPTH_INFINITE; - - /** - * These interfaces are to operations that can be performed on the array of resources, - * and on all resources identified by the depth parameter. - * @see execute(IOperation, IResource[], int, IProgressMonitor) - */ - protected static interface IOperation { - } - protected static interface IIterativeOperation extends IOperation { - public IStatus visit(IResource resource, int depth, IProgressMonitor progress); - } - protected static interface IRecursiveOperation extends IOperation { - public IStatus visit(IResource resource, IProgressMonitor progress); - } - - /** - * Answers the synchronizer. - */ - final protected static ISynchronizer getSynchronizer() { - return ResourcesPlugin.getWorkspace().getSynchronizer(); - } - - /** - * Answers a new state based on an existing local resource. - */ - abstract public ResourceState newState(IResource resource); - - /** - * Get the state descriptor for a given resource. - */ - public ResourceState getState(IResource resource) { - // Create a new resource state with default values. - ResourceState state = newState(resource); - state.loadState(); - return state; - } - - /** - * Get the resource from the provider to the workspace, and remember the fetched - * state as the base state of the resource. - * - * @see ITeamProvider.get(IResource[], int, IProgressMonitor) - */ - public void get(IResource[] resources, IProgressMonitor progress) - throws TeamException { - execute(new IIterativeOperation() { - public IStatus visit(IResource resource, int depth, IProgressMonitor progress) { - ResourceState state = getState(resource); - return new Symmetria().get(state, depth, progress); - } - }, resources, depth, progress); - } - - - /** - * Put the resources to the remote. - */ - public void put(IResource[] resources, IProgressMonitor progress) - throws TeamException { - execute(new IRecursiveOperation() { - public IStatus visit(IResource resource, IProgressMonitor progress) { - // The resource state must be checked-out. - ResourceState state = getState(resource); - return state.checkin(progress); - } - }, resources, depth, progress); - } - - /** - * Delete the corresponding remote resource. - * Note that deletes are always deep. - */ - public void delete(IResource[] resources, IProgressMonitor progress) - throws TeamException { - execute(new IIterativeOperation() { - public IStatus visit(IResource resource, int depth, IProgressMonitor progress) { - ResourceState state = getState(resource); - return state.delete(progress); - } - }, resources, IResource.DEPTH_INFINITE, progress); - } - - /** - * Answer if the local resource currently has a different timestamp to the - * base timestamp for this resource. - * - * @param resource the resource to test. - * @return <code>true</code> if the resource has a different modification - * timestamp, and <code>false</code> otherwise. - * @see ITeamSynch#isDirty(IResource) - */ - public boolean isDirty(IResource resource) { - ResourceState state = getState(resource); - return state.isDirty(resource); - } - - /** - * Answers true if the base identifier of the given resource is different to the - * current released state of the resource. - * - * @param resource the resource state to test. - * @return <code>true</code> if the resource base identifier is different to the - * current released state of the resource, and <code>false</code> otherwise. - * @see ITeamSynch#isOutOfDate(IResource) - */ - public boolean isOutOfDate(IResource resource) { - ResourceState state = getState(resource); - return state.isOutOfDate(); - } - - /** - * Answer whether the resource has a corresponding remote resource in the provider. - * - * @param resource the resource state to test. - * @return <code>true</code> if the resource has a corresponding remote resource, - * and <code>false</code> otherwise. - * @see ITeamSynch#hasRemote(IResource) - */ - public boolean hasRemote(IResource resource) { - ResourceState state = getState(resource); - return state.hasRemote(); - } - - - - /** - * Perform the given operation on the array of resources, each to the - * specified depth. Throw an exception if a problem ocurs, otherwise - * remain silent. - */ - protected void execute( - IOperation operation, - IResource[] resources, - int depth, - IProgressMonitor progress) - throws TeamException { - - // Create an array to hold the status for each resource. - IStatus[] statuses = new IStatus[resources.length]; - - // Remember if a failure occurred in any resource, so we can throw an exception at the end. - boolean failureOccurred = false; - - // For each resource in the local resources array. - for (int i = 0; i < resources.length; i++) { - if (operation instanceof IRecursiveOperation) - statuses[i] = execute((IRecursiveOperation)operation, resources[i], depth, progress); - else - statuses[i] = ((IIterativeOperation)operation).visit(resources[i], depth, progress); - failureOccurred = failureOccurred || (!statuses[i].isOK()); - } - - // Finally, if any problems occurred, throw the exeption with all the statuses, - // but if there were no problems exit silently. - if (failureOccurred) - throw new TeamException( - new MultiStatus( - TeamPlugin.ID, - IStatus.ERROR, - statuses, - Policy.bind("multiStatus.errorsOccurred"), //$NON-NLS-1$ - null)); - - // Cause all the resource changes to be broadcast to listeners. -// TeamPlugin.getManager().broadcastResourceStateChanges(resources); - } - - /** - * Perform the given operation on a resource to the given depth. - */ - protected IStatus execute( - IRecursiveOperation operation, - IResource resource, - int depth, - IProgressMonitor progress) { - - // Visit the given resource first. - IStatus status = operation.visit(resource, progress); - - // If the resource is a file then the depth parameter is irrelevant. - if (resource.getType() == IResource.FILE) - return status; - - // If we are not considering any members of the container then we are done. - if (depth == IResource.DEPTH_ZERO) - return status; - - // If the operation was unsuccessful, do not attempt to go deep. - if (!status.isOK()) - return status; - - // If the container has no children then we are done. - IResource[] members = getMembers(resource); - if (members.length == 0) - return status; - - // There are children and we are going deep, the response will be a multi-status. - MultiStatus multiStatus = - new MultiStatus( - status.getPlugin(), - status.getCode(), - status.getMessage(), - status.getException()); - - // The next level will be one less than the current level... - int childDepth = - (depth == IResource.DEPTH_ONE) - ? IResource.DEPTH_ZERO - : IResource.DEPTH_INFINITE; - - // Collect the responses in the multistatus. - for (int i = 0; i < members.length; i++) - multiStatus.add(execute(operation, members[i], childDepth, progress)); - - return multiStatus; - } - - /** - * Answers an array of local resource members for the given resource - * or an empty arrray if the resource has no members. - * - * @param resource the local resource whose members are required. - * @return an array of <code>IResource</code> or an empty array if - * the resource has no members. - */ - protected IResource[] getMembers(IResource resource) { - if (resource.getType() != IResource.FILE) { - try { - return ((IContainer) resource).members(); - } catch (CoreException exception) { - exception.printStackTrace(); - throw new RuntimeException(); - } - } //end-if - else - return new IResource[0]; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/target/UrlUtil.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/target/UrlUtil.java deleted file mode 100644 index a5b90da28..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/target/UrlUtil.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial implementation - ******************************************************************************/ -package org.eclipse.team.internal.core.target; - -import java.net.MalformedURLException; -import java.net.URL; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; - -public class UrlUtil { - - public static IPath getTrailingPath(URL fullURL, URL startingURL) { - IPath fullPath = new Path(fullURL.getPath()); - IPath startingPath = new Path(startingURL.getPath()); - int matchingCount = fullPath.matchingFirstSegments(startingPath); - return fullPath.removeFirstSegments(matchingCount); - } - - public static URL concat(String root, IPath end) throws MalformedURLException { - return new URL(concatString(root, end)); - } - - private static String concatString(String root, IPath end) { - if(end.isEmpty()) - return root; - if(root.length() == 0) - return end.toString(); - boolean rootHasTrailing = root.charAt(root.length() - 1) == Path.SEPARATOR; //has trailing '/' - boolean endHasLeading = end.isAbsolute(); // has leading '/' - - if(rootHasTrailing && endHasLeading) //http://mysite/ + /myFolder - return root + end.toString().substring(1); // we have two seperators, drop one - - if(!rootHasTrailing && !endHasLeading) //http://mysite + myFolder - return root + Path.SEPARATOR + end.toString(); - - return root + end.toString(); //have one separator between the two, just concat end - } -} diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/target/messages.properties b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/target/messages.properties deleted file mode 100644 index 39c4b3943..000000000 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/target/messages.properties +++ /dev/null @@ -1,11 +0,0 @@ - -teamStatus.notCheckedOut=Not checked out. -teamStatus.notCheckedIn=Not checked in. -teamStatus.unmanagedResource=Unmanaged resource. -teamStatus.noRemoteResource=Remote resource does not exist. -teamStatus.ioFailed=An IO error occurred. -teamStatus.conflict=A conflict occurred. -provider.configuration.missing=Required configuration value missing. -provider.configuration.invalid=Configuration value is invalid. -filetransfer.monitor={0} ({1}K of {2}K bytes) -multiStatus.errorsOccurred=Errors occurred.
\ No newline at end of file |