Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDani Megert2004-04-14 15:46:14 +0000
committerDani Megert2004-04-14 15:46:14 +0000
commit8048882152e3dd8bb9dd4d25ae2968c9aba05fdb (patch)
tree11941e4c47f030341fa942a532f882605d089677 /org.eclipse.core.filebuffers.tests
parentfeec0ceb0b6a70b3211729f5051a965caf07b8c3 (diff)
downloadeclipse.platform.text-8048882152e3dd8bb9dd4d25ae2968c9aba05fdb.tar.gz
eclipse.platform.text-8048882152e3dd8bb9dd4d25ae2968c9aba05fdb.tar.xz
eclipse.platform.text-8048882152e3dd8bb9dd4d25ae2968c9aba05fdb.zip
Initial Release - work in progressInitial_Release
Diffstat (limited to 'org.eclipse.core.filebuffers.tests')
-rw-r--r--org.eclipse.core.filebuffers.tests/.classpath7
-rw-r--r--org.eclipse.core.filebuffers.tests/.cvsignore1
-rw-r--r--org.eclipse.core.filebuffers.tests/.project28
-rw-r--r--org.eclipse.core.filebuffers.tests/about.html30
-rw-r--r--org.eclipse.core.filebuffers.tests/build.properties16
-rw-r--r--org.eclipse.core.filebuffers.tests/plugin.properties13
-rw-r--r--org.eclipse.core.filebuffers.tests/plugin.xml24
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferTest1.java251
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FilebuffersTestPlugin.java64
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/TestHelper.java143
-rw-r--r--org.eclipse.core.filebuffers.tests/testResources/ExternalFile1
-rw-r--r--org.eclipse.core.filebuffers.tests/testResources/LinkTarget11
12 files changed, 579 insertions, 0 deletions
diff --git a/org.eclipse.core.filebuffers.tests/.classpath b/org.eclipse.core.filebuffers.tests/.classpath
new file mode 100644
index 000000000..065ac06e1
--- /dev/null
+++ b/org.eclipse.core.filebuffers.tests/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.core.filebuffers.tests/.cvsignore b/org.eclipse.core.filebuffers.tests/.cvsignore
new file mode 100644
index 000000000..c5e82d745
--- /dev/null
+++ b/org.eclipse.core.filebuffers.tests/.cvsignore
@@ -0,0 +1 @@
+bin \ No newline at end of file
diff --git a/org.eclipse.core.filebuffers.tests/.project b/org.eclipse.core.filebuffers.tests/.project
new file mode 100644
index 000000000..4f8d85b98
--- /dev/null
+++ b/org.eclipse.core.filebuffers.tests/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.core.filebuffers.tests</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.core.filebuffers.tests/about.html b/org.eclipse.core.filebuffers.tests/about.html
new file mode 100644
index 000000000..9db411aab
--- /dev/null
+++ b/org.eclipse.core.filebuffers.tests/about.html
@@ -0,0 +1,30 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
+<html>
+<head>
+<title>About</title>
+<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1">
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>20th June, 2002</p>
+<h3>License</h3>
+<p>Eclipse.org makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the
+Common Public License Version 1.0 (&quot;CPL&quot;). A copy of the CPL is available at <a href="http://www.eclipse.org/legal/cpl-v10.html">http://www.eclipse.org/legal/cpl-v10.html</a>.
+For purposes of the CPL, &quot;Program&quot; will mean the Content.</p>
+
+<h3>Contributions</h3>
+
+<p>If this Content is licensed to you under the terms and conditions of the CPL, any Contributions, as defined in the CPL, uploaded, submitted, or otherwise
+made available to Eclipse.org, members of Eclipse.org and/or the host of Eclipse.org web site, by you that relate to such
+Content are provided under the terms and conditions of the CPL and can be made available to others under the terms of the CPL.</p>
+
+<p>If this Content is licensed to you under license terms and conditions other than the CPL (&quot;Other License&quot;), any modifications, enhancements and/or
+other code and/or documentation (&quot;Modifications&quot;) uploaded, submitted, or otherwise made available to Eclipse.org, members of Eclipse.org and/or the
+host of Eclipse.org, by you that relate to such Content are provided under terms and conditions of the Other License and can be made available
+to others under the terms of the Other License. In addition, with regard to Modifications for which you are the copyright holder, you are also
+providing the Modifications under the terms and conditions of the CPL and such Modifications can be made available to others under the terms of
+the CPL.</p>
+
+</body>
+</html> \ No newline at end of file
diff --git a/org.eclipse.core.filebuffers.tests/build.properties b/org.eclipse.core.filebuffers.tests/build.properties
new file mode 100644
index 000000000..8022cfc56
--- /dev/null
+++ b/org.eclipse.core.filebuffers.tests/build.properties
@@ -0,0 +1,16 @@
+###############################################################################
+# Copyright (c) 2000, 2004 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Common Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/cpl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+###############################################################################
+bin.includes = plugin.xml,\
+ test.xml,\
+ about.html,\
+ testResources/,\
+ *.jar,\
+source.javauitests.jar = src/
diff --git a/org.eclipse.core.filebuffers.tests/plugin.properties b/org.eclipse.core.filebuffers.tests/plugin.properties
new file mode 100644
index 000000000..b3cf95a35
--- /dev/null
+++ b/org.eclipse.core.filebuffers.tests/plugin.properties
@@ -0,0 +1,13 @@
+###############################################################################
+# Copyright (c) 2000, 2004 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Common Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/cpl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+###############################################################################
+
+Plugin.name= File Buffers Test Plug-in
+Plugin.providerName= Eclipse.org
diff --git a/org.eclipse.core.filebuffers.tests/plugin.xml b/org.eclipse.core.filebuffers.tests/plugin.xml
new file mode 100644
index 000000000..e07bcba6c
--- /dev/null
+++ b/org.eclipse.core.filebuffers.tests/plugin.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.0"?>
+<plugin
+ id="org.eclipse.core.filebuffers.tests"
+ name="%Plugin.name"
+ version="3.0.0"
+ provider-name="%Plugin.providerName"
+ class="org.eclipse.core.filebuffers.tests.FilebuffersTestPlugin">
+
+ <runtime>
+ <library name="filebufferstests.jar">
+ <export name="*"/>
+ </library>
+ </runtime>
+ <requires>
+ <import plugin="org.eclipse.core.runtime.compatibility"/>
+ <import plugin="org.eclipse.core.resources"/>
+ <import plugin="org.junit"/>
+ <import plugin="org.eclipse.core.filebuffers"/>
+ <import plugin="org.eclipse.text"/>
+ </requires>
+
+
+</plugin>
diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferTest1.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferTest1.java
new file mode 100644
index 000000000..b74e5ac03
--- /dev/null
+++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferTest1.java
@@ -0,0 +1,251 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.core.filebuffers.tests;
+
+import java.io.File;
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+
+import org.eclipse.core.filebuffers.FileBuffers;
+import org.eclipse.core.filebuffers.ITextFileBuffer;
+import org.eclipse.core.filebuffers.ITextFileBufferManager;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+
+
+
+public class FileBufferTest1 extends TestCase {
+
+ private final static String CONTENT1= "This is the content of the workspace file.";
+ private final static String CONTENT2= "This is the content of the link target.";
+ private final static String CONTENT3= "This is the content of the external file.";
+
+
+ private IProject fProject;
+
+
+ public static Test suite() {
+ TestSuite suite= new TestSuite();
+ suite.addTest(new FileBufferTest1("test1"));
+ suite.addTest(new FileBufferTest1("test2"));
+ suite.addTest(new FileBufferTest1("test3"));
+ suite.addTest(new FileBufferTest1("test4"));
+ suite.addTest(new FileBufferTest1("test5"));
+ suite.addTest(new FileBufferTest1("test6"));
+ return suite;
+ }
+
+ public FileBufferTest1(String name) {
+ super(name);
+ }
+
+ protected void setUp() throws Exception {
+ fProject= TestHelper.createProject("project");
+ }
+
+ protected void tearDown() throws Exception {
+ TestHelper.deleteProject("project");
+ }
+
+ public void test1() throws Exception {
+ IFolder folder= TestHelper.createFolder("project/folderA/folderB/");
+ IFile file= TestHelper.createFile(folder, "file", CONTENT1);
+ IPath path= file.getFullPath();
+ assertNotNull(path);
+
+ ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
+ manager.connect(path, null);
+ ITextFileBuffer buffer= manager.getTextFileBuffer(path);
+ assertNotNull(buffer);
+
+ IDocument document= buffer.getDocument();
+ assertNotNull(document);
+ assertEquals(CONTENT1, document.get());
+
+ manager.disconnect(path, null);
+ assertNull(manager.getTextFileBuffer(path));
+ }
+
+ public void test2() throws Exception {
+
+ IFolder folder= TestHelper.createFolder("project/folderA/folderB/");
+ IFile file= TestHelper.createFile(folder, "file", CONTENT1);
+ IPath path1= file.getFullPath();
+ assertNotNull(path1);
+
+ IPath path2= ResourcesPlugin.getWorkspace().getRoot().getLocation();
+ path2= path2.append(path1.makeAbsolute());
+
+ ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
+ manager.connect(path1, null);
+ ITextFileBuffer buffer1= manager.getTextFileBuffer(path1);
+ assertNotNull(buffer1);
+
+ ITextFileBuffer buffer2= manager.getTextFileBuffer(path2);
+ assertNotNull(buffer2);
+
+ manager.connect(path2, null);
+ buffer2= manager.getTextFileBuffer(path2);
+ assertNotNull(buffer2);
+
+ IDocument document1= buffer1.getDocument();
+ assertNotNull(document1);
+ assertEquals(CONTENT1, document1.get());
+
+ IDocument document2= buffer2.getDocument();
+ assertNotNull(document2);
+ assertEquals(CONTENT1, document2.get());
+
+ try {
+ document1.replace(0, document1.getLength(), CONTENT3);
+ } catch (BadLocationException x) {
+ assertTrue(false);
+ }
+
+ assertEquals(CONTENT3, document2.get());
+
+ manager.disconnect(path1, null);
+ assertNotNull(manager.getTextFileBuffer(path1));
+ assertNotNull(manager.getTextFileBuffer(path2));
+
+ manager.disconnect(path2, null);
+ assertNull(manager.getTextFileBuffer(path1));
+ assertNull(manager.getTextFileBuffer(path2));
+ }
+
+ public void test3() throws Exception {
+ IPath path= createLinkedFile("file", "testResources/LinkTarget1");
+ assertNotNull(path);
+
+ ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
+ manager.connect(path, null);
+ ITextFileBuffer buffer= manager.getTextFileBuffer(path);
+ Assert.assertNotNull(buffer);
+
+ IDocument document= buffer.getDocument();
+ Assert.assertNotNull(document);
+ Assert.assertTrue(CONTENT2.equals(document.get()));
+
+ manager.disconnect(path, null);
+ assertNull(manager.getTextFileBuffer(path));
+ }
+
+ public void test4() throws Exception {
+
+ IPath path1= createLinkedFile("file1", "testResources/LinkTarget1");
+ assertNotNull(path1);
+ IPath path2= createLinkedFile("file2", "testResources/LinkTarget1");
+ assertNotNull(path2);
+
+ ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
+ manager.connect(path1, null);
+ ITextFileBuffer buffer1= manager.getTextFileBuffer(path1);
+ assertNotNull(buffer1);
+ manager.connect(path2, null);
+ ITextFileBuffer buffer2= manager.getTextFileBuffer(path2);
+ assertNotNull(buffer2);
+
+ IDocument document1= buffer1.getDocument();
+ assertNotNull(document1);
+ IDocument document2= buffer2.getDocument();
+ assertNotNull(document2);
+
+ assertEquals(document1.get(), document2.get());
+ assertEquals(CONTENT2, document1.get());
+
+ try {
+ document1.replace(0, document1.getLength(), CONTENT1);
+ } catch (BadLocationException x) {
+ Assert.assertFalse(false);
+ }
+
+ assertFalse(document1.get().equals(document2.get()));
+
+ manager.disconnect(path1, null);
+ assertNull(manager.getTextFileBuffer(path1));
+ manager.disconnect(path2, null);
+ assertNull(manager.getTextFileBuffer(path2));
+ }
+
+ public void test5() throws Exception {
+ File externalFile= TestHelper.getFileInPlugin(FilebuffersTestPlugin.getDefault(), new Path("testResources/ExternalFile"));
+ assertNotNull(externalFile);
+ IPath path= new Path(externalFile.getAbsolutePath());
+
+ ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
+ manager.connect(path, null);
+ ITextFileBuffer buffer= manager.getTextFileBuffer(path);
+ assertNotNull(buffer);
+
+ IDocument document= buffer.getDocument();
+ assertNotNull(document);
+ assertTrue(CONTENT3.equals(document.get()));
+
+ manager.disconnect(path, null);
+ assertNull(manager.getTextFileBuffer(path));
+ }
+
+ public void test6() throws Exception {
+
+ IPath path1= createLinkedFile("file1", "testResources/ExternalFile");
+ assertNotNull(path1);
+
+ File externalFile= TestHelper.getFileInPlugin(FilebuffersTestPlugin.getDefault(), new Path("testResources/ExternalFile"));
+ assertNotNull(externalFile);
+ IPath path2= new Path(externalFile.getAbsolutePath());
+
+ ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
+ manager.connect(path1, null);
+ ITextFileBuffer buffer1= manager.getTextFileBuffer(path1);
+ assertNotNull(buffer1);
+ manager.connect(path2, null);
+ ITextFileBuffer buffer2= manager.getTextFileBuffer(path2);
+ assertNotNull(buffer2);
+
+ IDocument document1= buffer1.getDocument();
+ assertNotNull(document1);
+ IDocument document2= buffer2.getDocument();
+ assertNotNull(document2);
+
+ assertEquals(document1.get(), document2.get());
+ assertEquals(CONTENT3, document1.get());
+
+ try {
+ document1.replace(0, document1.getLength(), CONTENT1);
+ } catch (BadLocationException x) {
+ Assert.assertFalse(false);
+ }
+
+ assertFalse(document1.get().equals(document2.get()));
+
+ manager.disconnect(path1, null);
+ assertNull(manager.getTextFileBuffer(path1));
+ manager.disconnect(path2, null);
+ assertNull(manager.getTextFileBuffer(path2));
+ }
+
+ private IPath createLinkedFile(String fileName, String linkTarget) throws CoreException {
+ IFile file= TestHelper.createLinkedFile(fProject, new Path(fileName), FilebuffersTestPlugin.getDefault(), new Path(linkTarget));
+ return file != null ? file.getFullPath() : null;
+ }
+}
diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FilebuffersTestPlugin.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FilebuffersTestPlugin.java
new file mode 100644
index 000000000..31151383f
--- /dev/null
+++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FilebuffersTestPlugin.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.core.filebuffers.tests;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IPluginDescriptor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Plugin;
+
+/**
+ * The main plug-in class to be used in the desktop.
+ *
+ * @since 3.0
+ */
+public class FilebuffersTestPlugin extends Plugin {
+ //The shared instance.
+ private static FilebuffersTestPlugin fPlugin;
+
+ /**
+ * The constructor.
+ */
+ public FilebuffersTestPlugin(IPluginDescriptor descriptor) {
+ super(descriptor);
+ fPlugin = this;
+ }
+
+ /**
+ * Returns the shared instance.
+ */
+ public static FilebuffersTestPlugin getDefault() {
+ return fPlugin;
+ }
+
+ /**
+ * Returns the workspace instance.
+ */
+ public static IWorkspace getWorkspace() {
+ return ResourcesPlugin.getWorkspace();
+ }
+
+ public static File getFileInPlugin(Plugin plugin, IPath path) {
+ try {
+ URL installURL= new URL(plugin.getDescriptor().getInstallURL(), path.toString());
+ URL localURL= Platform.asLocalURL(installURL);
+ return new File(localURL.getFile());
+ } catch (IOException e) {
+ return null;
+ }
+ }
+}
diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/TestHelper.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/TestHelper.java
new file mode 100644
index 000000000..b789eed00
--- /dev/null
+++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/TestHelper.java
@@ -0,0 +1,143 @@
+/**********************************************************************
+Copyright (c) 2000, 2003 IBM Corp. and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Common Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/cpl-v10.html
+
+Contributors:
+ IBM Corporation - Initial implementation
+**********************************************************************/
+package org.eclipse.core.filebuffers.tests;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringBufferInputStream;
+import java.net.URL;
+
+import org.eclipse.core.internal.filebuffers.ContainerGenerator;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Plugin;
+
+/**
+ * @since 3.0
+ */
+public class TestHelper {
+
+ private final static IProgressMonitor NULL_MONITOR= new NullProgressMonitor();
+ private static final int MAX_RETRY= 5;
+
+ public static File getFileInPlugin(Plugin plugin, IPath path) {
+ try {
+ URL installURL= new URL(plugin.getDescriptor().getInstallURL(), path.toString());
+ URL localURL= Platform.asLocalURL(installURL);
+ return new File(localURL.getFile());
+ } catch (IOException e) {
+ return null;
+ }
+ }
+
+ public static IProject createProject(String projectName) throws CoreException {
+
+ IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
+ IProject project= root.getProject(projectName);
+ if (!project.exists())
+ project.create(NULL_MONITOR);
+ else
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+
+ if (!project.isOpen())
+ project.open(NULL_MONITOR);
+
+ return project;
+ }
+
+ public static void deleteProject(String projectName) throws CoreException {
+ IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
+ IProject project= root.getProject(projectName);
+ if (project.exists())
+ delete(project);
+ }
+
+ public static void delete(final IProject project) throws CoreException {
+ for (int i= 0; i < MAX_RETRY; i++) {
+ try {
+ project.delete(true, true, NULL_MONITOR);
+ i= MAX_RETRY;
+ } catch (CoreException x) {
+ if (i == MAX_RETRY - 1) {
+ FilebuffersTestPlugin.getDefault().getLog().log(x.getStatus());
+ throw x;
+ }
+ try {
+ Thread.sleep(1000); // sleep a second
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+ }
+
+ public static IFolder createFolder(String folderPath) throws CoreException {
+ ContainerGenerator generator= new ContainerGenerator(ResourcesPlugin.getWorkspace(), new Path(folderPath));
+ IContainer container= generator.generateContainer(NULL_MONITOR);
+ if (container instanceof IFolder)
+ return (IFolder) container;
+ return null;
+ }
+
+ public static IFile createFile(IFolder folder, String name, String contents) throws CoreException {
+ IFile file= folder.getFile(name);
+ if (contents == null)
+ contents= "";
+ InputStream inputStream= new StringBufferInputStream(contents);
+ file.create(inputStream, true, NULL_MONITOR);
+ return file;
+ }
+
+ public static IFile createLinkedFile(IContainer container, IPath filePath, Plugin plugin, IPath linkPath) throws CoreException {
+ IFile iFile= container.getFile(filePath);
+ File file= getFileInPlugin(plugin, linkPath);
+ iFile.createLink(new Path(file.getAbsolutePath()), IResource.ALLOW_MISSING_LOCAL, NULL_MONITOR);
+ return iFile;
+ }
+
+ public static IFolder createLinkedFolder(IContainer container, IPath folderPath, Plugin plugin, IPath linkPath) throws CoreException {
+ IFolder iFolder= container.getFolder(folderPath);
+ File file= getFileInPlugin(plugin, linkPath);
+ iFolder.createLink(new Path(file.getAbsolutePath()), IResource.ALLOW_MISSING_LOCAL, NULL_MONITOR);
+ return iFolder;
+ }
+
+ public static IProject createLinkedProject(String projectName, Plugin plugin, IPath linkPath) throws CoreException {
+ IWorkspace workspace= ResourcesPlugin.getWorkspace();
+ IProject project= workspace.getRoot().getProject(projectName);
+
+ IProjectDescription desc= workspace.newProjectDescription(projectName);
+ File file= getFileInPlugin(plugin, linkPath);
+ IPath projectLocation= new Path(file.getAbsolutePath());
+ if (Platform.getLocation().equals(projectLocation))
+ projectLocation= null;
+ desc.setLocation(projectLocation);
+
+ project.create(desc, NULL_MONITOR);
+ if (!project.isOpen())
+ project.open(NULL_MONITOR);
+
+ return project;
+ }
+}
diff --git a/org.eclipse.core.filebuffers.tests/testResources/ExternalFile b/org.eclipse.core.filebuffers.tests/testResources/ExternalFile
new file mode 100644
index 000000000..165dae0e1
--- /dev/null
+++ b/org.eclipse.core.filebuffers.tests/testResources/ExternalFile
@@ -0,0 +1 @@
+This is the content of the external file. \ No newline at end of file
diff --git a/org.eclipse.core.filebuffers.tests/testResources/LinkTarget1 b/org.eclipse.core.filebuffers.tests/testResources/LinkTarget1
new file mode 100644
index 000000000..d80dbfd20
--- /dev/null
+++ b/org.eclipse.core.filebuffers.tests/testResources/LinkTarget1
@@ -0,0 +1 @@
+This is the content of the link target. \ No newline at end of file

Back to the top