Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 19915 Details for
Bug 69640
[content type] associate content types to natures
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
patch for org.eclipse.core.tests.resources
org.eclipse.core.tests.resources_bug69640.diff (text/plain), 17.57 KB, created by
Rafael Chaves
on 2005-04-14 11:49:21 EDT
(
hide
)
Description:
patch for org.eclipse.core.tests.resources
Filename:
MIME Type:
Creator:
Rafael Chaves
Created:
2005-04-14 11:49:21 EDT
Size:
17.57 KB
patch
obsolete
>Index: plugin.xml >=================================================================== >RCS file: /home/eclipse/org.eclipse.core.tests.resources/plugin.xml,v >retrieving revision 1.62 >diff -u -r1.62 plugin.xml >--- plugin.xml 5 Apr 2005 15:59:14 -0000 1.62 >+++ plugin.xml 14 Apr 2005 15:48:45 -0000 >@@ -236,17 +236,40 @@ > </extension> > <extension > point="org.eclipse.core.runtime.contentTypes"> >+ <content-type >+ name="My Content Type" >+ id="myContent" >+ file-extensions="resources-mc" >+ default-charset="PROVIDER_CHARSET"/> > <content-type > name="A more specific XML" > id="anotherXML" > base-type="org.eclipse.core.runtime.xml" > describer="org.eclipse.core.runtime.content.XMLRootElementContentDescriber:org.eclipse.core.tests.resources.anotherXML"/> >- <content-type >- name="My Content Type" >- id="myContent" >- file-extensions="resources-mc" >- default-charset="PROVIDER_CHARSET"/> >+ <!-- content types for nature-content type association tests --> >+ <content-type >+ name="A content type for testing nature association" >+ id="nature_associated_1" >+ file-extensions="nature-associated" >+ base-type="org.eclipse.core.runtime.text"/> >+ <content-type >+ name="A derived content type for testing nature association" >+ id="nature_associated_2" >+ base-type="org.eclipse.core.tests.resources.nature_associated_1"/> >+</extension> >+<extension >+ id="contentTypeRelated1" >+ name="Content-type related nature 1" >+ point="org.eclipse.core.resources.natures"> >+ <content-type id="org.eclipse.core.tests.resources.nature_associated_1"/> >+</extension> >+<extension >+ id="contentTypeRelated2" >+ name="Content-type related nature 2" >+ point="org.eclipse.core.resources.natures"> >+ <content-type id="org.eclipse.core.tests.resources.nature_associated_2"/> > </extension> >+ > <extension > point="org.eclipse.core.resources.refreshProviders"> > <refreshProvider >Index: src/org/eclipse/core/tests/resources/AllTests.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/AllTests.java,v >retrieving revision 1.18 >diff -u -r1.18 AllTests.java >--- src/org/eclipse/core/tests/resources/AllTests.java 21 Feb 2005 23:10:08 -0000 1.18 >+++ src/org/eclipse/core/tests/resources/AllTests.java 14 Apr 2005 15:48:45 -0000 >@@ -25,6 +25,7 @@ > public static Test suite() { > TestSuite suite = new TestSuite(AllTests.class.getName()); > suite.addTest(CharsetTest.suite()); >+ suite.addTest(ContentDescriptionManagerTest.suite()); > suite.addTest(IFileTest.suite()); > suite.addTest(IFolderTest.suite()); > suite.addTest(IPathVariableTest.suite()); >Index: src/org/eclipse/core/tests/resources/CharsetTest.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/CharsetTest.java,v >retrieving revision 1.23 >diff -u -r1.23 CharsetTest.java >--- src/org/eclipse/core/tests/resources/CharsetTest.java 6 Apr 2005 18:43:52 -0000 1.23 >+++ src/org/eclipse/core/tests/resources/CharsetTest.java 14 Apr 2005 15:48:46 -0000 >@@ -14,8 +14,6 @@ > import junit.framework.Test; > import junit.framework.TestSuite; > import org.eclipse.core.internal.preferences.EclipsePreferences; >-import org.eclipse.core.internal.resources.ContentDescriptionManager; >-import org.eclipse.core.internal.resources.Workspace; > import org.eclipse.core.resources.*; > import org.eclipse.core.runtime.*; > import org.eclipse.core.runtime.content.*; >@@ -66,10 +64,10 @@ > } > } > >- private static final String SAMPLE_SPECIFIC_XML = "<?xml version=\"1.0\"?><org.eclipse.core.tests.resources.anotherXML/>"; >+ static final String SAMPLE_SPECIFIC_XML = "<?xml version=\"1.0\"?><org.eclipse.core.tests.resources.anotherXML/>"; > private static final String SAMPLE_XML_DEFAULT_ENCODING = "<?xml version=\"1.0\"?><org.eclipse.core.resources.tests.root/>"; >- private static final String SAMPLE_XML_ISO_8859_1_ENCODING = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><org.eclipse.core.resources.tests.root/>"; >- private static final String SAMPLE_XML_US_ASCII_ENCODING = "<?xml version=\"1.0\" encoding=\"US-ASCII\"?><org.eclipse.core.resources.tests.root/>"; >+ static final String SAMPLE_XML_ISO_8859_1_ENCODING = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><org.eclipse.core.resources.tests.root/>"; >+ static final String SAMPLE_XML_US_ASCII_ENCODING = "<?xml version=\"1.0\" encoding=\"US-ASCII\"?><org.eclipse.core.resources.tests.root/>"; > > private String savedWorkspaceCharset; > >@@ -251,82 +249,6 @@ > } > } > >- public void testBug79151() { >- IWorkspace workspace = getWorkspace(); >- IProject project = workspace.getRoot().getProject("MyProject"); >- IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); >- IContentType xml = contentTypeManager.getContentType("org.eclipse.core.runtime.xml"); >- String newExtension = "xml_bug_79151"; >- IFile file1 = project.getFile("file.xml"); >- IFile file2 = project.getFile("file." + newExtension); >- ensureExistsInWorkspace(file1, getContents(SAMPLE_XML_ISO_8859_1_ENCODING)); >- ensureExistsInWorkspace(file2, getContents(SAMPLE_XML_US_ASCII_ENCODING)); >- // ensure we start in a known state >- ((Workspace) workspace).getContentDescriptionManager().invalidateCache(true); >- // wait for cache flush to finish >- waitForCacheFlush(); >- // cache is new at this point >- assertEquals("0.9", ContentDescriptionManager.EMPTY_CACHE, ((Workspace) workspace).getContentDescriptionManager().getCacheState()); >- >- IContentDescription description1a = null, description1b = null, description1c = null, description1d = null; >- IContentDescription description2 = null; >- try { >- description1a = file1.getContentDescription(); >- description2 = file2.getContentDescription(); >- } catch (CoreException e) { >- fail("1.0", e); >- } >- assertNotNull("1.1", description1a); >- assertEquals("1.2", xml, description1a.getContentType()); >- assertNull("1.3", description2); >- try { >- description1b = file1.getContentDescription(); >- // ensure it comes from the cache (should be the very same object) >- assertNotNull(" 2.0", description1b); >- assertSame("2.1", description1a, description1b); >- } catch (CoreException e) { >- fail("2.2", e); >- } >- try { >- // change the content type >- xml.addFileSpec(newExtension, IContentType.FILE_EXTENSION_SPEC); >- } catch (CoreException e) { >- fail("3.0", e); >- } >- try { >- try { >- description1c = file1.getContentDescription(); >- description2 = file2.getContentDescription(); >- } catch (CoreException e) { >- fail("4.0", e); >- } >- // ensure it does *not* come from the cache (should be a different object) >- assertNotNull("4.1", description1c); >- assertNotSame("4.2", description1a, description1c); >- assertEquals("4.3", xml, description1c.getContentType()); >- assertNotNull("4.4", description2); >- assertEquals("4.5", xml, description2.getContentType()); >- } finally { >- try { >- // dissociate the xml2 extension from the XML content type >- xml.removeFileSpec(newExtension, IContentType.FILE_EXTENSION_SPEC); >- } catch (CoreException e) { >- fail("4.99", e); >- } >- } >- try { >- description1d = file1.getContentDescription(); >- description2 = file2.getContentDescription(); >- } catch (CoreException e) { >- fail("5.0", e); >- } >- // ensure it does *not* come from the cache (should be a different object) >- assertNotNull("5.1", description1d); >- assertNotSame("5.2", description1c, description1d); >- assertEquals("5.3", xml, description1d.getContentType()); >- assertNull("5.4", description2); >- } >- > public void testChangesDifferentProject() throws CoreException { > IWorkspace workspace = getWorkspace(); > IProject project1 = workspace.getRoot().getProject("Project1"); >@@ -1046,17 +968,4 @@ > } > } > } >- >- /** >- * Blocks the calling thread until the cache flush job completes. >- */ >- protected void waitForCacheFlush() { >- try { >- Platform.getJobManager().join(ContentDescriptionManager.FAMILY_DESCRIPTION_CACHE_FLUSH, null); >- } catch (OperationCanceledException e) { >- //ignore >- } catch (InterruptedException e) { >- //ignore >- } >- } > } >Index: src/org/eclipse/core/tests/resources/ContentDescriptionManagerTest.java >=================================================================== >RCS file: src/org/eclipse/core/tests/resources/ContentDescriptionManagerTest.java >diff -N src/org/eclipse/core/tests/resources/ContentDescriptionManagerTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/tests/resources/ContentDescriptionManagerTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,222 @@ >+/******************************************************************************* >+ * Copyright (c) 2005 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.core.tests.resources; >+ >+import java.io.ByteArrayInputStream; >+import java.io.InputStream; >+import junit.framework.Test; >+import junit.framework.TestSuite; >+import org.eclipse.core.internal.resources.ContentDescriptionManager; >+import org.eclipse.core.internal.resources.Workspace; >+import org.eclipse.core.resources.*; >+import org.eclipse.core.runtime.*; >+import org.eclipse.core.runtime.content.*; >+ >+public class ContentDescriptionManagerTest extends ResourceTest { >+ >+ private static final String CONTENT_TYPE_RELATED_NATURE2 = "org.eclipse.core.tests.resources.contentTypeRelated2"; >+ private static final String CONTENT_TYPE_RELATED_NATURE1 = "org.eclipse.core.tests.resources.contentTypeRelated1"; >+ >+ public static Test suite() { >+ return new TestSuite(ContentDescriptionManagerTest.class); >+ } >+ >+ public ContentDescriptionManagerTest(String name) { >+ super(name); >+ } >+ >+ protected InputStream projectDescriptionWithNatures(String project, String[] natures) { >+ StringBuffer contents = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?><projectDescription><name>" + project + "</name><natures>"); >+ for (int i = 0; i < natures.length; i++) >+ contents.append("<nature>" + natures[i] + "</nature>"); >+ contents.append("</natures></projectDescription>"); >+ return new ByteArrayInputStream(contents.toString().getBytes()); >+ } >+ >+ public void testNatureContentTypeAssociation() { >+ IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); >+ IContentType baseType = contentTypeManager.getContentType("org.eclipse.core.tests.resources.nature_associated_1"); >+ IContentType derivedType = contentTypeManager.getContentType("org.eclipse.core.tests.resources.nature_associated_2"); >+ assertNotNull("0.1", baseType); >+ assertNotNull("0.2", derivedType); >+ IProject project = getWorkspace().getRoot().getProject("proj1"); >+ IFile file = project.getFile("file.nature-associated"); >+ IFile descFile = project.getFile(IProjectDescription.DESCRIPTION_FILE_NAME); >+ ensureExistsInWorkspace(file, "it really does not matter"); >+ IContentDescription description = null; >+ >+ // originally, project description has no natures >+ try { >+ descFile.setContents(projectDescriptionWithNatures(project.getName(), new String[0]), IResource.FORCE, getMonitor()); >+ } catch (CoreException e) { >+ fail("1.0", e); >+ } >+ waitForCacheFlush(); >+ try { >+ description = file.getContentDescription(); >+ } catch (CoreException e) { >+ fail("1.1", e); >+ } >+ assertNotNull("1.2", description); >+ assertSame("1.3", derivedType, description.getContentType()); >+ >+ // change project description to include one of the natures >+ try { >+ descFile.setContents(projectDescriptionWithNatures(project.getName(), new String[] {CONTENT_TYPE_RELATED_NATURE1}), IResource.FORCE, getMonitor()); >+ } catch (CoreException e) { >+ fail("2.0", e); >+ } >+ waitForCacheFlush(); >+ try { >+ description = file.getContentDescription(); >+ } catch (CoreException e) { >+ fail("2.1", e); >+ } >+ assertNotNull("2.2", description); >+ assertSame("2.3", baseType, description.getContentType()); >+ >+ // change project description to include the other nature >+ try { >+ descFile.setContents(projectDescriptionWithNatures(project.getName(), new String[] {CONTENT_TYPE_RELATED_NATURE2}), IResource.FORCE, getMonitor()); >+ } catch (CoreException e) { >+ fail("3.0", e); >+ } >+ waitForCacheFlush(); >+ try { >+ description = file.getContentDescription(); >+ } catch (CoreException e) { >+ fail("3.1", e); >+ } >+ assertNotNull("3.2", description); >+ assertSame("3.3", derivedType, description.getContentType()); >+ >+ // change project description to include both of the natures >+ try { >+ descFile.setContents(projectDescriptionWithNatures(project.getName(), new String[] {CONTENT_TYPE_RELATED_NATURE1, CONTENT_TYPE_RELATED_NATURE2}), IResource.FORCE, getMonitor()); >+ } catch (CoreException e) { >+ fail("4.0", e); >+ } >+ waitForCacheFlush(); >+ try { >+ description = file.getContentDescription(); >+ } catch (CoreException e) { >+ fail("4.1", e); >+ } >+ assertNotNull("4.2", description); >+ assertSame("4.3", derivedType, description.getContentType()); >+ >+ // back to no natures >+ try { >+ descFile.setContents(projectDescriptionWithNatures(project.getName(), new String[0]), IResource.FORCE, getMonitor()); >+ } catch (CoreException e) { >+ fail("5.0", e); >+ } >+ waitForCacheFlush(); >+ try { >+ description = file.getContentDescription(); >+ } catch (CoreException e) { >+ fail("5.1", e); >+ } >+ assertNotNull("5.2", description); >+ assertSame("5.3", derivedType, description.getContentType()); >+ >+ } >+ >+ public void testBug79151() { >+ IWorkspace workspace = getWorkspace(); >+ IProject project = workspace.getRoot().getProject("MyProject"); >+ IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); >+ IContentType xml = contentTypeManager.getContentType("org.eclipse.core.runtime.xml"); >+ String newExtension = "xml_bug_79151"; >+ IFile file1 = project.getFile("file.xml"); >+ IFile file2 = project.getFile("file." + newExtension); >+ ensureExistsInWorkspace(file1, getContents(CharsetTest.SAMPLE_XML_ISO_8859_1_ENCODING)); >+ ensureExistsInWorkspace(file2, getContents(CharsetTest.SAMPLE_XML_US_ASCII_ENCODING)); >+ // ensure we start in a known state >+ ((Workspace) workspace).getContentDescriptionManager().invalidateCache(true, null); >+ // wait for cache flush to finish >+ waitForCacheFlush(); >+ // cache is new at this point >+ assertEquals("0.9", ContentDescriptionManager.EMPTY_CACHE, ((Workspace) workspace).getContentDescriptionManager().getCacheState()); >+ >+ IContentDescription description1a = null, description1b = null, description1c = null, description1d = null; >+ IContentDescription description2 = null; >+ try { >+ description1a = file1.getContentDescription(); >+ description2 = file2.getContentDescription(); >+ } catch (CoreException e) { >+ fail("1.0", e); >+ } >+ assertNotNull("1.1", description1a); >+ assertEquals("1.2", xml, description1a.getContentType()); >+ assertNull("1.3", description2); >+ try { >+ description1b = file1.getContentDescription(); >+ // ensure it comes from the cache (should be the very same object) >+ assertNotNull(" 2.0", description1b); >+ assertSame("2.1", description1a, description1b); >+ } catch (CoreException e) { >+ fail("2.2", e); >+ } >+ try { >+ // change the content type >+ xml.addFileSpec(newExtension, IContentType.FILE_EXTENSION_SPEC); >+ } catch (CoreException e) { >+ fail("3.0", e); >+ } >+ try { >+ try { >+ description1c = file1.getContentDescription(); >+ description2 = file2.getContentDescription(); >+ } catch (CoreException e) { >+ fail("4.0", e); >+ } >+ // ensure it does *not* come from the cache (should be a different object) >+ assertNotNull("4.1", description1c); >+ assertNotSame("4.2", description1a, description1c); >+ assertEquals("4.3", xml, description1c.getContentType()); >+ assertNotNull("4.4", description2); >+ assertEquals("4.5", xml, description2.getContentType()); >+ } finally { >+ try { >+ // dissociate the xml2 extension from the XML content type >+ xml.removeFileSpec(newExtension, IContentType.FILE_EXTENSION_SPEC); >+ } catch (CoreException e) { >+ fail("4.99", e); >+ } >+ } >+ try { >+ description1d = file1.getContentDescription(); >+ description2 = file2.getContentDescription(); >+ } catch (CoreException e) { >+ fail("5.0", e); >+ } >+ // ensure it does *not* come from the cache (should be a different object) >+ assertNotNull("5.1", description1d); >+ assertNotSame("5.2", description1c, description1d); >+ assertEquals("5.3", xml, description1d.getContentType()); >+ assertNull("5.4", description2); >+ } >+ >+ /** >+ * Blocks the calling thread until the cache flush job completes. >+ */ >+ protected void waitForCacheFlush() { >+ try { >+ Platform.getJobManager().join(ContentDescriptionManager.FAMILY_DESCRIPTION_CACHE_FLUSH, null); >+ } catch (OperationCanceledException e) { >+ //ignore >+ } catch (InterruptedException e) { >+ //ignore >+ } >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 69640
:
19913
| 19915