diff options
author | Thomas Wolf | 2019-02-09 22:43:36 +0000 |
---|---|---|
committer | Lars Vogel | 2019-02-12 07:17:58 +0000 |
commit | 4ffc136c9a8d8157575a5940a0878030215fa76e (patch) | |
tree | 3c3c7ae6c009f64660d7836467dbe2a6ab9cea76 | |
parent | 502ba4f4b36e6df1fbceacad1f0c42b4cd32ed76 (diff) | |
download | eclipse.platform.text-4ffc136c9a8d8157575a5940a0878030215fa76e.tar.gz eclipse.platform.text-4ffc136c9a8d8157575a5940a0878030215fa76e.tar.xz eclipse.platform.text-4ffc136c9a8d8157575a5940a0878030215fa76e.zip |
Bug 544315 - DocumentProviderRegistry: also try IPath to get extension
Make getDocumentProvider(IEditorInput) try a little harder by trying
to figure out an IPath from the editor input and use the extension
of that path, if one can be determined.
Change-Id: I6426e0e9fa09b71bd472d5ca545d1333c17323ce
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
7 files changed, 121 insertions, 4 deletions
diff --git a/org.eclipse.ui.editors.tests/META-INF/MANIFEST.MF b/org.eclipse.ui.editors.tests/META-INF/MANIFEST.MF index 458341361d5..110f4b4b036 100644 --- a/org.eclipse.ui.editors.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.ui.editors.tests/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %Plugin.name Bundle-SymbolicName: org.eclipse.ui.editors.tests;singleton:=true -Bundle-Version: 3.11.200.qualifier +Bundle-Version: 3.11.300.qualifier Bundle-Vendor: %Plugin.providerName Bundle-Localization: plugin Export-Package: org.eclipse.ui.editors.tests diff --git a/org.eclipse.ui.editors.tests/build.properties b/org.eclipse.ui.editors.tests/build.properties index 4dff298188c..f59a82ba5bf 100644 --- a/org.eclipse.ui.editors.tests/build.properties +++ b/org.eclipse.ui.editors.tests/build.properties @@ -16,7 +16,8 @@ bin.includes = plugin.properties,\ test.xml,\ about.html,\ .,\ - META-INF/ + META-INF/,\ + plugin.xml src.includes = about.html diff --git a/org.eclipse.ui.editors.tests/plugin.xml b/org.eclipse.ui.editors.tests/plugin.xml new file mode 100644 index 00000000000..f1c781ff384 --- /dev/null +++ b/org.eclipse.ui.editors.tests/plugin.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (c) 2019 Thomas Wolf <thomas.wolf@paranor.ch> + + This program and the accompanying materials + are made available under the terms of the Eclipse Public License 2.0 + which accompanies this distribution, and is available at + https://www.eclipse.org/legal/epl-2.0/ + + SPDX-License-Identifier: EPL-2.0 +--> +<plugin> + <extension point="org.eclipse.ui.editors.documentProviders"> + <provider id="org.eclipse.ui.editors.tests.documentProvider" + class="org.eclipse.ui.editors.tests.DocumentProviderRegistryTest$TestDocumentProvider" + extensions="testfile"> + </provider> + </extension> +</plugin>
\ No newline at end of file diff --git a/org.eclipse.ui.editors.tests/pom.xml b/org.eclipse.ui.editors.tests/pom.xml index 51fa4fa7e7b..5feb9da63a2 100644 --- a/org.eclipse.ui.editors.tests/pom.xml +++ b/org.eclipse.ui.editors.tests/pom.xml @@ -19,7 +19,7 @@ </parent> <groupId>org.eclipse.ui</groupId> <artifactId>org.eclipse.ui.editors.tests</artifactId> - <version>3.11.200-SNAPSHOT</version> + <version>3.11.300-SNAPSHOT</version> <packaging>eclipse-test-plugin</packaging> <properties> <testSuite>${project.artifactId}</testSuite> diff --git a/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/DocumentProviderRegistryTest.java b/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/DocumentProviderRegistryTest.java new file mode 100644 index 00000000000..58f6157e1e7 --- /dev/null +++ b/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/DocumentProviderRegistryTest.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2019 Thomas Wolf <thomas.wolf@paranor.ch> + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package org.eclipse.ui.editors.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; + +import org.junit.After; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileStore; + +import org.eclipse.core.runtime.Path; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; + +import org.eclipse.core.filebuffers.tests.ResourceHelper; + +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.ide.FileStoreEditorInput; +import org.eclipse.ui.part.FileEditorInput; + +import org.eclipse.ui.texteditor.DocumentProviderRegistry; +import org.eclipse.ui.texteditor.IDocumentProvider; + +import org.eclipse.ui.editors.text.TextFileDocumentProvider; + +public class DocumentProviderRegistryTest { + + @Rule + public TemporaryFolder tmp = new TemporaryFolder(); + + private IFile file; + + @After + public void tearDown() throws Exception { + if (file != null) { + ResourceHelper.delete(file.getProject()); + } + TestUtil.cleanUp(); + } + + @Test + public void testFindByExtensionInWorkspace() throws Exception { + IFolder folder = ResourceHelper.createFolder("DocumentProviderRegistryTestProject/test"); + file = ResourceHelper.createFile(folder, "file.testfile", ""); + assertTrue("File should exist: " + file.toString(), file.exists()); + IEditorInput editorInput = new FileEditorInput(file); + IDocumentProvider provider = DocumentProviderRegistry.getDefault().getDocumentProvider(editorInput); + assertEquals("Unexpected document provider found : " + provider.getClass().getName(), + TestDocumentProvider.class, provider.getClass()); + } + + @Test + public void testFindByExtensionNonWorkspace() throws Exception { + File external = tmp.newFile("external.testfile"); + IFileStore store = EFS.getLocalFileSystem().getStore(new Path(external.getCanonicalPath())); + IEditorInput editorInput = new FileStoreEditorInput(store); + IDocumentProvider provider = DocumentProviderRegistry.getDefault().getDocumentProvider(editorInput); + assertEquals("Unexpected document provider found : " + provider.getClass().getName(), + TestDocumentProvider.class, provider.getClass()); + } + + public static class TestDocumentProvider extends TextFileDocumentProvider { + + // Nothing; class registered in plugin.xml so that we can test that we + // found the right one. + + } +} diff --git a/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EditorsTestSuite.java b/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EditorsTestSuite.java index f5e3dc91f3a..98f79171182 100644 --- a/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EditorsTestSuite.java +++ b/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EditorsTestSuite.java @@ -26,6 +26,7 @@ import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) @SuiteClasses({ ChainedPreferenceStoreTest.class, + DocumentProviderRegistryTest.class, EncodingChangeTests.class, GotoLineTest.class, SegmentedModeTest.class, diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/DocumentProviderRegistry.java b/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/DocumentProviderRegistry.java index d4aa1643725..c08410cc061 100644 --- a/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/DocumentProviderRegistry.java +++ b/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/DocumentProviderRegistry.java @@ -25,10 +25,12 @@ import java.util.StringTokenizer; import org.osgi.framework.Bundle; +import org.eclipse.core.runtime.Adapters; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.ILog; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; @@ -36,6 +38,7 @@ import org.eclipse.core.runtime.Status; import org.eclipse.core.resources.IFile; import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IPathEditorInput; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.internal.editors.text.NLSUtility; @@ -312,8 +315,17 @@ public class DocumentProviderRegistry { IDocumentProvider provider= null; IFile file= editorInput.getAdapter(IFile.class); - if (file != null) + if (file != null) { provider= getDocumentProvider(file.getFileExtension()); + } else { + IPathEditorInput pathInput= Adapters.adapt(editorInput, IPathEditorInput.class); + if (pathInput != null) { + IPath path= pathInput.getPath(); + if (path != null) { + provider= getDocumentProvider(path.getFileExtension()); + } + } + } if (provider == null) { Set<IConfigurationElement> set= findInputTypeMapping(editorInput.getClass()); |