diff options
author | Michael Valenta | 2004-04-30 17:56:14 +0000 |
---|---|---|
committer | Michael Valenta | 2004-04-30 17:56:14 +0000 |
commit | 5a7cd023d4ca16a666f0251018a1872f039c3c1d (patch) | |
tree | 3d5a1b6268eade804bd38f6ae7a313ea78d007c0 | |
parent | 95fb880b83e598f5ba3870bd9b8f678396d3fdbc (diff) | |
download | eclipse.platform.team-5a7cd023d4ca16a666f0251018a1872f039c3c1d.tar.gz eclipse.platform.team-5a7cd023d4ca16a666f0251018a1872f039c3c1d.tar.xz eclipse.platform.team-5a7cd023d4ca16a666f0251018a1872f039c3c1d.zip |
Bug 59367: Non-uniform encoding support for Compare with Revision
4 files changed, 127 insertions, 49 deletions
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/variants/CachedResourceVariant.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/variants/CachedResourceVariant.java index b51dd1e3f..387c525ec 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/variants/CachedResourceVariant.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/variants/CachedResourceVariant.java @@ -10,13 +10,26 @@ *******************************************************************************/ package org.eclipse.team.core.variants; +import java.io.IOException; import java.io.InputStream; - +import org.eclipse.core.resources.IEncodedStorage; +import org.eclipse.core.resources.IResourceStatus; import org.eclipse.core.resources.IStorage; -import org.eclipse.core.runtime.*; -import org.eclipse.team.core.*; -import org.eclipse.team.internal.core.*; +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.PlatformObject; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.content.IContentDescription; +import org.eclipse.core.runtime.content.IContentTypeManager; +import org.eclipse.team.core.TeamException; +import org.eclipse.team.internal.core.Assert; import org.eclipse.team.internal.core.Policy; +import org.eclipse.team.internal.core.ResourceVariantCache; +import org.eclipse.team.internal.core.ResourceVariantCacheEntry; +import org.eclipse.team.internal.core.TeamPlugin; /** * A resource variant is a partial implementation of a remote resource @@ -49,7 +62,7 @@ public abstract class CachedResourceVariant extends PlatformObject implements IR * Internal class which provides access to the cached contents * of this resource variant */ - class ResourceVariantStorage implements IStorage { + class ResourceVariantStorage implements IEncodedStorage { public InputStream getContents() throws CoreException { if (!isContentsCached()) { // The cache may have been cleared if someone held @@ -70,6 +83,28 @@ public abstract class CachedResourceVariant extends PlatformObject implements IR public Object getAdapter(Class adapter) { return CachedResourceVariant.this.getAdapter(adapter); } + public String getCharset() throws CoreException { + IContentDescription description = getContentDescription(); + return (description == null || description.getProperty(IContentDescription.CHARSET) == null) ? null : (String) description.getProperty(IContentDescription.CHARSET); + } + public IContentDescription getContentDescription() throws CoreException { + // tries to obtain a description for this file contents + IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); + InputStream contents = null; + try { + contents = getContents(); + return contentTypeManager.getDescriptionFor(contents, getName(), IContentDescription.ALL); + } catch (IOException e) { + throw new TeamException(new Status(IStatus.ERROR, TeamPlugin.ID, IResourceStatus.FAILED_DESCRIBING_CONTENTS, "As error occurred computing the content type of resource variant {0}" + getFullPath(), e)); + } finally { + if (contents != null) + try { + contents.close(); + } catch (IOException e) { + // Ignore exceptions on close + } + } + } } /* (non-Javadoc) diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ResourceEditionNode.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ResourceEditionNode.java index a77e1568c..8451d2c60 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ResourceEditionNode.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ResourceEditionNode.java @@ -14,9 +14,15 @@ package org.eclipse.team.internal.ccvs.ui; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.lang.reflect.InvocationTargetException; - -import org.eclipse.compare.*; +import org.eclipse.compare.CompareUI; +import org.eclipse.compare.IEncodedStreamContentAccessor; +import org.eclipse.compare.IStreamContentAccessor; +import org.eclipse.compare.ITypedElement; import org.eclipse.compare.structuremergeviewer.IStructureComparator; +import org.eclipse.core.internal.dtree.IComparator; +import org.eclipse.core.resources.IEncodedStorage; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IStorage; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; @@ -29,7 +35,7 @@ import org.eclipse.team.internal.ccvs.core.ICVSRemoteResource; /** * A class for comparing ICVSRemoteResource objects */ -public class ResourceEditionNode implements IStructureComparator, ITypedElement, IStreamContentAccessor { +public class ResourceEditionNode implements IStructureComparator, ITypedElement, IEncodedStreamContentAccessor { private ICVSRemoteResource resource; private ResourceEditionNode[] children; @@ -91,34 +97,9 @@ public class ResourceEditionNode implements IStructureComparator, ITypedElement, * @see IStreamContentAccessor#getContents() */ public InputStream getContents() throws CoreException { - if (resource == null) { - return null; - } - try { - final InputStream[] holder = new InputStream[1]; - CVSUIPlugin.runWithProgress(null, true /*cancelable*/, new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - try { - IStorage storage = ((IResourceVariant)resource).getStorage(monitor); - if (storage != null) { - holder[0] = storage.getContents(); - } - } catch (TeamException e) { - throw new InvocationTargetException(e); - } catch (CoreException e) { - throw new InvocationTargetException(e); - } - } - }); - return holder[0]; - } catch (InterruptedException e) { - // operation canceled - } catch (InvocationTargetException e) { - Throwable t = e.getTargetException(); - if (t instanceof TeamException) { - throw new CoreException(((TeamException) t).getStatus()); - } - // should not get here + IStorage storage = getStorage(); + if (storage != null) { + return storage.getContents(); } return new ByteArrayInputStream(new byte[0]); } @@ -159,4 +140,47 @@ public class ResourceEditionNode implements IStructureComparator, ITypedElement, public int hashCode() { return getName().hashCode(); } + + /* (non-Javadoc) + * @see org.eclipse.compare.IEncodedStreamContentAccessor#getCharset() + */ + public String getCharset() throws CoreException { + // Use the local file encoding if there is one + IResource local = resource.getIResource(); + if (local != null && local.getType() == IResource.FILE) { + return ((IFile)local).getCharset(); + } + // See if the remote file has an encoding + IStorage storage = getStorage(); + if (storage instanceof IEncodedStorage) { + String charset = ((IEncodedStorage)storage).getCharset(); + if (charset != null) { + return charset; + } + } + return null; + } + + private IStorage getStorage() throws TeamException { + if (resource == null) { + return null; + } + final IStorage[] holder = new IStorage[1]; + try { + CVSUIPlugin.runWithProgress(null, true /*cancelable*/, new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + try { + holder[0] = ((IResourceVariant)resource).getStorage(monitor); + } catch (TeamException e) { + throw new InvocationTargetException(e); + } + } + }); + } catch (InvocationTargetException e) { + throw TeamException.asTeamException(e); + } catch (InterruptedException e) { + // Shouldn't happen. Ignore + } + return holder[0]; + } } diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/RestoreFromRepositoryFileSelectionPage.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/RestoreFromRepositoryFileSelectionPage.java index cbc464f13..b89cd2416 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/RestoreFromRepositoryFileSelectionPage.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/RestoreFromRepositoryFileSelectionPage.java @@ -30,6 +30,7 @@ import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Widget; import org.eclipse.team.core.TeamException; +import org.eclipse.team.core.variants.IResourceVariant; import org.eclipse.team.internal.ccvs.core.*; import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot; import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo; @@ -61,7 +62,7 @@ public class RestoreFromRepositoryFileSelectionPage extends CVSWizardPage { private static final int WIZARD_WIDTH = 550; - class HistoryInput implements ITypedElement, IStreamContentAccessor, IModificationDate { + class HistoryInput implements ITypedElement, IEncodedStreamContentAccessor, IModificationDate { IFile file; ILogEntry logEntry; @@ -70,7 +71,9 @@ public class RestoreFromRepositoryFileSelectionPage extends CVSWizardPage { this.logEntry = logEntry; } public InputStream getContents() throws CoreException { - return getContentsFromLogEntry(logEntry); + IStorage s = getStorageFromLogEntry(logEntry); + if (s == null) return null; + return new BufferedInputStream(s.getContents()); } public String getName() { return file.getName(); @@ -84,6 +87,13 @@ public class RestoreFromRepositoryFileSelectionPage extends CVSWizardPage { public long getModificationDate() { return logEntry.getDate().getTime(); } + public String getCharset() throws CoreException { + IStorage s = getStorageFromLogEntry(logEntry); + if (s instanceof IEncodedStorage) { + return ((IEncodedStorage)s).getCharset(); + } + return null; + } } /** @@ -129,7 +139,7 @@ public class RestoreFromRepositoryFileSelectionPage extends CVSWizardPage { // Top right: Revision selection pane revisionSelectionPane = new CompareViewerPane(hsplitter, SWT.BORDER | SWT.FLAT); - data = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);; + data = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); revisionSelectionPane.setLayoutData(data); historyTableProvider = new HistoryTableProvider(); revisionsTable = createRevisionSelectionTable(revisionSelectionPane, historyTableProvider); @@ -426,19 +436,14 @@ public class RestoreFromRepositoryFileSelectionPage extends CVSWizardPage { return (ILogEntry[])entriesCache.get(selectedFile); } - /** - * Method getContents. - * @param logEntry - * @return InputStream - */ - private InputStream getContentsFromLogEntry(final ILogEntry logEntry) { - final InputStream[] is = new InputStream[] { null }; + private IStorage getStorageFromLogEntry(final ILogEntry logEntry) { + final IStorage[] s = new IStorage[] { null }; try { getContainer().run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { ICVSRemoteFile remoteFile = logEntry.getRemoteFile(); - is[0] = remoteFile.getContents(monitor); + s[0] = ((IResourceVariant)remoteFile).getStorage(monitor); } catch (TeamException e) { throw new InvocationTargetException(e); } @@ -452,7 +457,7 @@ public class RestoreFromRepositoryFileSelectionPage extends CVSWizardPage { } catch (InterruptedException e) { return null; } - return new BufferedInputStream(is[0]); + return s[0]; } private void handleRevisionChecked(CheckStateChangedEvent event) { diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/RemoteResourceTypedElement.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/RemoteResourceTypedElement.java index 3210ffbaf..73a16661a 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/RemoteResourceTypedElement.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/RemoteResourceTypedElement.java @@ -13,6 +13,7 @@ package org.eclipse.team.internal.ui.synchronize; import java.io.InputStream; import org.eclipse.compare.*; +import org.eclipse.core.resources.IEncodedStorage; import org.eclipse.core.resources.IStorage; import org.eclipse.core.runtime.*; import org.eclipse.swt.graphics.Image; @@ -23,7 +24,7 @@ import org.eclipse.team.internal.core.Assert; /** * RemoteResourceTypedElement */ -public class RemoteResourceTypedElement extends BufferedContent implements ITypedElement, IEditableContent { +public class RemoteResourceTypedElement extends BufferedContent implements ITypedElement, IEditableContent, IEncodedStreamContentAccessor { private IResourceVariant remote; private IStorage bufferedContents; @@ -125,4 +126,17 @@ public class RemoteResourceTypedElement extends BufferedContent implements IType remote = variant; fireContentChanged(); } + + /* (non-Javadoc) + * @see org.eclipse.compare.IEncodedStreamContentAccessor#getCharset() + */ + public String getCharset() throws CoreException { + if(bufferedContents == null) { + cacheContents(new NullProgressMonitor()); + } + if (bufferedContents instanceof IEncodedStorage) { + return ((IEncodedStorage)bufferedContents).getCharset(); + } + return null; + } }
\ No newline at end of file |