diff options
author | Dani Megert | 2007-02-22 13:40:54 +0000 |
---|---|---|
committer | Dani Megert | 2007-02-22 13:40:54 +0000 |
commit | f23dda1f5064f94c1d138db237c3795d2ce769de (patch) | |
tree | 57638066a879a20f4879f25d25127ce5bbfb1dba /org.eclipse.core.filebuffers.tests | |
parent | 83492ed9a25acf36885c4b088be34f1fd5af89d0 (diff) | |
download | eclipse.platform.text-f23dda1f5064f94c1d138db237c3795d2ce769de.tar.gz eclipse.platform.text-f23dda1f5064f94c1d138db237c3795d2ce769de.tar.xz eclipse.platform.text-f23dda1f5064f94c1d138db237c3795d2ce769de.zip |
Fixed bug 148057: [misc][api] Allow the construction of an ITextFileBuffer from an IFileStore or a URI
Diffstat (limited to 'org.eclipse.core.filebuffers.tests')
8 files changed, 1635 insertions, 3 deletions
diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferCreation.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferCreation.java index 134d65a9123..8d6cc7ff7a8 100644 --- a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferCreation.java +++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferCreation.java @@ -15,6 +15,9 @@ import java.io.File; import junit.framework.Assert; import junit.framework.TestCase; +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileStore; + import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; @@ -90,6 +93,31 @@ public class FileBufferCreation extends TestCase { manager.disconnect(path, LocationKind.NORMALIZE, null); assertNull(manager.getTextFileBuffer(path, LocationKind.NORMALIZE)); } + + /* + * Tests the creation of file buffer for an existing file. + */ + public void test1_IFileStore() throws Exception { + IFolder folder= ResourceHelper.createFolder("project/folderA/folderB/"); + IFile file= ResourceHelper.createFile(folder, "file", CONTENT1); + IPath path= file.getFullPath(); + assertNotNull(path); + IFileStore fileStore= EFS.getLocalFileSystem().getStore(file.getLocation()); + + ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager(); + manager.connectFileStore(fileStore, null); + ITextFileBuffer buffer= manager.getFileStoreTextFileBuffer(fileStore); + assertNotNull(buffer); + + IDocument document= buffer.getDocument(); + assertNotNull(document); + assertEquals(CONTENT1, document.get()); + + assertSame(buffer, manager.getTextFileBuffer(document)); + + manager.disconnectFileStore(fileStore, null); + assertNull(manager.getFileStoreTextFileBuffer(fileStore)); + } /* * Tests that two different paths pointing to the same physical resource @@ -104,7 +132,7 @@ public class FileBufferCreation extends TestCase { IPath path2= ResourcesPlugin.getWorkspace().getRoot().getLocation(); path2= path2.append(path1.makeAbsolute()); - + ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager(); manager.connect(path1, LocationKind.NORMALIZE, null); ITextFileBuffer buffer1= manager.getTextFileBuffer(path1, LocationKind.NORMALIZE); @@ -528,4 +556,26 @@ public class FileBufferCreation extends TestCase { manager.disconnect(path, LocationKind.LOCATION, null); assertNull(manager.getTextFileBuffer(path, LocationKind.LOCATION)); } + + /* + * Tests the creation of a file buffer for a non-existing file. + */ + public void test7_IFileStore() throws Exception { + IPath path= FileBuffersTestPlugin.getDefault().getStateLocation(); + path= path.append("NonExistingFile"); + IFileStore fileStore= EFS.getLocalFileSystem().getStore(path); + + ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager(); + manager.connectFileStore(fileStore, null); + ITextFileBuffer buffer= manager.getFileStoreTextFileBuffer(fileStore); + Assert.assertNotNull(buffer); + + IDocument document= buffer.getDocument(); + Assert.assertNotNull(document); + Assert.assertTrue("".equals(document.get())); + assertSame(buffer, manager.getTextFileBuffer(document)); + + manager.disconnectFileStore(fileStore, null); + assertNull(manager.getFileStoreTextFileBuffer(fileStore)); + } } diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersTestSuite.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersTestSuite.java index ad8387d68e2..109d07ad643 100644 --- a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersTestSuite.java +++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersTestSuite.java @@ -33,6 +33,11 @@ public class FileBuffersTestSuite { suite.addTestSuite(FileBuffersForNonExistingExternalFiles.class); suite.addTestSuite(FileBuffersForNonExistingWorkspaceFiles.class); suite.addTestSuite(FileBuffersForNonAccessibleWorkspaceFiles.class); + + suite.addTestSuite(FileStoreFileBuffersForWorkspaceFiles.class); + suite.addTestSuite(FileStoreFileBuffersForExternalFiles.class); + suite.addTestSuite(FileStoreFileBuffersForNonExistingExternalFiles.class); + suite.addTestSuite(FileStoreFileBuffersForNonExistingWorkspaceFiles.class); //$JUnit-END$ return suite; } diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBufferFunctions.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBufferFunctions.java new file mode 100644 index 00000000000..cb7920cbb77 --- /dev/null +++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBufferFunctions.java @@ -0,0 +1,1163 @@ +/******************************************************************************* + * Copyright (c) 2000, 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.filebuffers.tests; + +import java.io.PrintStream; +import java.io.PrintWriter; + +import junit.framework.TestCase; + +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileInfo; +import org.eclipse.core.filesystem.IFileStore; +import org.eclipse.core.filesystem.URIUtil; + +import org.eclipse.core.runtime.IPath; + +import org.eclipse.core.resources.IProject; + +import org.eclipse.core.filebuffers.FileBuffers; +import org.eclipse.core.filebuffers.IFileBuffer; +import org.eclipse.core.filebuffers.ITextFileBuffer; +import org.eclipse.core.filebuffers.ITextFileBufferManager; + +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IDocumentExtension4; +import org.eclipse.jface.text.source.IAnnotationModel; + +/** + * FileBufferFunctions + */ +public abstract class FileStoreFileBufferFunctions extends TestCase { + + private IProject fProject; + protected ITextFileBufferManager fManager; + private IFileStore fFileStore; + + + protected abstract IPath createPath(IProject project) throws Exception; + + protected abstract void setReadOnly(boolean state) throws Exception; + + protected abstract boolean modifyUnderlyingFile() throws Exception; + + protected abstract boolean deleteUnderlyingFile() throws Exception; + + protected abstract IPath moveUnderlyingFile() throws Exception; + + protected abstract boolean isStateValidationSupported(); + + protected abstract Class getAnnotationModelClass() throws Exception; + + + protected void setUp() throws Exception { + fManager= FileBuffers.getTextFileBufferManager(); + fProject= ResourceHelper.createProject("project"); + fFileStore= EFS.getLocalFileSystem().getStore(createPath(fProject)); + ITextFileBuffer buffer= fManager.getFileStoreTextFileBuffer(fFileStore); + assertTrue(buffer == null); + } + + protected IProject getProject() { + return fProject; + } + + protected void tearDown() throws Exception { + ITextFileBuffer buffer= fManager.getFileStoreTextFileBuffer(fFileStore); + assertTrue(buffer == null); + ResourceHelper.deleteProject("project"); + } + + protected IPath getPath() { + return URIUtil.toPath(fFileStore.toURI()); + } + + /* + * Tests getLocation. + */ + public void test1() throws Exception { + fManager.connectFileStore(fFileStore, null); + try { + ITextFileBuffer buffer= fManager.getFileStoreTextFileBuffer(fFileStore); + assertEquals(fFileStore, buffer.getFileStore()); + + } finally { + fManager.disconnectFileStore(fFileStore, null); + } + } + + /* + * Tests isSynchronized. + */ + public void test2() throws Exception { + fManager.connectFileStore(fFileStore, null); + try { + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + assertTrue(fileBuffer.isSynchronized()); + IFileStore fileStore= fFileStore; + IFileInfo fileInfo= fileStore.fetchInfo(); + fileInfo.setLastModified(1000); + fileStore.putInfo(fileInfo, EFS.SET_LAST_MODIFIED, null); + long lastModified= fileStore.fetchInfo().getLastModified(); + assertTrue(lastModified == EFS.NONE || !fileBuffer.isSynchronized()); + + } finally { + fManager.disconnectFileStore(fFileStore, null); + } + } + + /* + * Tests isDirty. + */ + public void test3() throws Exception { + fManager.connectFileStore(fFileStore, null); + try { + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + assertFalse(fileBuffer.isDirty()); + IDocument document= fileBuffer.getDocument(); + document.replace(document.getLength(), 0, "appendix"); + assertTrue(fileBuffer.isDirty()); + + } finally { + fManager.disconnectFileStore(fFileStore, null); + } + } + + /* + * Tests isShared. + */ + public void test4() throws Exception { + fManager.connectFileStore(fFileStore, null); + try { + ITextFileBuffer fileBuffer1= fManager.getFileStoreTextFileBuffer(fFileStore); + assertFalse(fileBuffer1.isShared()); + + fManager.connectFileStore(fFileStore, null); + try { + ITextFileBuffer fileBuffer2= fManager.getFileStoreTextFileBuffer(fFileStore); + assertTrue(fileBuffer1.isShared()); + assertTrue(fileBuffer2.isShared()); + } finally { + fManager.disconnectFileStore(fFileStore, null); + } + + assertFalse(fileBuffer1.isShared()); + + } finally { + fManager.disconnectFileStore(fFileStore, null); + } + } + + /* + * Tests getModificationStamp. + */ + public void test5() throws Exception { + fManager.connectFileStore(fFileStore, null); + try { + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + long modificationStamp= fileBuffer.getModificationStamp(); + IFileInfo fileInfo= fFileStore.fetchInfo(); + assertEquals(modificationStamp != IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP, fileInfo.exists()); + fileInfo.setLastModified(1000); + fFileStore.putInfo(fileInfo, EFS.SET_LAST_MODIFIED, null); + long lastModified= fFileStore.fetchInfo().getLastModified(); + assertTrue(lastModified == EFS.NONE || modificationStamp != fileBuffer.getModificationStamp()); + } finally { + fManager.disconnectFileStore(fFileStore, null); + } + } + + /* + * Test revert. + */ + public void test6() throws Exception { + fManager.connectFileStore(fFileStore, null); + try { + + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + // set dirty bit + IDocument document= fileBuffer.getDocument(); + String originalContent= document.get(); + document.replace(document.getLength(), 0, "appendix"); + // invalidate synchronization state + IFileInfo fileInfo= fFileStore.fetchInfo(); + fileInfo.setLastModified(1000); + fFileStore.putInfo(fileInfo, EFS.SET_LAST_MODIFIED, null); + //revert + fileBuffer.revert(null); + // check assertions + assertEquals(originalContent, document.get()); + assertFalse(fileBuffer.isDirty()); + assertTrue(fileBuffer.isSynchronized()); + + } finally { + fManager.disconnectFileStore(fFileStore, null); + } + } + + /* + * Test commit. + */ + public void test7() throws Exception { + fManager.connectFileStore(fFileStore, null); + try { + + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + // set dirty bit + IDocument document= fileBuffer.getDocument(); + document.replace(document.getLength(), 0, "appendix"); + String originalContent= document.get(); + // commit + fileBuffer.commit(null, true); + // check assertions + assertEquals(originalContent, document.get()); + assertFalse(fileBuffer.isDirty()); + assertTrue(fileBuffer.isSynchronized()); + // revert to see effect is persistent + fileBuffer.revert(null); + // check assertions + assertEquals(originalContent, document.get()); + assertFalse(fileBuffer.isDirty()); + assertTrue(fileBuffer.isSynchronized()); + // disconnect + fManager.disconnectFileStore(fFileStore, null); + // reconnect + fManager.connectFileStore(fFileStore, null); + try { + fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + document= fileBuffer.getDocument(); + // check assertions + assertEquals(originalContent, document.get()); + assertFalse(fileBuffer.isDirty()); + assertTrue(fileBuffer.isSynchronized()); + } finally { + fManager.disconnectFileStore(fFileStore, null); + } + + } finally { + fManager.disconnectFileStore(fFileStore, null); + } + } + + /* + * Test validateState. + */ + public void test8_1() throws Exception { + fManager.connectFileStore(fFileStore, null); + try { + + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + fileBuffer.validateState(null, null); + assertTrue(fileBuffer.isStateValidated()); + + } finally { + fManager.disconnectFileStore(fFileStore, null); + } + } + + /* + * Test validateState. + */ + public void test8_2() throws Exception { + fManager.connectFileStore(fFileStore, null); + try { + + setReadOnly(true); + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + fileBuffer.validateState(null, null); + assertTrue(fileBuffer.isStateValidated()); + + } finally { + setReadOnly(false); + fManager.disconnectFileStore(fFileStore, null); + } + } + + /* + * Test resetStateValidation. + */ + public void test9_1() throws Exception { + fManager.connectFileStore(fFileStore, null); + try { + + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + fileBuffer.validateState(null, null); + fileBuffer.resetStateValidation(); + if (isStateValidationSupported()) + assertFalse(fileBuffer.isStateValidated()); + + } finally { + fManager.disconnectFileStore(fFileStore, null); + } + } + + /* + * Test resetStateValidation. + */ + public void test9_2() throws Exception { + fManager.connectFileStore(fFileStore, null); + try { + + setReadOnly(true); + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + fileBuffer.validateState(null, null); + fileBuffer.resetStateValidation(); + if (isStateValidationSupported()) + assertFalse(fileBuffer.isStateValidated()); + + } finally { + setReadOnly(false); + fManager.disconnectFileStore(fFileStore, null); + } + } + + /* + * Test IFileBufferListener#bufferCreated and IFileBufferListener#bufferDisposed + */ + public void test10() throws Exception { + class Listener extends FileBufferListener { + + public IFileBuffer buffer; + public int count; + + public void bufferCreated(IFileBuffer buf) { + ++count; + this.buffer= buf; + } + + public void bufferDisposed(IFileBuffer buf) { + --count; + this.buffer= buf; + } + } + + Listener listener= new Listener(); + fManager.addFileBufferListener(listener); + try { + + fManager.connectFileStore(fFileStore, null); + + assertTrue(listener.count == 1); + assertNotNull(listener.buffer); + IFileBuffer fileBuffer= fManager.getFileStoreFileBuffer(fFileStore); + assertTrue(listener.buffer == fileBuffer); + + fManager.disconnectFileStore(fFileStore, null); + assertTrue(listener.count == 0); + assertTrue(listener.buffer == fileBuffer); + + } finally { + try { + fManager.disconnectFileStore(fFileStore, null); + } finally { + fManager.removeFileBufferListener(listener); + } + } + } + + /* + * Test IFileBufferListener#dirtyStateChanged + */ + public void test11_1() throws Exception { + class Listener extends FileBufferListener { + + public IFileBuffer buffer; + public int count; + public boolean isDirty; + + public void dirtyStateChanged(IFileBuffer buf, boolean state) { + ++count; + this.buffer= buf; + this.isDirty= state; + } + } + + Listener listener= new Listener(); + fManager.addFileBufferListener(listener); + try { + + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + assertTrue(listener.count == 0 && listener.buffer == null); + + fManager.connectFileStore(fFileStore, null); + try { + + fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + IDocument document= fileBuffer.getDocument(); + document.replace(0, 0, "prefix"); + + assertTrue(listener.count == 1); + assertTrue(listener.buffer == fileBuffer); + assertTrue(listener.isDirty); + + fileBuffer.commit(null, true); + + assertTrue(listener.count == 2); + assertTrue(listener.buffer == fileBuffer); + assertFalse(listener.isDirty); + + } finally { + fManager.disconnectFileStore(fFileStore, null); + } + + } finally { + fManager.removeFileBufferListener(listener); + } + } + + /* + * Test IFileBufferListener#dirtyStateChanged + */ + public void test11_2() throws Exception { + class Listener extends FileBufferListener { + + public IFileBuffer buffer; + public int count; + public boolean isDirty; + + public void dirtyStateChanged(IFileBuffer buf, boolean state) { + ++count; + this.buffer= buf; + this.isDirty= state; + } + } + + Listener listener= new Listener(); + fManager.addFileBufferListener(listener); + try { + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + assertTrue(listener.count == 0 && listener.buffer == null); + + fManager.connectFileStore(fFileStore, null); + try { + + fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + IDocument document= fileBuffer.getDocument(); + document.replace(0, 0, "prefix"); + + assertTrue(listener.count == 1); + assertTrue(listener.buffer == fileBuffer); + assertTrue(listener.isDirty); + + fileBuffer.revert(null); + + assertTrue(listener.count == 2); + assertTrue(listener.buffer == fileBuffer); + assertFalse(listener.isDirty); + + } finally { + fManager.disconnectFileStore(fFileStore, null); + } + + } finally { + fManager.removeFileBufferListener(listener); + } + } + + /* + * Test IFileBufferListener#bufferContentAboutToBeReplaced/replaced + */ + public void test12_1() throws Exception { + class Listener extends FileBufferListener { + + public IFileBuffer preBuffer, postBuffer; + public int preCount, postCount; + + public void bufferContentAboutToBeReplaced(IFileBuffer buffer) { + ++preCount; + preBuffer= buffer; + } + + public void bufferContentReplaced(IFileBuffer buffer) { + ++postCount; + postBuffer= buffer; + } + } + + Listener listener= new Listener(); + fManager.addFileBufferListener(listener); + try { + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + assertTrue(listener.preCount == 0 && listener.postCount == 0 && listener.preBuffer == null && listener.postBuffer == null); + + fManager.connectFileStore(fFileStore, null); + try { + + fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + IDocument document= fileBuffer.getDocument(); + document.replace(0, 0, "prefix"); + + fileBuffer.revert(null); + + assertTrue(listener.preCount == 1); + assertTrue(listener.preBuffer == fileBuffer); + assertTrue(listener.postCount == 1); + assertTrue(listener.postBuffer == fileBuffer); + + } finally { + fManager.disconnectFileStore(fFileStore, null); + } + + } finally { + fManager.removeFileBufferListener(listener); + } + } + + /* + * Test IFileBufferListener#bufferContentAboutToBeReplaced/replaced + */ + public void test12_2() throws Exception { + class Listener extends FileBufferListener { + + public IFileBuffer preBuffer, postBuffer; + public int preCount, postCount; + + public void bufferContentAboutToBeReplaced(IFileBuffer buffer) { + ++preCount; + preBuffer= buffer; + } + + public void bufferContentReplaced(IFileBuffer buffer) { + ++postCount; + postBuffer= buffer; + } + } + + Listener listener= new Listener(); + fManager.addFileBufferListener(listener); + try { + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + assertTrue(listener.preCount == 0 && listener.postCount == 0 && listener.preBuffer == null && listener.postBuffer == null); + + fManager.connectFileStore(fFileStore, null); + try { + + fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + + if (modifyUnderlyingFile()) { + assertTrue(listener.preCount == 1); + assertTrue(listener.preBuffer == fileBuffer); + assertTrue(listener.postCount == 1); + assertTrue(listener.postBuffer == fileBuffer); + } + + } finally { + fManager.disconnectFileStore(fFileStore, null); + } + + } finally { + fManager.removeFileBufferListener(listener); + } + } + + /* + * Test IFileBufferListener#stateValidationChanged + */ + public void test13_1() throws Exception { + class Listener extends FileBufferListener { + + public IFileBuffer buffer; + public int count; + public boolean isStateValidated; + + public void stateValidationChanged(IFileBuffer buf, boolean state) { + ++count; + this.buffer= buf; + this.isStateValidated= state; + } + } + + Listener listener= new Listener(); + fManager.addFileBufferListener(listener); + try { + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + assertTrue(listener.count == 0 && listener.buffer == null); + + fManager.connectFileStore(fFileStore, null); + try { + + fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + fileBuffer.validateState(null, null); + + if (isStateValidationSupported()) { + assertTrue(listener.count == 1); + assertTrue(listener.buffer == fileBuffer); + assertTrue(listener.isStateValidated); + } + + } finally { + fManager.disconnectFileStore(fFileStore, null); + } + + } finally { + fManager.removeFileBufferListener(listener); + } + } + + /* + * Test IFileBufferListener#stateValidationChanged + */ + public void test13_2() throws Exception { + class Listener extends FileBufferListener { + + public IFileBuffer buffer; + public int count; + public boolean isStateValidated; + + public void stateValidationChanged(IFileBuffer buf, boolean state) { + ++count; + this.buffer= buf; + this.isStateValidated= state; + } + } + + Listener listener= new Listener(); + fManager.addFileBufferListener(listener); + try { + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + assertTrue(listener.count == 0 && listener.buffer == null); + + fManager.connectFileStore(fFileStore, null); + try { + + setReadOnly(true); + fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + fileBuffer.validateState(null, null); + + if (isStateValidationSupported()) { + assertTrue(listener.count == 1); + assertTrue(listener.buffer == fileBuffer); + assertTrue(listener.isStateValidated); + } + + } finally { + setReadOnly(false); + fManager.disconnectFileStore(fFileStore, null); + } + + } finally { + fManager.removeFileBufferListener(listener); + } + } + /* + * Test IFileBufferListener#stateValidationChanged + */ + public void test13_3() throws Exception { + class Listener extends FileBufferListener { + + public IFileBuffer buffer; + public int count; + public boolean isStateValidated; + + public void stateValidationChanged(IFileBuffer buf, boolean state) { + ++count; + this.buffer= buf; + this.isStateValidated= state; + } + } + + Listener listener= new Listener(); + fManager.addFileBufferListener(listener); + try { + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + assertTrue(listener.count == 0 && listener.buffer == null); + + fManager.connectFileStore(fFileStore, null); + try { + + fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + fileBuffer.validateState(null, null); + fileBuffer.resetStateValidation(); + + if (isStateValidationSupported()) { + assertTrue(listener.count == 2); + assertTrue(listener.buffer == fileBuffer); + assertFalse(listener.isStateValidated); + } + + } finally { + fManager.disconnectFileStore(fFileStore, null); + } + + } finally { + fManager.removeFileBufferListener(listener); + } + } + + /* + * Test IFileBufferListener#stateValidationChanged + */ + public void test13_4() throws Exception { + class Listener extends FileBufferListener { + + public IFileBuffer buffer; + public int count; + public boolean isStateValidated; + + public void stateValidationChanged(IFileBuffer buf, boolean state) { + ++count; + this.buffer= buf; + this.isStateValidated= state; + } + } + + Listener listener= new Listener(); + fManager.addFileBufferListener(listener); + try { + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + assertTrue(listener.count == 0 && listener.buffer == null); + + fManager.connectFileStore(fFileStore, null); + try { + + setReadOnly(true); + fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + fileBuffer.validateState(null, null); + fileBuffer.resetStateValidation(); + + if (isStateValidationSupported()) { + assertTrue(listener.count == 2); + assertTrue(listener.buffer == fileBuffer); + assertFalse(listener.isStateValidated); + } + + } finally { + setReadOnly(false); + fManager.disconnectFileStore(fFileStore, null); + } + + } finally { + fManager.removeFileBufferListener(listener); + } + } + + /* + * Test IFileBufferListener#underlyingFileDeleted + */ + public void test14() throws Exception { + class Listener extends FileBufferListener { + + public IFileBuffer buffer; + public int count; + + public void underlyingFileDeleted(IFileBuffer buf) { + ++count; + this.buffer= buf; + } + } + + Listener listener= new Listener(); + fManager.addFileBufferListener(listener); + try { + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + assertTrue(listener.count == 0 && listener.buffer == null); + + fManager.connectFileStore(fFileStore, null); + try { + + fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + if (deleteUnderlyingFile()) { + assertTrue(listener.count == 1); + assertTrue(listener.buffer == fileBuffer); + } + + } finally { + fManager.disconnectFileStore(fFileStore, null); + } + + } finally { + fManager.removeFileBufferListener(listener); + } + } + + /* + * Test IFileBufferListener#underlyingFileMoved + */ + public void test15() throws Exception { + class Listener extends FileBufferListener { + + public IFileBuffer buffer; + public int count; + public IPath newLocation; + + public void underlyingFileMoved(IFileBuffer buf, IPath location) { + ++count; + this.buffer= buf; + this.newLocation= location; + } + } + + Listener listener= new Listener(); + fManager.addFileBufferListener(listener); + try { + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + assertTrue(listener.count == 0 && listener.buffer == null); + + fManager.connectFileStore(fFileStore, null); + try { + + fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + IPath newLocation= moveUnderlyingFile(); + if (newLocation != null) { + assertTrue(listener.count == 1); + assertTrue(listener.buffer == fileBuffer); + assertEquals(listener.newLocation, newLocation); + } + + } finally { + fManager.disconnectFileStore(fFileStore, null); + } + + } finally { + fManager.removeFileBufferListener(listener); + } + } + + /* + * Test IFileBufferListener#stateChanging for external changes + */ + public void test16_1() throws Exception { + class Listener extends FileBufferListener { + + public IFileBuffer buffer; + public int count; + + public void stateChanging(IFileBuffer buf) { + ++count; + this.buffer= buf; + } + } + + Listener listener= new Listener(); + fManager.addFileBufferListener(listener); + try { + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + assertTrue(listener.count == 0 && listener.buffer == null); + + fManager.connectFileStore(fFileStore, null); + try { + + fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + if (modifyUnderlyingFile()) { + assertSame(listener.buffer, fileBuffer); + assertEquals(1, listener.count); + } + + } finally { + fManager.disconnectFileStore(fFileStore, null); + } + + } finally { + fManager.removeFileBufferListener(listener); + } + } + + /* + * Test IFileBufferListener#stateChanging for external changes + */ + public void test16_2() throws Exception { + class Listener extends FileBufferListener { + + public IFileBuffer buffer; + public int count; + + public void stateChanging(IFileBuffer buf) { + ++count; + this.buffer= buf; + } + } + + Listener listener= new Listener(); + fManager.addFileBufferListener(listener); + try { + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + assertTrue(listener.count == 0 && listener.buffer == null); + + fManager.connectFileStore(fFileStore, null); + try { + + fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + if (deleteUnderlyingFile()) { + assertTrue(listener.count == 1); + assertTrue(listener.buffer == fileBuffer); + } + + } finally { + fManager.disconnectFileStore(fFileStore, null); + } + + } finally { + fManager.removeFileBufferListener(listener); + } + } + + /* + * Test IFileBufferListener#stateChanging for external changes + */ + public void test16_3() throws Exception { + class Listener extends FileBufferListener { + + public IFileBuffer buffer; + public int count; + + public void stateChanging(IFileBuffer buf) { + ++count; + this.buffer= buf; + } + } + + Listener listener= new Listener(); + fManager.addFileBufferListener(listener); + try { + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + assertTrue(listener.count == 0 && listener.buffer == null); + + fManager.connectFileStore(fFileStore, null); + try { + + fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + if (moveUnderlyingFile() != null) { + assertTrue(listener.count == 1); + assertTrue(listener.buffer == fileBuffer); + } + + } finally { + fManager.disconnectFileStore(fFileStore, null); + } + + } finally { + fManager.removeFileBufferListener(listener); + } + } + + /* + * Test IFileBufferListener#stateChanging for internal changes + */ + public void test17_1() throws Exception { + class Listener extends FileBufferListener { + + public IFileBuffer buffer; + public int count; + + public void stateChanging(IFileBuffer buf) { + ++count; + this.buffer= buf; + } + } + + Listener listener= new Listener(); + fManager.addFileBufferListener(listener); + try { + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + assertTrue(listener.count == 0 && listener.buffer == null); + + fManager.connectFileStore(fFileStore, null); + try { + + fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + fileBuffer.validateState(null, null); + + if (isStateValidationSupported()) { + assertTrue(listener.count == 1); + assertTrue(listener.buffer == fileBuffer); + } + + } finally { + fManager.disconnectFileStore(fFileStore, null); + } + + } finally { + fManager.removeFileBufferListener(listener); + } + } + /* + * Test IFileBufferListener#stateChanging for internal changes + */ + public void test17_2() throws Exception { + class Listener extends FileBufferListener { + + public IFileBuffer buffer; + public int count; + + public void stateChanging(IFileBuffer buf) { + ++count; + this.buffer= buf; + } + } + + Listener listener= new Listener(); + fManager.addFileBufferListener(listener); + try { + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + assertTrue(listener.count == 0 && listener.buffer == null); + + fManager.connectFileStore(fFileStore, null); + try { + + fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + IDocument document= fileBuffer.getDocument(); + document.replace(0, 0, "prefix"); + fileBuffer.revert(null); + + assertTrue(listener.count == 1); + assertTrue(listener.buffer == fileBuffer); + + } finally { + fManager.disconnectFileStore(fFileStore, null); + } + + } finally { + fManager.removeFileBufferListener(listener); + } + } + + /* + * Test IFileBufferListener#stateChanging for internal changes + */ + public void test17_3() throws Exception { + class Listener extends FileBufferListener { + + public IFileBuffer buffer; + public int count; + + public void stateChanging(IFileBuffer buf) { + ++count; + this.buffer= buf; + } + } + + Listener listener= new Listener(); + fManager.addFileBufferListener(listener); + try { + ITextFileBuffer fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + assertTrue(listener.count == 0 && listener.buffer == null); + + fManager.connectFileStore(fFileStore, null); + try { + + fileBuffer= fManager.getFileStoreTextFileBuffer(fFileStore); + IDocument document= fileBuffer.getDocument(); + document.replace(0, 0, "prefix"); + fileBuffer.commit(null, true); + + assertTrue(listener.count == 1); + assertTrue(listener.buffer == fileBuffer); + + } finally { + fManager.disconnectFileStore(fFileStore, null); + } + + } finally { + fManager.removeFileBufferListener(listener); + } + } + + /* + * Test annotation model existence. + * ATTENTION: This test is only effective in a workspace that contains the "org.eclipse.ui.editors" bundle. + */ + public void test18() throws Exception { + fManager.connectFileStore(fFileStore, null); + try { + ITextFileBuffer buffer= fManager.getFileStoreTextFileBuffer(fFileStore); + assertNotNull(buffer); + + Class clazz= getAnnotationModelClass(); + if (clazz != null) { + IAnnotationModel model= buffer.getAnnotationModel(); + assertTrue(clazz.isInstance(model)); + } + + } finally { + fManager.disconnectFileStore(fFileStore, null); + } + } + + /* + * Test notification in case of failing listener. + */ + public void test19() throws Exception { + + class NotifiedListener extends FileBufferListener { + + int notifyCount= 0; + + public void bufferCreated(IFileBuffer buffer) { + notifyCount++; + } + public void bufferDisposed(IFileBuffer buffer) { + notifyCount++; + } + } + + class ForcedException extends RuntimeException { + private static final long serialVersionUID= 1L; + + public void printStackTrace(PrintStream s) { + s.println("!FORCED BY TEST: this entry is intentional"); + } + + public void printStackTrace(PrintWriter s) { + s.println("!FORCED BY TEST: this entry is intentional"); + } + } + + NotifiedListener notifyCounter1= new NotifiedListener(); + NotifiedListener notifyCounter2= new NotifiedListener(); + + FileBufferListener failingListener= new FileBufferListener() { + public void bufferCreated(IFileBuffer buffer) { + throw new ForcedException(); + } + public void bufferDisposed(IFileBuffer buffer) { + throw new ForcedException(); + } + }; + + fManager.addFileBufferListener(notifyCounter1); + fManager.addFileBufferListener(failingListener); + fManager.addFileBufferListener(notifyCounter2); + + fManager.connectFileStore(fFileStore, null); + try { + ITextFileBuffer buffer= fManager.getFileStoreTextFileBuffer(fFileStore); + assertNotNull(buffer); + + Class clazz= getAnnotationModelClass(); + if (clazz != null) { + IAnnotationModel model= buffer.getAnnotationModel(); + assertTrue(clazz.isInstance(model)); + } + + } finally { + fManager.disconnectFileStore(fFileStore, null); + fManager.removeFileBufferListener(notifyCounter1); + fManager.removeFileBufferListener(failingListener); + fManager.removeFileBufferListener(notifyCounter2); + } + + assertEquals(2, notifyCounter1.notifyCount); + assertEquals(2, notifyCounter2.notifyCount); + } + + public void testGetBufferForDocument() throws Exception { + fManager.connectFileStore(fFileStore, null); + try { + ITextFileBuffer buffer= fManager.getFileStoreTextFileBuffer(fFileStore); + assertNotNull(buffer); + IDocument document= buffer.getDocument(); + assertNotNull(document); + assertSame(buffer, fManager.getTextFileBuffer(document)); + } finally { + fManager.disconnectFileStore(fFileStore, null); + } + } +} diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForExternalFiles.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForExternalFiles.java new file mode 100644 index 00000000000..51246325b45 --- /dev/null +++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForExternalFiles.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2000, 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.filebuffers.tests; + +import java.io.File; + +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileStore; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; + +import org.eclipse.core.resources.IProject; + +import org.eclipse.core.filebuffers.FileBuffers; + +/** + * FileBuffersForExternalFiles + */ +public class FileStoreFileBuffersForExternalFiles extends FileStoreFileBufferFunctions { + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#tearDown() + */ + protected void tearDown() throws Exception { + FileTool.delete(getPath()); + FileTool.delete(FileBuffers.getSystemFileAtLocation(getPath()).getParentFile()); + super.tearDown(); + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#createPath(org.eclipse.core.resources.IProject) + */ + protected IPath createPath(IProject project) throws Exception { + File sourceFile= FileTool.getFileInPlugin(FileBuffersTestPlugin.getDefault(), new Path("testResources/ExternalFile")); + File externalFile= FileTool.createTempFileInPlugin(FileBuffersTestPlugin.getDefault(), new Path("externalResources/ExternalFile")); + FileTool.copy(sourceFile, externalFile); + return new Path(externalFile.getAbsolutePath()); + } + + protected void setReadOnly(boolean state) throws Exception { + IFileStore fileStore= FileBuffers.getFileStoreAtLocation(getPath()); + assertNotNull(fileStore); + fileStore.fetchInfo().setAttribute(EFS.ATTRIBUTE_READ_ONLY, state); + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#isStateValidationSupported() + */ + protected boolean isStateValidationSupported() { + return false; + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#deleteUnderlyingFile() + */ + protected boolean deleteUnderlyingFile() throws Exception { + return false; + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#moveUnderlyingFile() + */ + protected IPath moveUnderlyingFile() throws Exception { + return null; + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#modifyUnderlyingFile() + */ + protected boolean modifyUnderlyingFile() throws Exception { + return false; + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#getAnnotationModelClass() + */ + protected Class getAnnotationModelClass() throws Exception { + return null; + } +} diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForNonExistingExternalFiles.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForNonExistingExternalFiles.java new file mode 100644 index 00000000000..d73dc025232 --- /dev/null +++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForNonExistingExternalFiles.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2000, 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.filebuffers.tests; + +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileStore; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; + +import org.eclipse.core.resources.IProject; + +import org.eclipse.core.filebuffers.FileBuffers; + +/** + * FileBuffersForNonExistingExternalFiles + */ +public class FileStoreFileBuffersForNonExistingExternalFiles extends FileStoreFileBufferFunctions { + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#tearDown() + */ + protected void tearDown() throws Exception { + FileTool.delete(getPath()); + super.tearDown(); + } + + protected IPath createPath(IProject project) throws Exception { + IPath path= FileBuffersTestPlugin.getDefault().getStateLocation(); + path= path.append("NonExistingExternalFile"); + return new Path(path.toFile().getAbsolutePath()); + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#markReadOnly() + */ + protected void setReadOnly(boolean state) throws Exception { + IFileStore fileStore= FileBuffers.getFileStoreAtLocation(getPath()); + assertNotNull(fileStore); + fileStore.fetchInfo().setAttribute(EFS.ATTRIBUTE_READ_ONLY, state); + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#isStateValidationSupported() + */ + protected boolean isStateValidationSupported() { + return false; + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#deleteUnderlyingFile() + */ + protected boolean deleteUnderlyingFile() throws Exception { + return false; + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#moveUnderlyingFile() + */ + protected IPath moveUnderlyingFile() throws Exception { + return null; + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#modifyUnderlyingFile() + */ + protected boolean modifyUnderlyingFile() throws Exception { + return false; + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#getAnnotationModelClass() + */ + protected Class getAnnotationModelClass() throws Exception { + return null; + } +} diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForNonExistingWorkspaceFiles.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForNonExistingWorkspaceFiles.java new file mode 100644 index 00000000000..0650d8bc686 --- /dev/null +++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForNonExistingWorkspaceFiles.java @@ -0,0 +1,120 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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.filebuffers.tests; + +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileStore; + +import org.eclipse.core.runtime.IPath; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; + +import org.eclipse.core.filebuffers.FileBuffers; +import org.eclipse.core.filebuffers.ITextFileBuffer; +import org.eclipse.core.filebuffers.LocationKind; + +/** + * FileBuffersForNonExistingWorkspaceFiles + */ +public class FileStoreFileBuffersForNonExistingWorkspaceFiles extends FileStoreFileBufferFunctions { + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#tearDown() + */ + protected void tearDown() throws Exception { + FileTool.delete(getPath()); + super.tearDown(); + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#createPath(org.eclipse.core.resources.IProject) + */ + protected IPath createPath(IProject project) throws Exception { + IFolder folder= ResourceHelper.createFolder("project/folderA/folderB/"); + IPath filePath= folder.getLocation().append("NonExistingWorkspaceFile"); + return filePath.makeAbsolute(); + } + + public void testBug118199() throws Exception { + IFile file= getProject().getWorkspace().getRoot().getFile(getPath()); + assertFalse(file.exists()); + fManager.connect(getPath(), LocationKind.NORMALIZE, null); + try { + ITextFileBuffer buffer= fManager.getTextFileBuffer(getPath(), LocationKind.NORMALIZE); + buffer.getDocument().set("test"); + buffer.commit(null, false); + } finally { + fManager.disconnect(getPath(), LocationKind.NORMALIZE, null); + } + assertFalse(file.exists()); + } + + public void testBug118199_fixed() throws Exception { + IFile file= getProject().getWorkspace().getRoot().getFileForLocation(getPath()); + IPath path= file.getFullPath(); + assertFalse(file.exists()); + fManager.connect(path, LocationKind.IFILE, null); + try { + ITextFileBuffer buffer= fManager.getTextFileBuffer(path, LocationKind.IFILE); + buffer.getDocument().set("test"); + buffer.commit(null, false); + } finally { + fManager.disconnect(path, LocationKind.IFILE, null); + } + assertTrue(file.exists()); + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#markReadOnly() + */ + protected void setReadOnly(boolean state) throws Exception { + IFileStore fileStore= FileBuffers.getFileStoreAtLocation(getPath()); + assertNotNull(fileStore); + fileStore.fetchInfo().setAttribute(EFS.ATTRIBUTE_READ_ONLY, state); + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#isStateValidationSupported() + */ + protected boolean isStateValidationSupported() { + return false; + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#deleteUnderlyingFile() + */ + protected boolean deleteUnderlyingFile() throws Exception { + return false; + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#moveUnderlyingFile() + */ + protected IPath moveUnderlyingFile() throws Exception { + return null; + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#modifyUnderlyingFile() + */ + protected boolean modifyUnderlyingFile() throws Exception { + return false; + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#getAnnotationModelClass() + */ + protected Class getAnnotationModelClass() throws Exception { + return null; + } +} diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForWorkspaceFiles.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForWorkspaceFiles.java new file mode 100644 index 00000000000..8180df51397 --- /dev/null +++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForWorkspaceFiles.java @@ -0,0 +1,120 @@ +/******************************************************************************* + * Copyright (c) 2000, 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.filebuffers.tests; + +import java.io.IOException; +import java.io.OutputStream; + +import org.osgi.framework.Bundle; + +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileInfo; +import org.eclipse.core.filesystem.IFileStore; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourceAttributes; + +import org.eclipse.core.filebuffers.FileBuffers; + +import org.eclipse.jface.text.source.IAnnotationModel; + +/** + * FileBuffersForWorkspaceFiles + */ +public class FileStoreFileBuffersForWorkspaceFiles extends FileBufferFunctions { + + protected IPath createPath(IProject project) throws Exception { + IFolder folder= ResourceHelper.createFolder("project/folderA/folderB/"); + IFile file= ResourceHelper.createFile(folder, "WorkspaceFile", "content"); + return file.getFullPath(); + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#markReadOnly() + */ + protected void setReadOnly(boolean state) throws Exception { + IFile file= FileBuffers.getWorkspaceFileAtLocation(getPath()); + ResourceAttributes attributes= new ResourceAttributes(); + attributes.setReadOnly(state); + file.setResourceAttributes(attributes); + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#isStateValidationSupported() + */ + protected boolean isStateValidationSupported() { + return true; + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#deleteUnderlyingFile() + */ + protected boolean deleteUnderlyingFile() throws Exception { + IFile file= FileBuffers.getWorkspaceFileAtLocation(getPath()); + file.delete(true, false, null); + return file.exists(); + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#moveUnderlyingFile() + */ + protected IPath moveUnderlyingFile() throws Exception { + IFile file= FileBuffers.getWorkspaceFileAtLocation(getPath()); + ResourceHelper.createFolder("project/folderA/folderB/folderC"); + IPath path= new Path("/project/folderA/folderB/folderC/MovedWorkspaceFile"); + file.move(path, true, false, null); + + file= FileBuffers.getWorkspaceFileAtLocation(path); + if (file != null && file.exists()) + return path; + + return null; + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#modifyUnderlyingFile() + */ + protected boolean modifyUnderlyingFile() throws Exception { + IFileStore fileStore= FileBuffers.getFileStoreAtLocation(getPath()); + assertTrue(fileStore.fetchInfo().exists()); + OutputStream out= fileStore.openOutputStream(EFS.NONE, null); + try { + out.write(new String("Changed content of workspace file").getBytes()); + out.flush(); + } catch (IOException x) { + fail(); + } finally { + out.close(); + } + IFileInfo fileInfo= fileStore.fetchInfo(); + fileInfo.setLastModified(1000); + fileStore.putInfo(fileInfo, EFS.SET_LAST_MODIFIED, null); + IFile iFile= FileBuffers.getWorkspaceFileAtLocation(getPath()); + assertTrue(iFile.exists() && iFile.getFullPath().equals(getPath())); + iFile.refreshLocal(IResource.DEPTH_INFINITE, null); + return true; + } + + /* + * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#getAnnotationModelClass() + */ + protected Class getAnnotationModelClass() throws Exception { + Bundle bundle= Platform.getBundle("org.eclipse.ui.editors"); + return bundle != null ? IAnnotationModel.class : null; + } +} diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileTool.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileTool.java index 23befd9c8fb..2415e820003 100644 --- a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileTool.java +++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileTool.java @@ -27,8 +27,8 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Plugin; import org.eclipse.core.filebuffers.FileBuffers; @@ -179,7 +179,7 @@ public class FileTool { public static File getFileInPlugin(Plugin plugin, IPath path) { try { URL installURL= plugin.getBundle().getEntry(path.toString()); - URL localURL= Platform.asLocalURL(installURL); + URL localURL= FileLocator.toFileURL(installURL); return new File(localURL.getFile()); } catch (IOException e) { return null; |