This commit was manufactured by cvs2svn to create branch 'Bundle-
ization_attempt'.
Sprout from master 2003-12-03 21:38:42 UTC John Arthorne <johna> 'removed reference to boot plugin'
Delete:
tests/org.eclipse.core.tests.resources.saveparticipant/.classpath
tests/org.eclipse.core.tests.resources.saveparticipant/.cvsignore
tests/org.eclipse.core.tests.resources.saveparticipant/.project
tests/org.eclipse.core.tests.resources.saveparticipant/about.html
tests/org.eclipse.core.tests.resources.saveparticipant/build.properties
tests/org.eclipse.core.tests.resources.saveparticipant/plugin.xml
tests/org.eclipse.core.tests.resources.saveparticipant/src/org/eclipse/core/tests/resources/saveparticipant/SaveManager1Test.java
tests/org.eclipse.core.tests.resources.saveparticipant/src/org/eclipse/core/tests/resources/saveparticipant/SaveManager2Test.java
tests/org.eclipse.core.tests.resources.saveparticipant/src/org/eclipse/core/tests/resources/saveparticipant/SaveManager3Test.java
tests/org.eclipse.core.tests.resources.saveparticipant/src/org/eclipse/core/tests/resources/saveparticipant/SaveManagerTest.java
tests/org.eclipse.core.tests.resources.saveparticipant1/.classpath
tests/org.eclipse.core.tests.resources.saveparticipant1/.cvsignore
tests/org.eclipse.core.tests.resources.saveparticipant1/.project
tests/org.eclipse.core.tests.resources.saveparticipant1/about.html
tests/org.eclipse.core.tests.resources.saveparticipant1/build.properties
tests/org.eclipse.core.tests.resources.saveparticipant1/plugin.xml
tests/org.eclipse.core.tests.resources.saveparticipant1/src/org/eclipse/core/tests/resources/saveparticipant1/SaveParticipant1Plugin.java
tests/org.eclipse.core.tests.resources.saveparticipant2/.classpath
tests/org.eclipse.core.tests.resources.saveparticipant2/.cvsignore
tests/org.eclipse.core.tests.resources.saveparticipant2/.project
tests/org.eclipse.core.tests.resources.saveparticipant2/about.html
tests/org.eclipse.core.tests.resources.saveparticipant2/build.properties
tests/org.eclipse.core.tests.resources.saveparticipant2/plugin.xml
tests/org.eclipse.core.tests.resources.saveparticipant2/src/org/eclipse/core/tests/resources/saveparticipant2/SaveParticipant2Plugin.java
tests/org.eclipse.core.tests.resources.saveparticipant3/.classpath
tests/org.eclipse.core.tests.resources.saveparticipant3/.cvsignore
tests/org.eclipse.core.tests.resources.saveparticipant3/.project
tests/org.eclipse.core.tests.resources.saveparticipant3/about.html
tests/org.eclipse.core.tests.resources.saveparticipant3/build.properties
tests/org.eclipse.core.tests.resources.saveparticipant3/plugin.xml
tests/org.eclipse.core.tests.resources.saveparticipant3/src/org/eclipse/core/tests/resources/saveparticipant3/SaveParticipant3Plugin.java
tests/org.eclipse.core.tests.resources.saveparticipant3/src/org/eclipse/core/tests/resources/saveparticipant3/SaveParticipantPlugin.java
tests/org.eclipse.core.tests.resources/.classpath
tests/org.eclipse.core.tests.resources/.cvsignore
tests/org.eclipse.core.tests.resources/.project
tests/org.eclipse.core.tests.resources/MultipleProjectTestFiles/abc.project
tests/org.eclipse.core.tests.resources/MultipleProjectTestFiles/def.project
tests/org.eclipse.core.tests.resources/MultipleProjectTestFiles/org.apache.lucene.project
tests/org.eclipse.core.tests.resources/MultipleProjectTestFiles/org.eclipse.ant.core.project
tests/org.eclipse.core.tests.resources/about.html
tests/org.eclipse.core.tests.resources/build.properties
tests/org.eclipse.core.tests.resources/plugin.xml
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/alias/AllTests.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/alias/BasicAliasTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/alias/SyncAliasTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/AbstractBuilderTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/AllTests.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BrokenBuilder.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuildDeltaVerificationTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuilderCycleTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuilderNatureTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuilderTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/CycleBuilder.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/DeltaVerifierBuilder.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/MultiProjectBuildTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/RefreshLocalJavaFileBuilder.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/SnowBuilder.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/SortBuilder.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/TestBuilder.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/dtree/AllTests.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/dtree/DataTreeTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/dtree/DeltaDataTreeTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/AllTests.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/BasicFieldTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/BasicIndexedStoreTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/BasicObjectStoreTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/BasicPageStoreTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/IntegratedFieldTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/IntegratedIndexedStoreTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/IntegratedObjectStoreTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/IntegratedPageStoreTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/IntegratedTestEnvironment.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/StandAloneFieldTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/StandAloneIndexedStoreTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/StandAloneObjectStoreTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/StandAlonePageStoreTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/StandAloneTestEnvironment.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/TestEnvironment.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/TestObject.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/TestObjectPolicy.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/TestPage.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/TestPagePolicy.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/AllTests.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/BlobStoreTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/CaseSensitivityTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/CopyTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/DeleteTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/FileSystemResourceManagerTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/FileSystemStoreTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/HistoryStoreTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/LocalStoreTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/LocalSyncTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/MoveTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/RefreshLocalPerformanceTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/RefreshLocalTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/SafeChunkyInputOutputStreamTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/SafeFileInputOutputStreamTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/UnifiedTreeTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/properties/AllTests.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/properties/PropertyManagerTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/AllTests.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/Bug29116Nature.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/EarthNature.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ModelObjectReaderWriterTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ResourceInfoTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/SimpleNature.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/SnowNature.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/TestNature.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/WaterNature.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/WorkspacePreferencesTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/utils/AllTests.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/utils/ObjectMapTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/utils/QueueTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/AllTests.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/DeltaChainFlatteningTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/DeltaFlatteningTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/DeltaIteratorTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/ElementDeltaTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/ElementTreeDeltaChainTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/ElementTreeIteratorTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/ElementTreeSerializationTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/ElementTreeTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/IPathConstants.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/PhantomComparator.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/PhantomElementData.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/PluggableDeltaLogicTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/TestDeltaFilter.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/TestElementComparator.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/TestUtil.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/TreeFlatteningTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/WatsonTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/AllTests.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/AutomatedTests.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/Comparator.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IFileTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IFolderTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IPathVariableTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IProjectTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceChangeEventTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceChangeListenerTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceDeltaTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ISynchronizerTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IWorkspaceRootTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IWorkspaceTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedResourceTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedResourceWithPathVariableTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkerAttributeChangeListener.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkerSetTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkerTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkersChangeListener.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NatureTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectOrderTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceDeltaVerifier.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceMappingTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceURLTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceVisitorVerifier.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/TeamPrivateMemberTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/TestPerformer.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/WorkspaceTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/perf/BenchElementTree.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/perf/BenchLocalStoreTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/perf/BenchMiscWorkspace.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/perf/BenchWorkspace.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/perf/MarkerPerformanceTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/perf/WorkspacePerformanceTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/AllTests.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_25457.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_26294.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_27271.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_28981.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_29116.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_29671.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_32076.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_6708.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IFileTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IFolderTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IProjectTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IResourceTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IWorkspaceTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/LocalStoreRegressionTests.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/NLTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GEAB3C_Test.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GH2B0N_Test.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GHOM0N_Test.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/SimpleBuilder.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/FindDeletedMembersTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/SampleSessionTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/Test1G1N9GZ.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/Test1GALH44.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBug12575.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBug20127.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBug30015.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBug6995.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBuilderDeltaSerialization.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestCloseNoSave.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestClosedProjectLocation.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestInterestingProjectPersistence.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestMasterTableCleanup.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestMissingBuilder.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestMultiSnap.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSave.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSaveCreateProject.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSaveSnap.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSaveWithClosedProject.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSnapSaveSnap.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/WorkspaceDescriptionTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/WorkspaceSerializationTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/AllTests.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/BuilderUseCaseTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/ConcurrencyPerformanceTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/ConcurrencyTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/ConcurrentOperation.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/ConcurrentOperation01.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/HistoryStorePerformanceTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/IFileTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/IFolderTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/IProjectTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/IResourceTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/IWorkspaceRunnableUseCaseTest.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/SignaledBuilder.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot1Test.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot2Test.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot3Test.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot4Test.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot5Test.java
tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/SnapshotTest.javadiff --git a/tests/org.eclipse.core.tests.resources.saveparticipant/.classpath b/tests/org.eclipse.core.tests.resources.saveparticipant/.classpath
deleted file mode 100644
index 065ac06..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant/.classpath
+++ /dev/null
@@ -1,7 +0,0 @@
-<?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/tests/org.eclipse.core.tests.resources.saveparticipant/.cvsignore b/tests/org.eclipse.core.tests.resources.saveparticipant/.cvsignore
deleted file mode 100644
index c5e82d7..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant/.cvsignore
+++ /dev/null
@@ -1 +0,0 @@
-bin
\ No newline at end of file
diff --git a/tests/org.eclipse.core.tests.resources.saveparticipant/.project b/tests/org.eclipse.core.tests.resources.saveparticipant/.project
deleted file mode 100644
index e35cc91..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant/.project
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.eclipse.core.tests.resources.saveparticipant</name>
- <comment></comment>
- <projects>
- <project>org.eclipse.core.boot</project>
- <project>org.eclipse.core.resources</project>
- <project>org.eclipse.core.runtime</project>
- <project>org.eclipse.core.runtime.compatibility</project>
- <project>org.eclipse.core.tests.harness</project>
- <project>org.eclipse.core.tests.resources</project>
- <project>org.eclipse.core.tests.resources.saveparticipant1</project>
- <project>org.eclipse.core.tests.resources.saveparticipant2</project>
- <project>org.eclipse.core.tests.resources.saveparticipant3</project>
- <project>org.junit</project>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
diff --git a/tests/org.eclipse.core.tests.resources.saveparticipant/about.html b/tests/org.eclipse.core.tests.resources.saveparticipant/about.html
deleted file mode 100644
index 9db411a..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant/about.html
+++ /dev/null
@@ -1,30 +0,0 @@
-<!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 ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the
-Common Public License Version 1.0 ("CPL"). 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, "Program" 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 ("Other License"), any modifications, enhancements and/or
-other code and/or documentation ("Modifications") 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/tests/org.eclipse.core.tests.resources.saveparticipant/build.properties b/tests/org.eclipse.core.tests.resources.saveparticipant/build.properties
deleted file mode 100644
index bc2aef2..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant/build.properties
+++ /dev/null
@@ -1,3 +0,0 @@
-source.saveparticipant.jar=src/
-bin.includes=plugin.xml,*.jar,about.xml
-
diff --git a/tests/org.eclipse.core.tests.resources.saveparticipant/plugin.xml b/tests/org.eclipse.core.tests.resources.saveparticipant/plugin.xml
deleted file mode 100644
index ef0405a..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant/plugin.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.0"?>
-<plugin
- name="Eclipse Core Tests Save Participant"
- id="org.eclipse.core.tests.resources.saveparticipant"
- version="3.0"
- provider-name="Eclipse.org">
-
- <requires>
- <import plugin="org.eclipse.core.resources"/>
- <import plugin="org.eclipse.core.tests.harness"/>
- <import plugin="org.eclipse.core.runtime.compatibility"/>
- <import plugin="org.junit"/>
- <import plugin="org.eclipse.core.tests.resources"/>
- <import plugin="org.eclipse.core.tests.resources.saveparticipant1"/>
- <import plugin="org.eclipse.core.tests.resources.saveparticipant2"/>
- <import plugin="org.eclipse.core.tests.resources.saveparticipant3"/>
- </requires>
-
- <runtime>
- <library name="saveparticipant.jar">
- <export name="*"/>
- </library>
- </runtime>
-
- <extension point="org.eclipse.core.tests.harness.tests">
- <test id="org.eclipse.core.tests.resources.saveparticipant.SaveManagerTest">
- <run class="org.eclipse.core.tests.resources.saveparticipant.SaveManagerTest"/>
- </test>
- </extension>
-
-</plugin>
diff --git a/tests/org.eclipse.core.tests.resources.saveparticipant/src/org/eclipse/core/tests/resources/saveparticipant/SaveManager1Test.java b/tests/org.eclipse.core.tests.resources.saveparticipant/src/org/eclipse/core/tests/resources/saveparticipant/SaveManager1Test.java
deleted file mode 100644
index 6d2a863..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant/src/org/eclipse/core/tests/resources/saveparticipant/SaveManager1Test.java
+++ /dev/null
@@ -1,350 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2002 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v0.5
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v05.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- ******************************************************************************/
-package org.eclipse.core.tests.resources.saveparticipant;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.internal.builders.DeltaVerifierBuilder;
-import org.eclipse.core.tests.resources.regression.SimpleBuilder;
-import org.eclipse.core.tests.resources.saveparticipant1.SaveParticipant1Plugin;
-import org.eclipse.core.tests.resources.saveparticipant2.SaveParticipant2Plugin;
-import org.eclipse.core.tests.resources.saveparticipant3.SaveParticipant3Plugin;
-/**
- * This class needs to be used with SaveManager2Test. Basically this
- * one builds up an environment in a platform session and the other,
- * running in another session, makes sure the environment is safelly
- * restored.
- *
- * @see SaveManager2Test
- * @see SaveManager3Test
- */
-public class SaveManager1Test extends SaveManagerTest {
-/**
- * Need a zero argument constructor to satisfy the test harness.
- * This constructor should not do any real work nor should it be
- * called by user code.
- */
-public SaveManager1Test() {
-}
-public SaveManager1Test(String name) {
- super(name);
-}
-// copy and paste into the scrapbook
-public static void doIt() throws Exception {
- String[] testIds = {
- "saveparticipant.SaveManager1Test",
- "saveparticipant.SaveManager2Test",
- "saveparticipant.SaveManager3Test"};
- for (int i = 0; i < testIds.length; i++) {
- Process p = Runtime.getRuntime().exec(new String[] {
- "java", "org.eclipse.core.tests.harness.launcher.Main",
- "-test", testIds[i],
- "-data", "c:/temp/save_manager",
- (i < (testIds.length-1) ? "-nocleanup" : "") });
- p.waitFor();
- java.io.InputStream input = p.getInputStream();
- int c;
- while ((c = input.read()) != -1)
- System.out.print((char) c);
- input.close();
- input = p.getErrorStream();
- while ((c = input.read()) != -1)
- System.out.print((char) c);
- input.close();
- }
- System.exit(-1);
-}
-public static Test suite() {
- // we do not add the whole class because the order is important
- TestSuite suite = new TestSuite();
- suite.addTest(new SaveManager1Test("testSaveEmptyWorkspace"));
- suite.addTest(new SaveManager1Test("testCreateMyProject"));
- suite.addTest(new SaveManager1Test("testCreateProject2"));
- suite.addTest(new SaveManager1Test("testAddSaveParticipant"));
- suite.addTest(new SaveManager1Test("testBuilder"));
- suite.addTest(new SaveManager1Test("testSaveWorkspace"));
- suite.addTest(new SaveManager1Test("testPostSave"));
- return suite;
-}
-public void testAddSaveParticipant() {
- // get plugin
- IPluginDescriptor descriptor = Platform.getPluginRegistry().getPluginDescriptor(PI_SAVE_PARTICIPANT_1);
- SaveParticipant1Plugin plugin1 = null;
- try {
- plugin1 = (SaveParticipant1Plugin) descriptor.getPlugin();
- } catch (CoreException e) {
- fail("0.0", e);
- }
- assertTrue("0.1", plugin1 != null);
-
- // prepare plugin to the save operation
- plugin1.resetDeltaVerifier();
- IStatus status;
- try {
- status = plugin1.registerAsSaveParticipant();
- if (!status.isOK()) {
- System.out.println(status.getMessage());
- fail("1.0");
- }
- } catch (CoreException e) {
- fail("1.1", e);
- }
- plugin1.setExpectedSaveKind(ISaveContext.FULL_SAVE);
-
- // SaveParticipant2Plugin
- descriptor = Platform.getPluginRegistry().getPluginDescriptor(PI_SAVE_PARTICIPANT_2);
- SaveParticipant2Plugin plugin2 = null;
- try {
- plugin2 = (SaveParticipant2Plugin) descriptor.getPlugin();
- } catch (CoreException e) {
- fail("5.0", e);
- }
- assertTrue("5.1", plugin2 != null);
-
- // prepare plugin to the save operation
- plugin2.getDeltaVerifier().reset();
- try {
- status = plugin2.registerAsSaveParticipant();
- if (!status.isOK()) {
- System.out.println(status.getMessage());
- fail("6.0");
- }
- } catch (CoreException e) {
- fail("6.1", e);
- }
- plugin1.setExpectedSaveKind(ISaveContext.FULL_SAVE);
-
- // SaveParticipant3Plugin
- descriptor = Platform.getPluginRegistry().getPluginDescriptor(PI_SAVE_PARTICIPANT_3);
- SaveParticipant3Plugin plugin3 = null;
- try {
- plugin3 = (SaveParticipant3Plugin) descriptor.getPlugin();
- } catch (CoreException e) {
- fail("7.0", e);
- }
- assertTrue("7.1", plugin3 != null);
- try {
- status = plugin3.registerAsSaveParticipant();
- if (!status.isOK()) {
- System.out.println(status.getMessage());
- fail("7.2");
- }
- } catch (CoreException e) {
- fail("7.3", e);
- }
-}
-/**
- * Create another project and leave it closed for next session.
- */
-public void testAnotherProject() {
- IProject project = getWorkspace().getRoot().getProject(PROJECT_1);
- try {
- project.create(null);
- project.open(null);
- } catch (CoreException e) {
- fail("0.0", e);
- }
- assertTrue("0.1", project.exists());
- assertTrue("0.2", project.isOpen());
-
- try {
- project.close(null);
- } catch (CoreException e) {
- fail("1.0", e);
- }
- assertTrue("1.1", project.exists());
- assertTrue("1.2", !project.isOpen());
-
- // when closing and opening the project again, it should still exist
- project = getWorkspace().getRoot().getProject(PROJECT_1);
- try {
- project.open(null);
- } catch (CoreException e) {
- fail("2.0", e);
- }
- assertTrue("2.1", project.exists());
- assertTrue("2.2", project.isOpen());
-
- // create some children
- IResource[] resources = buildResources(project, defineHierarchy(PROJECT_1));
- ensureExistsInWorkspace(resources, true);
- assertExistsInFileSystem("3.1", resources);
- assertExistsInWorkspace("3.2", resources);
-
- try {
- project.close(null);
- project.open(null);
- } catch (CoreException e) {
- fail("4.0", e);
- }
- assertExistsInFileSystem("4.1", resources);
- assertExistsInWorkspace("4.2", resources);
-
- try {
- getWorkspace().save(true, null);
- } catch (CoreException e) {
- fail("5.0", e);
- }
-}
-public void testBuilder() {
- IProject project = getWorkspace().getRoot().getProject(PROJECT_1);
- assertTrue("0.0", project.isAccessible());
-
- try {
- // Make sure autobuild is on
- if (!getWorkspace().isAutoBuilding()) {
- IWorkspaceDescription wsDesc = getWorkspace().getDescription();
- wsDesc.setAutoBuilding(true);
- getWorkspace().setDescription(wsDesc);
- }
- // Create and set a build spec for the project
- IProjectDescription description = project.getDescription();
- ICommand command = description.newCommand();
- command.setBuilderName(DeltaVerifierBuilder.BUILDER_NAME);
- description.setBuildSpec(new ICommand[] { command });
- project.setDescription(description, null);
- project.build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- // close and open the project and see if the builder gets a good delta
- try {
- project.close(null);
- project.open(null);
- } catch (CoreException e) {
- fail("3.0", e);
- }
- IFile added = project.getFile("added file");
- DeltaVerifierBuilder verifier = DeltaVerifierBuilder.getInstance();
- verifier.addExpectedChange(added, project, IResourceDelta.ADDED, 0);
- try {
- added.create(getRandomContents(), true, null);
- } catch (CoreException e) {
- fail("3.1", e);
- }
- assertTrue("3.2", verifier.wasAutoBuild());
- assertTrue("3.3", verifier.isDeltaValid());
- // remove the file because we don't want it to affect any other delta in the test
- try {
- added.delete(true, false, null);
- } catch (CoreException e) {
- fail("3.4", e);
- }
-}
-/**
- * Create some resources and save the workspace.
- */
-public void testCreateMyProject() {
- IProject project = getWorkspace().getRoot().getProject(PROJECT_1);
- try {
- project.create(null);
- project.open(null);
- } catch (CoreException e) {
- fail("0.0", e);
- }
- assertTrue("0.1", project.exists());
- assertTrue("0.2", project.isOpen());
-
- try {
- project.close(null);
- } catch (CoreException e) {
- fail("1.0", e);
- }
- assertTrue("1.1", project.exists());
- assertTrue("1.2", !project.isOpen());
-
- // when closing and opening the project again, it should still exist
- project = getWorkspace().getRoot().getProject(PROJECT_1);
- try {
- project.open(null);
- } catch (CoreException e) {
- fail("2.0", e);
- }
- assertTrue("2.1", project.exists());
- assertTrue("2.2", project.isOpen());
-
- // create some children
- IResource[] resources = buildResources(project, defineHierarchy(PROJECT_1));
- ensureExistsInWorkspace(resources, true);
- assertExistsInFileSystem("3.1", resources);
- assertExistsInWorkspace("3.2", resources);
-
- try {
- project.close(null);
- project.open(null);
- } catch (CoreException e) {
- fail("4.0", e);
- }
- assertExistsInFileSystem("4.1", resources);
- assertExistsInWorkspace("4.2", resources);
-}
-/**
- * Create another project and leave it closed for next session.
- */
-public void testCreateProject2() {
- IProject project = getWorkspace().getRoot().getProject(PROJECT_2);
- try {
- project.create(null);
- project.open(null);
- } catch (CoreException e) {
- fail("0.0", e);
- }
- assertTrue("0.1", project.exists());
- assertTrue("0.2", project.isOpen());
-
- // create some children
- IResource[] resources = buildResources(project, defineHierarchy(PROJECT_2));
- ensureExistsInWorkspace(resources, true);
- assertExistsInFileSystem("3.1", resources);
- assertExistsInWorkspace("3.2", resources);
-
- // add a builder to this project
- try {
- IProjectDescription description = project.getDescription();
- ICommand command = description.newCommand();
- command.setBuilderName(SimpleBuilder.BUILDER_ID);
- description.setBuildSpec(new ICommand[] { command });
- project.setDescription(description, null);
- project.build(IncrementalProjectBuilder.FULL_BUILD, null);
- } catch (CoreException e) {
- fail("4.0", e);
- }
-
- try {
- project.close(null);
- } catch (CoreException e) {
- fail("5.0", e);
- }
- assertTrue("5.1", project.exists());
- assertTrue("5.2", !project.isOpen());
-}
-public void testPostSave() {
- // get plugin
- IPluginDescriptor descriptor = Platform.getPluginRegistry().getPluginDescriptor(PI_SAVE_PARTICIPANT_1);
- SaveParticipant1Plugin plugin = null;
- try {
- plugin = (SaveParticipant1Plugin) descriptor.getPlugin();
- } catch (CoreException e) {
- fail("0.0", e);
- }
- assertTrue("0.1", plugin != null);
-
- // look at the plugin save lifecycle
- IStatus status = plugin.getSaveLifecycleLog();
- if (!status.isOK()) {
- System.out.println(status.getMessage());
- assertTrue("1.0", false);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources.saveparticipant/src/org/eclipse/core/tests/resources/saveparticipant/SaveManager2Test.java b/tests/org.eclipse.core.tests.resources.saveparticipant/src/org/eclipse/core/tests/resources/saveparticipant/SaveManager2Test.java
deleted file mode 100644
index 366a5e9..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant/src/org/eclipse/core/tests/resources/saveparticipant/SaveManager2Test.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2002 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v0.5
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v05.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- ******************************************************************************/
-package org.eclipse.core.tests.resources.saveparticipant;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.internal.builders.DeltaVerifierBuilder;
-import org.eclipse.core.tests.resources.regression.SimpleBuilder;
-import org.eclipse.core.tests.resources.saveparticipant1.SaveParticipant1Plugin;
-import org.eclipse.core.tests.resources.saveparticipant3.SaveParticipant3Plugin;
-/**
- * @see SaveManager1Test
- * @see SaveManager3Test
- */
-public class SaveManager2Test extends SaveManagerTest {
-/**
- * Need a zero argument constructor to satisfy the test harness.
- * This constructor should not do any real work nor should it be
- * called by user code.
- */
-public SaveManager2Test() {
-}
-public SaveManager2Test(String name) {
- super(name);
-}
-public static Test suite() {
- // we do not add the whole class because the order is important
- TestSuite suite = new TestSuite();
- suite.addTest(new SaveManager2Test("testVerifyRestoredWorkspace"));
- suite.addTest(new SaveManager2Test("testBuilder"));
- suite.addTest(new SaveManager2Test("testSaveParticipant"));
- suite.addTest(new SaveManager2Test("testVerifyProject2"));
- suite.addTest(new SaveManager1Test("testSaveWorkspace"));
- return suite;
-}
-public void testBuilder() {
- IProject project = getWorkspace().getRoot().getProject(PROJECT_1);
- assertTrue("0.0", project.isAccessible());
-
- IFile added = project.getFile("added file");
- DeltaVerifierBuilder verifier = DeltaVerifierBuilder.getInstance();
- verifier.addExpectedChange(added, project, IResourceDelta.ADDED, 0);
- try {
- added.create(getRandomContents(), true, null);
- } catch (CoreException e) {
- fail("3.1", e);
- }
- assertTrue("3.2", verifier.wasAutoBuild());
- assertTrue("3.3", verifier.isDeltaValid());
- // remove the file because we don't want it to affect any other delta in the test
- try {
- added.delete(true, false, null);
- } catch (CoreException e) {
- fail("3.4", e);
- }
-}
-public void testSaveParticipant() {
- // get plugin
- IPluginDescriptor descriptor = Platform.getPluginRegistry().getPluginDescriptor(PI_SAVE_PARTICIPANT_1);
- SaveParticipant1Plugin plugin1 = null;
- try {
- plugin1 = (SaveParticipant1Plugin) descriptor.getPlugin();
- } catch (CoreException e) {
- fail("0.0", e);
- }
- assertTrue("0.1", plugin1 != null);
-
- // prepare plugin to the save operation
- plugin1.resetDeltaVerifier();
- IResource added1 = getWorkspace().getRoot().getFile(new Path(PROJECT_1).append("addedFile"));
- plugin1.addExpectedChange(added1, IResourceDelta.ADDED, 0);
- IStatus status;
- try {
- status = plugin1.registerAsSaveParticipant();
- if (!status.isOK()) {
- System.out.println(status.getMessage());
- assertTrue("1.0", false);
- }
- } catch (CoreException e) {
- fail("1.1", e);
- }
-
- // SaveParticipant3Plugin
- descriptor = Platform.getPluginRegistry().getPluginDescriptor(PI_SAVE_PARTICIPANT_3);
- SaveParticipant3Plugin plugin3 = null;
- try {
- plugin3 = (SaveParticipant3Plugin) descriptor.getPlugin();
- } catch (CoreException e) {
- fail("7.0", e);
- }
- assertTrue("7.1", plugin3 != null);
- try {
- status = plugin3.registerAsSaveParticipant();
- if (!status.isOK()) {
- System.out.println(status.getMessage());
- fail("7.2");
- }
- } catch (CoreException e) {
- fail("7.3", e);
- }
-}
-public void testVerifyProject2() {
- // project2 should be closed
- IProject project = getWorkspace().getRoot().getProject(PROJECT_2);
- assertTrue("0.0", project.exists());
- assertTrue("0.1", !project.isOpen());
-
- // verify its children
- IResource[] resources = buildResources(project, defineHierarchy(PROJECT_2));
- assertExistsInFileSystem("1.0", resources);
- assertDoesNotExistInWorkspace("1.1", resources);
-
- try {
- project.open(null);
- } catch (CoreException e) {
- fail("2.0", e);
- }
- assertTrue("2.1", project.exists());
- assertTrue("2.2", project.isOpen());
- assertExistsInFileSystem("2.3", resources);
- assertExistsInWorkspace("2.4", resources);
-
- // verify builder -- cause an incremental build
- try {
- touch(project);
- } catch (CoreException e) {
- fail("2.5", e);
- }
- SimpleBuilder builder = SimpleBuilder.getInstance();
- assertTrue("2.6", builder.wasAutoBuild());
-
- // add a file to test save participant delta
- IFile file = project.getFile("addedFile");
- try {
- file.create(getRandomContents(), true, null);
- } catch (CoreException e) {
- fail("3.0", e);
- }
-}
-public void testVerifyRestoredWorkspace() {
- IProject project = getWorkspace().getRoot().getProject(PROJECT_1);
- assertTrue("0.0", project.exists());
- assertTrue("0.1", project.isOpen());
-
- // verify children still exist
- IResource[] resources = buildResources(project, defineHierarchy(PROJECT_1));
- assertExistsInFileSystem("1.0", resources);
- assertExistsInWorkspace("1.1", resources);
-
- // add a file to test save participant delta
- IFile file = project.getFile("addedFile");
- try {
- file.create(getRandomContents(), true, null);
- } catch (CoreException e) {
- fail("2.0", e);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources.saveparticipant/src/org/eclipse/core/tests/resources/saveparticipant/SaveManager3Test.java b/tests/org.eclipse.core.tests.resources.saveparticipant/src/org/eclipse/core/tests/resources/saveparticipant/SaveManager3Test.java
deleted file mode 100644
index 084145f..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant/src/org/eclipse/core/tests/resources/saveparticipant/SaveManager3Test.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2002 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v0.5
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v05.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- ******************************************************************************/
-package org.eclipse.core.tests.resources.saveparticipant;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.tests.internal.builders.DeltaVerifierBuilder;
-import org.eclipse.core.tests.resources.saveparticipant1.SaveParticipant1Plugin;
-import org.eclipse.core.tests.resources.saveparticipant2.SaveParticipant2Plugin;
-import org.eclipse.core.tests.resources.saveparticipant3.SaveParticipant3Plugin;
-/**
- * @see SaveManager1Test
- * @see SaveManager2Test
- */
-public class SaveManager3Test extends SaveManagerTest {
-/**
- * Need a zero argument constructor to satisfy the test harness.
- * This constructor should not do any real work nor should it be
- * called by user code.
- */
-public SaveManager3Test() {
-}
-public SaveManager3Test(String name) {
- super(name);
-}
-public static Test suite() {
- // we do not add the whole class because the order is important
- TestSuite suite = new TestSuite();
- suite.addTest(new SaveManager3Test("testSaveParticipant"));
- suite.addTest(new SaveManager3Test("testBuilder"));
- suite.addTest(new SaveManager3Test("cleanUp"));
- return suite;
-}
-public void testBuilder() {
- IProject project = getWorkspace().getRoot().getProject(PROJECT_1);
- assertTrue("0.0", project.isAccessible());
-
- try {
- setAutoBuilding(false);
- touch(project);
- project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
- setAutoBuilding(true);
- } catch (CoreException e) {
- fail("1.0", e);
- }
- DeltaVerifierBuilder verifier = DeltaVerifierBuilder.getInstance();
- assertTrue("1.1", verifier.wasIncrementalBuild());
-
- IFile added = project.getFile("added file");
- verifier.addExpectedChange(added, project, IResourceDelta.ADDED, 0);
- try {
- added.create(getRandomContents(), true, null);
- } catch (CoreException e) {
- fail("3.1", e);
- }
- assertTrue("3.2", verifier.wasAutoBuild());
- assertTrue("3.3", verifier.isDeltaValid());
- // remove the file because we don't want it to affect any other delta in the test
- try {
- added.delete(true, false, null);
- } catch (CoreException e) {
- fail("3.4", e);
- }
-}
-public void testSaveParticipant() {
- // SaveParticipant1Plugin
- IPluginDescriptor descriptor = Platform.getPluginRegistry().getPluginDescriptor(PI_SAVE_PARTICIPANT_1);
- SaveParticipant1Plugin plugin1 = null;
- try {
- plugin1 = (SaveParticipant1Plugin) descriptor.getPlugin();
- } catch (CoreException e) {
- fail("0.0", e);
- }
- assertTrue("0.1", plugin1 != null);
-
- // check saved state and delta
- plugin1.resetDeltaVerifier();
- IStatus status;
- try {
- status = plugin1.registerAsSaveParticipant();
- if (!status.isOK()) {
- System.out.println(status.getMessage());
- assertTrue("1.0", false);
- }
- } catch (CoreException e) {
- fail("1.1", e);
- }
-
- // SaveParticipant2Plugin
- descriptor = Platform.getPluginRegistry().getPluginDescriptor(PI_SAVE_PARTICIPANT_2);
- SaveParticipant2Plugin plugin2 = null;
- try {
- plugin2 = (SaveParticipant2Plugin) descriptor.getPlugin();
- } catch (CoreException e) {
- fail("5.0", e);
- }
- assertTrue("5.1", plugin2 != null);
-
- // check saved state and delta
- plugin2.resetDeltaVerifier();
- // MyProject changes
- IProject project = getWorkspace().getRoot().getProject(PROJECT_1);
- IResource file = project.getFile("addedFile");
- plugin2.addExpectedChange(file, IResourceDelta.ADDED, 0);
-
- // Project2 changes
- project = getWorkspace().getRoot().getProject(PROJECT_2);
- plugin2.addExpectedChange(project, IResourceDelta.CHANGED, IResourceDelta.OPEN);
- file = project.getFile("addedFile");
- plugin2.addExpectedChange(file, project, IResourceDelta.ADDED, 0);
- IResource prjFile = project.getFile(".project");
- plugin2.addExpectedChange(prjFile, IResourceDelta.ADDED, 0);
- IResource[] resources = buildResources(project, defineHierarchy(PROJECT_2));
- plugin2.addExpectedChange(resources, IResourceDelta.ADDED, 0);
- //
- try {
- status = plugin2.registerAsSaveParticipant();
- if (!status.isOK()) {
- System.out.println(status.getMessage());
- fail("6.0");
- }
- } catch (CoreException e) {
- fail("6.1", e);
- }
-
- // SaveParticipant3Plugin
- descriptor = Platform.getPluginRegistry().getPluginDescriptor(PI_SAVE_PARTICIPANT_3);
- SaveParticipant3Plugin plugin3 = null;
- try {
- plugin3 = (SaveParticipant3Plugin) descriptor.getPlugin();
- } catch (CoreException e) {
- fail("7.0", e);
- }
- assertTrue("7.1", plugin3 != null);
- try {
- status = plugin3.registerAsSaveParticipant();
- if (!status.isOK()) {
- System.out.println(status.getMessage());
- fail("7.2");
- }
- } catch (CoreException e) {
- fail("7.3", e);
- }
-}
-public void cleanUp() {
- try {
- ensureDoesNotExistInWorkspace(getWorkspace().getRoot());
- getWorkspace().save(true, null);
- } catch(CoreException e) {
- fail("1.0", e);
- }
-}
-}
\ No newline at end of file
diff --git a/tests/org.eclipse.core.tests.resources.saveparticipant/src/org/eclipse/core/tests/resources/saveparticipant/SaveManagerTest.java b/tests/org.eclipse.core.tests.resources.saveparticipant/src/org/eclipse/core/tests/resources/saveparticipant/SaveManagerTest.java
deleted file mode 100644
index 35a7610..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant/src/org/eclipse/core/tests/resources/saveparticipant/SaveManagerTest.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2002 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v0.5
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v05.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- ******************************************************************************/
-package org.eclipse.core.tests.resources.saveparticipant;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.tests.harness.WorkspaceSessionTest;
-
-/**
- * Runs all the SaveManager tests as a single session test.
- */
-public class SaveManagerTest extends WorkspaceSessionTest {
-
- /** project names */
- static final String PROJECT_1 = "MyProject";
- static final String PROJECT_2 = "Project2";
-
- /** activities */
- static final String COMMENT_1 = "COMMENT ONE";
- static final String COMMENT_2 = "COMMENT TWO";
-
- /** plugin ids */
- static final String PI_SAVE_PARTICIPANT_1 = "org.eclipse.core.tests.resources.saveparticipant1";
- static final String PI_SAVE_PARTICIPANT_2 = "org.eclipse.core.tests.resources.saveparticipant2";
- static final String PI_SAVE_PARTICIPANT_3 = "org.eclipse.core.tests.resources.saveparticipant3";
-public SaveManagerTest() {
-}
-public SaveManagerTest(String name) {
- super(name);
-}
-protected String[] defineHierarchy(String project) {
- if (project.equals(PROJECT_1))
- return defineHierarchy1();
- if (project.equals(PROJECT_2))
- return defineHierarchy2();
- return new String[0];
-}
-protected String[] defineHierarchy1() {
- return new String[] {
- "/folder110/",
- "/folder110/folder120/",
- "/folder110/folder120/folder130/",
- "/folder110/folder120/folder130/folder140/",
- "/folder110/folder120/folder130/folder140/folder150/",
- "/folder110/folder120/folder130/folder140/folder150/file160",
- "/folder110/folder120/folder130/folder140/file150",
- "/folder110/folder121/",
- "/folder110/folder121/folder131/",
- "/folder110/folder120/folder130/folder141/"
- };
-}
-protected String[] defineHierarchy2() {
- return new String[] {
- "/file110",
- "/folder110/",
- "/folder110/file120",
- "/folder111/",
- "/folder111/folder120/",
- "/folder111/file121"
- };
-}
-public void saveWorkspace() {
- try {
- getWorkspace().save(true, null);
- } catch (CoreException e) {
- fail("2.0", e);
- }
-}
-/**
- * Sets the workspace autobuilding to the desired value.
- */
-protected void setAutoBuilding(boolean value) throws CoreException {
- IWorkspace workspace = getWorkspace();
- if (workspace.isAutoBuilding() == value)
- return;
- IWorkspaceDescription desc = workspace.getDescription();
- desc.setAutoBuilding(value);
- workspace.setDescription(desc);
-}
-public void test1() {
- SaveManager1Test test = new SaveManager1Test();
- test.saveWorkspace();
- test.testCreateMyProject();
- test.testCreateProject2();
- test.testAddSaveParticipant();
- test.testBuilder();
- test.saveWorkspace();
- test.testPostSave();
-
-}
-public void test2() {
- SaveManager2Test test = new SaveManager2Test();
- test.testVerifyRestoredWorkspace();
- test.testBuilder();
- test.testSaveParticipant();
- test.testVerifyProject2();
- test.saveWorkspace();
-}
-public void test3() {
- SaveManager3Test test = new SaveManager3Test();
- test.testSaveParticipant();
- test.testBuilder();
- test.cleanUp();
-}
-protected void touch(IProject project) throws CoreException {
- project.accept(new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- if (resource.getType() == IResource.FILE) {
- resource.touch(null);
- return false;
- }
- return true;
- }
- });
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources.saveparticipant1/.classpath b/tests/org.eclipse.core.tests.resources.saveparticipant1/.classpath
deleted file mode 100644
index 065ac06..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant1/.classpath
+++ /dev/null
@@ -1,7 +0,0 @@
-<?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/tests/org.eclipse.core.tests.resources.saveparticipant1/.cvsignore b/tests/org.eclipse.core.tests.resources.saveparticipant1/.cvsignore
deleted file mode 100644
index c5e82d7..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant1/.cvsignore
+++ /dev/null
@@ -1 +0,0 @@
-bin
\ No newline at end of file
diff --git a/tests/org.eclipse.core.tests.resources.saveparticipant1/.project b/tests/org.eclipse.core.tests.resources.saveparticipant1/.project
deleted file mode 100644
index c926019..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant1/.project
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.eclipse.core.tests.resources.saveparticipant1</name>
- <comment></comment>
- <projects>
- <project>org.eclipse.core.boot</project>
- <project>org.eclipse.core.resources</project>
- <project>org.eclipse.core.runtime</project>
- <project>org.eclipse.core.runtime.compatibility</project>
- <project>org.eclipse.core.tests.harness</project>
- <project>org.eclipse.core.tests.resources</project>
- <project>org.junit</project>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
diff --git a/tests/org.eclipse.core.tests.resources.saveparticipant1/about.html b/tests/org.eclipse.core.tests.resources.saveparticipant1/about.html
deleted file mode 100644
index 9db411a..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant1/about.html
+++ /dev/null
@@ -1,30 +0,0 @@
-<!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 ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the
-Common Public License Version 1.0 ("CPL"). 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, "Program" 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 ("Other License"), any modifications, enhancements and/or
-other code and/or documentation ("Modifications") 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/tests/org.eclipse.core.tests.resources.saveparticipant1/build.properties b/tests/org.eclipse.core.tests.resources.saveparticipant1/build.properties
deleted file mode 100644
index 485f4c4..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant1/build.properties
+++ /dev/null
@@ -1,3 +0,0 @@
-source.saveparticipant1.jar=src/
-bin.includes=plugin.xml,*.jar,about.xml
-
diff --git a/tests/org.eclipse.core.tests.resources.saveparticipant1/plugin.xml b/tests/org.eclipse.core.tests.resources.saveparticipant1/plugin.xml
deleted file mode 100644
index 1c075e9..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant1/plugin.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.0"?>
-<plugin
- name="Save Participant 1"
- id="org.eclipse.core.tests.resources.saveparticipant1"
- class="org.eclipse.core.tests.resources.saveparticipant1.SaveParticipant1Plugin"
- version="2.1.0"
- provider-name="Eclipse.org">
-
- <requires>
- <import plugin="org.eclipse.core.resources"/>
- <import plugin="org.eclipse.core.tests.resources"/>
- <import plugin="org.eclipse.core.runtime.compatibility"/>
- <import plugin="org.junit"/>
- </requires>
-
- <runtime>
- <library name="saveparticipant1.jar">
- <export name="*" />
- </library>
- </runtime>
-</plugin>
diff --git a/tests/org.eclipse.core.tests.resources.saveparticipant1/src/org/eclipse/core/tests/resources/saveparticipant1/SaveParticipant1Plugin.java b/tests/org.eclipse.core.tests.resources.saveparticipant1/src/org/eclipse/core/tests/resources/saveparticipant1/SaveParticipant1Plugin.java
deleted file mode 100644
index 6f1d956..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant1/src/org/eclipse/core/tests/resources/saveparticipant1/SaveParticipant1Plugin.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/**********************************************************************
- * Copyright (c) 2002 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 - Initial API and implementation
- **********************************************************************/
-package org.eclipse.core.tests.resources.saveparticipant1;
-
-import java.io.*;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.resources.ResourceDeltaVerifier;
-/**
- * This plugin was designed to test the save facility provided by the ResourcesPlugin.
- * So, it does not act by itself. Another plugin (like a test) needs to call its methods in order
- * to something happen (like add it as a save participant, provide the expected values and so on...).
- */
-public class SaveParticipant1Plugin extends Plugin implements ISaveParticipant {
- /** expected values */
- private ResourceDeltaVerifier deltaVerifier;
- private int expectedPreviousSaveNumber;
- private int saveKind;
-
- /** lifecycle log */
- protected MultiStatus saveLifecycleLog;
-
- /** constants */
- private static final String SAVE_NUMBER_LOCATION = "saveNumber";
-public SaveParticipant1Plugin(IPluginDescriptor descriptor) {
- super(descriptor);
- deltaVerifier = new ResourceDeltaVerifier();
-}
-public void addExpectedChange(IResource resource, int status, int changeFlags) {
- deltaVerifier.addExpectedChange(resource, status, changeFlags);
-}
-public void addExpectedChange(IResource resource, IResource topLevelParent, int status, int changeFlags) {
- deltaVerifier.addExpectedChange(resource, topLevelParent, status, changeFlags);
-}
-public void deregisterAsSaveParticipant() {
- getWorkspace().removeSaveParticipant(this);
-}
-public void doneSaving(ISaveContext context) {
- try {
- writeExpectedSaveNumber(context.getSaveNumber());
- } catch (Exception e) {
- e.printStackTrace(System.out);
- }
-}
-private String getMessage(int expectedPreviousSaveNumber, int previousSaveNumber) {
- StringBuffer message = new StringBuffer();
- message.append("Expected previous saved id was: ");
- message.append(expectedPreviousSaveNumber);
- message.append("\nPrevious saved id is: ");
- message.append(previousSaveNumber);
- message.append("\n");
- return message.toString();
-}
-public String getPluginId() {
- return getDescriptor().getUniqueIdentifier();
-}
-/**
- * @return a status indicating any problem during the save lifecycle of this plugin.
- */
-public IStatus getSaveLifecycleLog() {
- return saveLifecycleLog;
-}
-private IWorkspace getWorkspace() {
- return ResourcesPlugin.getWorkspace();
-}
-public void prepareToSave(ISaveContext context) throws CoreException {
- resetSaveLifecycleLog();
- IStatus status = validate(context);
- if (!status.isOK())
- saveLifecycleLog.addAll(status);
- context.needDelta();
- context.needSaveNumber();
-}
-/**
- * We do not care about deltas, only saved id.
- */
-private void readExpectedSavedNumber() {
- IPath location = getStateLocation().append(SAVE_NUMBER_LOCATION);
- try {
- DataInputStream input = new DataInputStream(new FileInputStream(location.toOSString()));
- try {
- expectedPreviousSaveNumber = input.readInt();
- } finally {
- input.close();
- }
- } catch (IOException e) {
- expectedPreviousSaveNumber = 0;
- }
-}
-/**
- * @return a status indicating if the ISavedState is the expected one or not.
- */
-public IStatus registerAsSaveParticipant() throws CoreException {
- ISavedState state = getWorkspace().addSaveParticipant(this, this);
- readExpectedSavedNumber();
- return validate(state);
-}
-public void resetDeltaVerifier() {
- deltaVerifier.reset();
-}
-private void resetSaveLifecycleLog() {
- String message = "save lifecycle log for SaveParticipantPlugin";
- saveLifecycleLog = new MultiStatus(getPluginId(), Status.OK, message, null);
-}
-public void rollback(ISaveContext context) {
-}
-public void saving(ISaveContext context) throws CoreException {
-}
-public void setExpectedSaveKind(int saveKind) {
- this.saveKind = saveKind;
-}
-private IStatus validate(ISaveContext context) {
- // previous saved id
- if (context.getPreviousSaveNumber() != 0 || expectedPreviousSaveNumber != 0) {
- try {
- // Test if id is different than expected. Also, catch NullPointerException
- // in cases we do not expect any of the ids to be null.
- if (context.getPreviousSaveNumber() != expectedPreviousSaveNumber) {
- String message = getMessage(expectedPreviousSaveNumber, context.getPreviousSaveNumber());
- return new Status(Status.ERROR, getPluginId(), Status.ERROR, message, null);
- }
- } catch (NullPointerException e) {
- String message = getMessage(expectedPreviousSaveNumber, context.getPreviousSaveNumber());
- return new Status(Status.ERROR, getPluginId(), Status.ERROR, message, e);
- }
- }
- // save kind
- if (context.getKind() != saveKind) {
- String message = "Save kind was different than expected.";
- return new Status(Status.ERROR, getPluginId(), Status.ERROR, message, null);
- }
- return new Status(Status.OK, getPluginId(), Status.OK, "OK", null);
-}
-private IStatus validate(ISavedState state) {
- if (state == null && expectedPreviousSaveNumber == 0)
- return new Status(Status.OK, getPluginId(), Status.OK, "OK", null);
- try {
- // Test if id or delta are different than expected. Also, catch NullPointerException
- // in cases we do not expect any of the states to be null.
- state.processResourceChangeEvents(deltaVerifier);
- if (state.getSaveNumber() != expectedPreviousSaveNumber) {
- String message = "saved id is different than expected";
- return new Status(Status.ERROR, getPluginId(), Status.ERROR, message, null);
- }
- if (!deltaVerifier.isDeltaValid()) {
- String message = "delta is different than expected\n";
- message = message + deltaVerifier.getMessage();
- return new Status(Status.ERROR, getPluginId(), Status.ERROR, message, null);
- }
- } catch (NullPointerException e) {
- String message = "ISavedState is different than expected";
- return new Status(Status.ERROR, getPluginId(), Status.ERROR, message, e);
- }
- return new Status(Status.OK, getPluginId(), Status.OK, "OK", null);
-}
-/**
- * We do not care about deltas, only save number.
- */
-private void writeExpectedSaveNumber(int saveNumber) throws IOException {
- IPath location = getStateLocation().append(SAVE_NUMBER_LOCATION);
- DataOutputStream output = new DataOutputStream(new FileOutputStream(location.toOSString()));
- try {
- output.writeInt(saveNumber);
- } finally {
- output.close();
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources.saveparticipant2/.classpath b/tests/org.eclipse.core.tests.resources.saveparticipant2/.classpath
deleted file mode 100644
index 065ac06..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant2/.classpath
+++ /dev/null
@@ -1,7 +0,0 @@
-<?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/tests/org.eclipse.core.tests.resources.saveparticipant2/.cvsignore b/tests/org.eclipse.core.tests.resources.saveparticipant2/.cvsignore
deleted file mode 100644
index c5e82d7..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant2/.cvsignore
+++ /dev/null
@@ -1 +0,0 @@
-bin
\ No newline at end of file
diff --git a/tests/org.eclipse.core.tests.resources.saveparticipant2/.project b/tests/org.eclipse.core.tests.resources.saveparticipant2/.project
deleted file mode 100644
index e966917..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant2/.project
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.eclipse.core.tests.resources.saveparticipant2</name>
- <comment></comment>
- <projects>
- <project>org.eclipse.core.boot</project>
- <project>org.eclipse.core.resources</project>
- <project>org.eclipse.core.runtime</project>
- <project>org.eclipse.core.runtime.compatibility</project>
- <project>org.eclipse.core.tests.harness</project>
- <project>org.eclipse.core.tests.resources</project>
- <project>org.junit</project>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
diff --git a/tests/org.eclipse.core.tests.resources.saveparticipant2/about.html b/tests/org.eclipse.core.tests.resources.saveparticipant2/about.html
deleted file mode 100644
index 9db411a..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant2/about.html
+++ /dev/null
@@ -1,30 +0,0 @@
-<!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 ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the
-Common Public License Version 1.0 ("CPL"). 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, "Program" 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 ("Other License"), any modifications, enhancements and/or
-other code and/or documentation ("Modifications") 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/tests/org.eclipse.core.tests.resources.saveparticipant2/build.properties b/tests/org.eclipse.core.tests.resources.saveparticipant2/build.properties
deleted file mode 100644
index f5a40e0..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant2/build.properties
+++ /dev/null
@@ -1,3 +0,0 @@
-source.saveparticipant2.jar=src/
-bin.includes=plugin.xml,*.jar,about.xml
-
diff --git a/tests/org.eclipse.core.tests.resources.saveparticipant2/plugin.xml b/tests/org.eclipse.core.tests.resources.saveparticipant2/plugin.xml
deleted file mode 100644
index 96ff831..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant2/plugin.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.0"?>
-<plugin
- name="Save Participant 2"
- id="org.eclipse.core.tests.resources.saveparticipant2"
- class="org.eclipse.core.tests.resources.saveparticipant2.SaveParticipant2Plugin"
- version="2.1.0"
- provider-name="Eclipse.org">
-
- <requires>
- <import plugin="org.eclipse.core.resources"/>
- <import plugin="org.eclipse.core.tests.resources"/>
- <import plugin="org.eclipse.core.runtime.compatibility"/>
- <import plugin="org.junit"/>
- </requires>
-
- <runtime>
- <library name="saveparticipant2.jar">
- <export name="*" />
- </library>
- </runtime>
-</plugin>
diff --git a/tests/org.eclipse.core.tests.resources.saveparticipant2/src/org/eclipse/core/tests/resources/saveparticipant2/SaveParticipant2Plugin.java b/tests/org.eclipse.core.tests.resources.saveparticipant2/src/org/eclipse/core/tests/resources/saveparticipant2/SaveParticipant2Plugin.java
deleted file mode 100644
index adc775b..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant2/src/org/eclipse/core/tests/resources/saveparticipant2/SaveParticipant2Plugin.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/**********************************************************************
- * Copyright (c) 2002 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 - Initial API and implementation
- **********************************************************************/
-package org.eclipse.core.tests.resources.saveparticipant2;
-
-import java.io.*;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.resources.ResourceDeltaVerifier;
-/**
- * This plugin was designed to test the save facility provided by the ResourcesPlugin.
- * So, it does not act by itself. Another plugin (like a test) needs to call its methods in order
- * to something happen (like add it as a save participant, provide the expected values and so on...).
- */
-public class SaveParticipant2Plugin extends Plugin implements ISaveParticipant {
- /** expected values */
- private ResourceDeltaVerifier deltaVerifier;
- private int expectedPreviousSaveNumber;
- private int saveKind;
-
- /** lifecycle log */
- protected MultiStatus saveLifecycleLog;
-
- /** constants */
- private static final String SAVE_NUMBER_LOCATION = "saveNumber";
-public SaveParticipant2Plugin(IPluginDescriptor descriptor) {
- super(descriptor);
- deltaVerifier = new ResourceDeltaVerifier();
-}
-public void addExpectedChange(IResource[] resources, int status, int changeFlags) {
- deltaVerifier.addExpectedChange(resources, status, changeFlags);
-}
-public void addExpectedChange(IResource resource, int status, int changeFlags) {
- deltaVerifier.addExpectedChange(resource, status, changeFlags);
-}
-public void addExpectedChange(IResource resource, IResource topLevelParent, int status, int changeFlags) {
- deltaVerifier.addExpectedChange(resource, topLevelParent, status, changeFlags);
-}
-public void deregisterAsSaveParticipant() {
- getWorkspace().removeSaveParticipant(this);
-}
-public void doneSaving(ISaveContext context) {
- try {
- writeExpectedSaveNumber(context.getSaveNumber());
- } catch (Exception e) {
- e.printStackTrace(System.out);
- }
-}
-/**
- * Used to set the expected delta from the saved id.
- */
-public ResourceDeltaVerifier getDeltaVerifier() {
- return deltaVerifier;
-}
-private String getMessage(int expectedPreviousSaveNumber, int previousSaveNumber) {
- StringBuffer message = new StringBuffer();
- message.append("Expected previous saved id was: ");
- message.append(expectedPreviousSaveNumber);
- message.append("\nPrevious saved id is: ");
- message.append(previousSaveNumber);
- message.append("\n");
- return message.toString();
-}
-public String getPluginId() {
- return getDescriptor().getUniqueIdentifier();
-}
-/**
- * @return a status indicating any problem during the save lifecycle of this plugin.
- */
-public IStatus getSaveLifecycleLog() {
- return saveLifecycleLog;
-}
-private IWorkspace getWorkspace() {
- return ResourcesPlugin.getWorkspace();
-}
-public void prepareToSave(ISaveContext context) throws CoreException {
- resetSaveLifecycleLog();
- IStatus status = validate(context);
- if (!status.isOK())
- saveLifecycleLog.addAll(status);
- context.needDelta();
- context.needSaveNumber();
-}
-/**
- * We do not care about deltas, only saved id.
- */
-private void readExpectedSavedNumber() {
- IPath location = getStateLocation().append(SAVE_NUMBER_LOCATION);
- try {
- DataInputStream input = new DataInputStream(new FileInputStream(location.toOSString()));
- try {
- expectedPreviousSaveNumber = input.readInt();
- } finally {
- input.close();
- }
- } catch (IOException e) {
- expectedPreviousSaveNumber = 0;
- }
-}
-/**
- * @return a status indicating if the ISavedState is the expected one or not.
- */
-public IStatus registerAsSaveParticipant() throws CoreException {
- ISavedState state = getWorkspace().addSaveParticipant(this, this);
- readExpectedSavedNumber();
- return validate(state);
-}
-public void resetDeltaVerifier() {
- deltaVerifier.reset();
-}
-protected void resetSaveLifecycleLog() {
- String message = "save lifecycle log for SaveParticipantPlugin";
- saveLifecycleLog = new MultiStatus(getPluginId(), Status.OK, message, null);
-}
-public void rollback(ISaveContext context) {
-}
-public void saving(ISaveContext context) throws CoreException {
-}
-public void setExpectedSaveKind(int saveKind) {
- this.saveKind = saveKind;
-}
-private IStatus validate(ISaveContext context) {
- // previous saved id
- if (context.getPreviousSaveNumber() != 0 || expectedPreviousSaveNumber != 0) {
- try {
- // Test if id is different than expected. Also, catch NullPointerException
- // in cases we do not expect any of the ids to be null.
- if (context.getPreviousSaveNumber() != expectedPreviousSaveNumber) {
- String message = getMessage(expectedPreviousSaveNumber, context.getPreviousSaveNumber());
- return new Status(Status.ERROR, getPluginId(), Status.ERROR, message, null);
- }
- } catch (NullPointerException e) {
- String message = getMessage(expectedPreviousSaveNumber, context.getPreviousSaveNumber());
- return new Status(Status.ERROR, getPluginId(), Status.ERROR, message, e);
- }
- }
- // save kind
- if (context.getKind() != saveKind) {
- String message = "Save kind was different than expected.";
- return new Status(Status.ERROR, getPluginId(), Status.ERROR, message, null);
- }
- return new Status(Status.OK, getPluginId(), Status.OK, "OK", null);
-}
-private IStatus validate(ISavedState state) {
- if (state == null && expectedPreviousSaveNumber == 0)
- return new Status(Status.OK, getPluginId(), Status.OK, "OK", null);
- try {
- // Test if id or delta are different than expected. Also, catch NullPointerException
- // in cases we do not expect any of the states to be null.
- state.processResourceChangeEvents(deltaVerifier);
- if (state.getSaveNumber() != expectedPreviousSaveNumber) {
- String message = "saved id is different than expected";
- return new Status(Status.ERROR, getPluginId(), Status.ERROR, message, null);
- }
- if (!deltaVerifier.isDeltaValid()) {
- String message = "delta is different than expected\n";
- message = message + deltaVerifier.getMessage();
- return new Status(Status.ERROR, getPluginId(), Status.ERROR, message, null);
- }
- } catch (NullPointerException e) {
- String message = "ISavedState is different than expected";
- return new Status(Status.ERROR, getPluginId(), Status.ERROR, message, e);
- }
- return new Status(Status.OK, getPluginId(), Status.OK, "OK", null);
-}
-/**
- * We do not care about deltas, only save number.
- */
-private void writeExpectedSaveNumber(int saveNumber) throws IOException {
- IPath location = getStateLocation().append(SAVE_NUMBER_LOCATION);
- DataOutputStream output = new DataOutputStream(new FileOutputStream(location.toOSString()));
- try {
- output.writeInt(saveNumber);
- } finally {
- output.close();
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources.saveparticipant3/.classpath b/tests/org.eclipse.core.tests.resources.saveparticipant3/.classpath
deleted file mode 100644
index 065ac06..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant3/.classpath
+++ /dev/null
@@ -1,7 +0,0 @@
-<?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/tests/org.eclipse.core.tests.resources.saveparticipant3/.cvsignore b/tests/org.eclipse.core.tests.resources.saveparticipant3/.cvsignore
deleted file mode 100644
index c5e82d7..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant3/.cvsignore
+++ /dev/null
@@ -1 +0,0 @@
-bin
\ No newline at end of file
diff --git a/tests/org.eclipse.core.tests.resources.saveparticipant3/.project b/tests/org.eclipse.core.tests.resources.saveparticipant3/.project
deleted file mode 100644
index 51d3195..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant3/.project
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.eclipse.core.tests.resources.saveparticipant3</name>
- <comment></comment>
- <projects>
- <project>org.eclipse.core.boot</project>
- <project>org.eclipse.core.resources</project>
- <project>org.eclipse.core.runtime</project>
- <project>org.eclipse.core.runtime.compatibility</project>
- <project>org.eclipse.core.tests.harness</project>
- <project>org.eclipse.core.tests.resources</project>
- <project>org.junit</project>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
diff --git a/tests/org.eclipse.core.tests.resources.saveparticipant3/about.html b/tests/org.eclipse.core.tests.resources.saveparticipant3/about.html
deleted file mode 100644
index 9db411a..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant3/about.html
+++ /dev/null
@@ -1,30 +0,0 @@
-<!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 ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the
-Common Public License Version 1.0 ("CPL"). 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, "Program" 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 ("Other License"), any modifications, enhancements and/or
-other code and/or documentation ("Modifications") 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/tests/org.eclipse.core.tests.resources.saveparticipant3/build.properties b/tests/org.eclipse.core.tests.resources.saveparticipant3/build.properties
deleted file mode 100644
index cbca661..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant3/build.properties
+++ /dev/null
@@ -1,2 +0,0 @@
-source.saveparticipant3.jar=src/
-bin.includes=plugin.xml,*.jar,about.xml
diff --git a/tests/org.eclipse.core.tests.resources.saveparticipant3/plugin.xml b/tests/org.eclipse.core.tests.resources.saveparticipant3/plugin.xml
deleted file mode 100644
index 4c17ec3..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant3/plugin.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.0"?>
-<plugin
- name="Save Participant 3"
- id="org.eclipse.core.tests.resources.saveparticipant3"
- class="org.eclipse.core.tests.resources.saveparticipant3.SaveParticipant3Plugin"
- version="2.1.0"
- provider-name="Eclipse.org">
-
- <requires>
- <import plugin="org.eclipse.core.resources"/>
- <import plugin="org.eclipse.core.runtime.compatibility"/>
- <import plugin="org.eclipse.core.tests.resources"/>
- <import plugin="org.junit"/>
- </requires>
-
- <runtime>
- <library name="saveparticipant3.jar">
- <export name="*" />
- </library>
- </runtime>
-</plugin>
diff --git a/tests/org.eclipse.core.tests.resources.saveparticipant3/src/org/eclipse/core/tests/resources/saveparticipant3/SaveParticipant3Plugin.java b/tests/org.eclipse.core.tests.resources.saveparticipant3/src/org/eclipse/core/tests/resources/saveparticipant3/SaveParticipant3Plugin.java
deleted file mode 100644
index 633ad24..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant3/src/org/eclipse/core/tests/resources/saveparticipant3/SaveParticipant3Plugin.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2002 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v0.5
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v05.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- ******************************************************************************/
-package org.eclipse.core.tests.resources.saveparticipant3;
-
-import org.eclipse.core.resources.ISaveContext;
-import org.eclipse.core.runtime.*;
-/**
- * This plugin is intended to the .safetable of config files.
- */
-public class SaveParticipant3Plugin extends SaveParticipantPlugin {
- protected boolean shouldFail = false;
- protected static final String file1 = "file_1";
-public SaveParticipant3Plugin(IPluginDescriptor descriptor) {
- super(descriptor);
-}
-protected IPath getFilePath(String name) {
- return getStateLocation().append(name);
-}
-protected IPath getRealPath(String name, int saveNumber) {
- return getFilePath(name + "." + saveNumber);
-}
-public void prepareToSave(ISaveContext context) throws CoreException {
- resetSaveLifecycleLog();
- context.needSaveNumber();
- IPath file = getFilePath(file1);
- if (context.lookup(file) != null) {
- validate(context);
- shouldFail = true;
- return;
- }
- IPath realPath = getRealPath(file1, context.getSaveNumber());
- context.map(file, realPath);
-}
-public void rollback(ISaveContext context) {
-}
-public void saving(ISaveContext context) throws CoreException {
- if (shouldFail)
- throw new CoreException(new Status(0, getDescriptor().getUniqueIdentifier(), 0, "fake failure", null));
-}
-protected void validate(ISaveContext context) {
- IPath file = getFilePath(file1);
- IPath realPath = getRealPath(file1, context.getPreviousSaveNumber());
- IPath value = context.lookup(file);
- if (value != null && value.equals(realPath))
- return;
- String message = "Name of configuration file is different than expected.";
- saveLifecycleLog.add(new Status(IStatus.ERROR, getDescriptor().getUniqueIdentifier(), 111, message, null));
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources.saveparticipant3/src/org/eclipse/core/tests/resources/saveparticipant3/SaveParticipantPlugin.java b/tests/org.eclipse.core.tests.resources.saveparticipant3/src/org/eclipse/core/tests/resources/saveparticipant3/SaveParticipantPlugin.java
deleted file mode 100644
index 6550b37..0000000
--- a/tests/org.eclipse.core.tests.resources.saveparticipant3/src/org/eclipse/core/tests/resources/saveparticipant3/SaveParticipantPlugin.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/**********************************************************************
- * Copyright (c) 2002 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 - Initial API and implementation
- **********************************************************************/
-package org.eclipse.core.tests.resources.saveparticipant3;
-
-import java.io.*;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.resources.ResourceDeltaVerifier;
-/**
- * This plugin was designed to test the save facility provided by the ResourcesPlugin.
- * So, it does not act by itself. Another plugin (like a test) needs to call its methods in order
- * to something happen (like add it as a save participant, provide the expected values and so on...).
- */
-public class SaveParticipantPlugin extends Plugin implements ISaveParticipant {
- /** expected values */
- private ResourceDeltaVerifier deltaVerifier;
- private int expectedPreviousSaveNumber;
- private int saveKind;
-
- /** lifecycle log */
- protected MultiStatus saveLifecycleLog;
-
- /** constants */
- private static final String SAVE_NUMBER_LOCATION = "saveNumber";
-public SaveParticipantPlugin(IPluginDescriptor descriptor) {
- super(descriptor);
- deltaVerifier = new ResourceDeltaVerifier();
-}
-public void deregisterAsSaveParticipant() {
- getWorkspace().removeSaveParticipant(this);
-}
-public void doneSaving(ISaveContext context) {
- try {
- writeExpectedSaveNumber(context.getSaveNumber());
- } catch (Exception e) {
- e.printStackTrace(System.out);
- }
-}
-/**
- * Used to set the expected delta from the saved id.
- */
-public ResourceDeltaVerifier getDeltaVerifier() {
- return deltaVerifier;
-}
-private String getMessage(int expectedPreviousSaveNumber, int previousSaveNumber) {
- StringBuffer message = new StringBuffer();
- message.append("Expected previous saved id was: ");
- message.append(expectedPreviousSaveNumber);
- message.append("\nPrevious saved id is: ");
- message.append(previousSaveNumber);
- message.append("\n");
- return message.toString();
-}
-public String getPluginId() {
- return getDescriptor().getUniqueIdentifier();
-}
-/**
- * @return a status indicating any problem during the save lifecycle of this plugin.
- */
-public IStatus getSaveLifecycleLog() {
- return saveLifecycleLog;
-}
-private IWorkspace getWorkspace() {
- return ResourcesPlugin.getWorkspace();
-}
-public void prepareToSave(ISaveContext context) throws CoreException {
- resetSaveLifecycleLog();
- IStatus status = validate(context);
- if (!status.isOK())
- saveLifecycleLog.addAll(status);
- context.needDelta();
- context.needSaveNumber();
-}
-/**
- * We do not care about deltas, only saved id.
- */
-private void readExpectedSavedNumber() {
- IPath location = getStateLocation().append(SAVE_NUMBER_LOCATION);
- try {
- DataInputStream input = new DataInputStream(new FileInputStream(location.toOSString()));
- try {
- expectedPreviousSaveNumber = input.readInt();
- } finally {
- input.close();
- }
- } catch (IOException e) {
- expectedPreviousSaveNumber = 0;
- }
-}
-/**
- * @return a status indicating if the ISavedState is the expected one or not.
- */
-public IStatus registerAsSaveParticipant() throws CoreException {
- ISavedState state = getWorkspace().addSaveParticipant(this, this);
- readExpectedSavedNumber();
- return validate(state);
-}
-protected void resetSaveLifecycleLog() {
- String message = "save lifecycle log for SaveParticipantPlugin";
- saveLifecycleLog = new MultiStatus(getPluginId(), Status.OK, message, null);
-}
-public void rollback(ISaveContext context) {
-}
-public void saving(ISaveContext context) throws CoreException {
-}
-public void setExpectedSaveKind(int saveKind) {
- this.saveKind = saveKind;
-}
-private IStatus validate(ISaveContext context) {
- // previous saved id
- if (context.getPreviousSaveNumber() != 0 || expectedPreviousSaveNumber != 0) {
- try {
- // Test if id is different than expected. Also, catch NullPointerException
- // in cases we do not expect any of the ids to be null.
- if (context.getPreviousSaveNumber() != expectedPreviousSaveNumber) {
- String message = getMessage(expectedPreviousSaveNumber, context.getPreviousSaveNumber());
- return new Status(Status.ERROR, getPluginId(), Status.ERROR, message, null);
- }
- } catch (NullPointerException e) {
- String message = getMessage(expectedPreviousSaveNumber, context.getPreviousSaveNumber());
- return new Status(Status.ERROR, getPluginId(), Status.ERROR, message, e);
- }
- }
- // save kind
- if (context.getKind() != saveKind) {
- String message = "Save kind was different than expected.";
- return new Status(Status.ERROR, getPluginId(), Status.ERROR, message, null);
- }
- return new Status(Status.OK, getPluginId(), Status.OK, "OK", null);
-}
-private IStatus validate(ISavedState state) {
- if (state == null && expectedPreviousSaveNumber == 0)
- return new Status(Status.OK, getPluginId(), Status.OK, "OK", null);
- try {
- // Test if id or delta are different than expected. Also, catch NullPointerException
- // in cases we do not expect any of the states to be null.
- state.processResourceChangeEvents(deltaVerifier);
- if (state.getSaveNumber() != expectedPreviousSaveNumber) {
- String message = "saved id is different than expected";
- return new Status(Status.ERROR, getPluginId(), Status.ERROR, message, null);
- }
- if (!deltaVerifier.isDeltaValid()) {
- String message = "delta is different than expected\n";
- message = message + deltaVerifier.getMessage();
- return new Status(Status.ERROR, getPluginId(), Status.ERROR, message, null);
- }
- } catch (NullPointerException e) {
- String message = "ISavedState is different than expected";
- return new Status(Status.ERROR, getPluginId(), Status.ERROR, message, e);
- }
- return new Status(Status.OK, getPluginId(), Status.OK, "OK", null);
-}
-/**
- * We do not care about deltas, only save number.
- */
-private void writeExpectedSaveNumber(int saveNumber) throws IOException {
- IPath location = getStateLocation().append(SAVE_NUMBER_LOCATION);
- DataOutputStream output = new DataOutputStream(new FileOutputStream(location.toOSString()));
- try {
- output.writeInt(saveNumber);
- } finally {
- output.close();
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/.classpath b/tests/org.eclipse.core.tests.resources/.classpath
deleted file mode 100644
index 065ac06..0000000
--- a/tests/org.eclipse.core.tests.resources/.classpath
+++ /dev/null
@@ -1,7 +0,0 @@
-<?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/tests/org.eclipse.core.tests.resources/.cvsignore b/tests/org.eclipse.core.tests.resources/.cvsignore
deleted file mode 100644
index c5e82d7..0000000
--- a/tests/org.eclipse.core.tests.resources/.cvsignore
+++ /dev/null
@@ -1 +0,0 @@
-bin
\ No newline at end of file
diff --git a/tests/org.eclipse.core.tests.resources/.project b/tests/org.eclipse.core.tests.resources/.project
deleted file mode 100644
index f35a8f8..0000000
--- a/tests/org.eclipse.core.tests.resources/.project
+++ /dev/null
@@ -1,33 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.eclipse.core.tests.resources</name>
- <comment></comment>
- <projects>
- <project>org.eclipse.core.boot</project>
- <project>org.eclipse.core.resources</project>
- <project>org.eclipse.core.runtime.compatibility</project>
- <project>org.eclipse.core.tests.harness</project>
- <project>org.junit</project>
- </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.jdt.core.javanature</nature>
- <nature>org.eclipse.pde.PluginNature</nature>
- </natures>
-</projectDescription>
diff --git a/tests/org.eclipse.core.tests.resources/MultipleProjectTestFiles/abc.project b/tests/org.eclipse.core.tests.resources/MultipleProjectTestFiles/abc.project
deleted file mode 100644
index 92d2758..0000000
--- a/tests/org.eclipse.core.tests.resources/MultipleProjectTestFiles/abc.project
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>abc.project</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
- <linkedResources>
- <link>
- <name>newLink</name>
- <type>2</type>
- <location>d:/abc/def</location>
- </link>
- </linkedResources>
-</projectDescription>
diff --git a/tests/org.eclipse.core.tests.resources/MultipleProjectTestFiles/def.project b/tests/org.eclipse.core.tests.resources/MultipleProjectTestFiles/def.project
deleted file mode 100644
index 648b546..0000000
--- a/tests/org.eclipse.core.tests.resources/MultipleProjectTestFiles/def.project
+++ /dev/null
@@ -1,39 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>def.project</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
- <linkedResources>
- <link>
- <name>newLink</name>
- <type>2</type>
- <location>d:/abc/def</location>
- </link>
- <link>
- <name>link2</name>
- <type>2</type>
- <location>d:/abc</location>
- </link>
- <link>
- <name>link3</name>
- <type>2</type>
- <location>d:/abc/def/ghi</location>
- </link>
- <link>
- <name>link4</name>
- <type>1</type>
- <location>d:/abc/def/afile.txt</location>
- </link>
- </linkedResources>
-</projectDescription>
diff --git a/tests/org.eclipse.core.tests.resources/MultipleProjectTestFiles/org.apache.lucene.project b/tests/org.eclipse.core.tests.resources/MultipleProjectTestFiles/org.apache.lucene.project
deleted file mode 100644
index 798846e..0000000
--- a/tests/org.eclipse.core.tests.resources/MultipleProjectTestFiles/org.apache.lucene.project
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.apache.lucene.project</name>
- <comment></comment>
- <projects>
- <project>org.eclipse.core.boot</project>
- <project>org.eclipse.core.runtime</project>
- </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.jdt.core.javanature</nature>
- <nature>org.eclipse.pde.PluginNature</nature>
- </natures>
-</projectDescription>
diff --git a/tests/org.eclipse.core.tests.resources/MultipleProjectTestFiles/org.eclipse.ant.core.project b/tests/org.eclipse.core.tests.resources/MultipleProjectTestFiles/org.eclipse.ant.core.project
deleted file mode 100644
index 8b726b8..0000000
--- a/tests/org.eclipse.core.tests.resources/MultipleProjectTestFiles/org.eclipse.ant.core.project
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.eclipse.ant.core.project</name>
- <comment></comment>
- <projects>
- <project>org.apache.ant</project>
- <project>org.apache.xerces</project>
- <project>org.eclipse.core.boot</project>
- <project>org.eclipse.core.runtime</project>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
- <arguments>
- <dictionary>
- <key>!{tool_show_log}</key>
- <value>true</value>
- </dictionary>
- <dictionary>
- <key>!{tool_refresh}</key>
- <value>${none}</value>
- </dictionary>
- <dictionary>
- <key>!{tool_name}</key>
- <value>org.eclipse.ant.core extra builder</value>
- </dictionary>
- <dictionary>
- <key>!{tool_dir}</key>
- <value></value>
- </dictionary>
- <dictionary>
- <key>!{tool_args}</key>
- <value>-DbuildType=${build_type}</value>
- </dictionary>
- <dictionary>
- <key>!{tool_loc}</key>
- <value>${workspace_loc:/org.eclipse.ant.core/scripts/buildExtraJAR.xml}</value>
- </dictionary>
- <dictionary>
- <key>!{tool_type}</key>
- <value>org.eclipse.ui.externaltools.type.ant</value>
- </dictionary>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
diff --git a/tests/org.eclipse.core.tests.resources/about.html b/tests/org.eclipse.core.tests.resources/about.html
deleted file mode 100644
index 9db411a..0000000
--- a/tests/org.eclipse.core.tests.resources/about.html
+++ /dev/null
@@ -1,30 +0,0 @@
-<!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 ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the
-Common Public License Version 1.0 ("CPL"). 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, "Program" 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 ("Other License"), any modifications, enhancements and/or
-other code and/or documentation ("Modifications") 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/tests/org.eclipse.core.tests.resources/build.properties b/tests/org.eclipse.core.tests.resources/build.properties
deleted file mode 100644
index 2504131..0000000
--- a/tests/org.eclipse.core.tests.resources/build.properties
+++ /dev/null
@@ -1,13 +0,0 @@
-###############################################################################
-# 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
-###############################################################################
-source.resourcestests.jar=src/
-bin.includes=plugin.xml,*.jar,MultipleProjectTestFiles/,about.xml
-
diff --git a/tests/org.eclipse.core.tests.resources/plugin.xml b/tests/org.eclipse.core.tests.resources/plugin.xml
deleted file mode 100644
index 7760b2b..0000000
--- a/tests/org.eclipse.core.tests.resources/plugin.xml
+++ /dev/null
@@ -1,600 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.0"?>
-<plugin
- name="Eclipse Core Tests Resources"
- id="org.eclipse.core.tests.resources"
- version="3.0"
- provider-name="Eclipse.org">
-
- <requires>
- <import plugin="org.eclipse.core.runtime.compatibility"/>
- <import plugin="org.eclipse.core.resources"/>
- <import plugin="org.eclipse.core.tests.harness"/>
- <import plugin="org.junit"/>
- </requires>
-
- <runtime>
- <library name="resourcestests.jar">
- <export name="*"/>
- </library>
- </runtime>
-
- <extension id="transientmarker" point="org.eclipse.core.resources.markers">
- <super type="org.eclipse.core.resources.marker"/>
- </extension>
-
- <extension point="org.eclipse.core.tests.harness.tests">
-
- <test id="resources.AutomatedTests">
- <run class="org.eclipse.core.tests.resources.AutomatedTests"/>
- </test>
- <test id="resources.AllTests">
- <run class="org.eclipse.core.tests.resources.AllTests"/>
- </test>
- <test id="resources.TeamPrivateMemberTest">
- <run class="org.eclipse.core.tests.resources.TeamPrivateMemberTest"/>
- </test>
- <test id="resources.IFileTest">
- <run class="org.eclipse.core.tests.resources.IFileTest"/>
- </test>
- <test id="resources.IFolderTest">
- <run class="org.eclipse.core.tests.resources.IFolderTest"/>
- </test>
- <test id="resources.IProjectTest">
- <run class="org.eclipse.core.tests.resources.IProjectTest"/>
- </test>
- <test id="resources.IPathVariableTest">
- <run class="org.eclipse.core.tests.resources.IPathVariableTest"/>
- </test>
- <test id="resources.IResourceChangeEventTest">
- <run class="org.eclipse.core.tests.resources.IResourceChangeEventTest"/>
- </test>
- <test id="resources.IResourceChangeListenerTest">
- <run class="org.eclipse.core.tests.resources.IResourceChangeListenerTest"/>
- </test>
- <test id="resources.IResourceDeltaTest">
- <run class="org.eclipse.core.tests.resources.IResourceDeltaTest"/>
- </test>
- <test id="resources.IResourceTest">
- <run class="org.eclipse.core.tests.resources.IResourceTest"/>
- </test>
- <test id="resources.ISynchronizerTest">
- <run class="org.eclipse.core.tests.resources.ISynchronizerTest"/>
- </test>
- <test id="resources.IWorkspaceTest">
- <run class="org.eclipse.core.tests.resources.IWorkspaceTest"/>
- </test>
- <test id="resources.IWorkspaceRootTest">
- <run class="org.eclipse.core.tests.resources.IWorkspaceRootTest"/>
- </test>
- <test id="resources.MarkerSetTest">
- <run class="org.eclipse.core.tests.resources.MarkerSetTest"/>
- </test>
- <test id="resources.MarkerTest">
- <run class="org.eclipse.core.tests.resources.MarkerTest"/>
- </test>
- <test id="resources.LinkedResourceTest">
- <run class="org.eclipse.core.tests.resources.LinkedResourceTest"/>
- </test>
- <test id="resources.LinkedResourceWithPathVariableTest">
- <run class="org.eclipse.core.tests.resources.LinkedResourceWithPathVariableTest"/>
- </test>
- <test id="resources.NatureTest">
- <run class="org.eclipse.core.tests.resources.NatureTest"/>
- </test>
- <test id="resources.ProjectOrderTest">
- <run class="org.eclipse.core.tests.resources.ProjectOrderTest"/>
- </test>
- <test id="resources.WorkspaceTest">
- <run class="org.eclipse.core.tests.resources.WorkspaceTest"/>
- </test>
- <test id="resources.ResourceMappingTest">
- <run class="org.eclipse.core.tests.resources.ResourceMappingTest"/>
- </test>
- <test id="resources.ResourceURLTest">
- <run class="org.eclipse.core.tests.resources.ResourceURLTest"/>
- </test>
-
- <test id="resources.performance.MarkerPerformanceTest">
- <run class="org.eclipse.core.tests.resources.perf.MarkerPerformanceTest"/>
- </test>
- <test id="resources.performance.BenchWorkspace">
- <run class="org.eclipse.core.tests.resources.perf.BenchWorkspace"/>
- </test>
- <test id="resources.performance.BenchMiscWorkspace">
- <run class="org.eclipse.core.tests.resources.perf.BenchMiscWorkspace"/>
- </test>
- <test id="resources.performance.WorkspacePerformanceTest">
- <run class="org.eclipse.core.tests.resources.perf.WorkspacePerformanceTest"/>
- </test>
-
- <test id="regression.AllTests">
- <run class="org.eclipse.core.tests.resources.regression.AllTests"/>
- </test>
- <test id="regression.IProjectTest">
- <run class="org.eclipse.core.tests.resources.regression.IProjectTest"/>
- </test>
- <test id="regression.IWorkspaceTest">
- <run class="org.eclipse.core.tests.resources.regression.IWorkspaceTest"/>
- </test>
- <test id="regression.IResourceTest">
- <run class="org.eclipse.core.tests.resources.regression.IResourceTest"/>
- </test>
- <test id="regression.LocalStoreRegressionTests">
- <run class="org.eclipse.core.tests.resources.regression.LocalStoreRegressionTests"/>
- </test>
- <test id="regression.NLTest">
- <run class="org.eclipse.core.tests.resources.regression.NLTest"/>
- </test>
- <test id="regression.Bug_6708">
- <run class="org.eclipse.core.tests.resources.regression.Bug_6708"/>
- </test>
- <test id="regression.Bug_27271">
- <run class="org.eclipse.core.tests.resources.regression.Bug_27271"/>
- </test>
- <test id="regression.Bug_26294">
- <run class="org.eclipse.core.tests.resources.regression.Bug_26294"/>
- </test>
- <test id="regression.IFileTest">
- <run class="org.eclipse.core.tests.resources.regression.IFileTest"/>
- </test>
- <test id="regression.IFolderTest">
- <run class="org.eclipse.core.tests.resources.regression.IFolderTest"/>
- </test>
- <test id="regression.PR_1GEAB3C_Test">
- <run class="org.eclipse.core.tests.resources.regression.PR_1GEAB3C_Test"/>
- </test>
- <test id="regression.PR_1G1N9GZ_1Test">
- <run class="org.eclipse.core.tests.resources.regression.PR_1G1N9GZ_1Test"/>
- </test>
- <test id="regression.PR_1G1N9GZ_2Test">
- <run class="org.eclipse.core.tests.resources.regression.PR_1G1N9GZ_2Test"/>
- </test>
- <test id="regression.PR_1GALH44_1Test">
- <run class="org.eclipse.core.tests.resources.regression.PR_1GALH44_1Test"/>
- </test>
- <test id="regression.PR_1GALH44_2Test">
- <run class="org.eclipse.core.tests.resources.regression.PR_1GALH44_2Test"/>
- </test>
- <test id="regression.PR_1GALH44_3Test">
- <run class="org.eclipse.core.tests.resources.regression.PR_1GALH44_3Test"/>
- </test>
- <test id="regression.PR_1GH2B0N_Test">
- <run class="org.eclipse.core.tests.resources.regression.PR_1GH2B0N_Test"/>
- </test>
- <test id="regression.PR_1GHOM0N_Test">
- <run class="org.eclipse.core.tests.resources.regression.PR_1GHOM0N_Test"/>
- </test>
- <test id="regression.Bug_29116">
- <run class="org.eclipse.core.tests.resources.regression.Bug_29116"/>
- </test>
- <test id="regression.Bug_25457">
- <run class="org.eclipse.core.tests.resources.regression.Bug_25457"/>
- </test>
- <test id="regression.Bug_32076">
- <run class="org.eclipse.core.tests.resources.regression.Bug_32076"/>
- </test>
-
- <test id = "org.eclipse.core.tests.resources.session.SampleSessionTest">
- <run class="org.eclipse.core.tests.resources.session.SampleSessionTest"/>
- </test>
- <test id = "org.eclipse.core.tests.resources.session.TestSave">
- <run class="org.eclipse.core.tests.resources.session.TestSave"/>
- </test>
- <test id = "org.eclipse.core.tests.resources.session.Test1G1N9GZ">
- <run class="org.eclipse.core.tests.resources.session.Test1G1N9GZ"/>
- </test>
- <test id = "org.eclipse.core.tests.resources.session.TestCloseNoSave">
- <run class="org.eclipse.core.tests.resources.session.TestCloseNoSave"/>
- </test>
- <test id = "org.eclipse.core.tests.resources.session.TestMultiSnap">
- <run class="org.eclipse.core.tests.resources.session.TestMultiSnap"/>
- </test>
- <test id = "org.eclipse.core.tests.resources.session.TestSaveCreateProject">
- <run class="org.eclipse.core.tests.resources.session.TestSaveCreateProject"/>
- </test>
- <test id = "org.eclipse.core.tests.resources.session.TestSaveSnap">
- <run class="org.eclipse.core.tests.resources.session.TestSaveSnap"/>
- </test>
- <test id = "org.eclipse.core.tests.resources.session.TestSaveWithClosedProject">
- <run class="org.eclipse.core.tests.resources.session.TestSaveWithClosedProject"/>
- </test>
- <test id = "org.eclipse.core.tests.resources.session.TestSnapSaveSnap">
- <run class="org.eclipse.core.tests.resources.session.TestSnapSaveSnap"/>
- </test>
- <test id = "org.eclipse.core.tests.resources.session.TestBug6995">
- <run class="org.eclipse.core.tests.resources.session.TestBug6995"/>
- </test>
- <test id = "org.eclipse.core.tests.resources.session.TestInterestingProjectPersistence">
- <run class="org.eclipse.core.tests.resources.session.TestInterestingProjectPersistence"/>
- </test>
- <test id = "org.eclipse.core.tests.resources.session.TestBuilderDeltaSerialization">
- <run class="org.eclipse.core.tests.resources.session.TestBuilderDeltaSerialization"/>
- </test>
- <test id = "org.eclipse.core.tests.resources.session.Test1GALH44">
- <run class="org.eclipse.core.tests.resources.session.Test1GALH44"/>
- </test>
- <test id = "org.eclipse.core.tests.resources.session.TestMissingBuilder">
- <run class="org.eclipse.core.tests.resources.session.TestMissingBuilder"/>
- </test>
- <test id = "org.eclipse.core.tests.resources.session.TestClosedProjectLocation">
- <run class="org.eclipse.core.tests.resources.session.TestClosedProjectLocation"/>
- </test>
- <test id = "org.eclipse.core.tests.resources.session.FindDeletedMembersTest">
- <run class="org.eclipse.core.tests.resources.session.FindDeletedMembersTest"/>
- </test>
- <test id = "org.eclipse.core.tests.resources.session.TestBug20127">
- <run class="org.eclipse.core.tests.resources.session.TestBug20127"/>
- </test>
- <test id = "org.eclipse.core.tests.resources.session.TestBug12575">
- <run class="org.eclipse.core.tests.resources.session.TestBug12575"/>
- </test>
- <test id = "org.eclipse.core.tests.resources.session.WorkspaceDescriptionTest">
- <run class="org.eclipse.core.tests.resources.session.WorkspaceDescriptionTest"/>
- </test>
- <test id = "org.eclipse.core.tests.resources.session.TestBug30015">
- <run class="org.eclipse.core.tests.resources.session.TestBug30015"/>
- </test>
- <test id = "org.eclipse.core.tests.resources.session.TestMasterTableCleanup">
- <run class="org.eclipse.core.tests.resources.session.TestMasterTableCleanup"/>
- </test>
-
- <test id="usecase.AllTests">
- <run class="org.eclipse.core.tests.resources.usecase.AllTests"/>
- </test>
- <test id="usecase.BuilderUseCaseTest">
- <run class="org.eclipse.core.tests.resources.usecase.BuilderUseCaseTest"/>
- </test>
- <test id="usecase.ConcurrencyPerformanceTest">
- <run class="org.eclipse.core.tests.resources.usecase.ConcurrencyPerformanceTest"/>
- </test>
- <test id="usecase.ConcurrencyTest">
- <run class="org.eclipse.core.tests.resources.usecase.ConcurrencyTest"/>
- </test>
- <test id="usecase.HistoryStorePerformanceTest">
- <run class="org.eclipse.core.tests.resources.usecase.HistoryStorePerformanceTest"/>
- </test>
- <test id="usecase.IFileTest">
- <run class="org.eclipse.core.tests.resources.usecase.IFileTest"/>
- </test>
- <test id="usecase.IFolderTest">
- <run class="org.eclipse.core.tests.resources.usecase.IFolderTest"/>
- </test>
- <test id="usecase.IProjectTest">
- <run class="org.eclipse.core.tests.resources.usecase.IProjectTest"/>
- </test>
- <test id="usecase.IWorkspaceRunnableUseCaseTest">
- <run class="org.eclipse.core.tests.resources.usecase.IWorkspaceRunnableUseCaseTest"/>
- </test>
- <test id = "org.eclipse.core.tests.resources.usecase.SnapshotTest">
- <run class="org.eclipse.core.tests.resources.usecase.SnapshotTest"/>
- </test>
-
- <test id="alias.AllTests">
- <run class="org.eclipse.core.tests.internal.alias.AllTests"/>
- </test>
- <test id="alias.BasicAliasTest">
- <run class="org.eclipse.core.tests.internal.alias.BasicAliasTest"/>
- </test>
- <test id="alias.SyncAliasTest">
- <run class="org.eclipse.core.tests.internal.alias.SyncAliasTest"/>
- </test>
-
- <test id="builders.AllTests">
- <run class="org.eclipse.core.tests.internal.builders.AllTests"/>
- </test>
- <test id="builders.BuilderNatureTest">
- <run class="org.eclipse.core.tests.internal.builders.BuilderNatureTest"/>
- </test>
- <test id="builders.BuilderTest">
- <run class="org.eclipse.core.tests.internal.builders.BuilderTest"/>
- </test>
- <test id="builders.BuilderCycleTest">
- <run class="org.eclipse.core.tests.internal.builders.BuilderCycleTest"/>
- </test>
- <test id="builders.BuildDeltaVerificationTest">
- <run class="org.eclipse.core.tests.internal.builders.BuildDeltaVerificationTest"/>
- </test>
- <test id="builders.MultiProjectBuildTest">
- <run class="org.eclipse.core.tests.internal.builders.MultiProjectBuildTest"/>
- </test>
-
- <test id="dtree.AllTests">
- <run class="org.eclipse.core.tests.internal.dtree.AllTests"/>
- </test>
- <test id="dtree.DataTreeTest">
- <run class="org.eclipse.core.tests.internal.dtree.DataTreeTest"/>
- </test>
- <test id="dtree.DeltaDataTreeTest">
- <run class="org.eclipse.core.tests.internal.dtree.DeltaDataTreeTest"/>
- </test>
-
- <test id="indexing.AllTests">
- <run class="org.eclipse.core.tests.internal.indexing.AllTests"/>
- </test>
- <test id="indexing.FieldTest">
- <run class="org.eclipse.core.tests.internal.indexing.FieldTest"/>
- </test>
- <test id="indexing.IndexedStoreTest">
- <run class="org.eclipse.core.tests.internal.indexing.IndexedStoreTest"/>
- </test>
- <test id="indexing.ObjectStoreTest">
- <run class="org.eclipse.core.tests.internal.indexing.ObjectStoreTest"/>
- </test>
- <test id="indexing.PageCacheTest">
- <run class="org.eclipse.core.tests.internal.indexing.PageCacheTest"/>
- </test>
- <test id="indexing.PageStoreTest">
- <run class="org.eclipse.core.tests.internal.indexing.PageStoreTest"/>
- </test>
-
- <test id="localstore.AllTests">
- <run class="org.eclipse.core.tests.internal.localstore.AllTests"/>
- </test>
- <test id="localstore.BlobOutputStreamTest">
- <run class="org.eclipse.core.tests.internal.localstore.BlobOutputStreamTest"/>
- </test>
- <test id="localstore.BlobStoreTest">
- <run class="org.eclipse.core.tests.internal.localstore.BlobStoreTest"/>
- </test>
- <test id="localstore.CaseSensitivityTest">
- <run class="org.eclipse.core.tests.internal.localstore.CaseSensitivityTest"/>
- </test>
- <test id="localstore.CopyTest">
- <run class="org.eclipse.core.tests.internal.localstore.CopyTest"/>
- </test>
- <test id="localstore.DeleteTest">
- <run class="org.eclipse.core.tests.internal.localstore.DeleteTest"/>
- </test>
- <test id="localstore.FileSystemResourceManagerTest">
- <run class="org.eclipse.core.tests.internal.localstore.FileSystemResourceManagerTest"/>
- </test>
- <test id="localstore.FileSystemStoreTest">
- <run class="org.eclipse.core.tests.internal.localstore.FileSystemStoreTest"/>
- </test>
- <test id="localstore.HistoryStoreTest">
- <run class="org.eclipse.core.tests.internal.localstore.HistoryStoreTest"/>
- </test>
- <test id="localstore.HistoryStoreUseCaseTest">
- <run class="org.eclipse.core.tests.internal.localstore.HistoryStoreUseCaseTest"/>
- </test>
- <test id="localstore.LocalSyncTest">
- <run class="org.eclipse.core.tests.internal.localstore.LocalSyncTest"/>
- </test>
- <test id="localstore.MoveTest">
- <run class="org.eclipse.core.tests.internal.localstore.MoveTest"/>
- </test>
- <test id="localstore.RefreshLocalPerformanceTest">
- <run class="org.eclipse.core.tests.internal.localstore.RefreshLocalPerformanceTest"/>
- </test>
- <test id="localstore.RefreshLocalTest">
- <run class="org.eclipse.core.tests.internal.localstore.RefreshLocalTest"/>
- </test>
- <test id="localstore.SafeChunkyInputOutputStreamTest">
- <run class="org.eclipse.core.tests.internal.localstore.SafeChunkyInputOutputStreamTest"/>
- </test>
- <test id="localstore.SafeFileInputOutputStreamTest">
- <run class="org.eclipse.core.tests.internal.localstore.SafeFileInputOutputStreamTest"/>
- </test>
- <test id="localstore.UnifiedTreeTest">
- <run class="org.eclipse.core.tests.internal.localstore.UnifiedTreeTest"/>
- </test>
-
- <test id="properties.AllTests">
- <run class="org.eclipse.core.tests.internal.properties.AllTests"/>
- </test>
- <test id="properties.PropertyManagerTest">
- <run class="org.eclipse.core.tests.internal.properties.PropertyManagerTest"/>
- </test>
-
- <test id="internal.resources.AllTests">
- <run class="org.eclipse.core.tests.internal.resources.AllTests"/>
- </test>
- <test id="internal.ModelObjectWriterTest">
- <run class="org.eclipse.core.tests.internal.resources.ModelObjectWriterTest"/>
- </test>
- <test id="internal.ResourceInfoTest">
- <run class="org.eclipse.core.tests.internal.resources.ResourceInfoTest"/>
- </test>
- <test id="internal.WorkspacePreferencesTest">
- <run class="org.eclipse.core.tests.internal.resources.WorkspacePreferencesTest"/>
- </test>
- <test id="internal.WorkspaceSerializationTest">
- <run class="org.eclipse.core.tests.internal.resources.WorkspaceSerializationTest"/>
- </test>
-
- <test id="utils.AllTests">
- <run class="org.eclipse.core.tests.internal.utils.AllTests"/>
- </test>
- <test id="utils.QueueTest">
- <run class="org.eclipse.core.tests.internal.utils.QueueTest"/>
- </test>
-
- <test id="watson.AllTests">
- <run class="org.eclipse.core.tests.internal.watson.AllTests"/>
- </test>
- <test id="watson.BenchElementTree">
- <run class="org.eclipse.core.tests.internal.watson.BenchElementTree"/>
- </test>
- <test id="watson.DeltaChainFlatteningTest">
- <run class="org.eclipse.core.tests.internal.watson.DeltaChainFlatteningTest"/>
- </test>
- <test id="watson.DeltaFlatteningTest">
- <run class="org.eclipse.core.tests.internal.watson.DeltaFlatteningTest"/>
- </test>
- <test id="watson.DeltaIteratorTest">
- <run class="org.eclipse.core.tests.internal.watson.DeltaIteratorTest"/>
- </test>
- <test id="watson.ElementDeltaTest">
- <run class="org.eclipse.core.tests.internal.watson.ElementDeltaTest"/>
- </test>
- <test id="watson.ElementTreeDeltaChainTest">
- <run class="org.eclipse.core.tests.internal.watson.ElementTreeDeltaChainTest"/>
- </test>
- <test id="watson.ElementTreeIteratorTest">
- <run class="org.eclipse.core.tests.internal.watson.ElementTreeIteratorTest"/>
- </test>
- <test id="watson.ElementTreeTest">
- <run class="org.eclipse.core.tests.internal.watson.ElementTreeTest"/>
- </test>
- <test id="watson.PluggableDeltaLogicTest">
- <run class="org.eclipse.core.tests.internal.watson.PluggableDeltaLogicTest"/>
- </test>
- <test id="watson.TestTreeFlattening">
- <run class="org.eclipse.core.tests.internal.watson.TestTreeFlattening"/>
- </test>
-
-</extension>
-
- <extension point="org.eclipse.core.resources.builders" id="deltaverifierbuilder" name="Delta Verifier">
- <builder>
- <run class="org.eclipse.core.tests.internal.builders.DeltaVerifierBuilder"/>
- </builder>
- </extension>
- <extension point="org.eclipse.core.resources.builders" id="sortbuilder" name="Sort Builder">
- <builder>
- <run class="org.eclipse.core.tests.internal.builders.SortBuilder"/>
- </builder>
- </extension>
- <extension point="org.eclipse.core.resources.builders" id="brokenbuilder" name="Broken Builder">
- <builder>
- <run class="org.eclipse.core.tests.internal.builders.BrokenBuilder"/>
- </builder>
- </extension>
- <extension point="org.eclipse.core.resources.builders" id="refreshbuilder" name="Refresh local builder">
- <builder>
- <run class="org.eclipse.core.tests.internal.builders.RefreshLocalJavaFileBuilder"/>
- </builder>
- </extension>
- <extension point="org.eclipse.core.resources.builders" id="sigbuilder" name="Signaled Builder">
- <builder>
- <run class="org.eclipse.core.tests.resources.usecase.SignaledBuilder"/>
- </builder>
- </extension>
- <extension point="org.eclipse.core.resources.builders" id="simplebuilder" name="Simple Builder">
- <builder hasNature="false">
- <run class="org.eclipse.core.tests.resources.regression.SimpleBuilder"/>
- </builder>
- </extension>
- <extension point="org.eclipse.core.resources.builders" id="snowbuilder" name="Snow Builder">
- <builder hasNature="true">
- <run class="org.eclipse.core.tests.internal.builders.SnowBuilder"/>
- </builder>
- </extension>
- <extension point="org.eclipse.core.resources.builders" id="cyclebuilder" name="Cycle Builder">
- <builder>
- <run class="org.eclipse.core.tests.internal.builders.CycleBuilder"/>
- </builder>
- </extension>
-
-<extension
- id="simpleNature"
- name="Simple"
- point="org.eclipse.core.resources.natures">
- <runtime>
- <run class="org.eclipse.core.tests.internal.resources.SimpleNature"/>
- </runtime>
- <options allowLinking="false"/>
-</extension>
-<extension
- id="snowNature"
- name="Snow"
- point="org.eclipse.core.resources.natures">
- <runtime>
- <run class="org.eclipse.core.tests.internal.resources.SnowNature"/>
- </runtime>
- <requires-nature
- id="org.eclipse.core.tests.resources.waterNature">
- </requires-nature>
- <one-of-nature
- id="org.eclipse.core.tests.resources.otherSet">
- </one-of-nature>
- <builder id="org.eclipse.core.tests.resources.snowbuilder"/>
-</extension>
-<extension
- id="waterNature"
- name="Water"
- point="org.eclipse.core.resources.natures">
- <one-of-nature
- id="org.eclipse.core.tests.resources.stateSet">
- </one-of-nature>
- <runtime>
- <run class="org.eclipse.core.tests.internal.resources.WaterNature">
- <parameter name="installBuilder" value="true"/>
- </run>
- </runtime>
-</extension>
-<extension
- id="earthNature"
- name="Earth"
- point="org.eclipse.core.resources.natures">
- <runtime>
- <run class="org.eclipse.core.tests.internal.resources.EarthNature">
- </run>
- </runtime>
- <one-of-nature id="org.eclipse.core.tests.resources.stateSet"/>
-</extension>
-<extension
- id="mudNature"
- name="Mud"
- point="org.eclipse.core.resources.natures">
- <runtime>
- <run class="org.eclipse.core.tests.internal.resources.MudNature"/>
- </runtime>
- <requires-nature id="org.eclipse.core.tests.resources.waterNature"/>
- <requires-nature id="org.eclipse.core.tests.resources.earthNature"/>
- <one-of-nature id="org.eclipse.core.tests.resources.otherSet"/>
-</extension>
-<extension
- id="invalidNature"
- point="org.eclipse.core.resources.natures">
- <run-thyme>
- <rrrrun class="foo"/>
- </run-thyme>
- <two-of-nature ic="baz"/>
-</extension>
-<extension
- id="missingPrerequisiteNature"
- name="Bogus Nature"
- point="org.eclipse.core.resources.natures">
- <runtime>
- <run class="org.eclipse.core.tests.internal.resources.MissingPrerequisiteNature"/>
- </runtime>
- <requires-nature id="does.not.exist.Nature"/>
-</extension>
-<extension
- id="cycle1"
- name="Cycle1"
- point="org.eclipse.core.resources.natures">
- <runtime>
- <run class="org.eclipse.core.tests.internal.resources.Cycle1Nature"/>
- </runtime>
- <requires-nature id="org.eclipse.core.tests.resources.cycle2"/>
-</extension>
-<extension
- id="cycle2"
- name="Cycle2"
- point="org.eclipse.core.resources.natures">
- <runtime>
- <run class="org.eclipse.core.tests.internal.resources.Cycle2Nature"/>
- </runtime>
- <requires-nature id="org.eclipse.core.tests.resources.cycle3"/>
-</extension>
-<extension
- id="cycle3"
- name="Cycle3"
- point="org.eclipse.core.resources.natures">
- <runtime>
- <run class="org.eclipse.core.tests.internal.resources.Cycle3Nature"/>
- </runtime>
- <requires-nature id="org.eclipse.core.tests.resources.cycle1"/>
-</extension>
-<extension
- id="nature29116"
- name="Test Bug 29116"
- point="org.eclipse.core.resources.natures">
- <runtime>
- <run class="org.eclipse.core.tests.internal.resources.Bug29116Nature"/>
- </runtime>
-</extension>
-</plugin>
\ No newline at end of file
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/alias/AllTests.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/alias/AllTests.java
deleted file mode 100644
index f625ad8..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/alias/AllTests.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.alias;
-
-import junit.framework.*;
-
-/**
- * Class for collecting all test classes that deal with alias support. An alias
- * is a resource in the workspace that has the same file system location as
- * another resource in the workspace. When a resource changes in a way that
- * affects the contents on disk, all aliases need to be updated.
- */
-public class AllTests extends TestCase {
- public AllTests() {
- super(null);
- }
- public AllTests(String name) {
- super(name);
- }
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTestSuite(BasicAliasTest.class);
- suite.addTestSuite(SyncAliasTest.class);
- return suite;
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/alias/BasicAliasTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/alias/BasicAliasTest.java
deleted file mode 100644
index c7eebb2..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/alias/BasicAliasTest.java
+++ /dev/null
@@ -1,586 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.alias;
-
-import java.util.Arrays;
-import java.util.Comparator;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.resources.Workspace;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-/**
- * Tests basic API methods in the face of aliased resources, and ensures that
- * nothing is ever out of sync.
- */
-public class BasicAliasTest extends EclipseWorkspaceTest {
- //resource handles (p=project, f=folder, l=file)
- private IProject pNoOverlap;
- private IProject pOverlap;
- private IProject pLinked;
- private IFolder fOverlap;
- private IFile lChildOverlap;
- private IFile lOverlap;
- private IFolder fLinked;
- private IFolder fLinkOverlap1;
- private IFolder fLinkOverlap2;
- private IFile lLinked;
- private IFile lChildLinked;
- private IPath linkOverlapLocation;
-
- public static Test suite() {
- return new TestSuite(BasicAliasTest.class);
- }
- public BasicAliasTest() {
- super();
- }
- public BasicAliasTest(String name) {
- super(name);
- }
- /**
- * Asserts that the two given resources are duplicates in the file system.
- * Asserts that both have same location, and same members. Also asserts
- * that both resources are in sync with the file system. The resource names
- * in the tree may be different. The resources may not necessarily exist.
- */
- public void assertOverlap(String message, IResource resource1, IResource resource2) {
- String errMsg = message + resource1.getFullPath().toString();
- assertEquals(errMsg + "(location)", resource1.getLocation(), resource2.getLocation());
- assertTrue(errMsg + "(sync)", resource1.isSynchronized(IResource.DEPTH_ZERO));
- assertTrue(errMsg + "(sync)", resource2.isSynchronized(IResource.DEPTH_ZERO));
-
- IResource[] children1 = null;
- IResource[] children2 = null;
- try {
- children1 = getSortedChildren(resource1);
- children2 = getSortedChildren(resource2);
- } catch (CoreException e) {
- fail(errMsg, e);
- }
- assertEquals(errMsg + "(child count)", children1.length, children2.length);
- for (int i = 0; i < children2.length; i++) {
- assertOverlap(message, children1[i], children2[i]);
- }
- }
- /**
- * Returns the children of the given resource, sorted in a consistent
- * alphabetical order.
- */
- private IResource[] getSortedChildren(IResource resource) throws CoreException {
- if (!(resource instanceof IContainer))
- return new IResource[0];
- IResource[] children = ((IContainer)resource).members();
- Arrays.sort(children, new Comparator() {
- public int compare(Object arg0, Object arg1) {
- return ((IResource)arg0).getFullPath().toString().compareTo(((IResource)arg1).getFullPath().toString());
- }
- });
- return children;
- }
- protected void setUp() throws Exception {
- super.setUp();
- IWorkspaceRoot root = getWorkspace().getRoot();
- //project with no overlap
- pNoOverlap = root.getProject("NoOverlap");
- ensureExistsInWorkspace(pNoOverlap, true);
- ensureExistsInWorkspace(buildResources(pNoOverlap, new String[] {"/1/", "/1/1", "/1/2", "/2/", "/2/1"}), true);
-
- //project with overlap
- pOverlap= root.getProject("Overlap");
- ensureExistsInWorkspace(pOverlap, true);
- fOverlap = pOverlap.getFolder("fOverlap");
- IFolder f2 = pOverlap.getFolder("F2");
- lOverlap = f2.getFile("lOverlap");
- lChildOverlap = fOverlap.getFile("lChildOverlap");
- ensureExistsInWorkspace(new IResource[] {fOverlap, f2, lOverlap, lChildOverlap}, true);
- //create some other random child elements
- ensureExistsInWorkspace(buildResources(pOverlap, new String[] {"/1/", "/1/1", "/1/2"}), true);
- ensureExistsInWorkspace(buildResources(f2, new String[] {"/1/", "/1/1", "/1/2"}), true);
- ensureExistsInWorkspace(buildResources(fOverlap, new String[] {"/1/", "/1/1", "/1/2"}), true);
-
- //create links
- pLinked= root.getProject("LinkProject");
- ensureExistsInWorkspace(pLinked, true);
- fLinked = pLinked.getFolder("LinkedFolder");
- fLinkOverlap1 = pLinked.getFolder("LinkOverlap1");
- fLinkOverlap2 = pLinked.getFolder("LinkOverlap2");
- lLinked = pLinked.getFile("LinkedFile");
- lChildLinked = fLinked.getFile(lChildOverlap.getName());
- fLinked.createLink(fOverlap.getLocation(), IResource.NONE, null);
- lLinked.createLink(lOverlap.getLocation(), IResource.NONE, null);
- ensureExistsInWorkspace(lChildLinked, true);
- ensureExistsInWorkspace(buildResources(pLinked, new String[] {"/a/", "/a/a", "/a/b"}), true);
- ensureExistsInWorkspace(buildResources(fLinked, new String[] {"/a/", "/a/a", "/a/b"}), true);
-
- linkOverlapLocation = getRandomLocation();
- linkOverlapLocation.toFile().mkdirs();
- fLinkOverlap1.createLink(linkOverlapLocation, IResource.NONE, null);
- fLinkOverlap2.createLink(linkOverlapLocation, IResource.NONE, null);
- }
- protected void tearDown() throws Exception {
- super.tearDown();
- Workspace.clear(linkOverlapLocation.toFile());
- }
- /**
- * This tests regression of bug 32785. In this bug, moving a linked folder,
- * then copying a linked folder, resulted in the alias table having a stale entry
- */
- public void testBug32785() {
- IProject project = pNoOverlap;
- IFolder link = project.getFolder("Source");
- IFile child = link.getFile("Child.txt");
- IPath location = getRandomLocation();
- location.toFile().mkdirs();
- try {
- try {
- link.createLink(location, IResource.NONE, getMonitor());
- ensureExistsInWorkspace(child, getRandomContents());
- } catch (CoreException e) {
- fail("1.99", e);
- }
- //move the link (rename)
- IFolder movedLink = project.getFolder("MovedLink");
- try {
- link.move(movedLink.getFullPath(), IResource.SHALLOW, getMonitor());
- } catch (CoreException e) {
- fail("2.99", e);
- }
- assertTrue("3.0", !link.exists());
- assertTrue("3.1", movedLink.exists());
- assertEquals("3.2", location, movedLink.getLocation());
-
- //now copy the moved link
- IFolder copiedLink = project.getFolder("CopiedLink");
- try {
- movedLink.copy(copiedLink.getFullPath(), IResource.SHALLOW, getMonitor());
- } catch (CoreException e) {
- fail("3.99", e);
- }
- assertTrue("4.0", !link.exists());
- assertTrue("4.1", movedLink.exists());
- assertTrue("4.2", copiedLink.exists());
- assertEquals("4.3", location, movedLink.getLocation());
- assertEquals("4.4", location, copiedLink.getLocation());
- assertTrue("4.5", movedLink.isSynchronized(IResource.DEPTH_INFINITE));
- assertTrue("4.6", copiedLink.isSynchronized(IResource.DEPTH_INFINITE));
- } finally {
- Workspace.clear(location.toFile());
- }
- }
-
- public void testCloseOpenProject() {
- }
- /**
- * Tests adding a file to a duplicate region by copying.
- */
- public void testCopyFile() {
- IFile sourceFile = pNoOverlap.getFile("CopySource");
- ensureExistsInWorkspace(sourceFile, true);
-
- //file in linked folder
- try {
- IFile linkDest = fLinked.getFile("CopyDestination");
- IFile overlapDest = fOverlap.getFile(linkDest.getName());
-
- sourceFile.copy(linkDest.getFullPath(), IResource.NONE, getMonitor());
- assertTrue("1.1", linkDest.exists());
- assertTrue("1.2", overlapDest.exists());
- assertOverlap("1.3", linkDest, overlapDest);
-
- linkDest.delete(IResource.NONE, getMonitor());
- assertTrue("1.4", !linkDest.exists());
- assertTrue("1.5", !overlapDest.exists());
- assertOverlap("1.6", linkDest, overlapDest);
- } catch (CoreException e) {
- fail("1.99", e);
- }
- //duplicate file
- try {
- IFile linkDest = lLinked;
- IFile overlapDest = lOverlap;
- //first delete the file, then copy it back
- overlapDest.delete(IResource.NONE, getMonitor());
- //the link will still exist, but the location won't
- assertTrue("2.1", linkDest.exists());
- assertTrue("2.2", !overlapDest.exists());
- assertTrue("2.3", !linkDest.getLocation().toFile().exists());
- assertEquals("2.4", linkDest.getLocation(), overlapDest.getLocation());
-
- sourceFile.copy(overlapDest.getFullPath(), IResource.NONE, getMonitor());
- assertTrue("2.4", linkDest.exists());
- assertTrue("2.5", overlapDest.exists());
- assertOverlap("2.6", linkDest, overlapDest);
- } catch (CoreException e) {
- fail("2.99", e);
- }
- //file in duplicate folder
- try {
- IFile linkDest = fLinked.getFile("CopyDestination");
- IFile overlapDest = fOverlap.getFile(linkDest.getName());
-
- sourceFile.copy(overlapDest.getFullPath(), IResource.NONE, getMonitor());
- assertTrue("3.1", linkDest.exists());
- assertTrue("3.2", overlapDest.exists());
- assertOverlap("3.3", linkDest, overlapDest);
-
- overlapDest.delete(IResource.NONE, getMonitor());
- assertTrue("3.4", !linkDest.exists());
- assertTrue("3.5", !overlapDest.exists());
- assertOverlap("3.6", linkDest, overlapDest);
- } catch (CoreException e) {
- fail("3.99", e);
- }
- }
- public void testCopyFolder() {
- IFolder source = pNoOverlap.getFolder("CopyFolder");
- ensureExistsInWorkspace(source, true);
-
- IFolder destFolder1 = fLinkOverlap1.getFolder(source.getName());
- IFolder destFolder2 = fLinkOverlap2.getFolder(source.getName());
- IResource[] allDest = new IResource[] {destFolder1, destFolder2};
- assertDoesNotExistInWorkspace("1.0", allDest);
-
- //copy to dest 1
- try {
- source.copy(destFolder1.getFullPath(), IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("1.1");
- }
- assertExistsInWorkspace("1.2", allDest);
-
- try {
- destFolder2.delete(IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("1.3", e);
- }
-
- //copy to dest 2
- try {
- source.copy(destFolder2.getFullPath(), IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("1.4");
- }
- assertExistsInWorkspace("1.5", allDest);
-
- try {
- destFolder1.delete(IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("1.6", e);
- }
- }
- /**
- * Test copying a linked folder into a child of its alias.
- */
- public void testCopyToChild() {
- //copying link to child should fail
- IFolder copyDest = fLinkOverlap1.getFolder("CopyDest");
- try {
- fLinkOverlap2.copy(copyDest.getFullPath(), IResource.NONE, getMonitor());
- fail("1.0");
- } catch (CoreException e) {
- //should fail
- }
- //moving link to child should fail
- try {
- fLinkOverlap2.move(copyDest.getFullPath(), IResource.NONE, getMonitor());
- fail("1.0");
- } catch (CoreException e) {
- //should fail
- }
-
- //copy to self should fail
- IFolder copyDest2 = fLinkOverlap2.getFolder(copyDest.getName());
- try {
- copyDest.create(IResource.NONE, true, getMonitor());
- } catch (CoreException e) {
- fail("1.3");
- }
- try {
- copyDest.copy(copyDest2.getFullPath(), IResource.NONE, getMonitor());
- fail("1.0");
- } catch (CoreException e) {
- //should fail
- }
- //moving link to self should fail
- try {
- copyDest.move(copyDest2.getFullPath(), IResource.NONE, getMonitor());
- fail("1.0");
- } catch (CoreException e) {
- //should fail
- }
- }
- public void testCreateDeleteFile() {
- //file in linked folder
- try {
- lChildLinked.delete(IResource.NONE, getMonitor());
- assertOverlap("1.1", lChildLinked, lChildOverlap);
- lChildLinked.create(getRandomContents(), IResource.NONE, getMonitor());
- assertOverlap("1.2", lChildLinked, lChildOverlap);
- } catch (CoreException e) {
- fail("1.99", e);
- }
- //duplicate file
- try {
- lOverlap.delete(IResource.NONE, getMonitor());
- assertEquals("2.0", lLinked.getLocation(), lOverlap.getLocation());
-
- assertTrue("2.1", !lOverlap.exists());
- assertTrue("2.2", !lOverlap.getLocation().toFile().exists());
- assertTrue("2.3", lOverlap.isSynchronized(IResource.DEPTH_INFINITE));
-
- //now the linked resource will still exist but its local contents won't
- assertTrue("2.4", lLinked.exists());
- assertTrue("2.5", !lLinked.getLocation().toFile().exists());
- assertTrue("2.6", !lLinked.isSynchronized(IResource.DEPTH_INFINITE));
- try {
- lLinked.setContents(getRandomContents(), IResource.NONE, getMonitor());
- //should fail
- fail("2.7");
- } catch (CoreException e) {
- //should fail
- }
- lOverlap.create(getRandomContents(), IResource.NONE, getMonitor());
- assertOverlap("2.8", lLinked, lOverlap);
- } catch (CoreException e) {
- fail("2.99", e);
- }
- //file in duplicate folder
- try {
- lChildOverlap.delete(IResource.NONE, getMonitor());
- assertOverlap("1.1", lChildLinked, lChildOverlap);
- lChildOverlap.create(getRandomContents(), IResource.NONE, getMonitor());
- assertOverlap("1.2", lChildLinked, lChildOverlap);
- } catch (CoreException e) {
- fail("3.0", e);
- }
- }
- public void testCreateDeleteFolder() {
- //folder in overlapping project
- try {
- fOverlap.delete(IResource.NONE, getMonitor());
- //linked resources don't disappear on deletion of underlying file
- assertTrue("1.0", fLinked.exists());
- assertTrue("1.1", !fLinked.getLocation().toFile().exists());
-
- fOverlap.create(IResource.NONE, true, getMonitor());
- assertOverlap("1.2", fOverlap, fLinked);
- } catch (CoreException e) {
- fail("1.99", e);
- }
- //linked folder
- try {
- fLinked.delete(IResource.NONE, getMonitor());
- //deleting a link should not delete file system contents
- assertTrue("2.0", fOverlap.exists());
- assertTrue("2.1", fOverlap.getLocation().toFile().exists());
-
- fLinked.createLink(fOverlap.getLocation(), IResource.NONE, getMonitor());
- assertOverlap("1.4", fOverlap, fLinked);
- } catch (CoreException e) {
- fail("2.99", e);
- }
-
- //child of linked folders
- IFolder child1 = fLinkOverlap1.getFolder("LinkChild");
- IFolder child2 = fLinkOverlap2.getFolder(child1.getName());
-
- try {
- child1.create(IResource.NONE, true, getMonitor());
- assertOverlap("3.0", child1, child2);
- child1.delete(IResource.NONE, getMonitor());
- assertTrue("3.1", !child1.exists());
- assertTrue("3.2", !child2.exists());
-
- child2.create(IResource.NONE, true, getMonitor());
- assertOverlap("3.3", child1, child2);
- child2.delete(IResource.NONE, getMonitor());
- assertTrue("3.4", !child1.exists());
- assertTrue("3.5", !child2.exists());
- } catch (CoreException e) {
- fail("3.99", e);
- }
- }
- public void testCreateDeleteLink() {
- }
- public void testCreateOpenProject() {
- }
- public void testDeepCopyLink() {
- }
- public void testDeepMoveLink() {
- }
- public void testDeleteLink() {
- //test deletion of a link that overlaps a project location
- IFolder linkOnProject = pLinked.getFolder("LinkOnProject");
- try {
- linkOnProject.createLink(pOverlap.getLocation(), IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- try {
- linkOnProject.delete(IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- //deletion of a link should not delete the project that it overlaps
- assertTrue("2.1", !linkOnProject.exists());
- assertTrue("2.2", pOverlap.exists());
- assertTrue("2.3", fOverlap.exists());
- }
- public void testDeleteProject() {
- }
- public void testDeleteProjectContents() {
- //delete the overlapping project - it should delete the children of the linked folder
- //but leave the actual links intact in the resource tree
- try {
- pOverlap.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
- assertDoesNotExistInWorkspace("1.1", new IResource[] {pOverlap, fOverlap, lOverlap, lChildOverlap, lChildLinked});
- assertDoesNotExistInFileSystem("1.2", new IResource[] {pOverlap, fOverlap, lOverlap, lChildOverlap, lChildLinked,
- lLinked, fLinked});
- assertExistsInWorkspace("1.3", new IResource[] {pLinked, fLinked, lLinked});
- }
- public void testFileAppendContents() {
- //linked file
- try {
- lLinked.appendContents(getRandomContents(), IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
- assertOverlap("1.1", lLinked, lOverlap);
-
- //file in linked folder
- try {
- lChildLinked.appendContents(getRandomContents(), IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
- assertOverlap("2.1", lChildLinked, lChildOverlap);
- //duplicate file
- try {
- lOverlap.appendContents(getRandomContents(), IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
- assertOverlap("3.1", lLinked, lOverlap);
- //file in duplicate folder
- try {
- lChildOverlap.appendContents(getRandomContents(), IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
- assertOverlap("3.1", lChildLinked, lChildOverlap);
- }
- public void testFileSetContents() {
- //linked file
- try {
- lLinked.setContents(getRandomContents(), IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
- assertOverlap("1.1", lLinked, lOverlap);
-
- //file in linked folder
- try {
- lChildLinked.setContents(getRandomContents(), IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
- assertOverlap("2.1", lChildLinked, lChildOverlap);
- //duplicate file
- try {
- lOverlap.setContents(getRandomContents(), IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
- assertOverlap("3.1", lLinked, lOverlap);
- //file in duplicate folder
- try {
- lChildOverlap.setContents(getRandomContents(), IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
- assertOverlap("3.1", lChildLinked, lChildOverlap);
- }
- /**
- * Tests moving a file into and out of an overlapping area (similar to
- * creation/deletion).
- */
- public void testMoveFile() {
- IFile destination = pNoOverlap.getFile("MoveDestination");
- //file in linked folder
- try {
- lChildLinked.move(destination.getFullPath(), IResource.NONE, getMonitor());
- assertDoesNotExistInWorkspace("1.1", lChildLinked);
- assertDoesNotExistInWorkspace("1.2", lChildOverlap);
- assertExistsInWorkspace("1.3", destination);
- assertOverlap("1.4", lChildLinked, lChildOverlap);
-
- destination.move(lChildLinked.getFullPath(), IResource.NONE, getMonitor());
- assertExistsInWorkspace("1.5", lChildLinked);
- assertExistsInWorkspace("1.6", lChildOverlap);
- assertDoesNotExistInWorkspace("1.7", destination);
- assertOverlap("1.8", lChildLinked, lChildOverlap);
- } catch (CoreException e) {
- fail("1.99", e);
- }
- //duplicate file
- try {
- lOverlap.move(destination.getFullPath(), IResource.NONE, getMonitor());
- assertDoesNotExistInWorkspace("3.1", lOverlap);
- assertExistsInWorkspace("3.2", lLinked);
- assertDoesNotExistInFileSystem("3.25", lLinked);
- assertExistsInWorkspace("3.3", destination);
- assertEquals("3.4", lLinked.getLocation(), lOverlap.getLocation());
- //lLinked will be out of sync because it exists in the ws but not fs
- assertTrue("3.4.1", !lLinked.isSynchronized(IResource.DEPTH_INFINITE));
-
- destination.move(lOverlap.getFullPath(), IResource.NONE, getMonitor());
- assertExistsInWorkspace("3.5", lLinked);
- assertExistsInWorkspace("3.6", lOverlap);
- assertDoesNotExistInWorkspace("3.7", destination);
- assertOverlap("3.8", lLinked, lOverlap);
- } catch (CoreException e) {
- fail("2.99", e);
- }
- //file in duplicate folder
- try {
- lChildOverlap.move(destination.getFullPath(), IResource.NONE, getMonitor());
- assertDoesNotExistInWorkspace("3.1", lChildLinked);
- assertDoesNotExistInWorkspace("3.2", lChildOverlap);
- assertExistsInWorkspace("3.3", destination);
- assertOverlap("3.4", lChildLinked, lChildOverlap);
-
- destination.move(lChildOverlap.getFullPath(), IResource.NONE, getMonitor());
- assertExistsInWorkspace("3.5", lChildLinked);
- assertExistsInWorkspace("3.6", lChildOverlap);
- assertDoesNotExistInWorkspace("3.7", destination);
- assertOverlap("3.8", lChildLinked, lChildOverlap);
- } catch (CoreException e) {
- fail("3.0", e);
- }
- }
- public void testMoveFolder() {
- }
- public void testShallowCopyLink() {
- }
- public void testShallowMoveLink() {
- }
- public void testShallowDeleteProject() {
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/alias/SyncAliasTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/alias/SyncAliasTest.java
deleted file mode 100644
index 800a972..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/alias/SyncAliasTest.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.alias;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-/**
- * Tests out of sync cases and refreshLocal in the presence of duplicate
- * resources.
- */
-public class SyncAliasTest extends EclipseWorkspaceTest {
- public static Test suite() {
- return new TestSuite(SyncAliasTest.class);
- }
- public SyncAliasTest() {
- super();
- }
- public SyncAliasTest(String name) {
- super(name);
- }
- public void testSimple() {
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/AbstractBuilderTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/AbstractBuilderTest.java
deleted file mode 100644
index 5ee4618..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/AbstractBuilderTest.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.builders;
-
-import java.util.Map;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-
-/**
- * This class does not define any tests, just convenience methods for other builder tests.
- */
-public abstract class AbstractBuilderTest extends EclipseWorkspaceTest {
-
- private boolean autoBuilding;
-
-public AbstractBuilderTest(String name) {
- super(name);
-}
-/**
- * Adds a new delta verifier builder to the given project.
- */
-protected void addBuilder(IProject project, String builderName) throws CoreException {
- IProjectDescription desc = project.getDescription();
- desc.setBuildSpec(new ICommand[] {createCommand(desc, builderName, "Project1Build1")});
- project.setDescription(desc, getMonitor());
-}
-/**
- * Creates and returns a new command with the SortBuilder, and the TestBuilder.BUILD_ID
- * parameter set to the given value.
- */
-protected ICommand createCommand(IProjectDescription description, String buildID) {
- return createCommand(description, SortBuilder.BUILDER_NAME, buildID);
-}
-/**
- * Creates and returns a new command with the given builder name, and the TestBuilder.BUILD_ID
- * parameter set to the given value.
- */
-protected ICommand createCommand(IProjectDescription description, String builderName, String buildID) {
- ICommand command = description.newCommand();
- Map args = command.getArguments();
- args.put(TestBuilder.BUILD_ID, buildID);
- command.setBuilderName(builderName);
- command.setArguments(args);
- return command;
-}
-/**
- * Dirties the given file, forcing a build.
- */
-protected void dirty(IFile file) throws CoreException {
- file.setContents(getRandomContents(), true, true, getMonitor());
-}
-/**
- * Sets the workspace autobuilding to the desired value.
- */
-protected void setAutoBuilding(boolean value) throws CoreException {
- IWorkspace workspace = getWorkspace();
- if (workspace.isAutoBuilding() == value)
- return;
- IWorkspaceDescription desc = workspace.getDescription();
- desc.setAutoBuilding(value);
- workspace.setDescription(desc);
-}
-/**
- * Sets the workspace build order to just contain the given project.
- */
-protected void setBuildOrder(IProject project) throws CoreException {
- IWorkspace workspace = getWorkspace();
- IWorkspaceDescription desc = workspace.getDescription();
- desc.setBuildOrder(new String[] {project.getName()});
- workspace.setDescription(desc);
-}
-/**
- * Sets the workspace build order to contain the two given projects
- */
-protected void setBuildOrder(IProject project1, IProject project2) throws CoreException {
- IWorkspace workspace = getWorkspace();
- IWorkspaceDescription desc = workspace.getDescription();
- desc.setBuildOrder(new String[] {project1.getName(), project2.getName()});
- workspace.setDescription(desc);
-}
-/**
- * Saves the current auto-build flag value so it can be restored later.
- */
-protected void setUp() throws Exception {
- super.setUp();
- autoBuilding = getWorkspace().isAutoBuilding();
-
-}
-/**
- * Restores the auto-build flag to its original value.
- */
-protected void tearDown() throws Exception {
- setAutoBuilding(autoBuilding);
- super.tearDown();
-}
-/**
- * Blocks the calling thread until autobuild completes.
- */
-protected void waitForBuild() {
- try {
- Platform.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, null);
- } catch (OperationCanceledException e) {
- } catch (InterruptedException e) {
- }
-}
-}
\ No newline at end of file
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/AllTests.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/AllTests.java
deleted file mode 100644
index 20e3520..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/AllTests.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.builders;
-
-
-import junit.framework.*;
-
-public class AllTests extends TestCase {
-public AllTests() {
- super(null);
-}
-public AllTests(String name) {
- super(name);
-}
-public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(BuilderTest.suite());
- suite.addTest(BuildDeltaVerificationTest.suite());
- suite.addTest(MultiProjectBuildTest.suite());
- suite.addTest(BuilderNatureTest.suite());
- suite.addTest(BuilderCycleTest.suite());
- return suite;
-}
-}
-
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BrokenBuilder.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BrokenBuilder.java
deleted file mode 100644
index 74f61dd..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BrokenBuilder.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.builders;
-
-/**
- * A builder that always fails to load.
- */
-public class BrokenBuilder extends TestBuilder {
- public static final String BUILDER_NAME = "org.eclipse.core.tests.resources.brokenbuilder";
- public BrokenBuilder() {
- throw new RuntimeException();
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuildDeltaVerificationTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuildDeltaVerificationTest.java
deleted file mode 100644
index 78acbcf..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuildDeltaVerificationTest.java
+++ /dev/null
@@ -1,417 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.builders;
-
-
-import java.io.ByteArrayInputStream;
-
-import junit.framework.*;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-
-/**
- * Tests that deltas supplied to the builder are accurate
- */
-public class BuildDeltaVerificationTest extends AbstractBuilderTest {
- DeltaVerifierBuilder verifier;
- /* some random resource handles */
- protected static final String PROJECT1 = "Project1";
- protected static final String PROJECT2 = "Project2";
- protected static final String FOLDER1 = "Folder1";
- protected static final String FOLDER2 = "Folder2";
- protected static final String FILE1 = "File1";
- protected static final String FILE2 = "File2";
- protected static final String FILE3 = "File3";
- IProject project1;
- IProject project2;
- IFolder folder1;//below project2
- IFolder folder2;//below folder1
- IFolder folder3;//same as file1
- IFile file1;//below folder1
- IFile file2;//below folder1
- IFile file3;//below folder2
-public BuildDeltaVerificationTest() {
- super(null);
-}
-/**
- * Creates a new instance of BuildDeltaVerificationTest.
- * @param name java.lang.String
- */
-public BuildDeltaVerificationTest(String name) {
- super(name);
-}
-/**
- * Tests that the builder is receiving an appropriate delta
- * @see SortBuilderPlugin
- * @see SortBuilder
- */
-public void assertDelta() {
- if (!verifier.isDeltaValid()) {
-// System.out.println(verifier.getMessage());
- }
- assertTrue("Should be an incremental build", verifier.wasIncrementalBuild());
- assertTrue(verifier.getMessage(), verifier.isDeltaValid());
-}
-/**
- * Runs code to handle a core exception
- */
-protected void handleCoreException(CoreException e) {
- assertTrue("CoreException: " + e.getMessage(), false);
-}
-/**
- * Rebuilds the solution.
- */
-protected void rebuild() throws CoreException {
- project1.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, getMonitor());
- project2.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, getMonitor());
-}
-/**
- * Sets up the fixture, for example, open a network connection.
- * This method is called before a test is executed.
- */
-protected void setUp() throws CoreException {
-
- // Turn auto-building off
- IWorkspace workspace = getWorkspace();
- setAutoBuilding(false);
-
- // Create some resource handles
- project1 = workspace.getRoot().getProject(PROJECT1);
- project2 = workspace.getRoot().getProject(PROJECT2);
- folder1 = project1.getFolder(FOLDER1);
- folder2 = folder1.getFolder(FOLDER2);
- folder3 = folder1.getFolder(FILE1);
- file1 = folder1.getFile(FILE1);
- file2 = folder1.getFile(FILE2);
- file3 = folder2.getFile(FILE1);
-
- // Create and open a project, folder and file
- try {
- project1.create(getMonitor());
- project1.open(getMonitor());
- folder1.create(true, true, getMonitor());
- file1.create(getRandomContents(), true, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- // Create and set a build spec for the project
- try {
- IProjectDescription desc = project1.getDescription();
- ICommand command = desc.newCommand();
- command.setBuilderName(DeltaVerifierBuilder.BUILDER_NAME);
- desc.setBuildSpec(new ICommand[] {command});
- project1.setDescription(desc, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- // Build the project
- try {
- project1.build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- } catch (CoreException e) {
- fail("3.3", e);
- }
-
- verifier = DeltaVerifierBuilder.getInstance();
- assertNotNull("Builder was not instantiated", verifier);
- assertTrue("First build should be a batch build", verifier.wasFullBuild());
-}
-public static Test suite() {
- TestSuite suite = new TestSuite(BuildDeltaVerificationTest.class);
-
-// suite.addTest(new BuildDeltaVerificationTest("testCloseOpenReplaceFile"));
- return suite;
-}
-/**
- * Tears down the fixture, for example, close a network connection.
- * This method is called after a test is executed.
- */
-protected void tearDown() throws Exception {
- super.tearDown();
- getWorkspace().getRoot().delete(true, getMonitor());
-}
-/**
- * Tests that the builder is receiving an appropriate delta
- * @see SortBuilderPlugin
- * @see SortBuilder
- */
-public void testAddAndRemoveFile() {
- try {
- ByteArrayInputStream in = new ByteArrayInputStream(new byte[] {4, 5, 6});
- file2.create(in, true, getMonitor());
- file2.delete(true, getMonitor());
- rebuild();
- //builder for project1 may not even be called (empty delta)
- if (verifier.wasFullBuild())
- verifier.emptyBuild();
- assertTrue(verifier.getMessage(), verifier.isDeltaValid());
- } catch (CoreException e) {
- handleCoreException(e);
- }
-}
-/**
- * Tests that the builder is receiving an appropriate delta
- * @see SortBuilderPlugin
- * @see SortBuilder
- */
-public void testAddAndRemoveFolder() {
- try {
- folder2.create(true, true, getMonitor());
- folder2.delete(true, getMonitor());
- rebuild();
- //builder for project1 may not even be called (empty delta)
- if (verifier.wasFullBuild())
- verifier.emptyBuild();
- assertTrue(verifier.getMessage(), verifier.isDeltaValid());
- } catch (CoreException e) {
- handleCoreException(e);
- }
-}
-/**
- * Tests that the builder is receiving an appropriate delta
- * @see SortBuilderPlugin
- * @see SortBuilder
- */
-public void testAddFile() {
- try {
- verifier.addExpectedChange(file2, project1, IResourceDelta.ADDED, 0);
- ByteArrayInputStream in = new ByteArrayInputStream(new byte[] {4, 5, 6});
- file2.create(in, true, getMonitor());
- rebuild();
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
-}
-/**
- * Tests that the builder is receiving an appropriate delta
- * @see SortBuilderPlugin
- * @see SortBuilder
- */
-public void testAddFileAndFolder() {
- try {
- verifier.addExpectedChange(folder2, project1, IResourceDelta.ADDED, 0);
- verifier.addExpectedChange(file3, project1,IResourceDelta. ADDED, 0);
- folder2.create(true, true, getMonitor());
- ByteArrayInputStream in = new ByteArrayInputStream(new byte[] {4, 5, 6});
- file3.create(in, true, getMonitor());
- rebuild();
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
-}
-/**
- * Tests that the builder is receiving an appropriate delta
- * @see SortBuilderPlugin
- * @see SortBuilder
- */
-public void testAddFolder() {
- try {
- verifier.addExpectedChange(folder2, project1, IResourceDelta.ADDED, 0);
- folder2.create(true, true, getMonitor());
- rebuild();
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
-}
-/**
- * Tests that the builder is receiving an appropriate delta
- * @see SortBuilderPlugin
- * @see SortBuilder
- */
-public void testAddProject() {
- try {
- //should not affect project1's delta
- project2.create(getMonitor());
- rebuild();
- //builder for project1 should not even be called
- assertTrue(verifier.getMessage(), verifier.isDeltaValid());
- } catch (CoreException e) {
- handleCoreException(e);
- }
-}
-/**
- * Tests that the builder is receiving an appropriate delta
- * @see SortBuilderPlugin
- * @see SortBuilder
- */
-public void testChangeFile() {
- try {
- /* change file1's contents */
- verifier.addExpectedChange(file1, project1, IResourceDelta.CHANGED, IResourceDelta.CONTENT);
- ByteArrayInputStream in = new ByteArrayInputStream(new byte[] {4, 5, 6});
- file1.setContents(in, true, false, getMonitor());
- rebuild();
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
-}
-/**
- * Tests that the builder is receiving an appropriate delta
- * @see SortBuilderPlugin
- * @see SortBuilder
- */
-public void testChangeFileToFolder() {
- try {
- /* change file1 into a folder */
- verifier.addExpectedChange(file1, project1, IResourceDelta.CHANGED, IResourceDelta.CONTENT | IResourceDelta.TYPE | IResourceDelta.REPLACED);
- file1.delete(true, getMonitor());
- folder3.create(true, true, getMonitor());
-
- rebuild();
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
-}
-/**
- * Tests that the builder is receiving an appropriate delta
- * @see SortBuilderPlugin
- * @see SortBuilder
- */
-public void testChangeFolderToFile() {
- try {
- /* change to a folder */
- file1.delete(true, getMonitor());
- folder3.create(true, true, getMonitor());
- rebuild();
-
- /* now change back to a file and verify */
- verifier.addExpectedChange(file1, project1, IResourceDelta.CHANGED, IResourceDelta.CONTENT | IResourceDelta.TYPE | IResourceDelta.REPLACED);
- folder3.delete(true, getMonitor());
- ByteArrayInputStream in = new ByteArrayInputStream(new byte[] {1,2});
- file1.create(in, true, getMonitor());
- rebuild();
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
-}
-/**
- * Tests that the builder is receiving an appropriate delta
- * @see SortBuilderPlugin
- * @see SortBuilder
- */
-public void testCloseOpenReplaceFile() {
- try {
-
- rebuild();
- project1.close(null);
- project1.open(null);
-
- /* change file1's contents */
- verifier = DeltaVerifierBuilder.getInstance();
- verifier.addExpectedChange(file1, project1, IResourceDelta.CHANGED, IResourceDelta.REPLACED | IResourceDelta.CONTENT);
- file1.delete(true, null);
- file1.create(getRandomContents(), true, null);
- rebuild();
- //new builder gets instantiated so grab a reference to the latest builder
- verifier = DeltaVerifierBuilder.getInstance();
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
-}
-/**
- * Tests that the builder is receiving an appropriate delta
- * @see SortBuilderPlugin
- * @see SortBuilder
- */
-public void testMoveFile() {
- try {
- verifier.addExpectedChange(folder2, project1, IResourceDelta.ADDED, 0);
- verifier.addExpectedChange(file1, project1, IResourceDelta.REMOVED, IResourceDelta.MOVED_TO, null, file3.getFullPath());
- verifier.addExpectedChange(file3, project1, IResourceDelta.ADDED, IResourceDelta.MOVED_FROM, file1.getFullPath(), null);
-
- folder2.create(true, true, getMonitor());
- file1.move(file3.getFullPath(), true, getMonitor());
- rebuild();
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
-}
-/**
- * Tests that the builder is receiving an appropriate delta
- * @see SortBuilderPlugin
- * @see SortBuilder
- */
-public void testRemoveFile() {
- try {
- verifier.addExpectedChange(file1, project1, IResourceDelta.REMOVED, 0);
- file1.delete(true, getMonitor());
- rebuild();
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
-}
-/**
- * Tests that the builder is receiving an appropriate delta
- * @see SortBuilderPlugin
- * @see SortBuilder
- */
-public void testRemoveFileAndFolder() {
- try {
- verifier.addExpectedChange(folder1, project1, IResourceDelta.REMOVED, 0);
- verifier.addExpectedChange(file1, project1, IResourceDelta.REMOVED, 0);
- folder1.delete(true, getMonitor());
- rebuild();
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
-}
-/**
- * Tests that the builder is receiving an appropriate delta
- * @see SortBuilderPlugin
- * @see SortBuilder
- */
-public void testReplaceFile() {
- try {
- /* change file1's contents */
- verifier.addExpectedChange(file1, project1, IResourceDelta.CHANGED, IResourceDelta.REPLACED | IResourceDelta.CONTENT);
- ByteArrayInputStream in = new ByteArrayInputStream(new byte[] {4, 5, 6});
- file1.delete(true, getMonitor());
- file1.create(in, true, getMonitor());
- rebuild();
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
-}
-/**
- * Tests that the builder is receiving an appropriate delta
- * @see SortBuilderPlugin
- * @see SortBuilder
- */
-public void testTwoFileChanges() {
- try {
- verifier.addExpectedChange(file1, project1, IResourceDelta.CHANGED, IResourceDelta.CONTENT);
- verifier.addExpectedChange(file2, project1, IResourceDelta.ADDED, 0);
-
- ByteArrayInputStream in = new ByteArrayInputStream(new byte[] {4, 5, 6});
- file1.setContents(in, true, false, getMonitor());
-
- ByteArrayInputStream in2 = new ByteArrayInputStream(new byte[] {4, 5, 6});
- file2.create(in2, true, getMonitor());
-
- rebuild();
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuilderCycleTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuilderCycleTest.java
deleted file mode 100644
index 29e60b8..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuilderCycleTest.java
+++ /dev/null
@@ -1,215 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.builders;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-
-/**
- * Tests platform support for build cycles. Namely, the ability of builders to
- * request that a rebuild occur automatically if it modifies projects that came
- * before it in the build order.
- */
-public class BuilderCycleTest extends AbstractBuilderTest {
- public BuilderCycleTest(String name) {
- super(name);
- }
- public BuilderCycleTest() {
- super(null);
- }
- public static Test suite() {
- return new TestSuite(BuilderCycleTest.class);
- }
-
- public void testIsBeforeThisProject() {
- IWorkspaceRoot root = getWorkspace().getRoot();
- IProject project = root.getProject("Project");
- IProject before1 = root.getProject("Before1");
- IProject before2 = root.getProject("Before2");
- IProject after1 = root.getProject("After1");
- IProject after2 = root.getProject("After2");
- ensureExistsInWorkspace(new IResource[] { project, before1, before2, after1, after2 }, true);
-
- try {
- IWorkspaceDescription description = getWorkspace().getDescription();
- description.setBuildOrder(new String[] { before1.getName(), before2.getName(), project.getName(), after1.getName(), after2.getName()});
- description.setAutoBuilding(false);
- getWorkspace().setDescription(description);
- } catch (CoreException e) {
- fail("1.0", e);
- }
- try {
- IProjectDescription description = project.getDescription();
- ICommand command1 = createCommand(description, CycleBuilder.BUILDER_NAME, "Build0");
- description.setBuildSpec(new ICommand[] { command1 });
- project.setDescription(description, IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
- try {
- getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
-
- CycleBuilder builder = CycleBuilder.getInstance();
- builder.resetBuildCount();
- builder.setBeforeProjects(new IProject[] {before1, before2});
- builder.setAfterProjects(new IProject[] {after1, after2});
-
- try {
- //create a file to ensure incremental build is called
- project.getFile("Foo.txt").create(getRandomContents(), IResource.NONE, getMonitor());
- getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, getMonitor());
- builder.resetBuildCount();
- getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
- }
- public void skipTestNeedRebuild() {
- IWorkspaceRoot root = getWorkspace().getRoot();
- IProject project = root.getProject("Project");
- IFolder unsorted = project.getFolder(SortBuilder.DEFAULT_UNSORTED_FOLDER);
- IFile unsortedFile = unsorted.getFile("File.txt");
- ensureExistsInWorkspace(project, true);
- ensureExistsInWorkspace(unsorted, true);
- ensureExistsInWorkspace(unsortedFile, true);
-
- //setup so that the sortbuilder and cycle builder are both touching files in the project
- try {
- setAutoBuilding(true);
- IProjectDescription description = project.getDescription();
- ICommand command1 = createCommand(description, CycleBuilder.BUILDER_NAME, "Build0");
- ICommand command2 = createCommand(description, SortBuilder.BUILDER_NAME, "Build1");
- description.setBuildSpec(new ICommand[] {command1, command2});
- project.setDescription(description, IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
- CycleBuilder builder = CycleBuilder.getInstance();
- builder.resetBuildCount();
- try {
- getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
-
- //don't request rebuilds and ensure we're only called once
- builder.setRebuildsToRequest(0);
- builder.resetBuildCount();
- try {
- getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- } catch (CoreException e) {
- fail("4.0", e);
- }
- assertEquals("4.1", 1, builder.getBuildCount());
-
- //force an incremental build
- IFile file = project.getFile("foo.txt");
- builder.resetBuildCount();
- try {
- file.create(getRandomContents(), IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("4.2", e);
- }
- assertEquals("4.3", 1, builder.getBuildCount());
-
- //request 1 rebuild and ensure we're called twice
- builder.setRebuildsToRequest(1);
- builder.resetBuildCount();
- try {
- getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- } catch (CoreException e) {
- fail("5.0", e);
- }
- assertEquals("5.1", 2, builder.getBuildCount());
-
- //force an incremental build
- builder.resetBuildCount();
- try {
- file.setContents(getRandomContents(), IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("5.2", e);
- }
- assertEquals("5.3", 2, builder.getBuildCount());
-
- //request 5 rebuilds and ensure we're called six times
- builder.setRebuildsToRequest(5);
- builder.resetBuildCount();
- try {
- getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- } catch (CoreException e) {
- fail("6.0", e);
- }
- assertEquals("6.1", 6, builder.getBuildCount());
-
- //force an incremental build
- builder.resetBuildCount();
- try {
- file.setContents(getRandomContents(), IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("6.2", e);
- }
- assertEquals("6.3", 6, builder.getBuildCount());
-
- //request many rebuilds and ensure we're called according to the build policy
- int maxBuilds = getWorkspace().getDescription().getMaxBuildIterations();
- builder.setRebuildsToRequest(maxBuilds * 2);
- builder.resetBuildCount();
- try {
- getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- } catch (CoreException e) {
- fail("7.0", e);
- }
- assertEquals("7.1", maxBuilds, builder.getBuildCount());
-
- //force an incremental build
- builder.resetBuildCount();
- try {
- file.setContents(getRandomContents(), IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("7.2", e);
- }
- assertEquals("7.3", maxBuilds, builder.getBuildCount());
-
- //change the rebuild policy and ensure we're called the correct number of times
- maxBuilds = 7;
- try {
- IWorkspaceDescription desc = getWorkspace().getDescription();
- desc.setMaxBuildIterations(maxBuilds);
- getWorkspace().setDescription(desc);
- } catch (CoreException e) {
- fail("8.0", e);
- }
- builder.setRebuildsToRequest(maxBuilds * 2);
- builder.resetBuildCount();
- try {
- getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- } catch (CoreException e) {
- fail("8.1", e);
- }
- assertEquals("8.2", maxBuilds, builder.getBuildCount());
-
- //force an incremental build
- builder.resetBuildCount();
- try {
- file.setContents(getRandomContents(), IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("8.3", e);
- }
- assertEquals("8.4", maxBuilds, builder.getBuildCount());
-
-
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuilderNatureTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuilderNatureTest.java
deleted file mode 100644
index a767cec..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuilderNatureTest.java
+++ /dev/null
@@ -1,248 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.builders;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-
-/**
- * Tests relationship between natures and builders. Builders that are owned
- * by a nature can only be run if their owning nature is defined on the project
- * being built.
- */
-public class BuilderNatureTest extends AbstractBuilderTest {
-public BuilderNatureTest() {
- super(null);
-}
-public BuilderNatureTest(String testName) {
- super(testName);
-}
-protected InputStream projectFileWithoutSnow() {
- String contents =
-"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
-"<projectDescription>\n" +
-" <name>P1</name>\n" +
-" <comment></comment>\n" +
-" <projects>\n" +
-" </projects>\n" +
-" <buildSpec>\n" +
-" <buildCommand>\n" +
-" <name>org.eclipse.core.tests.resources.snowbuilder</name>\n" +
-" <arguments>\n" +
-" <dictionary>\n" +
-" <key>BuildID</key>\n" +
-" <value>SnowBuild</value>\n" +
-" </dictionary>\n" +
-" </arguments>\n" +
-" </buildCommand>\n" +
-" </buildSpec>\n" +
-" <natures>\n" +
-" <nature>org.eclipse.core.tests.resources.waterNature</nature>\n" +
-" </natures>\n" +
-"</projectDescription>";
-
- return new ByteArrayInputStream(contents.getBytes());
-}
-protected InputStream projectFileWithoutWater() {
- String contents =
-"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
-"<projectDescription>\n" +
-" <name>P1</name>\n" +
-" <comment></comment>\n" +
-" <projects>\n" +
-" </projects>\n" +
-" <buildSpec>\n" +
-" <buildCommand>\n" +
-" <name>org.eclipse.core.tests.resources.snowbuilder</name>\n" +
-" <arguments>\n" +
-" <dictionary>\n" +
-" <key>BuildID</key>\n" +
-" <value>SnowBuild</value>\n" +
-" </dictionary>\n" +
-" </arguments>\n" +
-" </buildCommand>\n" +
-" </buildSpec>\n" +
-" <natures>\n" +
-" <nature>org.eclipse.core.tests.resources.snowNature</nature>\n" +
-" </natures>\n" +
-"</projectDescription>";
-
- return new ByteArrayInputStream(contents.getBytes());
-}
-public static Test suite() {
- return new TestSuite(BuilderNatureTest.class);
-
-// TestSuite suite = new TestSuite();
-// suite.addTest(new BuilderNatureTest("testMissingNature"));
-// return suite;
-}
-public void testBasic() {
- //add the water and snow natures to the project, and ensure
- //the snow builder gets run
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("P1");
- ensureExistsInWorkspace(project, true);
- SnowBuilder builder= SnowBuilder.getInstance();
- builder.reset();
- try {
- setAutoBuilding(true);
- IProjectDescription desc = project.getDescription();
- desc.setNatureIds(new String[] {NATURE_WATER, NATURE_SNOW});
- project.setDescription(desc, IResource.FORCE, getMonitor());
- waitForBuild();
- } catch (CoreException e) {
- fail("0.99", e);
- }
- builder.addExpectedLifecycleEvent(SnowBuilder.SET_INITIALIZATION_DATA);
- builder.addExpectedLifecycleEvent(SnowBuilder.STARTUP_ON_INITIALIZE);
- builder.addExpectedLifecycleEvent(SnowBuilder.SNOW_BUILD_EVENT);
- builder.assertLifecycleEvents("1.0");
-}
-/**
- * Get the project in a state where the snow nature is disabled,
- * then ensure the snow builder is not run but remains on the build spec
- */
-public void testDisabledNature() {
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("P1");
- ensureExistsInWorkspace(project, true);
- try {
- setAutoBuilding(true);
- IProjectDescription desc = project.getDescription();
- desc.setNatureIds(new String[] {NATURE_WATER, NATURE_SNOW});
- project.setDescription(desc, IResource.FORCE, getMonitor());
- waitForBuild();
- } catch (CoreException e) {
- fail("0.99", e);
- }
- //remove the water nature, thus invalidating snow nature
- SnowBuilder builder= SnowBuilder.getInstance();
- builder.reset();
- IFile descFile = project.getFile(IProjectDescription.DESCRIPTION_FILE_NAME);
- try {
- //setting description file will also trigger build
- descFile.setContents(projectFileWithoutWater(), IResource.FORCE, getMonitor());
- waitForBuild();
- } catch(CoreException e) {
- fail("1.99", e);
- }
- //assert that builder was skipped
- builder.assertLifecycleEvents("1.0");
-
- //now re-enable the nature and ensure that the delta was null
- builder.reset();
- builder.addExpectedLifecycleEvent(SnowBuilder.SNOW_BUILD_EVENT);
- try {
- IProjectDescription desc = project.getDescription();
- desc.setNatureIds(new String[] {NATURE_WATER, NATURE_SNOW});
- project.setDescription(desc, IResource.FORCE, getMonitor());
- waitForBuild();
- } catch (CoreException e) {
- fail("2.99", e);
- }
- builder.assertLifecycleEvents("2.0");
- assertTrue("2.1", builder.wasDeltaNull());
-}
-/**
- * Get the project in a state where the snow nature is missing,
- * then ensure the snow builder is removed from the build spec.
- */
-public void testMissingNature() {
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("P1");
- ensureExistsInWorkspace(project, true);
- try {
- setAutoBuilding(true);
- IProjectDescription desc = project.getDescription();
- desc.setNatureIds(new String[] {NATURE_WATER, NATURE_SNOW});
- project.setDescription(desc, IResource.FORCE, getMonitor());
- waitForBuild();
- } catch (CoreException e) {
- fail("0.99", e);
- }
- //remove the snow nature through normal API
- SnowBuilder builder= SnowBuilder.getInstance();
- builder.reset();
- try {
- IProjectDescription desc = project.getDescription();
- desc.setNatureIds(new String[] {NATURE_WATER});
- project.setDescription(desc, IResource.NONE, getMonitor());
- waitForBuild();
- } catch (CoreException e) {
- fail("1.99", e);
- }
- //make sure the snow builder wasn't run
- builder.assertLifecycleEvents("2.0");
-
- //make sure the build spec doesn't include snow builder
- try {
- ICommand[] commands = project.getDescription().getBuildSpec();
- for (int i = 0; i < commands.length; i++)
- if (commands[i].getBuilderName().equals(SnowBuilder.BUILDER_NAME))
- assertTrue("2.1", false);
- } catch(CoreException e) {
- fail("2.99", e);
- }
-
- //now add the snow nature back and ensure snow builder runs
- builder.reset();
- builder.addExpectedLifecycleEvent(SnowBuilder.SNOW_BUILD_EVENT);
- try {
- IProjectDescription desc = project.getDescription();
- desc.setNatureIds(new String[] {NATURE_WATER, NATURE_SNOW});
- project.setDescription(desc, IResource.KEEP_HISTORY, getMonitor());
- waitForBuild();
- } catch (CoreException e) {
- fail("3.99", e);
- }
- builder.assertLifecycleEvents("3.0");
-
- //now remove the snow nature by hacking .project
- //the deconfigure method won't run, but the builder should still be removed.
- builder.reset();
- IFile descFile = project.getFile(IProjectDescription.DESCRIPTION_FILE_NAME);
- try {
- //setting description file will also trigger build
- descFile.setContents(projectFileWithoutSnow(), IResource.FORCE, getMonitor());
- waitForBuild();
- } catch(CoreException e) {
- fail("4.99", e);
- }
- //assert that builder was skipped
- builder.assertLifecycleEvents("4.0");
-
- //make sure the build spec doesn't include snow builder
- try {
- ICommand[] commands = project.getDescription().getBuildSpec();
- for (int i = 0; i < commands.length; i++)
- if (commands[i].getBuilderName().equals(SnowBuilder.BUILDER_NAME))
- assertTrue("4.1", false);
- } catch(CoreException e) {
- fail("5.99", e);
- }
-
- //now re-enable the nature and ensure that the delta was null
- builder.reset();
- builder.addExpectedLifecycleEvent(SnowBuilder.SNOW_BUILD_EVENT);
- try {
- IProjectDescription desc = project.getDescription();
- desc.setNatureIds(new String[] {NATURE_WATER, NATURE_SNOW});
- project.setDescription(desc, IResource.FORCE, getMonitor());
- waitForBuild();
- } catch (CoreException e) {
- fail("6.99", e);
- }
- builder.assertLifecycleEvents("5.0");
- assertTrue("5.1", builder.wasDeltaNull());
-}
-}
\ No newline at end of file
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuilderTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuilderTest.java
deleted file mode 100644
index 122aa1a..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuilderTest.java
+++ /dev/null
@@ -1,760 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.builders;
-
-
-import java.util.Map;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-
-
-/**
- * This class tests public API related to building and to build specifications.
- * Specifically, the following methods are tested:
- *
- * IWorkspace#build
- * IProject#build
- * IProjectDescription#getBuildSpec
- * IProjectDescription#setBuildSpec
- */
-public class BuilderTest extends AbstractBuilderTest {
-public BuilderTest() {
- super(null);
-}
-/**
- * BuilderTest constructor comment.
- * @param name java.lang.String
- */
-public BuilderTest(String name) {
- super(name);
-}
-public static Test suite() {
- TestSuite suite = new TestSuite(BuilderTest.class);
- return suite;
-}
-/**
- * Tears down the fixture, for example, close a network connection.
- * This method is called after a test is executed.
- */
-protected void tearDown() throws Exception {
- super.tearDown();
- getWorkspace().getRoot().delete(true, null);
- TestBuilder builder = SortBuilder.getInstance();
- if (builder != null)
- builder.reset();
- builder = DeltaVerifierBuilder.getInstance();
- if (builder != null)
- builder.reset();
-}
-/**
- * Tests the lifecycle of a builder.
- * @see SortBuilderPlugin
- * @see SortBuilder
- */
-public void testAutoBuildPR() {
- //REF: 1FUQUJ4
-
- // Create some resource handles
- IWorkspace workspace = getWorkspace();
- IProject project1 = workspace.getRoot().getProject("PROJECT" + 1);
- IFolder folder = project1.getFolder("FOLDER");
- IFolder sub = folder.getFolder("sub");
- IFile fileA = folder.getFile("A");
- IFile fileB = sub.getFile("B");
-
- // Create some resources
- try {
- // Turn auto-building on
- setAutoBuilding(true);
-
- project1.create(getMonitor());
- project1.open(getMonitor());
-
- // Set build spec
- IProjectDescription desc = project1.getDescription();
- ICommand command = desc.newCommand();
- command.setBuilderName(SortBuilder.BUILDER_NAME);
- command.getArguments().put(SortBuilder.BUILD_ID, "Project1Build1");
- desc.setBuildSpec(new ICommand[] {command});
- project1.setDescription(desc, getMonitor());
- } catch (CoreException e) {
- fail("1.99", e);
- }
-
- // Create folders and files
- try {
- folder.create(true, true, getMonitor());
- fileA.create(getRandomContents(), true, getMonitor());
- sub.create(true, true, getMonitor());
- fileB.create(getRandomContents(), true, getMonitor());
- } catch (CoreException e) {
- fail("1.99", e);
- }
-}
-/**
- * Tests installing and running a builder that always fails during instantation.
- */
-public void testBrokenBuilder() {
-
- // Create some resource handles
- IProject project = getWorkspace().getRoot().getProject("PROJECT");
-
- try {
- setAutoBuilding(false);
- // Create and open a project
- project.create(getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- // Create and set a build spec for the project
- try {
- IProjectDescription desc = project.getDescription();
- ICommand command1 = desc.newCommand();
- command1.setBuilderName(BrokenBuilder.BUILDER_NAME);
- ICommand command2 = desc.newCommand();
- command2.setBuilderName(SortBuilder.BUILDER_NAME);
-
- desc.setBuildSpec(new ICommand[] {command1, command2});
- project.setDescription(desc, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
- //do an incremental build -- build should fail, but second builder should run
- try {
- getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, getMonitor());
- fail("3.0");
- } catch (CoreException e) {
- //expected
- }
- TestBuilder verifier = SortBuilder.getInstance();
- verifier.addExpectedLifecycleEvent(TestBuilder.SET_INITIALIZATION_DATA);
- verifier.addExpectedLifecycleEvent(TestBuilder.STARTUP_ON_INITIALIZE);
- verifier.addExpectedLifecycleEvent(TestBuilder.DEFAULT_BUILD_ID);
- verifier.assertLifecycleEvents("3.1");
-
- //build again -- it should suceed this time
- try {
- getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- } catch (CoreException e) {
- fail("4.0", e);
- }
-}
-/**
- * Tests the lifecycle of a builder.
- * @see SortBuilderPlugin
- * @see SortBuilder
- */
-public void testBuildCommands() {
-
- // Create some resource handles
- IWorkspace workspace = getWorkspace();
- IProject project1 = workspace.getRoot().getProject("PROJECT" + 1);
- IProject project2 = workspace.getRoot().getProject("PROJECT" + 2);
- IFile file1 = project1.getFile("FILE1");
- IFile file2 = project2.getFile("FILE2");
-
- //set the build order
- try {
- IWorkspaceDescription workspaceDesc = workspace.getDescription();
- workspaceDesc.setBuildOrder(new String[] {project1.getName(), project2.getName()});
- workspace.setDescription(workspaceDesc);
- } catch (CoreException e) {
- }
-
- TestBuilder verifier = null;
- try {
- // Turn auto-building off
- setAutoBuilding(false);
-
- // Create some resources
- project1.create(getMonitor());
- project1.open(getMonitor());
- project2.create(getMonitor());
- project2.open(getMonitor());
- file1.create(getRandomContents(), true, getMonitor());
- file2.create(getRandomContents(), true, getMonitor());
-
- // Do an initial build to get the builder instance
- IProjectDescription desc = project1.getDescription();
- desc.setBuildSpec(new ICommand[] {createCommand(desc, "Project1Build1")});
- project1.setDescription(desc, getMonitor());
- project1.build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- verifier = SortBuilder.getInstance();
- verifier.addExpectedLifecycleEvent(TestBuilder.SET_INITIALIZATION_DATA);
- verifier.addExpectedLifecycleEvent(TestBuilder.STARTUP_ON_INITIALIZE);
- verifier.addExpectedLifecycleEvent("Project1Build1");
- verifier.assertLifecycleEvents("1.0");
- } catch (CoreException e) {
- fail("1.99", e);
- }
-
- // Build spec with no commands
- try {
- IProjectDescription desc = project1.getDescription();
- desc.setBuildSpec(new ICommand[] {});
- project1.setDescription(desc, getMonitor());
- } catch (CoreException e) {
- fail("2.99", e);
- }
-
- // Build the project -- should do nothing
- try {
- verifier.reset();
- dirty(file1);
- project1.build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- verifier.assertLifecycleEvents("3.1");
- } catch (CoreException e) {
- fail("3.99", e);
- }
-
- // Build command with no arguments -- will use default build ID
- try {
- IProjectDescription desc = project1.getDescription();
- ICommand command = desc.newCommand();
- command.setBuilderName(SortBuilder.BUILDER_NAME);
- desc.setBuildSpec(new ICommand[] { command });
- project1.setDescription(desc, getMonitor());
- } catch (CoreException e) {
- fail("4.99", e);
- }
-
- // Build the project
- try {
- dirty(file1);
- project1.build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- verifier.addExpectedLifecycleEvent(TestBuilder.DEFAULT_BUILD_ID);
- verifier.assertLifecycleEvents("5.2");
- } catch (CoreException e) {
- fail("5.99", e);
- }
-
- // Create and set a build specs for project one
- try {
- IProjectDescription desc = project1.getDescription();
- desc.setBuildSpec(new ICommand[] {createCommand(desc, "Project1Build1")});
- project1.setDescription(desc, getMonitor());
- } catch (CoreException e) {
- fail("6.99", e);
- }
-
- // Create and set a build spec for project two
- try {
- IProjectDescription desc = project2.getDescription();
- desc.setBuildSpec(new ICommand[] {
- createCommand(desc, SortBuilder.BUILDER_NAME, "Project2Build1"),
- createCommand(desc, DeltaVerifierBuilder.BUILDER_NAME, "Project2Build2")});
- project2.setDescription(desc, getMonitor());
- } catch (CoreException e) {
- fail("7.99", e);
- }
-
- // Build
- try {
- verifier.addExpectedLifecycleEvent("Project1Build1");
- //second builder is touched for the first time
- verifier.addExpectedLifecycleEvent(TestBuilder.SET_INITIALIZATION_DATA);
- verifier.addExpectedLifecycleEvent(TestBuilder.STARTUP_ON_INITIALIZE);
- verifier.addExpectedLifecycleEvent("Project2Build1");
- verifier.addExpectedLifecycleEvent(TestBuilder.SET_INITIALIZATION_DATA);
- verifier.addExpectedLifecycleEvent(TestBuilder.STARTUP_ON_INITIALIZE);
- verifier.addExpectedLifecycleEvent("Project2Build2");
- dirty(file1);
- dirty(file2);
- workspace.build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- verifier.assertLifecycleEvents("8.0");
-
- verifier.addExpectedLifecycleEvent("Project1Build1");
- dirty(file1);
- project1.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, getMonitor());
- verifier.assertLifecycleEvents("8.2");
-
- dirty(file2);
- project2.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, getMonitor());
- verifier.addExpectedLifecycleEvent("Project2Build1");
- verifier.addExpectedLifecycleEvent("Project2Build2");
- verifier.assertLifecycleEvents("8.3");
- } catch (CoreException e) {
- fail("8.99", e);
- }
-
- // Change order of build commands
- try {
- IProjectDescription desc = project2.getDescription();
- desc.setBuildSpec(new ICommand[] {
- createCommand(desc, DeltaVerifierBuilder.BUILDER_NAME, "Project2Build2"),
- createCommand(desc, SortBuilder.BUILDER_NAME, "Project2Build1")});
-
- project2.setDescription(desc, getMonitor());
- } catch (CoreException e) {
- fail("10.99", e);
- }
-
- // Build
- try {
- workspace.build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- verifier.addExpectedLifecycleEvent("Project1Build1");
- verifier.addExpectedLifecycleEvent("Project2Build2");
- verifier.addExpectedLifecycleEvent("Project2Build1");
- verifier.assertLifecycleEvents("11.0");
-
- dirty(file1);
- dirty(file2);
- project1.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, getMonitor());
- verifier.addExpectedLifecycleEvent("Project1Build1");
- verifier.assertLifecycleEvents("11.2");
-
- dirty(file1);
- dirty(file2);
- project2.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, getMonitor());
- verifier.addExpectedLifecycleEvent("Project2Build2");
- verifier.addExpectedLifecycleEvent("Project2Build1");
- verifier.assertLifecycleEvents("11.3 ");
- } catch (CoreException e) {
- fail("11.99", e);
- }
-}
-/**
- * Tests the lifecycle of a builder.
- * @see SortBuilderPlugin
- * @see SortBuilder
- */
-public void testBuildOrder() {
-
- IWorkspace workspace = getWorkspace();
-
- // Create some resource handles
- IProject proj1 = workspace.getRoot().getProject("PROJECT" + 1);
- IProject proj2 = workspace.getRoot().getProject("PROJECT" + 2);
-
- try {
- // Turn auto-building off
- setAutoBuilding(false);
-
- // Create some resources
- proj1.create(getMonitor());
- proj1.open(getMonitor());
- proj2.create(getMonitor());
- proj2.open(getMonitor());
-
- //set the build order
- setBuildOrder(proj1, proj2);
- } catch (CoreException e) {
- fail("1.99", e);
- }
-
- // Create and set a build specs for project one
- try {
- IProjectDescription desc = proj1.getDescription();
- desc.setBuildSpec(new ICommand[] {createCommand(desc, "Build0")});
- proj1.setDescription(desc, getMonitor());
- } catch (CoreException e) {
- fail("2.99", e);
- }
-
- // Create and set a build spec for project two
- try {
- IProjectDescription desc = proj2.getDescription();
- desc.setBuildSpec(new ICommand[] {createCommand(desc, "Build1"), createCommand(desc, "Build2")});
- proj2.setDescription(desc, getMonitor());
- } catch (CoreException e) {
- fail("3.99", e);
- }
-
- // Set up a plug-in lifecycle verifier for testing purposes
- TestBuilder verifier = null;
-
- // Build the workspace
- try {
- workspace.build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- verifier = SortBuilder.getInstance();
- verifier.addExpectedLifecycleEvent(TestBuilder.SET_INITIALIZATION_DATA);
- verifier.addExpectedLifecycleEvent(TestBuilder.STARTUP_ON_INITIALIZE);
- verifier.addExpectedLifecycleEvent("Build0");
- verifier.addExpectedLifecycleEvent(TestBuilder.SET_INITIALIZATION_DATA);
- verifier.addExpectedLifecycleEvent(TestBuilder.STARTUP_ON_INITIALIZE);
- verifier.addExpectedLifecycleEvent("Build1");
- verifier.addExpectedLifecycleEvent("Build2");
- verifier.assertLifecycleEvents("4.0 ");
- } catch (CoreException e) {
- fail("4.99", e);
- }
-
- //build in reverse order
- try {
- setBuildOrder(proj2, proj1);
- workspace.build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- verifier.addExpectedLifecycleEvent("Build1");
- verifier.addExpectedLifecycleEvent("Build2");
- verifier.addExpectedLifecycleEvent("Build0");
- verifier.assertLifecycleEvents("5.0");
- } catch (CoreException e) {
- fail("5.99");
- }
-
- //only specify build order for project1
- try {
- setBuildOrder(proj1);
- workspace.build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- verifier.addExpectedLifecycleEvent("Build0");
- verifier.addExpectedLifecycleEvent("Build1");
- verifier.addExpectedLifecycleEvent("Build2");
- verifier.assertLifecycleEvents("6.0");
- } catch (CoreException e) {
- fail("6.99");
- }
-
- //only specify build order for project2
- try {
- setBuildOrder(proj2, proj1);
- workspace.build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- verifier.addExpectedLifecycleEvent("Build1");
- verifier.addExpectedLifecycleEvent("Build2");
- verifier.addExpectedLifecycleEvent("Build0");
- verifier.assertLifecycleEvents("7.0");
- } catch (CoreException e) {
- fail("7.99");
- }
-}
-/**
- * Ensure that build order is preserved when project is closed/opened.
- */
-public void testCloseOpenProject() {
- IWorkspace workspace = getWorkspace();
-
- IProject project = workspace.getRoot().getProject("PROJECT" + 1);
-
- try {
- // Create some resources
- project.create(getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("1.99", e);
- }
- // Create and set a build spec
- try {
- IProjectDescription desc = project.getDescription();
- desc.setBuildSpec(new ICommand[] {createCommand(desc, "Build1"), createCommand(desc, "Build2")});
- project.setDescription(desc, getMonitor());
- } catch (CoreException e) {
- fail("2.99", e);
- }
- try {
- project.close(getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("3.99", e);
- }
- //ensure the build spec hasn't changed
- try {
- IProjectDescription desc = project.getDescription();
- ICommand[] commands = desc.getBuildSpec();
- assertEquals("4.0", 2, commands.length);
- assertEquals("4.1", commands[0].getBuilderName(), SortBuilder.BUILDER_NAME);
- assertEquals("4.2", commands[1].getBuilderName(), SortBuilder.BUILDER_NAME);
- Map args = commands[0].getArguments();
- assertEquals("4.3", "Build1", (String)args.get(TestBuilder.BUILD_ID));
- args = commands[1].getArguments();
- assertEquals("4.4", "Build2", (String)args.get(TestBuilder.BUILD_ID));
- } catch (CoreException e) {
- fail("4.99", e);
- }
-}
-/**
- * Tests the method IncrementProjectBuilder.forgetLastBuiltState
- */
-public void testForgetLastBuiltState() {
- // Create some resource handles
- IProject project = getWorkspace().getRoot().getProject("PROJECT");
-
- try {
- // Turn auto-building off
- setAutoBuilding(false);
- // Create and open a project
- project.create(getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- // Create and set a build spec for the project
- try {
- IProjectDescription desc = project.getDescription();
- ICommand command = desc.newCommand();
- command.setBuilderName(SortBuilder.BUILDER_NAME);
- desc.setBuildSpec(new ICommand[] {command});
- project.setDescription(desc, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- // Set up a plug-in lifecycle verifier for testing purposes
- SortBuilder verifier = null;
-
- //do an initial build
- try {
- project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, SortBuilder.BUILDER_NAME, null, getMonitor());
- verifier = SortBuilder.getInstance();
- } catch (CoreException e) {
- fail("3.2", e);
- }
-
- //forget last built state
- verifier.forgetLastBuiltState();
-
- // Now do another incremental build. Delta should be null
- try {
- project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, SortBuilder.BUILDER_NAME, null, getMonitor());
- assertTrue("4.0", verifier.wasDeltaNull());
- } catch (CoreException e) {
- fail("4.99", e);
- }
-
- // Do another incremental build, requesting a null build state. Delta should not be null
- verifier.requestForgetLastBuildState();
- try {
- project.touch(getMonitor());
- project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, SortBuilder.BUILDER_NAME, null, getMonitor());
- assertTrue("5.0", !verifier.wasDeltaNull());
- } catch (CoreException e) {
- fail("5.99", e);
- }
-
- //try a snapshot when a builder has a null tree
- try {
- getWorkspace().save(false, getMonitor());
- } catch (CoreException e) {
- fail("6.99");
- }
-
- // Do another incremental build. Delta should be null
- try {
- project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, SortBuilder.BUILDER_NAME, null, getMonitor());
- assertTrue("7.0", verifier.wasDeltaNull());
- } catch (CoreException e) {
- fail("7.99", e);
- }
-
- // Delete the project
- try {
- project.delete(false, getMonitor());
- } catch (CoreException e) {
- fail("99.99", e);
- }
-}
-/**
- * Tests the lifecycle of a builder.
- */
-public void testLifecycleEvents() throws CoreException {
-
- // Create some resource handles
- IProject project = getWorkspace().getRoot().getProject("PROJECT");
-
- try {
- // Turn auto-building off
- setAutoBuilding(false);
-
- // Create and open a project
- project.create(getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- // Create and set a build spec for the project
- try {
- IProjectDescription desc = project.getDescription();
- ICommand command = desc.newCommand();
- command.setBuilderName(SortBuilder.BUILDER_NAME);
- desc.setBuildSpec(new ICommand[] {command});
- project.setDescription(desc, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- // Set up a plug-in lifecycle verifier for testing purposes
- TestBuilder verifier = null;
-
- //try to do an incremental build when there has never
- //been a batch build
- try {
- getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, getMonitor());
- verifier = SortBuilder.getInstance();
- verifier.addExpectedLifecycleEvent(TestBuilder.SET_INITIALIZATION_DATA);
- verifier.addExpectedLifecycleEvent(TestBuilder.STARTUP_ON_INITIALIZE);
- verifier.addExpectedLifecycleEvent(TestBuilder.DEFAULT_BUILD_ID);
- verifier.assertLifecycleEvents("3.1");
- } catch (CoreException e) {
- fail("3.2", e);
- }
-
- // Now do another incremental build. Since we just did one, nothing
- // should happen in this one.
- try {
- getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, getMonitor());
- verifier.assertLifecycleEvents("3.4");
- } catch (CoreException e) {
- fail("3.5", e);
- }
-
- // Now do a batch build
- try {
- getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- verifier.addExpectedLifecycleEvent(TestBuilder.DEFAULT_BUILD_ID);
- verifier.assertLifecycleEvents("3.6");
- } catch (CoreException e) {
- fail("3.8", e);
- }
-
- // Close the project
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("4.1", e);
- }
-
- // Open the project, build it, and delete it
- try {
- project.open(getMonitor());
- getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- project.delete(false, getMonitor());
- verifier.addExpectedLifecycleEvent(TestBuilder.SET_INITIALIZATION_DATA);
- verifier.addExpectedLifecycleEvent(TestBuilder.STARTUP_ON_INITIALIZE);
- verifier.addExpectedLifecycleEvent(TestBuilder.DEFAULT_BUILD_ID);
- verifier.assertLifecycleEvents("5.0");
- } catch (CoreException e) {
- fail("5.1", e);
- }
-}
-/**
- * Tests the lifecycle of a builder.
- * @see SortBuilderPlugin
- * @see SortBuilder
- */
-public void testMoveProject() {
- // Create some resource handles
- IWorkspace workspace = getWorkspace();
- IProject proj1 = workspace.getRoot().getProject("PROJECT" + 1);
- IProject proj2 = workspace.getRoot().getProject("Destination");
-
- try {
- // Turn auto-building off
- setAutoBuilding(false);
-
- // Create some resources
- proj1.create(getMonitor());
- proj1.open(getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- // Create and set a build specs for project one
- try {
- IProjectDescription desc = proj1.getDescription();
- ICommand command = desc.newCommand();
- command.setBuilderName(SortBuilder.BUILDER_NAME);
- command.getArguments().put(SortBuilder.BUILD_ID, "Build0");
- desc.setBuildSpec(new ICommand[] {command});
- proj1.setDescription(desc, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- // build project1
- try {
- proj1.build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
-
- // move proj1 to proj2
- try {
- proj1.move(proj2.getFullPath(), false, getMonitor());
- } catch (CoreException e) {
- fail("4.0", e);
- }
-
- // build proj2
- try {
- proj2.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, getMonitor());
- } catch (CoreException e) {
- fail("5.0", e);
- }
-}
-/**
- * Tests that turning autobuild on will invoke a build in the next operation.
- */
-public void testTurnOnAutobuild() throws CoreException {
-
- // Create some resource handles
- IProject project = getWorkspace().getRoot().getProject("PROJECT");
- final IFile file = project.getFile("File.txt");
-
- try {
- // Turn auto-building off
- setAutoBuilding(false);
-
- // Create and open a project
- project.create(getMonitor());
- project.open(getMonitor());
- file.create(getRandomContents(), IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- // Create and set a build spec for the project
- try {
- IProjectDescription desc = project.getDescription();
- ICommand command = desc.newCommand();
- command.setBuilderName(SortBuilder.BUILDER_NAME);
- desc.setBuildSpec(new ICommand[] {command});
- project.setDescription(desc, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- // Set up a plug-in lifecycle verifier for testing purposes
- TestBuilder verifier = null;
-
- //try to do an incremental build when there has never
- //been a batch build
- try {
- getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, getMonitor());
- verifier = SortBuilder.getInstance();
- verifier.addExpectedLifecycleEvent(TestBuilder.SET_INITIALIZATION_DATA);
- verifier.addExpectedLifecycleEvent(TestBuilder.STARTUP_ON_INITIALIZE);
- verifier.addExpectedLifecycleEvent(TestBuilder.DEFAULT_BUILD_ID);
- verifier.assertLifecycleEvents("3.1");
- } catch (CoreException e) {
- fail("3.2", e);
- }
-
- // Now make a change and then turn autobuild on. Turning it on should cause a build.
- IWorkspaceRunnable r = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- file.setContents(getRandomContents(), IResource.NONE, getMonitor());
- IWorkspaceDescription desc = getWorkspace().getDescription();
- desc.setAutoBuilding(true);
- getWorkspace().setDescription(desc);
- }
- };
- waitForBuild();
- getWorkspace().run(r, getMonitor());
- waitForBuild();
- verifier.addExpectedLifecycleEvent(TestBuilder.DEFAULT_BUILD_ID);
- verifier.assertLifecycleEvents("4.0");
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/CycleBuilder.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/CycleBuilder.java
deleted file mode 100644
index 55ea778..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/CycleBuilder.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.builders;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.util.Map;
-
-import junit.framework.Assert;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-
-/**
- * Helper builder for cycle related tests.
- */
-public class CycleBuilder extends TestBuilder {
- public static final String BUILDER_NAME = "org.eclipse.core.tests.resources.cyclebuilder";
-
- protected IProject[] beforeProjects = new IProject[0];
- protected IProject[] afterProjects = new IProject[0];
- protected int rebuildsToRequest = 0;
- private static CycleBuilder singleton;
- protected int buildCount = 0;
-
- /**
- * Returns the most recently created instance.
- */
- public static CycleBuilder getInstance() {
- return singleton;
- }
- public CycleBuilder() {
- singleton = this;
- }
- protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
- if (beforeProjects != null) {
- for (int i = 0; i < beforeProjects.length; i++) {
- Assert.assertTrue("Missing before project: " + beforeProjects[i], hasBeenBuilt(beforeProjects[i]));
- }
- }
- if (afterProjects != null) {
- for (int i = 0; i < afterProjects.length; i++) {
- Assert.assertTrue("Missing after project: " + afterProjects[i], !hasBeenBuilt(afterProjects[i]));
- }
- }
- if (rebuildsToRequest > buildCount) {
- changeAllFiles();
- needRebuild();
- }
- //ensure that subsequent builds are always incremental
- if (buildCount > 0)
- Assert.assertTrue("Should be incremental build", kind == IncrementalProjectBuilder.INCREMENTAL_BUILD);
- buildCount++;
- return null;
- }
-
- /**
- * Method getRandomContents.
- * @return InputStream
- */
- protected InputStream getRandomContents() {
- return new ByteArrayInputStream("foo".getBytes());
- }
-
- /**
- * Method changeSomething.
- */
- private void changeAllFiles() throws CoreException {
- IResourceVisitor visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- if (resource.getType() == IResource.FILE) {
- if (resource.getName().equals(IProjectDescription.DESCRIPTION_FILE_NAME))
- return false;
- ((IFile) resource).setContents(getRandomContents(), IResource.NONE, null);
- }
- return true;
- }
- };
- getProject().accept(visitor, IResource.DEPTH_INFINITE, IResource.NONE);
- }
- public int getBuildCount() {
- return buildCount;
- }
- public void resetBuildCount() {
- buildCount = 0;
- }
- public void setAfterProjects(IProject[] afterProjects) {
- this.afterProjects = afterProjects;
- }
- public void setBeforeProjects(IProject[] beforeProjects) {
- this.beforeProjects = beforeProjects;
- }
- public void setRebuildsToRequest(int rebuildsToRequest) {
- this.rebuildsToRequest = rebuildsToRequest;
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/DeltaVerifierBuilder.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/DeltaVerifierBuilder.java
deleted file mode 100644
index 0838ab8..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/DeltaVerifierBuilder.java
+++ /dev/null
@@ -1,242 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.builders;
-
-
-import java.util.ArrayList;
-import java.util.Map;
-
-import junit.framework.Assert;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.resources.ResourceDeltaVerifier;
-/**
- * This classes poses as a builder, and makes sure that the delta
- * supplied to the builder is as expected. Most of the work is
- * forwarded to a ResourceDeltaVerifier.
- */
-public class DeltaVerifierBuilder extends TestBuilder {
- public static final String BUILDER_NAME = "org.eclipse.core.tests.resources.deltaverifierbuilder";
- /**
- * The singleton builder instance
- */
- protected static DeltaVerifierBuilder fgSingleton;
- /**
- * The resource delta verifier that asserts the delta structure. Sharing it between
- * builders means we can do things like shutdown the project, re-open, build, and
- * assert the delta is appropriate.
- */
- protected static final ResourceDeltaVerifier verifier = new ResourceDeltaVerifier();
-
- /**
- * Whether the last build was full or batch
- */
- protected int triggerForLastBuild = 0;
-
- /**
- * Whether the last incremental build was empty
- */
- protected boolean deltaWasEmpty = false;
-
- /** The projects to request deltas for (may be null) */
- protected IProject[] requestedDeltas;
- /** The projects to check deltas for (may be null) */
- protected IProject[] checkDeltas;
- /** The deltas that were actually received */
- protected ArrayList receivedDeltas = new ArrayList();
- /** The empty deltas that were received */
- protected ArrayList emptyDeltas = new ArrayList();
-
-/**
- * Captures the builder instantiated through reflection
- */
-public DeltaVerifierBuilder() {
- if (fgSingleton != null) {
- //copy interesting data from old singleton
- this.triggerForLastBuild = fgSingleton.triggerForLastBuild;
- this.deltaWasEmpty = fgSingleton.deltaWasEmpty;
- this.requestedDeltas = fgSingleton.requestedDeltas;
- this.checkDeltas = fgSingleton.checkDeltas;
- this.receivedDeltas = fgSingleton.receivedDeltas;
- this.emptyDeltas = fgSingleton.emptyDeltas;
- }
- fgSingleton = this;
-}
-/**
- * Returns the singleton instance
- */
-public static DeltaVerifierBuilder getInstance() {
- if (fgSingleton == null) {
- new DeltaVerifierBuilder();
- }
- return fgSingleton;
-}
-/**
- * Signals to the comparer that the given resource is expected to
- * change in the specified way. The change flags should be set to
- * zero if no change is expected.
- * @param resource the resource that is expected to change
- * @param topLevelParent Do not added expected changes above this parent
- * @param status the type of change (ADDED, REMOVED, CHANGED)
- * @param changeFlags the type of change (CONTENT, SYNC, etc)
- * @param movedPath or null
- * @see IResourceConstants
- */
-public void addExpectedChange(IResource resource, IResource topLevelParent, int status, int changeFlags){
- verifier.addExpectedChange(resource, topLevelParent, status, changeFlags, null, null);
-}
-/**
- * Signals to the comparer that the given resource is expected to
- * change in the specified way. The change flags should be set to
- * zero if no change is expected.
- * @param resource the resource that is expected to change
- * @param topLevelParent Do not added expected changes above this parent
- * @param status the type of change (ADDED, REMOVED, CHANGED)
- * @param changeFlags the type of change (CONTENT, SYNC, etc)
- * @param movedPath or null
- * @see IResourceConstants
- */
-public void addExpectedChange(IResource resource, IResource topLevelParent, int status, int changeFlags, IPath movedFromPath, IPath movedToPath){
- verifier.addExpectedChange(resource, topLevelParent, status, changeFlags, movedFromPath, movedToPath);
-}
-/**
- * Like a wiley restaurant critic, this method masquerades as a builder, but is actually
- * verifying that the provided delta is correct.
- */
-protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
- super.build(kind, args, monitor);
- triggerForLastBuild = kind;
- doCheckDeltas();
- IResourceDelta delta = getDelta(getProject());
- deltaWasEmpty = delta == null || delta.getKind() == 0;
- if (deltaWasEmpty) {
- //full build or empty delta
- verifier.reset();
- } else {
- verifier.verifyDelta(delta);
- }
- return getRequestedDeltas();
-}
-/**
- * Indicates which projects to check receipt of deltas for.
- */
-public void checkDeltas(IProject[] projects) {
- checkDeltas = projects;
-}
-/**
- * Asks the platform for the deltas for a set of projects, and notes which deltas were
- * actually returned.
- */
-protected void doCheckDeltas() {
- if (checkDeltas == null)
- return;
- receivedDeltas.clear();
- for (int i = 0; i < checkDeltas.length; i++) {
- IResourceDelta delta = getDelta(checkDeltas[i]);
- if (delta != null) {
- receivedDeltas.add(checkDeltas[i]);
- //check if the delta was empty
- if (delta.getKind() == IResourceDelta.NO_CHANGE && delta.getAffectedChildren().length == 0) {
- emptyDeltas.add(checkDeltas[i]);
- }
- //regression test -- ensure delta resource is non null
- Assert.assertTrue("Non-null delta", delta.getResource() != null);
- Assert.assertTrue("Delta rooted at project", delta.getResource().getType() == IResource.PROJECT);
- }
- }
-}
-
-/**
- * Signals that an empty build has occurred, so the build method hasn't
- * been called but the state should still be considered valid.
- */
-public void emptyBuild() throws CoreException {
- build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null, null);
-}
-/**
- * Returns the empty deltas received during the last build.
- */
-public ArrayList getEmptyDeltas() {
- return emptyDeltas;
-}
-/**
- * Returns a message that describes the result of the resource
- * delta verification checks.
- */
-public String getMessage() {
- String msg;
- if (deltaWasEmpty) {
- if (verifier.hasExpectedChanges()) {
- msg = "Had expected changes but delta was empty";
- } else {
- msg = "No Delta";
- }
- } else {
- msg = verifier.getMessage();
- }
- return msg;
-}
-
-/**
- * Returns the projects for the deltas that were actually received during the last build.
- */
-public ArrayList getReceivedDeltas() {
- return receivedDeltas;
-}
-/**
- * Returns the projects to request deltas for next build.
- */
-protected IProject[] getRequestedDeltas() {
- return requestedDeltas == null ? new IProject[0] : requestedDeltas;
-}
-
-/**
- * Returns whether the resource delta passed all verification
- * checks. An empty delta is valid if no changes were expected.
- */
-public boolean isDeltaValid(){
- return (deltaWasEmpty && !verifier.hasExpectedChanges()) || verifier.isDeltaValid();
-}
-/**
- * Indicates that the builder should request deltas for the given projects.
- */
-public void requestDeltas(IProject[] projects) {
- requestedDeltas = projects;
- receivedDeltas.clear();
- emptyDeltas.clear();
-}
-
-/*
- * @see TestBuilder#reset()
- */
-public void reset() {
- super.reset();
- triggerForLastBuild = 0;
- if (verifier != null)
- verifier.reset();
-}
-public boolean wasAutoBuild() {
- return triggerForLastBuild == IncrementalProjectBuilder.AUTO_BUILD;
-}
-/**
- * Returns true if the builder has been invoked since the last time it was reset,
- * and false otherwise.
- */
-public boolean wasBuilt() {
- return triggerForLastBuild != 0;
-}
-public boolean wasFullBuild() {
- return triggerForLastBuild == IncrementalProjectBuilder.FULL_BUILD;
-}
-public boolean wasIncrementalBuild() {
- return triggerForLastBuild == IncrementalProjectBuilder.INCREMENTAL_BUILD;
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/MultiProjectBuildTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/MultiProjectBuildTest.java
deleted file mode 100644
index 4204e93..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/MultiProjectBuildTest.java
+++ /dev/null
@@ -1,274 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.builders;
-
-
-import java.util.*;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.tests.resources.TestPerformer;
-
-
-/**
- * This class tests builds that span multiple projects. Project builders
- * can specify what other projects they are interested in receiving deltas for,
- * and they should only be receiving deltas for exactly those projects.
- */
-public class MultiProjectBuildTest extends AbstractBuilderTest {
- //various resource handles
- private IProject project1;
- private IProject project2;
- private IProject project3;
- private IProject project4;
- private IFile file1;
- private IFile file2;
- private IFile file3;
- private IFile file4;
-public MultiProjectBuildTest() {
- super(null);
-}
-/**
- * Public constructor required for test harness.
- */
-public MultiProjectBuildTest(String name) {
- super(name);
-}
-/**
- * Returns an array of interesting project combinations.
- */
-protected Object[] interestingProjects() {
- //mix things up, because requests from one run affect results in the next.
- return new Object[] {
- new IProject[] {},
- new IProject[] {project3},
- new IProject[] {project1},
- new IProject[] {project1, project2, project3},
- new IProject[] {project2},
- new IProject[] {project3},
- new IProject[] {project4},
- new IProject[] {project1, project2},
- new IProject[] {project1, project3},
- new IProject[] {project3},
- new IProject[] {project2, project3},
- new IProject[] {project1, project2, project3},
- new IProject[] {project1, project2, project4},
- new IProject[] {project1},
- new IProject[] {project1, project3, project4},
- new IProject[] {project1, project2},
- new IProject[] {project2, project3, project4},
- new IProject[] {project3, project4},
- new IProject[] {project1, project2, project3, project4},
- };
-}
-
-public static Test suite() {
- return new TestSuite(MultiProjectBuildTest.class);
-}
-/**
- * Modifies any files in the given projects, all in a single operation
- */
-protected void dirty(final IProject[] projects) throws CoreException {
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- for (int i = 0; i < projects.length; i++) {
- IResource[] members = projects[i].members();
- for (int j = 0; j < members.length; j++) {
- if (members[j].getType() == IResource.FILE && !members[j].getName().equals(IProjectDescription.DESCRIPTION_FILE_NAME)) {
- ((IFile)members[j]).setContents(getRandomContents(), true, true, null);
- }
- }
- }
- getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
- }
- }, getMonitor());
-}
-/**
- * Returns an array reversed.
- */
-Object[] reverse(Object[] input) {
- if (input == null) return null;
- int len = input.length;
- Object[] output = new Object[len];
- for (int i = 0; i < len; i++) {
- output[len-i-1] = input[i];
- }
- return output;
-}
-
-/*
- * @see TestCase#setUp()
- */
-protected void setUp() throws Exception {
- super.setUp();
- setAutoBuilding(true);
- IWorkspaceRoot root = getWorkspace().getRoot();
- project1 = root.getProject("Project1");
- project2 = root.getProject("Project2");
- project3 = root.getProject("Project3");
- project4 = root.getProject("Project4");
- file1 = project1.getFile("File1");
- file2 = project2.getFile("File2");
- file3 = project3.getFile("File3");
- file4 = project4.getFile("File4");
- IResource[] resources = {project1, project2, project3, project4, file1, file2, file3, file4};
- ensureExistsInWorkspace(resources, true);
-}
-
-/*
- * @see TestCase#tearDown()
- */
-protected void tearDown() throws Exception {
- super.tearDown();
- getWorkspace().getRoot().delete(true, getMonitor());
-}
-/**
- * In this test, only project1 has a builder, but it is interested in deltas from the other projects.
- * We vary the set of projects that are changed, and the set of projects we request deltas for.
- */
-public void testDeltas() {
- //add builder and do an initial build to get the instance
- try {
- setAutoBuilding(false);
- addBuilder(project1, DeltaVerifierBuilder.BUILDER_NAME);
- project1.build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
- final DeltaVerifierBuilder builder = DeltaVerifierBuilder.getInstance();
- assertTrue("1.1", builder != null);
- //always check deltas for all projects
- final IProject[] allProjects = new IProject[] { project1, project2, project3, project4 };
- builder.checkDeltas(allProjects);
-
- //hold onto the set of requested projects here
- final IProject[][] previousRequest = new IProject[][] { new IProject[] { project1 }
- };
- //hold onto projects that have been modified since the last time the builder was run.
- final HashSet previouslyModified = new HashSet();
- new TestPerformer("testDeltas") {
- public Object[] interestingOldState(Object[] args) throws Exception {
- return null;
- }
- public Object invokeMethod(Object[] args, int count) throws Exception {
- //set requests for next build
- IProject[] requested = (IProject[]) args[0];
- IProject[] toModify = (IProject[]) args[1];
- builder.reset();
- builder.requestDeltas(requested);
- //do the build
- dirty(toModify);
- Object result = previousRequest[0];
- if (builder.wasBuilt()) {
- //if the builder ran, update previous request
- previousRequest[0] = requested;
- previouslyModified.clear();
- } else {
- previouslyModified.addAll(Arrays.asList(toModify));
- }
- return result;
- }
- public boolean shouldFail(Object[] args, int count) {
- return false;
- }
- public boolean wasSuccess(Object[] args, Object result, Object[] oldState) throws Exception {
- HashSet requested = new HashSet(Arrays.asList((IProject[]) result));
- HashSet modified = new HashSet(Arrays.asList((IProject[]) args[1]));
- modified.addAll(previouslyModified);
- HashSet obtained = new HashSet();
- if (!builder.getReceivedDeltas().isEmpty())
- obtained.addAll(builder.getReceivedDeltas());
- ArrayList emptyDeltas = builder.getEmptyDeltas();
-
- //the builder's project is implicitly requested
- requested.add(builder.getProject());
-
- for (int i = 0; i < allProjects.length; i++) {
- IProject project = allProjects[i];
- boolean wasObtained = obtained.contains(project);
- boolean wasRequested = requested.contains(project);
- boolean wasModified = modified.contains(project);
- boolean wasEmpty = emptyDeltas.contains(project);
- if (wasObtained) {
- //every delta we obtained should have been requested and (modified or empty)
- if (!wasRequested || !(wasModified || wasEmpty))
- return false;
- } else {
- //if delta was not obtained, then must be unchanged or not requested
- if (wasRequested && wasModified)
- return false;
- }
- }
- return true;
- }
- }
- .performTest(new Object[][] { interestingProjects(), reverse(interestingProjects())});
-}
-/**
- * Tests a builder that requests deltas for closed and missing projects.
- */
-public void testRequestMissingProject() {
- //add builder and do an initial build to get the instance
- try {
- addBuilder(project1, DeltaVerifierBuilder.BUILDER_NAME);
- project1.build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
- final DeltaVerifierBuilder builder = DeltaVerifierBuilder.getInstance();
- assertTrue("1.1", builder != null);
- //always check deltas for all projects
- final IProject[] allProjects = new IProject[] {project1, project2, project3, project4};
- try {
- project2.close(getMonitor());
- project3.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, getMonitor());
- } catch (CoreException e1) {
- fail("1.99", e1);
- }
- builder.checkDeltas(allProjects);
-
- //modify a file in project1 to force an autobuild
- try {
- file1.setContents(getRandomContents(), IResource.NONE, getMonitor());
- } catch (CoreException e2) {
- fail("2.99", e2);
- }
-}
-/**
- * Test for Bug #5102. Never reproduced but interesting little test, worth keeping around
- */
-public void testPR() throws Exception {
- //create a project with a RefreshLocalJavaFileBuilder and a SortBuilder on the classpath
- IProject project = getWorkspace().getRoot().getProject("P1");
- project.create(null);
- project.open(null);
- IProjectDescription desc = project.getDescription();
- ICommand one = desc.newCommand();
- one.setBuilderName(RefreshLocalJavaFileBuilder.BUILDER_NAME);
- ICommand two = desc.newCommand();
- two.setBuilderName(SortBuilder.BUILDER_NAME);
- desc.setBuildSpec(new ICommand[] {one, two});
- project.setDescription(desc, null);
-
- //do a full build
- project.build(IncrementalProjectBuilder.FULL_BUILD, null);
-
- //do an incremental build by creating a file
- IFile file = project.getFile("Foo");
- file.create(getRandomContents(), true, getMonitor());
-
-}
-
-}
-
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/RefreshLocalJavaFileBuilder.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/RefreshLocalJavaFileBuilder.java
deleted file mode 100644
index 76527fa..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/RefreshLocalJavaFileBuilder.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.builders;
-
-
-import java.io.FileOutputStream;
-import java.util.Map;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-
-/**
- * This builder is for investigating a PR. It creates java files on disk, then
- * does refresh local to bring them into the workspace. It creates the same file
- * regardless of full vs. incremental build, or what the delta is.
- */
-public class RefreshLocalJavaFileBuilder extends TestBuilder {
- public static final String BUILDER_NAME = "org.eclipse.core.tests.resources.refreshbuilder";
-
-/*
- * @see InternalBuilder#build(int, Map, IProgressMonitor)
- */
-protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
- super.build(kind, args, monitor);
-
- IProject project = getProject();
- IFile file = project.getFile("A.java");
- IPath localLocation = project.getLocation().append(file.getName());
- java.io.File localFile = localLocation.toFile();
- try {
- if (localFile.exists())
- localFile.delete();
- FileOutputStream out = new FileOutputStream(localFile);
- out.write("public class A {}".getBytes());
- out.close();
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
-
- project.refreshLocal(IResource.DEPTH_INFINITE, null);
-
-
- return null;
-}
-
-}
-
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/SnowBuilder.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/SnowBuilder.java
deleted file mode 100644
index 10fc6d7..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/SnowBuilder.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.builders;
-
-import java.util.Map;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-/**
- * Test builder that is associated with the snow nature.
- */
-public class SnowBuilder extends TestBuilder {
- private static SnowBuilder singleton;
- private boolean wasDeltaNull = false;
-
- public static final String BUILDER_NAME = "org.eclipse.core.tests.resources.snowbuilder";
- public static final String SNOW_BUILD_EVENT = "SnowBuild";
-
-/**
- * Captures the builder instantiated through reflection
- */
-public SnowBuilder() {
- if (singleton != null) {
- //copy interesting data from old singleton
-// expectedEvents.addAll(singleton.expectedEvents);
-// actualEvents.addAll(singleton.actualEvents);
-// wasDeltaNull = singleton.wasDeltaNull;
- }
- singleton = this;
-}
-/**
- * Returns the singleton instance
- */
-public static SnowBuilder getInstance() {
- if (singleton == null) {
- new SnowBuilder();
- }
- return singleton;
-}
-/**
- * @see InternalBuilder#build(int, Map, IProgressMonitor)
- */
-protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
- wasDeltaNull = getDelta(getProject()) == null;
- return super.build(kind, args, monitor);
-}
-public boolean wasDeltaNull() {
- return wasDeltaNull;
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/SortBuilder.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/SortBuilder.java
deleted file mode 100644
index 4c98079..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/SortBuilder.java
+++ /dev/null
@@ -1,438 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.builders;
-
-
-import java.io.*;
-import java.util.ArrayList;
-import java.util.Map;
-
-import org.eclipse.core.internal.resources.ResourceException;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-
-/**
- * A <code>SortBuilder</code> maintains a collection of files located
- * under a project's "sorted" folder. These files mirror another
- * collection of files located under the project's "unsorted" folder.
- * The content (bytes) of each sorted file is the content of the
- * unsorted file it mirrors, but sorted in either ascending or
- * descending order depending on the build command.
- * @see SortBuilderPlugin
- */
-public class SortBuilder extends TestBuilder {
- public static final String BUILDER_NAME = "org.eclipse.core.tests.resources.sortbuilder";
- /**
- * The most recently created instance
- */
- protected static SortBuilder singleton;
-
- /**
- * All instances.
- */
- protected static final ArrayList allInstances = new ArrayList();
-
-
- /**
- * Whether the last build was full, auto or incremental
- */
- private int triggerForLastBuild = -1;
-
- /**
- * Whether the last build provided a null delta.
- */
- private boolean wasDeltaNull = false;
- /**
- * List of the resources that were in the last delta, if any.
- */
- protected final ArrayList changedResources = new ArrayList();
-
- private boolean requestForgetState = false;
-
- /**
- * Build command parameters.
- */
- public static String SORT_ORDER = "SortOrder";
- public static String ASCENDING = "Ascending";
- public static String DESCENDING = "Descending";
- public static String SORTED_FOLDER = "SortedFolder";
- public static String UNSORTED_FOLDER = "UnsortedFolder";
-
- /**
- * Default folders
- */
- public static String DEFAULT_SORTED_FOLDER = "SortedFolder";
- public static String DEFAULT_UNSORTED_FOLDER = "UnsortedFolder";
-
-
-public SortBuilder() {
- singleton = this;
- allInstances.add(this);
-}
-/**
- * Returns all instances of the SortBuilder that have ever been instantiated.
- * The returned array is in the order in which the builders were first instantiated.
- */
-public static SortBuilder[] allInstances() {
- return (SortBuilder[]) allInstances.toArray(new SortBuilder[allInstances.size()]);
-}
-/**
- * Implemements the inherited abstract method in
- * <code>BaseBuilder</code>.
- * @see BaseBuilder#build(IResourceDelta,int,IProgressMonitor)
- */
-protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
- arguments = args;
- super.build(kind, args, monitor);
- triggerForLastBuild = kind;
- IResourceDelta delta = getDelta(getProject());
- recordChangedResources(delta);
- wasDeltaNull = delta == null;
-
- if (delta == null || kind == IncrementalProjectBuilder.FULL_BUILD) {
- fullBuild();
- } else {
- try {
- incrementalBuild(delta);
- } catch (Exception e) {
- throw new CoreException(new Status(IStatus.ERROR, "tests", IResourceStatus.BUILD_FAILED, "Incremental build failed due to internal error", e));
- }
- }
- //forget last built state if requested to do so
- if (requestForgetState) {
- requestForgetState = false;
- forgetLastBuiltState();
- }
- String project = (String)arguments.get(INTERESTING_PROJECT);
- if (project != null) {
- return new IProject[] {getProject().getWorkspace().getRoot().getProject(project)};
- } else {
- return new IProject[0];
- }
-}
-/**
- * Sort the given unsorted file in either ascending or descending
- * order (depending on the build command) and update its corresponding
- * sorted file with the result.
- * @param unsortedFile
- * @exception Exception if the build can't proceed
- */
-private void build(IFile unsortedFile) throws CoreException {
- InputStream is = unsortedFile.getContents();
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
-
- try {
- try {
- int c;
- while((c = is.read()) != -1){
- bos.write(c);
- }
- } finally {
- is.close();
- }
- } catch (IOException e) {
- throw new ResourceException(IResourceStatus.BUILD_FAILED, null, "IOException sorting file", e);
- }
-
- byte[] bytes = bos.toByteArray();
-
- quicksort(bytes, 0, bytes.length - 1, isSortOrderAscending());
-
- IFile sortedFile = (IFile)convertToSortedResource(unsortedFile);
- createResource(sortedFile);
-
- ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
- sortedFile.setContents(bis, true, false, null);
-}
-/**
- * Converts the given unsorted resource handle to its corresponding
- * sorted resource handle. Neither resources need exist, but their
- * types must be a folder (FOLDER) or a file (FILE).
- * @param IResource
- * @exception Exception if the resource is not a folder or a file
- */
-private IResource convertToSortedResource(IResource unsortedResource) throws CoreException {
- IPath sortedFolderRelativePath = unsortedResource.getProjectRelativePath().removeFirstSegments(1);
-
- int type = unsortedResource.getType();
-
- if (type == IResource.FOLDER) {
- return getSortedFolder().getFolder(sortedFolderRelativePath);
- } else
- if (type == IResource.FILE) {
- return getSortedFolder().getFile(sortedFolderRelativePath);
- } else {
- throw new ResourceException(IResourceStatus.RESOURCE_WRONG_TYPE, null, "Wrong resource type", null);
- }
-}
-/**
- * Creates the given resource, and its parent if necessary. The
- * resource must not be a solution and it's project must exist.
- * @param resource
- * @exception Exception if the resource is not a folder or a file
- */
-private void createResource(IResource resource) throws CoreException {
- if (resource.exists()) {
- return;
- }
-
- createResource(resource.getParent());
-
- int type = resource.getType();
-
- if (type == IResource.FOLDER) {
- ((IFolder) resource).create(true, true, null);
- } else
- if (type == IResource.FILE) {
- ((IFile) resource).create(null, true, null);
- } else {
- throw new ResourceException(IResourceStatus.RESOURCE_WRONG_TYPE, null, "Wrong resource type", null);
- }
-}
-/**
- * Deletes the given resource, and its children if necessary. The
- * resource must not be a solution and its project must exist.
- * @param resource
- * @exception CoreException if the resource is not a folder or a file
- */
-private void deleteResource(IResource resource) throws CoreException {
- if (!resource.exists()) {
- return;
- }
-
- int type = resource.getType();
-
- if (type == IResource.FOLDER) {
- IFolder folder = (IFolder) resource;
- IResource[] members = folder.members();
- for (int i = 0; i < members.length; i++) {
- deleteResource((IResource) members[i]);
- }
- folder.delete(true, null);
- } else
- if (type == IResource.FILE) {
- ((IFile) resource).delete(true, null);
- } else {
- throw new ResourceException(IResourceStatus.RESOURCE_WRONG_TYPE, null, "Wrong resource type", null);
- }
-}
-/**
- * Performs a full build by discarding the results of the previous
- * build and sorting all files in the unsorted folder.
- * @exception BuildException if the build can't proceed
- */
-private void fullBuild() throws CoreException {
- try {
- IFolder sortedFolder = getSortedFolder();
- IFolder unsortedFolder = getUnsortedFolder();
-
- if(sortedFolder.exists()){
- //delete all sorted files
- IResource[] members = sortedFolder.members();
- for(int i = 0; i < members.length; i++) {
- deleteResource((IResource)members[i]);
- }
- }
-
- if(unsortedFolder.exists()){
- fullBuild(unsortedFolder);
- }
- } catch(Exception e){
- throw new ResourceException(IResourceStatus.BUILD_FAILED, null, "Sort builder failed", e);
- }
-}
-/**
- * Performs a full build on the given unsorted resource by sorting
- * it, if it is a file, and sorting its children, if it is a folder.
- * @exception Exception if the build can't proceed
- */
-private void fullBuild(IResource unsortedResource) throws Exception {
- if(unsortedResource.getType() == IResource.FILE){
- build((IFile)unsortedResource);
- } else {
- IResource[] members = ((IFolder)unsortedResource).members();
- for(int i = 0; i < members.length; i++){
- IResource member = (IResource)members[i];
- fullBuild(member);
- }
- }
-}
-/**
- * Returns the set of resources that were affected in the last delta.
- * Affected means that resource changed or one of its children changed.
- */
-public IResource[] getAffectedResources() {
- return (IResource[]) changedResources.toArray(new IResource[changedResources.size()]);
-}
-/**
- * Returns the most recently created instance.
- */
-public static SortBuilder getInstance() {
- return singleton;
-}
-/**
- * Returns the folder under which sorted resources are found.
- * @return IFolder
- */
-private IFolder getSortedFolder() {
- String sortedFolder = (String) arguments.get(SORTED_FOLDER);
- if (sortedFolder == null)
- sortedFolder = DEFAULT_SORTED_FOLDER;
- return getProject().getFolder(sortedFolder);
-}
-/**
- * Returns the folder under which unsorted resources are found.
- * @return IFolder
- */
-private IFolder getUnsortedFolder() {
- String unsortedFolder = (String) arguments.get(UNSORTED_FOLDER);
- if (unsortedFolder == null)
- unsortedFolder = DEFAULT_UNSORTED_FOLDER;
- return getProject().getFolder(unsortedFolder);
-}
-/**
- * Performs an incremental build by leveraging the result of the
- * previous build.
- * @param delta describes how the resources have changed since
- * the last build
- * @exception Exception if the build can't proceed
- */
-private void incrementalBuild(IResourceDelta delta) throws CoreException {
- IResource unsortedResource = delta.getResource();
- IPath unsortedFolderPath = getUnsortedFolder().getFullPath();
- IPath deltaPath = delta.getResource().getFullPath();
-
- boolean isUnderUnsortedFolder =
- unsortedFolderPath.isPrefixOf(deltaPath);
-
- boolean isOverUnsortedFolder =
- deltaPath.isPrefixOf(unsortedFolderPath);
-
- if(isUnderUnsortedFolder){
- int status = delta.getKind();
- int changeFlags = delta.getFlags();
-
- int type = unsortedResource.getType();
-
- IResource sortedResource =
- convertToSortedResource(unsortedResource);
-
- if(status == IResourceDelta.REMOVED){
- if(sortedResource.exists()){
- sortedResource.delete(false, null);
- }
- } else if(type == IResource.FILE && status == IResourceDelta.ADDED){
- build((IFile)unsortedResource);
- } else if(type == IResource.FILE && status == IResourceDelta.CHANGED && (changeFlags & IResourceDelta.CONTENT) != 0){
- build((IFile)unsortedResource);
- }
- }
-
- if(isUnderUnsortedFolder || isOverUnsortedFolder){
- IResourceDelta[] affectedChildren = delta.getAffectedChildren();
- for(int i = 0; i < affectedChildren.length; ++i){
- incrementalBuild(affectedChildren[i]);
- }
- }
-}
-/**
- * Returns true if the unsorted files are to be sorted in ascending
- * order, or false if they are to be sorted in descending order.
- * @return boolean
- */
-private boolean isSortOrderAscending() {
- String sortOrder = (String) arguments.get(SORT_ORDER);
- return !DESCENDING.equals(sortOrder);
-}
-/**
- * Remember all resources that appeared in the delta.
- */
-private void recordChangedResources(IResourceDelta delta) throws CoreException {
- changedResources.clear();
- if (delta == null)
- return;
- delta.accept(new IResourceDeltaVisitor() {
- /*
- * @see IResourceDeltaVisitor#visit(IResourceDelta)
- */
- public boolean visit(IResourceDelta delta) throws CoreException {
- changedResources.add(delta.getResource());
- return true;
- }
- });
-}
-/**
- * Requests that the next invocation of build() will call
- * forgetLastBuiltState().
- */
-public void requestForgetLastBuildState() {
- requestForgetState = true;
-}
-/**
- * Sorts the specified bytes in either ascending or descending order.
- * @param bytes
- * @param start position of first byte
- * @param end position of last byte
- * @param ascendingOrder true if the bytes are to be sorted in
- * ascending order, false if the bytes are to be sorted in
- * descending order
- */
-private void quicksort(byte[] bytes, int start, int end, boolean ascendingOrder){
- if(start >= end || start < 0 || end >= bytes.length){
- return;
- }
-
- int pos = start;
- int mid = (start + end) / 2;
- swap(bytes, start, mid);
-
- for(int i = start + 1; i <= end; ++i){
- if(ascendingOrder && bytes[i] < bytes[start] ||
- !ascendingOrder && bytes[i] > bytes[start]){
- ++pos;
- swap(bytes, pos, i);
- }
- }
-
- swap(bytes, start, pos);
- quicksort(bytes, start, pos, ascendingOrder);
- quicksort(bytes, pos + 1, end, ascendingOrder);
-}
-/**
- * Swaps the specified bytes in the given byte array.
- * @param bytes
- * @param pos1 the position of the first byte
- * @param pos2 the position of the second byte
- */
-private void swap(byte[] bytes, int pos1, int pos2) {
- byte temp = bytes[pos1];
- bytes[pos1] = bytes[pos2];
- bytes[pos2] = temp;
-}
-public boolean wasAutoBuild() {
- return triggerForLastBuild == IncrementalProjectBuilder.AUTO_BUILD;
-}
-/**
- * Returns true if this builder has ever been built, and false otherwise.
- */
-public boolean wasBuilt() {
- return triggerForLastBuild != -1;
-}
-public boolean wasDeltaNull() {
- return wasDeltaNull;
-}
-public boolean wasFullBuild() {
- return triggerForLastBuild == IncrementalProjectBuilder.FULL_BUILD;
-}
-public boolean wasIncrementalBuild() {
- return triggerForLastBuild == IncrementalProjectBuilder.INCREMENTAL_BUILD;
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/TestBuilder.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/TestBuilder.java
deleted file mode 100644
index 105af02..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/TestBuilder.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.builders;
-
-import java.util.*;
-
-import junit.framework.Assert;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IncrementalProjectBuilder;
-import org.eclipse.core.runtime.*;
-
-/**
- * An abstract builder that is designed to be extended for testing
- * purposes.
- */
-public abstract class TestBuilder extends IncrementalProjectBuilder {
- /**
- * Build command parameters.
- */
- public static final String BUILD_ID = "BuildID";
- public static final String INTERESTING_PROJECT = "InterestingProject";
-
- /**
- * Lifecycle event identifiers
- */
- public static final String STARTUP_ON_INITIALIZE = "StartupOnInitialize";
- public static final String SET_INITIALIZATION_DATA = "SetInitializationData";
- public static final String DEFAULT_BUILD_ID = "Build0";
-
- /**
- * The arguments for one run of the builder.
- */
- protected Map arguments;
- private IConfigurationElement config = null;
- private String name = null;
- private Object data = null;
-
- /**
- * These are static because we want one event set for all builder instances.
- */
- private static final ArrayList expectedEvents = new ArrayList();
- private static final ArrayList actualEvents = new ArrayList();
-/**
- * Logs the given plug-in lifecycle event for this builder's plugin.
- */
-public void addExpectedLifecycleEvent(String event) {
- expectedEvents.add(event);
-}
-/**
- * Verifies that the given lifecycle events occurred. Throws an assertion
- * failure if expectations are not met. If successful, clears the list of expected
- * and actual events in preparation for the next test.
- */
-public void assertLifecycleEvents(String text) {
- Assert.assertEquals(text, expectedEvents, actualEvents);
- reset();
-}
-/**
- * Implemements the inherited abstract method in
- * <code>InternalBuilder</code>.
- * @see InternalBuilder#build(IResourceDelta,int,IProgressMonitor)
- */
-protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
- arguments = args == null ? new HashMap(1) : args;
- logPluginLifecycleEvent(getBuildId());
- return new IProject[0];
-}
-/**
- * Returns an ID that identifies the current build.
- */
-private String getBuildId() {
- String buildId = (String) arguments.get(BUILD_ID);
- if (buildId == null)
- buildId = DEFAULT_BUILD_ID;
- return buildId;
-}
-/**
- * Return the configuration element that created this builder.
- * @see setInitializationData(IConfigurationElement, String, Object)
- */
-public IConfigurationElement getConfigurationElement(){
- return config;
-}
-/**
- * Return the data, always a <code>Hashtable</code> or
- * <code>String</code>, that was set when this builder was initialized.
- * @see setInitializationData(IConfigurationElement, String, Object)
- */
-public Object getData(){
- return data;
-}
-/**
- * Return the name of the child configuration element that named
- * this builder in its class attribute.
- * @see setInitializationData(IConfigurationElement, String, Object)
- */
-public String getName(){
- return name;
-}
-/**
- * Logs the given plug-in lifecycle event for this builder's plugin.
- */
-private void logPluginLifecycleEvent(String event) {
- actualEvents.add(event);
-}
-/**
- * Resets expected and actual lifecycle events for this builder.
- */
-public void reset() {
- expectedEvents.clear();
- actualEvents.clear();
-}
-/**
- * Part of <code>IExecutableExtensionAdaptor</code> interface.
- * @see IExecutableExtensionAdaptor
- * @see IConfigurationElement#createExecutableExtension(String)
- */
-public void setInitializationData(IConfigurationElement config, String name, Object data) {
- logPluginLifecycleEvent(SET_INITIALIZATION_DATA);
- this.config = config;
- this.name = name;
- this.data = data;
-}
-/**
- * Implemented inherited method from <code>BaseBuilder</code>.
- * @see BaseBuilder#startupOnInitialize
- */
-protected void startupOnInitialize() {
- logPluginLifecycleEvent(STARTUP_ON_INITIALIZE);
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/dtree/AllTests.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/dtree/AllTests.java
deleted file mode 100644
index 9942422..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/dtree/AllTests.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.dtree;
-
-
-import junit.framework.*;
-
-public class AllTests extends TestCase {
-public AllTests() {
- super(null);
-}
-public AllTests(String name) {
- super(name);
-}
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(DataTreeTest.suite());
- suite.addTest(DeltaDataTreeTest.suite());
- return suite;
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/dtree/DataTreeTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/dtree/DataTreeTest.java
deleted file mode 100644
index 4a59447..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/dtree/DataTreeTest.java
+++ /dev/null
@@ -1,536 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.dtree;
-
-
-import junit.framework.*;
-import org.eclipse.core.internal.dtree.*;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-
-/**
- * Test class for complete data trees.
- */
-public class DataTreeTest extends TestCase {
- DataTree tree, emptyTree;
- IPath rootKey, leftKey, rightKey;
-public DataTreeTest() {
- super(null);
-}
-public DataTreeTest(String name) {
- super(name);
-}
- /**
- * Init tests
- */
- protected void setUp() {
- //data tree tests don't use the CoreTest environment
-
- emptyTree = new DataTree();
- tree = new DataTree();
- rootKey = Path.ROOT;
-
- /* Add two children to root */
- try {
- tree.createChild(rootKey, "leftOfRoot");
- tree.createChild(rootKey, "rightOfRoot");
- } catch (ObjectNotFoundException e) {
- throw new Error("Error in setUp");
- }
-
- leftKey = rootKey.append("leftOfRoot");
- rightKey = rootKey.append("rightOfRoot");
-
- /* Add three children to left of root and one to right of root */
- try {
- tree.createChild(leftKey, "one");
- tree.createChild(leftKey, "two");
- tree.createChild(leftKey, "three");
-
- tree.createChild(rightKey, "rightOfRight");
- } catch (ObjectNotFoundException e) {
- throw new Error("Error in setUp");
- }
-
- }
-/**
- * Run all tests
- */
-public static Test suite() {
- TestSuite suite = new TestSuite(DataTreeTest.class);
- suite.addTest(DeltaDataTreeTest.suite());
- return suite;
-}
-/**
- */
-protected void tearDown() throws Exception {
- //data tree tests don't use the CoreTest environment
-}
- /**
- * Create a child of the specified node and give it the specified local name.<p>
- * If a child with such a name exists, replace it with the new child
- * @exception ObjectNotFoundException
- * parentKey does not exist in the receiver
- */
- public void testCreateChild () {
-
- boolean caught;
- int size;
-
- caught = false;
- /* Create child with bogus parent key */
- try {
- tree.createChild(rootKey.append("bogus"), "foobar");
- } catch (ObjectNotFoundException e) {
- caught = true;
- } finally {
- assertTrue ("1", caught);
- }
-
- caught = false;
- /* Create child of empty tree with bogus parent */
- try {
- emptyTree.createChild(rootKey.append("bogus"), "foobar");
- } catch (ObjectNotFoundException e) {
- caught = true;
- } finally {
- assertTrue ("2", caught);
- }
-
- /* Add child to empty tree */
- try {
- emptyTree.createChild(rootKey, "first");
- } catch (ObjectNotFoundException e) {}
- assertTrue ("3", emptyTree.includes(rootKey.append("first")));
-
- /* Add root level child to non-empty tree */
- try {
- tree.createChild(rootKey, "NewTopLevel");
- } catch (ObjectNotFoundException e) {}
- assertTrue ("4", tree.includes(rootKey.append("NewTopLevel")));
- assertTrue ("5", tree.includes(leftKey));
- assertTrue ("6", tree.includes(rightKey));
- assertTrue ("7", tree.includes(leftKey.append("one")));
-
- /* Add child to leaf in non-empty tree */
- try {
- tree.createChild(leftKey.append("one"), "NewBottom");
- } catch (ObjectNotFoundException e) {}
- assertTrue ("8", tree.includes(leftKey));
- assertTrue ("9", tree.includes(rightKey));
- assertTrue ("10", tree.includes(leftKey.append("one")));
- assertTrue ("11", tree.includes(leftKey.append("one").append("NewBottom")));
-
- /* Add child to node containing only one child */
- try {
- tree.createChild(rightKey, "NewRight");
- } catch (ObjectNotFoundException e) {}
- assertTrue ("12", tree.includes(leftKey));
- assertTrue ("13", tree.includes(rightKey));
- assertTrue ("14", tree.includes(rightKey.append("rightOfRight")));
- assertTrue ("15", tree.includes(rightKey.append("NewRight")));
-
-
- /* Add same child twice */
- size = (tree.getNamesOfChildren(leftKey)).length;
- tree.createChild (leftKey, "double");
- tree.createChild (leftKey, "double");
- /* Make sure size has only increased by one */
- assertTrue ((tree.getNamesOfChildren(leftKey)).length == size + 1);
-
- }
- /**
- * Delete the child with the specified local name from the specified
- * node. Note: this method requires both parentKey and localName,
- * making it impossible to delete the root node.<p>
- *
- * @exception ObjectNotFoundException
- * a child of parentKey with name localName does not exist in the receiver
- */
- public void testDeleteChild() {
-
- boolean caught;
-
- /* Delete from empty */
- caught = false;
- try {
- emptyTree.deleteChild(rootKey, "non-existant");
- } catch (ObjectNotFoundException e) {
- caught = true;
- } finally {
- assertTrue ("1", caught);
- }
-
- /* delete a child that is not the child of parentKey */
- caught = false;
- try {
- tree.deleteChild(rootKey, "rightOfRight");
- } catch (ObjectNotFoundException e) {
- caught = true;
- } finally {
- assertTrue ("2", caught);
- }
- assertTrue ("3", tree.includes(rightKey.append("rightOfRight")));
-
- /* delete with bogus parent */
- caught = false;
- try {
- tree.deleteChild(rootKey.append("bogus"), "rightOfRight");
- } catch (ObjectNotFoundException e) {
- caught = true;
- } finally {
- assertTrue ("4", caught);
- }
- assertTrue ("5", tree.includes(rightKey.append("rightOfRight")));
-
- /* delete with bogus local name */
- caught = false;
- try {
- tree.deleteChild(leftKey, "four");
- } catch (ObjectNotFoundException e) {
- caught = true;
- } finally {
- assertTrue ("6", caught);
- }
- assertTrue ("7", tree.includes(leftKey));
-
- /* Delete a node with children */
- try {
- tree.deleteChild(rootKey, "leftOfRoot");
- } catch (ObjectNotFoundException e) {}
-
- assertTrue ("8", !tree.includes(leftKey));
- assertTrue ("9", !tree.includes(leftKey.append("one")));
- assertTrue ("10", tree.includes(rootKey));
-
- /* delete a leaf */
- try {
- tree.deleteChild(rightKey, "rightOfRight");
- } catch (ObjectNotFoundException e) {}
- assertTrue ("11", !tree.includes(rightKey.append("rightOfRight")));
- assertTrue ("12", tree.includes(rightKey));
-
- return;
- }
- /**
- * Initialize the receiver so that it is a complete, empty tree. It does
- * not represent a delta on another tree. An empty tree is defined to
- * have a root node with nil data and no children.
- */
- public void testEmpty() {
-
- assertTrue ("1", emptyTree.includes(rootKey));
- assertTrue ("2", TestHelper.getRootNode(emptyTree) != null);
- assertTrue ("3", TestHelper.getRootNode(emptyTree).getChildren().length == 0);
-
- return;
- }
- /**
- * Answer the key of the child with the given index of the
- * specified node.<p>
- *
- * @param: NodeKey, int
- * @return: NodeKey
- *
- * @exception ObjectNotFoundException
- * parentKey does not exist in the receiver
- * @exception ArrayIndexOutOfBoundsException
- * if no child with the given index (runtime exception)
- */
- public void testGetChild() {
-
- boolean caught;
-
- /* Get valid children */
- caught = false;
- try {
- assertTrue (tree.getChild(rootKey, 0).equals(leftKey));
- assertTrue (tree.getChild(leftKey, 2).equals(leftKey.append("two")));
- } catch (ObjectNotFoundException e) {
- caught = true;
- }
- assertTrue (!caught);
-
- /* Get non-existant child of root */
- caught = false;
- try {
- tree.getChild(rootKey, 99);
- } catch (ArrayIndexOutOfBoundsException e) {
- caught = true;
- } catch (ObjectNotFoundException e) {
- throw new Error();
- }
- assertTrue (caught);
-
- /* Get non-existant child of interior node */
- caught = false;
- try {
- tree.getChild(leftKey, 99);
- } catch (ArrayIndexOutOfBoundsException e) {
- caught = true;
- } catch (ObjectNotFoundException e) {
- throw new Error();
- }
- assertTrue (caught);
-
- /* Get non-existant child of leaf node */
- caught = false;
- try {
- tree.getChild(leftKey.append("one"), 99);
- } catch (ArrayIndexOutOfBoundsException e) {
- caught = true;
- } catch (ObjectNotFoundException e) {
- throw new Error();
- }
- assertTrue (caught);
-
- /* Try to getChild using non-existent key */
- caught = false;
- try {
- tree.getChild(rootKey.append("bogus"), 0);
- } catch (ObjectNotFoundException e) {
- caught = true;
- }
- assertTrue (caught);
-
- return;
- }
- /**
- * Answer the number of children of the specified node.
- *
- * @exception ObjectNotFoundException
- * parentKey does not exist in the receiver
- */
- public void testGetChildCount () {
-
- boolean caught;
-
- caught = false;
- try {
- /* empty tree */
- assertTrue ("1", emptyTree.getChildCount(rootKey) == 0);
-
- /* root node */
- assertTrue ("2", tree.getChildCount(rootKey) == 2);
-
- /* interior nodes */
- assertTrue ("3", tree.getChildCount(leftKey) == 3);
- assertTrue ("4", tree.getChildCount(rightKey) == 1);
-
- /* leaf nodes */
- assertTrue ("5", tree.getChildCount(leftKey.append("one")) == 0);
- assertTrue ("6", tree.getChildCount(leftKey.append("three")) == 0);
- assertTrue ("7", tree.getChildCount(rightKey.append("rightOfRight")) == 0);
- } catch (ObjectNotFoundException e) {
- caught = true;
- } finally {
- assertTrue (!caught);
- }
-
- caught = false;
- /* invalid parent key */
- try {
- tree.getChildCount(rootKey.append("bogus"));
- } catch (ObjectNotFoundException e) {
- caught = true;
- }
- assertTrue (caught);
-
- /* invalid parent of empty tree */
- caught = false;
- try {
- emptyTree.getChildCount(rootKey.append("bogus"));
- } catch (ObjectNotFoundException e) {
- caught = true;
- }
- assertTrue (caught);
-
- return;
- }
- /**
- * Answer the keys for the children of the specified node.
- *
- * @exception ObjectNotFoundException
- * parentKey does not exist in the receiver"
- */
- public void testGetChildren() {
-
- boolean caught;
- IPath
- testChildren[],
- rootChildren[] = {leftKey, rightKey},
- leftChildren[] = {leftKey.append("one"), leftKey.append("two"), leftKey.append("three")},
- rightChildren[] = {rightKey.append("rightOfRight")};
-
- caught = false;
- try {
- /* empty tree */
- testChildren = emptyTree.getChildren(rootKey);
- assertTrue ("1", testChildren.length == 0);
-
- /* root node */
- testChildren = tree.getChildren(rootKey);
- assertTrue ("2", testChildren.length == 2);
- assertTrue ("3", testChildren[0].equals(rootChildren[0]));
- assertTrue ("4", testChildren[1].equals(rootChildren[1]));
-
- /* interior nodes */
- testChildren = tree.getChildren(leftKey);
- assertTrue ("5", testChildren.length == 3);
- assertTrue ("6", testChildren[0].equals(leftChildren[0]));
- assertTrue ("7", testChildren[2].equals(leftChildren[1]));
- assertTrue ("8", testChildren[1].equals(leftChildren[2]));
-
- /* leaf nodes */
- testChildren = tree.getChildren(leftChildren[0]);
- assertTrue ("9", testChildren.length == 0);
-
- testChildren = tree.getChildren(rightChildren[0]);
- assertTrue ("10", testChildren.length == 0);
- } catch (ObjectNotFoundException e) {
- caught = true;
- } finally {
- assertTrue ("11", !caught);
- }
-
- caught = false;
- /* invalid parent key */
- try {
- tree.getChildren(rootKey.append("bogus"));
- } catch (ObjectNotFoundException e) {
- caught = true;
- }
- assertTrue ("12", caught);
-
- /* invalid parent of empty tree */
- caught = false;
- try {
- emptyTree.getChildren(rootKey.append("bogus"));
- } catch (ObjectNotFoundException e) {
- caught = true;
- }
- assertTrue ("13", caught);
-
- return;
- }
- /**
- * Answer the local name of the child with the given index of the
- * specified node.
- * @exception ObjectNotFoundException
- * parentKey does not exist in the receiver
- * @exception ArrayIndexOutOfBoundsException
- * if no child with the given index
- */
- public void testGetNameOfChild () {
-
- /* tested thoroughly in testGetChild() and testGetNamesOfChildren */
-
- return;
- }
- /**
- * Answer the local names for the children of the specified node.
- *
- * @exception ObjectNotFoundException
- * parentKey does not exist in the receiver
- */
- public void testGetNamesOfChildren() {
-
- boolean caught;
- String
- testChildren[],
- rootChildren[] = {"leftOfRoot", "rightOfRoot"},
- leftChildren[] = {"one", "two", "three"};
-
- caught = false;
- try {
- /* empty tree */
- testChildren = emptyTree.getNamesOfChildren(rootKey);
- assertTrue ("1", testChildren.length == 0);
-
- /* root node */
- testChildren = tree.getNamesOfChildren(rootKey);
- assertTrue ("2", testChildren.length == 2);
- assertTrue ("3", testChildren[0].equals(rootChildren[0]));
- assertTrue ("4", testChildren[1].equals(rootChildren[1]));
-
- /* interior nodes */
- testChildren = tree.getNamesOfChildren(leftKey);
- assertTrue ("5", testChildren.length == 3);
- assertTrue ("6", testChildren[0].equals(leftChildren[0]));
- assertTrue ("7", testChildren[2].equals(leftChildren[1]));
- assertTrue ("8", testChildren[1].equals(leftChildren[2]));
-
- /* leaf nodes */
- testChildren = tree.getNamesOfChildren(leftKey.append("one"));
- assertTrue ("9", testChildren.length == 0);
-
- testChildren = tree.getNamesOfChildren(rightKey.append("rightOfRight"));
- assertTrue ("10", testChildren.length == 0);
- } catch (ObjectNotFoundException e) {
- caught = true;
- } finally {
- assertTrue ("11", !caught);
- }
-
- caught = false;
- /* invalid parent key */
- try {
- tree.getNamesOfChildren(rootKey.append("bogus"));
- } catch (ObjectNotFoundException e) {
- caught = true;
- }
- assertTrue ("12", caught);
-
- /* invalid parent of empty tree */
- caught = false;
- try {
- emptyTree.getNamesOfChildren(rootKey.append("bogus"));
- } catch (ObjectNotFoundException e) {
- caught = true;
- }
- assertTrue ("13", caught);
-
- return;
- }
- /**
- * Answer true if the receiver includes a node with the given key, false
- * otherwise.
- */
- public void testIncludes () {
-
- /* tested in testCreateChild() and testDeleteChild() */
-
- assertTrue (emptyTree.includes(rootKey));
- assertTrue (tree.includes(rootKey));
- assertTrue (tree.includes(leftKey));
- assertTrue (tree.includes(rightKey));
- assertTrue (tree.includes(leftKey.append("one")));
- assertTrue (tree.includes(rightKey.append("rightOfRight")));
-
- assertTrue (!emptyTree.includes(rootKey.append("bogus")));
- assertTrue (!tree.includes(rootKey.append("bogus")));
- assertTrue (!tree.includes(leftKey.append("bogus")));
- assertTrue (!tree.includes(leftKey.append("one").append("bogus")));
- assertTrue (!tree.includes(rightKey.append("bogus")));
-
-
-
- return;
- }
- /*
- * @see Assert#assertTrue(boolean)
- */
-
- /*
- * @see Assert#assertTrue(String, boolean)
- */
-
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/dtree/DeltaDataTreeTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/dtree/DeltaDataTreeTest.java
deleted file mode 100644
index 018a79c..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/dtree/DeltaDataTreeTest.java
+++ /dev/null
@@ -1,1018 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.dtree;
-
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.dtree.*;
-import org.eclipse.core.internal.watson.DefaultElementComparator;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-
-/**
- * Test class for delta trees.
- */
-public class DeltaDataTreeTest extends DataTreeTest {
-
- DeltaDataTree tree, emptyTree, changedTree, deltaTree;
-public DeltaDataTreeTest() {
-}
-public DeltaDataTreeTest(String name) {
- super(name);
-}
- /**
- * Assert that the given tree is the same as the final delta tree
- * created in the string of deltas in testLongDeltaChain and testReroot
- *
- */
- public void assertDelta (DeltaDataTree originalTree) {
-
- /* compare to tree */
- assertTrue ("1", originalTree.includes(rootKey));
- assertTrue ("2", originalTree.includes(leftKey));
- assertTrue ("3", originalTree.includes(rightKey));
- assertTrue ("4", originalTree.includes(rootKey.append("newTopLevel")));
-
- assertTrue ("5", originalTree.includes(leftKey.append("new")));
- assertTrue ("6", originalTree.includes(leftKey.append("two")));
- assertTrue ("7", originalTree.includes(leftKey.append("three")));
- assertTrue ("8", originalTree.includes(rightKey.append("rightOfRight")));
-
- /* this was removed from "tree" */
- assertTrue ("9", !originalTree.includes(leftKey.append("one")));
- }
- /**
- * Assert that the given tree is the same as the original "tree" created
- * during setup
- */
- public void assertTree (DeltaDataTree originalTree) {
-
- /* compare to tree */
- assertTrue ("1", originalTree.includes(rootKey));
- assertTrue ("2", originalTree.includes(leftKey));
- assertTrue ("3", originalTree.includes(rightKey));
-
- assertTrue ("4", originalTree.includes(leftKey.append("one")));
- assertTrue ("5", originalTree.includes(leftKey.append("two")));
- assertTrue ("6", originalTree.includes(leftKey.append("three")));
- assertTrue ("7", originalTree.includes(rightKey.append("rightOfRight")));
- }
- /**
- * Init tests
- */
- protected void setUp() {
-
- emptyTree = new DeltaDataTree();
- tree = new DeltaDataTree();
- rootKey = Path.ROOT;
-
- /* Add two children to root */
- try {
- tree.createChild(rootKey, "leftOfRoot");
- tree.createChild(rootKey, "rightOfRoot");
- } catch (ObjectNotFoundException e) {
- throw new Error("(1) Error in setUp");
- }
-
- leftKey = rootKey.append("leftOfRoot");
- rightKey = rootKey.append("rightOfRoot");
-
- /* Add three children to left of root and one to right of root */
- try {
- tree.createChild(leftKey, "one");
- tree.createChild(leftKey, "two");
- tree.createChild(leftKey, "three");
-
- tree.createChild(rightKey, "rightOfRight");
- } catch (ObjectNotFoundException e) {
- throw new Error("(2) Error in setUp");
- }
-
- changedTree = new DeltaDataTree();
- changedTree.createSubtree(rootKey, tree.copyCompleteSubtree(rootKey));
- }
- /**
- * Run all tests
- */
-
- public static Test suite() {
- TestSuite suite= new TestSuite();
- suite.addTest(new DeltaDataTreeTest("testSetup"));
-
- suite.addTest(new DeltaDataTreeTest("testAddAndRemoveOnSameLayer"));
- suite.addTest(new DeltaDataTreeTest("testAddTwiceAndDelete"));
- suite.addTest(new DeltaDataTreeTest("testAssembleWithIn"));
- suite.addTest(new DeltaDataTreeTest("testCreateChild"));
- suite.addTest(new DeltaDataTreeTest("testDeleteChild"));
- suite.addTest(new DeltaDataTreeTest("testDeltaOnCompletelyDifferentTrees"));
- suite.addTest(new DeltaDataTreeTest("testEmpty"));
- suite.addTest(new DeltaDataTreeTest("testForwardDeltaOnDataDeltaNode"));
- suite.addTest(new DeltaDataTreeTest("testForwardDeltaWith"));
- suite.addTest(new DeltaDataTreeTest("testForwardDeltaWithEquality"));
- suite.addTest(new DeltaDataTreeTest("testGetChild"));
- suite.addTest(new DeltaDataTreeTest("testGetChildCount"));
- suite.addTest(new DeltaDataTreeTest("testGetChildren"));
- suite.addTest(new DeltaDataTreeTest("testGetNameOfChild"));
- suite.addTest(new DeltaDataTreeTest("testGetNamesOfChildren"));
- suite.addTest(new DeltaDataTreeTest("testGetNodeInfo"));
- suite.addTest(new DeltaDataTreeTest("testIncludes"));
- suite.addTest(new DeltaDataTreeTest("testLongDeltaChain"));
- suite.addTest(new DeltaDataTreeTest("testNewEmptyDeltaTree"));
- suite.addTest(new DeltaDataTreeTest("testRegression1FVVP6L"));
- suite.addTest(new DeltaDataTreeTest("testRegression1FVVP6LWithChildren"));
- suite.addTest(new DeltaDataTreeTest("testReroot"));
-
- return suite;
- }
-/**
- * Test for problem adding and deleting in same delta layer.
- */
-public void testAddAndRemoveOnSameLayer() {
- IPath elementA = Path.ROOT.append("A");
- DeltaDataTree tree1 = new DeltaDataTree();
-
- tree1.createChild(Path.ROOT, "A", "Data for A");
-
- tree1.immutable();
- DeltaDataTree tree2;
- tree2 = tree1.newEmptyDeltaTree();
-
- tree2.createChild(elementA, "B", "New B Data");
- tree2.deleteChild(elementA, "B");
-
- tree2.immutable();
-
- //do a bunch of operations to ensure the tree isn't corrupt.
- tree1.compareWith(tree2, DefaultElementComparator.getComparator());
- tree2.compareWith(tree1, DefaultElementComparator.getComparator());
- tree1.forwardDeltaWith(tree2, DefaultElementComparator.getComparator());
- tree2.forwardDeltaWith(tree1, DefaultElementComparator.getComparator());
- tree1.copyCompleteSubtree(Path.ROOT);
- tree2.copyCompleteSubtree(Path.ROOT);
- tree1.reroot();
- tree2.reroot();
- tree1.makeComplete();
- tree2.makeComplete();
-}
-/**
- * Test for problem when two complete nodes exist, and then
- * the deleting only masks the first one.
- */
-public void testAddTwiceAndDelete() {
- DeltaDataTree tree1 = new DeltaDataTree();
-
- tree1.createChild(Path.ROOT, "A", "Data for A");
-
- tree1.immutable();
- tree1 = tree1.newEmptyDeltaTree();
-
- tree1.createChild(Path.ROOT, "A", "New A Data");
-
- tree1.immutable();
- tree1 = tree1.newEmptyDeltaTree();
-
- tree1.deleteChild(Path.ROOT, "A");
- tree1.immutable();
-
- assertTrue(tree1.getChildCount(Path.ROOT) == 0);
-
-
-}
- public void testAssembleWithIn () {
-
- /**
- * Answer the result of assembling @node1 (a node of the receiver)
- * with @node2 (a node of @tree2).
- * The @node2 represents a forward delta based on @node1.
- */
-
- DeltaDataTree assembledTree;
-
- /* make a change */
- changedTree.deleteChild(leftKey, "two");
-
- /* make delta tree */
- deltaTree = tree.forwardDeltaWith (changedTree, DefaultElementComparator.getComparator());
-
-
- /* get changedTree from original and forward delta on original */
- assembledTree = tree.assembleWithForwardDelta (deltaTree);
-
- /* make sure the reconstructed tree is as expected */
- assertTrue (assembledTree.includes(rootKey));
- assertTrue (assembledTree.includes(leftKey));
- assertTrue (assembledTree.includes(leftKey.append("one")));
- assertTrue (!assembledTree.includes(leftKey.append("two")));
- assertTrue (assembledTree.includes(leftKey.append("three")));
- assertTrue (assembledTree.includes(rightKey));
-
- }
- /**
- * Create a child of the specified node and give it the specified local name.<p>
- * If a child with such a name exists, replace it with the new child
- * @exception ObjectNotFoundException
- * parentKey does not exist in the receiver
- */
- public void testCreateChild () {
-
- boolean caught;
- int size;
-
- caught = false;
- /* Create child with bogus parent key */
- try {
- tree.createChild(rootKey.append("bogus"), "foobar");
- } catch (ObjectNotFoundException e) {
- caught = true;
- } finally {
- assertTrue ("1", caught);
- }
-
- caught = false;
- /* Create child of empty tree with bogus parent */
- try {
- emptyTree.createChild(rootKey.append("bogus"), "foobar");
- } catch (ObjectNotFoundException e) {
- caught = true;
- } finally {
- assertTrue ("2", caught);
- }
-
- /* Add child to empty tree */
- try {
- emptyTree.createChild(rootKey, "first");
- } catch (ObjectNotFoundException e) {}
- assertTrue ("3", emptyTree.includes(rootKey.append("first")));
-
- /* Add root level child to non-empty tree */
- try {
- tree.createChild(rootKey, "NewTopLevel");
- } catch (ObjectNotFoundException e) {}
- assertTrue ("4", tree.includes(rootKey.append("NewTopLevel")));
- assertTrue ("5", tree.includes(leftKey));
- assertTrue ("6", tree.includes(rightKey));
- assertTrue ("7", tree.includes(leftKey.append("one")));
-
- /* Add child to leaf in non-empty tree */
- try {
- tree.createChild(leftKey.append("one"), "NewBottom");
- } catch (ObjectNotFoundException e) {}
- assertTrue ("8", tree.includes(leftKey));
- assertTrue ("9", tree.includes(rightKey));
- assertTrue ("10", tree.includes(leftKey.append("one")));
- assertTrue ("11", tree.includes(leftKey.append("one").append("NewBottom")));
-
- /* Add child to node containing only one child */
- try {
- tree.createChild(rightKey, "NewRight");
- } catch (ObjectNotFoundException e) {}
- assertTrue ("12", tree.includes(leftKey));
- assertTrue ("13", tree.includes(rightKey));
- assertTrue ("14", tree.includes(rightKey.append("rightOfRight")));
- assertTrue ("15", tree.includes(rightKey.append("NewRight")));
-
- /* Add same child twice */
- size = (tree.getNamesOfChildren(leftKey)).length;
- tree.createChild (leftKey, "double");
- tree.createChild (leftKey, "double");
- /* Make sure size has only increased by one */
- assertTrue ((tree.getNamesOfChildren(leftKey)).length == size + 1);
-
- return;
- }
- /**
- * Delete the child with the specified local name from the specified
- * node. Note: this method requires both parentKey and localName,
- * making it impossible to delete the root node.<p>
- *
- * @exception ObjectNotFoundException
- * a child of parentKey with name localName does not exist in the receiver
- */
- public void testDeleteChild() {
-
- boolean caught;
-
- /* Delete from empty */
- caught = false;
- try {
- emptyTree.deleteChild(rootKey, "non-existant");
- } catch (ObjectNotFoundException e) {
- caught = true;
- } finally {
- assertTrue ("1", caught);
- }
-
- /* delete a child that is not the child of parentKey */
- caught = false;
- try {
- tree.deleteChild(rootKey, "rightOfRight");
- } catch (ObjectNotFoundException e) {
- caught = true;
- } finally {
- assertTrue ("2", caught);
- }
- assertTrue ("3", tree.includes(rightKey.append("rightOfRight")));
-
- /* delete with bogus parent */
- caught = false;
- try {
- tree.deleteChild(rootKey.append("bogus"), "rightOfRight");
- } catch (ObjectNotFoundException e) {
- caught = true;
- } finally {
- assertTrue ("4", caught);
- }
- assertTrue ("5", tree.includes(rightKey.append("rightOfRight")));
-
- /* delete with bogus local name */
- caught = false;
- try {
- tree.deleteChild(leftKey, "four");
- } catch (ObjectNotFoundException e) {
- caught = true;
- } finally {
- assertTrue ("6", caught);
- }
- assertTrue ("7", tree.includes(leftKey));
-
- /* Delete a node with children */
- try {
- tree.deleteChild(rootKey, "leftOfRoot");
- } catch (ObjectNotFoundException e) {}
-
- assertTrue ("8", !tree.includes(leftKey));
- assertTrue ("9", !tree.includes(leftKey.append("one")));
- assertTrue ("10", tree.includes(rootKey));
-
- /* delete a leaf */
- try {
- tree.deleteChild(rightKey, "rightOfRight");
- } catch (ObjectNotFoundException e) {}
- assertTrue ("11", !tree.includes(rightKey.append("rightOfRight")));
- assertTrue ("12", tree.includes(rightKey));
-
- return;
- }
- /**
- * Creates a delta on two unrelated delta trees
- */
- public void testDeltaOnCompletelyDifferentTrees () {
-
- DeltaDataTree newTree = new DeltaDataTree();
-
-
- /* Create a new tree */
-
- /* Add two children to root */
- try {
- newTree.createChild(rootKey, "newLeft");
- newTree.createChild(rootKey, "newRight");
- } catch (ObjectNotFoundException e) {
- throw new Error("(1) Error in setUp");
- }
-
- /* Add three children to left of root and one to right of root */
- try {
- newTree.createChild(rootKey.append("newLeft"), "newOne");
- newTree.createChild(rootKey.append("newLeft"), "newTwo");
- newTree.createChild(rootKey.append("newLeft"), "newThree");
-
- newTree.createChild(rootKey.append("newRight"), "newRightOfRight");
- newTree.createChild(rootKey.append("newRight").append("newRightOfRight"), "bottom");
- } catch (ObjectNotFoundException e) {
- throw new Error("(2) Error in setUp");
- }
-
- /* get delta on different trees */
- deltaTree = newTree.forwardDeltaWith (tree, DefaultElementComparator.getComparator());
-
- /* assert delta has same content as tree */
- assertTree (deltaTree);
- assertTrue (!deltaTree.includes(rootKey.append("newLeft")));
- assertTrue (!deltaTree.includes(rootKey.append("newRight")));
-
-
- }
- /**
- * Initialize the receiver so that it is a complete, empty tree. It does
- * not represent a delta on another tree. An empty tree is defined to
- * have a root node with nil data and no children.
- */
- public void testEmpty() {
-
- assertTrue ("1", emptyTree.includes(rootKey));
- assertTrue ("2", TestHelper.getRootNode(emptyTree) != null);
- assertTrue ("3", TestHelper.getRootNode(emptyTree).getChildren().length == 0);
-
- return;
- }
- /**
- * Tests the forwardDeltaWith function where the delta is calculated
- * between a data delta node in the old tree and a complete data node
- * in the new tree.
- * This is a regression test for a problem with DataDeltaNode.forwardDeltaWith(...).
- */
- public void testForwardDeltaOnDataDeltaNode () {
-
- tree.immutable();
- DeltaDataTree tree1 = tree.newEmptyDeltaTree();
-
- tree1.setData(leftKey, "replaced");
- DeltaDataTree delta = tree1.forwardDeltaWith(changedTree, DefaultElementComparator.getComparator());
- assertTrue(delta.getData(leftKey) == null); // the value in changedTree
- }
- /**
- * Tests the forwardDeltaWith() function
- */
- public void testForwardDeltaWith () {
-
- DeltaDataTree assembledTree;
-
- /* make several changes */
- changedTree.deleteChild(leftKey, "two");
- changedTree.createChild (leftKey, "four");
- changedTree.createChild (leftKey, "five");
- changedTree.createChild (leftKey, "six");
- changedTree.createChild (rootKey, "NewTopLevel");
-
- /* make delta tree */
- deltaTree = tree.forwardDeltaWith (changedTree, DefaultElementComparator.getComparator());
-
- /* get changedTree from original and forward delta on original */
- assembledTree = tree.assembleWithForwardDelta (deltaTree);
-
- /* make sure the reconstructed tree is as expected */
- assertTrue (assembledTree.includes(rootKey));
- assertTrue (assembledTree.includes(leftKey));
- assertTrue (assembledTree.includes(rightKey));
- assertTrue (assembledTree.includes(rootKey.append("NewTopLevel")));
-
- assertTrue (assembledTree.includes(leftKey.append("one")));
- assertTrue (!assembledTree.includes(leftKey.append("two")));
- assertTrue (assembledTree.includes(leftKey.append("three")));
- assertTrue (assembledTree.includes(leftKey.append("four")));
- assertTrue (assembledTree.includes(leftKey.append("five")));
- assertTrue (assembledTree.includes(leftKey.append("six")));
- assertTrue (assembledTree.includes(rightKey.append("rightOfRight")));
-
- }
- /**
- * Tests the forwardDeltaWith() function using the equality comparer.
- */
- public void testForwardDeltaWithEquality () {
-
- DeltaDataTree assembledTree;
-
- /* make several changes */
- changedTree.deleteChild(leftKey, "two");
- changedTree.createChild (leftKey, "four");
- IPath oneKey = leftKey.append("one");
- changedTree.setData(oneKey, "New");
-
- /* make delta tree */
- deltaTree = tree.forwardDeltaWith (changedTree, DefaultElementComparator.getComparator());
-
- /* get changedTree from original and forward delta on original */
- assembledTree = tree.assembleWithForwardDelta (deltaTree);
-
- /* make sure the reconstructed tree is as expected */
- assertTrue (assembledTree.includes(rootKey));
- assertTrue (assembledTree.includes(leftKey));
- assertTrue (assembledTree.includes(rightKey));
-
- assertTrue (assembledTree.includes(leftKey.append("one")));
- assertTrue (!assembledTree.includes(leftKey.append("two")));
- assertTrue (assembledTree.includes(leftKey.append("three")));
- assertTrue (assembledTree.includes(leftKey.append("four")));
- Object data = assembledTree.getData(oneKey);
- assertTrue( data != null && data.equals("New") );
-
- }
- /**
- * Answer the key of the child with the given index of the
- * specified node.<p>
- *
- * @param: NodeKey, int
- * @return: NodeKey
- *
- * @exception ObjectNotFoundException
- * parentKey does not exist in the receiver
- * @exception ArrayIndexOutOfBoundsException
- * if no child with the given index (runtime exception)
- */
- public void testGetChild() {
-
- boolean caught;
-
- /* Get valid children */
- caught = false;
- try {
- assertTrue (tree.getChild(rootKey, 0).equals(leftKey));
- assertTrue (tree.getChild(leftKey, 2).equals(leftKey.append("two")));
- } catch (ObjectNotFoundException e) {
- caught = true;
- }
- assertTrue (!caught);
-
- /* Get non-existant child of root */
- caught = false;
- try {
- tree.getChild(rootKey, 99);
- } catch (ArrayIndexOutOfBoundsException e) {
- caught = true;
- } catch (ObjectNotFoundException e) {
- throw new Error();
- }
- assertTrue (caught);
-
- /* Get non-existant child of interior node */
- caught = false;
- try {
- tree.getChild(leftKey, 99);
- } catch (ArrayIndexOutOfBoundsException e) {
- caught = true;
- } catch (ObjectNotFoundException e) {
- throw new Error();
- }
- assertTrue (caught);
-
- /* Get non-existant child of leaf node */
- caught = false;
- try {
- tree.getChild(leftKey.append("one"), 99);
- } catch (ArrayIndexOutOfBoundsException e) {
- caught = true;
- } catch (ObjectNotFoundException e) {
- throw new Error();
- }
- assertTrue (caught);
-
- /* Try to getChild using non-existent key */
- caught = false;
- try {
- tree.getChild(rootKey.append("bogus"), 0);
- } catch (ObjectNotFoundException e) {
- caught = true;
- }
- assertTrue (caught);
-
- return;
- }
- /**
- * Answer the number of children of the specified node.
- *
- * @exception ObjectNotFoundException
- * parentKey does not exist in the receiver
- */
- public void testGetChildCount () {
-
- boolean caught;
-
- caught = false;
- try {
- /* empty tree */
- assertTrue ("1", emptyTree.getChildCount(rootKey) == 0);
-
- /* root node */
- assertTrue ("2", tree.getChildCount(rootKey) == 2);
-
- /* interior nodes */
- assertTrue ("3", tree.getChildCount(leftKey) == 3);
- assertTrue ("4", tree.getChildCount(rightKey) == 1);
-
- /* leaf nodes */
- assertTrue ("5", tree.getChildCount(leftKey.append("one")) == 0);
- assertTrue ("6", tree.getChildCount(leftKey.append("three")) == 0);
- assertTrue ("7", tree.getChildCount(rightKey.append("rightOfRight")) == 0);
- } catch (ObjectNotFoundException e) {
- caught = true;
- } finally {
- assertTrue (!caught);
- }
-
- caught = false;
- /* invalid parent key */
- try {
- tree.getChildCount(rootKey.append("bogus"));
- } catch (ObjectNotFoundException e) {
- caught = true;
- }
- assertTrue (caught);
-
- /* invalid parent of empty tree */
- caught = false;
- try {
- emptyTree.getChildCount(rootKey.append("bogus"));
- } catch (ObjectNotFoundException e) {
- caught = true;
- }
- assertTrue (caught);
-
-
-
- return;
- }
- /**
- * Answer the keys for the children of the specified node.
- *
- * @exception ObjectNotFoundException
- * parentKey does not exist in the receiver"
- */
- public void testGetChildren() {
-
- boolean caught;
- IPath
- testChildren[],
- rootChildren[] = {leftKey, rightKey},
- leftChildren[] = {leftKey.append("one"), leftKey.append("two"), leftKey.append("three")},
- rightChildren[] = {rightKey.append("rightOfRight")};
-
- caught = false;
- try {
- /* empty tree */
- testChildren = emptyTree.getChildren(rootKey);
- assertTrue ("1", testChildren.length == 0);
-
- /* root node */
- testChildren = tree.getChildren(rootKey);
- assertTrue ("2", testChildren.length == 2);
- assertTrue ("3", testChildren[0].equals(rootChildren[0]));
- assertTrue ("4", testChildren[1].equals(rootChildren[1]));
-
- /* interior nodes */
- testChildren = tree.getChildren(leftKey);
- assertTrue ("5", testChildren.length == 3);
- assertTrue ("6", testChildren[0].equals(leftChildren[0]));
- assertTrue ("7", testChildren[2].equals(leftChildren[1]));
- assertTrue ("8", testChildren[1].equals(leftChildren[2]));
-
- /* leaf nodes */
- testChildren = tree.getChildren(leftChildren[0]);
- assertTrue ("9", testChildren.length == 0);
-
- testChildren = tree.getChildren(rightChildren[0]);
- assertTrue ("10", testChildren.length == 0);
- } catch (ObjectNotFoundException e) {
- caught = true;
- } finally {
- assertTrue ("11", !caught);
- }
-
- caught = false;
- /* invalid parent key */
- try {
- tree.getChildren(rootKey.append("bogus"));
- } catch (ObjectNotFoundException e) {
- caught = true;
- }
- assertTrue ("12", caught);
-
- /* invalid parent of empty tree */
- caught = false;
- try {
- emptyTree.getChildren(rootKey.append("bogus"));
- } catch (ObjectNotFoundException e) {
- caught = true;
- }
- assertTrue ("13", caught);
-
- return;
- }
- /**
- * Answer the local name of the child with the given index of the
- * specified node.
- * @exception ObjectNotFoundException
- * parentKey does not exist in the receiver
- * @exception ArrayIndexOutOfBoundsException
- * if no child with the given index
- */
- public void testGetNameOfChild () {
-
- /* tested thoroughly in testGetChild() and testGetNamesOfChildren */
-
- return;
- }
- /**
- * Returns the local names for the children of the specified node.
- *
- * @exception ObjectNotFoundException
- * parentKey does not exist in the receiver
- */
- public void testGetNamesOfChildren() {
-
- boolean caught;
- String
- testChildren[],
- rootChildren[] = {"leftOfRoot", "rightOfRoot"},
- leftChildren[] = {"one", "two", "three"},
- rightChildren[] = {"rightOfRight"};
-
- caught = false;
- try {
- /* empty tree */
- testChildren = emptyTree.getNamesOfChildren(rootKey);
- assertTrue ("1", testChildren.length == 0);
-
- /* root node */
- testChildren = tree.getNamesOfChildren(rootKey);
- assertTrue ("2", testChildren.length == 2);
- assertTrue ("3", testChildren[0].equals(rootChildren[0]));
- assertTrue ("4", testChildren[1].equals(rootChildren[1]));
-
- /* interior nodes */
- testChildren = tree.getNamesOfChildren(leftKey);
- assertTrue ("5", testChildren.length == 3);
- assertTrue ("6", testChildren[0].equals(leftChildren[0]));
- assertTrue ("7", testChildren[2].equals(leftChildren[1]));
- assertTrue ("8", testChildren[1].equals(leftChildren[2]));
-
- testChildren = tree.getNamesOfChildren(rightKey);
- assertTrue("8.1", testChildren.length == 1);
- assertTrue("8.2", testChildren[0].equals(rightChildren[0]));
-
- /* leaf nodes */
- testChildren = tree.getNamesOfChildren(leftKey.append("one"));
- assertTrue ("9", testChildren.length == 0);
-
- testChildren = tree.getNamesOfChildren(rightKey.append("rightOfRight"));
- assertTrue ("10", testChildren.length == 0);
- } catch (ObjectNotFoundException e) {
- caught = true;
- } finally {
- assertTrue ("11", !caught);
- }
-
- caught = false;
- /* invalid parent key */
- try {
- tree.getNamesOfChildren(rootKey.append("bogus"));
- } catch (ObjectNotFoundException e) {
- caught = true;
- }
- assertTrue ("12", caught);
-
- /* invalid parent of empty tree */
- caught = false;
- try {
- emptyTree.getNamesOfChildren(rootKey.append("bogus"));
- } catch (ObjectNotFoundException e) {
- caught = true;
- }
- assertTrue ("13", caught);
-
- return;
- }
- /**
- * Test the getNodeInfo(NodeKey) method
- */
- public void testGetNodeInfo () {
-
- /**
- * Answer a node info object describing the specified node
- * of the receiver. Only the receiver's representation is accessed. If the
- * receiver is a delta representation, and the specified node has not been
- * modified in the delta, the node info describes the node as missing (the parent
- * tree is not consulted).
- */
-
- /* basic node info on a complete tree */
- NodeInfo info = tree.getNodeInfo(rootKey);
- assertTrue ("1", info.getNamesOfChildren().length == 2);
- assertTrue ("2", info.getNamesOfChildren()[0].equals("leftOfRoot"));
- assertTrue ("3", info.getNamesOfChildren()[1].equals("rightOfRoot"));
- assertTrue ("4", info.getNamesOfDeletedChildren().length == 0);
-
- info = tree.getNodeInfo (leftKey);
- assertTrue ("5", info.getNamesOfChildren().length == 3);
- assertTrue ("6", info.getNamesOfChildren()[0].equals("one"));
- assertTrue ("7", info.getNamesOfChildren()[2].equals("two"));
- assertTrue ("8", info.getNamesOfDeletedChildren().length == 0);
-
- /* create a delta with deletions */
- tree.immutable();
- DeltaDataTree delta = tree.newEmptyDeltaTree();
- delta.deleteChild (leftKey, "one");
- delta.deleteChild (rootKey, "rightOfRoot");
-
- /* get info on deleted tree */
- info = delta.getNodeInfo (rootKey);
- assertTrue ("9", info.getNamesOfChildren().length == 1);
- assertTrue ("10", info.getNamesOfDeletedChildren().length == 1);
- assertTrue ("11", info.getNamesOfChildren()[0].equals("leftOfRoot"));
- assertTrue ("12", info.getNamesOfDeletedChildren()[0].equals("rightOfRoot"));
-
- info = delta.getNodeInfo (leftKey);
- assertTrue ("13", info.getNamesOfChildren().length == 0);
- assertTrue ("14", info.getNamesOfDeletedChildren().length == 1);
- assertTrue ("15", info.getNamesOfDeletedChildren()[0].equals("one"));
-
- info = delta.getNodeInfo (rightKey);
- assertTrue ("16", info.getType() == AbstractDataTreeNode.T_DELETED_NODE);
-
- }
- /**
- * Returns true if the receiver includes a node with the given key, false
- * otherwise.
- */
- public void testIncludes () {
-
- /* tested in testCreateChild() and testDeleteChild() */
-
- assertTrue (emptyTree.includes(rootKey));
- assertTrue (tree.includes(rootKey));
- assertTrue (tree.includes(leftKey));
- assertTrue (tree.includes(rightKey));
- assertTrue (tree.includes(leftKey.append("one")));
- assertTrue (tree.includes(rightKey.append("rightOfRight")));
-
- assertTrue (!emptyTree.includes(rootKey.append("bogus")));
- assertTrue (!tree.includes(rootKey.append("bogus")));
- assertTrue (!tree.includes(leftKey.append("bogus")));
- assertTrue (!tree.includes(leftKey.append("one").append("bogus")));
- assertTrue (!tree.includes(rightKey.append("bogus")));
-
-
-
- return;
- }
- /**
- * Tests operations on a chain of deltas
- */
- public void testLongDeltaChain () {
-
- final int NUM_DELTAS = 10;
-
- DeltaDataTree deltas[] = new DeltaDataTree[NUM_DELTAS];
-
- /* create a delta on the original tree, and make a change */
- tree.immutable();
- deltas[0] = tree.newEmptyDeltaTree();
- deltas[0].createChild (leftKey, "new");
- assertTree (deltas[0]);
- assertTrue (deltas[0].includes(leftKey.append("new")));
-
- /* create a second delta and make a change to that */
- deltas[0].immutable();
- deltas[1] = deltas[0].newEmptyDeltaTree();
- deltas[1].deleteChild (leftKey, "one");
- assertEquals ("parent 0 -> 1", deltas[1].getParent(), deltas[0]);
- assertTrue (!deltas[1].includes(leftKey.append("one")));
-
- /* create a third delta and make a change to that */
- deltas[1].immutable();
- deltas[2] = deltas[1].newEmptyDeltaTree();
- deltas[2].createChild (rootKey, "newTopLevel");
- assertEquals ("parent 1 -> 2", deltas[2].getParent(), deltas[1]);
- assertEquals ("parent 0 -> 2", deltas[2].getParent().getParent(), deltas[0]);
- assertTrue (!deltas[2].includes(leftKey.append("one")));
- assertTrue (deltas[2].includes(rootKey.append("newTopLevel")));
-
-
- }
- /**
- * Tests the newEmptyDeltaTree method
- */
- public void testNewEmptyDeltaTree () {
-
- tree.immutable();
- DeltaDataTree delta = tree.newEmptyDeltaTree();
- assertEquals ("parent", tree, delta.getParent());
- assertTree (delta);
-
- }
-/**
- * Test for problem deleting and re-adding in same delta layer.
- */
-public void testRegression1FVVP6L() {
- IPath elementA = Path.ROOT.append("A");
-
- DeltaDataTree tree1 = new DeltaDataTree();
-
- tree1.createChild(Path.ROOT, "A", "Data for A");
- tree1.createChild(elementA, "B", "Data for B");
-
- tree1.immutable();
- tree1 = tree1.newEmptyDeltaTree();
-
- tree1.deleteChild(elementA, "B");
- tree1.createChild(elementA, "B", "New B Data");
-
- tree1.immutable();
- tree1 = tree1.newEmptyDeltaTree();
-
- tree1.deleteChild(elementA, "B");
-
- try {
- tree1.copyCompleteSubtree(Path.ROOT);
- } catch (RuntimeException e) {
- assertTrue("Unexpected error copying tree", false);
- }
-
-}
-/**
- * Test for problem deleting and re-adding in same delta layer.
- */
-public void testRegression1FVVP6LWithChildren() {
- IPath elementA = Path.ROOT.append("A");
- IPath elementB = elementA.append("B");
- IPath elementC = elementB.append("C");
-
- DeltaDataTree tree1 = new DeltaDataTree();
-
- tree1.createChild(Path.ROOT, "A", "Data for A");
- tree1.createChild(elementA, "B", "Data for B");
- tree1.createChild(elementB, "C", "Data for C");
-
- tree1.immutable();
- tree1 = tree1.newEmptyDeltaTree();
-
- tree1.deleteChild(elementA, "B");
- tree1.createChild(elementA, "B", "New B Data");
-
- tree1.immutable();
- tree1 = tree1.newEmptyDeltaTree();
-
- assertTrue("Child exists after deletion", !tree1.includes(elementC));
-
- try {
- tree1.copyCompleteSubtree(Path.ROOT);
- } catch (RuntimeException e) {
- assertTrue("Unexpected error copying tree", false);
- }
-
-}
- /**
- * Tests the reroot function
- */
- public void testReroot () {
-
- final int NUM_DELTAS = 10;
-
- DeltaDataTree deltas[] = new DeltaDataTree[NUM_DELTAS];
-
- /* create a delta on the original tree, and make a change */
- tree.immutable();
- deltas[0] = tree.newEmptyDeltaTree();
- deltas[0].createChild (leftKey, "new");
- assertTree (deltas[0]);
- assertTrue (deltas[0].includes(leftKey.append("new")));
-
- /* create a second delta and make a change to that */
- deltas[0].immutable();
- deltas[1] = deltas[0].newEmptyDeltaTree();
- deltas[1].deleteChild (leftKey, "one");
- assertEquals ("parent 0 -> 1", deltas[1].getParent(), deltas[0]);
- assertTrue (!deltas[1].includes(leftKey.append("one")));
-
- /* create a third delta and make a change to that */
- deltas[1].immutable();
- deltas[2] = deltas[1].newEmptyDeltaTree();
- deltas[2].createChild (rootKey, "newTopLevel");
- assertEquals ("parent 1 -> 2", deltas[2].getParent(), deltas[1]);
- assertEquals ("parent 0 -> 2", deltas[2].getParent().getParent(), deltas[0]);
- assertTrue (!deltas[2].includes(leftKey.append("one")));
- assertTrue (deltas[2].includes(rootKey.append("newTopLevel")));
-
- /* create a fourth delta and reroot at it */
- deltas[2].immutable();
- deltas[3] = deltas[2].newEmptyDeltaTree();
- deltas[3].immutable();
- deltas[3].reroot();
- assertTrue (deltas[3].getParent() == null);
- assertTrue (deltas[2].getParent() == deltas[3]);
- assertTrue (deltas[1].getParent() == deltas[2]);
- assertTrue (deltas[0].getParent() == deltas[1]);
-
- /* test that all trees have the same representation as before rerooting */
- assertTree (tree);
- assertTrue (!tree.includes(leftKey.append("new")));
- assertTrue (tree.includes(leftKey.append("one")));
- assertTree (deltas[0]);
- assertTrue (deltas[0].includes(leftKey.append("new")));
- assertTrue (deltas[0].includes(leftKey.append("one")));
- assertTrue (deltas[1].includes(leftKey.append("new")));
- assertTrue (!deltas[1].includes(leftKey.append("one")));
- assertDelta (deltas[2]);
- assertDelta (deltas[3]);
-
- }
- /**
- * Tests that the setUp() method is doing what it should
- */
- public void testSetup ( ) {
-
- assertTree (tree);
- assertTree (changedTree);
-
- return;
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/AllTests.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/AllTests.java
deleted file mode 100644
index 1a28db5..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/AllTests.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.indexing;
-
-import junit.framework.*;
-
-public class AllTests extends TestCase {
-
- public AllTests() {
- super(null);
- }
-
- public AllTests(String name) {
- super(name);
- }
-
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(IntegratedFieldTest.suite());
- suite.addTest(IntegratedIndexedStoreTest.suite());
- suite.addTest(IntegratedObjectStoreTest.suite());
- suite.addTest(IntegratedPageStoreTest.suite());
- return suite;
- }
-
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/BasicFieldTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/BasicFieldTest.java
deleted file mode 100644
index d5a4e1a..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/BasicFieldTest.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.indexing;
-
-import java.util.*;
-import org.eclipse.core.internal.indexing.*;
-import junit.framework.*;
-
-public class BasicFieldTest extends TestCase {
-
- protected TestEnvironment env;
-
- public BasicFieldTest(String name, TestEnvironment env) {
- super(name);
- this.env = env;
- }
-
- public static Test suite(TestEnvironment env) {
- List names = new Vector(10);
- names.add("testBuffer");
- names.add("testPointer");
- names.add("testField");
- names.add("testFieldArray");
- TestSuite suite = new TestSuite();
- for (Iterator z = names.iterator(); z.hasNext();) {
- suite.addTest(new BasicFieldTest((String)z.next(), env));
- }
- return suite;
- }
-
- public void testBuffer() throws Exception {
- byte[] b = new byte[256];
- Buffer buf = new Buffer(b);
- int n = buf.length();
- buf.clear();
- b[0] = -128;
- b[1] = -0;
- b[2] = -0;
- b[3] = -0;
- assertEquals("t01", 0xFFFFFF80, buf.getInt(0, 1));
- assertEquals("t02", 0xFFFF8000, buf.getInt(0, 2));
- assertEquals("t03", 0xFF800000, buf.getInt(0, 3));
- assertEquals("t04", 0x80000000, buf.getInt(0, 4));
- assertEquals("t05", 0x00000080, buf.getUInt(0, 1));
- assertEquals("t06", 0x00008000, buf.getUInt(0, 2));
- assertEquals("t07", 0x00800000, buf.getUInt(0, 3));
- assertEquals("t08", 0x00000000, buf.getUInt(0, 4));
-
- for (int i = 0; i < n; i ++) b[i] = 1;
- buf.clear(10, 10);
- for (int i = 0; i < n; i++) {
- if (i < 10) assertEquals("t31", 1, b[i]);
- else if (i < 20) assertEquals("t32", 0, b[i]);
- else assertEquals("t33", 1, b[i]);
- }
-
- n = 16;
- b = new byte[n];
- buf = new Buffer(b);
- b[0] = 1;
- buf.copyInternal(0, 1, 1);
- buf.copyInternal(0, 2, 2);
- buf.copyInternal(0, 4, 4);
- buf.copyInternal(0, 8, 8);
- for (int i = 0; i < n; i++) {
- assertEquals("t21", 1, b[i]);
- }
-
- byte[] b1 = new byte[4];
- byte[] b2 = new byte[2];
- Buffer buf1 = new Buffer(b1);
- Buffer buf2 = new Buffer(b2);
- assertEquals("t22", 1, Buffer.compare(buf1, buf2));
- assertEquals("t23", -1, Buffer.compare(buf2, buf1));
- assertEquals("t24", 0, Buffer.compare(buf1, buf1));
- b2[0] = 1;
- assertEquals("t25", -1, Buffer.compare(buf1, buf2));
- assertEquals("t26", 1, Buffer.compare(buf2, buf1));
- }
-
- public void testField() throws Exception {
- }
-
- public void testFieldArray() throws Exception {
- }
-
- public void testPointer() throws Exception {
- }
-
- public void testFieldDef() throws Exception {
- byte[] b = new byte[256];
- Field f = new Field(b);
- Buffer buf = new Buffer(b);
- FieldDef d01 = new FieldDef(FieldDef.F_INT, 2, 1);
- FieldDef d02 = new FieldDef(FieldDef.F_INT, 2, 2);
- FieldDef d03 = new FieldDef(FieldDef.F_INT, 2, 3);
- FieldDef d04 = new FieldDef(FieldDef.F_INT, 2, 4);
- FieldDef d05 = new FieldDef(FieldDef.F_LONG, 2, 5);
- FieldDef d06 = new FieldDef(FieldDef.F_LONG, 2, 6);
- FieldDef d07 = new FieldDef(FieldDef.F_LONG, 2, 7);
- FieldDef d08 = new FieldDef(FieldDef.F_LONG, 2, 8);
- FieldDef d99 = new FieldDef(FieldDef.F_BYTES, 2, 99);
-
- f.clear();
- f.put(d01, 255);
- assertEquals("1d01", 255L << 56, buf.getLong(2, 8));
- f.put(d02, 255);
- assertEquals("1d02", 255L << 48, buf.getLong(2, 8));
- f.put(d03, 255);
- assertEquals("1d03", 255L << 40, buf.getLong(2, 8));
- f.put(d04, 255);
- assertEquals("1d04", 255L << 32, buf.getLong(2, 8));
- f.put(d05, 255);
- assertEquals("1d05", 255L << 24, buf.getLong(2, 8));
- f.put(d06, 255);
- assertEquals("1d06", 255L << 16, buf.getLong(2, 8));
- f.put(d07, 255);
- assertEquals("1d07", 255L << 8, buf.getLong(2, 8));
- f.put(d08, 255);
- assertEquals("1d08", 255L << 0, buf.getLong(2, 8));
-
- f.clear();
- f.put(d01, 255);
- assertEquals("2d01", 255, f.getUInt(d01));
- f.put(d02, 255);
- assertEquals("2d02", 255, f.getUInt(d02));
- f.put(d03, 255);
- assertEquals("2d03", 255, f.getUInt(d03));
- f.put(d04, 255);
- assertEquals("2d04", 255, f.getUInt(d04));
- f.put(d05, 255);
- assertEquals("2d05", 255, f.getUInt(d05));
- f.put(d06, 255);
- assertEquals("2d06", 255, f.getUInt(d06));
- f.put(d07, 255);
- assertEquals("2d07", 255, f.getUInt(d07));
- f.put(d08, 255);
- assertEquals("2d08", 255, f.getUInt(d08));
- f.put(d99, 255);
- assertEquals("2d99", 255, f.getUInt(d99));
- assertEquals("3d99", 255, buf.getUInt(100, 1));
- }
-
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/BasicIndexedStoreTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/BasicIndexedStoreTest.java
deleted file mode 100644
index c8dfb08..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/BasicIndexedStoreTest.java
+++ /dev/null
@@ -1,988 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.indexing;
-
-import java.io.StringWriter;
-import java.util.*;
-
-import junit.framework.*;
-import org.eclipse.core.internal.indexing.*;
-
-public class BasicIndexedStoreTest extends TestCase {
-
- TestEnvironment env;
-
- public BasicIndexedStoreTest(String name, TestEnvironment env) {
- super(name);
- this.env = env;
- }
-
- public static Test suite(TestEnvironment env) {
- TestSuite suite = new TestSuite();
- suite.addTest(new BasicIndexedStoreTest("testSanity", env));
- suite.addTest(new BasicIndexedStoreTest("testRecovery", env));
- suite.addTest(new BasicIndexedStoreTest("testTransactions", env));
- suite.addTest(new BasicIndexedStoreTest("testIndexInsert", env));
- suite.addTest(new BasicIndexedStoreTest("testIndexCursorOperations", env));
- suite.addTest(new BasicIndexedStoreTest("testIndexRemove", env));
- suite.addTest(new BasicIndexedStoreTest("testIndexOrdering", env));
- suite.addTest(new BasicIndexedStoreTest("testIndexReplace", env));
- suite.addTest(new BasicIndexedStoreTest("testObjectUpdate", env));
- suite.addTest(new BasicIndexedStoreTest("testObjectPerformance", env));
- suite.addTest(new BasicIndexedStoreTest("testMultiCursorSearch", env));
- suite.addTest(new BasicIndexedStoreTest("testMultiCursorUpdate", env));
- suite.addTest(new BasicIndexedStoreTest("testMultiCursorRemove1", env));
- suite.addTest(new BasicIndexedStoreTest("testMultiCursorRemove2", env));
- suite.addTest(new BasicIndexedStoreTest("testIndexSplit", env));
- suite.addTest(new BasicIndexedStoreTest("test1GCE9JD", env));
- suite.addTest(new BasicIndexedStoreTest("testObjectLife", env));
- return suite;
- }
-
- private int random(int lo, int hi) {
- double t0 = Math.random();
- double t1 = (hi + 1 - lo) * t0 + lo;
- double t2 = Math.floor(t1);
- return (int) t2;
- }
-
- /**
- * Generates a string of length n from a number i.
- */
- private String generateString(int n, int i) {
- StringWriter a = new StringWriter();
- String suffix = Integer.toString(i);
- for (int k = 0; k < (n - suffix.length()); k++) a.write("0");
- a.write(suffix);
- return a.toString();
- }
-
- /**
- * Insert entries with the specified key length into the index. Compare the ordering after insertion.
- * Key values are 0 to numberOfEntries-1.
- * Keys are inserted in order of their value modulo the skip value.
- * That is, all values equivalent to 0 are inserted first, then all values equivalent to 1, ...
- */
- private void insertAndCompare(int keySize, int numberOfEntries, int skipValue) throws Exception {
- IndexedStore.delete(env.getFileName());
- IndexedStore store = new IndexedStore();
- store.open(env.getFileName());
- store.createIndex("Index");
- Index index = store.getIndex("Index");
- String key;
- for (int i = 0; i < skipValue; i++) {
- int j = i;
- while (j < numberOfEntries) {
- key = generateString(keySize, j);
- index.insert(key, "");
- j += skipValue;
- if (j % 100 == 0)
- store.commit();
- }
- store.commit();
- }
- store.close();
-
- store.open(env.getFileName());
- index = store.getIndex("Index");
- IndexCursor c = index.open();
- c.findFirstEntry();
- int j = 0;
- while (!c.isAtEnd()) {
- assertEquals(c.getKeyAsString(), generateString(keySize, j));
- c.next();
- j++;
- }
- store.close();
- }
-
-
- /**
- * Test for index store mess up recorded in PR 1GCE9JD
- */
- public void test1GCE9JD() throws Exception {
- IndexedStore store = null;
- IndexedStore.delete(env.getFileName());
- store = new IndexedStore();
- store.open(env.getFileName());
- try {
- String a = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>.<classpath>. <classpathentry kind=\"src\" path=\"\"/>. <classpathentry kind=\"output\" path=\"\"/>.</classpath>";
- store.createIndex("index");
- ObjectID id = store.createObject(a);
- String b = store.getObjectAsString(id);
- assertEquals(a, b);
- } finally {
- store.close();
- }
- }
-
-
- /**
- * This tests basic cursor insertion, location, and removal operations.
- */
- public void testIndexCursorOperations() throws Exception {
- IndexedStore.delete(env.getFileName());
- IndexedStore store = new IndexedStore();
- store.open(env.getFileName());
- try {
-
- /* Create an index */
- store.createIndex("Index1");
- Index index = store.getIndex("Index1");
- String key = null;
- ObjectID id = null;
-
- /* populate the index using unique values and duplicate keys */
- for (int i = 0; i < 10; i++) {
- index.insert("abaa", new ObjectID(i));
- }
- for (int i = 10; i < 20; i++) {
- index.insert("acaa", new ObjectID(i));
- }
- store.commit();
-
- /* run the index from beginning to end, testing the values */
- IndexCursor c = index.open();
- int i = 0;
- c.findFirstEntry();
- while (!c.isAtEnd()) {
- id = c.getValueAsObjectID();
- assertTrue("assertion 1 value " + i, id.equals(new ObjectID(i)));
- c.next();
- i++;
- }
-
- /* run the index from the end to the beginning, testing the values */
- i = 19;
- c.previous();
- while (!c.isAtBeginning()) {
- id = c.getValueAsObjectID();
- assertTrue("assertion 2 value " + i, id.equals(new ObjectID(i)));
- c.previous();
- i--;
- }
- c.close();
-
- /* find all entries matching a given prefix */
- c = index.open();
- key = "ab";
- c.find(key);
- i = 0;
- while (c.keyMatches(key)) {
- id = c.getValueAsObjectID();
- assertTrue("assertion 3 value " + i, id.equals(new ObjectID(i)));
- c.next();
- i++;
- }
- assertTrue("assertion 3.1", i == 10);
- c.close();
-
- /* find all entries matching a different prefix */
- key = "ac";
- c = index.open();
- c.find(key);
- while (c.keyMatches(key)) {
- id = c.getValueAsObjectID();
- assertTrue("assertion 4 value " + i, id.equals(new ObjectID(i)));
- c.next();
- i++;
- }
- assertTrue("assertion 4.1", i == 20);
- c.close();
-
- /* find all entries matching a third prefix */
- key = "a";
- c = index.open();
- i = 0;
- c.find(key);
- while (c.keyMatches(key)) {
- id = c.getValueAsObjectID();
- assertTrue("assertion 5 value " + i, id.equals(new ObjectID(i)));
- c.next();
- i++;
- }
- assertTrue("assertion 5.1", i == 20);
- c.close();
-
- /* remove some entries that match a given prefix */
- key = "ab";
- c = index.open();
- c.find(key);
- while (c.keyMatches(key)) {
- c.remove();
- }
- c.close();
- store.commit();
- i = index.getNumberOfEntries();
- assertTrue("assertion 5.9 value " + i, i == 10);
-
- /* rescan the index to find all entries that match the short prefix again */
- key = "a";
- c = index.open();
- c.find(key);
- i = 10;
- while (c.keyMatches(key)) {
- id = c.getValueAsObjectID();
- assertTrue("assertion 6 value " + i, id.equals(new ObjectID(i)));
- c.next();
- i++;
- }
- assertTrue("assertion 6.1", i == 20);
- c.close();
-
- /* get the list of all identifiers in the index */
- Vector v = index.getObjectIdentifiersMatching("a");
- Iterator idStream = v.iterator();
- i = 10;
- while (idStream.hasNext()) {
- id = (ObjectID) idStream.next();
- assertTrue("assertion 7 value " + i, id.equals(new ObjectID(i)));
- i++;
- }
- assertTrue(i == 20);
- store.removeIndex("Index1");
- } finally {
- store.close();
- }
- }
-
-
- /**
- * Insert 1000 entries with a key length 64 and value length 0 into an index.
- */
- public void testIndexInsert() throws Exception {
- insertAndCompare(64, 1000, 1);
- }
-
-
- /**
- * Tests the insertion of strings -- makes sure conversion to UTF8 is done correctly and that
- * the index leaf nodes are ordered properly.
- * Also tests many small insertions.
- */
- public void testIndexOrdering() throws Exception {
- IndexedStore.delete(env.getFileName());
- IndexedStore store = new IndexedStore();
- store.open(env.getFileName());
- try {
- store.createIndex("Index");
- Index index = store.getIndex("Index");
- String key, value;
-
- /* populate the index */
- for (int i = 0; i < 10000; i++) {
- key = (new Integer(i)).toString();
- value = "";
- index.insert(key, value);
- if (i % 500 == 0)
- store.commit();
- }
- } finally {
- store.close();
- }
-
- /* run the index, testing the key order */
- store.open(env.getFileName());
- try {
- Index index = store.getIndex("Index");
- IndexCursor c = index.open();
- c.findFirstEntry();
- String lastKey = "";
- while (!c.isAtEnd()) {
- String key = c.getKeyAsString();
- assertTrue(lastKey.compareTo(key) < 0);
- lastKey = key;
- c.next();
- }
- c.close();
- } finally {
- store.close();
- }
- }
-
-
- /**
- * Tests removal of items.
- * Create an index. Add items and remove items from it.
- * Alternately expanding the index and contracting it.
- */
- public void testIndexRemove() throws Exception {
- int limit = 200;
- int keySize = 500;
- int valueSize = 100;
- IndexedStore.delete(env.getFileName());
- IndexedStore store = new IndexedStore();
- store.open(env.getFileName());
- try {
- store.createIndex("Index");
- Index index = store.getIndex("Index");
- for (int i = 0; i < limit; i += 20) {
- for (int j = 0; j < i; j++) {
- String key = generateString(keySize, j);
- String value = generateString(valueSize, 0);
- index.insert(key, value);
- }
- store.commit();
- assertEquals("test after insert", i, index.getNumberOfEntries());
- index.getNumberOfNodes();
- IndexCursor c = index.open();
- for (int j = 0; j < i; j++) {
- String key = generateString(keySize, j);
- c.find(key).remove();
- }
- c.close();
- store.commit();
- assertEquals("test after removal", 0, index.getNumberOfEntries());
- assertEquals("test nodes after removal", 0, index.getNumberOfNodes());
- }
- } finally {
- store.close();
- }
- }
-
-
- /**
- * Tests the replacement of values of items in an index.
- */
- public void testIndexReplace() throws Exception {
- IndexedStore.delete(env.getFileName());
- IndexedStore store = new IndexedStore();
- int n = 5000;
- int i;
- store.open(env.getFileName());
- try {
- Index index = store.createIndex("Index");
- String key;
- String value = "---*---*---*---*";
-
- for (i = 0; i < n; i++) {
- key = generateString(16, i);
- index.insert(key, "");
- if (i % 100 == 99)
- store.commit();
- }
-
- IndexCursor c = index.open();
- c.findFirstEntry();
- i = 0;
- while (!c.isAtEnd()) {
- c.updateValue(value);
- c.next();
- if (i % 100 == 99)
- store.commit();
- i++;
- }
- assertTrue(i == n);
-
- c = index.open();
- c.findFirstEntry();
- i = 0;
- while (!c.isAtEnd()) {
- assertEquals(value, c.getValueAsString());
- c.next();
- i++;
- }
- } finally {
- store.close();
- }
- }
-
-
- /**
- * Store sequential keys in an index, retrieve them by cursor and by individual key.
- * Make sure there are enough to force some page splitting behavior. There are runs of
- * keys in this test. Retrieval by key points at first one.
- */
- public void testIndexSplit() throws Exception {
- int n = 5; /* the number of key runs to generate */
- int l = 500; /* the length of each key */
- int r = 200; /* number of entries in a run of keys */
- int i;
- Vector key = new Vector(n);
-
- env.println("Generating...");
- for (i = 0; i < n; i++) {
- key.addElement(generateString(l, i));
- }
- env.println("...Done");
-
- IndexedStore.delete(env.getFileName());
- IndexedStore store = new IndexedStore();
-
- env.println("Inserting...");
- store.open(env.getFileName());
- try {
- Index index = store.createIndex("Index");
- for (i = 0; i < n; i++) {
- for (int j = 0; j < r; j++) {
- index.insert((String) key.elementAt(i), "");
- }
- store.commit();
- }
- } finally {
- store.close();
- }
- env.println("...Done");
-
- env.println("Retrieving by cursor...");
- store.open(env.getFileName());
- try {
- Index index = store.getIndex("Index");
- IndexCursor c = index.open();
- c.findFirstEntry();
- i = 0;
- while (!c.isAtEnd()) {
- for (int j = 0; j < r; j++) {
- assertEquals(c.getKeyAsString(), (String) key.elementAt(i));
- c.next();
- }
- i++;
- }
- } finally {
- store.close();
- }
- env.println("...Done");
-
- env.println("Retrieving by key...");
- store.open(env.getFileName());
- try {
- Index index = store.getIndex("Index");
- IndexCursor c = index.open();
- for (i = 0; i < n; i++) {
- c.find((String) key.elementAt(i));
- for (int j = 0; j < r; j++) {
- assertTrue(c.keyEquals((String) key.elementAt(i)));
- c.next();
- }
- }
- c.close();
- } finally {
- store.close();
- }
- env.println("...Done");
- }
-
-
- /**
- * Tests usage of multiple cursors in a single thread.
- * This is a removal test to ensure there are no interactions between cursors.
- * A value will be removed that will cause cursors to be adjusted.
- * Make sure that all the cursors are adjusted correctly.
- */
- public void testMultiCursorRemove1() throws Exception {
- IndexedStore.delete(env.getFileName());
- IndexedStore store = new IndexedStore();
- int keySize = 10;
- String key;
- int n = 10; /* number of entries & cursors */
- store.open(env.getFileName());
- try {
- Index index = store.createIndex("Index");
-
- /* create and populate an index */
- for (int i = 0; i < n; i++) {
- key = generateString(keySize, i);
- index.insert(key, "");
- }
- store.commit();
-
- /* get and place n cursors at the n entries */
- IndexCursor[] c = new IndexCursor[n];
- for (int i = 0; i < n; i++) {
- key = generateString(keySize, i);
- c[i] = index.open();
- c[i].find(key);
- }
-
- /* remove the entries at the cursors, this will cause cursor adjustment. */
- for (int i = 0; i < n; i++) {
- c[i].remove();
- for (int j = i + 1; j < n; j++) {
- String key0 = generateString(keySize, j);
- String keyj = c[j].getKeyAsString();
- if (j == i + 1) {
- String keyi = c[i].getKeyAsString();
- assertEquals(keyi, keyj);
- }
- assertEquals(key0, keyj);
- }
- c[i].close();
- }
- } finally {
- store.close();
- }
- }
-
-
- /**
- * Test usage of multiple cursors in a single thread.
- * This is a deletion test to ensure that if two cursors point to the
- * same entry you can delete the entry, but the other cursors become
- * invalid until repositioned.
- */
- public void testMultiCursorRemove2() throws Exception {
- IndexedStore.delete(env.getFileName());
- IndexedStore store = new IndexedStore();
- int keySize = 10;
- String key;
- int n = 10; // number of entries
-
- store.open(env.getFileName());
-
- try {
- /* create and populate an index */
- Index index = store.createIndex("Index");
- for (int i = 0; i < n; i++) {
- key = generateString(keySize, i);
- index.insert(key, "");
- }
- store.commit();
-
- /* Place two cursors at the same entry */
- IndexCursor c1 = index.open().findFirstEntry();
- IndexCursor c2 = index.open().findFirstEntry();
-
- /* Remove the entry at the first cursor and test the second cursor for results */
- c1.remove();
-
- int id = 0;
- try {
- c2.remove();
- } catch (IndexedStoreException e) {
- id = e.id;
- }
- assertEquals("remove test", IndexedStoreException.EntryRemoved, id);
-
- id = 0;
- try {
- c2.getKey();
- } catch (IndexedStoreException e) {
- id = e.id;
- }
- assertEquals("get key test", IndexedStoreException.EntryRemoved, id);
-
- id = 0;
- try {
- c2.getValue();
- } catch (IndexedStoreException e) {
- id = e.id;
- }
- assertEquals("get value test", IndexedStoreException.EntryRemoved, id);
-
- id = 0;
- try {
- c2.updateValue("123");
- } catch (IndexedStoreException e) {
- id = e.id;
- }
- assertEquals("update value test", IndexedStoreException.EntryRemoved, id);
-
- id = 0;
- try {
- c2.isAtEnd();
- } catch (IndexedStoreException e) {
- id = e.id;
- }
- assertEquals("isAtEnd test", IndexedStoreException.EntryRemoved, id);
-
- id = 0;
- try {
- c2.isAtBeginning();
- } catch (IndexedStoreException e) {
- id = e.id;
- }
- assertEquals("isAtBeginning test", IndexedStoreException.EntryRemoved, id);
-
- id = 0;
- try {
- c2.isSet();
- } catch (IndexedStoreException e) {
- id = e.id;
- }
- assertEquals("isSet test", IndexedStoreException.EntryRemoved, id);
-
- id = 0;
- try {
- c2.next();
- } catch (IndexedStoreException e) {
- id = e.id;
- }
- assertEquals("move next test", IndexedStoreException.EntryRemoved, id);
-
- id = 0;
- try {
- c2.previous();
- } catch (IndexedStoreException e) {
- id = e.id;
- }
- assertEquals("move previous test", IndexedStoreException.EntryRemoved, id);
-
- id = 0;
- try {
- c2.keyEquals("");
- } catch (IndexedStoreException e) {
- id = e.id;
- }
- assertEquals("key equals test", IndexedStoreException.EntryRemoved, id);
-
- id = 0;
- try {
- c2.keyMatches("");
- } catch (IndexedStoreException e) {
- id = e.id;
- }
- assertEquals("key matches test", IndexedStoreException.EntryRemoved, id);
-
- c2.reset();
- id = 0;
- try {
- c2.next();
- } catch (IndexedStoreException e) {
- id = e.id;
- }
- assertEquals("reset test", 0, id);
-
- assertEquals("positioning test", c1.getValueAsString(), c2.getValueAsString());
-
- } finally {
- store.close();
- }
- }
-
-
- /**
- * Test usage of multiple cursors in a single thread.
- * This is a search test to ensure there are no interactions between cursors.
- */
- public void testMultiCursorSearch() throws Exception {
- int keySize = 5;
- int n = 10; /* number of cursors */
-
- IndexedStore.delete(env.getFileName());
- IndexedStore store = new IndexedStore();
- store.open(env.getFileName());
-
- try {
-
- /* create and populate an index, all keys and values are unique */
- Index index = store.createIndex("Index");
- for (int i = 0; i < 1000; i++) {
- String key = generateString(keySize, i);
- index.insert(key, "");
- }
- store.commit();
-
- /* get n cursors and position them at the first entry */
- IndexCursor[] c = new IndexCursor[n];
- for (int i = 0; i < n; i++) {
- c[i] = index.open();
- c[i].findFirstEntry();
- }
-
- /* search using the cursors, cursors should never be left in an unset state. */
- for (int i = 0; i < 100; i++) {
-
- /* save the keys at each cursor -- gives a snapshot of the state */
- String[] savedKeys = new String[n];
- for (int j = 0; j < n; j++) {
- savedKeys[j] = c[j].getKeyAsString();
- }
-
- /* select a random cursor, position in the index, direction, and length to scan */
- int pos = random(0, 999);
- int length = random(10, 40);
- int direction = ((random(0, 1) == 0) ? -1 : 1);
- int selection = random(0, n - 1);
- IndexCursor cx = c[selection];
-
- /* scan starting at the cursor, skipping the begin/end state */
- String key = generateString(keySize, pos);
- cx.find(key);
- for (int j = 0; j < length; j++) {
- String k = cx.getKeyAsString();
- assertTrue(pos == Integer.parseInt(k));
- if (direction < 0) {
- cx.previous();
- if (cx.isAtBeginning())
- cx.previous();
- pos--;
- if (pos < 0)
- pos = 999;
- } else {
- cx.next();
- if (cx.isAtEnd())
- cx.next();
- pos++;
- if (pos > 999)
- pos = 0;
- }
- }
-
- /* check the other cursors for any side effects */
- for (int j = 0; j < n; j++) {
- if (j == selection)
- continue;
- assertEquals(savedKeys[j], c[j].getKeyAsString());
- }
- }
- for (int i = 0; i < n; i++)
- c[i].close();
- } finally {
- store.close();
- }
- }
-
-
- /**
- * Test usage of multiple cursors in a single thread.
- * This is an update test to ensure there are no interactions between cursors.
- * This tests adjustments due to node splitting.
- */
- public void testMultiCursorUpdate() throws Exception {
- IndexedStore.delete(env.getFileName());
- IndexedStore store = new IndexedStore();
- int keySize = 1000;
- int valueSize1 = 0;
- int valueSize2 = 2000;
- String key, value;
- int n = 10; /* number of cursors */
-
- /* create and populate an index, all keys and values are unique */
- store.open(env.getFileName());
- try {
- Index index = store.createIndex("Index");
- for (int i = 0; i < n; i++) {
- key = generateString(keySize, i);
- value = generateString(valueSize1, i);
- index.insert(key, value);
- }
- store.commit();
-
- /* get n cursors and position them at the n entries */
- IndexCursor[] c = new IndexCursor[n];
- for (int i = 0; i < n; i++) {
- c[i] = index.open();
- key = generateString(keySize, i);
- c[i].find(key);
- }
-
- /*
- Update the values at the cursors.
- This will cause major splitting.
- Test cursor values after each update.
- */
- for (int i = 0; i < n; i++) {
- value = generateString(valueSize2, i);
- c[i].updateValue(value);
- for (int j = 0; j < n; j++) {
- int size = (j <= i) ? valueSize2 : valueSize1;
- String v1 = generateString(size, j);
- String v2 = c[j].getValueAsString();
- assertEquals(v1, v2);
- }
- }
-
- for (int i = 0; i < n; i++)
- c[i].close();
- } finally {
- store.close();
- }
- }
-
-
- /**
- * Timed test for creation and retrieval of 100000 simple objects.
- */
- public void testObjectPerformance() throws Exception {
- IndexedStore.delete(env.getFileName());
- IndexedStore store = new IndexedStore();
- HashSet ids = new HashSet();
-
- store.open(env.getFileName());
- try {
- int n = 100000;
- byte[] a = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef".getBytes();
- long t0 = System.currentTimeMillis();
- for (int i = 0; i < n; i++) {
- ids.add(store.createObject(a));
- if (i % 1000 == 999)
- store.commit();
- }
- long t1 = System.currentTimeMillis();
- env.println("Time to create = " + ((t1 - t0) / 1000));
- } finally {
- store.close();
- }
-
- store.open(env.getFileName());
- try {
- Iterator idStream = ids.iterator();
- long t0 = System.currentTimeMillis();
- while (idStream.hasNext()) {
- store.getObject((ObjectID) idStream.next());
- }
- long t1 = System.currentTimeMillis();
- env.println("Time to retrieve = " + ((t1 - t0) / 1000));
- } finally {
- store.close();
- }
-
- }
-
-
- /**
- * Tests the creation and updating of objects in the store.
- * This test stores a single small object and then grows it over time until is is 6000 bytes.
- */
- public void testObjectUpdate() throws Exception {
- int n = 1000;
- IndexedStore.delete(env.getFileName());
- IndexedStore store = new IndexedStore();
- store.open(env.getFileName());
- try {
- String s = "";
- ObjectID id = store.createObject(s);
- for (int i = 0; i < n; i++) {
- s = s + "123456";
- store.updateObject(id, s);
- }
- s = store.getObjectAsString(id);
- for (int i = 0; i < (6 * n); i += 6) {
- String s2 = s.substring(i, i + 6);
- assertEquals(s2, "123456");
- }
- } finally {
- store.close();
- }
- }
-
-
- /**
- * Tests the creating, updating, and deleting of objects in the store.
- * This test generates object names and objects, stores the names in an
- * index and the objects as blobs. Deletions and updates are done as well.
- */
- public void testObjectLife() throws Exception {
- int n = 50000;
- IndexedStore.delete(env.getFileName());
- IndexedStore store = new IndexedStore();
- store.open(env.getFileName());
- try {
- Index index = store.createIndex("index");
- IndexCursor cursor = index.open();
- ObjectID id = null;
- String name = null;
- String value = null;
- Random r = new Random(100); // same seed should generate the same test on the same VM
- for (int i = 0; i < n; i++) {
- env.print(i, 8);
- int k = Math.abs(r.nextInt());
- int k1 = k % 100; // used to gen name
- int k2 = k % 2; // used to gen operation
- name = "Object" + generateString(20, k1);
- value = "Value" + k1;
- cursor.find(name);
- if (cursor.keyEquals(name)) {
- id = cursor.getValueAsObjectID();
- String foundValue = store.getObjectAsString(id);
- assertEquals(value, foundValue);
- switch (k2) {
- case 0: // delete object named x if it exists
- env.println(" Deleting " + name);
- store.removeObject(id);
- cursor.remove();
- break;
- case 1:
- env.println(" Updating " + name);
- store.updateObject(id, value);
- break;
- default: // no operation
- env.println(" Nothing");
- }
- } else {
- env.println(" Inserting " + name);
- id = store.createObject(value);
- index.insert(name, id);
- }
- if (i % 20 == 19) {
- env.println(" Commit");
- store.commit();
- }
- }
- } finally {
- store.close();
- }
- }
-
-
- /**
- * Tests simple recovery APIs.
- */
- public void testRecovery() throws Exception {
- IndexedStore store = null;
- IndexedStore.delete(env.getFileName());
- store = new IndexedStore();
- store.open(env.getFileName());
- try {
- try {
- store.open(env.getFileName());
- } catch (IndexedStoreException e) {
- if (e.id != IndexedStoreException.StoreIsOpen)
- fail("expected exception did not occur");
- }
- IndexedStore store2 = IndexedStore.find(env.getFileName());
- if (store2 == null)
- fail("store looks like its not open");
- assertSame(store, store2);
- } finally {
- store.close();
- }
- }
-
-
- /**
- * Tests simple creation and deletion of an IndexedStore.
- */
- public void testSanity() throws Exception {
- IndexedStore.delete(env.getFileName());
- IndexedStore store = new IndexedStore();
- store.open(env.getFileName());
- store.close();
- }
-
-
- /**
- * Tests simple transaction APIs.
- */
- public void testTransactions() throws Exception {
- IndexedStore store = null;
- IndexedStore.delete(env.getFileName());
- store = new IndexedStore();
- store.open(env.getFileName());
- try {
- store.createIndex("Index");
- store.getIndex("Index");
- store.rollback();
- try {
- store.getIndex("Index");
- } catch (IndexedStoreException e) {
- if (e.id != IndexedStoreException.IndexNotFound)
- fail("expected exception was not thrown");
- }
- store.createIndex("Index");
- store.getIndex("Index");
- store.commit();
- store.getIndex("Index");
- } finally {
- store.close();
- }
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/BasicObjectStoreTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/BasicObjectStoreTest.java
deleted file mode 100644
index fe1e88e..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/BasicObjectStoreTest.java
+++ /dev/null
@@ -1,233 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.indexing;
-
-import java.util.*;
-import java.io.*;
-import org.eclipse.core.internal.indexing.*;
-import junit.framework.*;
-
-public class BasicObjectStoreTest extends TestCase {
-
- protected Vector addresses;
- protected TestEnvironment env;
-
- public BasicObjectStoreTest(String name, TestEnvironment env) {
- super(name);
- this.env = env;
- }
-
- public static Test suite(TestEnvironment env) {
- TestSuite suite = new TestSuite();
- suite.addTest(new BasicObjectStoreTest("testSanity", env));
- suite.addTest(new BasicObjectStoreTest("testInsertRemove", env));
- suite.addTest(new BasicObjectStoreTest("testPopulate", env));
- suite.addTest(new BasicObjectStoreTest("testUpdate", env));
- suite.addTest(new BasicObjectStoreTest("testIdentity", env));
- suite.addTest(new BasicObjectStoreTest("testRemove", env));
- suite.addTest(new BasicObjectStoreTest("testLarge", env));
- return suite;
- }
-
- /**
- * Generates a string of length n from a number i.
- */
- private String generateString(int n, int i) {
- StringWriter a = new StringWriter();
- String suffix = Integer.toString(i);
- for (int k = 0; k < (n - suffix.length()); k++)
- a.write("0");
- a.write(suffix);
- return a.toString();
- }
-
- // populate an object store with 256 copies of a particular string
- public void populate(String string) throws Exception {
- ObjectStore store = new ObjectStore(new TestObjectPolicy());
- store.open(env.getFileName());
- try {
- addresses = new Vector();
- for (int i = 0; i < 255; i++) {
- TestObject object = new TestObject(string.getBytes());
- ObjectAddress address = store.insertObject(object);
- addresses.addElement(address);
- if (i % 16 == 15) store.commit();
- }
- } finally {
- store.close();
- }
- }
-
- // test object identity
- public void testIdentity() throws Exception {
- ObjectStore.delete(env.getFileName());
- String s = "000011112222";
- populate(s);
- ObjectStore store = new ObjectStore(new TestObjectPolicy());
- store.open(env.getFileName());
- try {
- s = "aaaabbbbcccc";
- int n = addresses.size();
- for (int i = 0; i < n; i++) {
- ObjectAddress address = (ObjectAddress) addresses.elementAt(i);
- TestObject object1 = (TestObject) store.acquireObject(address);
- TestObject object2 = (TestObject) store.acquireObject(address);
- object1.updateValue(s.getBytes());
- String t = new String(object2.getValue());
- assertEquals("Testing", s, t);
- assertSame(object1, object2);
- store.releaseObject(object1);
- store.releaseObject(object2);
- store.commit();
- }
- } finally {
- store.close();
- }
- }
-
- /**
- * Tests inserts and removes of objects. This should force the compression of
- * object pages.
- */
- public void testInsertRemove() throws Exception {
- String string = "---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*";
- ObjectStore.delete(env.getFileName());
- ObjectStore store = new ObjectStore(new TestObjectPolicy());
- store.open(env.getFileName());
- try {
- for (int i = 0; i < 1000; i++) {
- TestObject object = new TestObject(string.getBytes());
- ObjectAddress address = store.insertObject(object);
- store.removeObject(address);
- if (i % 100 == 99)
- store.commit();
- }
- } finally {
- store.close();
- }
- }
-
- // put some big objects in
- public void testLarge() throws Exception {
- ObjectStore.delete(env.getFileName());
- StringBuffer buf = new StringBuffer(3500);
- while (buf.length() < 3500)
- buf.append("---*---*---*---*");
- String s = buf.toString();
- byte[] b1 = s.getBytes();
- ObjectStore store = new ObjectStore(new TestObjectPolicy());
- store.open(env.getFileName());
- try {
- addresses = new Vector();
- for (int i = 0; i < (16 * 1024); i++) {
- TestObject object = new TestObject(b1);
- addresses.addElement(store.insertObject(object));
- if (i % 16 == 15)
- store.commit();
- }
- int n = addresses.size();
- for (int i = 0; i < n; i++) {
- ObjectAddress address = (ObjectAddress) addresses.elementAt(i);
- TestObject o = (TestObject) store.acquireObject(address);
- byte[] b2 = o.getValue();
- String t = new String(b2);
- store.releaseObject(o);
- assertEquals(s, t);
- }
- } finally {
- store.close();
- }
- }
-
- // populate and check the contents of the database
- public void testPopulate() throws Exception {
- ObjectStore.delete(env.getFileName());
- ObjectStore store = new ObjectStore(new TestObjectPolicy());
- StringBuffer buffer = new StringBuffer(4096);
- String fragment = "---*---*---*---*";
- for (int j = 0; j < 64; j++) {
- String s = buffer.toString();
- populate(s);
- store.open(env.getFileName());
- try {
- int n = addresses.size();
- for (int i = 0; i < n; i++) {
- ObjectAddress address = (ObjectAddress) addresses.elementAt(i);
- TestObject o = (TestObject) store.acquireObject(address);
- String t = new String(o.getValue());
- store.releaseObject(o);
- assertEquals(s, t);
- }
- } finally {
- store.close();
- }
- buffer.append(fragment);
- }
- }
-
- // remove all the objects
- public void testRemove() throws Exception {
- ObjectStore.delete(env.getFileName());
- String s = "000011112222";
- populate(s);
- ObjectStore store = new ObjectStore(new TestObjectPolicy());
- store.open(env.getFileName());
- try {
- int n = addresses.size();
- for (int i = 0; i < n; i++) {
- ObjectAddress address = (ObjectAddress) addresses.elementAt(i);
- store.removeObject(address);
- store.commit();
- }
- } finally {
- store.close();
- }
- }
-
- // open and close
- public void testSanity() throws Exception {
- ObjectStore.delete(env.getFileName());
- ObjectStore store = new ObjectStore(new TestObjectPolicy());
- store.open(env.getFileName());
- store.close();
- return;
- }
-
- // update the objects and check the contents again, object size does not change
- public void testUpdate() throws Exception {
- ObjectStore.delete(env.getFileName());
- String s = "000011112222";
- populate(s);
- ObjectStore store = new ObjectStore(new TestObjectPolicy());
- store.open(env.getFileName());
- try {
- s = "aaaabbbbcccc";
- int n = addresses.size();
- for (int i = 0; i < n; i++) {
- ObjectAddress address = (ObjectAddress) addresses.elementAt(i);
- TestObject object = (TestObject) store.acquireObject(address);
- object.updateValue(s.getBytes());
- store.releaseObject(object);
- store.commit();
- }
- for (int i = 0; i < n; i++) {
- ObjectAddress address = (ObjectAddress) addresses.elementAt(i);
- TestObject object = (TestObject) store.acquireObject(address);
- String t = new String(object.getValue());
- store.releaseObject(object);
- assertEquals(s, t);
- }
- } finally {
- store.close();
- }
- }
-
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/BasicPageStoreTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/BasicPageStoreTest.java
deleted file mode 100644
index 89d3c9d..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/BasicPageStoreTest.java
+++ /dev/null
@@ -1,335 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.indexing;
-
-import org.eclipse.core.internal.indexing.*;
-import java.util.*;
-import junit.framework.*;
-
-public class BasicPageStoreTest extends TestCase {
-
- protected TestEnvironment env;
-
- public BasicPageStoreTest(String name, TestEnvironment env) {
- super(name);
- this.env = env;
- }
-
- public static Test suite(TestEnvironment env) {
- TestSuite suite = new TestSuite();
- suite.addTest(new BasicPageStoreTest("testCreate", env));
- suite.addTest(new BasicPageStoreTest("testDelete", env));
- suite.addTest(new BasicPageStoreTest("testWrite", env));
- suite.addTest(new BasicPageStoreTest("testLogging1", env));
- suite.addTest(new BasicPageStoreTest("testLogging2", env));
- suite.addTest(new BasicPageStoreTest("testLogging3", env));
- suite.addTest(new BasicPageStoreTest("testWriteLarge", env));
- suite.addTest(new BasicPageStoreTest("testWriteHuge", env));
- suite.addTest(new BasicPageStoreTest("testReadOnly", env));
- suite.addTest(new BasicPageStoreTest("testCacheHitsSequential", env));
- suite.addTest(new BasicPageStoreTest("testCacheHitsCircular", env));
- suite.addTest(new BasicPageStoreTest("testCacheHitsRandom", env));
- suite.addTest(new BasicPageStoreTest("testRandomReadWrite", env));
- return suite;
- }
-
- // check a byte array against a value
- boolean check(byte[] b, byte i) {
- for (int j = 0; j < b.length; j++) {
- if (b[j] != i) return false;
- }
- return true;
- }
-
- // fill a byte array with a value
- void fill(byte[] b, byte i) {
- for (int j = 0; j < b.length; j++) b[j] = i;
- }
-
- /**
- * Creates an initialized 128 page store.
- */
- public int initializeStore() throws Exception {
- PageStore.delete(env.getFileName());
- PageStore store = new PageStore(new TestPagePolicy());
- store.open(env.getFileName());
- int n = 128;
- for (int i = 0; i < n; i++) {
- TestPage p = (TestPage)store.acquire(i);
- p.fill((byte)i);
- p.release();
- }
- store.close();
- return n;
- }
-
- void printStats(PageStore store) throws Exception {
- env.println("Number of pages = " + store.numberOfPages());
- env.println("Number of writes = " + store.numberOfFileWrites());
- env.println("Number of file reads = " + store.numberOfFileReads());
- env.println("Number of cache reads = " + store.numberOfCacheHits());
- env.println("Number of reads = " + store.numberOfReads());
- env.println("Cache hit ratio = " + (float)store.numberOfCacheHits()/(float)store.numberOfReads());
- }
-
- /**
- * Test cache performance using a circular reference pattern.
- */
- public void testCacheHitsCircular() throws Exception {
- env.printHeading("testCacheHitsCircular");
- initializeStore();
- PageStore store = new PageStore(new TestPagePolicy());
- env.println("Testing 41 of 40");
- store.open(env.getFileName());
- for (int j = 0; j < 100; j++) {
- for (int i = 0; i < 41; i++) {
- TestPage p = (TestPage)store.acquire(i);
- assertTrue(p.check((byte) i));
- p.release();
- }
- }
- printStats(store);
- store.close();
- env.println("Testing 40 of 40");
- store.open(env.getFileName());
- for (int j = 0; j < 100; j++) {
- for (int i = 0; i < 40; i++) {
- TestPage p = (TestPage)store.acquire(i);
- assertTrue(p.check((byte) i));
- p.release();
- }
- }
- printStats(store);
- store.close();
- }
-
- /**
- * Test the effect of increasing cache sizes
- */
- public void testCacheHitsRandom() throws Exception {
- env.printHeading("testCacheHitsRandom");
- PageStore.delete(env.getFileName());
- int n = initializeStore();
- for (int m = 0; m <= n; m+=16) {
- PageStore store = new PageStore(new TestPagePolicy());
- store.open(env.getFileName());
- Random r = new Random(100);
- for (int i = 0; i < 1000; i++) {
- TestPage p = (TestPage)store.acquire(Math.abs(r.nextInt() % n));
- p.release();
- }
- printStats(store);
- store.close();
- }
- }
-
- /**
- * Checks the performance of sequential access.
- */
- public void testCacheHitsSequential() throws Exception {
- env.printHeading("testCacheHitsSequential");
- int n = initializeStore();
- PageStore store = new PageStore(new TestPagePolicy());
- store.open(env.getFileName());
- for (int i = 0; i < n; i++) {
- TestPage p = (TestPage)store.acquire(i);
- assertTrue(p.check((byte) i));
- p.release();
- }
- printStats(store);
- store.close();
- }
-
- /**
- */
- public void testCreate() throws Exception {
- env.printHeading("testCreate");
- PageStore.create(env.getFileName());
- assertTrue(PageStore.exists(env.getFileName()));
- }
-
- /**
- */
- public void testDelete() throws Exception {
- env.printHeading("testDelete");
- PageStore.delete(env.getFileName());
- assertTrue(!PageStore.exists(env.getFileName()));
- }
-
- /**
- * Tests the log.
- */
- public void testLogging1() throws Exception {
- env.printHeading("testLogging1");
- PageStore.delete(env.getFileName());
- PageStore store = new PageStore(new TestPagePolicy());
- store.open(env.getFileName());
- testLogPopulate(store);
- store.testLogging1();
- testLogValidate(store);
- store.close();
- }
-
- /**
- * Tests the log.
- */
- public void testLogging2() throws Exception {
- env.printHeading("testLogging2");
- PageStore.delete(env.getFileName());
- PageStore store = new PageStore(new TestPagePolicy());
- store.open(env.getFileName());
- testLogPopulate(store);
- store.testLogging2();
- testLogValidate(store);
- store.close();
- }
-
- /**
- * Tests the log.
- */
- public void testLogging3() throws Exception {
- env.printHeading("testLogging3");
- PageStore.delete(env.getFileName());
- PageStore store = new PageStore(new TestPagePolicy());
- store.open(env.getFileName());
- testLogPopulate(store);
- store.testLogging3();
- testLogValidate(store);
- store.close();
- }
-
- /**
- * Populate the store for the logging tests.
- */
- public void testLogPopulate(PageStore store) throws Exception {
- for (int i = 0; i < 128; i++) {
- TestPage p = (TestPage)store.acquire(i);
- p.fill((byte) i);
- p.release();
- }
- }
-
- /**
- * Tests the contents of the store for the logging tests.
- */
- public void testLogValidate(PageStore store) throws Exception {
- for (int i = 0; i < 128; i++) {
- TestPage p = (TestPage)store.acquire(i);
- assertTrue("Failed checking page " + i, p.check((byte) i));
- p.release();
- }
- }
-
- /**
- * Tests random reading & writing.
- */
- public void testRandomReadWrite() throws Exception {
- env.printHeading("testRandomReadWrite");
- PageStore.delete(env.getFileName());
- int n = 128;
- byte[] value = new byte[n];
- for (int i = 0; i < n; i++) value[i] = 0;
- PageStore store = new PageStore(new TestPagePolicy());
- store.open(env.getFileName());
- Random r = new Random(100);
- for (int i = 0; i < 2000; i++) {
- int k = Math.abs(r.nextInt() % n);
- TestPage p = (TestPage)store.acquire(k);
- assertTrue(p.check(value[k]));
- value[k] = (byte) r.nextInt();
- p.fill(value[k]);
- p.release();
- }
- printStats(store);
- store.close();
- }
-
- /**
- * Tests read-only access on the store.
- */
- public void testReadOnly() throws Exception {
- env.printHeading("testReadOnly");
- PageStore.delete(env.getFileName());
- int n = initializeStore();
- PageStore store = new PageStore(new TestPagePolicy());
- store.open(env.getFileName());
- assertTrue(store.numberOfPages() == n);
- for (int i = 0; i < n; i++) {
- TestPage p = (TestPage) store.acquire(i);
- assertTrue(p.check((byte) i));
- p.release();
- }
- printStats(store);
- store.close();
- }
-
- /**
- * Adds & checks 128 8K pages (1 meg) to the page file.
- */
- public void testWrite() throws Exception {
- env.printHeading("testWrite");
- PageStore.delete(env.getFileName());
- PageStore store = new PageStore(new TestPagePolicy());
- store.open(env.getFileName());
- writeBlock(store);
- printStats(store);
- store.close();
- }
-
- /**
- * Adds a 64 meg chunk to the page file.
- */
- public void testWriteHuge() throws Exception {
- env.printHeading("testWriteHuge");
- PageStore.delete(env.getFileName());
- PageStore store = new PageStore(new TestPagePolicy());
- store.open(env.getFileName());
- for (int i = 0; i < 64; i++) writeBlock(store);
- printStats(store);
- store.close();
- }
-
- /**
- * Adds a 16 meg chunk to the page file.
- */
- public void testWriteLarge() throws Exception {
- env.printHeading("testWriteLarge");
- PageStore.delete(env.getFileName());
- PageStore store = new PageStore(new TestPagePolicy());
- store.open(env.getFileName());
- for (int i = 0; i < 16; i++) writeBlock(store);
- printStats(store);
- store.close();
- }
-
- /**
- * Adds & checks 128 8K pages (1 meg) to the page file.
- */
- public int writeBlock(PageStore store) throws Exception {
- TestPage p = null;
- int m = 128;
- int n1 = store.numberOfPages();
- int n2 = n1 + m;
- for (int i = n1; i < n2; i++) {
- p = (TestPage)store.acquire(i);
- p.fill((byte) i);
- p.release();
- }
- store.commit();
- assertEquals(store.numberOfPages(), n2);
- for (int i = n1; i < n2; i++) {
- p = (TestPage)store.acquire(i);
- assertTrue("Page " + i + " " + p.value(), p.check((byte) i));
- p.release();
- }
- return m;
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/IntegratedFieldTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/IntegratedFieldTest.java
deleted file mode 100644
index 36d0b96..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/IntegratedFieldTest.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.indexing;
-
-import junit.framework.*;
-
-public class IntegratedFieldTest {
-
- public static Test suite() {
- TestEnvironment env = new IntegratedTestEnvironment();
- return BasicFieldTest.suite(env);
- }
-
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/IntegratedIndexedStoreTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/IntegratedIndexedStoreTest.java
deleted file mode 100644
index e17d404..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/IntegratedIndexedStoreTest.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.indexing;
-
-import junit.framework.*;
-
-public class IntegratedIndexedStoreTest {
-
- public static Test suite() {
- TestEnvironment env = new IntegratedTestEnvironment();
- return BasicIndexedStoreTest.suite(env);
- }
-
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/IntegratedObjectStoreTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/IntegratedObjectStoreTest.java
deleted file mode 100644
index f8c7863..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/IntegratedObjectStoreTest.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.indexing;
-
-import junit.framework.*;
-
-public class IntegratedObjectStoreTest {
-
- public static Test suite() {
- TestEnvironment env = new IntegratedTestEnvironment();
- return BasicObjectStoreTest.suite(env);
- }
-
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/IntegratedPageStoreTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/IntegratedPageStoreTest.java
deleted file mode 100644
index 9a0dc98..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/IntegratedPageStoreTest.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.indexing;
-
-import junit.framework.*;
-
-public class IntegratedPageStoreTest {
-
- public static Test suite() {
- TestEnvironment env = new IntegratedTestEnvironment();
- return BasicPageStoreTest.suite(env);
- }
-
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/IntegratedTestEnvironment.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/IntegratedTestEnvironment.java
deleted file mode 100644
index afdd19e..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/IntegratedTestEnvironment.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.indexing;
-
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-public class IntegratedTestEnvironment extends EclipseWorkspaceTest implements TestEnvironment {
-
- public String getFileName() {
- return getWorkspace().getRoot().getLocation().append("test.dat").toOSString();
- }
-
- public void print(String s) {
- }
-
- public void print(int n, int width) {
- }
-
- public void println(String s) {
- }
-
- public void printHeading(String s) {
- }
-
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/StandAloneFieldTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/StandAloneFieldTest.java
deleted file mode 100644
index 5d45500..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/StandAloneFieldTest.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.indexing;
-
-import junit.textui.TestRunner;
-
-public class StandAloneFieldTest {
-
- public static void main(String[] args) {
- TestRunner.run(BasicFieldTest.suite(new StandAloneTestEnvironment()));
- }
-
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/StandAloneIndexedStoreTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/StandAloneIndexedStoreTest.java
deleted file mode 100644
index 6209545..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/StandAloneIndexedStoreTest.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.indexing;
-
-import junit.textui.TestRunner;
-
-public class StandAloneIndexedStoreTest {
-
- public static void main(String[] args) {
- TestRunner.run(BasicIndexedStoreTest.suite(new StandAloneTestEnvironment()));
- }
-
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/StandAloneObjectStoreTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/StandAloneObjectStoreTest.java
deleted file mode 100644
index 8607a07..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/StandAloneObjectStoreTest.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.indexing;
-
-import junit.textui.TestRunner;
-
-public class StandAloneObjectStoreTest {
-
- public static void main(String[] args) {
- TestRunner.run(BasicObjectStoreTest.suite(new StandAloneTestEnvironment()));
- }
-
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/StandAlonePageStoreTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/StandAlonePageStoreTest.java
deleted file mode 100644
index 62f2494..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/StandAlonePageStoreTest.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.indexing;
-
-import junit.textui.TestRunner;
-
-public class StandAlonePageStoreTest {
-
- public static void main(String[] args) {
- TestRunner.run(BasicPageStoreTest.suite(new StandAloneTestEnvironment()));
- }
-
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/StandAloneTestEnvironment.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/StandAloneTestEnvironment.java
deleted file mode 100644
index 43d0d54..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/StandAloneTestEnvironment.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.indexing;
-
-import java.io.*;
-
-public class StandAloneTestEnvironment implements TestEnvironment {
-
- protected final static String sep = File.separator;
- protected final static String driveLetter = "c:";
- protected final static String directoryName = driveLetter + sep + "tests" + sep;
- protected final static String fileName = directoryName + "test.dat";
-
- private PrintWriter out;
-
- public StandAloneTestEnvironment() {
-// out = new PrintWriter(System.out, true);
- try {
- out = new PrintWriter(new FileWriter(directoryName + sep + "test.txt"), true);
- } catch (IOException e) {
- }
- }
-
- public String getFileName() {
- return fileName;
- }
-
- public void print(String s) {
- if (out != null) out.print(s);
- }
-
- public void print(int n, int width) {
- StringBuffer b = new StringBuffer(width);
- String s = Integer.toString(n);
- if (s.length() > width) {
- for (int i = 0; i < width; i++) b.append("#");
- } else {
- for (int i = 0; i < width - s.length(); i++) b.append(" ");
- b.append(s);
- }
- print(b.toString());
- }
-
- public void println(String s) {
- if (out != null) out.println(s);
- }
-
- public void printHeading(String s) {
- if (out != null) {
- out.println();
- out.println(s);
- }
- }
-
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/TestEnvironment.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/TestEnvironment.java
deleted file mode 100644
index d33db45..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/TestEnvironment.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.indexing;
-
-public interface TestEnvironment {
-
- /**
- * Returns the file name which will be used as a target for a
- * particular test suite. This will be the name of an IndexedStore,
- * an ObjectStore, or a PageStore file.
- */
- public String getFileName();
-
- /**
- * Prints a string on an output stream. All testcase strings are informational only.
- */
- public void print(String s);
-
- /**
- * Prints a string on an output stream. All testcase strings are informational only.
- */
- public void println(String s);
-
- /**
- * Prints a number on an output stream. All testcase strings are informational only.
- */
- public void print(int n, int width);
-
- /**
- * Prints a blank line first then a full line
- */
- public void printHeading(String s);
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/TestObject.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/TestObject.java
deleted file mode 100644
index ca31cb8..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/TestObject.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.indexing;
-
-import org.eclipse.core.internal.indexing.*;
-
-class TestObject extends StoredObject {
-
- private static final int TYPE = 99;
- protected byte[] value;
-
- /**
- * Standard constructor -- constructs an object that will be inserted into a store
- */
- TestObject(byte[] value) {
- super();
- this.value = new Field(value).get();
- }
-
- /**
- * Standard constructor -- constructs an object from bytes that came from the store.
- */
- TestObject(Field buffer, ObjectStore store, ObjectAddress address) throws ObjectStoreException {
- super(buffer, store, address);
- }
-
- /**
- * Places the contents of the fields into the buffer.
- * Subclasses should implement and call super.
- */
- protected void insertValues(Field buffer) {
- super.insertValues(buffer);
- buffer.subfield(2).put(value);
- }
-
- /**
- * Places the contents of the buffer into the fields.
- * Subclasses should implement and call super.
- */
- protected void extractValues(Field buffer) throws ObjectStoreException {
- super.extractValues(buffer);
- value = buffer.subfield(2).get();
- }
-
- /**
- * Returns the maximum size of this object's instance -- including its type field.
- * Subclasses should override.
- */
- protected int getMaximumSize() {
- return ObjectStore.MAXIMUM_OBJECT_SIZE;
- }
-
- /**
- * Returns the minimum size of this object's instance -- including its type field.
- * Subclasses should override.
- */
- protected int getMinimumSize() {
- return 2;
- }
-
- /**
- * Returns the length of the stored object for this instance. Including the
- * type field.
- */
- protected int length() {
- return 2 + value.length;
- }
-
- /**
- * Returns the required type of this class of object.
- * Subclasses must override.
- */
- protected int getRequiredType() {
- return TYPE;
- }
-
- /**
- * Returns the value of the object.
- */
- public byte[] getValue() {
- return new Field(value).get();
- }
-
- /**
- * Updates the value.
- */
- protected void updateValue(byte[] bytes) {
- new Field(value).put(bytes);
- setChanged();
- }
-
- /**
- * Returns a id tag to be used in toString
- */
- public String toString() {
- StringBuffer buf = new StringBuffer();
- buf.append("TestObject(");
- for (int i = 0; i < value.length; i++) {
- if (i > 0) buf.append(" ");
- if (i > 30) {
- buf.append("...");
- break;
- }
- buf.append(value[i]);
- }
- buf.append(")");
- return buf.toString();
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/TestObjectPolicy.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/TestObjectPolicy.java
deleted file mode 100644
index fb69bc2..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/TestObjectPolicy.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.indexing;
-
-import org.eclipse.core.internal.indexing.*;
-
-public class TestObjectPolicy extends AbstractObjectPolicy {
-
-
- /**
- * Constructor for TestObjectPolicy
- */
- public TestObjectPolicy() {
- super();
- }
-
-
- /**
- * @see ObjectPolicy#createObject(Field, ObjectStore, ObjectAddress)
- */
- public StoredObject createObject(Field field, ObjectStore store, ObjectAddress address) throws ObjectStoreException {
- return new TestObject(field, store, address);
- }
-
-
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/TestPage.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/TestPage.java
deleted file mode 100644
index 99ca0e3..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/TestPage.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.indexing;
-
-import org.eclipse.core.internal.indexing.*;
-
-class TestPage extends Page {
-
- /**
- * Creates a new page.
- */
- protected TestPage(int pageNumber, byte[] buffer, PageStore pageStore) {
- super(pageNumber, pageStore);
- pageBuffer = new Buffer(Page.SIZE);
- pageBuffer.copyFrom(buffer);
- }
-
- public boolean check(byte b) {
- for (int i = 0; i < pageBuffer.length(); i++) {
- if (pageBuffer.getByte(i) == b) continue;
- return false;
- }
- return true;
- }
-
- public void fill(byte b) {
- for (int i = 0; i < pageBuffer.length(); i++) {
- pageBuffer.put(i, b);
- }
- setChanged();
- notifyObservers();
- }
-
- public byte value() {
- return pageBuffer.getByte(0);
- }
-
- public void toBuffer(byte[] buffer) {
- pageBuffer.copyTo(buffer);
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/TestPagePolicy.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/TestPagePolicy.java
deleted file mode 100644
index 86bf078..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/indexing/TestPagePolicy.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.indexing;
-
-import org.eclipse.core.internal.indexing.*;
-
-public class TestPagePolicy extends AbstractPagePolicy {
-
-
- /**
- * @see PageStorePolicy#createPage(int, byte[], PageStore)
- */
- public Page createPage(int pageNumber, byte[] buffer, PageStore pageStore) {
- return new TestPage(pageNumber, buffer, pageStore);
- }
-
-
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/AllTests.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/AllTests.java
deleted file mode 100644
index 016911b..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/AllTests.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.localstore;
-
-import junit.framework.*;
-
-public class AllTests extends TestCase {
-/**
- * AllTests constructor comment.
- * @param name java.lang.String
- */
-public AllTests() {
- super(null);
-}
-/**
- * AllTests constructor comment.
- * @param name java.lang.String
- */
-public AllTests(String name) {
- super(name);
-}
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(BlobStoreTest.suite());
- suite.addTest(CaseSensitivityTest.suite());
- suite.addTest(CopyTest.suite());
- suite.addTest(DeleteTest.suite());
- suite.addTest(FileSystemResourceManagerTest.suite());
- suite.addTest(FileSystemStoreTest.suite());
- suite.addTest(HistoryStoreTest.suite());
- suite.addTest(LocalStoreTest.suite());
- suite.addTest(LocalSyncTest.suite());
- suite.addTest(MoveTest.suite());
- suite.addTest(RefreshLocalTest.suite());
- suite.addTest(SafeChunkyInputOutputStreamTest.suite());
- suite.addTest(SafeFileInputOutputStreamTest.suite());
- suite.addTest(UnifiedTreeTest.suite());
- return suite;
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/BlobStoreTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/BlobStoreTest.java
deleted file mode 100644
index 4ee9aa0..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/BlobStoreTest.java
+++ /dev/null
@@ -1,242 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.localstore;
-
-import java.io.*;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.localstore.BlobStore;
-import org.eclipse.core.internal.resources.Workspace;
-import org.eclipse.core.internal.utils.UniversalUniqueIdentifier;
-import org.eclipse.core.runtime.*;
-//
-public class BlobStoreTest extends LocalStoreTest {
-public BlobStoreTest() {
- super();
-}
-public BlobStoreTest(String name) {
- super(name);
-}
-public static Test suite() {
- return new TestSuite(BlobStoreTest.class);
-}
-public void testConstructor() {
- /* build scenario */
- IPath path = getWorkspace().getRoot().getLocation().append("blobstore");
- File temp = path.toFile();
- temp.mkdirs();
- assertTrue("0.1", temp.isDirectory());
-
- /* null location */
- boolean ok = false;
- try {
- new BlobStore(null, 0);
- } catch (RuntimeException e) {
- ok = true;
- }
- assertTrue("1.1", ok);
-
- /* empty location */
- ok = false;
- try {
- new BlobStore(Path.EMPTY, 128);
- } catch (RuntimeException e) {
- ok = true;
- }
- assertTrue("2.1", ok);
-
- /* inexisting location */
- ok = false;
- try {
- new BlobStore(new Path("../this/path/should/not/be/a/folder"), 128);
- } catch (RuntimeException e) {
- ok = true;
- }
- assertTrue("3.1", ok);
-
- /* invalid limit values */
- ok = false;
- try {
- new BlobStore(path, 0);
- } catch (RuntimeException e) {
- ok = true;
- }
- assertTrue("4.1", ok);
- ok = false;
- try {
- new BlobStore(path, -1);
- } catch (RuntimeException e) {
- ok = true;
- }
- assertTrue("4.2", ok);
- ok = false;
- try {
- new BlobStore(path, 35);
- } catch (RuntimeException e) {
- ok = true;
- }
- assertTrue("4.3", ok);
- ok = false;
- try {
- new BlobStore(path, 512);
- } catch (RuntimeException e) {
- ok = true;
- }
- assertTrue("4.4", ok);
-}
-public void testDeleteBlob() {
- /* initialize common objects */
- IPath path = getWorkspace().getRoot().getLocation().append("blobstore");
- File root = path.toFile();
- root.mkdirs();
- assertTrue("1.1", root.isDirectory());
- BlobStore store = new BlobStore(path, 64);
-
- /* delete blob that does not exist */
- assertTrue("2.1", !store.deleteBlob(new UniversalUniqueIdentifier()));
-
- /* delete existing blob */
- File target = new File(root, "target");
- UniversalUniqueIdentifier uuid = null;
- try {
- createFile(target, "bla bla bla");
- uuid = store.addBlob(target, true);
- } catch (IOException e) {
- fail("4.0", e);
- } catch (CoreException e) {
- fail("4.1", e);
- }
- assertTrue("4.3", store.deleteBlob(uuid));
-
- /* remove trash */
- Workspace.clear(root);
-}
-/**
- * #deleteEmptyDir is tested indirectly here.
- */
-public void testDeleteEmptyDir() {
- /* initialize common objects */
- IPath path = getWorkspace().getRoot().getLocation().append("blobstore");
- File root = path.toFile();
- root.mkdirs();
- assertTrue("1.1", root.isDirectory());
- // use just one directory
- BlobStore store = new BlobStore(path, 1);
-
- /* create 2 blobs */
- File target = new File(root, "target");
- File target2 = new File(root, "target2");
- UniversalUniqueIdentifier firstUUID = null;
- UniversalUniqueIdentifier secondUUID = null;
- try {
- createFile(target, "bla bla bla");
- createFile(target2, "bla bla bla");
- firstUUID = store.addBlob(target, true);
- secondUUID = store.addBlob(target2, true);
- } catch (IOException e) {
- fail("4.0", e);
- } catch (CoreException e) {
- fail("4.1", e);
- }
-
- /* get directory name */
- String[] list = root.list();
- assertTrue("3.0", list != null);
- assertTrue("3.1", list.length == 1);
- File directory = new File(root, list[0]);
- assertTrue("3.2", directory.isDirectory());
-
- /* delete one, the directory should not be deleted */
- assertTrue("4.1", store.deleteBlob(firstUUID));
- assertTrue("4.2", directory.exists());
-
- /* delete the other, the directory should be deleted */
- assertTrue("5.1", store.deleteBlob(secondUUID));
- assertTrue("5.2", !directory.exists());
-
- /* remove trash */
- Workspace.clear(root);
-}
-public void testGetBlob() {
- /* initialize common objects */
- IPath path = getWorkspace().getRoot().getLocation().append("blobstore");
- File root = path.toFile();
- root.mkdirs();
- assertTrue("1.1", root.isDirectory());
- BlobStore store = new BlobStore(path, 64);
-
- /* null UUID */
- boolean ok = false;
- try {
- store.getBlob(null);
- } catch (RuntimeException e) {
- ok = true;
- } catch (CoreException e) {
- fail("2.0", e);
- }
- assertTrue("2.1", ok);
-
- /* get existing blob */
- File target = new File(root, "target");
- UniversalUniqueIdentifier uuid = null;
- String content = "nothing important........tnatropmi gnihton";
- try {
- createFile(target, content);
- uuid = store.addBlob(target, true);
- } catch (IOException e) {
- fail("3.0", e);
- } catch (CoreException e) {
- fail("3.1", e);
- }
- InputStream input = null;
- try {
- input = store.getBlob(uuid);
- } catch (CoreException e) {
- fail("3.4", e);
- }
- assertTrue("4.1", compareContent(getContents(content), input));
-
- /* remove trash */
- Workspace.clear(root);
-}
-public void testSetBlob() {
- /* initialize common objects */
- IPath path = getWorkspace().getRoot().getLocation().append("blobstore");
- File root = path.toFile();
- root.mkdirs();
- assertTrue("1.1", root.isDirectory());
- BlobStore store = new BlobStore(path, 64);
-
- /* normal conditions */
- File target = new File(root, "target");
- UniversalUniqueIdentifier uuid = null;
- String content = "nothing important........tnatropmi gnihton";
- try {
- createFile(target, content);
- uuid = store.addBlob(target, true);
- } catch (IOException e) {
- fail("2.0", e);
- } catch (CoreException e) {
- fail("2.1", e);
- }
- InputStream input = null;
- try {
- input = store.getBlob(uuid);
- } catch (CoreException e) {
- fail("2.4", e);
- }
- assertTrue("2.5", compareContent(getContents(content), input));
-
- /* remove trash */
- Workspace.clear(root);
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/CaseSensitivityTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/CaseSensitivityTest.java
deleted file mode 100644
index 1ab7f21..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/CaseSensitivityTest.java
+++ /dev/null
@@ -1,658 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.localstore;
-
-import java.io.IOException;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.localstore.CoreFileSystemLibrary;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.Path;
-
-public class CaseSensitivityTest extends LocalStoreTest {
- private boolean isCaseSensitive = CoreFileSystemLibrary.isCaseSensitive();
-
-public CaseSensitivityTest() {
- super();
-}
-public CaseSensitivityTest(String name) {
- super(name);
-}
-public static Test suite() {
- return new TestSuite(CaseSensitivityTest.class);
-}
-public void testCreateProjects() {
- String projectName = "testProject31415";
-
- // create a project, should be fine
- IProject project1 = getWorkspace().getRoot().getProject(projectName);
- try {
- project1.create(null);
- project1.open(null);
- assertTrue("1.0",true);
- } catch (CoreException e) {
- assertTrue("1.0",false); // should not happen
- return; // no point in proceding
- }
-
- // create a second project; should fail because has same name with different casing
- IProject project2 = getWorkspace().getRoot().getProject(projectName.toUpperCase());
- try {
- project2.create(null);
- project2.open(null);
- assertTrue("1.1",isCaseSensitive);
- } catch (CoreException e) {
- assertTrue("1.1",!isCaseSensitive);
- }
-}
-
-public void testCreateFolders() {
- String folderName = "testFolder31415";
- IProject aProject = getWorkspace().getRoot().getProjects()[0];
-
- // create a folder, should be fine
- IFolder folder1 = aProject.getFolder(folderName);
- try {
- folder1.create(true, true, null);
- assertTrue("1.0",true);
- } catch (CoreException e) {
- assertTrue("1.0",false); // should not happen
- return; // no point in proceding
- }
-
- // create a second folder; should fail because has same name with different casing
- IFolder folder2 = aProject.getFolder(folderName.toUpperCase());
- try {
- folder2.create(true, true, null);
- assertTrue("1.1",isCaseSensitive);
- } catch (CoreException e) {
- assertTrue("1.1",!isCaseSensitive);
- }
-
- // create a file; should fail because has same name with different casing
- IFile file = aProject.getFile(folderName.toUpperCase());
- try {
- file.create(getRandomContents(), true, null);
- assertTrue("1.2",false);
- } catch (CoreException e) {
- assertTrue("1.2",true);
- }
-}
-
-public void testCreateFiles() {
- String fileName = "testFile31415";
- IProject aProject = getWorkspace().getRoot().getProjects()[0];
-
- // create a file, should be fine
- IFile file1 = aProject.getFile(fileName);
- try {
- file1.create(getRandomContents(), true, null);
- assertTrue("1.0",true);
- } catch (CoreException e) {
- assertTrue("1.0",false); // should not happen
- return; // no point in proceding
- }
-
- // create a second file; should fail because has same name with different casing
- IFile file2 = aProject.getFile(fileName.toUpperCase());
- try {
- file2.create(getRandomContents(), true, null);
- assertTrue("1.1",isCaseSensitive);
- } catch (CoreException e) {
- assertTrue("1.1",!isCaseSensitive);
- }
-
- // create a folder; should fail because has same name with different casing
- IFolder folder = aProject.getFolder(fileName.toUpperCase());
- try {
- folder.create(true, true, null);
- assertTrue("1.2",false);
- } catch (CoreException e) {
- assertTrue("1.2",true);
- }
-}
-
-public void testRenameProject() {
- String project1name = "project1test31415";
- String project2name = "project2test31415";
-
- // create 2 projects with different names
- IProject project1 = getWorkspace().getRoot().getProject(project1name);
- try {
- project1.create(null);
- project1.open(null);
- assertTrue("1.0",true);
- } catch (CoreException e) {
- assertTrue("1.0",false); // should not happen
- return; // no point in proceding
- }
-
- IProject project2 = getWorkspace().getRoot().getProject(project2name);
- try {
- project2.create(null);
- project2.open(null);
- assertTrue("1.1",true);
- } catch (CoreException e) {
- assertTrue("1.1",false); // should not happen
- return; // no point in proceding
- }
-
- // try to rename project 1 to the uppercase name of project 2, should fail
- try {
- project1.move(Path.ROOT.append(project2.getName().toUpperCase()),true,null);
- assertTrue("1.2",isCaseSensitive);
- } catch (CoreException e) {
- assertTrue("1.2",!isCaseSensitive);
- }
-}
-
-public void testRenameFolder() {
- String folder1name = "folder1test31415";
- String folder2name = "folder2test31415";
- IProject aProject = getWorkspace().getRoot().getProjects()[0];
-
- // create 2 folders with different names
- IFolder folder1 = aProject.getFolder(folder1name);
- try {
- folder1.create(true, true, null);
- assertTrue("1.0",true);
- } catch (CoreException e) {
- assertTrue("1.1",false); // should not happen
- return; // no point in proceding
- }
-
- IFolder folder2 = aProject.getFolder(folder2name);
- try {
- folder2.create(true, true, null);
- assertTrue("2.1",true);
- } catch (CoreException e) {
- assertTrue("2.2",false); // should not happen
- return; // no point in proceding
- }
-
- // try to rename folder 1 to the uppercase name of folder 2, should fail
- IFolder folder3 = aProject.getFolder(folder2name.toUpperCase());
- try {
- folder1.move(folder3.getFullPath(),true,null);
- assertTrue("3.1",isCaseSensitive);
- } catch (CoreException e) {
- assertTrue("3.2",!isCaseSensitive);
- }
-}
-
-public void testRenameFile() {
- String file1name = "file1test31415";
- String file2name = "file2test31415";
- IProject aProject = getWorkspace().getRoot().getProjects()[0];
-
- // create 2 files with different names
- IFile file1 = aProject.getFile(file1name);
- try {
- file1.create(getRandomContents(), true, null);
- assertTrue("1.0",true);
- } catch (CoreException e) {
- assertTrue("1.1",false); // should not happen
- return; // no point in proceding
- }
-
- IFile file2 = aProject.getFile(file2name);
- try {
- file2.create(getRandomContents(), true, null);
- assertTrue("2.1",true);
- } catch (CoreException e) {
- assertTrue("2.2",false); // should not happen
- return; // no point in proceding
- }
-
- // try to rename folder 1 to the uppercase name of folder 2, should fail
- IFile file3 = aProject.getFile(file2name.toUpperCase());
- try {
- file1.move(file3.getFullPath(),true,null);
- assertTrue("3.1",isCaseSensitive);
- } catch (CoreException e) {
- assertTrue("3.2",!isCaseSensitive);
- }
-}
-
-public void testCopyAndMoveFolder() {
- String folderName = "folderTest31415";
- IProject sourceProject = getWorkspace().getRoot().getProjects()[0];
- IProject destinationProject = getWorkspace().getRoot().getProjects()[1];
-
- // create 2 folders, one in each project, with case-different names
- IFolder folder1 = sourceProject.getFolder(folderName);
- try {
- folder1.create(true, true, null);
- assertTrue("1.0",true);
- } catch (CoreException e) {
- assertTrue("1.0",false); // should not happen
- return; // no point in proceding
- }
-
- IFolder folder2 = destinationProject.getFolder(folderName.toUpperCase());
- try {
- folder2.create(true, true, null);
- assertTrue("1.1",true);
- } catch (CoreException e) {
- assertTrue("1.1",false); // should not happen
- return; // no point in proceding
- }
-
- // try to copy the folder from source project to destination project.
- // should fail due to conflict
- try {
- folder1.copy(destinationProject.getFullPath().append(folder1.getName()),true,null);
- assertTrue("1.2",isCaseSensitive);
- } catch (CoreException e) {
- assertTrue("1.2",!isCaseSensitive);
- }
-
- // try to move the folder from source project to destination project.
- // should fail due to conflict
- try {
- folder1.move(destinationProject.getFullPath().append(folder1.getName()),true,null);
- assertTrue("1.3",false);
- } catch (CoreException e) {
- assertTrue("1.3",true);
- }
-}
-
-public void testCopyAndMoveFile() {
- String fileName = "fileTest31415";
- IProject sourceProject = getWorkspace().getRoot().getProjects()[0];
- IProject destinationProject = getWorkspace().getRoot().getProjects()[1];
-
- // create 2 files, one in each project, with case-different names
- IFile file1 = sourceProject.getFile(fileName);
- try {
- file1.create(getRandomContents(), true, null);
- assertTrue("1.0",true);
- } catch (CoreException e) {
- assertTrue("1.0",false); // should not happen
- return; // no point in proceding
- }
-
- IFile file2 = destinationProject.getFile(fileName.toUpperCase());
- try {
- file2.create(getRandomContents(), true, null);
- assertTrue("1.1",true);
- } catch (CoreException e) {
- assertTrue("1.1",false); // should not happen
- return; // no point in proceding
- }
-
- // try to copy the file from source project to destination project.
- // should fail due to conflict
- try {
- file1.copy(destinationProject.getFullPath().append(file1.getName()),true,null);
- assertTrue("1.2",isCaseSensitive);
- } catch (CoreException e) {
- assertTrue("1.2",!isCaseSensitive);
- }
-
- // try to move the file from source project to destination project.
- // should fail due to conflict
- try {
- file1.move(destinationProject.getFullPath().append(file1.getName()),true,null);
- assertTrue("1.3",false);
- } catch (CoreException e) {
- assertTrue("1.3",true);
- }
-}
-
-public void testCopyAndMoveFolderOverFile() {
- String name = "test31415";
- IProject sourceProject = getWorkspace().getRoot().getProjects()[0];
- IProject destinationProject = getWorkspace().getRoot().getProjects()[1];
-
- // create 2 resources, one in each project, with case-different names
- IFolder folder = sourceProject.getFolder(name);
- try {
- folder.create(true, true, null);
- assertTrue("1.0",true);
- } catch (CoreException e) {
- assertTrue("1.0",false); // should not happen
- return; // no point in proceding
- }
-
- IFile file = destinationProject.getFile(name.toUpperCase());
- try {
- file.create(getRandomContents(), true, null);
- assertTrue("1.1",true);
- } catch (CoreException e) {
- assertTrue("1.1",false); // should not happen
- return; // no point in proceding
- }
-
- // try to copy the folder from source project to destination project.
- // should fail due to conflict with existing file with case-different name
- try {
- folder.copy(destinationProject.getFullPath().append(folder.getName()),true,null);
- assertTrue("1.2",isCaseSensitive);
- } catch (CoreException e) {
- assertTrue("1.2",!isCaseSensitive);
- }
-
- // try to move the folder from source project to destination project.
- // should fail due to conflict with existing file with case-different name
- try {
- folder.move(destinationProject.getFullPath().append(folder.getName()),true,null);
- assertTrue("1.3",false);
- } catch (CoreException e) {
- assertTrue("1.3",true);
- }
-}
-
-public void testCopyAndMoveFileOverFolder() {
- String name = "test31415";
- IProject sourceProject = getWorkspace().getRoot().getProjects()[0];
- IProject destinationProject = getWorkspace().getRoot().getProjects()[1];
-
- // create 2 resources, one in each project, with case-different names
- IFile file = sourceProject.getFile(name);
- try {
- file.create(getRandomContents(), true, null);
- assertTrue("1.0",true);
- } catch (CoreException e) {
- assertTrue("1.0",false); // should not happen
- return; // no point in proceding
- }
-
- IFolder folder = destinationProject.getFolder(name.toUpperCase());
- try {
- folder.create(true, true, null);
- assertTrue("1.1",true);
- } catch (CoreException e) {
- assertTrue("1.1",false); // should not happen
- return; // no point in proceding
- }
-
- // try to copy the file from source project to destination project.
- // should fail due to conflict with existing folder with case-different name
- try {
- file.copy(destinationProject.getFullPath().append(file.getName()),true,null);
- assertTrue("1.2",isCaseSensitive);
- } catch (CoreException e) {
- assertTrue("1.2",!isCaseSensitive);
- }
-
- // try to move the file from source project to destination project.
- // should fail due to conflict with existing folder with case-different name
- try {
- file.move(destinationProject.getFullPath().append(file.getName()),true,null);
- assertTrue("1.3",false);
- } catch (CoreException e) {
- assertTrue("1.3",true);
- }
-}
-public void testCopyAndMoveFolderBecomeProject() {
- IProject sourceProject = getWorkspace().getRoot().getProjects()[0];
- IProject blockingProject = getWorkspace().getRoot().getProjects()[1];
-
- // create a folder in the source project with a case-different name to the second project
- IFolder folder = sourceProject.getFolder(blockingProject.getName().toUpperCase());
- try {
- folder.create(true, true, null);
- } catch (CoreException e) {
- fail("1.0",e);
- }
-
- // try to move the folder from source project to the root, which makes it a project.
- // should always fails since we aren't allowed to move a folder to be a project.
- try {
- folder.move(Path.ROOT.append(folder.getName()),true,null);
- fail("1.1");
- } catch (CoreException e) {
- }
-
- // try to copy the folder from source project to the root, which makes it a project.
- // should always fail since we aren't allowed to copy a folder to be a project
- try {
- folder.copy(Path.ROOT.append(folder.getName()),true,null);
- fail("1.2");
- } catch (CoreException e) {
- }
-}
-public void testCopyAndMoveProjectBecomeFolder() {
- IProject sourceProject = getWorkspace().getRoot().getProjects()[0];
- IProject destinationProject = getWorkspace().getRoot().getProjects()[1];
-
- // create a file in the destination project with a case-different name of the source project
- IFile file = destinationProject.getFile(sourceProject.getName().toUpperCase());
- try {
- file.create(getRandomContents(), true, null);
- } catch (CoreException e) {
- fail("1.0",e);
- }
-
- // try to move the source project to the destination project, which makes it a folder.
- // should fail because we aren't allowed to move a project to be a folder
- try {
- sourceProject.move(destinationProject.getFullPath().append(sourceProject.getName()),true,null);
- fail("1.1");
- } catch (CoreException e) {
- }
-
- // try to copy the source project to the destination project, which makes it a folder.
- // should fail because we aren't allowed to copy a project to be a folder
- try {
- sourceProject.copy(destinationProject.getFullPath().append(sourceProject.getName()),true,null);
- fail("1.2");
- } catch (CoreException e) {
- }
-}
-public void testRefreshLocalFolder1() {
- String name = "test31415";
- IProject project = getWorkspace().getRoot().getProjects()[0];
-
- // create a Folder, which should be fine
- IFolder folder = project.getFolder(name.toUpperCase());
- try {
- folder.create(true, true, null);
- assertTrue("1.0",true);
- } catch (CoreException e) {
- fail("1.1", e); // should not happen
- }
-
- // get a Folder handle with the same name but different casing
- // in order to determine file system location
- IFolder herringRouge = project.getFolder(name);
-
- // create a directory with the folder's name
- folder.getLocation().toFile().delete();
- java.io.File dir = herringRouge.getLocation().toFile();
- dir.mkdir();
-
- // do a refresh, which should cause a problem
- try {
- project.refreshLocal(IResource.DEPTH_INFINITE,null);
- } catch (CoreException e) {
- fail("1.2", e);
- }
-
- assertTrue("2.0", !folder.exists());
- assertTrue("2.1", herringRouge.exists());
-}
-public void testRefreshLocalFile1() {
- String name = "test31415";
- IProject project = getWorkspace().getRoot().getProjects()[0];
-
- // create a File, which should be fine
- IFile file = project.getFile(name.toUpperCase());
- try {
- file.create(getRandomContents(), true, null);
- assertTrue("1.0",true);
- } catch (CoreException e) {
- fail("1.1", e); // should not happen
- }
-
- // get a File handle with the same name but different casing
- // in order to determine file system location
- IFile herringRouge = project.getFile(name);
-
- // create a file in the local file system with the same name but different casing
- ensureDoesNotExistInFileSystem(file);
- ensureExistsInFileSystem(herringRouge);
-
- // do a refresh, which should cause a problem
- try {
- project.refreshLocal(IResource.DEPTH_INFINITE,null);
- } catch (CoreException e) {
- fail("3.0", e);
- }
-
- assertTrue("4.0", !file.exists());
- assertTrue("4.1", herringRouge.exists());
-}
-
-public void testRefreshLocalFolder2() {
- String name = "test31415";
- IProject project = getWorkspace().getRoot().getProjects()[0];
-
- // create a Folder, which should be fine
- IFolder folder = project.getFolder(name.toUpperCase());
- try {
- folder.create(true, true, null);
- assertTrue("1.0",true);
- } catch (CoreException e) {
- fail("1.1", e); // should not happen
- }
-
- // get a File handle with the same name but different casing
- // in order to determine file system location
- IFile herringRouge = project.getFile(name);
-
- // create a file in the local file system with the same name but different casing
- ensureDoesNotExistInFileSystem(folder);
- ensureExistsInFileSystem(herringRouge);
-
- // do a refresh, which should cause a problem
- try {
- project.refreshLocal(IResource.DEPTH_INFINITE,null);
- } catch (CoreException e) {
- fail("3.0", e);
- }
-
- assertTrue("4.0", !folder.exists());
- assertTrue("4.1", herringRouge.exists());
-}
-
-public void testRefreshLocalFile2() {
- String name = "test31415";
- IProject project = getWorkspace().getRoot().getProjects()[0];
-
- // create a File, which should be fine
- IFile file = project.getFile(name.toUpperCase());
- try {
- file.create(getRandomContents(), true, null);
- assertTrue("1.0",true);
- } catch (CoreException e) {
- fail("1.1", e); // should not happen
- }
-
- // get a Folder handle with the same name but different casing
- // in order to determine file system location
- IFolder herringRouge = project.getFolder(name);
-
- // create a directory with the folder's name
- java.io.File localFile = file.getLocation().toFile();
- localFile.delete();
- assertTrue("2.0", !localFile.exists());
- java.io.File dir = herringRouge.getLocation().toFile();
- dir.mkdir();
- assertTrue("2.1", dir.exists());
-
- // do a refresh, which should cause a problem
- try {
- project.refreshLocal(IResource.DEPTH_INFINITE,null);
- } catch (CoreException e) {
- fail("3.0", e);
- }
-
- assertTrue("4.0", !file.exists());
- assertTrue("4.1", herringRouge.exists());
-}
-public void testDeleteResources() {
- String name = "test31415";
-
- // create a project, should be fine
- IProject project = getWorkspace().getRoot().getProject(name);
- try {
- project.create(null);
- project.open(null);
- assertTrue("1.0",true);
- } catch (CoreException e) {
- assertTrue("1.1",false); // should not happen
- return; // no point in proceding
- }
-
- // create a Folder, which should be fine
- IFolder folder = project.getFolder(name);
- try {
- folder.create(true, true, null);
- assertTrue("2.0",true);
- } catch (CoreException e) {
- fail("2.1", e); // should not happen
- }
-
- // create a File, which should be fine
- IFile file = folder.getFile(name);
- try {
- file.create(getRandomContents(), true, null);
- assertTrue("3.0",true);
- } catch (CoreException e) {
- fail("3.1", e); // should not happen
- }
-
- // replace the File's filesystem rep. with a case-different name
- java.io.File localFile = file.getLocation().toFile();
- localFile.delete();
- assertTrue("4.0", !localFile.exists());
- localFile = new java.io.File(file.getLocation().removeLastSegments(1).toString(),name.toUpperCase());
- try {
- localFile.createNewFile();
- } catch (IOException e) {
- fail("4.1",e);
- }
- assertTrue("4.2", localFile.exists());
-
- try {
- file.delete(true,null);
- // FIXME: there is a bug in the code related to this scenario
-// assert("5.0", isCaseSensitive);
- } catch (CoreException e) {
- // FIXME: there is a bug in the code related to this scenario
-// assert("5.1", !isCaseSensitive);
- }
-
- localFile.delete(); // so that we can change its parent folder
- assertTrue("6.0", !localFile.exists());
-
- // replace the Folder's filesystem rep. with a case-different name
- java.io.File localFolder = folder.getLocation().toFile();
- localFolder.delete();
- assertTrue("7.0", !localFolder.exists());
- localFolder = new java.io.File(folder.getLocation().removeLastSegments(1).toString(),name.toUpperCase());
- localFolder.mkdir();
- assertTrue("7.1", localFolder.exists());
-
- try {
- folder.delete(true,null);
- // FIXME: there is a bug in the code related to this scenario
-// assert("8.0", isCaseSensitive);
- } catch (CoreException e) {
- // FIXME: there is a bug in the code related to this scenario
-// assert("8.1", !isCaseSensitive);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/CopyTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/CopyTest.java
deleted file mode 100644
index def05d3..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/CopyTest.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.localstore;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-
-/**
- * Test the copy operation.
- */
-public class CopyTest extends LocalStoreTest {
-public CopyTest() {
- super();
-}
-public CopyTest(String name) {
- super(name);
-}
-public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(new CopyTest("testCopyResource"));
- return suite;
-}
-public void testCopyResource() throws Throwable {
- /* create common objects */
- IProject[] projects = getWorkspace().getRoot().getProjects();
-
- /* create folder and file */
- IFolder folder = projects[0].getFolder("folder");
- IFile file = folder.getFile("file.txt");
- ensureExistsInWorkspace(folder, true);
- ensureExistsInFileSystem(folder);
- ensureExistsInWorkspace(file, true);
- ensureExistsInFileSystem(file);
- /* add some properties to file (server, local and session) */
- QualifiedName[] propNames = new QualifiedName[numberOfProperties];
- String[] propValues = new String[numberOfProperties];
- for (int i = 0; i < numberOfProperties; i++) {
- propNames[i] = new QualifiedName("test", "prop" + i);
- propValues[i] = "value" + i;
- file.setPersistentProperty(propNames[i], propValues[i]);
- file.setSessionProperty(propNames[i], propValues[i]);
- }
-
- /* copy to absolute path */
- IResource destination = projects[0].getFile("copy of file.txt");
- ensureDoesNotExistInFileSystem(destination);
- try {
- file.copy(destination.getFullPath(), true, null);
- } catch (CoreException e) {
- fail("1.0", e);
- }
- assertTrue("1.1", destination.exists());
- /* assert properties were properly copied */
- for (int i = 0; i < numberOfProperties; i++) {
- String persistentValue = destination.getPersistentProperty(propNames[i]);
- Object sessionValue = destination.getSessionProperty(propNames[i]);
- assertTrue("1.2", propValues[i].equals(persistentValue));
- assertTrue("1.4", !propValues[i].equals(sessionValue));
- }
- ensureDoesNotExistInWorkspace(destination);
- ensureDoesNotExistInFileSystem(destination);
-
- /* copy to relative path */
- IPath path = new Path("copy of file.txt");
- destination = folder.getFile(path);
- ensureDoesNotExistInFileSystem(destination);
- try {
- file.copy(path, true, null);
- } catch (CoreException e) {
- fail("2.0", e);
- }
- assertTrue("2.1", destination.exists());
- /* assert properties were properly copied */
- for (int i = 0; i < numberOfProperties; i++) {
- String persistentValue = destination.getPersistentProperty(propNames[i]);
- Object sessionValue = destination.getSessionProperty(propNames[i]);
- assertTrue("2.2", propValues[i].equals(persistentValue));
- assertTrue("2.4", !propValues[i].equals(sessionValue));
- }
- ensureDoesNotExistInWorkspace(destination);
- ensureDoesNotExistInFileSystem(destination);
-
- /* copy folder to destination under its hierarchy */
- destination = folder.getFolder("subfolder");
- try {
- folder.copy(destination.getFullPath(), true, null);
- fail("3.1");
- } catch (RuntimeException e) {
- } catch (CoreException e) {
- fail("3.2", e);
- }
-
- /* test flag force = false */
- projects[0].refreshLocal(IResource.DEPTH_INFINITE, null);
- IFolder subfolder = folder.getFolder("subfolder");
- ensureExistsInFileSystem(subfolder);
- IFile anotherFile = folder.getFile("new file");
- ensureExistsInFileSystem(anotherFile);
- destination = projects[0].getFolder("destination");
- try {
- folder.copy(destination.getFullPath(), false, null);
- fail("4.1");
- } catch (CoreException e) {
- assertTrue("4.2", e.getStatus().getChildren().length == 2);
- }
- assertTrue("4.3", destination.exists());
- assertTrue("4.4", ((IContainer) destination).getFile(new Path(file.getName())).exists());
- assertTrue("4.5", !((IContainer) destination).getFolder(new Path(subfolder.getName())).exists());
- assertTrue("4.6", !((IContainer) destination).getFile(new Path(anotherFile.getName())).exists());
- /* assert properties were properly copied */
- IResource target = ((IContainer) destination).getFile(new Path(file.getName()));
- for (int i = 0; i < numberOfProperties; i++) {
- String persistentValue = target.getPersistentProperty(propNames[i]);
- Object sessionValue = target.getSessionProperty(propNames[i]);
- assertTrue("4.7", propValues[i].equals(persistentValue));
- assertTrue("4.9", !propValues[i].equals(sessionValue));
- }
- ensureDoesNotExistInWorkspace(destination);
- ensureDoesNotExistInFileSystem(destination);
-
- /* copy a file that is not local but exists in the workspace */
- file = projects[0].getFile("ghost");
- file.create(null, true, null);
- ensureDoesNotExistInFileSystem(file);
- destination = projects[0].getFile("destination");
- try {
- file.copy(destination.getFullPath(), true, null);
- fail("5.1");
- } catch (CoreException e) {
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/DeleteTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/DeleteTest.java
deleted file mode 100644
index 7f902a0..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/DeleteTest.java
+++ /dev/null
@@ -1,422 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.localstore;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.resources.Workspace;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-
-/**
- *
- */
-public class DeleteTest extends LocalStoreTest {
-public DeleteTest() {
- super();
-}
-public DeleteTest(String name) {
- super(name);
-}
-public static Test suite() {
- return new TestSuite(DeleteTest.class);
-
-// TestSuite suite = new TestSuite();
-// suite.addTest(new DeleteTest("testDeleteResource"));
-// return suite;
-}
-public void testDeleteOpenProject() {
- IProject project = projects[0];
- IFolder folder = project.getFolder("folder");
- IFile file = folder.getFile("file");
-
- /* ===========================================================
- * project is OPEN, deleteContents=FALSE, force=TRUE
- * =========================================================== */
-
- /* create some resources */
- ensureExistsInWorkspace(new IResource[] {project, folder, file}, true);
- IPath folderPath = folder.getLocation();
- IPath filePath = file.getLocation();
- IPath projectLocation = project.getLocation();
-
- /* delete */
- try {
- project.delete(false, true, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- /* assert project does not exist anymore in the workspace*/
- assertTrue("1.1", !project.exists());
- assertTrue("1.2", !((Workspace) getWorkspace()).getMetaArea().locationFor(project).toFile().exists());
- assertNull("1.3", project.getLocation());
-
- /* assert resources still exist */
- assertTrue("1.4", folderPath.toFile().isDirectory());
- assertTrue("1.5", filePath.toFile().isFile());
-
- /* remove trash */
- Workspace.clear(projectLocation.toFile());
-
- /* ===========================================================
- * project is OPEN, deleteContents=TRUE, force=TRUE
- * - uses default default mapping
- * ========================================================== */
-
- /* initialize common objects */
- ensureExistsInWorkspace(new IResource[] {project, folder, file}, true);
- folderPath = folder.getLocation();
- filePath = file.getLocation();
- projectLocation = project.getLocation();
-
- /* delete */
- try {
- project.delete(true, true, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- /* assert project does not exist anymore in the workspace */
- assertTrue("2.1", !project.exists());
- assertTrue("2.2", !((Workspace) getWorkspace()).getMetaArea().locationFor(project).toFile().exists());
- assertNull("2.3", project.getLocation());
-
- /* assert resources do not exist anymore */
- assertTrue("2.4", !projectLocation.toFile().exists());
- assertTrue("2.5", !folderPath.toFile().exists());
- assertTrue("2.6", !filePath.toFile().exists());
-
- /* ===========================================================
- * project is OPEN, deleteContents=TRUE, force=TRUE
- * - defines default mapping
- * - does not create resources on disk
- * =========================================================== */
-
- /* initialize common objects */
- ensureExistsInWorkspace(project, true);
- ensureExistsInWorkspace(new IResource[] {folder, file}, false);
- folderPath = folder.getLocation();
- filePath = file.getLocation();
- projectLocation = project.getLocation();
-
- /* delete */
- try {
- project.delete(true, true, getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
-
- /* assert project does not exist anymore */
- assertTrue("3.1", !project.exists());
- assertTrue("3.2", !((Workspace) getWorkspace()).getMetaArea().locationFor(project).toFile().exists());
- assertNull("3.3", project.getLocation());
-
- /* assert resources do not exist anymore */
- assertTrue("3.4", !folderPath.toFile().isDirectory());
- assertTrue("3.5", !filePath.toFile().isFile());
-
- /* ===========================================================
- * project is OPEN, deleteContents=TRUE, force=true
- * - create resources at default default area
- * - defines default mapping
- * =========================================================== */
-
- /* initialize common objects */
- ensureExistsInWorkspace(new IResource[] {project, folder, file}, true);
- folderPath = folder.getLocation();
- filePath = file.getLocation();
-
- /* delete */
- try {
- project.delete(true, true, getMonitor());
- } catch (CoreException e) {
- fail("4.0", e);
- }
-
- /* assert project does not exist anymore */
- assertTrue("6.1", !project.exists());
- assertTrue("6.2", !((Workspace) getWorkspace()).getMetaArea().locationFor(project).toFile().exists());
- assertNull("6.3", project.getLocation());
-
- /* assert resources do not still exist at default default area */
- assertTrue("6.4", !folderPath.toFile().exists());
- assertTrue("6.5", !filePath.toFile().exists());
-
- /* remove trash */
- Workspace.clear(folderPath.toFile());
-
- /* ===========================================================
- * project is OPEN, deleteContents=TRUE, force=TRUE
- * - defines default mapping
- * - creates resources only on disk
- * =========================================================== */
-
- /* initialize common objects */
- ensureExistsInWorkspace(project, true);
- ensureExistsInFileSystem(new IResource[] {folder, file});
- folderPath = folder.getLocation();
- filePath = file.getLocation();
- projectLocation = project.getLocation();
-
- /* delete */
- try {
- project.delete(true, true, getMonitor());
- } catch (CoreException e) {
- fail("7.0", e);
- }
-
- /* assert project does not exist anymore */
- assertTrue("7.1", !project.exists());
- assertTrue("7.2", !((Workspace) getWorkspace()).getMetaArea().locationFor(project).toFile().exists());
- assertNull("7.3", project.getLocation());
-
- /* assert resources do not exist anymore */
- assertTrue("7.4", !folderPath.toFile().isDirectory());
- assertTrue("7.5", !filePath.toFile().isFile());
-
-}
-public void testDeleteClosedProject() throws Throwable {
-
- IProject project = projects[0];
- IFolder folder = project.getFolder("folder");
- IFile file = folder.getFile("file");
-
- /* ===========================================================
- * project is CLOSED, deleteContents=FALSE, force=TRUE
- * - resources exist in workspace but not on disk
- * =========================================================== */
-
- /* initialize common objects */
- ensureExistsInWorkspace(new IResource[] {project, folder}, true);
- ensureExistsInWorkspace(file, false);
- IPath folderPath = folder.getLocation();
- IPath filePath = file.getLocation();
- IPath projectLocation = project.getLocation();
-
- /* close and delete */
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
- try {
- project.delete(false, true, getMonitor());
- } catch (CoreException e) {
- fail("1.1", e);
- }
-
- /* assert project does not exist anymore in the workspace */
- assertTrue("1.2", !project.exists());
- assertTrue("1.3", !((Workspace) getWorkspace()).getMetaArea().locationFor(project).toFile().exists());
- assertNull("1.4", project.getLocation());
-
- /* assert resources still exist (if appropriate) */
- assertTrue("1.5", folderPath.toFile().exists());
- assertTrue("1.6", !filePath.toFile().exists());
-
- /* remove trash */
- Workspace.clear(projectLocation.toFile());
-
- /* ===========================================================
- * project is CLOSED, deleteContents=TRUE, force=TRUE
- * - uses default default mapping
- * =========================================================== */
-
- /* initialize common objects */
- ensureExistsInWorkspace(new IResource[] {project, folder, file}, true);
- folderPath = folder.getLocation();
- filePath = file.getLocation();
-
- /* close and delete */
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
- try {
- project.delete(true, true, getMonitor());
- } catch (CoreException e) {
- fail("2.1", e);
- }
-
- /* assert project does not exist anymore */
- assertTrue("2.2", !project.exists());
- assertTrue("2.3", !((Workspace) getWorkspace()).getMetaArea().locationFor(project).toFile().exists());
- assertNull("2.4", project.getLocation());
-
- /* assert resources do not exist anymore */
- assertTrue("2.5", !folderPath.toFile().isDirectory());
- assertTrue("2.6", !filePath.toFile().isFile());
-
- /* ===========================================================
- * project is CLOSED, deleteContents=TRUE, force = FALSE
- * - uses default default mapping
- * =========================================================== */
-
- /* initialize common objects */
- ensureExistsInWorkspace(new IResource[] {project, folder}, true);
- ensureExistsInWorkspace(file, false);
- folderPath = folder.getLocation();
- filePath = file.getLocation();
- projectLocation = project.getLocation();
-
- /* close and delete */
- try {
- projects[0].close(getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
- try {
- projects[0].delete(true, false, getMonitor());
- } catch (CoreException e) {
- fail("3.1", e);
- }
-
- /* assert project was deleted */
- assertTrue("3.2", !project.exists());
- IPath metaAreaLocation = ((Workspace) getWorkspace()).getMetaArea().locationFor(project);
- assertTrue("3.3", !metaAreaLocation.toFile().exists());
- assertTrue("3.4", !metaAreaLocation.append(".properties").toFile().exists());
- assertTrue("3.5", !projectLocation.append(IProjectDescription.DESCRIPTION_FILE_NAME).toFile().exists());
- assertNull("3.6", project.getLocation());
-
- /* assert resources do not exist anymore */
- assertTrue("3.7", !folderPath.toFile().exists());
- assertTrue("3.8", !filePath.toFile().exists());
-}
-public void testDeleteResource() throws Throwable {
- /* test's hierarchy
-
- P0
- |
- |-- folder
- |
- |-- fileSync
- |
- |-- fileUnsync
- |
- |-- fileCreated
- |
- |-- subfolderSync
- | |
- | |-- deletedfolderSync
- |
- |-- subfolderUnsync
- | |
- | |-- subsubfolderUnsync
- | |
- | |-- susubfileSync
- | |
- | |-- susubfileUnsync
-
- */
-
- /* =================== */
- /* (1) force = TRUE */
- /* =================== */
-
- /* create some resources */
- IFolder folder = projects[0].getFolder("folder");
- ensureExistsInWorkspace(folder, true);
- IFile fileSync = folder.getFile("fileSync");
- ensureExistsInWorkspace(fileSync, true);
- IFile fileUnsync = folder.getFile("fileUnsync");
- ensureExistsInWorkspace(fileUnsync, true);
- IFile fileCreated = folder.getFile("fileCreated");
- ensureExistsInFileSystem(fileCreated); // create only in file system
- IFolder subfolderSync = folder.getFolder("subfolderSync");
- ensureExistsInWorkspace(subfolderSync, true);
- IFolder deletedfolderSync = subfolderSync.getFolder("deletedfolderSync");
- ensureExistsInWorkspace(deletedfolderSync, true);
- IFolder subfolderUnsync = folder.getFolder("subfolderUnsync");
- ensureExistsInWorkspace(subfolderUnsync, true);
- IFolder subsubfolderUnsync = subfolderUnsync.getFolder("subsubfolderUnsync");
- ensureExistsInWorkspace(subsubfolderUnsync, true);
- IFile subsubfileSync = subsubfolderUnsync.getFile("subsubfileSync");
- ensureExistsInWorkspace(subsubfileSync, true);
- IFile subsubfileUnsync = subsubfolderUnsync.getFile("subsubfileUnsync");
- ensureExistsInWorkspace(subsubfileUnsync, true);
-
- /* make some resources "unsync" with the workspace */
- Thread.sleep(sleepTime);
- ensureExistsInFileSystem(fileUnsync);
- ensureDoesNotExistInFileSystem(deletedfolderSync);
- ensureExistsInFileSystem(subsubfileUnsync);
-
- /* delete */
- folder.delete(true, null);
-
- /* assert resources do not exist anymore */
- assertTrue("1.1", !folder.getLocation().toFile().exists());
-
- /* =================== */
- /* (2) force = FALSE */
- /* =================== */
-
- /* create some resources */
- folder = projects[0].getFolder("folder");
- ensureExistsInWorkspace(folder, true);
- //
- fileSync = folder.getFile("fileSync");
- ensureExistsInWorkspace(fileSync, true);
- //
- fileUnsync = folder.getFile("fileUnsync");
- ensureExistsInWorkspace(fileUnsync, true);
- //
- fileCreated = folder.getFile("fileCreated");
- ensureExistsInFileSystem(fileCreated); // create only in file system
- //
- subfolderSync = folder.getFolder("subfolderSync");
- ensureExistsInWorkspace(subfolderSync, true);
- //
- deletedfolderSync = subfolderSync.getFolder("deletedfolderSync");
- ensureExistsInWorkspace(deletedfolderSync, true);
- //
- subfolderUnsync = folder.getFolder("subfolderUnsync");
- ensureExistsInWorkspace(subfolderUnsync, true);
- //
- subsubfolderUnsync = subfolderUnsync.getFolder("subsubfolderUnsync");
- ensureExistsInWorkspace(subsubfolderUnsync, true);
- //
- subsubfileSync = subsubfolderUnsync.getFile("subsubfileSync");
- ensureExistsInWorkspace(subsubfileSync, true);
- //
- subsubfileUnsync = subsubfolderUnsync.getFile("subsubfileUnsync");
- ensureExistsInWorkspace(subsubfileUnsync, true);
-
- /* make some resources "unsync" with the workspace */
- Thread.sleep(sleepTime);
- ensureExistsInFileSystem(fileUnsync);
- ensureDoesNotExistInFileSystem(deletedfolderSync);
- ensureExistsInFileSystem(subsubfileUnsync);
-
- /* delete */
- try {
- folder.delete(false, null);
- fail("2.0");
- } catch (CoreException e) {
- }
-
- /* assert resources do not exist anymore in the file system */
- assertTrue("2.1", folder.getLocation().toFile().exists());
- assertTrue("2.2", !fileSync.getLocation().toFile().exists());
- assertTrue("2.3", fileUnsync.getLocation().toFile().exists());
- assertTrue("2.4", !subfolderSync.getLocation().toFile().exists());
- assertTrue("2.5", subfolderUnsync.getLocation().toFile().exists());
- assertTrue("2.6", !deletedfolderSync.getLocation().toFile().exists());
- assertTrue("2.7", subsubfolderUnsync.getLocation().toFile().exists());
- assertTrue("2.8", subsubfileUnsync.getLocation().toFile().exists());
- assertTrue("2.9", !subsubfileSync.getLocation().toFile().exists());
- assertTrue("2.10", fileCreated.getLocation().toFile().exists());
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/FileSystemResourceManagerTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/FileSystemResourceManagerTest.java
deleted file mode 100644
index 58c0d36..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/FileSystemResourceManagerTest.java
+++ /dev/null
@@ -1,439 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.localstore;
-
-import java.io.InputStream;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.localstore.CoreFileSystemLibrary;
-import org.eclipse.core.internal.resources.*;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-//
-public class FileSystemResourceManagerTest extends LocalStoreTest implements ICoreConstants {
-public FileSystemResourceManagerTest() {
- super();
-}
-public FileSystemResourceManagerTest(String name) {
- super(name);
-}
-public String[] defineHierarchy() {
- return new String[] {
- "/Folder1/",
- "/Folder1/File1",
- "/Folder1/Folder2/",
- "/Folder1/Folder2/File2",
- "/Folder1/Folder2/Folder3/"
- };
-}
-public static Test suite() {
- return new TestSuite(FileSystemResourceManagerTest.class);
-}
-/**
- */
-public void testContainerFor() throws Throwable {
-
- /* test null parameter */
- try {
- getLocalManager().containerForLocation(null);
- fail("1.1");
- } catch (RuntimeException e) {
- }
-
- /* test normal conditions under default mapping */
-
- // project/target
- Path path = new Path("target");
- IFolder folder = projects[0].getFolder(path);
- IPath location = projects[0].getLocation().append(path);
- IFolder testFolder = (IFolder) getLocalManager().containerForLocation(location);
- assertTrue("2.1", folder.equals(testFolder));
-
- // project/folder/target
- path = new Path("folder/target");
- folder = projects[0].getFolder(path);
- location = projects[0].getLocation().append(path);
- testFolder = (IFolder) getLocalManager().containerForLocation(location);
- assertTrue("2.2", folder.equals(testFolder));
-
- // project/folder/folder/target
- path = new Path("folder/folder/target");
- folder = projects[0].getFolder(path);
- location = projects[0].getLocation().append(path);
- testFolder = (IFolder) getLocalManager().containerForLocation(location);
- assertTrue("2.3", folder.equals(testFolder));
-
- /* non-existent location */
- testFolder = (IFolder) getLocalManager().containerForLocation(new Path("../this/path/must/not/exist"));
- assertTrue("3.1", testFolder == null);
-}
-/**
- * this test should move to FileTest
- */
-public void testCreateFile() throws Throwable {
- /* initialize common objects */
- IProject project = projects[0];
- IFile file = project.getFile("foo");
- /* common contents */
- String originalContent = "this string should not be equal the other";
-
- /* create file with flag false */
- try {
- file.create(getContents(originalContent), false, null);
- } catch (CoreException e) {
- fail("1.1", e);
- }
- assertTrue("1.2", file.exists());
- assertTrue("1.3", file.isLocal(IResource.DEPTH_ZERO));
- assertEquals("1.4", CoreFileSystemLibrary.getLastModified(file.getLocation().toOSString()), ((Resource) file).getResourceInfo(false, false).getLocalSyncInfo());
- try {
- assertTrue("1.5", compareContent(getContents(originalContent), getLocalManager().read((org.eclipse.core.internal.resources.File) file, true, null)));
- } catch (CoreException e) {
- fail("1.6", e);
- }
-}
-/**
- */
-public void testFileFor() throws Throwable {
-
- /* test null parameter */
- try {
- getLocalManager().fileForLocation(null);
- fail("1.1");
- } catch (RuntimeException e) {
- }
-
- /* test normal conditions under default mapping */
-
- // project/file
- Path path = new Path("file");
- IFile file = projects[0].getFile(path);
- IPath location = projects[0].getLocation().append(path);
- IFile testFile = getLocalManager().fileForLocation(location);
- assertTrue("2.1", file.equals(testFile));
-
- // project/folder/file
- path = new Path("folder/file");
- file = projects[0].getFile(path);
- location = projects[0].getLocation().append(path);
- testFile = getLocalManager().fileForLocation(location);
- assertTrue("2.2", file.equals(testFile));
-
- // project/folder/folder/file
- path = new Path("folder/folder/file");
- file = projects[0].getFile(path);
- location = projects[0].getLocation().append(path);
- testFile = getLocalManager().fileForLocation(location);
- assertTrue("2.3", file.equals(testFile));
-
- /* non-existent location */
- testFile = getLocalManager().fileForLocation(new Path("../this/path/must/not/exist"));
- assertTrue("7.1", testFile == null);
-}
-public void testIsLocal() throws Throwable {
- /* initialize common objects */
- final IProject project = projects[0];
-
- // create resources
- IResource[] resources = buildResources(project, defineHierarchy());
- ensureExistsInWorkspace(resources, true);
- ensureDoesNotExistInFileSystem(resources);
-
- // exists
- assertTrue("1.0", project.isLocal(IResource.DEPTH_INFINITE)); // test
-
- // test the depth parameter
- final IFolder folder = project.getFolder("Folder1");
- IWorkspaceRunnable operation = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
-
- IResource[] members = folder.members();
-
- for (int i = 0; i < members.length; i++) {
- ((Resource) members[i]).getResourceInfo(false, true).clear(M_LOCAL_EXISTS);
- }
- }
- };
- getWorkspace().run(operation, null);
- assertTrue("2.0", project.isLocal(IResource.DEPTH_ONE));
- assertTrue("3.0", folder.isLocal(IResource.DEPTH_ZERO));
- assertTrue("4.0", !folder.isLocal(IResource.DEPTH_INFINITE));
-
- // remove the trash
- ensureDoesNotExistInWorkspace(project);
-}
-/**
- * Scenario:
- * 1 solution
- * 3 projects
- */
-public void testLocationFor() throws Throwable {
-
- /* test project */
- IPath location = projects[0].getLocation();
- assertTrue("2.1", location.equals(getLocalManager().locationFor((Project) projects[0])));
- assertTrue("2.2", location.equals(Platform.getLocation().append(projects[0].getName())));
-}
-/**
- * Scenario:
- * 1 solution
- * 3 projects
- */
-public void testResourcePathFor() throws Throwable {
-
- ///* test null parameter */
- //try {
- //getLocalManager().resourcePathFor(null);
- //fail("1.1");
- //} catch (RuntimeException e) {
- //} catch (CoreException e) {
- //fail("1.2", e);
- //}
-
- ///* test normal conditions under default mapping */
-
- //// project/file
- //Path path = new Path("file");
- //IFile file = projects[0].getFile(path);
- //IPath location = projects[0].getLocation().append(path);
- //IPath testPath = getLocalManager().resourcePathFor(location);
- //assert("2.1", file.getFullPath().equals(testPath));
-
- //// project/folder/file
- //path = new Path("folder/file");
- //file = projects[0].getFile(path);
- //location = projects[0].getLocation().append(path);
- //testPath = getLocalManager().resourcePathFor(location);
- //assert("2.2", file.getFullPath().equals(testPath));
-
- //// project/folder/folder/file
- //path = new Path("folder/folder/file");
- //file = projects[0].getFile(path);
- //location = projects[0].getLocation().append(path);
- //testPath = getLocalManager().resourcePathFor(location);
- //assert("2.3", file.getFullPath().equals(testPath));
-}
-public void testSynchronizeProject() throws Throwable {
- /* test DEPTH parameter */
- /* DEPTH_ZERO */
- IFile file = projects[0].getFile("file");
- ensureExistsInFileSystem(file);
- projects[0].refreshLocal(IResource.DEPTH_ZERO, null);
- assertTrue("1.1", !file.exists());
- /* DEPTH_ONE */
- IFolder folder = projects[0].getFolder("folder");
- IFolder subfolder = folder.getFolder("subfolder");
- IFile subfile = folder.getFile("subfile");
- ensureExistsInFileSystem(folder);
- ensureExistsInFileSystem(subfolder);
- ensureExistsInFileSystem(subfile);
- projects[0].refreshLocal(IResource.DEPTH_ONE, null);
- assertTrue("2.1", file.exists());
- assertTrue("2.2", folder.exists());
- assertTrue("2.3", !subfolder.exists());
- assertTrue("2.4", !subfile.exists());
- /* DEPTH_INFINITE */
- projects[0].refreshLocal(IResource.DEPTH_INFINITE, null);
- assertTrue("3.1", file.exists());
- assertTrue("3.2", folder.exists());
- assertTrue("3.3", subfolder.exists());
- assertTrue("3.4", subfile.exists());
-
- /* closed project */
- /* #open synchronizes project */
- file = projects[0].getFile("closed");
- projects[0].close(null);
- ensureExistsInFileSystem(file);
- projects[0].open(null);
- assertTrue("4.1", file.exists());
- projects[0].refreshLocal(IResource.DEPTH_INFINITE, null);
- assertTrue("4.2", file.exists());
-
- /* refreshing an inexisting project should do nothing */
- getWorkspace().getRoot().getProject("inexistingProject").refreshLocal(IResource.DEPTH_INFINITE, null);
-}
-public void testWriteFile() {
- /* initialize common objects */
- IProject project = projects[0];
- IFile file = project.getFile("foo");
- ensureExistsInWorkspace(file, true);
- /* common contents */
- String originalContent = "this string should not be equal the other";
- String anotherContent = "and this string should not... well, you know...";
- InputStream original;
- InputStream another;
-
- /* write file for the first time */
- original = getContents(originalContent);
- try {
- write(file, original, true, null);
- } catch (CoreException e) {
- fail("1.0", e);
- }
- original = getContents(originalContent);
- try {
- assertTrue("1.1", compareContent(original, getLocalManager().read((org.eclipse.core.internal.resources.File) file, true, null)));
- } catch (CoreException e) {
- fail("1.2", e);
- }
-
- /* test the overwrite parameter (false) */
- another = getContents(anotherContent);
- try {
- write(file, another, false, null);
- } catch (CoreException e) {
- fail("2.0", e);
- }
- another = getContents(anotherContent);
- try {
- assertTrue("2.1", compareContent(another, getLocalManager().read((org.eclipse.core.internal.resources.File) file, true, null)));
- } catch (CoreException e) {
- fail("2.2", e);
- }
-
- /* test the overwrite parameter (true) */
- original = getContents(originalContent);
- try {
- write(file, original, true, null);
- } catch (CoreException e) {
- fail("3.0", e);
- }
- original = getContents(originalContent);
- try {
- assertTrue("3.1", compareContent(original, getLocalManager().read((org.eclipse.core.internal.resources.File) file, true, null)));
- } catch (CoreException e) {
- fail("3.2", e);
- }
-
- /* test the overwrite parameter (false) */
- ensureOutOfSync(file);
- another = getContents(anotherContent);
- try {
- write(file, another, false, null);
- fail("4.0", null);
- } catch (CoreException e) {
- }
- try {
- file.setContents(another, false, false, null);
- fail("4.3");
- } catch (CoreException e) {
- }
- try {
- file.setContents(another, true, false, null);
- } catch (CoreException e) {
- fail("4.4", e);
- }
-
- /* test the overwrite parameter (false) */
- ensureDoesNotExistInFileSystem(file);
- another = getContents(anotherContent);
- try {
- write(file, another, false, null);
- fail("5.0");
- } catch (CoreException e) {
- }
-
- /* remove trash */
- ensureDoesNotExistInWorkspace(project);
-}
-public void testWriteFolder() throws Throwable {
- /* initialize common objects */
- IProject project = projects[0];
- IFolder folder = project.getFolder("foo");
- ensureExistsInWorkspace(folder, true);
- boolean ok;
-
- /* existing file on destination */
- ensureDoesNotExistInFileSystem(folder);
- IFile file = project.getFile("foo");
- ensureExistsInFileSystem(file);
- /* force = true */
- ok = false;
- try {
- write(folder, true, null);
- } catch (CoreException e) {
- ok = true;
- }
- assertTrue("1.1", ok);
- /* force = false */
- ok = false;
- try {
- write(folder, false, null);
- } catch (CoreException e) {
- ok = true;
- }
- assertTrue("1.2", ok);
- ensureDoesNotExistInFileSystem(file);
-
- /* existing folder on destination */
- ensureExistsInFileSystem(folder);
- /* force = true */
- write(folder, true, null);
- assertTrue("2.1", folder.getLocation().toFile().isDirectory());
- /* force = false */
- ok = false;
- try {
- write(folder, false, null);
- } catch (CoreException e) {
- ok = true;
- }
- assertTrue("2.2", ok);
- ensureDoesNotExistInFileSystem(folder);
-
- /* inexisting resource on destination */
- /* force = true */
- write(folder, true, null);
- assertTrue("3.1", folder.getLocation().toFile().isDirectory());
- ensureDoesNotExistInFileSystem(folder);
- /* force = false */
- write(folder, false, null);
- assertTrue("3.1", folder.getLocation().toFile().isDirectory());
-}
-/**
- * 1.2 - write a project with default local location
- * 2.1 - delete project's local location
- */
-public void testWriteProject() throws Throwable {
- /* initialize common objects */
- final IProject project = projects[0];
-
- /* remove project location and write */
- IPath location = getLocalManager().locationFor((Project) project);
- ensureDoesNotExistInFileSystem(project);
- assertTrue("2.1", !location.toFile().isDirectory());
- //write project in a runnable, otherwise tree will be locked
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- ((Project)project).writeDescription(IResource.FORCE);
- }
- }, null);
- assertTrue("2.2", location.toFile().isDirectory());
- long lastModified = CoreFileSystemLibrary.getLastModified(getLocalManager().getDescriptionLocationFor(project).toOSString());
- assertEquals("2.3", lastModified, ((Resource) project).getResourceInfo(false, false).getLocalSyncInfo());
-}
-protected void write(final IFile file, final InputStream contents, final boolean force, IProgressMonitor monitor) throws CoreException {
- IWorkspaceRunnable operation = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- getLocalManager().write(file, getLocalManager().locationFor(file), contents, force, false, false, null);
- }
- };
- getWorkspace().run(operation, null);
-}
-protected void write(final IFolder folder, final boolean force, IProgressMonitor monitor) throws CoreException {
- IWorkspaceRunnable operation = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- getLocalManager().write((Folder) folder, force, null);
- }
- };
- getWorkspace().run(operation, null);
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/FileSystemStoreTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/FileSystemStoreTest.java
deleted file mode 100644
index 69c5fc8..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/FileSystemStoreTest.java
+++ /dev/null
@@ -1,434 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.localstore;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Date;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.localstore.CoreFileSystemLibrary;
-import org.eclipse.core.internal.localstore.FileSystemStore;
-import org.eclipse.core.internal.resources.Workspace;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.*;
-
-public class FileSystemStoreTest extends LocalStoreTest {
-public FileSystemStoreTest() {
- super();
-}
-public FileSystemStoreTest(String name) {
- super(name);
-}
-public static Test suite() {
- return new TestSuite(FileSystemStoreTest.class);
-}
-/**
- * Basically this is a test for the Windows Platform.
- */
-public void testCopyAcrossVolumes() throws Throwable {
-
- /* test if we are in the adequate environment */
- if (!new File("c:\\").exists() || !new File("d:\\").exists())
- return;
-
- /* initialize commom objetcs */
- FileSystemStore store = new FileSystemStore();
-
- /* build scenario */
- // create source root folder
- File tempC = new File("c:\\temp");
- tempC.mkdirs();
- assertTrue("1.1", tempC.isDirectory());
- // create destination root folder
- File tempD = new File("d:\\temp");
- tempD.mkdirs();
- assertTrue("1.2", tempD.isDirectory());
- // create tree
- File target = new File(tempC, "target");
- Workspace.clear(target);
- target.mkdirs();
- createTree(getTree(target));
-
- /* c:\temp\target -> d:\temp\target */
- File destination = new File(tempD, "target");
- store.copy(target, destination, IResource.DEPTH_INFINITE, null);
- assertTrue("3.1", verifyTree(getTree(destination)));
- Workspace.clear(destination);
-
- /* c:\temp\target -> d:\temp\copy of target */
- destination = new File(tempD, "copy of target");
- store.copy(target, destination, IResource.DEPTH_INFINITE, null);
- assertTrue("4.1", verifyTree(getTree(destination)));
- Workspace.clear(destination);
-
- /* c:\temp\target -> d:\temp\target (but the destination is already a file */
- destination = new File(tempD, "target");
- String anotherContent = "nothing..................gnihton";
- createFile(destination, anotherContent);
- assertTrue("5.1", destination.isFile());
- boolean ok = false;
- try {
- store.copy(target, destination, IResource.DEPTH_INFINITE, null);
- } catch (CoreException e) {
- ok = true;
- }
- assertTrue("5.2", ok);
- assertTrue("5.3", !verifyTree(getTree(destination)));
- Workspace.clear(destination);
-
- /* c:\temp\target -> d:\temp\target (but the destination is already a folder */
- destination = new File(tempD, "target");
- destination.mkdirs();
- assertTrue("6.1", destination.isDirectory());
- store.copy(target, destination, IResource.DEPTH_INFINITE, null);
- assertTrue("6.2", verifyTree(getTree(destination)));
- Workspace.clear(destination);
-
- /* remove trash */
- Workspace.clear(target);
-}
-public void testCopyDirectory() throws Throwable {
- /* initialize commom objetcs */
- FileSystemStore store = new FileSystemStore();
-
- /* build scenario */
- File temp = getWorkspace().getRoot().getLocation().append("temp").toFile();
- temp.mkdirs();
- assertTrue("1.1", temp.isDirectory());
- // create tree
- File target = new File(temp, "target");
- Workspace.clear(target);
- target.mkdirs();
- createTree(getTree(target));
-
- /* temp\target -> temp\copy of target */
- File copyOfTarget = new File(temp, "copy of target");
- store.copy(target, copyOfTarget, IResource.DEPTH_INFINITE, null);
- assertTrue("2.1", verifyTree(getTree(copyOfTarget)));
- Workspace.clear(copyOfTarget);
-
- /* remove trash */
- Workspace.clear(target);
-}
-public void testCopyFile() throws Throwable {
- /* initialize commom objetcs */
- FileSystemStore store = new FileSystemStore();
-
- /* build scenario */
- File temp = getWorkspace().getRoot().getLocation().append("temp").toFile();
- temp.mkdirs();
- assertTrue("1.1", temp.isDirectory());
- // create target
- String content = "this is just a simple content \n to a simple file \n to test a 'simple' copy";
- File target = new File(temp, "target");
- Workspace.clear(target);
- createFile(target, content);
- assertTrue("1.3", target.exists());
- assertTrue("1.4", compareContent(getContents(content), store.read(target)));
-
- /* temp\target -> temp\copy of target */
- File copyOfTarget = new File(temp, "copy of target");
- store.copy(target, copyOfTarget, IResource.DEPTH_INFINITE, null);
- assertTrue("2.1", compareContent(getContents(content), store.read(copyOfTarget)));
- copyOfTarget.delete();
-
- // We need to know whether or not we can unset the read-only flag
- // in order to perform this part of the test.
- if (CoreFileSystemLibrary.usingNatives()) {
- /* make source read-only and try the copy temp\target -> temp\copy of target */
- copyOfTarget = new File(temp, "copy of target");
- CoreFileSystemLibrary.setReadOnly(target.getAbsolutePath(), true);
- store.copy(target, copyOfTarget, IResource.DEPTH_INFINITE, null);
- assertTrue("3.1", compareContent(getContents(content), store.read(copyOfTarget)));
- // reset readonly flag for cleanup
- CoreFileSystemLibrary.setReadOnly(copyOfTarget.getAbsolutePath(), false);
- copyOfTarget.delete();
- // reset the readonly flag for cleanup
- CoreFileSystemLibrary.setReadOnly(target.getAbsolutePath(), false);
- Workspace.clear(target);
- }
-
- /* copy a big file to test progress monitor */
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < 1000; i++)
- sb.append("asdjhasldhaslkfjhasldkfjhasdlkfjhasdlfkjhasdflkjhsdaf");
- File bigFile = new File(temp, "bigFile");
- createFile(bigFile, sb.toString());
- assertTrue("7.1", bigFile.exists());
- assertTrue("7.2", compareContent(getContents(sb.toString()), store.read(bigFile)));
- File destination = new File(temp, "copy of bigFile");
- //IProgressMonitor monitor = new LoggingProgressMonitor(System.out);
- IProgressMonitor monitor = getMonitor();
- store.copy(bigFile, destination, IResource.DEPTH_INFINITE, monitor);
- assertTrue("7.3", compareContent(getContents(sb.toString()), store.read(destination)));
- destination.delete();
-
- /* remove trash */
- Workspace.clear(temp);
-}
-/**
- * Basically this is a test for the Windows Platform.
- */
-public void testCopyFileAcrossVolumes() throws Throwable {
- /* test if we are in the adequate environment */
- if (!new File("c:\\").exists() || !new File("d:\\").exists())
- return;
-
- /* initialize commom objetcs */
- FileSystemStore store = new FileSystemStore();
-
- /* build scenario */
- // create source
- File tempC = new File("c:\\temp");
- tempC.mkdirs();
- assertTrue("1.1", tempC.isDirectory());
- // create destination
- File tempD = new File("d:\\temp");
- tempD.mkdirs();
- assertTrue("1.2", tempD.isDirectory());
- // create target
- String content = "this is just a simple content \n to a simple file \n to test a 'simple' copy";
- File target = new File(tempC, "target");
- Workspace.clear(target);
- createFile(target, content);
- assertTrue("1.3", target.exists());
- assertTrue("1.4", compareContent(getContents(content), store.read(target)));
-
- /* c:\temp\target -> d:\temp\target */
- File destination = new File(tempD, "target");
- store.copy(target, destination, IResource.DEPTH_INFINITE, null);
- assertTrue("3.1", compareContent(getContents(content), store.read(destination)));
- destination.delete();
-
- /* c:\temp\target -> d:\temp\copy of target */
- destination = new File(tempD, "copy of target");
- store.copy(target, destination, IResource.DEPTH_INFINITE, null);
- assertTrue("4.1", compareContent(getContents(content), store.read(destination)));
- destination.delete();
-
- /* c:\temp\target -> d:\temp\target (but the destination is already a file */
- destination = new File(tempD, "target");
- String anotherContent = "nothing..................gnihton";
- createFile(destination, anotherContent);
- assertTrue("5.1", destination.isFile());
- store.copy(target, destination, IResource.DEPTH_INFINITE, null);
- assertTrue("5.2", compareContent(getContents(content), store.read(destination)));
- destination.delete();
-
- /* c:\temp\target -> d:\temp\target (but the destination is already a folder */
- destination = new File(tempD, "target");
- destination.delete();
- destination.mkdirs();
- assertTrue("6.1", destination.isDirectory());
- boolean ok = false;
- try {
- store.copy(target, destination, IResource.DEPTH_INFINITE, null);
- } catch (CoreException e) {
- /* test if the input stream inside the copy method was closed */
- assertTrue("6.1.1", target.delete());
- createFile(target, content);
- ok = true;
- }
- assertTrue("6.2", ok);
- assertTrue("6.3", destination.isDirectory());
- destination.delete();
-
- /* remove trash */
- target.delete();
-}
-public void testGetStat() {
- /* evaluate test environment */
- IPath root = getWorkspace().getRoot().getLocation().append("" + new Date().getTime());
- File temp = root.toFile();
- if (!temp.exists()) {
- temp.mkdirs();
- if (!temp.exists())
- return;
- }
-
- /* create common objects */
- File target = new File(temp, "target");
- long stat;
-
- /* test stat with an inexisting file */
- stat = CoreFileSystemLibrary.getStat(target.getAbsolutePath());
- assertTrue("1.0", stat == 0);
-
- /* test stat with an existing folder */
- target.mkdirs();
- stat = CoreFileSystemLibrary.getStat(target.getAbsolutePath());
- assertTrue("2.0", stat != 0);
-
- /* remove trash */
- target.delete();
- temp.delete();
-}
-public void testMove() throws Throwable {
- /* initialize commom objetcs */
- FileSystemStore store = new FileSystemStore();
-
- /* build scenario */
- File tempC = getWorkspace().getRoot().getLocation().append("temp").toFile();
- tempC.mkdirs();
- assertTrue("1.1", tempC.isDirectory());
- // create target file
- File target = new File(tempC, "target");
- String content = "just a content.....tnetnoc a tsuj";
- createFile(target, content);
- assertTrue("1.3", target.exists());
- // create target tree
- File tree = new File(tempC, "tree");
- Workspace.clear(tree);
- tree.mkdirs();
- createTree(getTree(tree));
-
- /* rename file */
- File destination = new File(tempC, "destination");
- store.move(target, destination, true, null);
- assertTrue("2.1", destination.isFile());
- assertTrue("2.2", !target.exists());
- store.move(destination, target, true, null);
- assertTrue("2.3", target.isFile());
- assertTrue("2.4", !destination.exists());
-
- /* rename file (but destination is already a file) */
- String anotherContent = "another content";
- createFile(destination, anotherContent);
- boolean ok = false;
- try {
- store.move(target, destination, false, null);
- } catch (CoreException e) {
- ok = true;
- }
- assertTrue("3.1", ok);
- assertTrue("3.2", target.isFile());
- destination.delete();
- assertTrue("3.3", !destination.exists());
-
- /* rename file (but destination is already a folder) */
- store.writeFolder(destination);
- try {
- store.move(target, destination, false, null);
- } catch (CoreException e) {
- ok = true;
- }
- assertTrue("4.1", ok);
- assertTrue("4.2", target.isFile());
- destination.delete();
- assertTrue("4.3", !destination.exists());
-
- /* rename folder */
- destination = new File(tempC, "destination");
- store.move(tree, destination, true, null);
- assertTrue("6.1", verifyTree(getTree(destination)));
- assertTrue("6.2", !tree.exists());
- store.move(destination, tree, true, null);
- assertTrue("6.3", verifyTree(getTree(tree)));
- assertTrue("6.4", !destination.exists());
-
- /* remove trash */
- Workspace.clear(target);
- Workspace.clear(tree);
-}
-public void testMoveAcrossVolumes() throws Throwable {
- /* test if we are in the adequate environment */
- if (!new File("c:\\").exists() || !new File("d:\\").exists())
- return;
-
- /* initialize commom objetcs */
- FileSystemStore store = new FileSystemStore();
-
- /* build scenario */
- // create source
- File tempC = new File("c:\\temp");
- tempC.mkdirs();
- assertTrue("1.1", tempC.isDirectory());
- // create destination
- File tempD = new File("d:\\temp");
- tempD.mkdirs();
- assertTrue("1.2", tempD.isDirectory());
- // create target file
- File target = new File(tempC, "target");
- String content = "just a content.....tnetnoc a tsuj";
- createFile(target, content);
- assertTrue("1.3", target.exists());
- // create target tree
- File tree = new File(tempC, "tree");
- Workspace.clear(tree);
- tree.mkdirs();
- createTree(getTree(tree));
-
- /* move file across volumes */
- File destination = new File(tempD, "target");
- store.move(target, destination,true, null);
- assertTrue("5.1", destination.isFile());
- assertTrue("5.2", !target.exists());
- store.move(destination, target, true, null);
- assertTrue("5.3", target.isFile());
- assertTrue("5.4", !destination.exists());
-
- /* move folder across volumes */
- destination = new File(tempD, "target");
- store.move(tree, destination, true, null);
- assertTrue("9.1", verifyTree(getTree(destination)));
- assertTrue("9.2", !tree.exists());
- store.move(destination, tree, true, null);
- assertTrue("9.3", verifyTree(getTree(tree)));
- assertTrue("9.4", !destination.exists());
-
- /* remove trash */
- Workspace.clear(target);
- Workspace.clear(tree);
-}
-public void testReadOnly() throws IOException {
- // We need to know whether or not we can unset the read-only flag
- // in order to perform this test.
- if (!CoreFileSystemLibrary.usingNatives())
- return;
-
- /* evaluate test environment */
- IPath root = getWorkspace().getRoot().getLocation().append("" + new Date().getTime());
- IPath target = root.append("target");
- File temp = root.toFile();
- if (!temp.exists()) {
- temp.mkdirs();
- if (!temp.exists())
- return;
- }
- try {
- createFileInFileSystem(target);
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- // file
- String fileName = target.toOSString();
- assertTrue("1.0", !CoreFileSystemLibrary.isReadOnly(fileName));
- assertTrue("1.1", CoreFileSystemLibrary.setReadOnly(fileName, true));
- assertTrue("1.2", CoreFileSystemLibrary.isReadOnly(fileName));
- assertTrue("1.3", CoreFileSystemLibrary.setReadOnly(fileName, false));
- assertTrue("1.4", !CoreFileSystemLibrary.isReadOnly(fileName));
-
- // folder
- fileName = root.toOSString();
- assertTrue("2.0", !CoreFileSystemLibrary.isReadOnly(fileName));
- assertTrue("2.1", CoreFileSystemLibrary.setReadOnly(fileName, true));
- assertTrue("2.2", CoreFileSystemLibrary.isReadOnly(fileName));
- assertTrue("2.3", CoreFileSystemLibrary.setReadOnly(fileName, false));
- assertTrue("2.4", !CoreFileSystemLibrary.isReadOnly(fileName));
-
- /* remove trash */
- target.toFile().delete();
- temp.delete();
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/HistoryStoreTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/HistoryStoreTest.java
deleted file mode 100644
index f0212dc..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/HistoryStoreTest.java
+++ /dev/null
@@ -1,2215 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.localstore;
-
-import java.io.*;
-import java.util.*;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.eclipse.core.internal.indexing.IndexCursor;
-import org.eclipse.core.internal.indexing.IndexedStoreException;
-import org.eclipse.core.internal.localstore.*;
-import org.eclipse.core.internal.properties.IndexedStoreWrapper;
-import org.eclipse.core.internal.resources.*;
-import org.eclipse.core.internal.utils.UniversalUniqueIdentifier;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-/**
- * This class defines all tests for the HistoryStore Class.
- */
-
-public class HistoryStoreTest extends EclipseWorkspaceTest {
-
- class VerificationFailedException extends Exception {
- VerificationFailedException(String message) {
- super(message);
- }
- }
- class HistoryStoreVisitorVerifier implements IHistoryStoreVisitor {
- Set expected = new HashSet();
- Set actual = new HashSet();
- public boolean visit(HistoryStoreEntry state) throws IndexedStoreException {
- actual.add(state.getPath());
- return true;
- }
- public void reset() {
- expected = new HashSet();
- actual = new HashSet();
- }
- public void addExpected(IPath path) {
- expected.add(path);
- }
- public void verify() throws VerificationFailedException {
- if (expected.size() != actual.size())
- throw new VerificationFailedException("Expected size (" + expected.size() + ") and actual size (" + actual.size() + ") differ.");
- for (Iterator i = expected.iterator(); i.hasNext();) {
- IPath path = (IPath) i.next();
- if (!actual.contains(path))
- throw new VerificationFailedException("Did not visit expected path: " + path);
- }
- }
- }
- class LogListenerVerifier implements ILogListener {
- List expected = new ArrayList();
- List actual = new ArrayList();
-
- void addExpected(int statusCode) {
- expected.add(new Integer(statusCode));
- }
- void verify() throws VerificationFailedException {
- String message;
- if (expected.size() != actual.size()) {
- message = "Expected size: " + expected.size() + " does not equal actual size: " + actual.size() + "\n";
- message += dump();
- throw new VerificationFailedException(message);
- }
- for (Iterator i = expected.iterator(); i.hasNext();) {
- Integer status = (Integer)i.next();
- if (!actual.contains(status)) {
- message = "Expected and actual results differ.\n";
- message += dump();
- throw new VerificationFailedException(message);
- }
- }
- }
- void reset() {
- expected = new ArrayList();
- actual = new ArrayList();
- }
- String dump() {
- StringBuffer buffer = new StringBuffer();
- buffer.append("Expected:\n");
- for (Iterator i = expected.iterator(); i.hasNext();)
- buffer.append("\t" + i.next() + "\n");
- buffer.append("Actual:\n");
- for (Iterator i = actual.iterator(); i.hasNext();)
- buffer.append("\t" + i.next() + "\n");
- return buffer.toString();
- }
- /**
- * @see org.eclipse.core.runtime.ILogListener#logging(org.eclipse.core.runtime.IStatus, java.lang.String)
- */
- public void logging(IStatus status, String plugin) {
- actual.add(new Integer(status.getCode()));
- }
-
- }
-
-public HistoryStoreTest() {
- super();
-}
-public HistoryStoreTest(String name) {
- super(name);
-}
-public static Test suite() {
-// TestSuite suite = new TestSuite();
-// suite.addTest(new HistoryStoreTest("testSimultaneousStates"));
-// return suite;
- return new TestSuite(HistoryStoreTest.class);
-}
-protected void tearDown() throws Exception {
- super.tearDown();
- wipeHistoryStore();
-}
-private int numBytes (InputStream input) {
- int i = 0;
- int c = -1;
- try {
- c = input.read();
- while (c != -1) {
- i++;
- c = input.read();
- }
- } catch (IOException e) {
- i = 0;
- }
- if (c != -1)
- i = 0;
- return i;
-}
-/**
- * Test the various policies in place to ensure that the history store
- * does not grow to unmanageable size. The policies currently in place
- * include:
- * - store only a maximum number of states for each file
- * - do not store files greater than some stated size
- * - consider history store information stale after some specified period
- * of time and discard stale data
- *
- * History store states are always stored in order from the newest state to
- * the oldest state. This will be tested as well
- *
- * Scenario:
- * 1. Create project AddStateAndPoliciesProject
- * 2. Create file (file.txt) random contents
- * 3. Set policy information in the workspace description as follows:
- * - don't store states older than 1 day
- * - keep a maximum of 5 states per file
- * - file states must be less than 1 Mb
- * 4. Make 8 modifications to file.txt (causing 8 states to be created)
- * 5. Ensure only 5 states were kept.
- * 6. Ensure states are in order from newest to oldest.
- * 7. Set policy such that file states must be no greater than 7 bytes.
- * 8. Create a new file file1.txt
- * 9. Add 10 bytes of data to this file.
- * 10. Check each of the states for this file and ensure they are not
- * greater than 7 bytes.
- * 11. Revert to policy in #3
- * 12. Make sure we still have 5 states for file.txt (the first file we
- * worked with)
- * 13. Change the policy so that data older than 10 seconds is stale.
- * 14. Wait 12 seconds (make it longer than 10 seconds to ensure we don't
- * encounter granularity issues).
- * 15. Check file states. There should be none left.
- */
-public void testAddStateAndPolicies() {
-
- /* Create common objects. */
- IProject project = getWorkspace().getRoot().getProject("Project");
- IFile file = project.getFile("file.txt");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- file.create(getRandomContents(), true, getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- /* set local history policies */
- // keep orignal
- IWorkspaceDescription originalDescription = getWorkspace().getDescription();
- // get another copy for changes
- IWorkspaceDescription description = getWorkspace().getDescription();
- // longevity set to 1 day
- description.setFileStateLongevity(1000 * 3600 * 24);
- // keep a max of 5 file states
- description.setMaxFileStates(5);
- // max size of file = 1 Mb
- description.setMaxFileStateSize(1024 * 1024);
- try {
- getWorkspace().setDescription(description);
- } catch (CoreException e) {
- fail("0.1", e);
- }
-
- /* test max file states */
- for (int i = 0; i < 8; i++) {
- try {
- ensureOutOfSync(file);
- file.refreshLocal(IResource.DEPTH_ZERO, getMonitor());
- file.setContents(getRandomContents(), true, true, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
- }
- IFileState[] states = null;
- try {
- getWorkspace().save(true, null);
- states = file.getHistory(getMonitor());
- } catch (CoreException e) {
- fail("1.1", e);
- }
- // We added 8 states. Make sure we only have 5 (the max).
- assertEquals("1.2", description.getMaxFileStates(), states.length);
-
- // assert that states are in the correct order (newer ones first)
- long lastModified = states[0].getModificationTime();
- for (int i = 1; i < states.length; i++) {
- assertTrue("1.3", lastModified > states[i].getModificationTime());
- lastModified = states[i].getModificationTime();
- }
-
- /* test max file state size */
- description.setMaxFileStates(15);
- // max size of file = 7 bytes
- description.setMaxFileStateSize(7);
- try {
- getWorkspace().setDescription(description);
- } catch (CoreException e) {
- fail("2.0.0", e);
- }
- file = project.getFile("file1.txt");
- try {
- file.create(new ByteArrayInputStream(new byte[0]), true, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
- // Add 10 bytes to exceed the max file state size.
- for (int i = 0; i < 10; i++) {
- try {
- file.appendContents(getContents("a"), true, true, getMonitor());
- } catch (CoreException e) {
- fail("2.1", e);
- }
- }
- try {
- getWorkspace().save(true, null);
- states = file.getHistory(getMonitor());
- // #states = size + 1 for the 0 byte length file to begin with.
- for (int i = 0; i < states.length; i++) {
- int bytesRead = numBytes(states[i].getContents());
- assertTrue("2.2." + i, bytesRead <= description.getMaxFileStateSize());
- }
- } catch (CoreException e) {
- fail("2.3", e);
- }
-
- /* test max file longevity */
- // use the file of the first test
- file = project.getFile("file.txt");
- // 1 day
- description.setFileStateLongevity(1000 * 3600 * 24);
- description.setMaxFileStates(5);
- // 1 Mb
- description.setMaxFileStateSize(1024 * 1024);
- // the description should be the same as the first test
- try {
- getWorkspace().setDescription(description);
- } catch (CoreException e) {
- fail("3.0", e);
- }
- try {
- states = file.getHistory(getMonitor());
- // Make sure we have 5 states for file file.txt
- assertEquals("3.3", description.getMaxFileStates(), states.length);
- } catch (CoreException e) {
- fail("3.2", e);
- }
- // change policies
- // 10 seconds
- description.setFileStateLongevity(1000 * 10);
- // 1 Mb
- description.setMaxFileStateSize(1024 * 1024);
- try {
- getWorkspace().setDescription(description);
- } catch (CoreException e) {
- fail("3.3", e);
- }
- try {
- // sleep for more than 10 seconds (the granularity varies on
- // some machines so we will sleep for 12 seconds)
- Thread.sleep(1000 * 12);
- } catch (InterruptedException e) {
- }
- try {
- getWorkspace().save(true, null);
- states = file.getHistory(getMonitor());
- // The 5 states for file.txt should have exceeded their longevity
- // and been removed. Make sure we have 0 states left.
- assertEquals("3.4", 0, states.length);
- } catch (CoreException e) {
- fail("3.5", e);
- }
-
- /* remove garbage */
- try {
- project.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("20.0", e);
- }
- try {
- getWorkspace().setDescription(originalDescription);
- } catch (CoreException e) {
- fail("20.1", e);
- }
-}
-
-/*
- * Test the functionality in store.clean() which is called to ensure
- * the history store to ensure that the history store does not grow to
- * unmanageable size. The policies currently in place include:
- * - store only a maximum number of states for each file
- * - do not store files greater than some stated size
- * - consider history store information stale after some specified period
- * of time and discard stale data
- *
- */
-public void testClean() {
-
- /* Create common objects. */
- IProject project = getWorkspace().getRoot().getProject("Project");
- IFile file = project.getFile("file.txt");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- file.create(getRandomContents(), true, getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
- HistoryStore store = ((Workspace) getWorkspace()).getFileSystemManager().getHistoryStore();
- // keep orignal
- IWorkspaceDescription originalDescription = getWorkspace().getDescription();
- // get another copy for changes
- IWorkspaceDescription description = getWorkspace().getDescription();
-
- /* test max file states */
- // 1 day
- description.setFileStateLongevity(1000 * 3600 * 24);
- // 500 states per file max.
- description.setMaxFileStates(500);
- // 1Mb max size
- description.setMaxFileStateSize(1024 * 1024);
- try {
- getWorkspace().setDescription(description);
- } catch (CoreException e) {
- fail("0.1", e);
- }
-
- // Set up 8 file states for this file when 500 are allowed
- for (int i = 0; i < 8; i++) {
- try {
- ensureOutOfSync(file);
- file.refreshLocal(IResource.DEPTH_ZERO, getMonitor());
-// try {
-// Thread.sleep(5000); // necessary because of lastmodified granularity in some file systems
-// } catch (InterruptedException e) {
-// }
- file.setContents(getRandomContents(), true, true, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
- }
- // All 8 states should exist.
- long oldLastModTimes[] = new long[8];
- try {
- IFileState[] states = file.getHistory(getMonitor());
- assertEquals("1.1", 8, states.length);
- for (int i = 0; i < 8; i++) {
- oldLastModTimes[i] = states[i].getModificationTime();
- }
- } catch (CoreException e) {
- fail("1.2", e);
- }
-
- // Set max. number of file states to be 3
- description.setMaxFileStates(3);
- try {
- getWorkspace().setDescription(description);
- } catch (CoreException e) {
- fail("2.0", e);
- }
- // Run 'clean' - should cause 5 of 8 states to be removed
- store.clean();
- // Restore max. number of states/file to 500
- description.setMaxFileStates(500);
- try {
- getWorkspace().setDescription(description);
- } catch (CoreException e) {
- fail("2.2", e);
- }
-
- // Check to ensure only 3 states remain. Make sure these are the 3
- // newer states.
- try {
- IFileState[] states = file.getHistory(getMonitor());
- assertEquals("2.3", 3, states.length);
- // assert that states are in the correct order (newer ones first)
- long lastModified = states[0].getModificationTime();
- for (int i = 1; i < states.length; i++) {
- assertTrue("2.4." + i, lastModified > states[i].getModificationTime());
- lastModified = states[i].getModificationTime();
- }
- // Make sure we kept the 3 newer states.
- for (int i = 0; i < states.length; i++) {
- assertTrue("2.5." + i, oldLastModTimes[i] == states[i].getModificationTime());
- }
- } catch (CoreException e) {
- fail("2.6", e);
- }
-
- /* test max file longevity */
- file = project.getFile("file.txt"); // use the file of the first test
- description.setFileStateLongevity(1000 * 3600 * 24); // 1 day
- description.setMaxFileStates(500);
- description.setMaxFileStateSize(1024 * 1024); // 1 Mb
- // the description should be the same as the first test
- try {
- getWorkspace().setDescription(description);
- } catch (CoreException e) {
- fail("3.0", e);
- }
- try {
- IFileState[] states = file.getHistory(getMonitor());
- assertEquals("3.1", 3, states.length);
- } catch (CoreException e) {
- fail("3.2", e);
- }
- // change policies
- // 10 seconds
- description.setFileStateLongevity(1000 * 10);
- // 1 Mb
- description.setMaxFileStateSize(1024 * 1024);
- try {
- getWorkspace().setDescription(description);
- } catch (CoreException e) {
- fail("4.0", e);
- }
- try {
- // sleep for 12 seconds (must exceed 10 seconds). This should
- // cause all 3 states for file.txt to be considered stale.
- Thread.sleep(1000 * 12);
- } catch (InterruptedException e) {
- }
- store.clean();
- // change policies - restore to original values
- // 1 day
- description.setFileStateLongevity(1000 * 3600 * 24);
- // 1 Mb
- description.setMaxFileStateSize(1024 * 1024);
- try {
- getWorkspace().setDescription(description);
- } catch (CoreException e) {
- fail("5.0", e);
- }
- // Ensure we have no state information left. It should have been
- // considered stale.
- try {
- IFileState[] states = file.getHistory(getMonitor());
- assertEquals("5.1", 0, states.length);
- } catch (CoreException e) {
- fail("5.2", e);
- }
-
- /* remove garbage */
- try {
- project.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("20.0", e);
- }
- try {
- getWorkspace().setDescription(originalDescription);
- } catch (CoreException e) {
- fail("20.1", e);
- }
-}
-/**
- * Test for existence of file states in the HistoryStore.
- */
-public void testExists() throws Throwable {
-
- /* Create common objects. */
- IProject project = getWorkspace().getRoot().getProject("Project");
- IFile file = project.getFile("removeAllStatesFile.txt");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- file.create(getRandomContents(), true, getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- // Constant for the number of states we will create
- final int ITERATIONS = 20;
-
- /* Add multiple states for one file location. */
- for (int i = 0; i < ITERATIONS; i++) {
- try {
- file.setContents(getRandomContents(), true, true, getMonitor());
- } catch (CoreException e) {
- fail("3.0." + i, e);
- }
- }
-
- /* Valid Case: Test retrieved values. */
- IFileState[] states = null;
- try {
- states = file.getHistory(getMonitor());
- } catch (CoreException e) {
- fail("5.0", e);
- }
- // Make sure we have ITERATIONS number of states
- assertTrue("5.1", states.length == ITERATIONS);
- // Make sure that each of these states really exists in the filesystem.
- for (int i = 0; i < states.length; i++)
- assertTrue("5.2." + i, states[i].exists());
-
- /* remove garbage */
- try {
- project.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("20.0", e);
- }
-}
-/**
- * Test for retrieving contents of files with states logged in the HistoryStore.
- */
-public void testGetContents() throws Throwable {
-
- final int ITERATIONS = 20;
-
- /* Create common objects. */
- IProject project = getWorkspace().getRoot().getProject("Project");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- /* Create files. */
- IFile file = project.getFile("getContentsFile.txt");
- String contents = "This file has some contents in testGetContents.";
- ensureExistsInWorkspace(file, contents);
-
- IFile secondValidFile = project.getFile("secondGetContentsFile.txt");
- contents = "A file with some other contents in testGetContents.";
- ensureExistsInWorkspace(secondValidFile, contents);
-
- HistoryStore historyStore = ((Workspace) getWorkspace()).getFileSystemManager().getHistoryStore();
-
- /* Simulated date -- Increment once for each edition added. */
- long myLong = 0L;
-
- /* Add multiple editions for one file location. */
- for (int i = 0; i < ITERATIONS; i++, myLong++) {
- historyStore.addState(file.getFullPath(), file.getLocation(), myLong, true);
- try {
- contents = "This file has some contents in testGetContents.";
- InputStream is = new ByteArrayInputStream(contents.getBytes());
- createFileInFileSystem(file.getLocation(), is);
- file.refreshLocal(IResource.DEPTH_INFINITE, null);
- } catch (CoreException e) {
- fail("1.1." + i, e);
- } catch (IOException e) {
- fail("1.2." + i, e);
- }
- }
-
- /* Add multiple editions for second file location. */
- for (int i = 0; i < ITERATIONS; i++, myLong++) {
- historyStore.addState(secondValidFile.getFullPath(), secondValidFile.getLocation(), myLong, true);
- try {
- contents = "A file with some other contents in testGetContents.";
- InputStream is = new ByteArrayInputStream(contents.getBytes());
- createFileInFileSystem(secondValidFile.getLocation(), is);
- secondValidFile.refreshLocal(IResource.DEPTH_INFINITE, null);
- } catch (CoreException e) {
- fail("2.1." + i, e);
- } catch (IOException e) {
- fail("2.2." + i, e);
- }
- }
-
- /* Ensure contents of file and retrieved resource are identical.
- Does not check timestamps. Timestamp checks are performed in a separate test. */
- DataInputStream inFile = null;
- DataInputStream inContents = null;
- IFileState[] stateArray = null;
- stateArray = historyStore.getStates(file.getFullPath());
- for (int i = 0; i < stateArray.length; i++, myLong++) {
- inFile = new DataInputStream(file.getContents(false));
- try {
- inContents = new DataInputStream(historyStore.getContents(stateArray[i]));
- } catch (CoreException e) {
- fail("3.1." + i, e);
- }
- if (!compareContent(inFile, inContents))
- fail("3.2." + i + " No match, files are not identical.");
- }
-
- stateArray = historyStore.getStates(secondValidFile.getFullPath());
- for (int i = 0; i < stateArray.length; i++, myLong++) {
- inFile = new DataInputStream(secondValidFile.getContents(false));
- try {
- inContents = new DataInputStream(historyStore.getContents(stateArray[i]));
- } catch (CoreException e) {
- fail("4.1." + i, e);
- }
- if (!compareContent(inFile, inContents))
- fail("4.2." + i + " No match, files are not identical.");
- }
-
- /* Test getting an invalid file state. */
- for (int i = 0; i < ITERATIONS; i++) {
- // Create bogus FileState using invalid uuid.
- try {
- InputStream in = historyStore.getContents(new FileState(historyStore, Path.ROOT, myLong, new UniversalUniqueIdentifier()));
- in.close();
- fail("6." + i + " Edition should be invalid.");
- } catch (CoreException e) {
- }
- }
-
- /* Test verification using null file state. */
- for (int i = 0; i < ITERATIONS; i++) {
- try {
- historyStore.getContents(null);
- fail("7." + i + " Null edition should be invalid.");
- } catch (RuntimeException e) {
- }
- }
-
- /* remove garbage */
- try {
- project.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("20.0", e);
- }
-}
-public void testRemoveAll() {
-
- /* Create common objects. */
- IProject project = getWorkspace().getRoot().getProject("Project");
- IFile file = project.getFile("removeAllStatesFile.txt");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- file.create(getRandomContents(), true, getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
- final int ITERATIONS = 20;
-
- /* test remove in a file */
- for (int i = 0; i < ITERATIONS; i++) {
- try {
- file.setContents(getRandomContents(), true, true, getMonitor());
- } catch (CoreException e) {
- fail("3.0." + i, e);
- }
- }
-
- /* Valid Case: Ensure correct number of states available. */
- IFileState[] states = null;
- try {
- states = file.getHistory(getMonitor());
- } catch (CoreException e) {
- fail("4.0", e);
- }
- assertTrue("4.1", states.length == ITERATIONS);
-
- /* Remove all states, and verify that no states remain. */
- try {
- file.clearHistory(getMonitor());
- states = file.getHistory(getMonitor());
- assertEquals("5.0", 0, states.length);
- } catch (CoreException e) {
- fail("5.1", e);
- }
-
- /* test remove in a folder -- make sure it does not affect other resources' states*/
- IFolder folder = project.getFolder("folder");
- IFile anotherOne = folder.getFile("anotherOne");
- try {
- folder.create(true, true, getMonitor());
- anotherOne.create(getRandomContents(), true, getMonitor());
- } catch (CoreException e) {
- fail("6.0", e);
- }
- for (int i = 0; i < ITERATIONS; i++) {
- try {
- file.setContents(getRandomContents(), true, true, getMonitor());
- anotherOne.setContents(getRandomContents(), true, true, getMonitor());
- } catch (CoreException e) {
- fail("6.1." + i, e);
- }
- }
-
- try {
- states = file.getHistory(getMonitor());
- assertEquals("6.2", ITERATIONS, states.length);
- states = anotherOne.getHistory(getMonitor());
- assertEquals("6.3", ITERATIONS, states.length);
- } catch (CoreException e) {
- fail("6.4", e);
- }
-
- /* Remove all states, and verify that no states remain. */
- try {
- project.clearHistory(getMonitor());
- states = file.getHistory(getMonitor());
- assertEquals("7.0", 0, states.length);
- states = anotherOne.getHistory(getMonitor());
- assertEquals("7.1", 0, states.length);
- } catch (CoreException e) {
- fail("7.2", e);
- }
-
- /* test remove in a folder -- make sure it does not affect other resources' states*/
- IFile aaa = project.getFile("aaa");
- IFolder bbb = project.getFolder("bbb");
- anotherOne = bbb.getFile("anotherOne");
- IFile ccc = project.getFile("ccc");
- try {
- bbb.create(true, true, getMonitor());
- anotherOne.create(getRandomContents(), true, getMonitor());
- aaa.create(getRandomContents(), true, getMonitor());
- ccc.create(getRandomContents(), true, getMonitor());
- } catch (CoreException e) {
- fail("8.0", e);
- }
- for (int i = 0; i < ITERATIONS; i++) {
- try {
- anotherOne.setContents(getRandomContents(), true, true, getMonitor());
- aaa.setContents(getRandomContents(), true, true, getMonitor());
- ccc.setContents(getRandomContents(), true, true, getMonitor());
- } catch (CoreException e) {
- fail("8.1." + i, e);
- }
- }
-
- try {
- states = anotherOne.getHistory(getMonitor());
- assertEquals("8.3", ITERATIONS, states.length);
- states = aaa.getHistory(getMonitor());
- assertEquals("8.4", ITERATIONS, states.length);
- states = ccc.getHistory(getMonitor());
- assertEquals("8.5", ITERATIONS, states.length);
- } catch (CoreException e) {
- fail("8.6", e);
- }
-
- /* Remove all states, and verify that no states remain. aaa and ccc should not be affected. */
- try {
- bbb.clearHistory(getMonitor());
- states = anotherOne.getHistory(getMonitor());
- assertEquals("9.1", 0, states.length);
- states = aaa.getHistory(getMonitor());
- assertEquals("9.2", ITERATIONS, states.length);
- states = ccc.getHistory(getMonitor());
- assertEquals("9.3", ITERATIONS, states.length);
- } catch (CoreException e) {
- fail("9.4", e);
- }
-
- /* remove garbage */
- try {
- project.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("20.0", e);
- }
-}
-/**
- * Simple use case for History Store.
- *
- * Scenario: # Editions
- * 1. Create file "content 1" 0
- * 2. Set new content "content 2" 1
- * 3. Set new content "content 3" 2
- * 4. Delete file 3
- * 5. Roll back to first version "content 1" 3
- * 6. Set new content "content 2" 4
- * 7. Roll back to third version "content 3" 5
- */
-public void testSimpleUse() {
-
- /* Initialize common objects. */
- IProject project = getWorkspace().getRoot().getProject("Project");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
- String[] contents = { "content1", "content2", "content3" };
- IFile file = project.getFile("file");
-
- /* Create the file. */
- try {
- file.create(getContents(contents[0]), true, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- /* Set new contents on the file. Should add two entries to the store. */
- try {
- for (int i = 0; i < 2; i++)
- file.setContents(getContents(contents[i + 1]), true, true, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- /* Ensure two entries are available for the file, and that content matches. */
- try {
- IFileState[] states = file.getHistory(getMonitor());
- assertEquals("3.0", 2, states.length);
- assertTrue("3.1.1", compareContent(getContents(contents[1]), states[0].getContents()));
- assertTrue("3.1.2", compareContent(getContents(contents[0]), states[1].getContents()));
- } catch (CoreException e) {
- fail("3.2", e);
- }
-
- /* Delete the file. Should add an entry to the store. */
- try {
- file.delete(true, true, getMonitor());
- } catch (CoreException e) {
- fail("4.0", e);
- }
-
- /* Ensure three entries are available for the file, and that content matches. */
- try {
- IFileState[] states = file.getHistory(getMonitor());
- assertEquals("5.0", 3, states.length);
- assertTrue("5.1.1", compareContent(getContents(contents[2]), states[0].getContents()));
- assertTrue("5.1.2", compareContent(getContents(contents[1]), states[1].getContents()));
- assertTrue("5.1.3", compareContent(getContents(contents[0]), states[2].getContents()));
- } catch (CoreException e) {
- fail("5.2", e);
- }
-
- /* Roll file back to first version, and ensure that content matches. */
- try {
- IFileState[] states = file.getHistory(getMonitor());
- // Create the file with the contents from one of the states.
- // Won't add another entry to the store.
- file.create(states[0].getContents(), false, getMonitor());
-
- // Check history store.
- states = file.getHistory(getMonitor());
- assertEquals("6.0", 3, states.length);
- assertTrue("6.1.1", compareContent(getContents(contents[2]), states[0].getContents()));
- assertTrue("6.1.2", compareContent(getContents(contents[1]), states[1].getContents()));
- assertTrue("6.1.3", compareContent(getContents(contents[0]), states[2].getContents()));
-
- // Check file contents.
- assertTrue("6.2", compareContent(getContents(contents[2]), file.getContents(false)));
-
- } catch (CoreException e) {
- fail("6.3", e);
- }
-
- /* Set new contents on the file. Should add an entry to the history store. */
- try {
- file.setContents(getContents(contents[1]), true, true, null);
- } catch (CoreException e) {
- fail("7.0", e);
- }
-
- /* Ensure four entries are available for the file, and that entries match. */
- try {
- IFileState[] states = file.getHistory(getMonitor());
- assertEquals("8.0", 4, states.length);
- assertTrue("8.1.1", compareContent(getContents(contents[2]), states[0].getContents()));
- assertTrue("8.1.2", compareContent(getContents(contents[2]), states[1].getContents()));
- assertTrue("8.1.3", compareContent(getContents(contents[1]), states[2].getContents()));
- assertTrue("8.1.4", compareContent(getContents(contents[0]), states[3].getContents()));
- } catch (CoreException e) {
- fail("8.2", e);
- }
-
- /* Roll file back to third version, and ensure that content matches. */
- try {
- IFileState[] states = file.getHistory(getMonitor());
- // Will add another entry to log.
- file.setContents(states[2], true, true, getMonitor());
-
- // Check history log.
- states = file.getHistory(getMonitor());
- assertEquals("9.0", 5, states.length);
- assertTrue("9.1.1", compareContent(getContents(contents[1]), states[0].getContents()));
- assertTrue("9.1.2", compareContent(getContents(contents[2]), states[1].getContents()));
- assertTrue("9.1.3", compareContent(getContents(contents[2]), states[2].getContents()));
- assertTrue("9.1.4", compareContent(getContents(contents[1]), states[3].getContents()));
- assertTrue("9.1.5", compareContent(getContents(contents[0]), states[4].getContents()));
-
- // Check file contents.
- assertTrue("9.2", compareContent(getContents(contents[1]), file.getContents(false)));
-
- } catch (CoreException e) {
- fail("9.3", e);
- }
-
- /* remove garbage */
- try {
- project.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("20.0", e);
- }
-}
-public void testDelete() {
- // create common objects
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- // test file
- IFile file = project.getFile("file.txt");
- try {
- file.create(getRandomContents(), true, getMonitor());
- file.setContents(getRandomContents(), true, true, getMonitor());
- file.setContents(getRandomContents(), true, true, getMonitor());
-
- // Check to see that there are only 2 states before the deletion
- IFileState[] states = file.getHistory(getMonitor());
- assertEquals("1.0", 2, states.length);
-
- // Delete the file. This should add a state to the history store.
- file.delete(true, true, getMonitor());
- states = file.getHistory(getMonitor());
- assertEquals("1.1", 3, states.length);
-
- // Re-create the file. This should not affect the history store.
- file.create(getRandomContents(), true, getMonitor());
- states = file.getHistory(getMonitor());
- assertEquals("1.2", 3, states.length);
- } catch (CoreException e) {
- fail("1.20", e);
- }
-
- // test folder
- IFolder folder = project.getFolder("folder");
- // Make sure this has a different name as the history store information
- // for the first 'file.txt' is likely still around.
- file = folder.getFile("file2.txt");
- try {
- folder.create(true, true, getMonitor());
- file.create(getRandomContents(), true, getMonitor());
- file.setContents(getRandomContents(), true, true, getMonitor());
- file.setContents(getRandomContents(), true, true, getMonitor());
-
- // There should only be 2 history store entries.
- IFileState[] states = file.getHistory(getMonitor());
- assertEquals("2.0", 2, states.length);
-
- // Delete the folder. This should cause one more history store entry.
- folder.delete(true, true, getMonitor());
- states = file.getHistory(getMonitor());
- assertEquals("2.1", 3, states.length);
-
- // Re-create the folder. There should be no new history store entries.
- folder.create(true, true, getMonitor());
- file.create(getRandomContents(), true, getMonitor());
- states = file.getHistory(getMonitor());
- assertEquals("2.2", 3, states.length);
- } catch (CoreException e) {
- fail("2.20", e);
- }
-
- try {
- project.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("20.0", e);
- }
-}
-
-public void testFindDeleted() {
- // create common objects
- IWorkspaceRoot root = getWorkspace().getRoot();
- IProject project = root.getProject("MyProject");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
-
- IFile[] df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("0.1", 0, df.length);
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- // test that a deleted file can be found
- IFile pfile = project.getFile("findDeletedFile.txt");
- try {
- // create and delete a file
- pfile.create(getRandomContents(), true, getMonitor());
- pfile.delete(true, true, getMonitor());
-
- // the deleted file should show up as a deleted member of project
- IFile[] df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("0.1", 1, df.length);
- assertEquals("0.2", pfile, df[0]);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("0.3", 1, df.length);
- assertEquals("0.4", pfile, df[0]);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("0.5", 0, df.length);
-
- // the deleted file should show up as a deleted member of workspace root
- df = root.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("0.5.1", 0, df.length);
-
- df = root.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("0.5.2", 1, df.length);
- assertEquals("0.5.3", pfile, df[0]);
-
- df = root.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("0.5.4", 0, df.length);
-
- // recreate the file
- pfile.create(getRandomContents(), true, getMonitor());
-
- // the deleted file should no longer show up as a deleted member of project
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("0.6", 0, df.length);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("0.7", 0, df.length);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("0.8", 0, df.length);
-
- // the deleted file should no longer show up as a deleted member of ws root
- df = root.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("0.8.1", 0, df.length);
-
- df = root.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("0.8.2", 0, df.length);
-
- df = root.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("0.8.3", 0, df.length);
-
- } catch (CoreException e) {
- fail("0.00", e);
- }
-
- // scrub the project
- try {
- project.delete(true, getMonitor());
- project.create(getMonitor());
- project.open(getMonitor());
-
- IFile[] df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("0.9", 0, df.length);
- } catch (CoreException e) {
- fail("0.10", e);
- }
-
- // test folder
- IFolder folder = project.getFolder("folder");
- IFile file = folder.getFile("filex.txt");
- IFile folderAsFile = project.getFile(folder.getProjectRelativePath());
- try {
- // create and delete a file in a folder
- folder.create(true, true, getMonitor());
- file.create(getRandomContents(), true, getMonitor());
- file.delete(true, true, getMonitor());
-
- // the deleted file should show up as a deleted member
- IFile[] df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("1.1", 0, df.length);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("1.2", 1, df.length);
- assertEquals("1.3", file, df[0]);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("1.4", 0, df.length);
-
- // recreate the file
- file.create(getRandomContents(), true, getMonitor());
-
- // the deleted file should no longer show up as a deleted member
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("1.5", 0, df.length);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("1.6", 0, df.length);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("1.7", 0, df.length);
-
- // deleting the folder should bring it back
- folder.delete(true, true, getMonitor());
-
- // the deleted file should show up as a deleted member of project
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("1.8", 0, df.length);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("1.9", 1, df.length);
- assertEquals("1.10", file, df[0]);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("1.11", 0, df.length);
-
- // create and delete a file where the folder was
- folderAsFile.create(getRandomContents(), true, getMonitor());
- folderAsFile.delete(true, true, getMonitor());
- folder.create(true, true, getMonitor());
-
- // the deleted file should show up as a deleted member of folder
- df = folder.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("1.12", 1, df.length);
- assertEquals("1.13", folderAsFile, df[0]);
-
- df = folder.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("1.14", 2, df.length);
- List dfList = Arrays.asList(df);
- assertTrue("1.15", dfList.contains(file));
- assertTrue("1.16", dfList.contains(folderAsFile));
-
- df = folder.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("1.17", 2, df.length);
- dfList = Arrays.asList(df);
- assertTrue("1.18", dfList.contains(file));
- assertTrue("1.19", dfList.contains(folderAsFile));
-
-
- } catch (CoreException e) {
- fail("1.00", e);
- }
-
- // scrub the project
- try {
- project.delete(true, getMonitor());
- project.create(getMonitor());
- project.open(getMonitor());
-
- IFile[] df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("1.50", 0, df.length);
- } catch (CoreException e) {
- fail("1.51", e);
- }
-
- // test a bunch of deletes
- folder = project.getFolder("folder");
- IFile file1 = folder.getFile("file1.txt");
- IFile file2 = folder.getFile("file2.txt");
- IFolder folder2 = folder.getFolder("folder2");
- IFile file3 = folder2.getFile("file3.txt");
- try {
- // create and delete a file in a folder
- folder.create(true, true, getMonitor());
- folder2.create(true, true, getMonitor());
- file1.create(getRandomContents(), true, getMonitor());
- file2.create(getRandomContents(), true, getMonitor());
- file3.create(getRandomContents(), true, getMonitor());
- folder.delete(true, true, getMonitor());
-
- // under root
- IFile[] df = root.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("3.1", 0, df.length);
-
- df = root.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("3.2", 0, df.length);
-
- df = root.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("3.3", 3, df.length);
- List dfList = Arrays.asList(df);
- assertTrue("3.3.1", dfList.contains(file1));
- assertTrue("3.3.2", dfList.contains(file2));
- assertTrue("3.3.3", dfList.contains(file3));
-
- // under project
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("3.4", 0, df.length);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("3.5", 0, df.length);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("3.6", 3, df.length);
- dfList = Arrays.asList(df);
- assertTrue("3.6.1", dfList.contains(file1));
- assertTrue("3.6.2", dfList.contains(file2));
- assertTrue("3.6.3", dfList.contains(file3));
-
- // under folder
- df = folder.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("3.7", 0, df.length);
-
- df = folder.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("3.8", 2, df.length);
-
- df = folder.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("3.9", 3, df.length);
-
- // under folder2
- df = folder2.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("3.10", 0, df.length);
-
- df = folder2.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("3.11", 1, df.length);
-
- df = folder2.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("3.12", 1, df.length);
-
- } catch (CoreException e) {
- fail("3.00", e);
- }
-
- try {
- project.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("3.5", e);
- }
-
- // once the project is gone, so is all the history for that project
- try {
- // under root
- IFile[] df = root.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("4.1", 0, df.length);
-
- df = root.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("4.2", 0, df.length);
-
- df = root.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("4.3", 0, df.length);
-
-
- // under project
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("4.4", 0, df.length);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("4.5", 0, df.length);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("4.6", 0, df.length);
-
- // under folder
- df = folder.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("4.7", 0, df.length);
-
- df = folder.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("4.8", 0, df.length);
-
- df = folder.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("4.9", 0, df.length);
-
- // under folder2
- df = folder2.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("4.10", 0, df.length);
-
- df = folder2.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("4.11", 0, df.length);
-
- df = folder2.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("4.12", 0, df.length);
-
- } catch (CoreException e) {
- fail("4.00", e);
- }
-}
-
-/**
- * Simple move case for History Store when the local history is being
- * copied.
- *
- * Scenario:
- * 1. Create file "content 1"
- * 2. Set new content "content 2"
- * 3. Set new content "content 3"
- * 4. Move file
- * 5. Set new content to moved file "content 4"
- * 6. Set new content to moved file "content 5"
- *
- * The original file should have two states available.
- * But the moved file should have 4 states as it retains the states from
- * before the move took place as well.
- */
-public void testSimpleMove() {
-
- /* Initialize common objects. */
- IProject project = getWorkspace().getRoot().getProject("SimpleMoveProject");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
- String[] contents = { "content1", "content2", "content3", "content4",
- "content5" };
- IFile file = project.getFile("simpleMoveFileWithCopy");
- IFile moveFile = project.getFile("copyOfSimpleMoveFileWithCopy");
-
- /* Create first file. */
- try {
- file.create(getContents(contents[0]), true, null);
- } catch (CoreException e) {
- fail("1.2", e);
- }
-
- /* Set new contents on source file. Should add two entries to the history store. */
- try {
- file.setContents(getContents(contents[1]), true, true, null);
- file.setContents(getContents(contents[2]), true, true, null);
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- /* Move source file to second location.
- * Moved files should have the history of the original file.
- */
- try {
- file.move(moveFile.getFullPath(),true, null);
- } catch (CoreException e) {
- fail("3.0", e);
- }
-
- /* Check history for both files. */
- try {
- IFileState[] states = file.getHistory(null);
- assertEquals("4.0", 2, states.length);
- states = moveFile.getHistory(null);
- assertEquals("4.1", 2, states.length);
- } catch (CoreException e) {
- fail("4.2", e);
- }
-
- /* Set new contents on moved file. Should add two entries to the history store. */
- try {
- moveFile.setContents(getContents(contents[3]), true, true, null);
- moveFile.setContents(getContents(contents[4]), true, true, null);
- } catch (CoreException e) {
- fail("5.0", e);
- }
-
- /* Check history for both files. */
- try {
- // Check log for original file.
- IFileState[] states = file.getHistory(null);
- assertEquals("6.0", 2, states.length);
- assertTrue("6.1", compareContent(getContents(contents[1]), states[0].getContents()));
- assertTrue("6.2", compareContent(getContents(contents[0]), states[1].getContents()));
-
- // Check log for moved file.
- states = moveFile.getHistory(null);
- assertEquals("6.3", 4, states.length);
- assertTrue("6.4", compareContent(getContents(contents[3]), states[0].getContents()));
- assertTrue("6.5", compareContent(getContents(contents[2]), states[1].getContents()));
- assertTrue("6.6", compareContent(getContents(contents[1]), states[2].getContents()));
- assertTrue("6.7", compareContent(getContents(contents[0]), states[3].getContents()));
-
- } catch (CoreException e) {
- fail("6.8", e);
- }
-
- /* remove garbage */
- try {
- project.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("7.0", e);
- }
-}
-
-/**
- * Simple copy case for History Store when the local history is being
- * copied.
- *
- * Scenario:
- * 1. Create file "content 1"
- * 2. Set new content "content 2"
- * 3. Set new content "content 3"
- * 4. Move file
- * 5. Set new content to copied file "content 4"
- * 6. Set new content to copied file "content 5"
- *
- * The original file should have two states available.
- * But the copied file should have 4 states as it retains the states from
- * before the copy took place as well.
- */
-public void testSimpleCopy() {
-
- /* Initialize common objects. */
- IProject project = getWorkspace().getRoot().getProject("SimpleCopyProject");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
- String[] contents = {"content1", "content2", "content3", "content4",
- "content5"};
- IFile file = project.getFile("simpleCopyFileWithHistoryCopy");
- IFile copyFile = project.getFile("copyOfSimpleCopyFileWithHistoryCopy");
-
- /* Create first file. */
- try {
- file.create(getContents(contents[0]), true, null);
- } catch (CoreException e) {
- fail("1.2", e);
- }
-
- /* Set new contents on first file. Should add two entries to the history store. */
- try {
- file.setContents(getContents(contents[1]), true, true, null);
- file.setContents(getContents(contents[2]), true, true, null);
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- /* Copy first file to the second. Second file should have no history. */
- try {
- file.copy(copyFile.getFullPath(), true, null);
- } catch (CoreException e) {
- fail("3.0", e);
- }
-
- /* Check history for both files. */
- try {
- IFileState[] states = file.getHistory(null);
- assertEquals("4.0", 2, states.length);
- states = copyFile.getHistory(null);
- assertEquals("4.1", 2, states.length);
- } catch (CoreException e) {
- fail("4.2", e);
- }
-
- /* Set new contents on second file. Should add two entries to the history store. */
- try {
- copyFile.setContents(getContents(contents[3]), true, true, null);
- copyFile.setContents(getContents(contents[4]), true, true, null);
- } catch (CoreException e) {
- fail("5.0", e);
- }
-
- /* Check history for both files. */
- try {
- // Check log for original file.
- IFileState[] states = file.getHistory(null);
- assertEquals("6.0", 2, states.length);
- assertTrue("6.1", compareContent(getContents(contents[1]), states[0].getContents()));
- assertTrue("6.2", compareContent(getContents(contents[0]), states[1].getContents()));
-
- // Check log for copy.
- states = copyFile.getHistory(null);
- assertEquals("6.3", 4, states.length);
- assertTrue("6.4", compareContent(getContents(contents[3]), states[0].getContents()));
- assertTrue("6.5", compareContent(getContents(contents[2]), states[1].getContents()));
- assertTrue("6.6", compareContent(getContents(contents[1]), states[2].getContents()));
- assertTrue("6.7", compareContent(getContents(contents[0]), states[3].getContents()));
-
- } catch (CoreException e) {
- fail("6.8", e);
- }
-
-
- /* remove garbage */
- try {
- project.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("7.0", e);
- }
-}
-
-/**
- * Move case for History Store of folder when the local history is being
- * copied.
- *
- * Scenario:
- * 1. Create folder (folder1)
- * 2. Create file "content 1"
- * 3. Set new content "content 2"
- * 4. Set new content "content 3"
- * 5. Move folder
- * 6. Set new content to moved file "content 4"
- * 7. Set new content to moved file "content 5"
- *
- * The original file should have two states available.
- * But the moved file should have 4 states as it retains the states from
- * before the move took place as well.
- */
-public void testMoveFolder() {
- String[] contents = {"content1", "content2", "content3", "content4",
- "content5"};
- // create common objects
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- IFile file = project.getFile("file1.txt");
-
- IFolder folder = project.getFolder("folder1");
- IFolder folder2 = project.getFolder("folder2");
- file = folder.getFile("file1.txt");
- try {
- // Setup folder1 and file1.txt with some local history
- folder.create(true, true, getMonitor());
- file.create(getContents(contents[0]), true, getMonitor());
- file.setContents(getContents(contents[1]), true, true, getMonitor());
- file.setContents(getContents(contents[2]), true, true, getMonitor());
- IFileState[] states = file.getHistory(getMonitor());
- assertEquals("1.0", 2, states.length);
- assertTrue("1.1", compareContent(getContents(contents[1]), states[0].getContents()));
- assertTrue("1.2", compareContent(getContents(contents[0]), states[1].getContents()));
-
- // Now do the move
- folder.move(folder2.getFullPath(), true, getMonitor());
-
- // Check to make sure the file has been moved
- IFile file2 = folder2.getFile("file1.txt");
- assertTrue("1.3", file2.getFullPath().toString().endsWith("folder2/file1.txt"));
-
- // Give the new (moved file) some new contents
- file2.setContents(getContents(contents[3]), true, true, getMonitor());
- file2.setContents(getContents(contents[4]), true, true, getMonitor());
-
- // Check the local history of both files
- states = file.getHistory(getMonitor());
- assertEquals("2.0", 2, states.length);
- assertTrue("2.1", compareContent(getContents(contents[1]), states[0].getContents()));
- assertTrue("2.2", compareContent(getContents(contents[0]), states[1].getContents()));
- states = file2.getHistory(getMonitor());
- assertEquals("2.3", 4, states.length);
- assertTrue("2.4", compareContent(getContents(contents[3]), states[0].getContents()));
- assertTrue("2.5", compareContent(getContents(contents[2]), states[1].getContents()));
- assertTrue("2.6", compareContent(getContents(contents[1]), states[2].getContents()));
- assertTrue("2.7", compareContent(getContents(contents[0]), states[3].getContents()));
- } catch (CoreException e) {
- fail("2.8", e);
- }
-
- try {
- project.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
-}
-
-/**
- * Copy case for History Store of folder when the local history is being
- * copied.
- *
- * Scenario:
- * 1. Create folder (folder1)
- * 2. Create file "content 1"
- * 3. Set new content "content 2"
- * 4. Set new content "content 3"
- * 5. Copy folder
- * 6. Set new content to moved file "content 4"
- * 7. Set new content to moved file "content 5"
- *
- * The original file should have two states available.
- * But the copied file should have 4 states as it retains the states from
- * before the copy took place as well.
- */
-public void testCopyFolder() {
- String[] contents = {"content1", "content2", "content3", "content4",
- "content5"};
- // create common objects
- IProject project = getWorkspace().getRoot().getProject("CopyFolderProject");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- IFile file = project.getFile("file1.txt");
-
- IFolder folder = project.getFolder("folder1");
- IFolder folder2 = project.getFolder("folder2");
- file = folder.getFile("file1.txt");
- try {
- // Setup folder1 and file1.txt with some local history
- folder.create(true, true, getMonitor());
- file.create(getContents(contents[0]), true, getMonitor());
- file.setContents(getContents(contents[1]), true, true, getMonitor());
- file.setContents(getContents(contents[2]), true, true, getMonitor());
- IFileState[] states = file.getHistory(getMonitor());
- assertEquals("1.0", 2, states.length);
- assertTrue("1.1", compareContent(getContents(contents[1]), states[0].getContents()));
- assertTrue("1.2", compareContent(getContents(contents[0]), states[1].getContents()));
-
- // Now do the move
- folder.copy(folder2.getFullPath(), true, getMonitor());
-
- // Check to make sure the file has been copied
- IFile file2 = folder2.getFile("file1.txt");
- assertTrue("1.3", file2.getFullPath().toString().endsWith("folder2/file1.txt"));
-
- // Give the new (copied file) some new contents
- file2.setContents(getContents(contents[3]), true, true, getMonitor());
- file2.setContents(getContents(contents[4]), true, true, getMonitor());
-
- // Check the local history of both files
- states = file.getHistory(getMonitor());
- assertEquals("2.0", 2, states.length);
- assertTrue("2.1", compareContent(getContents(contents[1]), states[0].getContents()));
- assertTrue("2.2", compareContent(getContents(contents[0]), states[1].getContents()));
- states = file2.getHistory(getMonitor());
- assertEquals("2.3", 4, states.length);
- assertTrue("2.4", compareContent(getContents(contents[3]), states[0].getContents()));
- assertTrue("2.5", compareContent(getContents(contents[2]), states[1].getContents()));
- assertTrue("2.6", compareContent(getContents(contents[1]), states[2].getContents()));
- assertTrue("2.7", compareContent(getContents(contents[0]), states[3].getContents()));
- } catch (CoreException e) {
- fail("2.8", e);
- }
-
- try {
- project.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
-}
-
-/**
- * Move case for History Store of project. Note that local history is
- * NOT copied for a project move.
- *
- * Scenario:
- * 1. Create folder (folder1)
- * 2. Create file "content 1"
- * 2. Set new content "content 2"
- * 3. Set new content "content 3"
- * 4. Copy folder
- * 5. Set new content to moved file "content 4"
- * 6. Set new content to moved file "content 5"
- *
- * The original file should have two states available.
- * But the copied file should have 4 states as it retains the states from
- * before the copy took place as well.
- */
-public void testMoveProject() {
- String[] contents = {"content1", "content2", "content3", "content4",
- "content5"};
- // create common objects
- IProject project = getWorkspace().getRoot().getProject("MoveProjectProject");
- IProject project2 = getWorkspace().getRoot().getProject("SecondMoveProjectProject");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- IFile file = project.getFile("file1.txt");
-
- IFolder folder = project.getFolder("folder1");
- file = folder.getFile("file1.txt");
- try {
- // Setup folder1 and file1.txt with some local history
- folder.create(true, true, getMonitor());
- file.create(getContents(contents[0]), true, getMonitor());
- file.setContents(getContents(contents[1]), true, true, getMonitor());
- file.setContents(getContents(contents[2]), true, true, getMonitor());
- IFileState[] states = file.getHistory(getMonitor());
- assertEquals("1.0", 2, states.length);
- assertTrue("1.1", compareContent(getContents(contents[1]), states[0].getContents()));
- assertTrue("1.2", compareContent(getContents(contents[0]), states[1].getContents()));
-
- // Now do the move
- project.move(new Path("SecondMoveProjectProject"), true, getMonitor());
-
- // Check to make sure the file has been moved
- IFile file2 = project2.getFile("folder1/file1.txt");
- assertTrue("1.3", file2.getFullPath().toString().endsWith("SecondMoveProjectProject/folder1/file1.txt"));
-
- // Give the new (copied file) some new contents
- file2.setContents(getContents(contents[3]), true, true, getMonitor());
- file2.setContents(getContents(contents[4]), true, true, getMonitor());
-
- // Check the local history of both files
- states = file.getHistory(getMonitor());
- assertEquals("2.0", 2, states.length);
- assertTrue("2.1", compareContent(getContents(contents[1]), states[0].getContents()));
- assertTrue("2.2", compareContent(getContents(contents[0]), states[1].getContents()));
- states = file2.getHistory(getMonitor());
- assertEquals("2.3", 4, states.length);
- assertTrue("2.4", compareContent(getContents(contents[3]), states[0].getContents()));
- assertTrue("2.5", compareContent(getContents(contents[2]), states[1].getContents()));
- assertTrue("2.6", compareContent(getContents(contents[1]), states[2].getContents()));
- assertTrue("2.7", compareContent(getContents(contents[0]), states[3].getContents()));
- } catch (CoreException e) {
- fail("2.9", e);
- }
-
- try {
- project.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
-}
-/*
- * This little helper method makes sure that the history store is
- * completely clean after it is invoked. If a history store entry or
- * a file is left, it may become part of the history for another file in
- * another test (if this file has the same name).
- */
-private void wipeHistoryStore() {
- HistoryStore store = ((Workspace) getWorkspace()).getFileSystemManager().getHistoryStore();
- // Remove all the entries from the history store index. Note that
- // this does not cause the history store states to be removed.
- store.removeAll();
- // Now make sure all the states are really removed.
- store.removeGarbage();
-}
-
-/*
- * This test is designed to exercise the public API method
- * HistoryStore.copyHistory(). The following tests will be performed:
- * - give a null source path
- * - give a null destination path
- * - give the same path for source and destination
- * - give an invalid source path but a valid destination path
- * - give an invalid destination path but a valid source path
- */
-public void testCopyHistoryFile() {
- // Create a project, folder and file so we have some history store
- // Should have a project that appears as follows:
- // - project name TestCopyHistoryProject
- // - has one folder called folder1
- // - folder1 has one file called file1.txt
- // - file1.txt was created with initial data "content1"
- // - change data in file1.txt to be "content2"
- // - change data in file1.txt to be "content3"
- // As a result of the above, there should be 2 history store states for
- // file1.txt (one with "contents1" and the other with "contents2".
-
- String[] contents = {"content0", "content1", "content2", "content3", "content4"};
- // create common objects
- IProject project = getWorkspace().getRoot().getProject("TestCopyHistoryProject");
- ensureExistsInWorkspace(project, true);
-
- IFolder folder = project.getFolder("folder1");
- IFile file = folder.getFile("file1.txt");
- IFile file2 = folder.getFile("file2.txt");
- try {
- // Setup folder1 and file1.txt with some local history
- folder.create(true, true, getMonitor());
- file.create(getContents(contents[0]), true, getMonitor());
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- fail("0.0", e);
- }
- file.setContents(getContents(contents[1]), true, true, getMonitor());
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- fail("0.1", e);
- }
- file.setContents(getContents(contents[2]), true, true, getMonitor());
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- fail("0.2", e);
- }
- IFileState[] states = file.getHistory(getMonitor());
- assertEquals("1.0", 2, states.length);
- assertTrue("1.1", compareContent(getContents(contents[1]), states[0].getContents()));
- assertTrue("1.2", compareContent(getContents(contents[0]), states[1].getContents()));
- file2.create(getContents(contents[3]), true, getMonitor());
- file2.setContents(getContents(contents[4]), true, true, getMonitor());
- } catch (CoreException e) {
- fail("1.3", e);
- }
-
- // Run some tests with illegal arguments
- LogListenerVerifier verifier = new LogListenerVerifier();
- ILog log = ResourcesPlugin.getPlugin().getLog();
- log.addLogListener(verifier);
-
- // Test with null source and/or destination
- HistoryStore store = ((Resource) file).getLocalManager().getHistoryStore();
- verifier.addExpected(IResourceStatus.INTERNAL_ERROR);
- store.copyHistory(null, null);
- try {
- verifier.verify();
- } catch (VerificationFailedException e) {
- fail("1.4 ", e);
- }
- verifier.reset();
-
- verifier.addExpected(IResourceStatus.INTERNAL_ERROR);
- store.copyHistory(null, file2.getLocation());
- try {
- verifier.verify();
- } catch (VerificationFailedException e) {
- fail("1.5 ", e);
- }
- verifier.reset();
-
- verifier.addExpected(IResourceStatus.INTERNAL_ERROR);
- store.copyHistory(file.getLocation(), null);
- try {
- verifier.verify();
- } catch (VerificationFailedException e) {
- fail("1.6 ", e);
- }
- verifier.reset();
-
- // Try to copy the history store stuff to the same location
- verifier.addExpected(IResourceStatus.INTERNAL_ERROR);
- store.copyHistory(file.getLocation(), file.getLocation());
- try {
- verifier.verify();
- } catch (VerificationFailedException e) {
- fail("1.7 ", e);
- }
- verifier.reset();
-
- // Remember to remove the log listener now that we are done
- // testing illegal arguments.
- log.removeLogListener(verifier);
-
- // Test a valid copy of a file
- store.copyHistory(file.getFullPath(), file2.getFullPath());
- IFileState[] states = null;
- try {
- states = file2.getHistory(getMonitor());
- } catch (CoreException e) {
- fail("2.4");
- }
- assertEquals("2.4", 3, states.length);
- try {
- assertTrue("2.5", compareContent(getContents(contents[3]), states[0].getContents()));
- assertTrue("2.6", compareContent(getContents(contents[1]), states[1].getContents()));
- assertTrue("2.7", compareContent(getContents(contents[0]), states[2].getContents()));
- } catch (CoreException e) {
- fail("2.8");
- }
-}
-public void testCopyHistoryFolder() {
- String[] contents = {"content0", "content1", "content2", "content3", "content4"};
- // create common objects
- IProject project = getWorkspace().getRoot().getProject("TestCopyHistoryProject");
- ensureExistsInWorkspace(project, true);
-
- IFolder folder = project.getFolder("folder1");
- IFolder folder2 = project.getFolder("folder2");
- IFile file = folder.getFile("file1.txt");
- IFile file2 = folder2.getFile("file1.txt");
- try {
- // Setup folder1 and file1.txt with some local history
- folder.create(true, true, getMonitor());
- file.create(getContents(contents[0]), true, getMonitor());
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- fail("0.0", e);
- }
- file.setContents(getContents(contents[1]), true, true, getMonitor());
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- fail("0.1", e);
- }
- file.setContents(getContents(contents[2]), true, true, getMonitor());
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- fail("0.2", e);
- }
- IFileState[] states = file.getHistory(getMonitor());
- assertEquals("1.0", 2, states.length);
- assertTrue("1.1", compareContent(getContents(contents[1]), states[0].getContents()));
- assertTrue("1.2", compareContent(getContents(contents[0]), states[1].getContents()));
- folder2.create(true, true, getMonitor());
- file2.create(getContents(contents[3]), true, getMonitor());
- file2.setContents(getContents(contents[4]), true, true, getMonitor());
- } catch (CoreException e) {
- fail("1.9", e);
- }
-
- // Test a valid copy of a folder
- HistoryStore store = ((Resource) file).getLocalManager().getHistoryStore();
- store.copyHistory(folder.getFullPath(), folder2.getFullPath());
- IFileState[] states = null;
- try {
- states = file2.getHistory(getMonitor());
- } catch (CoreException e) {
- fail("2.4");
- }
- assertEquals("2.4", 3, states.length);
- try {
- assertTrue("2.5", compareContent(getContents(contents[3]), states[0].getContents()));
- assertTrue("2.6", compareContent(getContents(contents[1]), states[1].getContents()));
- assertTrue("2.7", compareContent(getContents(contents[0]), states[2].getContents()));
- } catch (CoreException e) {
- fail("2.8");
- }
-}
-public void testCopyHistoryProject() {
- String[] contents = {"content0", "content1", "content2", "content3", "content4"};
- // create common objects
- IProject project = getWorkspace().getRoot().getProject("TestCopyHistoryProject");
- IProject project2 = getWorkspace().getRoot().getProject("TestCopyHistoryProject2");
- ensureExistsInWorkspace(new IResource[] {project, project2}, true);
-
- IFolder folder = project.getFolder("folder1");
- IFolder folder2 = project2.getFolder("folder1");
- IFile file = folder.getFile("file1.txt");
- IFile file2 = folder2.getFile("file1.txt");
- try {
- // Setup folder1 and file1.txt with some local history
- folder.create(true, true, getMonitor());
- file.create(getContents(contents[0]), true, getMonitor());
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- fail("0.0", e);
- }
- file.setContents(getContents(contents[1]), true, true, getMonitor());
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- fail("0.1", e);
- }
- file.setContents(getContents(contents[2]), true, true, getMonitor());
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- fail("0.2", e);
- }
- IFileState[] states = file.getHistory(getMonitor());
- assertEquals("1.0", 2, states.length);
- assertTrue("1.1", compareContent(getContents(contents[1]), states[0].getContents()));
- assertTrue("1.2", compareContent(getContents(contents[0]), states[1].getContents()));
- folder2.create(true, true, getMonitor());
- file2.create(getContents(contents[3]), true, getMonitor());
- file2.setContents(getContents(contents[4]), true, true, getMonitor());
- } catch (CoreException e) {
- fail("1.9", e);
- }
-
- // Test a valid copy of a folder
- HistoryStore store = ((Resource) file).getLocalManager().getHistoryStore();
- store.copyHistory(project.getFullPath(), project2.getFullPath());
- IFileState[] states = null;
- try {
- states = file2.getHistory(getMonitor());
- } catch (CoreException e) {
- fail("2.4");
- }
- assertEquals("2.4", 3, states.length);
- try {
- assertTrue("2.5", compareContent(getContents(contents[3]), states[0].getContents()));
- assertTrue("2.6", compareContent(getContents(contents[1]), states[1].getContents()));
- assertTrue("2.7", compareContent(getContents(contents[0]), states[2].getContents()));
- } catch (CoreException e) {
- fail("2.8");
- }
-}
-public void testBug28238() {
- // paths to mimic files in the workspace
- IPath project = new Path("myproject");
- IPath folder = project.append("myfolder");
- IPath destinationFolder = project.append("myfolder2");
- IPath file = folder.append("myfile.txt");
- IPath destinationFile = destinationFolder.append(file.lastSegment());
-
- HistoryStore store = ((Resource) getWorkspace().getRoot()).getLocalManager().getHistoryStore();
-
- // location of the data on disk
- IPath path = getRandomLocation();
- try {
- createFileInFileSystem(path, getRandomContents());
- } catch (IOException e) {
- fail("1.0", e);
- }
-
- // add the data to the history store
- store.addState(file, path, System.currentTimeMillis(), true);
- IFileState[] states = store.getStates(file);
- assertEquals("2.0", 1, states.length);
-
- // copy the data
- store.copyHistory(folder, destinationFolder);
-
- states = store.getStates(destinationFile);
- assertEquals("3.0", 1, states.length);
-}
-public void testBug28603() {
- // paths to mimic files in the workspace
- IProject project = getWorkspace().getRoot().getProject("myproject");
- IFolder folder1 = project.getFolder("myfolder1");
- IFolder folder2 = project.getFolder("myfolder2");
- IFile file1 = folder1.getFile("myfile.txt");
- IFile file2 = folder2.getFile(file1.getName());
-
- ensureExistsInWorkspace(new IResource[] {project, folder1, folder2}, true);
- try {
- file1.create(getRandomContents(), IResource.FORCE, getMonitor());
- file1.setContents(getRandomContents(), IResource.FORCE | IResource.KEEP_HISTORY, getMonitor());
- file1.setContents(getRandomContents(), IResource.FORCE | IResource.KEEP_HISTORY, getMonitor());
- file1.setContents(getRandomContents(), IResource.FORCE | IResource.KEEP_HISTORY, getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
- int maxStates = ResourcesPlugin.getWorkspace().getDescription().getMaxFileStates();
-
- IFileState[] states = null;
- try {
- states = file1.getHistory(getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
- assertEquals("1.1", 3, states.length);
- int currentStates = 3;
-
- for (int i = 0; i < maxStates + 10; i++) {
- try {
- states = file1.getHistory(getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
- assertEquals("2.1 file1 states", currentStates, states.length);
- try {
- file1.move(file2.getFullPath(), true, true, getMonitor());
- } catch (CoreException e) {
- fail("2.2", e);
- }
-
- try {
- states = file2.getHistory(getMonitor());
- } catch (CoreException e) {
- fail("2.3", e);
- }
- currentStates = currentStates < maxStates ? currentStates + 1 : maxStates;
- assertEquals("2.4 file2 states", currentStates, states.length);
- try {
- file2.move(file1.getFullPath(), true, true, getMonitor());
- } catch (CoreException e) {
- fail("2.5", e);
- }
- try {
- states = file1.getHistory(getMonitor());
- } catch (CoreException e) {
- fail("2.6", e);
- }
- currentStates = currentStates < maxStates ? currentStates + 1 : maxStates;
- assertEquals("2.7 file1 states", currentStates, states.length);
- }
-}
-protected void addToHistory(String message, HistoryStore store, IPath path, InputStream input) {
- IPath localLocation = getRandomLocation();
- try {
- createFileInFileSystem(localLocation, input);
- } catch (IOException e) {
- fail(message, e);
- }
- store.addState(path, localLocation, System.currentTimeMillis(), true);
-}
-public void testAccept() {
- HistoryStore store = ((Resource) getWorkspace().getRoot()).getLocalManager().getHistoryStore();
- IPath a = new Path("/a");
- IPath ab = a.append("b");
- IPath abc = ab.append("c");
-
- IPath a1 = new Path("/a1");
-
- addToHistory("1.0", store, a, getRandomContents());
- addToHistory("1.1", store, ab, getRandomContents());
- addToHistory("1.2", store, abc, getRandomContents());
- addToHistory("1.3", store, a1, getRandomContents());
-
- // visit only /a
- HistoryStoreVisitorVerifier verifier = new HistoryStoreVisitorVerifier();
- verifier.addExpected(a);
- org.eclipse.core.internal.localstore.TestingSupport.accept(store, a, verifier, false);
- try {
- verifier.verify();
- } catch (VerificationFailedException e) {
- fail("2.0", e);
- }
-
- // visit /a and all its children. Ensure that we don't visit /a1
- verifier.reset();
- verifier.addExpected(a);
- verifier.addExpected(ab);
- verifier.addExpected(abc);
- org.eclipse.core.internal.localstore.TestingSupport.accept(store, a, verifier, true);
- try {
- verifier.verify();
- } catch (VerificationFailedException e) {
- fail("2.1", e);
- }
-
- // visit starting at the root. Should visit all entries
- verifier.reset();
- verifier.addExpected(a);
- verifier.addExpected(ab);
- verifier.addExpected(abc);
- verifier.addExpected(a1);
- org.eclipse.core.internal.localstore.TestingSupport.accept(store, Path.ROOT, verifier, true);
- try {
- verifier.verify();
- } catch (VerificationFailedException e) {
- fail("2.2", e);
- }
-}
-public void testSimultaneousStates(){
- /* Create common objects. */
- IProject project = getWorkspace().getRoot().getProject("Project");
- IFile file = project.getFile("file.txt");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- file.create(getRandomContents(), true, getMonitor());
- file.setContents(getRandomContents(), IResource.FORCE | IResource.KEEP_HISTORY, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- IFileState[] states = null;
- try {
- getWorkspace().save(true, null);
- states = file.getHistory(getMonitor());
- } catch (CoreException e) {
- fail("1.1", e);
- }
- assertEquals("1.2", 1, states.length);
-
- long lastModifiedTime = states[0].getModificationTime();
-
- // Create more states for this file with the same path
- // and last modification time
- HistoryStore historyStore = ((Workspace) getWorkspace()).getFileSystemManager().getHistoryStore();
- historyStore.addState(file.getFullPath(), file.getLocation(), lastModifiedTime, false);
- historyStore.addState(file.getFullPath(), file.getLocation(), lastModifiedTime, false);
- try {
- states = file.getHistory(getMonitor());
- } catch (CoreException e) {
- fail("1.3", e);
- }
- assertEquals("1.4", 3, states.length);
-
- // Now get all the HistoryStoreEntry's that match these
- // states and make sure the counter is different for
- // each one.
- final String INDEX_FILE = ".index"; //$NON-NLS-1$
- IPath location = ((Workspace)getWorkspace()).getMetaArea().getHistoryStoreLocation();
- IndexedStoreWrapper store = new IndexedStoreWrapper(location.append(INDEX_FILE));;
-
- boolean[] counts = {false, false, false};
-
- store = new IndexedStoreWrapper(location.append(INDEX_FILE));
- byte[] key = HistoryStoreEntry.keyPrefixToBytes(file.getFullPath(), lastModifiedTime);
- try {
- IndexCursor cursor = store.getCursor();
- cursor.find(key);
- // Check for a prefix match.
- while (cursor.keyMatches(key)) {
- byte[] storedKey = cursor.getKey();
- // set the boolean for the appropriate counter
- if (storedKey.length - ILocalStoreConstants.SIZE_COUNTER == key.length) {
- HistoryStoreEntry storedEntry = HistoryStoreEntry.create(store, cursor);
- int counter = storedEntry.getCount();
- assertTrue ("1.5", counter < 3);
- // Make sure we haven't already seen this
- // counter.
- assertFalse("1.6", counts[counter]);
- counts[counter] = true;
- }
- cursor.next();
- }
- cursor.close();
- } catch (Exception e) {
- fail ("1.7");
- }
- // Make sure we saw each of the counts once
- for (int i = 0; i < counts.length; i++) {
- assertTrue("1.8" + i, counts[i]);
- }
-
- // Clean up
- try {
- project.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("1.9", e);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/LocalStoreTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/LocalStoreTest.java
deleted file mode 100644
index 48b169a..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/LocalStoreTest.java
+++ /dev/null
@@ -1,179 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.localstore;
-
-import java.io.*;
-
-import org.eclipse.core.internal.localstore.FileSystemResourceManager;
-import org.eclipse.core.internal.resources.Workspace;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-public abstract class LocalStoreTest extends EclipseWorkspaceTest {
- // test configuration attributes
- protected static int numberOfProjects = 3;
- protected static int numberOfProperties = 5;
- protected static final int sleepTime = 5000;
-
- // projects names and projects
- protected String[] projectNames;
- protected IProject[] projects;
-
-
-public LocalStoreTest() {
- super();
-}
-public LocalStoreTest(String name) {
- super(name);
-}
-protected int countChildren(File root) {
- String[] children = root.list();
- if (children == null)
- return 0;
- int result = 0;
- for (int i = 0; i < children.length; i++) {
- File child = new File(root, children[i]);
- if (child.isDirectory())
- result += countChildren(child);
- result++;
- }
- return result;
-}
-public int countChildren(IFolder root) throws CoreException {
- int total = 0;
- IResource[] children = root.members();
- for (int i = 0; i < children.length; i++) {
- if (children[i].getType() == IResource.FILE)
- total++;
- else
- total += countChildren((IFolder) children[i]);
- }
- return total;
-}
-/**
- * Create a file with random content. If a resource exists in the same path,
- * the resource is deleted.
- */
-protected void createFile(File target, String content) throws IOException {
- Workspace.clear(target);
- InputStream input = new ByteArrayInputStream(content.getBytes());
- FileOutputStream output = new FileOutputStream(target);
- transferData(input, output);
- assertTrue(target.isFile());
-}
-protected void createNode(File node) throws IOException {
- char type = node.getName().charAt(0);
- if (type == 'd')
- node.mkdirs();
- else {
- InputStream input = getRandomContents();
- FileOutputStream output = new FileOutputStream(node);
- transferData(input, output);
- }
-}
-protected void createTree(File[] tree) throws IOException {
- for (int i = 0; i < tree.length; i++)
- createNode(tree[i]);
-}
-/**
- * The returned arry will have at least the specified size.
- */
-protected byte[] getBigContents(int size) {
- return getBigString(size).getBytes();
-}
-/**
- * The returned arry will have at least the specified size.
- */
-protected String getBigString(int size) {
- StringBuffer sb = new StringBuffer();
- while (sb.length() < size)
- sb.append(getRandomString());
- return sb.toString();
-}
-public FileSystemResourceManager getLocalManager() {
- return ((Workspace) getWorkspace()).getFileSystemManager();
-}
-protected File[] getTree(File root) {
- return getTree(root, getTreeElements());
-}
-protected File[] getTree(File root, String[] elements) {
- File[] tree = new File[elements.length];
- for (int i = 0; i < elements.length; i++)
- tree[i] = new File(root, elements[i]);
- return tree;
-}
-protected String[] getTreeElements() {
- String[] tree = new String[10];
- tree[0] = "d-folder";
- tree[1] = tree[0] + File.separator + "d-subfolder";
- tree[2] = tree[0] + File.separator + "f-file";
- tree[3] = tree[1] + File.separator + "f-anotherFile";
- tree[4] = tree[1] + File.separator + "d-subfolder";
- tree[5] = "d-1";
- tree[6] = "d-2";
- tree[7] = "f-3";
- tree[8] = "f-4";
- tree[9] = "f-5";
- return tree;
-}
-protected void setUp() throws Exception {
- super.setUp();
-
- projectNames = new String[numberOfProjects];
- projects = new IProject[numberOfProjects];
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- for (int i = 0; i < projectNames.length; i++) {
- projectNames[i] = "Project"+i;
- projects[i] = getWorkspace().getRoot().getProject(projectNames[i]);
- projects[i].create(null);
- projects[i].open(null);
- }
- }
- }, null);
-}
-protected void tearDown() throws Exception {
- getWorkspace().getRoot().delete(true, true, getMonitor());
- super.tearDown();
-}
- /**
- * Copy the data from the input stream to the output stream.
- * Close just the input stream.
- */
- public void transferDataWithoutCloseStreams(InputStream input, OutputStream output) {
- try {
- int c = 0;
- while ((c = input.read()) != -1) {
- output.write(c);
- }
- //input.close();
- //output.close();
- } catch (IOException e) {
- e.printStackTrace();
- assertTrue(e.toString(), false);
- }
- }
-protected boolean verifyNode(File node) {
- char type = node.getName().charAt(0);
- if (type == 'd')
- return true == node.isDirectory();
- else
- return true == node.isFile();
-}
-protected boolean verifyTree(File[] tree) {
- for (int i = 0; i < tree.length; i++)
- if (!verifyNode(tree[i]))
- return false;
- return true;
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/LocalSyncTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/LocalSyncTest.java
deleted file mode 100644
index 5046606..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/LocalSyncTest.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.localstore;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.resources.*;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-///
-public class LocalSyncTest extends LocalStoreTest implements ICoreConstants {
-public LocalSyncTest() {
- super();
-}
-public LocalSyncTest(String name) {
- super(name);
-}
-public void assertExistsInFileSystemWithNoContent(IFile target) throws CoreException {
- assertTrue(existsInFileSystemWithNoContent(target));
-}
-public String[] defineHierarchy() {
- return new String[] {
- "/File1",
- "/Folder1/",
- "/Folder1/File1",
- "/Folder1/Folder2/"
- };
-}
-private boolean existsInFileSystemWithNoContent(IResource resource) throws CoreException {
- IPath path = resource.getLocation();
- return path.toFile().exists() && path.toFile().length() == 0;
-}
-public static Test suite() {
- TestSuite suite = new TestSuite(LocalSyncTest.class);
- return suite;
-}
-public void testProjectDeletion() throws Throwable {
- /* initialize common objects */
- Project project = (Project)projects[0];
-
- //snapshot will recreate the deleted .project file
- TestingSupport.waitForSnapshot();
-
- // create resources
- IResource[] resources = buildResources(project, defineHierarchy());
- ensureExistsInWorkspace(resources, true);
-
- // delete project's default directory
- Workspace.clear(project.getLocation().toFile());
-
- // run synchronize
- //The .project file has been deleted, so this will fail
- try {
- project.refreshLocal(IResource.DEPTH_INFINITE, null);
- fail("1.0");
- } catch (CoreException e) {
- }
-
- /* project should still exists */
- assertTrue("1.1", project.exists());
-
- /* resources should not exist anymore */
- for (int i = 1; i < resources.length; i++)
- assertTrue("1.2", !resources[i].exists());
-}
-public void testProjectWithNoResources() throws Throwable {
- /* initialize common objects */
- Project project = (Project)projects[0];
-
- /* check normal behaviour */
- project.refreshLocal(IResource.DEPTH_INFINITE, null);
- assertTrue("1.1", project.exists());
-}
-/**
- * Simple synchronization test. Uses one solution and one project.
- */
-public void testSimpleSync() throws Throwable {
- /* initialize common objects */
- Project project = (Project) projects[0];
-
- // create resource handles
- IResource index = project.getFile(new Path("index.html"));
- IResource toc = project.getFile(new Path("toc.html"));
- IResource file = project.getFile(new Path("file"));
- IResource folder = project.getFolder(new Path("folder"));
-
- // add resources to the workspace
- ensureExistsInWorkspace((IFile) index, "");
- ensureExistsInWorkspace((IFile) toc, true);
- ensureExistsInWorkspace((IFile) file, "");
- ensureExistsInWorkspace((IFolder) folder, true);
-
- // run synchronize
- project.refreshLocal(IResource.DEPTH_INFINITE, null); // test
-
- //-----------------------------------------------------------
- // test synchronize
- assertExistsInWorkspace(index);
- assertExistsInFileSystemWithNoContent((IFile) index);
- //
- assertExistsInWorkspace(toc);
- assertExistsInFileSystem(toc);
- assertTrue(toc.exists());
- //
- assertExistsInWorkspace(file);
- assertExistsInFileSystemWithNoContent((IFile) file);
- assertTrue(file.exists());
- assertTrue(file.getType() == IResource.FILE);
- //
- assertExistsInWorkspace(folder);
- assertTrue(folder.getType() == IResource.FOLDER);
- //-----------------------------------------------------------
-
- // make some modifications in the local resources
- // index stays the same
- ensureDoesNotExistInFileSystem(toc);
- //
- ensureDoesNotExistInFileSystem(file);
- ensureDoesNotExistInFileSystem(folder);
- Thread.sleep(5000);
- file = project.getFolder(new Path("file"));
- folder = project.getFile(new Path("folder"));
- ensureExistsInFileSystem((IFolder) file);
- ensureExistsInFileSystem((IFile) folder);
-
- // run synchronize
- project.refreshLocal(IResource.DEPTH_INFINITE, null); // test
-
- //-----------------------------------------------------------
- // test synchronize
- assertExistsInWorkspace(index);
- assertExistsInFileSystemWithNoContent((IFile) index);
- //
- assertDoesNotExistInFileSystem((IFile) toc);
- assertDoesNotExistInWorkspace(toc);
- //
- assertExistsInWorkspace(file);
- assertExistsInFileSystem(file);
- assertTrue(file.exists());
- assertTrue(file.getType() == IResource.FOLDER);
- //
- assertExistsInWorkspace(folder);
- assertExistsInFileSystem(folder);
- assertTrue(file.exists());
- assertTrue(folder.getType() == IResource.FILE);
- //-----------------------------------------------------------
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/MoveTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/MoveTest.java
deleted file mode 100644
index b17a517..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/MoveTest.java
+++ /dev/null
@@ -1,713 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.localstore;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.resources.*;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-/**
- * Tests the move operation.
- */
-public class MoveTest extends LocalStoreTest {
-public MoveTest() {
- super();
-}
-public MoveTest(String name) {
- super(name);
-}
-public String[] defineHierarchy() {
- return new String[] {
- "/",
- "/file1",
- "/file2",
- "/folder1/",
- "/folder1/file3",
- "/folder1/file4",
- "/folder2/",
- "/folder2/file5",
- "/folder2/file6",
- "/folder1/folder3/",
- "/folder1/folder3/file7",
- "/folder1/folder3/file8" };
-}
-public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(new MoveTest("testRenameProjects"));
- suite.addTest(new MoveTest("testRenameFolder"));
- suite.addTest(new MoveTest("testRenameFile"));
- suite.addTest(new MoveTest("testMoveFolderBetweenProjects"));
- suite.addTest(new MoveTest("testMoveFileBetweenProjects"));
- suite.addTest(new MoveTest("testMoveFolderAcrossVolumes"));
- suite.addTest(new MoveTest("testMoveFileAcrossVolumes"));
- suite.addTest(new MoveTest("testMoveHierarchy"));
- suite.addTest(new MoveTest("testMoveHierarchyBetweenProjects"));
- suite.addTest(new MoveTest("testMoveResource"));
- return suite;
-}
-/**
- * This test has Windows as the target OS. Drives C: and D: should be available.
- */
-public void testMoveFileAcrossVolumes() {
- /* test if we are in the adequate environment */
- if (!new java.io.File("c:\\").exists() || !new java.io.File("d:\\").exists())
- return;
-
- // create common objects
- IProject source = getWorkspace().getRoot().getProject("SourceProject");
- IProject destination = getWorkspace().getRoot().getProject("DestinationProject");
- IPath destinationLocation = new Path("d:/temp/destination");
- try {
- source.create(getMonitor());
- source.open(getMonitor());
- IProjectDescription description = getWorkspace().newProjectDescription("DestinationProject");
- description.setLocation(destinationLocation);
- destination.create(description, getMonitor());
- destination.open(getMonitor());
- } catch (CoreException e) {
- //if projects could not be created then test machine does not have the necessary drives
- return;
- }
-
- String fileName = "fileToBeMoved.txt";
- IFile file = source.getFile(fileName);
- try {
- file.create(getRandomContents(), true, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- // add some properties to file (persistent and session)
- QualifiedName[] propNames = new QualifiedName[numberOfProperties];
- String[] propValues = new String[numberOfProperties];
- try {
- for (int j = 0; j < numberOfProperties; j++) {
- propNames[j] = new QualifiedName("test", "prop" + j);
- propValues[j] = "value" + j;
- file.setPersistentProperty(propNames[j], propValues[j]);
- file.setSessionProperty(propNames[j], propValues[j]);
- }
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- // move file
- IPath dest = destination.getFile(fileName).getFullPath();
- try {
- file.move(dest, true, getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
-
- // assert file was moved
- IFile newFile = destination.getFile(fileName);
- assertDoesNotExistInWorkspace("4.1", file);
- assertDoesNotExistInFileSystem("4.2", file);
- assertExistsInWorkspace("4.3", newFile);
- assertExistsInFileSystem("4.4", newFile);
-
- // assert properties still exist (server, local and session)
- try {
- for (int j = 0; j < numberOfProperties; j++) {
- String persistentValue = newFile.getPersistentProperty(propNames[j]);
- Object sessionValue = newFile.getSessionProperty(propNames[j]);
- assertEquals("5.1", persistentValue, propValues[j]);
- assertEquals("5.2", sessionValue, propValues[j]);
- }
- } catch (CoreException e) {
- fail("5.3", e);
- }
-
- // remove garbage
- try {
- source.delete(true, true, getMonitor());
- destination.delete(true, true, getMonitor());
- } catch (CoreException e) {
- fail("20.0", e);
- }
- ensureDoesNotExistInFileSystem(destinationLocation.toFile());
-}
-/**
- * Move one file from one project to another.
- */
-public void testMoveFileBetweenProjects() throws Exception {
- // create common objects
- IProject[] projects = getWorkspace().getRoot().getProjects();
-
- // get file instance
- String fileName = "newFile.txt";
- IFile file = projects[0].getFile(fileName);
- ensureExistsInWorkspace(file, true);
-
- // add some properties to file (persistent and session)
- QualifiedName[] propNames = new QualifiedName[numberOfProperties];
- String[] propValues = new String[numberOfProperties];
- for (int j = 0; j < numberOfProperties; j++) {
- propNames[j] = new QualifiedName("test", "prop" + j);
- propValues[j] = "value" + j;
- file.setPersistentProperty(propNames[j], propValues[j]);
- file.setSessionProperty(propNames[j], propValues[j]);
- }
-
- // move file
- IPath destination = projects[1].getFile(fileName).getFullPath();
- file.move(destination, true, null);
-
- // get new file instance
- IFile newFile = projects[1].getFile(fileName);
-
- // assert file was renamed
- assertDoesNotExistInWorkspace(file);
- assertDoesNotExistInFileSystem(file);
- assertExistsInWorkspace(newFile);
- assertExistsInFileSystem(newFile);
-
- // assert properties still exist (server, local and session)
- for (int j = 0; j < numberOfProperties; j++) {
- String persistentValue = newFile.getPersistentProperty(propNames[j]);
- Object sessionValue = newFile.getSessionProperty(propNames[j]);
- assertTrue("persistent property value is not the same", propValues[j].equals(persistentValue));
- assertTrue("session property value is not the same", propValues[j].equals(sessionValue));
- }
-}
-/**
- * This test has Windows as the target OS. Drives C: and D: should be available.
- */
-public void testMoveFolderAcrossVolumes() {
- /* test if we are in the adequate environment */
- if (!new java.io.File("c:\\").exists() || !new java.io.File("d:\\").exists())
- return;
-
- // create common objects
- IProject source = getWorkspace().getRoot().getProject("SourceProject");
- IProject destination = getWorkspace().getRoot().getProject("DestinationProject");
- try {
- source.create(getMonitor());
- source.open(getMonitor());
- IProjectDescription description = getWorkspace().newProjectDescription("DestinationProject");
- description.setLocation(new Path("d:/temp/destination"));
- destination.create(description, getMonitor());
- destination.open(getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- // get folder instance
- String folderName = "folderToBeMoved";
- IFolder folder = source.getFolder(folderName);
- try {
- folder.create(true, true, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- // add some properties to file (persistent and session)
- QualifiedName[] propNames = new QualifiedName[numberOfProperties];
- String[] propValues = new String[numberOfProperties];
- try {
- for (int j = 0; j < numberOfProperties; j++) {
- propNames[j] = new QualifiedName("test", "prop" + j);
- propValues[j] = "value" + j;
- folder.setPersistentProperty(propNames[j], propValues[j]);
- folder.setSessionProperty(propNames[j], propValues[j]);
- }
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- // rename folder
- IPath dest = destination.getFile(folderName).getFullPath();
- try {
- folder.move(dest, true, getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
-
- // assert folder was renamed
- IFolder newFolder = destination.getFolder(folderName);
- assertDoesNotExistInWorkspace("4.1", folder);
- assertDoesNotExistInFileSystem("4.2", folder);
- assertExistsInWorkspace("4.3", newFolder);
- assertExistsInFileSystem("4.4", newFolder);
-
- // assert properties still exist (server, local and session)
- try {
- for (int j = 0; j < numberOfProperties; j++) {
- String persistentValue = newFolder.getPersistentProperty(propNames[j]);
- Object sessionValue = newFolder.getSessionProperty(propNames[j]);
- assertEquals("5.1", persistentValue, propValues[j]);
- assertEquals("5.2", sessionValue, propValues[j]);
- }
- } catch (CoreException e) {
- fail("5.3", e);
- }
-
- // remove garbage
- try {
- source.delete(true, true, getMonitor());
- destination.delete(true, true, getMonitor());
- } catch (CoreException e) {
- fail("20.0", e);
- }
-}
-/**
- * Move one folder from one project to another.
- */
-public void testMoveFolderBetweenProjects() throws Exception {
- // create common objects
- IProject[] projects = getWorkspace().getRoot().getProjects();
-
- // get folder instance
- String folderName = "newFolder";
- IFolder folder = projects[0].getFolder(folderName);
- ensureExistsInWorkspace(folder, true);
-
- // add some properties to folder (persistent and session)
- QualifiedName[] propNames = new QualifiedName[numberOfProperties];
- String[] propValues = new String[numberOfProperties];
- for (int j = 0; j < numberOfProperties; j++) {
- propNames[j] = new QualifiedName("test", "prop" + j);
- propValues[j] = "value" + j;
- folder.setPersistentProperty(propNames[j], propValues[j]);
- folder.setSessionProperty(propNames[j], propValues[j]);
- }
-
- // rename folder
- IPath destination = projects[1].getFolder(folderName).getFullPath();
- folder.move(destination, true, null);
-
- // get new folder instance
- IFolder newFolder = projects[1].getFolder(folderName);
-
- // assert folder was renamed
- assertDoesNotExistInWorkspace(folder);
- assertDoesNotExistInFileSystem(folder);
- assertExistsInWorkspace(newFolder);
- assertExistsInFileSystem(newFolder);
-
- // assert properties still exist (server, local and session)
- for (int j = 0; j < numberOfProperties; j++) {
- String persistentValue = newFolder.getPersistentProperty(propNames[j]);
- Object sessionValue = newFolder.getSessionProperty(propNames[j]);
- assertTrue("persistent property value is not the same", propValues[j].equals(persistentValue));
- assertTrue("session property value is not the same", propValues[j].equals(sessionValue));
- }
-}
-/**
- * Move some hierarchy of folders and files.
- */
-public void testMoveHierarchy() throws Exception {
- // create common objects
- IProject[] projects = getWorkspace().getRoot().getProjects();
-
- // create the source folder
- String folderSourceName = "folder source";
- IFolder folderSource = projects[0].getFolder(folderSourceName);
- ensureExistsInWorkspace(folderSource, true);
-
- // create hierarchy
- String[] hierarchy = defineHierarchy();
- IResource[] resources = buildResources(folderSource, hierarchy);
- ensureExistsInWorkspace(resources, true);
-
- // add some properties to each resource (persistent and session)
- String[] propNames = new String[numberOfProperties];
- String[] propValues = new String[numberOfProperties];
- for (int j = 0; j < numberOfProperties; j++) {
- propNames[j] = "prop" + j;
- propValues[j] = "value" + j;
- for (int i = 0; i < resources.length; i++) {
- IResource resource = resources[i];
- QualifiedName propName = new QualifiedName("test", resource.getName() + propNames[j]);
- String propValue = resource.getName() + propValues[j];
- resource.setPersistentProperty(propName, propValue);
- resource.setSessionProperty(propName, propValue);
- }
- }
-
- // create the destination folder
- String folderDestinationName = "folder destination";
- IFolder folderDestination = projects[0].getFolder(folderDestinationName);
-
- // move hierarchy
- //IProgressMonitor monitor = new LoggingProgressMonitor(System.out);
- IProgressMonitor monitor = getMonitor();
- folderSource.move(folderDestination.getFullPath(), true, monitor);
-
- // get new hierarchy instance
- IResource[] newResources = buildResources(folderDestination, hierarchy);
-
- // assert hierarchy was moved
- assertDoesNotExistInWorkspace(resources);
- assertDoesNotExistInFileSystem(resources);
- assertExistsInWorkspace(newResources);
- assertExistsInFileSystem(newResources);
-
- // assert properties still exist (server, local and session)
- for (int j = 0; j < numberOfProperties; j++) {
- for (int i = 0; i < newResources.length; i++) {
- IResource destResource = newResources[i];
- IResource sourceResource = resources[i];
- /* The names of the properties will remain the same in both the source and
- destination hierarchies. So, be sure to use sourceResource to get the
- name or your qualified name will contain 'folder destination' instead of
- 'folder source' and the property value will be null.
- */
- QualifiedName propName = new QualifiedName("test", sourceResource.getName() + propNames[j]);
- String propValue = sourceResource.getName() + propValues[j];
- String persistentValue = destResource.getPersistentProperty(propName);
- Object sessionValue = destResource.getSessionProperty(propName);
- assertTrue("persistent property value is not the same", propValue.equals(persistentValue));
- assertTrue("session property value is not the same", propValue.equals(sessionValue));
- }
- }
-}
-/**
- * Move some hierarchy of folders and files between projects. It also test moving a
- * hierarchy across volumes.
- */
-public void testMoveHierarchyBetweenProjects() throws Exception {
- // create common objects
- IProject[] projects = getWorkspace().getRoot().getProjects();
-
- // create the source folder
- String folderSourceName = "source";
- IFolder folderSource = projects[0].getFolder(folderSourceName);
- ensureExistsInWorkspace(folderSource, true);
-
- // build hierarchy
- String[] hierarchy = defineHierarchy();
- IResource[] resources = buildResources(folderSource, hierarchy);
- ensureExistsInWorkspace(resources, true);
-
- // add some properties to each resource
- String[] propNames = new String[numberOfProperties];
- String[] propValues = new String[numberOfProperties];
- for (int j = 0; j < numberOfProperties; j++) {
- propNames[j] = "prop" + j;
- propValues[j] = "value" + j;
- for (int i = 0; i < resources.length; i++) {
- IResource resource = resources[i];
- QualifiedName propName = new QualifiedName("test", resource.getName() + propNames[j]);
- String propValue = resource.getName() + propValues[j];
- resource.setPersistentProperty(propName, propValue);
- resource.setSessionProperty(propName, propValue);
- }
- }
-
- // create the destination folder
- String folderDestinationName = "destination";
- IFolder folderDestination = projects[1].getFolder(folderDestinationName);
-
- // move hierarchy
- folderSource.move(folderDestination.getFullPath(), true, null);
-
- // get new hierarchy instance
- IResource[] newResources = buildResources(folderDestination, hierarchy);
-
- // assert hierarchy was moved
- assertDoesNotExistInWorkspace(resources);
- assertDoesNotExistInFileSystem(resources);
- assertExistsInWorkspace(newResources);
- assertExistsInFileSystem(newResources);
-
- // assert properties still exist (server, local and session)
- for (int j = 0; j < numberOfProperties; j++) {
- for (int i = 0; i < newResources.length; i++) {
- IResource destResource = newResources[i];
- IResource sourceResource = resources[i];
- /* The names of the properties will remain the same in both the source and
- destination hierarchies. So, be sure to use sourceResource to get the
- name or your qualified name will contain 'destination' instead of
- 'source' and the property value will be null.
- */
- QualifiedName propName = new QualifiedName("test", sourceResource.getName() + propNames[j]);
- String propValue = sourceResource.getName() + propValues[j];
- String persistentValue = destResource.getPersistentProperty(propName);
- Object sessionValue = destResource.getSessionProperty(propName);
- assertTrue("persistent property value is not the same", propValue.equals(persistentValue));
- assertTrue("session property value is not the same", propValue.equals(sessionValue));
- }
- }
-}
-public void testMoveResource() throws Exception {
- /* create common objects */
- IProject[] projects = getWorkspace().getRoot().getProjects();
-
- /* create folder and file */
- IFolder folder = projects[0].getFolder("folder");
- IFile file = folder.getFile("file.txt");
- ensureExistsInWorkspace(folder, true);
- ensureExistsInWorkspace(file, true);
-
- /* move to absolute destination */
- IResource destination = projects[0].getFile("file.txt");
- file.move(destination.getFullPath(), true, null);
- assertTrue("1.1", !file.exists());
- assertTrue("1.2", destination.exists());
- destination.move(file.getFullPath(), true, null);
- assertTrue("1.3", file.exists());
- assertTrue("1.4", !destination.exists());
-
- /* move to relative destination */
- IPath path = new Path("destination");
- destination = folder.getFile(path);
- file.move(path, true, null);
- assertTrue("2.1", !file.exists());
- assertTrue("2.2", destination.exists());
- destination.move(file.getFullPath(), true, null);
- assertTrue("2.3", file.exists());
- assertTrue("2.4", !destination.exists());
-
- /* move folder to destination under its hierarchy */
- destination = folder.getFolder("subfolder");
- boolean ok = false;
- try {
- folder.move(destination.getFullPath(), true, null);
- } catch (RuntimeException e) {
- ok = true;
- }
- assertTrue("3.1", ok);
-
- /* test flag force = false */
- projects[0].refreshLocal(IResource.DEPTH_INFINITE, null);
- IFolder subfolder = folder.getFolder("aaa");
- ensureExistsInFileSystem(subfolder);
- IFile anotherFile = folder.getFile("bbb");
- ensureExistsInFileSystem(anotherFile);
- destination = projects[0].getFolder("destination");
- ok = false;
- try {
- folder.move(destination.getFullPath(), false, null);
- } catch (CoreException e) {
- ok = true;
- // FIXME: remove this check?
-// assertTrue("4.1", e.getStatus().getChildren().length == 2);
- }
- assertTrue("4.2", ok);
- try {
- folder.move(destination.getFullPath(), false, null);
- fail("4.2.1");
- } catch (CoreException e) {
- }
- assertTrue("4.3", folder.exists());
- // FIXME: should #move be a best effort operation?
- // its ok for the root to be moved but ensure the destination child wasn't moved
- IResource destChild = ((IContainer) destination).getFile(new Path(anotherFile.getName()));
- assertTrue("4.4", !destination.exists());
- assertTrue("4.5", !destChild.exists());
- // cleanup and delete the destination
- try {
- destination.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- } catch (CoreException e) {
- fail("4.6", e);
- }
- try {
- destination.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("4.7", e);
- }
-
- folder.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- try {
- folder.move(destination.getFullPath(), false, getMonitor());
- } catch (CoreException e) {
- fail("4.8");
- }
-
- destination.move(folder.getFullPath(), true, null);
- assertTrue("4.9", folder.exists());
- assertTrue("4.10", !destination.exists());
-
- /* move a file that is not local but exists in the workspace */
- file = projects[0].getFile("ghost");
- final IFile hackFile = file;
- final Workspace workspace = (Workspace) getWorkspace();
- IWorkspaceRunnable operation = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- workspace.createResource(hackFile, false);
- }
- };
- workspace.run(operation, null);
- destination = projects[0].getFile("destination");
- ok = false;
- try {
- file.move(destination.getFullPath(), true, null);
- } catch (CoreException e) {
- ok = true;
- }
- assertTrue("5.1", ok);
-
- /* move file over a phantom */
- assertTrue("6.1", file.exists());
- operation = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- ((Resource) hackFile).convertToPhantom();
- }
- };
- workspace.run(operation, null);
- assertTrue("6.2", !file.exists());
- ResourceInfo info = ((File) file).getResourceInfo(true, false);
- int flags = ((File) file).getFlags(info);
- assertTrue("6.3", ((Resource) file).exists(flags, true));
- anotherFile = folder.getFile("anotherFile");
- ensureExistsInWorkspace(anotherFile, true);
- anotherFile.move(file.getFullPath(), true, null);
- assertTrue("6.4", file.exists());
-}
-/**
- * A simple test that renames a file.
- */
-public void testRenameFile() throws Exception {
- // create common objects
- IProject[] projects = getWorkspace().getRoot().getProjects();
-
- // create a folder
- String fileName = "file.txt";
- IFile file = projects[0].getFile(fileName);
- ensureExistsInWorkspace(file, true);
-
- // add some properties to file (persistent and session)
- QualifiedName[] propNames = new QualifiedName[numberOfProperties];
- String[] propValues = new String[numberOfProperties];
- for (int j = 0; j < numberOfProperties; j++) {
- propNames[j] = new QualifiedName("test", "prop" + j);
- propValues[j] = "value" + j;
- file.setPersistentProperty(propNames[j], propValues[j]);
- file.setSessionProperty(propNames[j], propValues[j]);
- }
-
- // rename file
- String newFileName = "newFile.txt";
- IPath destination = projects[0].getFile(newFileName).getFullPath();
- file.move(destination, true, null);
-
- // get new folder instance
- IFile newFile = projects[0].getFile(newFileName);
-
- // assert file was renamed
- assertDoesNotExistInWorkspace(file);
- assertDoesNotExistInFileSystem(file);
- assertExistsInWorkspace(newFile);
- assertExistsInFileSystem(newFile);
-
- // assert properties still exist (server, local and session)
- for (int j = 0; j < numberOfProperties; j++) {
- String persistentValue = newFile.getPersistentProperty(propNames[j]);
- Object sessionValue = newFile.getSessionProperty(propNames[j]);
- assertTrue("persistent property value is not the same", propValues[j].equals(persistentValue));
- assertTrue("session property value is not the same", propValues[j].equals(sessionValue));
- }
-}
-/**
- * A simple test that renames a folder.
- *
- * - creates a folder
- * - set properties (server, local and session)
- * - rename folder
- * - assert rename worked
- * - assert properties still exist
- */
-public void testRenameFolder() throws Exception {
- // create common objects
- IProject[] projects = getWorkspace().getRoot().getProjects();
-
- // create a folder
- String folderName = "folder";
- IFolder folder = projects[0].getFolder(folderName);
- ensureExistsInWorkspace(folder, true);
-
- // add some properties to folder (persistent and session)
- QualifiedName[] propNames = new QualifiedName[numberOfProperties];
- String[] propValues = new String[numberOfProperties];
- for (int j = 0; j < numberOfProperties; j++) {
- propNames[j] = new QualifiedName("test", "prop" + j);
- propValues[j] = "value" + j;
- folder.setPersistentProperty(propNames[j], propValues[j]);
- folder.setSessionProperty(propNames[j], propValues[j]);
- }
-
- // rename folder
- String newFolderName = "newFolder";
- IPath destination = projects[0].getFolder(newFolderName).getFullPath();
- folder.move(destination, true, null);
-
- // get new folder instance
- IFolder newFolder = projects[0].getFolder(newFolderName);
-
- // assert folder was renamed
- assertDoesNotExistInWorkspace(folder);
- assertDoesNotExistInFileSystem(folder);
- assertExistsInWorkspace(newFolder);
- assertExistsInFileSystem(newFolder);
-
- // assert properties still exist (server, local and session)
- for (int j = 0; j < numberOfProperties; j++) {
- String persistentValue = newFolder.getPersistentProperty(propNames[j]);
- Object sessionValue = newFolder.getSessionProperty(propNames[j]);
- assertTrue("persistent property value is not the same", propValues[j].equals(persistentValue));
- assertTrue("session property value is not the same", propValues[j].equals(sessionValue));
- }
-}
-/**
- * Renames 3 projects using their names.
- *
- * - add properties to projects (server, local and session)
- * - rename projects
- * - assert properties are correct
- * - assert resources are correct
- */
-public void testRenameProjects() throws Exception {
- /* create common objects */
- IProject[] projects = getWorkspace().getRoot().getProjects();
-
- // add some properties to projects (persistent and session)
- numberOfProperties = numberOfProjects;
- QualifiedName[] propNames = new QualifiedName[numberOfProperties];
- String[] propValues = new String[numberOfProperties];
- for (int i = 0; i < numberOfProjects; i++) {
- propNames[i] = new QualifiedName("test", "prop" + i);
- propValues[i] = "value" + i;
- projects[i].setPersistentProperty(propNames[i], propValues[i]);
- projects[i].setSessionProperty(propNames[i], propValues[i]);
- }
-
- // assert properties exist (persistent and session)
- for (int i = 0; i < numberOfProjects; i++) {
- String persistentValue = projects[i].getPersistentProperty(propNames[i]);
- Object sessionValue = projects[i].getSessionProperty(propNames[i]);
- assertTrue("1.0." + i, propValues[i].equals(persistentValue));
- assertTrue("1.1." + i, propValues[i].equals(sessionValue));
- }
-
- // move (rename) projects
- String prefix = "Renamed_PrOjEcT";
- for (int i = 0; i < numberOfProjects; i++) {
- String projectName = prefix + i;
- IPath destination = getWorkspace().getRoot().getProject(projectName).getFullPath();
- projects[i].move(destination, true, null);
- projectNames[i] = projectName;
- }
-
- // get new projects instances
- for (int i = 0; i < numberOfProjects; i++)
- projects[i] = getWorkspace().getRoot().getProject(projectNames[i]);
-
- // assert properties still exist (persistent and session)
- for (int i = 0; i < numberOfProjects; i++) {
- String persistentValue = projects[i].getPersistentProperty(propNames[i]);
- Object sessionValue = projects[i].getSessionProperty(propNames[i]);
- assertTrue("2.0." + i, propValues[i].equals(persistentValue));
- assertTrue("2.1." + i, propValues[i].equals(sessionValue));
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/RefreshLocalPerformanceTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/RefreshLocalPerformanceTest.java
deleted file mode 100644
index 07842c2..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/RefreshLocalPerformanceTest.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.localstore;
-
-import java.io.File;
-import java.util.Date;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-//
-public class RefreshLocalPerformanceTest extends EclipseWorkspaceTest {
- /** big site default volume (windows) */
- public static final String bigSiteDevice = "d:";
-
- /** big site initial location */
- public static final IPath bigSiteLocation = new Path(bigSiteDevice, "/bigsite");
-
- /** benchmark */
- public Date startDate;
-public RefreshLocalPerformanceTest() {
- super();
-}
-public RefreshLocalPerformanceTest(String name) {
- super(name);
-}
-protected int countChildren(File root) {
- String[] children = root.list();
- if (children == null)
- return 0;
- int result = 0;
- for (int i = 0; i < children.length; i++) {
- File child = new File(root, children[i]);
- if (child.isDirectory())
- result += countChildren(child);
- result++;
- }
- return result;
-}
-public String dispTime(long diff) {
- return String.valueOf(diff);
-}
-public void startClock() {
- startDate = new Date();
-}
-public long stopClock() {
- Date stopDate = new Date();
- return stopDate.getTime() - startDate.getTime();
-}
-// this test should not be in AllTests because it is noly a performance test
-public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(new RefreshLocalPerformanceTest("testLocalRefreshPerformance"));
- return suite;
-}
-/**
- * Defines only a default mapping to a project and refreshs locally.
- */
-public void testLocalRefreshPerformance() throws Exception {
- // test if the test can be done in this machine
- if (!bigSiteLocation.toFile().isDirectory())
- return;
-
- // create common objects
- int n = 10;
- IProject project = getWorkspace().getRoot().getProject("MyTestProject");
- IProjectDescription description = getWorkspace().newProjectDescription(project.getName());
- description.setLocation(bigSiteLocation);
-
- // performance data
- long averageWithTree = 0;
- long averageWithoutTree = 0;
- long[] withoutTree = new long[n];
- long[] withTree = new long[n];
-
- // report the number of files to be refreshed
- int numberOfFiles = countChildren(bigSiteLocation.toFile());
- System.out.println("Number of local resources: " + numberOfFiles);
-
- // test each project
- for (int i = 0; i < n; i++) {
- project.create(description, null);
- project.open(null);
-
- // refresh local (new project)
- System.out.print("NO TREE: ");
- startClock();
- project.refreshLocal(IResource.DEPTH_INFINITE, null);
- withoutTree[i] = stopClock();
- System.out.println(dispTime(withoutTree[i]));
- // test with existing workspace tree
- System.out.print("TREE: ");
- startClock();
- project.refreshLocal(IResource.DEPTH_INFINITE, null);
- withTree[i] = stopClock();
- System.out.println(dispTime(withTree[i]));
-
- // calculate average
- averageWithoutTree += withoutTree[i];
- averageWithTree += withTree[i];
-
- // delete project but leave contents
- project.delete(false, false, null);
- }
- averageWithoutTree /= n;
- averageWithTree /= n;
- System.out.println("Average without tree: " + averageWithoutTree);
- System.out.println("Average with tree: " + averageWithTree);
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/RefreshLocalTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/RefreshLocalTest.java
deleted file mode 100644
index cfa02f2..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/RefreshLocalTest.java
+++ /dev/null
@@ -1,279 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.localstore;
-
-import java.io.File;
-import java.io.IOException;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.eclipse.core.boot.BootLoader;
-import org.eclipse.core.internal.localstore.CoreFileSystemLibrary;
-import org.eclipse.core.internal.resources.*;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-//
-public class RefreshLocalTest extends LocalStoreTest implements ICoreConstants {
-public RefreshLocalTest() {
- super();
-}
-public RefreshLocalTest(String name) {
- super(name);
-}
-public static Test suite() {
- return new TestSuite(RefreshLocalTest.class);
-}
-/**
- * Test discovery of a linked resource on refresh.
- */
-public void testDiscoverLinkedResource() {
- //create a linked resource with local contents missing
-// IProject project = projects[0];
-// ensureExistsInWorkspace(project, true);
-// IPath location = getRandomLocation();
-// IFile link = project.getFile("Link");
-// try {
-// link.createLink(location, IResource.ALLOW_MISSING_LOCAL, getMonitor());
-// } catch (CoreException e) {
-// fail("0.99", e);
-// }
-//
-// //should not be synchronized (exists in ws, but not in fs)
-// assertTrue("1.0", !project.isSynchronized(IResource.DEPTH_INFINITE));
-// assertTrue("1.1", !link.isSynchronized(IResource.DEPTH_ZERO));
-//
-// //should exist in workspace
-// assertTrue("1.3", link.exists());
-//
-// //refreshing shouldn't get rid of the link
-// try {
-// link.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
-// } catch (CoreException e) {
-// fail("1.99", e);
-// }
-// assertTrue("1.4", link.exists());
-//
-// //create the contents in the file system
-// try {
-// createFileInFileSystem(location);
-// } catch (CoreException e) {
-// fail("2.99", e);
-// }
-//
-// //should now be synchronized
-// assertTrue("2.1", project.isSynchronized(IResource.DEPTH_INFINITE));
-// assertTrue("2.2", link.isSynchronized(IResource.DEPTH_ZERO));
-//
-// //refresh
-// try {
-// link.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
-// } catch (CoreException e) {
-// fail("3.99", e);
-// }
-//
-// //assert should exist in workspace
-// assertTrue("2.3", link.exists());
-}
-/**
- * Tests discovering a file via refresh local when neither the file
- * nor its parent exists in the workspace.
- */
-public void testFileDiscovery() throws Throwable {
- /* initialize common objects */
- IProject project = projects[0];
-
- IFolder folder = project.getFolder("Folder");
- IFile file = folder.getFile("File");
- IResource[] both = new IResource[] {folder, file};
-
- ensureExistsInFileSystem(both);
- ensureDoesNotExistInWorkspace(both);
-
- assertTrue("1.0", !file.exists());
- assertTrue("1.1", !folder.exists());
- assertTrue("1.2", !file.isSynchronized(IResource.DEPTH_ZERO));
- assertTrue("1.3", !folder.isSynchronized(IResource.DEPTH_INFINITE));
- file.refreshLocal(IResource.DEPTH_ZERO, getMonitor());
- assertTrue("1.4", file.exists());
- assertTrue("1.5", folder.exists());
-
- //try again with deleted project
- project.delete(IResource.FORCE, getMonitor());
-
- ensureExistsInFileSystem(both);
- ensureDoesNotExistInWorkspace(both);
-
- assertTrue("2.0", !file.exists());
- assertTrue("2.1", !folder.exists());
- file.refreshLocal(IResource.DEPTH_ZERO, getMonitor());
- assertTrue("2.2", !file.exists());
- assertTrue("2.3", !folder.exists());
-}
-public void testFileToFolder() throws Throwable {
- /* initialize common objects */
- IProject project = projects[0];
-
- /* */
- IFile file = project.getFile("file");
- file.create(null, true, null);
- ensureDoesNotExistInFileSystem(file);
- //
- File target = file.getLocation().toFile();
- target.mkdirs();
- //
- assertTrue("1.1", file.exists());
- assertTrue("1.2", target.isDirectory());
- file.refreshLocal(IResource.DEPTH_ZERO, null);
- assertTrue("1.3", !file.exists());
- IFolder folder = project.getFolder("file");
- assertTrue("1.4", folder.exists());
-}
-public void testFolderToFile() throws Throwable {
- /* initialize common objects */
- IProject project = projects[0];
-
- /* test folder to file */
- IFolder folder = project.getFolder("folder");
- folder.create(true, true, null);
- ensureDoesNotExistInFileSystem(folder);
- //
- IFile file = project.getFile("folder");
- ensureExistsInFileSystem(file);
- //
- assertTrue("1.1", folder.exists());
- folder.refreshLocal(IResource.DEPTH_ZERO, null);
- assertTrue("1.2", !folder.exists());
- assertTrue("1.3", file.exists());
-}
-public void testRefreshFolder() throws Throwable {
- /* initialize common objects */
- IProject project = projects[0];
-
- /* test deletion of a child */
- IFile file = project.getFile("file");
- final IFile hackFile = file;
- final Workspace workspace = (Workspace) getWorkspace();
- IWorkspaceRunnable operation = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- workspace.createResource(hackFile, false);
- ((Resource) hackFile).getResourceInfo(false, true).set(M_LOCAL_EXISTS);
- }
- };
- workspace.run(operation, null);
- assertTrue("1.0", file.exists());
- assertTrue("1.1", file.isLocal(IResource.DEPTH_ZERO));
- project.refreshLocal(IResource.DEPTH_INFINITE, null);
- assertTrue("1.2", !file.exists());
- ensureDoesNotExistInWorkspace(file);
- ensureDoesNotExistInFileSystem(file);
-
- /* test creation of a child */
- file = project.getFile("file");
- ensureExistsInFileSystem(file);
- assertTrue("2.0", !file.exists());
- project.refreshLocal(IResource.DEPTH_INFINITE, null);
- assertTrue("2.1", file.exists());
- ensureDoesNotExistInWorkspace(file);
- ensureDoesNotExistInFileSystem(file);
-
- /* test changes of a child (child is folder) */
- IFolder folder = project.getFolder("folder");
- folder.create(true, true, null);
- file = folder.getFile("file");
- ensureExistsInFileSystem(file);
- assertTrue("3.1", folder.exists());
- assertTrue("3.2", folder.isLocal(IResource.DEPTH_ZERO));
- assertTrue("3.3", !file.exists());
- folder.refreshLocal(IResource.DEPTH_ZERO, null);
- assertTrue("3.4", folder.exists());
- assertTrue("3.5", folder.isLocal(IResource.DEPTH_ZERO));
- assertTrue("3.6", !file.exists());
- folder.refreshLocal(IResource.DEPTH_ONE, null);
- assertTrue("3.7", folder.exists());
- assertTrue("3.8", folder.isLocal(IResource.DEPTH_ZERO));
- assertTrue("3.9", file.exists());
- ensureDoesNotExistInWorkspace(folder);
- ensureDoesNotExistInFileSystem(folder);
-
- /* test changes of a child (child is file) */
- file = project.getFile("file");
- ensureExistsInWorkspace(file, true);
- assertTrue("4.1", file.exists());
- assertTrue("4.2", file.isLocal(IResource.DEPTH_ZERO));
- assertEquals("4.3", CoreFileSystemLibrary.getLastModified(file.getLocation().toOSString()), ((Resource) file).getResourceInfo(false, false).getLocalSyncInfo());
- Thread.sleep(sleepTime);
- ensureExistsInFileSystem(file);
- assertTrue("4.4", ((Resource) file).getResourceInfo(false, false).getLocalSyncInfo() != CoreFileSystemLibrary.getLastModified(file.getLocation().toOSString()));
- project.refreshLocal(IResource.DEPTH_INFINITE, null);
- assertEquals("4.5", CoreFileSystemLibrary.getLastModified(file.getLocation().toOSString()), ((Resource) file).getResourceInfo(false, false).getLocalSyncInfo());
- ensureDoesNotExistInWorkspace(file);
- ensureDoesNotExistInFileSystem(file);
-}
-public void testSimpleRefresh() throws Throwable {
- /* initialize common objects */
- IProject project = projects[0];
-
- /* test root deletion */
- IFile file = project.getFile("file");
- File target = file.getLocation().toFile();
- ensureExistsInWorkspace(file, true);
- ensureDoesNotExistInFileSystem(file);
- assertTrue("1.0", file.exists());
- file.refreshLocal(IResource.DEPTH_INFINITE, null);
- assertTrue("1.1", !file.exists());
-
- /* test root and children creation */
- IFolder folder = project.getFolder("folder");
- target = folder.getLocation().toFile();
- createTree(getTree(target));
- assertTrue("2.0", !folder.exists());
- folder.refreshLocal(IResource.DEPTH_INFINITE, null);
- assertTrue("2.1", folder.exists());
- assertTrue("2.2", ((Resource) folder).countResources(IResource.DEPTH_INFINITE, false) == (getTree(target).length + 1));
-}
-/**
- * Tests if files with names that are invalid segments are properly rejected - does not run on Windows.
- */
-public void skipTestDiscoverFileWithInvalidName() {
- //FIXME Temporarily skip this test due to VM vendor bug #96338
-
- if (BootLoader.getOS().equals(BootLoader.OS_WIN32))
- return;
-
- /* initialize common objects */
- IProject project = projects[0];
-
- /* test root deletion */
- IFile file = project.getFile("file.txt");
- ensureExistsInFileSystem(file);
-
- File fileWithInvalidName = new File(project.getLocation().toFile(), "a\\b");
- try {
- assertTrue("0.1", fileWithInvalidName.createNewFile());
- } catch (IOException e) {
- fail("0.2", e);
- }
- assertTrue("1.0", !file.exists());
- try {
- project.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- fail("2.0 - should have failed");
- } catch (CoreException ce) {
- IStatus status = ce.getStatus();
- assertTrue("2.1", status.isMultiStatus());
- IStatus[] children = status.getChildren();
- assertEquals("2.2", 1, children.length);
- assertTrue("2.3", children[0] instanceof ResourceStatus);
- assertEquals("2.4", IResourceStatus.INVALID_RESOURCE_NAME, children[0].getCode());
- }
- assertTrue("3.0", file.exists());
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/SafeChunkyInputOutputStreamTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/SafeChunkyInputOutputStreamTest.java
deleted file mode 100644
index 3c793e8..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/SafeChunkyInputOutputStreamTest.java
+++ /dev/null
@@ -1,278 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.localstore;
-
-import java.io.*;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.localstore.*;
-import org.eclipse.core.internal.resources.Workspace;
-import org.eclipse.core.runtime.IPath;
-
-public class SafeChunkyInputOutputStreamTest extends LocalStoreTest {
- protected File temp;
-public SafeChunkyInputOutputStreamTest() {
- super();
-}
-public SafeChunkyInputOutputStreamTest(String name) {
- super(name);
-}
-protected boolean compare(byte[] source, byte[] target) {
- if (source.length != target.length)
- return false;
- for (int i = 0; i < target.length; i++)
- if (source[i] != target[i])
- return false;
- return true;
-}
-protected byte[] merge(byte[] b1, byte[] b2) {
- byte[] result = new byte[b1.length + b2.length];
- for (int i = 0; i < b1.length; i++)
- result[i] = b1[i];
- for (int i = 0; i < b2.length; i++)
- result[b1.length + i] = b2[i];
- return result;
-}
-protected void setUp() throws Exception {
- super.setUp();
- IPath location = getRandomLocation();
- temp = location.append("temp").toFile();
- temp.mkdirs();
- assertTrue("could not create temp directory", temp.isDirectory());
-}
-public static Test suite() {
- return new TestSuite(SafeChunkyInputOutputStreamTest.class);
-}
-protected void tearDown() throws Exception {
- ensureDoesNotExistInFileSystem(temp.getParentFile());
- super.tearDown();
-}
-public void testBufferLimit() {
- File target = new File(temp, "target");
- Workspace.clear(target); // make sure there was nothing here before
- assertTrue("1.0", !target.exists());
-
- // use only one chunk but bigger than the buffer
- int bufferSize = 10024;
- byte[] chunk = getBigContents(bufferSize);
- SafeChunkyOutputStream output = null;
- try {
- output = new SafeChunkyOutputStream(target);
- try {
- output.write(chunk);
- output.succeed();
- } finally {
- output.close();
- }
- } catch (IOException e) {
- fail("2.0", e);
- }
-
- // read chunks
- SafeChunkyInputStream input = null;
- try {
- input = new SafeChunkyInputStream(target.getAbsolutePath());
- try {
- byte[] read = new byte[chunk.length];
- assertTrue("3.0", input.read(read) == chunk.length);
- assertTrue("3.6", compare(chunk, read));
- } finally {
- input.close();
- }
- } catch (IOException e) {
- fail("3.20", e);
- }
- Workspace.clear(target); // make sure there was nothing here before
-}
-public void testFailure() {
- File target = new File(temp, "target");
- Workspace.clear(target); // make sure there was nothing here before
- assertTrue("1.0", !target.exists());
-
- // misc
- byte[] fakeEnd = new byte[ILocalStoreConstants.END_CHUNK.length];
- System.arraycopy(ILocalStoreConstants.END_CHUNK, 0, fakeEnd, 0, ILocalStoreConstants.END_CHUNK.length);
- fakeEnd[fakeEnd.length - 1] = 86;
-
- // write chunks
- byte[] chunk1 = getRandomString().getBytes();
- byte[] chunk2 = getRandomString().getBytes();
- byte[] chunk3 = getRandomString().getBytes();
- byte[] chunk4 = getRandomString().getBytes();
- byte[] chunk5 = getRandomString().getBytes();
- byte[] chunk6 = getRandomString().getBytes();
- SafeChunkyOutputStream output = null;
- try {
- output = new SafeChunkyOutputStream(target);
- try {
- output.write(chunk1);
- output.succeed();
- output = new SafeChunkyOutputStream(target);
- // fake failure
- output.write(chunk2);
- output.write(ILocalStoreConstants.BEGIN_CHUNK); // another begin
- output.succeed();
- //
- output = new SafeChunkyOutputStream(target);
- output.write(chunk3);
- output.succeed();
- output = new SafeChunkyOutputStream(target);
- // fake failure
- output.write(chunk4);
- output.write(ILocalStoreConstants.END_CHUNK); // another end
- output.succeed();
- //
- output = new SafeChunkyOutputStream(target);
- output.write(chunk5);
- output.succeed();
- // fake failure
- output.write(fakeEnd);
- output.write(chunk6);
- output.succeed();
- } finally {
- output.close();
- }
- } catch (IOException e) {
- fail("2.0", e);
- }
-
- // read chunks
- SafeChunkyInputStream input = null;
- try {
- input = new SafeChunkyInputStream(target);
- try {
- byte[] read1 = new byte[chunk1.length];
- //byte[] read2 = new byte[chunk2.length];
- byte[] read3 = new byte[chunk3.length];
- byte[] read4 = new byte[chunk4.length];
- byte[] read5 = new byte[chunk5.length];
- byte[] read6 = new byte[fakeEnd.length + chunk6.length];
- assertTrue("3.0", input.read(read1) == chunk1.length);
- //assert("3.1", input.read(read2) == chunk2.length);
- assertTrue("3.2", input.read(read3) == chunk3.length);
- assertTrue("3.3", input.read(read4) == chunk4.length);
- assertTrue("3.4", input.read(read5) == chunk5.length);
- assertTrue("3.5", input.read(read6) == (fakeEnd.length + chunk6.length));
- assertTrue("3.6", compare(chunk1, read1));
- //assert("3.7", compare(chunk2, read2));
- assertTrue("3.8", compare(chunk3, read3));
- assertTrue("3.9", compare(chunk4, read4));
- assertTrue("3.10", compare(chunk5, read5));
- byte[] expected = merge(fakeEnd, chunk6);
- assertTrue("3.11", compare(expected, read6));
- } finally {
- input.close();
- }
- } catch (IOException e) {
- fail("3.20", e);
- }
- Workspace.clear(target); // make sure there was nothing here before
-}
-public void testAlmostEmpty() {
- File target = new File(temp, "target");
- Workspace.clear(target); // make sure there was nothing here before
- assertTrue("1.0", !target.exists());
-
- // open the file but don't write anything.
- SafeChunkyOutputStream output = null;
- try {
- output = new SafeChunkyOutputStream(target);
- } catch (IOException e) {
- fail("1.0", e);
- } finally {
- if (output != null)
- try {
- output.close();
- } catch (IOException e) {
- fail("1.1", e);
- }
- }
-
- SafeChunkyInputStream input = null;
- try {
- input = new SafeChunkyInputStream(target);
- new DataInputStream(input).readUTF();
- fail("2.0");
- } catch (EOFException e) {
- // should hit here
- } catch (IOException e) {
- fail("2.1", e);
- } finally {
- if (input != null)
- try {
- input.close();
- } catch (IOException e) {
- fail("2.2", e);
- }
- }
-}
-public void testSimple() {
- File target = new File(temp, "target");
- Workspace.clear(target); // make sure there was nothing here before
- assertTrue("1.0", !target.exists());
-
- // write chunks
- byte[] chunk1 = getRandomString().getBytes();
- byte[] chunk2 = getRandomString().getBytes();
- byte[] chunk3 = getRandomString().getBytes();
- byte[] chunk4 = getRandomString().getBytes();
- byte[] chunk5 = getRandomString().getBytes();
- SafeChunkyOutputStream output = null;
- try {
- output = new SafeChunkyOutputStream(target);
- try {
- output.write(chunk1);
- output.succeed();
- output.write(chunk2);
- output.succeed();
- output.write(chunk3);
- output.succeed();
- output.write(chunk4);
- output.succeed();
- output.write(chunk5);
- output.succeed();
- } finally {
- output.close();
- }
- } catch (IOException e) {
- fail("2.0", e);
- }
-
- // read chunks
- SafeChunkyInputStream input = null;
- try {
- input = new SafeChunkyInputStream(target);
- try {
- byte[] read1 = new byte[chunk1.length];
- byte[] read2 = new byte[chunk2.length];
- byte[] read3 = new byte[chunk3.length];
- byte[] read4 = new byte[chunk4.length];
- byte[] read5 = new byte[chunk5.length];
- assertTrue("3.0", input.read(read1) == chunk1.length);
- assertTrue("3.1", input.read(read2) == chunk2.length);
- assertTrue("3.2", input.read(read3) == chunk3.length);
- assertTrue("3.3", input.read(read4) == chunk4.length);
- assertTrue("3.4", input.read(read5) == chunk5.length);
- assertTrue("3.5", compare(chunk1, read1));
- assertTrue("3.6", compare(chunk2, read2));
- assertTrue("3.7", compare(chunk3, read3));
- assertTrue("3.8", compare(chunk4, read4));
- assertTrue("3.9", compare(chunk5, read5));
- } finally {
- input.close();
- }
- } catch (IOException e) {
- fail("3.10", e);
- }
- Workspace.clear(target); // make sure there was nothing here before
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/SafeFileInputOutputStreamTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/SafeFileInputOutputStreamTest.java
deleted file mode 100644
index 2490f73..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/SafeFileInputOutputStreamTest.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.localstore;
-
-import java.io.*;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.localstore.*;
-import org.eclipse.core.internal.resources.Workspace;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-public class SafeFileInputOutputStreamTest extends EclipseWorkspaceTest {
- protected File temp;
-public SafeFileInputOutputStreamTest() {
- super();
-}
-public SafeFileInputOutputStreamTest(String name) {
- super(name);
-}
-public SafeFileOutputStream createSafeStream(File target, String errorCode) {
- return createSafeStream(target.getAbsolutePath(), null, errorCode);
-}
-public SafeFileOutputStream createSafeStream(String targetPath, String tempFilePath, String errorCode) {
- try {
- return new SafeFileOutputStream(targetPath, tempFilePath);
- } catch (IOException e) {
- fail(errorCode, e);
- }
- return null; // never happens
-}
-public InputStream getContents(java.io.File target, String errorCode) {
- try {
- return new SafeFileInputStream(target);
- } catch (IOException e) {
- fail(errorCode, e);
- }
- return null; // never happens
-}
-protected void setUp() throws Exception {
- super.setUp();
- IPath location = getRandomLocation();
- temp = location.append("temp").toFile();
- temp.mkdirs();
- assertTrue("could not create temp directory", temp.isDirectory());
-}
-public static Test suite() {
- return new TestSuite(SafeFileInputOutputStreamTest.class);
-}
-protected void tearDown() throws Exception {
- Workspace.clear(temp.getParentFile());
- super.tearDown();
-}
-public void testSafeFileInputStream() {
- File target = new File(temp, "target");
- Workspace.clear(target); // make sure there was nothing here before
- assertTrue("1.0", !target.exists());
- FileSystemStore store = new FileSystemStore();
-
- // define temp path
- Path parentLocation = new Path(target.getParentFile().getAbsolutePath());
- IPath tempLocation = parentLocation.append(target.getName() + ".backup");
-
- // we did not have a file on the destination, so we should not have a temp file
- SafeFileOutputStream safeStream = createSafeStream(target.getAbsolutePath(), tempLocation.toOSString(), "2.0");
- File tempFile = tempLocation.toFile();
- String contents = getRandomString();
- try {
- store.transferStreams(getContents(contents), safeStream, target.getAbsolutePath(), null);
- } catch (CoreException e) {
- fail("3.0", e);
- }
-
- // now we should have a temp file
- safeStream = createSafeStream(target.getAbsolutePath(), tempLocation.toOSString(), "4.0");
- tempFile = tempLocation.toFile();
- try {
- store.transferStreams(getContents(contents), safeStream, target.getAbsolutePath(), null);
- } catch (CoreException e) {
- fail("4.0", e);
- }
-
- assertTrue("5.0", target.exists());
- assertTrue("5.1", !tempFile.exists());
- InputStream diskContents;
- try {
- diskContents = new SafeFileInputStream(tempLocation.toOSString(), target.getAbsolutePath());
- assertTrue("5.2", compareContent(diskContents, getContents(contents)));
- } catch (IOException e) {
- fail("5.3", e);
- }
- Workspace.clear(target); // make sure there was nothing here before
-}
-public void testSimple() {
- File target = new File(temp, "target");
- Workspace.clear(target); // make sure there was nothing here before
- assertTrue("1.0", !target.exists());
- FileSystemStore store = new FileSystemStore();
-
- // basic use (like a FileOutputStream)
- SafeFileOutputStream safeStream = createSafeStream(target, "1.0");
- String contents = getRandomString();
- try {
- store.transferStreams(getContents(contents), safeStream, target.getAbsolutePath(), null);
- } catch (CoreException e) {
- fail("1.1", e);
- }
- InputStream diskContents = getContents(target, "1.2");
- assertTrue("1.3", compareContent(diskContents, getContents(contents)));
-
- // update target contents
- contents = getRandomString();
- safeStream = createSafeStream(target, "2.0");
- File tempFile = new File(safeStream.getTempFilePath());
- assertTrue("2.0", tempFile.exists());
- try {
- store.transferStreams(getContents(contents), safeStream, target.getAbsolutePath(), null);
- } catch (CoreException e) {
- fail("3.0", e);
- }
- diskContents = getContents(target, "3.1");
- assertTrue("3.2", compareContent(diskContents, getContents(contents)));
- assertTrue("3.3", !tempFile.exists());
- Workspace.clear(target); // make sure there was nothing here before
-}
-public void testSpecifiedTempFile() {
- File target = new File(temp, "target");
- Workspace.clear(target); // make sure there was nothing here before
- assertTrue("1.0", !target.exists());
- FileSystemStore store = new FileSystemStore();
-
- // define temp path
- Path parentLocation = new Path(target.getParentFile().getAbsolutePath());
- IPath tempLocation = parentLocation.append(target.getName() + ".backup");
-
- // we did not have a file on the destination, so we should not have a temp file
- SafeFileOutputStream safeStream = createSafeStream(target.getAbsolutePath(), tempLocation.toOSString(), "2.0");
- File tempFile = tempLocation.toFile();
- assertTrue("2.1", !tempFile.exists());
-
- // update target contents
- String contents = getRandomString();
- try {
- store.transferStreams(getContents(contents), safeStream, target.getAbsolutePath(), null);
- } catch (CoreException e) {
- fail("3.0", e);
- }
- InputStream diskContents = getContents(target, "3.1");
- assertTrue("3.2", compareContent(diskContents, getContents(contents)));
- assertTrue("3.3", !tempFile.exists());
-
- // now we should have a temp file
- safeStream = createSafeStream(target.getAbsolutePath(), tempLocation.toOSString(), "4.0");
- tempFile = tempLocation.toFile();
- assertTrue("4.1", tempFile.exists());
-
- // update target contents
- contents = getRandomString();
- try {
- store.transferStreams(getContents(contents), safeStream, target.getAbsolutePath(), null);
- } catch (CoreException e) {
- fail("5.0", e);
- }
- diskContents = getContents(target, "5.1");
- assertTrue("5.2", compareContent(diskContents, getContents(contents)));
- assertTrue("5.3", !tempFile.exists());
- Workspace.clear(target); // make sure there was nothing here before
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/UnifiedTreeTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/UnifiedTreeTest.java
deleted file mode 100644
index 973a237..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/UnifiedTreeTest.java
+++ /dev/null
@@ -1,221 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.localstore;
-
-import java.io.*;
-import java.util.Hashtable;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.localstore.*;
-import org.eclipse.core.internal.resources.Workspace;
-import org.eclipse.core.internal.utils.Policy;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-/**
- *
- */
-public class UnifiedTreeTest extends LocalStoreTest {
- protected static int limit = 10;
-public UnifiedTreeTest() {
- super();
-}
-public UnifiedTreeTest(String name) {
- super(name);
-}
-protected void createFiles(File folder, Hashtable set) throws CoreException {
- FileSystemStore store = new FileSystemStore();
- for (int i = 0; i < limit; i++) {
- File child = new File(folder, "fsFile" + i);
- InputStream input = new ByteArrayInputStream("contents".getBytes());
- store.write(child, input, false, Policy.monitorFor(null));
- String location = child.getAbsolutePath();
- set.put(location, "");
- }
-}
-protected void createFiles(final IContainer target, final Hashtable set) throws CoreException {
- final Workspace workspace = (Workspace) getWorkspace();
- IWorkspaceRunnable operation = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- for (int i = 0; i < limit; i++) {
- IFile child = target.getFile(new Path("wbFile" + i));
- workspace.createResource(child, false);
- String location = child.getLocation().toOSString();
- set.put(location, "");
- }
- }
- };
- workspace.run(operation, null);
-}
-protected void createResourcesInFileSystem(File folder, Hashtable set) throws CoreException {
- createFiles(folder, set);
- for (int i = 0; i < limit; i++) {
- File child = new File(folder, "fsFolder" + i);
- child.mkdirs();
- String location = child.getAbsolutePath();
- set.put(location, "");
- if (i < (limit / 2))
- createFiles(child, set);
- }
-}
-protected void createResourcesInWorkspace(IContainer target, Hashtable set) throws CoreException {
- createFiles(target, set);
- for (int i = 0; i < limit; i++) {
- IFolder child = target.getFolder(new Path("wbFolder" + i));
- child.create(true, true, null);
- String location = child.getLocation().toOSString();
- set.put(location, "");
- if (i < (limit / 2))
- createFiles(child, set);
- }
-}
-public static Test suite() {
- //TestSuite suite = new TestSuite();
- //suite.addTest(new UnifiedTreeTest("testTraverseMechanismInProjectWithMappings"));
- //return suite;
- return new TestSuite(UnifiedTreeTest.class);
-}
-/**
- * Creates some resources in the file system and some in the workspace. After that,
- * makes sure the visitor is going to walk through all of them.
- */
-public void testTraverseMechanismInFolder() throws Throwable {
- /* create common objects */
- IProject project = projects[0];
- IFolder folder = project.getFolder("root");
- folder.create(true, true, null);
-
- /* Create a hashtable to hold all resources the tree should visit.
- The resources are going to be removed from the hashtable as
- the visitor visits it. */
- final Hashtable set = new Hashtable();
-
- /* create some workspace structure */
- createResourcesInWorkspace(folder, set);
-
- /* create some file system structure */
- createResourcesInFileSystem(folder.getLocation().toFile(), set);
-
- /* create a visitor */
- IUnifiedTreeVisitor visitor = new IUnifiedTreeVisitor() {
- public boolean visit(UnifiedTreeNode node) throws CoreException {
-
- /* test the node.getLocalLocation() method */
- String key = node.getLocalLocation();
- assertEquals("1.0", node.getResource().getLocation().toOSString(), key);
-
- /* remove from the hashtable the resource we're visiting */
- set.remove(key);
- return true;
- }
- };
-
- /* instantiate a unified tree and use the visitor */
- UnifiedTree tree = new UnifiedTree(folder);
- tree.accept(visitor);
-
- /* if the hashtable is empty, we walked through all resources */
- assertTrue("2.0", set.isEmpty());
-}
-/**
- * Creates some resources in the file system and some in the workspace. After that,
- * makes sure the visitor is going to walk through some of them.
- */
-public void testTraverseMechanismInFolderSkipingSomeChildren() throws Throwable {
- /* create common objects */
- IProject project = projects[0];
- IFolder folder = project.getFolder("root");
- folder.create(true, true, null);
-
- /* Create a hashtable to hold all resources the tree should visit.
- The resources are going to be removed from the hashtable as
- the visitor visits it. */
- final Hashtable set = new Hashtable();
-
- /* create some workspace structure */
- createResourcesInWorkspace(folder, set);
-
- /* create some file system structure */
- createResourcesInFileSystem(folder.getLocation().toFile(), set);
-
- /* create a visitor */
- IUnifiedTreeVisitor visitor = new IUnifiedTreeVisitor() {
- public boolean visit(UnifiedTreeNode node) throws CoreException {
-
- /* test the node.getLocalLocation() method */
- String key = node.getLocalLocation();
- assertEquals("1.0", node.getResource().getLocation().toOSString(), key);;
-
- /* force children to be added to the queue */
- node.getChildren();
-
- /* skip some resources */
- if (node.getResource().getName().startsWith("fsFolder"))
- return false;
-
- /* remove from the hashtable the resource we're visiting */
- set.remove(key);
- return true;
- }
- };
-
-
- /**/
- int initialSize = set.size();
-
- /* instantiate a unified tree and use the visitor */
- UnifiedTree tree = new UnifiedTree(folder);
- tree.accept(visitor);
-
- /* if the hashtable is empty, we walked through all resources */
- assertTrue("2.0", !set.isEmpty());
- assertTrue("2.1", set.size() != initialSize);
-}
-/**
- * Creates some resources in the file system and some in the workspace. After that,
- * makes sure the visitor is going to walk through all of them.
- */
-public void testTraverseMechanismInProject() throws Throwable {
- /* create common objects */
- IProject project = projects[0];
-
- /* Create a hashtable to hold all resources the tree should visit.
- The resources are going to be removed from the hashtable as
- the visitor visits it. */
- final Hashtable set = new Hashtable();
-
- /* create some workspace structure */
- createResourcesInWorkspace(project, set);
-
- /* create some file system structure */
- createResourcesInFileSystem(project.getLocation().toFile(), set);
-
- /* create a visitor */
- IUnifiedTreeVisitor visitor = new IUnifiedTreeVisitor() {
- public boolean visit(UnifiedTreeNode node) throws CoreException {
-
- /* test the node.getLocalLocation() method */
- String key = node.getLocalLocation();
- assertEquals("1.0", node.getResource().getLocation().toOSString(), key);
- /* remove from the hashtable the resource we're visiting */
- set.remove(key);
- return true;
- }
- };
-
- /* instantiate a unified tree and use the visitor */
- UnifiedTree tree = new UnifiedTree(project);
- tree.accept(visitor);
-
- /* if the hashtable is empty, we walked through all resources */
- assertTrue("2.0", set.isEmpty());
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/properties/AllTests.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/properties/AllTests.java
deleted file mode 100644
index a7ec737..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/properties/AllTests.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.properties;
-
-
-import junit.framework.*;
-
-public class AllTests extends TestCase {
-public AllTests() {
- super(null);
-}
-public AllTests(String name) {
- super(name);
-}
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(PropertyManagerTest.suite());
- return suite;
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/properties/PropertyManagerTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/properties/PropertyManagerTest.java
deleted file mode 100644
index d44c246..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/properties/PropertyManagerTest.java
+++ /dev/null
@@ -1,419 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.properties;
-
-
-import java.util.Enumeration;
-import java.util.Vector;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.properties.PropertyManager;
-import org.eclipse.core.internal.properties.StoredProperty;
-import org.eclipse.core.internal.resources.Resource;
-import org.eclipse.core.internal.resources.Workspace;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.internal.localstore.LocalStoreTest;
-
-public class PropertyManagerTest extends LocalStoreTest {
-
-public PropertyManagerTest() {
- super(null);
-}
-public PropertyManagerTest(String name) {
- super(name);
-}
-public static Test suite() {
-// TestSuite suite = new TestSuite();
-// suite.addTest(new PropertyManagerTest("testConcurrentDelete"));
-// return suite;
- return new TestSuite(PropertyManagerTest.class);
-}
-/**
- * Tests concurrent acces to the property store.
- */
-public void testConcurrentAccess() {
-
- // create common objects
- final IFile target = projects[0].getFile("target");
- try {
- target.create(getRandomContents(), true, getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- // prepare keys and values
- final int N = 50;
- final QualifiedName[] names = new QualifiedName[N];
- final String[] values = new String[N];
- createProperties(target, names, values);
-
- final int THREAD_COUNT = 3;
- final CoreException[] errorPointer = new CoreException[1];
- Thread[] threads = createThreads(target, names, values, errorPointer);
- join(threads);
- if (errorPointer[0] != null)
- fail("2.0", errorPointer[0]);
-
- // remove trash
- try {
- target.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("20.0", e);
- }
-}
-/**
- * Tests concurrent access to the property store while the project is being
- * deleted.
- */
-public void testConcurrentDelete() {
- Thread[] threads;
- final IFile target = projects[0].getFile("target");
- final int REPEAT = 8;
- for (int i = 0; i < REPEAT;i++) {
- // create common objects
- ensureExistsInWorkspace(projects[0], true);
- ensureExistsInWorkspace(target, true);
-
- // prepare keys and values
- final int N = 50;
- final QualifiedName[] names = new QualifiedName[N];
- final String[] values = new String[N];
- createProperties(target, names, values);
-
- final CoreException[] errorPointer = new CoreException[1];
- threads = createThreads(target, names, values, errorPointer);
- try {
- //give the threads a chance to start
- Thread.sleep(10);
- } catch (InterruptedException e1) {
- }
- try {
- //delete the project while the threads are still running
- target.getProject().delete(IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("1.99." + i);
- }
- join(threads);
- if (errorPointer[0] != null)
- fail("2.0." + i, errorPointer[0]);
- }
- // remove trash
- try {
- target.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("20.0", e);
- }
-}
-private void join(Thread[] threads) {
- //wait for all threads to finish
- for (int j = 0; j < threads.length; j++) {
- try {
- threads[j].join();
- } catch (InterruptedException e) {
- }
- }
-}
-private Thread[] createThreads(final IFile target, final QualifiedName[] names, final String[] values, final CoreException[] errorPointer) {
- final int THREAD_COUNT = 3;
- Thread[] threads = new Thread[THREAD_COUNT];
- for (int j = 0; j < THREAD_COUNT; j++) {
- final String id = "GetSetProperty" + j;
- threads[j] = new Thread(new Runnable() {
- public void run() {
- try {
- doGetSetProperties(target, id, names, values);
- } catch (CoreException e) {
- //ignore failure if the project has been deleted
- if (target.exists()) {
- e.printStackTrace();
- errorPointer[0] = e;
- return;
- }
- }
- }
- }, id);
- threads[j].start();
- }
- return threads;
-}
-private void createProperties(IFile target, QualifiedName[] names, String[] values) {
- for (int i = 0; i < names.length; i++) {
- names[i] = new QualifiedName("org.eclipse.core.tests", "prop" + i);
- values[i] = "property value" + i;
- }
- // create properties
- for (int i = 0; i < names.length; i++) {
- try {
- target.setPersistentProperty(names[i], values[i]);
- } catch (CoreException e) {
- fail("1." + i, e);
- }
- }
-}
-protected void doGetSetProperties(IFile target, String threadID, QualifiedName[] names, String[] values) throws CoreException {
- final int N = names.length;
- for (int j = 0; j < 10; j++) {
- for (int i = 0; i < N; i++) {
- target.getPersistentProperty(names[i]);
- }
- // change properties
- for (int i = 0; i < N; i++) {
-// values[i] = values[i] + " - changed (" + threadID + ")";
- target.setPersistentProperty(names[i], values[i]);
- }
- // verify
- for (int i = 0; i < N; i++) {
- target.getPersistentProperty(names[i]);
- }
- }
-}
-public void testCopy() throws Throwable {
- PropertyManager manager = new PropertyManager((Workspace) getWorkspace());
- IProject source = projects[0];
- IFolder sourceFolder = source.getFolder("myfolder");
- IResource sourceFile = sourceFolder.getFile("myfile.txt");
- IProject destination = projects[1];
- IFolder destFolder = destination.getFolder(sourceFolder.getName());
- IResource destFile = destFolder.getFile(sourceFile.getName());
- QualifiedName propName = new QualifiedName("test", "prop");
- String propValue = "this is the property value";
-
- /*
- * persistent properties
- */
- manager.setProperty(source, propName, propValue);
- manager.setProperty(sourceFolder, propName, propValue);
- manager.setProperty(sourceFile, propName, propValue);
-
- assertNotNull("1.1", manager.getProperty(source, propName));
- assertTrue("1.2", manager.getProperty(source, propName).equals(propValue));
- assertNotNull("1.3", manager.getProperty(sourceFolder, propName));
- assertTrue("1.4", manager.getProperty(sourceFolder, propName).equals(propValue));
- assertNotNull("1.5", manager.getProperty(sourceFile, propName));
- assertTrue("1.6", manager.getProperty(sourceFile, propName).equals(propValue));
-
- // do the copy at the project level
- manager.copy(source, destination, IResource.DEPTH_INFINITE);
-
- assertNotNull("1.7", manager.getProperty(destination, propName));
- assertTrue("1.8", manager.getProperty(destination, propName).equals(propValue));
-
- assertNotNull("1.9", manager.getProperty(destFolder, propName));
- assertTrue("1.10", manager.getProperty(destFolder, propName).equals(propValue));
- assertNotNull("1.11", manager.getProperty(destFile, propName));
- assertTrue("1.12", manager.getProperty(destFile, propName).equals(propValue));
-
- // do the same thing but copy at the folder level
- manager.deleteProperties(source, IResource.DEPTH_INFINITE);
- manager.deleteProperties(destination, IResource.DEPTH_INFINITE);
- assertNull("2.0", manager.getProperty(source, propName));
- assertNull("2.1", manager.getProperty(sourceFolder, propName));
- assertNull("2.2", manager.getProperty(sourceFile, propName));
- assertNull("2.3", manager.getProperty(destination, propName));
- assertNull("2.4", manager.getProperty(destFolder, propName));
- assertNull("2.5", manager.getProperty(destFile, propName));
- manager.setProperty(sourceFolder, propName, propValue);
- manager.setProperty(sourceFile, propName, propValue);
- assertNotNull("2.6", manager.getProperty(sourceFolder, propName));
- assertTrue("2.7", manager.getProperty(sourceFolder, propName).equals(propValue));
- assertNotNull("2.8", manager.getProperty(sourceFile, propName));
- assertTrue("2.9", manager.getProperty(sourceFile, propName).equals(propValue));
-
- manager.copy(sourceFolder, destFolder, IResource.DEPTH_INFINITE);
-
- assertNotNull("2.10", manager.getProperty(destFolder, propName));
- assertTrue("2.11", manager.getProperty(destFolder, propName).equals(propValue));
- assertNotNull("2.12", manager.getProperty(destFile, propName));
- assertTrue("2.13", manager.getProperty(destFile, propName).equals(propValue));
-
- /* test overwrite */
- String newPropValue = "change property value";
- manager.setProperty(source, propName, newPropValue);
- assertTrue("2.0", manager.getProperty(source, propName).equals(newPropValue));
- manager.copy(source, destination, IResource.DEPTH_INFINITE);
- assertTrue("2.1", manager.getProperty(destination, propName).equals(newPropValue));
-}
-public void testDeleteProperties() throws Throwable {
- /* create common objects */
- PropertyManager manager = new PropertyManager((Workspace) getWorkspace());
- IFile target = projects[0].getFile("target");
-
- /* server properties */
- QualifiedName propName = new QualifiedName("eclipse", "prop");
- String propValue = "this is the property value";
- manager.setProperty(target, propName, propValue);
- assertTrue("1.1", manager.getProperty(target, propName).equals(propValue));
- /* delete */
- manager.deleteProperties((Resource) target, IResource.DEPTH_INFINITE);
- assertTrue("1.3", manager.getProperty(target, propName) == null);
-
- //test deep deletion of project properties
- IProject source = projects[0];
- IFolder sourceFolder = source.getFolder("myfolder");
- IResource sourceFile = sourceFolder.getFile("myfile.txt");
- propName = new QualifiedName("test", "prop");
- propValue = "this is the property value";
-
- /*
- * persistent properties
- */
- manager.setProperty(source, propName, propValue);
- manager.setProperty(sourceFolder, propName, propValue);
- manager.setProperty(sourceFile, propName, propValue);
-
- assertNotNull("2.1", manager.getProperty(source, propName));
- assertTrue("2.2", manager.getProperty(source, propName).equals(propValue));
- assertNotNull("2.3", manager.getProperty(sourceFolder, propName));
- assertTrue("2.4", manager.getProperty(sourceFolder, propName).equals(propValue));
- assertNotNull("2.5", manager.getProperty(sourceFile, propName));
- assertTrue("2.6", manager.getProperty(sourceFile, propName).equals(propValue));
-
- //delete properties
- manager.deleteProperties(source, IResource.DEPTH_INFINITE);
- assertNull("3.1", manager.getProperty(source, propName));
- assertNull("3.2", manager.getProperty(sourceFolder, propName));
- assertNull("3.3", manager.getProperty(sourceFile, propName));
-
-}
-/**
- * Do a stress test by adding a very large property to the store.
- */
-public void testLargeProperty() {
- // create common objects
- IFile target = projects[0].getFile("target");
- try {
- target.create(getRandomContents(), true, getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- QualifiedName name = new QualifiedName("stressTest", "prop");
- final int SIZE = 10000;
- StringBuffer valueBuf = new StringBuffer(SIZE);
- for (int i = 0; i < SIZE; i++) {
- valueBuf.append("a");
- }
- String value = valueBuf.toString();
- try {
- target.setPersistentProperty(name, value);
- //should fail
- fail("1.0");
- } catch (CoreException e) {
- }
-
- // remove trash
- try {
- target.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("20.0", e);
- }
-}
-public void testProperties() throws Throwable {
- IProgressMonitor monitor = null;
-
- // create common objects
- PropertyManager manager = new PropertyManager((Workspace) getWorkspace());
- IFile target = projects[0].getFile("target");
- target.create(null, false, monitor);
-
- // these are the properties that we are going to use
- QualifiedName propName1 = new QualifiedName("org.eclipse.core.tests", "prop1");
- QualifiedName propName2 = new QualifiedName("org.eclipse.core.tests", "prop2");
- QualifiedName propName3 = new QualifiedName("org.eclipse.core.tests", "prop3");
- String propValue1 = "this is the property value1";
- String propValue2 = "this is the property value2";
- String propValue3 = "this is the property value3";
- Vector props = new Vector(3);
- props.addElement(new StoredProperty(propName1, propValue1));
- props.addElement(new StoredProperty(propName2, propValue2));
- props.addElement(new StoredProperty(propName3, propValue3));
-
- // set the properties individually and retrieve them
- for (Enumeration e = props.elements(); e.hasMoreElements();) {
- StoredProperty prop = (StoredProperty) e.nextElement();
- manager.setProperty(target, prop.getName(), prop.getStringValue());
- assertTrue("1.0." + prop.getName(), prop.getStringValue().equals(manager.getProperty(target, prop.getName())));
- }
- manager.deleteProperties((Resource) target, IResource.DEPTH_INFINITE);
-
- // remove trash
- target.delete(false, monitor);
-}
-public void testSimpleUpdate() {
-
- // create common objects
- IFile target = projects[0].getFile("target");
- try {
- target.create(getRandomContents(), true, getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- // prepare keys and values
- int N = 3;
- QualifiedName[] names = new QualifiedName[3];
- String[] values = new String[N];
- for (int i = 0; i < N; i++) {
- names[i] = new QualifiedName("org.eclipse.core.tests", "prop" + i);
- values[i] = "property value" + i;
- }
-
- // create properties
- for (int i = 0; i < N; i++) {
- try {
- target.setPersistentProperty(names[i], values[i]);
- } catch (CoreException e) {
- fail("1." + i, e);
- }
- }
-
- // verify
- for (int i = 0; i < N; i++) {
- try {
- assertTrue("2.0", target.getPersistentProperty(names[i]).equals(values[i]));
- } catch (CoreException e) {
- fail("3." + i, e);
- }
- }
-
- for (int j = 0; j < 20; j++) {
-
- // change properties
- for (int i = 0; i < N; i++) {
- try {
- values[i] = values[i] + " - changed";
- target.setPersistentProperty(names[i], values[i]);
- } catch (CoreException e) {
- fail("4." + i, e);
- }
- }
-
- // verify
- for (int i = 0; i < N; i++) {
- try {
- assertTrue("5.0", target.getPersistentProperty(names[i]).equals(values[i]));
- } catch (CoreException e) {
- fail("6." + i, e);
- }
- }
-
- }
-
- // remove trash
- try {
- target.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("20.0", e);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/AllTests.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/AllTests.java
deleted file mode 100644
index 28d8383..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/AllTests.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.resources;
-
-
-import junit.framework.*;
-
-public class AllTests extends TestCase {
-/**
- * AllTests constructor comment.
- * @param name java.lang.String
- */
-public AllTests() {
- super(null);
-}
-/**
- * AllTests constructor comment.
- * @param name java.lang.String
- */
-public AllTests(String name) {
- super(name);
-}
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(ModelObjectReaderWriterTest.suite());
- suite.addTest(ResourceInfoTest.suite());
- suite.addTest(WorkspacePreferencesTest.suite());
- return suite;
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/Bug29116Nature.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/Bug29116Nature.java
deleted file mode 100644
index 5df2b3b..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/Bug29116Nature.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.resources;
-
-import java.util.HashMap;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.tests.internal.builders.SortBuilder;
-
-/**
- * Nature for testing regression of bug 29116.
- */
-public class Bug29116Nature extends TestNature {
- /**
- * Constructor for Bug29116Nature.
- */
- public Bug29116Nature() {
- super();
- }
- /**
- * @see org.eclipse.core.resources.IProjectNature#configure()
- */
- public void configure() throws CoreException {
- //install the snow builder
- IProject project = getProject();
- IProjectDescription desc = project.getDescription();
- ICommand[] oldSpec = desc.getBuildSpec();
- ICommand[] newSpec = new ICommand[oldSpec.length+1];
- System.arraycopy(oldSpec, 0, newSpec, 0, oldSpec.length);
- ICommand newCommand = desc.newCommand();
- newCommand.setBuilderName(SortBuilder.BUILDER_NAME);
- HashMap args = new HashMap(20);
- newCommand.setArguments(args);
- newSpec[oldSpec.length] = newCommand;
- desc.setBuildSpec(newSpec);
- project.setDescription(desc, IResource.FORCE | IResource.KEEP_HISTORY, null);
-
- //run the builder (this should cause the error)
- project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, SortBuilder.BUILDER_NAME, args, null);
- }
-
- /**
- * @see org.eclipse.core.resources.IProjectNature#setProject(org.eclipse.core.resources.IProject)
- */
- public void setProject(IProject project) {
- super.setProject(project);
- }
-
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/EarthNature.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/EarthNature.java
deleted file mode 100644
index 777e88f..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/EarthNature.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.resources;
-
-/**
- */
-public class EarthNature extends TestNature {
-/**
- * Constructor for EarthNature.
- */
-public EarthNature() {
- super();
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ModelObjectReaderWriterTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ModelObjectReaderWriterTest.java
deleted file mode 100644
index 2bc1f4a..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ModelObjectReaderWriterTest.java
+++ /dev/null
@@ -1,825 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.resources;
-
-
-import java.io.*;
-import java.net.URL;
-import java.util.*;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.localstore.SafeFileOutputStream;
-import org.eclipse.core.internal.plugins.PluginDescriptor;
-import org.eclipse.core.internal.resources.*;
-import org.eclipse.core.internal.utils.Policy;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-import org.xml.sax.InputSource;
-/**
- *
- */
-public class ModelObjectReaderWriterTest extends EclipseWorkspaceTest {
- static final IPath LONG_LOCATION = new Path("D:/eclipse/dev/i0218/eclipse/pffds/fds//fds///fdsfsdfsd///fdsfdsf/fsdfsdfsd/lugi/dsds/fsd//f/ffdsfdsf/fsdfdsfsd/fds//fdsfdsfdsf/fdsfdsfds/fdsfdsfdsf/fdsfdsfdsds/ns/org.eclipse.help.ui_2.1.0/contexts.xml");
-public ModelObjectReaderWriterTest() {
-}
-public ModelObjectReaderWriterTest(String name) {
- super(name);
-}
-protected boolean contains(Object key, Object[] array) {
- for (int i = 0; i < array.length; i++)
- if (key.equals(array[i]))
- return true;
- return false;
-}
-protected String getInvalidWorkspaceDescription() {
- return
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
- "<workspaceDescription>\n" +
- "<name>Foo</name>\n" +
- "<autobuild>Foo</autobuild>\n" +
- "<snapshotInterval>300Foo000</snapshotInterval>\n" +
- "<fileStateLongevity>Foo480000</fileStateLongevity>\n" +
- "<maxFileStateSize>104856Foo</maxFileStateSize>\n" +
- "<maxFileStates>5Foo0</maxFileStates>\n" +
- "</workspaceDescription>\n";
-}
-public static Test suite() {
-// TestSuite suite = new TestSuite();
-// suite.addTest(new ModelObjectReaderWriterTest("testMultipleProjectDescriptions"));
-// return suite;
- return new TestSuite(ModelObjectReaderWriterTest.class);
-}
-public void testProjectDescription() throws Throwable {
- // Use ModelObject2 to read the project description
-
- /* initialize common objects */
- ModelObjectWriter writer = new ModelObjectWriter();
- ProjectDescriptionReader reader = new ProjectDescriptionReader();
- IPath root = getWorkspace().getRoot().getLocation();
- IPath location = root.append("ModelObjectWriterTest2.pbs");
- /* test write */
- ProjectDescription description = new ProjectDescription();
- description.setLocation(location);
- description.setName("MyProjectDescription");
- HashMap args = new HashMap(3);
- args.put("ArgOne", "ARGH!");
- args.put("ArgTwo", "2 x ARGH!");
- args.put("NullArg", null);
- args.put("EmptyArg", "");
- ICommand[] commands = new ICommand[2];
- commands[0] = description.newCommand();
- commands[0].setBuilderName("MyCommand");
- commands[0].setArguments(args);
- commands[1] = description.newCommand();
- commands[1].setBuilderName("MyOtherCommand");
- commands[1].setArguments(args);
- description.setBuildSpec(commands);
-
- SafeFileOutputStream output = new SafeFileOutputStream(location.toFile());
- writer.write(description, output);
- output.close();
-
- /* test read */
- FileInputStream input = new FileInputStream(location.toFile());
- InputSource in = new InputSource(input);
- ProjectDescription description2 = reader.read(in);
- assertTrue("1.1", description.getName().equals(description2.getName()));
- assertTrue("1.3", location.equals(description.getLocation()));
-
- ICommand[] commands2 = description2.getBuildSpec();
- assertEquals("2.00", 2, commands2.length);
- assertEquals("2.01", "MyCommand", commands2[0].getBuilderName());
- assertEquals("2.02", "ARGH!", commands2[0].getArguments().get("ArgOne"));
- assertEquals("2.03", "2 x ARGH!", commands2[0].getArguments().get("ArgTwo"));
- assertEquals("2.04", "", commands2[0].getArguments().get("NullArg"));
- assertEquals("2.05", "", commands2[0].getArguments().get("EmptyArg"));
- assertEquals("2.06", "MyOtherCommand", commands2[1].getBuilderName());
- assertEquals("2.07", "ARGH!", commands2[1].getArguments().get("ArgOne"));
- assertEquals("2.08", "2 x ARGH!", commands2[1].getArguments().get("ArgTwo"));
- assertEquals("2.09", "", commands2[0].getArguments().get("NullArg"));
- assertEquals("2.10", "", commands2[0].getArguments().get("EmptyArg"));
-
- /* remove trash */
- Workspace.clear(location.toFile());
-}
-public void testProjectDescription2() throws Throwable {
- // Use ModelObject2 to read the project description
-
- /* initialize common objects */
- ModelObjectWriter writer = new ModelObjectWriter();
- ProjectDescriptionReader reader = new ProjectDescriptionReader();
- IPath root = getWorkspace().getRoot().getLocation();
- IPath location = root.append("ModelObjectWriterTest3.pbs");
- /* test write */
- ProjectDescription description = new ProjectDescription();
- description.setLocation(location);
- description.setName("MyProjectDescription");
- HashMap args = new HashMap(3);
- args.put("ArgOne", "ARGH!");
- ICommand[] commands = new ICommand[1];
- commands[0] = description.newCommand();
- commands[0].setBuilderName("MyCommand");
- commands[0].setArguments(args);
- description.setBuildSpec(commands);
- String comment = "Now is the time for all good men to come to the aid of the party. Now is the time for all good men to come to the aid of the party. Now is the time for all good men to come to the aid of the party.";
- description.setComment(comment);
- IProject[] refProjects = new IProject[3];
- refProjects[0] = ResourcesPlugin.getWorkspace().getRoot().getProject("org.eclipse.core.runtime");
- refProjects[1] = ResourcesPlugin.getWorkspace().getRoot().getProject("org.eclipse.core.boot");
- refProjects[2] = ResourcesPlugin.getWorkspace().getRoot().getProject("org.eclipse.core.resources");
- description.setReferencedProjects(refProjects);
-
- SafeFileOutputStream output = new SafeFileOutputStream(location.toFile());
- writer.write(description, output);
- output.close();
-
- /* test read */
- FileInputStream input = new FileInputStream(location.toFile());
- InputSource in = new InputSource(input);
- ProjectDescription description2 = reader.read(in);
- assertTrue("1.1", description.getName().equals(description2.getName()));
- assertTrue("1.3", location.equals(description.getLocation()));
-
- ICommand[] commands2 = description2.getBuildSpec();
- assertEquals("2.00", 1, commands2.length);
- assertEquals("2.01", "MyCommand", commands2[0].getBuilderName());
- assertEquals("2.02", "ARGH!", commands2[0].getArguments().get("ArgOne"));
-
- assertTrue("3.0", description.getComment().equals(description2.getComment()));
-
- IProject[] ref = description.getReferencedProjects();
- IProject[] ref2 = description2.getReferencedProjects();
- assertEquals("4.0", 3, ref2.length);
- assertTrue("4.1", ref[0].getName().equals(ref2[0].getName()));
- assertTrue("4.2", ref[1].getName().equals(ref2[1].getName()));
- assertTrue("4.3", ref[2].getName().equals(ref2[2].getName()));
-
- /* remove trash */
- Workspace.clear(location.toFile());
-}
-public void testInvalidWorkspaceDescription() {
- /* initialize common objects */
- WorkspaceDescriptionReader reader = new WorkspaceDescriptionReader();
- IPath root = getWorkspace().getRoot().getLocation();
- IPath location = root.append("ModelObjectWriterTest2.pbs");
-
- /* write the bogus description */
- try {
- FileWriter writer = new FileWriter(location.toFile());
- writer.write(getInvalidWorkspaceDescription());
- writer.close();
- } catch (IOException e) {
- fail("1.91", e);
- }
-
- /* test read */
- try {
- FileInputStream input = null;
- try {
- input = new FileInputStream(location.toFile());
- } catch (FileNotFoundException e) {
- fail("1.99", e);
- }
- //on reading invalid values the reader should revert to default values
- WorkspaceDescription desc2 = (WorkspaceDescription) reader.read(input);
- //assertion "1.1" removed because workspace name can't be invalid
- assertTrue("1.2", Policy.defaultAutoBuild == desc2.isAutoBuilding());
- assertTrue("1.3", Policy.defaultDeltaExpiration == desc2.getDeltaExpiration());
- assertTrue("1.4", Policy.defaultFileStateLongevity == desc2.getFileStateLongevity());
- assertTrue("1.5", Policy.defaultMaxFileStates == desc2.getMaxFileStates());
- assertTrue("1.6", Policy.defaultMaxFileStateSize == desc2.getMaxFileStateSize());
- assertTrue("1.7", Policy.defaultOperationsPerSnapshot == desc2.getOperationsPerSnapshot());
- assertTrue("1.8", Policy.defaultSnapshots == desc2.isSnapshotEnabled());
- } finally {
- /* remove trash */
- Workspace.clear(location.toFile());
- }
-}
-private String[] getPathMembers(URL path) {
- String[] list = null;
- String protocol = path.getProtocol();
- if (protocol.equals("file")) { //$NON-NLS-1$
- list = (new java.io.File(path.getFile())).list();
- } else {
- // XXX: attempt to read URL and see if we got html dir page
- }
- return list == null ? new String[0] : list;
-}
-private void compareProjectDescriptions (int errorTag, ProjectDescription description, ProjectDescription description2) {
- assertTrue (errorTag + ".0", description.getName().equals(description2.getName()));
- String comment = description.getComment();
- if (comment == null) {
- // The old reader previously returned null for an empty comment. We
- // are changing this so it now returns an empty string.
- assertEquals (errorTag + ".1", 0, description2.getComment().length());
- } else
- assertTrue (errorTag + ".2", description.getComment().equals(description2.getComment()));
-
- IProject[] projects = description.getReferencedProjects();
- IProject[] projects2 = description2.getReferencedProjects();
- compareProjects(errorTag, projects, projects2);
-
- ICommand[] commands = description.getBuildSpec();
- ICommand[] commands2 = description2.getBuildSpec();
- compareBuildSpecs(errorTag, commands, commands2);
-
- String[] natures = description.getNatureIds();
- String[] natures2 = description2.getNatureIds();
- compareNatures(errorTag, natures, natures2);
-
- HashMap links = description.getLinks();
- HashMap links2 = description2.getLinks();
- compareLinks(errorTag, links, links2);
-}
-private void compareProjects (int errorTag, IProject[] projects, IProject[] projects2) {
- // ASSUMPTION: projects and projects2 are non-null
- assertEquals (errorTag + ".1.0", projects.length, projects2.length);
- for (int i = 0; i < projects.length; i++) {
- assertTrue(errorTag + ".1." + (i + 1), projects[i].getName().equals(projects2[i].getName()));
- }
-}
-private void compareBuildSpecs (int errorTag, ICommand[] commands, ICommand[] commands2) {
- // ASSUMPTION: commands and commands2 are non-null
- assertEquals (errorTag + ".2.0", commands.length, commands2.length);
- for (int i = 0; i < commands.length; i++) {
- assertTrue(errorTag + ".2." + (i + 1) + "0", commands[i].getBuilderName().equals(commands2[i].getBuilderName()));
- Map args = commands[i].getArguments();
- Map args2 = commands2[i].getArguments();
- assertEquals (errorTag + ".2." + (i + 1) + "0", args.size(), args2.size());
- Set keys = args.keySet();
- int x = 1;
- for (Iterator j = keys.iterator(); j.hasNext(); x++) {
- Object key = j.next();
- String value = (String)args.get(key);
- String value2 = (String)args2.get(key);
- if (value == null)
- assertNull(errorTag + ".2." + (i + 1) + x, value2);
- else
- assertTrue(errorTag + ".3." + (i + 1) + x, ((String)args.get(key)).equals(((String)args2.get(key))));
- }
- }
-}
-private void compareNatures (int errorTag, String[] natures, String[] natures2) {
- // ASSUMPTION: natures and natures2 are non-null
- assertEquals (errorTag + ".3.0", natures.length, natures2.length);
- for (int i = 0; i < natures.length; i++) {
- assertTrue(errorTag + ".3." + (i + 1), natures[i].equals(natures2[i]));
- }
-}
-
-public void testInvalidProjectDescription4() throws Throwable {
- String invalidProjectDescription =
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
- "<projectDescription>\n" +
- " <name>abc</name>\n" +
- " <comment></comment>\n" +
- " <projects>\n" +
- " </projects>\n" +
- " <buildSpec>\n" +
- " </buildSpec>\n" +
- " <natures>\n" +
- " </natures>\n" +
- " <linkedResources>\n" +
- " <link>\n" +
- " <name>newLink</name>\n" +
- " <type>foobar</type>\n" +
- " <location>d:/abc/def</location>\n" +
- " </link>\n" +
- " </linkedResources>\n" +
- "</projectDescription>";
-
- IPath root = getWorkspace().getRoot().getLocation();
- IPath location = root.append("ModelObjectReaderWriterTest.txt");
- ProjectDescriptionReader reader = new ProjectDescriptionReader();
- // Write out the project description file
- ensureDoesNotExistInFileSystem(location.toFile());
- InputStream stream = new ByteArrayInputStream(invalidProjectDescription.getBytes());
- createFileInFileSystem(location, stream);
- try {
- ProjectDescription projDesc = reader.read(location);
-
- assertNotNull ("3.0", projDesc);
- assertTrue("3.1", projDesc.getName().equals("abc"));
- assertEquals("3.2", 0, projDesc.getComment().length());
- assertNull("3.3", projDesc.getLocation());
- assertEquals("3.4", new IProject[0], projDesc.getReferencedProjects());
- assertEquals("3.5", new String[0], projDesc.getNatureIds());
- assertEquals("3.6", new ICommand[0], projDesc.getBuildSpec());
- LinkDescription link = (LinkDescription)projDesc.getLinks().values().iterator().next();
- assertEquals("3.7", "newLink", link.getName());
- assertEquals("3.8", "d:/abc/def", link.getLocation().toString());
- } finally {
- Workspace.clear(location.toFile());
- }
-}
-private void compareLinks (int errorTag, HashMap links, HashMap links2) {
- if (links == null) {
- assertNull (errorTag + ".4.0", links2);
- return;
- }
- assertEquals (errorTag + ".4.01", links.size(), links2.size());
- Set keys = links.keySet();
- int x = 1;
- for (Iterator i = keys.iterator(); i.hasNext(); x++) {
- String key = (String)i.next();
- LinkDescription value = (LinkDescription)links.get(key);
- LinkDescription value2 = (LinkDescription)links2.get(key);
- assertTrue(errorTag + ".4." + x, value.getName().equals(value2.getName()));
- assertEquals(errorTag + ".5." + x, value.getType(), value2.getType());
- assertTrue(errorTag + ".6." + x, value.getLocation().equals(value2.getLocation()));
- }
-}
-public void testInvalidProjectDescription1() throws Throwable {
- String invalidProjectDescription =
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
- "<homeDescription>\n" +
- " <name>abc</name>\n" +
- " <comment></comment>\n" +
- " <projects>\n" +
- " </projects>\n" +
- " <buildSpec>\n" +
- " <buildCommand>\n" +
- " <name>org.eclipse.jdt.core.javabuilder</name>\n" +
- " <arguments>\n" +
- " </arguments>\n" +
- " </buildCommand>\n" +
- " </buildSpec>\n" +
- " <natures>\n" +
- " <nature>org.eclipse.jdt.core.javanature</nature>\n" +
- " </natures>\n" +
- " <linkedResources>\n" +
- " <link>\n" +
- " <name>newLink</name>\n" +
- " <type>2</type>\n" +
- " <location>d:/abc/def</location>\n" +
- " </link>\n" +
- " </linkedResources>\n" +
- "</homeDescription>";
-
- IPath root = getWorkspace().getRoot().getLocation();
- IPath location = root.append("ModelObjectReaderWriterTest.txt");
- ProjectDescriptionReader reader = new ProjectDescriptionReader();
- // Write out the project description file
- ensureDoesNotExistInFileSystem(location.toFile());
- InputStream stream = new ByteArrayInputStream(invalidProjectDescription.getBytes());
- createFileInFileSystem(location, stream);
- try {
- ProjectDescription projDesc = reader.read(location);
-
- assertNull ("1.0", projDesc);
- } finally {
- Workspace.clear(location.toFile());
- }
-}
-public void testInvalidProjectDescription2() throws Throwable {
- String invalidProjectDescription =
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
- "<projectDescription>\n" +
- " <bogusname>abc</bogusname>\n" +
- "</projectDescription>";
-
- IPath root = getWorkspace().getRoot().getLocation();
- IPath location = root.append("ModelObjectReaderWriterTest.txt");
- ProjectDescriptionReader reader = new ProjectDescriptionReader();
- // Write out the project description file
- ensureDoesNotExistInFileSystem(location.toFile());
- InputStream stream = new ByteArrayInputStream(invalidProjectDescription.getBytes());
- createFileInFileSystem(location, stream);
- try {
- ProjectDescription projDesc = reader.read(location);
-
- assertNotNull ("2.0", projDesc);
- assertNull("2.1", projDesc.getName());
- assertEquals("2.2", 0, projDesc.getComment().length());
- assertNull("2.3", projDesc.getLocation());
- assertEquals("2.4", new IProject[0], projDesc.getReferencedProjects());
- assertEquals("2.5", new String[0], projDesc.getNatureIds());
- assertEquals("2.6", new ICommand[0], projDesc.getBuildSpec());
- assertNull("2.7", projDesc.getLinks());
- } finally {
- Workspace.clear(location.toFile());
- }
-}
-public void testInvalidProjectDescription3() throws Throwable {
- String invalidProjectDescription =
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
- "<projectDescription>\n" +
- " <name>abc</name>\n" +
- " <comment></comment>\n" +
- " <projects>\n" +
- " </projects>\n" +
- " <buildSpec>\n" +
- " <badBuildCommand>\n" +
- " <name>org.eclipse.jdt.core.javabuilder</name>\n" +
- " <arguments>\n" +
- " </arguments>\n" +
- " </badBuildCommand>\n" +
- " </buildSpec>\n" +
- "</projectDescription>";
-
- IPath root = getWorkspace().getRoot().getLocation();
- IPath location = root.append("ModelObjectReaderWriterTest.txt");
- ProjectDescriptionReader reader = new ProjectDescriptionReader();
- // Write out the project description file
- ensureDoesNotExistInFileSystem(location.toFile());
- InputStream stream = new ByteArrayInputStream(invalidProjectDescription.getBytes());
- createFileInFileSystem(location, stream);
- try {
- ProjectDescription projDesc = reader.read(location);
-
- assertNotNull ("3.0", projDesc);
- assertTrue("3.1", projDesc.getName().equals("abc"));
- assertEquals("3.2", 0, projDesc.getComment().length());
- assertNull("3.3", projDesc.getLocation());
- assertEquals("3.4", new IProject[0], projDesc.getReferencedProjects());
- assertEquals("3.5", new String[0], projDesc.getNatureIds());
- assertEquals("3.6", new ICommand[0], projDesc.getBuildSpec());
- assertNull("3.7", projDesc.getLinks());
- } finally {
- Workspace.clear(location.toFile());
- }
-}
-private String getLongDescription() {
- return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
- "<projectDescription>" +
- "<name>org.eclipse.help.ui</name>" +
- "<comment></comment>" +
- " <projects>" +
- " <project>org.eclipse.core.boot</project>" +
- " <project>org.eclipse.core.resources</project>" +
- " <project>org.eclipse.core.runtime</project>" +
- " <project>org.eclipse.help</project>" +
- " <project>org.eclipse.help.appserver</project>" +
- " <project>org.eclipse.search</project>" +
- " <project>org.eclipse.ui</project>" +
- " </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.jdt.core.javanature</nature>" +
- " <nature>org.eclipse.pde.PluginNature</nature>" +
- " </natures>" +
- " <linkedResources>" +
- " <link>" +
- " <name>contexts.xml</name>" +
- " <type>1</type>" +
- " <location>" + LONG_LOCATION + "</location>" +
- " </link>" +
- " <link>" +
- " <name>doc</name>" +
- " <type>2</type>" +
- " <location>" + LONG_LOCATION + "</location>" +
- " </link>" +
- " <link>" +
- " <name>icons</name>" +
- " <type>2</type>" +
- " <location>" + LONG_LOCATION + "</location>" +
- " </link>" +
- " <link>" +
- " <name>preferences.ini</name>" +
- " <type>1</type>" +
- " <location>" + LONG_LOCATION + "</location>" +
- " </link>" +
- " <link>" +
- " <name>.options</name>" +
- " <type>1</type>" +
- " <location>" + LONG_LOCATION + "</location>" +
- " </link>" +
- " <link>" +
- " <name>plugin.properties</name>" +
- " <type>1</type>" +
- " <location>" + LONG_LOCATION + "</location>" +
- " </link>" +
- " <link>" +
- " <name>plugin.xml</name>" +
- " <type>1</type>" +
- " <location>" + LONG_LOCATION + "</location>" +
- " </link>" +
- " <link>" +
- " <name>about.html</name>" +
- " <type>1</type>" +
- " <location>" + LONG_LOCATION + "</location>" +
- " </link>" +
- " <link>" +
- " <name>helpworkbench.jar</name>" +
- " <type>1</type>" +
- " <location>" + LONG_LOCATION + "</location>" +
- " </link>" +
- "</linkedResources>" +
- "</projectDescription>";
-}
-/**
- * Test multiple elements where they shouldn't be
- */
-public void testLongProjectDescription() throws Throwable {
- String longProjectDescription = getLongDescription();
-
- IPath location = getRandomLocation();
- try {
- ProjectDescriptionReader reader = new ProjectDescriptionReader();
- // Write out the project description file
- ensureDoesNotExistInFileSystem(location.toFile());
- InputStream stream = new ByteArrayInputStream(longProjectDescription.getBytes());
- createFileInFileSystem(location, stream);
- ProjectDescription projDesc = reader.read(location);
- ensureDoesNotExistInFileSystem(location.toFile());
- for (Iterator i = projDesc.getLinks().values().iterator(); i.hasNext(); ) {
- LinkDescription link = (LinkDescription) i.next();
- assertEquals("1.0." + link.getName(), LONG_LOCATION, link.getLocation());
- }
- } finally {
- Workspace.clear(location.toFile());
- }
-}
-public void testMultipleProjectDescriptions() throws Throwable {
- URL whereToLook = null;
- PluginDescriptor tempPlugin = (PluginDescriptor)Platform.getPluginRegistry().getPluginDescriptor("org.eclipse.core.tests.resources");
- String pluginPath = tempPlugin.getLocation().concat("MultipleProjectTestFiles/");
- try {
- whereToLook = new URL (pluginPath);
- } catch (java.net.MalformedURLException e) {
- assertTrue("Bad URL for " + pluginPath, true);
- }
- String[] members = {"abc.project","def.project",
- "org.apache.lucene.project", "org.eclipse.ant.core.project"};
- HashMap baselines = buildBaselineDescriptors(new Path(pluginPath));
- ProjectDescriptionReader reader = new ProjectDescriptionReader();
-
- for (int i = 0; i < members.length; i++) {
- URL currentURL = null;
- currentURL = new URL(whereToLook, members[i]);
- InputStream is = null;
- try {
- is = currentURL.openStream();
- } catch (IOException e) {
- fail("0.5");
- }
- InputSource in = new InputSource(is);
- ProjectDescription description = reader.read(in);
-
- compareProjectDescriptions(i + 1, description, (ProjectDescription)baselines.get(members[i]));
- }
-}
-private HashMap buildBaselineDescriptors(IPath pluginPath) {
- HashMap result = new HashMap();
- IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
-
- ProjectDescription desc = new ProjectDescription();
- desc.setName("abc.project");
- ICommand[] commands = new ICommand[1];
- commands[0] = desc.newCommand();
- commands[0].setBuilderName("org.eclipse.jdt.core.javabuilder");
- desc.setBuildSpec(commands);
- String[] natures = new String[1];
- natures[0] = "org.eclipse.jdt.core.javanature";
- desc.setNatureIds(natures);
- HashMap linkMap = new HashMap();
- LinkDescription link = new LinkDescription("newLink", 2, new Path("d:/abc/def"));
- linkMap.put(link.getName(), link);
- desc.setLinkDescriptions(linkMap);
- result.put(desc.getName(), desc);
- commands = null;
- natures = null;
- link = null;
- linkMap = null;
- desc = null;
-
- desc = new ProjectDescription();
- desc.setName("def.project");
- commands = new ICommand[1];
- commands[0] = desc.newCommand();
- commands[0].setBuilderName("org.eclipse.jdt.core.javabuilder");
- desc.setBuildSpec(commands);
- natures = new String[1];
- natures[0] = "org.eclipse.jdt.core.javanature";
- desc.setNatureIds(natures);
- linkMap = new HashMap();
- link = new LinkDescription("newLink", 2, new Path("d:/abc/def"));
- linkMap.put(link.getName(), link);
- link = new LinkDescription("link2", 2, new Path("d:/abc"));
- linkMap.put(link.getName(), link);
- link = new LinkDescription("link3", 2, new Path("d:/abc/def/ghi"));
- linkMap.put(link.getName(), link);
- link = new LinkDescription("link4", 1, new Path("d:/abc/def/afile.txt"));
- linkMap.put(link.getName(), link);
- desc.setLinkDescriptions(linkMap);
- result.put(desc.getName(), desc);
- commands = null;
- natures = null;
- link = null;
- linkMap = null;
- desc = null;
-
- desc = new ProjectDescription();
- desc.setName("org.apache.lucene.project");
- IProject[] refProjects = new Project[2];
- refProjects[0] = root.getProject("org.eclipse.core.boot");
- refProjects[1] = root.getProject("org.eclipse.core.runtime");
- desc.setReferencedProjects(refProjects);
- commands = new ICommand[3];
- commands[0] = desc.newCommand();
- commands[0].setBuilderName("org.eclipse.jdt.core.javabuilder");
- commands[1] = desc.newCommand();
- commands[1].setBuilderName("org.eclipse.pde.ManifestBuilder");
- commands[2] = desc.newCommand();
- commands[2].setBuilderName("org.eclipse.pde.SchemaBuilder");
- desc.setBuildSpec(commands);
- natures = new String[2];
- natures[0] = "org.eclipse.jdt.core.javanature";
- natures[1] = "org.eclipse.pde.PluginNature";
- desc.setNatureIds(natures);
- result.put(desc.getName(), desc);
- refProjects = null;
- commands = null;
- natures = null;
- desc = null;
-
- desc = new ProjectDescription();
- desc.setName("org.eclipse.ant.core.project");
- refProjects = new Project[4];
- refProjects[0] = root.getProject("org.apache.ant");
- refProjects[1] = root.getProject("org.apache.xerces");
- refProjects[2] = root.getProject("org.eclipse.core.boot");
- refProjects[3] = root.getProject("org.eclipse.core.runtime");
- desc.setReferencedProjects(refProjects);
- commands = new ICommand[2];
- commands[0] = desc.newCommand();
- commands[0].setBuilderName("org.eclipse.jdt.core.javabuilder");
- commands[1] = desc.newCommand();
- commands[1].setBuilderName("org.eclipse.ui.externaltools.ExternalToolBuilder");
- Map argMap = new HashMap();
- argMap.put("!{tool_show_log}", "true");
- argMap.put("!{tool_refresh}", "${none}");
- argMap.put("!{tool_name}", "org.eclipse.ant.core extra builder");
- argMap.put("!{tool_dir}", "");
- argMap.put("!{tool_args}", "-DbuildType=${build_type}");
- argMap.put("!{tool_loc}", "${workspace_loc:/org.eclipse.ant.core/scripts/buildExtraJAR.xml}");
- argMap.put("!{tool_type}", "org.eclipse.ui.externaltools.type.ant");
- commands[1].setArguments(argMap);
- desc.setBuildSpec(commands);
- natures = new String[1];
- natures[0] = "org.eclipse.jdt.core.javanature";
- desc.setNatureIds(natures);
- result.put(desc.getName(), desc);
- refProjects = null;
- commands = null;
- natures = null;
- desc = null;
-
- return result;
-}
-public void testWorkspaceDescription() throws Throwable {
-
- /* initialize common objects */
- ModelObjectWriter writer = new ModelObjectWriter();
- WorkspaceDescriptionReader reader = new WorkspaceDescriptionReader();
- IPath root = getWorkspace().getRoot().getLocation();
- IPath location = root.append("ModelObjectWriterTest.pbs");
-
- /* test write */
- WorkspaceDescription desc = new WorkspaceDescription("MyWorkspace");
- desc.setName("aName");
- desc.setAutoBuilding(false);
- desc.setFileStateLongevity(654321l);
- desc.setMaxFileStates(1000);
- desc.setMaxFileStateSize(123456789l);
-
- SafeFileOutputStream output = new SafeFileOutputStream(location.toFile());
- writer.write(desc, output);
- output.close();
-
- /* test read */
- try {
- FileInputStream input = new FileInputStream(location.toFile());
- WorkspaceDescription desc2 = (WorkspaceDescription) reader.read(input);
- assertTrue("1.1", desc.getName().equals(desc2.getName()));
- assertTrue("1.2", desc.isAutoBuilding() == desc2.isAutoBuilding());
- assertTrue("1.3", desc.getDeltaExpiration() == desc2.getDeltaExpiration());
- assertTrue("1.4", desc.getFileStateLongevity() == desc2.getFileStateLongevity());
- assertTrue("1.5", desc.getMaxFileStates() == desc2.getMaxFileStates());
- assertTrue("1.6", desc.getMaxFileStateSize() == desc2.getMaxFileStateSize());
- assertTrue("1.7", desc.getOperationsPerSnapshot() == desc2.getOperationsPerSnapshot());
- assertTrue("1.8", desc.isSnapshotEnabled() == desc2.isSnapshotEnabled());
- } finally {
- /* remove trash */
- Workspace.clear(location.toFile());
- }
-}
-public void testMultiLineCharFields() throws Throwable {
- String multiLineProjectDescription =
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
- "<projectDescription>\n" +
- " <name>\n" +
- " abc\n" +
- " </name>\n" +
- " <comment>This is the comment.</comment>\n" +
- " <projects>\n" +
- " <project>\n" +
- " org.eclipse.core.boot\n" +
- " </project>\n" +
- " </projects>\n" +
- " <buildSpec>\n" +
- " <buildCommand>\n" +
- " <name>\n" +
- " org.eclipse.jdt.core.javabuilder\n" +
- " </name>\n" +
- " <arguments>\n" +
- " <key>thisIsTheKey</key>\n" +
- " <value>thisIsTheValue</value>\n" +
- " </arguments>\n" +
- " </buildCommand>\n" +
- " </buildSpec>\n" +
- " <natures>\n" +
- " <nature>\n" +
- " org.eclipse.jdt.core.javanature\n" +
- " </nature>\n" +
- " </natures>\n" +
- " <linkedResources>\n" +
- " <link>\n" +
- " <name>\n" +
- " newLink\n" +
- " </name>\n" +
- " <type>\n" +
- " 2\n" +
- " </type>\n" +
- " <location>\n" +
- " d:/abc/def\n" +
- " </location>\n" +
- " </link>\n" +
- " </linkedResources>\n" +
- "</projectDescription>";
-
- String singleLineProjectDescription =
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
- "<projectDescription>\n" +
- " <name>abc</name>\n" +
- " <comment>This is the comment.</comment>\n" +
- " <projects>\n" +
- " <project>org.eclipse.core.boot</project>\n" +
- " </projects>\n" +
- " <buildSpec>\n" +
- " <buildCommand>\n" +
- " <name>org.eclipse.jdt.core.javabuilder</name>\n" +
- " <arguments>\n" +
- " <key>thisIsTheKey</key>\n" +
- " <value>thisIsTheValue</value>\n" +
- " </arguments>\n" +
- " </buildCommand>\n" +
- " </buildSpec>\n" +
- " <natures>\n" +
- " <nature>org.eclipse.jdt.core.javanature</nature>\n" +
- " </natures>\n" +
- " <linkedResources>\n" +
- " <link>\n" +
- " <name>newLink</name>\n" +
- " <type>2</type>\n" +
- " <location>d:/abc/def</location>\n" +
- " </link>\n" +
- " </linkedResources>\n" +
- "</projectDescription>";
-
- IPath root = getWorkspace().getRoot().getLocation();
- IPath multiLocation = root.append("multiLineTest.txt");
- IPath singleLocation = root.append("singleLineTest.txt");
- ProjectDescriptionReader reader = new ProjectDescriptionReader();
- // Write out the project description file
- ensureDoesNotExistInFileSystem(multiLocation.toFile());
- ensureDoesNotExistInFileSystem(singleLocation.toFile());
- InputStream multiStream = new ByteArrayInputStream(multiLineProjectDescription.getBytes());
- InputStream singleStream = new ByteArrayInputStream(singleLineProjectDescription.getBytes());
- try {
- createFileInFileSystem(multiLocation, multiStream);
- createFileInFileSystem(singleLocation, singleStream);
- ProjectDescription multiDesc = reader.read(multiLocation);
- ProjectDescription singleDesc = reader.read(singleLocation);
- compareProjectDescriptions(1, multiDesc, singleDesc);
- } finally {
- Workspace.clear(multiLocation.toFile());
- Workspace.clear(singleLocation.toFile());
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ResourceInfoTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ResourceInfoTest.java
deleted file mode 100644
index 3d5f4eb..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ResourceInfoTest.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.resources;
-
-
-import java.io.*;
-import java.util.Enumeration;
-import java.util.Hashtable;
-
-import org.eclipse.core.internal.resources.ResourceInfo;
-import org.eclipse.core.runtime.QualifiedName;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-public class ResourceInfoTest extends EclipseWorkspaceTest {
-/**
- * ResourceInfoTest constructor comment.
- */
-public ResourceInfoTest() {
- super();
-}
-/**
- * ResourceInfoTest constructor comment.
- * @param name java.lang.String
- */
-public ResourceInfoTest(String name) {
- super(name);
-}
-static public void assertEquals(String message, byte[] expected, byte[] actual) {
- if (expected == null && actual == null)
- return;
- if (expected == null || actual == null)
- assertTrue(message, false);
- assertEquals(message, expected.length, actual.length);
- for (int i = 0; i < expected.length; i++)
- assertEquals(message, expected[i], actual[i]);
-}
-static public void assertEquals(String message, Hashtable expected, Hashtable actual) {
- if (expected == null && actual == null)
- return;
- if (expected == null || actual == null)
- assertTrue(message, false);
- assertEquals(message, expected.size(), actual.size());
- for (Enumeration e = expected.keys(); e.hasMoreElements();) {
- Object key = e.nextElement();
- assertTrue(message, actual.containsKey(key));
- Object expectedValue = expected.get(key);
- Object actualValue = actual.get(key);
- if (expectedValue instanceof byte[] && actualValue instanceof byte[])
- assertEquals(message, (byte[]) expectedValue, (byte[]) actualValue);
- else
- assertEquals(message, expectedValue, actualValue);
- }
-}
-static public void assertEquals(String message, ResourceInfo expected, ResourceInfo actual) {
- if (expected == null && actual == null)
- return;
- if (expected == null || actual == null)
- assertTrue(message, false);
- boolean different = false;
- different &= expected.getFlags() == actual.getFlags();
- different &= expected.getContentId() == actual.getContentId();
- different &= expected.getModificationStamp() == actual.getModificationStamp();
- different &= expected.getNodeId() == actual.getNodeId();
- different &= expected.getLocalSyncInfo() == actual.getLocalSyncInfo();
- assertEquals(message, expected.getSyncInfo(false), actual.getSyncInfo(false));
- different &= expected.getMarkerGenerationCount() == actual.getMarkerGenerationCount();
- if (different)
- assertTrue(message, false);
-}
-public void testSerialization() {
- ByteArrayInputStream input = null;
- ByteArrayOutputStream output = null;
- ResourceInfo info = new ResourceInfo();
- ResourceInfo newInfo = new ResourceInfo();
-
- // write out an empty info
- try {
- output = new ByteArrayOutputStream();
- info.writeTo(new DataOutputStream(output));
- } catch (IOException e) {
- fail("1.0", e);
- }
- try {
- input = new ByteArrayInputStream(output.toByteArray());
- newInfo.readFrom(0, new DataInputStream(input));
- } catch (IOException e) {
- fail("1.1", e);
- }
- assertEquals("1.2", info, newInfo);
-
- // write and info with syncinfo set
- info = new ResourceInfo();
- // set no bytes
- QualifiedName qname = new QualifiedName("org.eclipse.core.tests", "myTest1");
- byte[] bytes = new byte[0];
- info.setSyncInfo(qname, bytes);
- // set some real bytes
- qname = new QualifiedName("org.eclipse.core.tests", "myTest2");
- bytes = new byte[] { 0, 1, 2, 3, 4, 5 };
- info.setSyncInfo(qname, bytes);
- try {
- output = new ByteArrayOutputStream();
- info.writeTo(new DataOutputStream(output));
- } catch (IOException e) {
- fail("2.0", e);
- }
- try {
- newInfo = new ResourceInfo();
- input = new ByteArrayInputStream(output.toByteArray());
- newInfo.readFrom(0, new DataInputStream(input));
- } catch (IOException e) {
- fail("2.1", e);
- }
- assertEquals("2.2", info, newInfo);
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/SimpleNature.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/SimpleNature.java
deleted file mode 100644
index 49f4a5a..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/SimpleNature.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.resources;
-
-/**
- */
-public class SimpleNature extends TestNature {
-/**
- * Constructor for SimpleNature.
- */
-public SimpleNature() {
- super();
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/SnowNature.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/SnowNature.java
deleted file mode 100644
index e6fbeaf..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/SnowNature.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.resources;
-
-import java.util.HashMap;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.tests.internal.builders.SnowBuilder;
-import org.eclipse.core.tests.internal.builders.TestBuilder;
-
-/**
- */
-public class SnowNature extends TestNature {
-/**
- * Constructor for SnowNature.
- */
-public SnowNature() {
- super();
-}
-/**
- * @see IProjectNature#configure()
- */
-public void configure() throws CoreException {
- //install the snow builder
- IProject project = getProject();
- IProjectDescription desc = project.getDescription();
- ICommand[] oldSpec = desc.getBuildSpec();
- ICommand[] newSpec = new ICommand[oldSpec.length+1];
- System.arraycopy(oldSpec, 0, newSpec, 0, oldSpec.length);
- ICommand newCommand = desc.newCommand();
- newCommand.setBuilderName(SnowBuilder.BUILDER_NAME);
- HashMap args = new HashMap(20);
- args.put(TestBuilder.BUILD_ID, SnowBuilder.SNOW_BUILD_EVENT);
- newCommand.setArguments(args);
- newSpec[oldSpec.length] = newCommand;
- desc.setBuildSpec(newSpec);
- project.setDescription(desc, IResource.FORCE | IResource.KEEP_HISTORY, null);
-}
-
-/**
- * @see IProjectNature#deconfigure()
- */
-public void deconfigure() throws CoreException {
- //remove the snow builder
- IProjectDescription description = getProject().getDescription();
- ICommand[] commands = description.getBuildSpec();
- for (int i = 0; i < commands.length; ++i) {
- if (commands[i].getBuilderName().equals(SnowBuilder.BUILDER_NAME)) {
- ICommand[] newCommands = new ICommand[commands.length - 1];
- System.arraycopy(commands, 0, newCommands, 0, i);
- System.arraycopy(commands, i + 1, newCommands, i, commands.length - i - 1);
- description.setBuildSpec(newCommands);
- getProject().setDescription(description, null);
- return;
- }
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/TestNature.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/TestNature.java
deleted file mode 100644
index cbd8a0f..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/TestNature.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.resources;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectNature;
-import org.eclipse.core.runtime.CoreException;
-
-/**
- */
-public class TestNature implements IProjectNature {
- private IProject project;
-/**
- * Constructor for TestNature.
- */
-public TestNature() {
- super();
-}
-/**
- * @see IProjectNature#configure()
- */
-public void configure() throws CoreException {
-}
-/**
- * @see IProjectNature#deconfigure()
- */
-public void deconfigure() throws CoreException {
-}
-/**
- * @see IProjectNature#getProject()
- */
-public IProject getProject() {
- return project;
-}
-/**
- * @see IProjectNature#setProject(IProject)
- */
-public void setProject(IProject project) {
- this.project = project;
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/WaterNature.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/WaterNature.java
deleted file mode 100644
index e2d5c8f..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/WaterNature.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.resources;
-
-/**
- */
-public class WaterNature extends TestNature {
-/**
- * Constructor for WaterNature.
- */
-public WaterNature() {
- super();
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/WorkspacePreferencesTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/WorkspacePreferencesTest.java
deleted file mode 100644
index 4290f2b..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/WorkspacePreferencesTest.java
+++ /dev/null
@@ -1,322 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.resources;
-
-import java.util.*;
-
-import junit.framework.*;
-
-import org.eclipse.core.internal.resources.*;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-public class WorkspacePreferencesTest extends EclipseWorkspaceTest {
- private IWorkspace workspace;
- private Preferences preferences;
- /**
- * Constructor for WorkspacePreferencesTest.
- * @param name
- */
- public WorkspacePreferencesTest(String name) {
- super(name);
- }
-
- /**
- * @see TestCase#setUp()
- */
- protected void setUp() throws Exception {
- super.setUp();
- workspace = ResourcesPlugin.getWorkspace();
- preferences = ResourcesPlugin.getPlugin().getPluginPreferences();
- workspace.setDescription(Workspace.defaultWorkspaceDescription());
- }
-
- /**
- * @see TestCase#tearDown()
- */
- protected void tearDown() throws Exception {
- super.tearDown();
- workspace.setDescription(Workspace.defaultWorkspaceDescription());
- }
- /**
- * Tests properties state in a brand new workspace (must match defaults).
- */
- public void testDefaults() {
- IWorkspaceDescription description = Workspace.defaultWorkspaceDescription();
-
- assertEquals("1.0", description, preferences);
-
- // ensures that all properties in the default workspace description
- // appear as non-default-default properties in the property store
- String[] descriptionProperties =
- {
- ResourcesPlugin.PREF_AUTO_BUILDING,
- ResourcesPlugin.PREF_BUILD_ORDER,
- ResourcesPlugin.PREF_DEFAULT_BUILD_ORDER,
- ResourcesPlugin.PREF_FILE_STATE_LONGEVITY,
- ResourcesPlugin.PREF_MAX_BUILD_ITERATIONS,
- ResourcesPlugin.PREF_MAX_FILE_STATE_SIZE,
- ResourcesPlugin.PREF_MAX_FILE_STATES,
- ResourcesPlugin.PREF_SNAPSHOT_INTERVAL };
- List defaultPropertiesList = Arrays.asList(preferences.defaultPropertyNames());
- for (int i = 0; i < descriptionProperties.length; i++) {
- String property = descriptionProperties[i];
- assertTrue("2.0 - Description property is not default: " + property, defaultPropertiesList.contains(property));
- }
- }
- /**
- * Makes changes in the preferences and ensure they are reflected in the
- * workspace description.
- */
- public void testSetPreferences() {
- preferences.setValue(ResourcesPlugin.PREF_AUTO_BUILDING, true);
- assertTrue("1.0", workspace.getDescription().isAutoBuilding());
-
- preferences.setValue(ResourcesPlugin.PREF_AUTO_BUILDING, false);
- assertTrue("1.1", !workspace.getDescription().isAutoBuilding());
-
- preferences.setValue(ResourcesPlugin.PREF_DEFAULT_BUILD_ORDER, true);
- assertTrue("2.0", workspace.getDescription().getBuildOrder() == null);
-
- preferences.setValue(ResourcesPlugin.PREF_DEFAULT_BUILD_ORDER, false);
- assertTrue("2.1", workspace.getDescription().getBuildOrder() != null);
-
- preferences.setValue(ResourcesPlugin.PREF_BUILD_ORDER, "x:y,z:z");
- List expectedList = Arrays.asList(new String[] { "x", "y,z", "z" });
- List actualList = Arrays.asList(workspace.getDescription().getBuildOrder());
- assertEquals("2.2", expectedList, actualList);
-
- preferences.setValue(ResourcesPlugin.PREF_BUILD_ORDER, "");
- assertTrue("2.3", workspace.getDescription().getBuildOrder().length == 0);
-
- long snapshotInterval = 800000000L;
- preferences.setValue(ResourcesPlugin.PREF_SNAPSHOT_INTERVAL, snapshotInterval);
- assertEquals("3.0", snapshotInterval, workspace.getDescription().getSnapshotInterval());
-
- long defaultSnapshotInterval = preferences.getDefaultLong(ResourcesPlugin.PREF_SNAPSHOT_INTERVAL);
- preferences.setValue(ResourcesPlugin.PREF_SNAPSHOT_INTERVAL, defaultSnapshotInterval);
- assertEquals("3.1", defaultSnapshotInterval, workspace.getDescription().getSnapshotInterval());
-
- preferences.setToDefault(ResourcesPlugin.PREF_SNAPSHOT_INTERVAL);
- assertEquals("3.2", defaultSnapshotInterval, workspace.getDescription().getSnapshotInterval());
- assertEquals("Description not synchronized", workspace.getDescription(), preferences);
-
- }
- /**
- * Ensures property change events are properly fired when setting workspace description.
- */
- public void testEvents() {
- IWorkspaceDescription original = workspace.getDescription();
-
- IWorkspaceDescription modified = workspace.getDescription();
- // 1 - PREF_AUTO_BUILDING
- modified.setAutoBuilding(!original.isAutoBuilding());
- // 2 - PREF_DEFAULT_BUILD_ORDER and 3 - PREF_BUILD_ORDER
- modified.setBuildOrder(new String[] { "a", "b", "c" });
- // 4 - PREF_FILE_STATE_LONGEVITY
- modified.setFileStateLongevity((original.getFileStateLongevity() + 1) * 2);
- // 5 - PREF_MAX_BUILD_ITERATIONS
- modified.setMaxBuildIterations((original.getMaxBuildIterations() + 1) * 2);
- // 6 - PREF_MAX_FILE_STATES
- modified.setMaxFileStates((original.getMaxFileStates() + 1) * 2);
- // 7 - PREF_MAX_FILE_STATE_SIZE
- modified.setMaxFileStateSize((original.getMaxFileStateSize() + 1) * 2);
- // 8 - PREF_SNAPSHOT_INTERVAL
- modified.setSnapshotInterval((original.getSnapshotInterval() + 1) * 2);
-
- final List changedProperties = new LinkedList();
- Preferences.IPropertyChangeListener listener = new Preferences.IPropertyChangeListener() {
- public void propertyChange(Preferences.PropertyChangeEvent event) {
- changedProperties.add(event.getProperty());
- }
- };
- try {
- preferences.addPropertyChangeListener(listener);
- try {
- workspace.setDescription(original);
- } catch (CoreException e) {
- fail("1.0", e);
- }
- // no events should have been fired
- assertEquals("1.1 - wrong number of properties changed ", 0, changedProperties.size());
- try {
- workspace.setDescription(modified);
- } catch (CoreException e) {
- fail("2.0", e);
- }
- // the right number of events should have been fired
- assertEquals("2.1 - wrong number of properties changed ", 8, changedProperties.size());
- } finally {
- preferences.removePropertyChangeListener(listener);
- }
- }
-
- /**
- * Ensures preferences with both default/non-default values are properly exported/imported.
- */
- public void testImportExport() {
- IPath originalPreferencesFile = getRandomLocation().append("original.epf");
- IPath modifiedPreferencesFile = getRandomLocation().append("modified.epf");
- try {
- // saves the current preferences (should be the default ones)
- IWorkspaceDescription original = workspace.getDescription();
-
- // sets a non-used preference to a non-default value so a
- // preferences file can be generated
- preferences.setValue("foo.bar", getRandomString());
-
- // exports original preferences (only default values - except for bogus preference above)
- try {
- Preferences.exportPreferences(originalPreferencesFile);
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- // creates a modified description
- IWorkspaceDescription modified = workspace.getDescription();
- modified.setAutoBuilding(!original.isAutoBuilding());
- modified.setBuildOrder(new String[] {"a", "b", "c"});
- modified.setFileStateLongevity((original.getFileStateLongevity() + 1) * 2);
- modified.setMaxBuildIterations((original.getMaxBuildIterations() + 1) * 2);
- modified.setMaxFileStates((original.getMaxFileStates() + 1) * 2);
- modified.setMaxFileStateSize((original.getMaxFileStateSize() + 1) * 2);
- modified.setSnapshotInterval((original.getSnapshotInterval() + 1) * 2);
-
- // sets modified description
- try {
- workspace.setDescription(modified);
- } catch (CoreException ce) {
- fail("2.0", ce);
- }
- assertEquals("2.1", modified, workspace.getDescription());
-
- // exports modified preferences
- try {
- Preferences.exportPreferences(modifiedPreferencesFile);
- } catch (CoreException e) {
- fail("3.0", e);
- }
-
- // imports original preferences
- try {
- Preferences.importPreferences(originalPreferencesFile);
- } catch (CoreException e) {
- fail("4.0", e);
- }
- // ensures preferences exported match the imported ones
- assertEquals("4.1", original, workspace.getDescription());
-
- // imports modified preferences
- try {
- Preferences.importPreferences(modifiedPreferencesFile);
- } catch (CoreException e) {
- fail("5.0", e);
- }
- // ensures preferences exported match the imported ones
- assertEquals("5.1", modified, workspace.getDescription());
- } finally {
- ensureDoesNotExistInFileSystem(originalPreferencesFile.toFile());
- ensureDoesNotExistInFileSystem(modifiedPreferencesFile.toFile());
- }
-
- }
-
- /**
- * Makes changes through IWorkspace#setDescription and checks if the changes
- * are reflected in the preferences.
- */
- public void testSetDescription() {
- IWorkspaceDescription description = workspace.getDescription();
- description.setAutoBuilding(false);
- description.setBuildOrder(new String[] { "a", "b,c", "c" });
- description.setFileStateLongevity(60000 * 5);
- description.setMaxBuildIterations(35);
- description.setMaxFileStates(16);
- description.setMaxFileStateSize(100050);
- description.setSnapshotInterval(1234567);
- try {
- workspace.setDescription(description);
- } catch (CoreException ce) {
- fail("2.0", ce);
- }
- assertEquals("2.1 - Preferences not synchronized", description, preferences);
-
- // try to make changes without committing them
-
- // sets current state to a known value
- description.setFileStateLongevity(90000);
- try {
- workspace.setDescription(description);
- } catch (CoreException ce) {
- fail("3.0", ce);
- }
- // try to make a change
- description.setFileStateLongevity(100000);
- // the original value should remain set
- assertEquals("3.1", 90000, workspace.getDescription().getFileStateLongevity());
- assertEquals("3.2", 90000, preferences.getLong(ResourcesPlugin.PREF_FILE_STATE_LONGEVITY));
- }
- /**
- * Checks if a legacy workspace description is correctly loaded and
- * its file discarded.
- */
- public void testMigration() {
- WorkspaceDescription description = new WorkspaceDescription("Legacy workspace");
- description.setAutoBuilding(false);
- final String[] buildOrder = new String[] { "g", "r", "e", "p" };
- description.setBuildOrder(buildOrder);
- description.setFileStateLongevity(Math.abs((long) (Math.random() * 100000L)));
- description.setMaxFileStates(Math.abs((int) (Math.random() * 100000L)));
- description.setMaxFileStateSize(Math.abs((long) (Math.random() * 100000L)));
- description.setSnapshotInterval(Math.abs((long) (Math.random() * 100000L)));
- LocalMetaArea localMetaArea = ((Workspace) workspace).getMetaArea();
- try {
- localMetaArea.write(description);
- } catch (CoreException ce) {
- fail("1.0", ce);
- }
- assertTrue("2.0 - file .description does not exist", localMetaArea.getOldWorkspaceDescriptionLocation().toFile().isFile());
- WorkspaceDescription descriptionFromDisk = localMetaArea.readOldWorkspace();
- assertTrue("2.1 - file .description still exists", !localMetaArea.getOldWorkspaceDescriptionLocation().toFile().isFile());
- assertEquals("3.0", description, descriptionFromDisk);
- }
- /**
- * Compares the values in a workspace description with the corresponding
- * properties in a preferences object.
- */
- public void assertEquals(String message, IWorkspaceDescription description, Preferences preferences) throws ComparisonFailure {
- assertEquals(message + " - 1", description.isAutoBuilding(), preferences.getBoolean(ResourcesPlugin.PREF_AUTO_BUILDING));
- assertEquals(message + " - 2", description.getBuildOrder() == null, preferences.getBoolean(ResourcesPlugin.PREF_DEFAULT_BUILD_ORDER));
- assertEquals(message + " - 3", WorkspacePreferences.convertStringArraytoString(description.getBuildOrder()), preferences.getString(ResourcesPlugin.PREF_BUILD_ORDER));
- assertEquals(message + " - 4", description.getFileStateLongevity(), preferences.getLong(ResourcesPlugin.PREF_FILE_STATE_LONGEVITY));
- assertEquals(message + " - 5", description.getMaxFileStates(), preferences.getInt(ResourcesPlugin.PREF_MAX_FILE_STATES));
- assertEquals(message + " - 6", description.getMaxFileStateSize(), preferences.getLong(ResourcesPlugin.PREF_MAX_FILE_STATE_SIZE));
- assertEquals(message + " - 7", description.getSnapshotInterval(), preferences.getLong(ResourcesPlugin.PREF_SNAPSHOT_INTERVAL));
- assertEquals(message + " - 8", description.getMaxBuildIterations(), preferences.getLong(ResourcesPlugin.PREF_MAX_BUILD_ITERATIONS));
- }
- /**
- * Compares two workspace description objects..
- */
- public void assertEquals(String message, IWorkspaceDescription description1, IWorkspaceDescription description2) throws ComparisonFailure {
- assertEquals(message + " - 1", description1.isAutoBuilding(), description2.isAutoBuilding());
- assertEquals(message + " - 2", description1.getBuildOrder(), description2.getBuildOrder());
- assertEquals(message + " - 3", WorkspacePreferences.convertStringArraytoString(description1.getBuildOrder()), WorkspacePreferences.convertStringArraytoString(description2.getBuildOrder()));
- assertEquals(message + " - 4", description1.getFileStateLongevity(), description2.getFileStateLongevity());
- assertEquals(message + " - 5", description1.getMaxFileStates(), description2.getMaxFileStates());
- assertEquals(message + " - 6", description1.getMaxFileStateSize(), description2.getMaxFileStateSize());
- assertEquals(message + " - 7", description1.getSnapshotInterval(), description2.getSnapshotInterval());
- assertEquals(message + " - 8", description1.getMaxBuildIterations(), description2.getMaxBuildIterations());
- }
- public static Test suite() {
- return new TestSuite(WorkspacePreferencesTest.class);
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/utils/AllTests.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/utils/AllTests.java
deleted file mode 100644
index 1486fd4..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/utils/AllTests.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.utils;
-
-
-import junit.framework.*;
-
-public class AllTests extends TestCase {
-/**
- * AllTests constructor comment.
- * @param name java.lang.String
- */
-public AllTests() {
- super(null);
-}
-/**
- * AllTests constructor comment.
- * @param name java.lang.String
- */
-public AllTests(String name) {
- super(name);
-}
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(QueueTest.suite());
- suite.addTest(ObjectMapTest.suite());
- return suite;
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/utils/ObjectMapTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/utils/ObjectMapTest.java
deleted file mode 100644
index 2895cbf..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/utils/ObjectMapTest.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.utils;
-
-import java.util.*;
-import java.util.Collection;
-import java.util.Set;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.utils.ObjectMap;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-public class ObjectMapTest extends EclipseWorkspaceTest {
- private static final int MAXIMUM = 100;
- private Object[] values;
- /**
- * Need a zero argument constructor to satisfy the test harness.
- * This constructor should not do any real work nor should it be
- * called by user code.
- */
- public ObjectMapTest() {
- }
- /**
- * Creates a new markers test.
- */
- public ObjectMapTest(String name) {
- super(name);
- }
- /**
- * Configures the markers test suite.
- */
- public static Test suite() {
- return new TestSuite(ObjectMapTest.class);
-
- //TestSuite suite = new TestSuite();
- //suite.addTest(new ObjectMapTest("_testPR"));
- //return suite;
- }
- public void testPut() {
-
- // create the objects to insert into the map
- ObjectMap map = new ObjectMap();
- int max = 100;
- Object[] values = new Object[max];
- for (int i = 0; i < max; i++)
- values[i] = new Long(System.currentTimeMillis());
-
- // add each object to the map
- for (int i = 0; i < values.length; i++) {
- Object key = new Integer(i);
- map.put(key, values[i]);
- assertTrue("2.0." + i, map.containsKey(key));
- assertTrue("2.1." + i, map.containsValue(values[i]));
- assertEquals("2.2." + i, i + 1, map.size());
- }
-
- // make sure they are all still there
- assertEquals("3.0", max, map.size());
- for (int i = 0; i < values.length; i++) {
- Object key = new Integer(i);
- assertTrue("3.1." + i, map.containsKey(key));
- assertNotNull("3.2." + i, map.get(key));
- }
- }
- public void testRemove() {
-
- // populate the map
- ObjectMap map = populateMap(MAXIMUM);
-
- // remove each element
- for (int i = MAXIMUM - 1; i >= 0; i--) {
- Object key = new Integer(i);
- map.remove(key);
- assertTrue("2.0." + i, !map.containsKey(key));
- assertEquals("2.1," + i, i, map.size());
- // check that the others still exist
- for (int j = 0; j < i; j++)
- assertTrue("2.2." + j, map.containsKey(new Integer(j)));
- }
-
- // all gone?
- assertEquals("3.0", 0, map.size());
- }
- public void testContains() {
- ObjectMap map = populateMap(MAXIMUM);
-
- for (int i = 0; i < MAXIMUM; i++) {
- assertTrue("2.0." + i, map.containsKey(new Integer(i)));
- assertTrue("2.1." + i, map.containsValue(values[i]));
- }
-
- assertFalse("3.0", map.containsKey(new Integer(MAXIMUM + 1)));
- assertFalse("3.1", map.containsKey(new Integer(-1)));
- assertFalse("3.2", map.containsValue(null));
- assertFalse("3.3", map.containsValue(getRandomString()));
- }
- public void testValues() {
- ObjectMap map = populateMap(MAXIMUM);
-
- Collection result = map.values();
- for (int i = 0; i < MAXIMUM; i++)
- assertTrue("2.0." + i, result.contains(values[i]));
- }
- public void testKeySet() {
- ObjectMap map = populateMap(MAXIMUM);
- Set keys = map.keySet();
- assertEquals("1.0", MAXIMUM, keys.size());
- }
- public void testEntrySet() {
- ObjectMap map = populateMap(MAXIMUM);
- Set entries = map.entrySet();
- for (int i = 0; i < MAXIMUM; i++)
- assertTrue("1.0." + i, contains(entries, values[i]));
- }
- /**
- * The given set is a set of Map.Entry objects.
- */
- private boolean contains(Set set, Object value) {
- for (Iterator i=set.iterator(); i.hasNext();) {
- Map.Entry entry = (Map.Entry) i.next();
- if (entry.getValue().equals(value))
- return true;
- }
- return false;
- }
- private ObjectMap populateMap(int max) {
- // populate the map
- ObjectMap map = new ObjectMap();
- values = new Object[max];
- for (int i = 0; i < max; i++) {
- values[i] = new Long(System.currentTimeMillis());
- map.put(new Integer(i), values[i]);
- }
- assertEquals("#populateMap", max, map.size());
- return map;
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/utils/QueueTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/utils/QueueTest.java
deleted file mode 100644
index 6d03661..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/utils/QueueTest.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.utils;
-
-
-import java.util.Enumeration;
-
-import junit.framework.*;
-import org.eclipse.core.internal.utils.Queue;
-
-public class QueueTest extends TestCase {
-public QueueTest() {
- super(null);
-}
-public QueueTest(String name) {
- super(name);
-}
-public static Test suite() {
- return new TestSuite(QueueTest.class);
-}
-public void testElements() {
- /* add elements without removing */
- Queue queue = new Queue(5, false);
- for (int i = 0; i < 10; i++)
- queue.add(String.valueOf(i));
-
- /* assert elements are correct */
- Enumeration elements = queue.elements();
- for (int i = 0; i < 10; i++)
- assertTrue("1.0", elements.nextElement().equals(String.valueOf(i)));
-
- /* add and remove elements */
- queue = new Queue(5, false);
- for (int i = 0; i < 5; i++)
- queue.add(String.valueOf(i));
- for (int i = 0; i < 4; i++)
- queue.remove();
- for (int i = 0; i < 10; i++)
- queue.add(String.valueOf(i));
-
- /* assert elements are correct */
- elements = queue.elements();
- for (int i = 4; i < 5; i++)
- assertTrue("2.0", elements.nextElement().equals(String.valueOf(i)));
- for (int i = 0; i < 10; i++)
- assertTrue("2.1", elements.nextElement().equals(String.valueOf(i)));
-}
-public void testGrow() {
- /* add elements without removing */
- Queue queue = new Queue(5, false);
- for (int i = 0; i < 10; i++)
- queue.add(String.valueOf(i));
- assertTrue("1.0", queue.size() == 10);
-
- /* add and remove elements */
- queue = new Queue(5, false);
- for (int i = 0; i < 5; i++)
- queue.add(String.valueOf(i));
- for (int i = 0; i < 4; i++)
- queue.remove();
- for (int i = 0; i < 10; i++) {
- queue.add(String.valueOf(i));
- }
- assertTrue("2.0", queue.size() == 11);
-}
-public void testRemoveTail() {
- /* head < tail */
- Queue queue = new Queue(10, false);
- for (int i = 0; i < 8; i++)
- queue.add(String.valueOf(i));
- assertTrue("1.0", queue.peekTail().equals("7"));
- assertTrue("1.1", queue.removeTail().equals("7"));
- assertTrue("1.2", queue.peekTail().equals("6"));
-
- /* head > tail */
- queue = new Queue(5, false);
- for (int i = 0; i < 5; i++)
- queue.add(String.valueOf(i));
- for (int i = 0; i < 4; i++)
- queue.remove();
- for (int i = 0; i < 10; i++) {
- queue.add(String.valueOf(i));
- }
- assertTrue("2.0", queue.peekTail().equals("9"));
- assertTrue("2.1", queue.removeTail().equals("9"));
- assertTrue("2.2", queue.peekTail().equals("8"));
-}
-public void testReusableElements() {
- /**/
- class ReusableObject {
- int value;
- };
-
- /* add elements */
- Queue queue = new Queue(10, true);
- for (int i = 0; i < 9; i++) {
- ReusableObject o = new ReusableObject();
- o.value = i;
- queue.add(o);
- }
-
- /* remove elements */
- for (int i = 0; i < 9; i++)
- queue.remove();
-
- /* add one more element to avoid null */
- queue.add(new ReusableObject());
-
- /* add again reusing the elements */
- for (int i = 0; i < 9; i++) {
- ReusableObject o = (ReusableObject) queue.getNextAvailableObject();
- assertTrue("1.0", o != null);
- o.value = i;
- queue.add(o);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/AllTests.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/AllTests.java
deleted file mode 100644
index eccf8c5..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/AllTests.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.watson;
-
-import junit.framework.*;
-
-public class AllTests extends TestCase {
-/**
- * AllTests constructor comment.
- * @param name java.lang.String
- */
-public AllTests() {
- super(null);
-}
-/**
- * AllTests constructor comment.
- * @param name java.lang.String
- */
-public AllTests(String name) {
- super(name);
-}
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(DeltaChainFlatteningTest.suite());
- suite.addTest(DeltaFlatteningTest.suite());
- suite.addTest(DeltaIteratorTest.suite());
- suite.addTest(ElementDeltaTest.suite());
- suite.addTest(ElementTreeDeltaChainTest.suite());
- suite.addTest(ElementTreeIteratorTest.suite());
- suite.addTest(ElementTreeTest.suite());
- suite.addTest(PluggableDeltaLogicTest.suite());
- suite.addTest(TreeFlatteningTest.suite());
- return suite;
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/DeltaChainFlatteningTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/DeltaChainFlatteningTest.java
deleted file mode 100644
index 1ada891..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/DeltaChainFlatteningTest.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.watson;
-
-import java.io.*;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.watson.*;
-import org.eclipse.core.runtime.IPath;
-
-public class DeltaChainFlatteningTest extends ElementTreeSerializationTest {
- protected ElementTree[] fDeltaChain;
- protected ElementTree[] fRefriedDeltaChain;
-public DeltaChainFlatteningTest() {
- super(null);
-}
-public DeltaChainFlatteningTest(String name) {
- super(name);
-}
-/**
- * doRead method comment.
- */
-public Object doRead(ElementTreeReader reader, DataInputStream input) throws IOException {
- return reader.readDeltaChain(input);
-}
-/**
- * Runs a test for this class at a certain depth and path
- */
-public void doTest(IPath path, int depth) {
- fSubtreePath = path;
- fDepth = depth;
- fDeltaChain = TestUtil.doRoutineOperations(fTree, project1);
- TestUtil.scramble(fDeltaChain);
-
- ElementTree[] refried = (ElementTree[])doPipeTest();
- for (int j = 0; j < refried.length; j++) {
- TestUtil.assertEqualTrees("Same after delta chain serialize", fDeltaChain[j], refried[j], fSubtreePath, fDepth);
- }
-}
-/**
- * doWrite method comment.
- */
-public void doWrite(ElementTreeWriter writer, DataOutputStream output) throws IOException {
- writer.writeDeltaChain(fDeltaChain, fSubtreePath, fDepth, output, DefaultElementComparator.getComparator());
-}
-/**
- * Sets up the delta chain to be serialized
- */
-protected void setUp() throws Exception {
- super.setUp();
- fTree = TestUtil.createTestElementTree();
- /* do a bunch of operations on fTree to build a delta chain */
- fDeltaChain = TestUtil.doManyRoutineOperations(fTree, project1);
-}
-public static Test suite() {
- TestSuite suite= new TestSuite(DeltaChainFlatteningTest.class);
- return suite;
-}
-/**
- * Tests the reading and writing of element deltas
- */
-public void test0() {
- doExhaustiveTests();
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/DeltaFlatteningTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/DeltaFlatteningTest.java
deleted file mode 100644
index 2cb07d8..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/DeltaFlatteningTest.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.watson;
-
-import java.io.*;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.watson.*;
-import org.eclipse.core.runtime.IPath;
-
-public class DeltaFlatteningTest extends ElementTreeSerializationTest {
- protected ElementTree fNewTree;
- protected IPath project3, folder5, file4, file5;
-public DeltaFlatteningTest() {
- super(null);
-}
-public DeltaFlatteningTest(String name) {
- super(name);
-}
-/**
- * Performs the serialization activity for this test
- */
-public Object doRead(ElementTreeReader reader, DataInputStream input) throws IOException {
- return reader.readDelta(fNewTree, input);
-}
-/**
- * Runs a test for this class at a certain depth and path
- */
-public void doTest(IPath path, int depth) {
-
- /* Get an element tree from somewhere. */
- fTree= TestUtil.createTestElementTree();
- fSubtreePath = path;
- fDepth = depth;
- ElementTree newTree = (ElementTree)doPipeTest();
- TestUtil.assertEqualTrees(this.getClass().toString() + "test0", fTree, newTree, fSubtreePath, fDepth);
-}
-/**
- * Performs the serialization activity for this test
- */
-public void doWrite(ElementTreeWriter writer, DataOutputStream output) throws IOException{
- writer.writeDelta(fTree, fNewTree, fSubtreePath, fDepth, output, DefaultElementComparator.getComparator());
-}
-protected void setUp() throws Exception {
- super.setUp();
- fTree = TestUtil.createTestElementTree();
- /**
- * The following changes will be made to the base tree:
- * - add project3
- * - add folder5 below project3
- * - delete file1
- * - change data of folder2
- * - add file4 below project2
- * - add file5 below folder1
- * - delete folder3
- */
-
- fNewTree = fTree.newEmptyDelta();
-
- project3 = solution.append("project3");
- folder5 = project3.append("folder5");
- file4 = project2.append("file4");
- file5 = folder1.append("file5");
-
- fNewTree.createElement(project3, "project3");
- fNewTree.createElement(folder5, "folder5");
- fNewTree.deleteElement(file1);
- fNewTree.createElement(folder2, "ChangedData");
- fNewTree.createElement(file4, "file4");
- fNewTree.createElement(file5, "file5");
- fNewTree.deleteElement(folder3);
- fNewTree.immutable();
-
- /* assert the new structure */
- TestUtil.assertHasPaths(fNewTree, new IPath[] {solution, project1, project2, project3,
- file2, file4, file5, folder1, folder2, folder4, folder5});
- TestUtil.assertNoPaths(fNewTree, new IPath[] {file1, file3, folder3});
-}
-public static Test suite() {
- TestSuite suite= new TestSuite(DeltaFlatteningTest.class);
- return suite;
-}
-/**
- * Tests the reading and writing of element deltas
- */
-public void test0() {
- doExhaustiveTests();
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/DeltaIteratorTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/DeltaIteratorTest.java
deleted file mode 100644
index f06dd9f..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/DeltaIteratorTest.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.watson;
-
-import java.util.Hashtable;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.watson.*;
-import org.eclipse.core.runtime.IPath;
-
-/**
- * Tests functionality of the DeltaIterator class
- */
-public class DeltaIteratorTest extends ElementDeltaTest implements IPathConstants {
-public DeltaIteratorTest() {
- super(null);
-}
-public DeltaIteratorTest(String name) {
- super(name);
-}
-protected String compareToString(int compare) {
- switch (compare) {
- case TestElementComparator.ADDED:
- return "ADDED";
- case TestElementComparator.REMOVED:
- return "REMOVED";
- case TestElementComparator.CHANGED:
- return "CHANGED";
- case 0:
- return "NOCHANGE";
- default:
- return "Unknown: " + compare;
- }
-}
-/**
- * Initializes a hashtable of IPath -> String describing the changes
- * For that path. The string is of the form oldObject:newObject:comparison.
- */
-protected Hashtable getChangeTable() {
- Hashtable table = new Hashtable();
- table.put(solution, "solution:solution:NOCHANGE");
- table.put(project2, "project2:project2:NOCHANGE");
- table.put(project3, "null:project3:ADDED");
- table.put(folder1, "folder1:folder1:NOCHANGE");
- table.put(folder2, "folder2:ChangedData:CHANGED");
- table.put(folder3, "folder3:null:REMOVED");
- table.put(folder5, "null:folder5:ADDED");
- table.put(file1, "file1:null:REMOVED");
- table.put(file3, "file3:null:REMOVED");
- table.put(file4, "null:file4:ADDED");
- table.put(file5, "null:file5:ADDED");
- return table;
-}
-public static Test suite() {
- TestSuite suite= new TestSuite(DeltaIteratorTest.class);
- return suite;
-}
-public void testIterator() {
- DeltaIterator iterator = new DeltaIterator();
-
- final Hashtable changeTable = getChangeTable();
-
- IDeltaVisitor visitor = new IDeltaVisitor() {
- public boolean visitElement(ElementTreeDelta tree, IPath path, Object oldData, Object newData, int comparison) {
-
- String val = (String)changeTable.remove(path);
- String visitVal = (oldData == null) ? "null" : oldData.toString();
- visitVal += ":" + newData + ":" + compareToString(comparison);
- assertEquals(val, visitVal);
- return true;
- }
- };
-
- iterator.iterate(fTreeDelta, visitor);
- assertTrue(changeTable.size() == 0);
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/ElementDeltaTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/ElementDeltaTest.java
deleted file mode 100644
index 320173d..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/ElementDeltaTest.java
+++ /dev/null
@@ -1,578 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.watson;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.watson.*;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-
-/**
- * Tests the class org.eclispe.core.internal.watson.ElementDelta
- */
-public class ElementDeltaTest extends WatsonTest implements IPathConstants {
- protected ElementTreeDelta fTreeDelta;
- protected ElementTree fTree, fNewTree;
-
- protected IPath project3, folder5, file4, file5;
-public ElementDeltaTest() {
- super(null);
-}
-public ElementDeltaTest(String name) {
- super(name);
-}
-protected void setUp() throws Exception {
- /**
- * The following changes will be made to the base tree:
- * - add project3
- * - add folder5 below project3
- * - delete file1
- * - change data of folder2
- * - add file4 below project2
- * - add file5 below folder1
- * - delete folder3
- */
-
- fTree = TestUtil.createTestElementTree();
- fNewTree = fTree.newEmptyDelta();
-
- project3 = solution.append("project3");
- folder5 = project3.append("folder5");
- file4 = project2.append("file4");
- file5 = folder1.append("file5");
-
- fNewTree.createElement(project3, "project3");
- fNewTree.createElement(folder5, "folder5");
- fNewTree.deleteElement(file1);
- fNewTree.createElement(folder2, "ChangedData");
- fNewTree.createElement(file4, "file4");
- fNewTree.createElement(file5, "file5");
- fNewTree.deleteElement(folder3);
- fNewTree.immutable();
-
- /* assert the new structure */
- TestUtil.assertHasPaths(fNewTree, new IPath[] {solution, project1, project2, project3,
- file2, file4, file5, folder1, folder2, folder4, folder5});
- TestUtil.assertNoPaths(fNewTree, new IPath[] {file1, file3, folder3});
-
- /* compute the delta */
- fTreeDelta = fNewTree.computeDeltaWith(fTree, TestUtil.getComparator());
-}
-public static Test suite() {
- TestSuite suite= new TestSuite(ElementDeltaTest.class);
- suite.addTest(DeltaIteratorTest.suite());
- return suite;
-}
-/**
- *
- */
-protected void tearDown() throws Exception {
- //ElementTree tests don't use the CoreTest infrastructure
-}
-/**
- * Tests the getAffectedChildren(filter) API method.
- */
-public void testGetAddedChildren() {
- /* create a filter for added children */
- IDeltaFilter filter = new IDeltaFilter() {
- public boolean includeElement(int flag) {
- return flag == TestElementComparator.ADDED;
- }
- };
-
- /* delta for root */
- ElementDelta delta = fTreeDelta.getElementDelta(Path.ROOT);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for solution */
- delta = fTreeDelta.getElementDelta(solution);
- ElementDelta[] addedChildren = delta.getAffectedChildren(filter);
- assertTrue(addedChildren.length == 1);
- assertTrue(addedChildren[0].getPath().equals(project3));
-
- /* delta for project1 */
- delta = fTreeDelta.getElementDelta(project1);
- assertTrue(delta == null);
-
- /* delta for project2 */
- delta = fTreeDelta.getElementDelta(project2);
- addedChildren = delta.getAffectedChildren(filter);
- assertTrue(addedChildren.length == 1);
- assertTrue(addedChildren[0].getPath().equals(file4));
-
-
- /* delta for project3 */
- delta = fTreeDelta.getElementDelta(project3);
- addedChildren = delta.getAffectedChildren(filter);
- assertTrue(addedChildren.length == 1);
- assertTrue(addedChildren[0].getPath().equals(folder5));
-
- /* delta for folder1 */
- delta = fTreeDelta.getElementDelta(folder1);
- addedChildren = delta.getAffectedChildren(filter);
- assertTrue(addedChildren.length == 1);
- assertTrue(addedChildren[0].getPath().equals(file5));
-
-
- /* delta for folder2 */
- delta = fTreeDelta.getElementDelta(folder2);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for folder3 */
- delta = fTreeDelta.getElementDelta(folder3);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for folder4 */
- delta = fTreeDelta.getElementDelta(folder4);
- assertTrue(delta == null);
-
- /* delta for folder5 */
- delta = fTreeDelta.getElementDelta(folder5);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for file1 */
- delta = fTreeDelta.getElementDelta(file1);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for file2 */
- delta = fTreeDelta.getElementDelta(file2);
- assertTrue(delta == null);
-
- /* delta for file3 */
- delta = fTreeDelta.getElementDelta(file3);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for file4 */
- delta = fTreeDelta.getElementDelta(file4);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for file5 */
- delta = fTreeDelta.getElementDelta(file5);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-}
-/**
- * Tests the getAffectedChildren API call.
- */
-public void testGetAffectedChildren() {
- IDeltaFilter filter = TestUtil.getFilter();
- /* delta for root */
- ElementDelta delta = fTreeDelta.getElementDelta(Path.ROOT);
- ElementDelta[] children = delta.getAffectedChildren(filter);
- assertTrue(children.length == 1);
- assertTrue(children[0].getPath().equals(solution));
-
- /* delta for solution */
- delta = fTreeDelta.getElementDelta(solution);
- children = delta.getAffectedChildren(filter);
- assertTrue(children.length == 2);
- assertTrue(children[0].getPath().equals(project2));
- assertTrue(children[1].getPath().equals(project3));
-
- /* delta for project1 */
- delta = fTreeDelta.getElementDelta(project1);
- assertTrue(delta == null);
-
- /* delta for project2 */
- delta = fTreeDelta.getElementDelta(project2);
- children = delta.getAffectedChildren(filter);
- assertTrue(children.length == 4);
- assertTrue(children[0].getPath().equals(file1));
- assertTrue(children[1].getPath().equals(file4));
- assertTrue(children[2].getPath().equals(folder1));
- assertTrue(children[3].getPath().equals(folder2));
-
- /* delta for project3 */
- delta = fTreeDelta.getElementDelta(project3);
- children = delta.getAffectedChildren(filter);
- assertTrue(children.length == 1);
- assertTrue(children[0].getPath().equals(folder5));
-
- /* delta for folder1 */
- delta = fTreeDelta.getElementDelta(folder1);
- children = delta.getAffectedChildren(filter);
- assertTrue(children.length == 2);
- assertTrue(children[0].getPath().equals(file5));
- assertTrue(children[1].getPath().equals(folder3));
-
- /* delta for folder2 */
- delta = fTreeDelta.getElementDelta(folder2);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for folder3 */
- delta = fTreeDelta.getElementDelta(folder3);
- children = delta.getAffectedChildren(filter);
- assertTrue(children.length == 1);
- assertTrue(children[0].getPath().equals(file3));
-
- /* delta for folder4 */
- delta = fTreeDelta.getElementDelta(folder4);
- assertTrue(delta == null);
-
- /* delta for folder5 */
- delta = fTreeDelta.getElementDelta(folder5);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for file1 */
- delta = fTreeDelta.getElementDelta(file1);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for file2 */
- delta = fTreeDelta.getElementDelta(file2);
- assertTrue(delta == null);
-
- /* delta for file3 */
- delta = fTreeDelta.getElementDelta(file3);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for file4 */
- delta = fTreeDelta.getElementDelta(file4);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for file5 */
- delta = fTreeDelta.getElementDelta(file5);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-}
-/**
- * Tests the getChangedChildren API call
- */
-public void testGetChangedChildren() {
- /* create a filter for changed children */
- IDeltaFilter filter = new IDeltaFilter() {
- public boolean includeElement(int flag) {
- return flag == TestElementComparator.CHANGED;
- }
- };
-
- /* delta for root */
- ElementDelta delta = fTreeDelta.getElementDelta(Path.ROOT);
- ElementDelta[] children = delta.getAffectedChildren(filter);
- assertTrue(children.length == 0);
-
- /* delta for solution */
- delta = fTreeDelta.getElementDelta(solution);
- children = delta.getAffectedChildren(filter);
- assertTrue(children.length == 0);
-
- /* delta for project1 */
- delta = fTreeDelta.getElementDelta(project1);
- assertTrue(delta == null);
-
- /* delta for project2 */
- delta = fTreeDelta.getElementDelta(project2);
- children = delta.getAffectedChildren(filter);
- assertTrue(children.length == 1);
- assertTrue(children[0].getPath().equals(folder2));
-
- /* delta for project3 */
- delta = fTreeDelta.getElementDelta(project3);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for folder1 */
- delta = fTreeDelta.getElementDelta(folder1);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for folder2 */
- delta = fTreeDelta.getElementDelta(folder2);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for folder3 */
- delta = fTreeDelta.getElementDelta(folder3);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for folder4 */
- delta = fTreeDelta.getElementDelta(folder4);
- assertTrue(delta == null);
-
- /* delta for folder5 */
- delta = fTreeDelta.getElementDelta(folder5);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for file1 */
- delta = fTreeDelta.getElementDelta(file1);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for file2 */
- delta = fTreeDelta.getElementDelta(file2);
- assertTrue(delta == null);
-
- /* delta for file3 */
- delta = fTreeDelta.getElementDelta(file3);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for file4 */
- delta = fTreeDelta.getElementDelta(file4);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for file5 */
- delta = fTreeDelta.getElementDelta(file5);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-}
-/**
- * Tests the getComparison() API call
- */
-public void testGetComparison() {
- /* delta for root */
- ElementDelta delta = fTreeDelta.getElementDelta(Path.ROOT);
- TestUtil.assertNoChange(delta.getComparison());
-
- /* delta for solution */
- delta = fTreeDelta.getElementDelta(solution);
- TestUtil.assertNoChange(delta.getComparison());
-
- /* delta for project1 */
- delta = fTreeDelta.getElementDelta(project1);
- assertTrue(delta == null);
-
- /* delta for project2 */
- delta = fTreeDelta.getElementDelta(project2);
- TestUtil.assertNoChange(delta.getComparison());
-
- /* delta for project3 */
- delta = fTreeDelta.getElementDelta(project3);
- TestUtil.assertAdded(delta.getComparison());
-
- /* delta for folder1 */
- delta = fTreeDelta.getElementDelta(folder1);
- TestUtil.assertNoChange(delta.getComparison());
-
- /* delta for folder2 */
- delta = fTreeDelta.getElementDelta(folder2);
- TestUtil.assertChanged(delta.getComparison());
-
- /* delta for folder3 */
- delta = fTreeDelta.getElementDelta(folder3);
- TestUtil.assertRemoved(delta.getComparison());
-
- /* delta for folder4 */
- delta = fTreeDelta.getElementDelta(folder4);
- assertTrue(delta == null);
-
- /* delta for folder5 */
- delta = fTreeDelta.getElementDelta(folder5);
- TestUtil.assertAdded(delta.getComparison());
-
- /* delta for file1 */
- delta = fTreeDelta.getElementDelta(file1);
- TestUtil.assertRemoved(delta.getComparison());
-
- /* delta for file2 */
- delta = fTreeDelta.getElementDelta(file2);
- assertTrue(delta == null);
-
- /* delta for file3 */
- delta = fTreeDelta.getElementDelta(file3);
- TestUtil.assertRemoved(delta.getComparison());
-
- /* delta for file4 */
- delta = fTreeDelta.getElementDelta(file4);
- TestUtil.assertAdded(delta.getComparison());
-
- /* delta for file5 */
- delta = fTreeDelta.getElementDelta(file5);
- TestUtil.assertAdded(delta.getComparison());
-}
-/**
- * Tests the getElementDelta API call. This method is basically
- * a template for all other tests in this class.
- */
-public void testGetElementDelta() {
- /* delta for root */
- ElementDelta delta = fTreeDelta.getElementDelta(Path.ROOT);
-
- /* delta for solution */
- delta = fTreeDelta.getElementDelta(solution);
-
- /* delta for project1 */
- delta = fTreeDelta.getElementDelta(project1);
- assertTrue(delta == null);
-
- /* delta for project2 */
- delta = fTreeDelta.getElementDelta(project2);
-
- /* delta for project3 */
- delta = fTreeDelta.getElementDelta(project3);
-
- /* delta for folder1 */
- delta = fTreeDelta.getElementDelta(folder1);
-
- /* delta for folder2 */
- delta = fTreeDelta.getElementDelta(folder2);
-
- /* delta for folder3 */
- delta = fTreeDelta.getElementDelta(folder3);
-
- /* delta for folder4 */
- delta = fTreeDelta.getElementDelta(folder4);
- assertTrue(delta == null);
-
- /* delta for folder5 */
- delta = fTreeDelta.getElementDelta(folder5);
-
- /* delta for file1 */
- delta = fTreeDelta.getElementDelta(file1);
-
- /* delta for file2 */
- delta = fTreeDelta.getElementDelta(file2);
- assertTrue(delta == null);
-
- /* delta for file3 */
- delta = fTreeDelta.getElementDelta(file3);
-
- /* delta for file4 */
- delta = fTreeDelta.getElementDelta(file4);
-
- /* delta for file5 */
- delta = fTreeDelta.getElementDelta(file5);
-}
-/**
- * Tests the getRemovedChildren API call
- */
-public void testGetRemovedChildren() {
- /* create a filter for removed children */
- IDeltaFilter filter = new IDeltaFilter() {
- public boolean includeElement(int flag) {
- return flag == TestElementComparator.REMOVED;
- }
- };
-
- /* delta for root */
- ElementDelta delta = fTreeDelta.getElementDelta(Path.ROOT);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for solution */
- delta = fTreeDelta.getElementDelta(solution);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for project1 */
- delta = fTreeDelta.getElementDelta(project1);
- assertTrue(delta == null);
-
- /* delta for project2 */
- delta = fTreeDelta.getElementDelta(project2);
- ElementDelta[] children = delta.getAffectedChildren(filter);
- assertTrue(children.length == 1);
- assertTrue(children[0].getPath().equals(file1));
-
- /* delta for project3 */
- delta = fTreeDelta.getElementDelta(project3);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for folder1 */
- delta = fTreeDelta.getElementDelta(folder1);
- children = delta.getAffectedChildren(filter);
- assertTrue(children.length == 1);
- assertTrue(children[0].getPath().equals(folder3));
-
- /* delta for folder2 */
- delta = fTreeDelta.getElementDelta(folder2);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for folder3 */
- delta = fTreeDelta.getElementDelta(folder3);
- children = delta.getAffectedChildren(filter);
- assertTrue(children.length == 1);
- assertTrue(children[0].getPath().equals(file3));
-
- /* delta for folder4 */
- delta = fTreeDelta.getElementDelta(folder4);
- assertTrue(delta == null);
-
- /* delta for folder5 */
- delta = fTreeDelta.getElementDelta(folder5);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for file1 */
- delta = fTreeDelta.getElementDelta(file1);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for file2 */
- delta = fTreeDelta.getElementDelta(file2);
- assertTrue(delta == null);
-
- /* delta for file3 */
- delta = fTreeDelta.getElementDelta(file3);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for file4 */
- delta = fTreeDelta.getElementDelta(file4);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for file5 */
- delta = fTreeDelta.getElementDelta(file5);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-}
-/**
- * Tests the hasAffectedChildren API call.
- */
-public void testHasAffectedChildren() {
- IDeltaFilter filter = TestUtil.getFilter();
- /* delta for root */
- ElementDelta delta = fTreeDelta.getElementDelta(Path.ROOT);
- assertTrue(delta.hasAffectedChildren(filter));
-
- /* delta for solution */
- delta = fTreeDelta.getElementDelta(solution);
- assertTrue(delta.hasAffectedChildren(filter));
-
- /* delta for project1 */
- delta = fTreeDelta.getElementDelta(project1);
- assertTrue(delta == null);
-
- /* delta for project2 */
- delta = fTreeDelta.getElementDelta(project2);
- assertTrue(delta.hasAffectedChildren(filter));
-
- /* delta for project3 */
- delta = fTreeDelta.getElementDelta(project3);
- assertTrue(delta.hasAffectedChildren(filter));
-
- /* delta for folder1 */
- delta = fTreeDelta.getElementDelta(folder1);
- assertTrue(delta.hasAffectedChildren(filter));
-
- /* delta for folder2 */
- delta = fTreeDelta.getElementDelta(folder2);
- assertTrue(delta.getAffectedChildren(filter).length == 0);
-
- /* delta for folder3 */
- delta = fTreeDelta.getElementDelta(folder3);
- assertTrue(delta.hasAffectedChildren(filter));
-
- /* delta for folder4 */
- delta = fTreeDelta.getElementDelta(folder4);
- assertTrue(delta == null);
-
- /* delta for folder5 */
- delta = fTreeDelta.getElementDelta(folder5);
- assertTrue(!delta.hasAffectedChildren(filter));
-
- /* delta for file1 */
- delta = fTreeDelta.getElementDelta(file1);
- assertTrue(!delta.hasAffectedChildren(filter));
-
- /* delta for file2 */
- delta = fTreeDelta.getElementDelta(file2);
- assertTrue(delta == null);
-
- /* delta for file3 */
- delta = fTreeDelta.getElementDelta(file3);
- assertTrue(!delta.hasAffectedChildren(filter));
-
- /* delta for file4 */
- delta = fTreeDelta.getElementDelta(file4);
- assertTrue(!delta.hasAffectedChildren(filter));
-
- /* delta for file5 */
- delta = fTreeDelta.getElementDelta(file5);
- assertTrue(!delta.hasAffectedChildren(filter));
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/ElementTreeDeltaChainTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/ElementTreeDeltaChainTest.java
deleted file mode 100644
index 03a71a5..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/ElementTreeDeltaChainTest.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.watson;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.watson.ElementTree;
-import org.eclipse.core.runtime.IPath;
-/**
- * Tests the ElementTree.mergeDeltaChain() method.
- */
-public class ElementTreeDeltaChainTest extends WatsonTest implements IPathConstants {
- protected ElementTree fTree;
- protected IPath project3;
-public ElementTreeDeltaChainTest() {
- super(null);
-}
-public ElementTreeDeltaChainTest(String name) {
- super(name);
-}
-protected void setUp() throws Exception {
- fTree = TestUtil.createTestElementTree();
- project3 = solution.append("project3");
-}
-public static Test suite() {
- TestSuite suite= new TestSuite(ElementTreeDeltaChainTest.class);
- return suite;
-}
-/**
- *
- */
-protected void tearDown() throws Exception {
- //ElementTree tests don't use the CoreTest infrastructure
-}
-/**
- * Tries some bogus merges and makes sure an exception is thrown.
- */
-public void testIllegalMerges() {
- fTree = fTree.newEmptyDelta();
-
- /* null trees */
- boolean caught = false;
- Exception ex = null;
- try {
- fTree.mergeDeltaChain(solution, null);
- } catch (RuntimeException e) {
- caught = true;
- ex = e;
- } finally {
- assertTrue(ex.getMessage(), caught);
- }
-
- /* create a tree with a whole bunch of operations in project3 */
- ElementTree projectTree = new ElementTree();
- projectTree.createElement(solution, "Dummy");
- projectTree.createElement(project3, "project3");
- ElementTree[] trees = TestUtil.doManyRoutineOperations(projectTree, project3);
-
- /* scramble the order of the project trees */
- TestUtil.scramble(trees);
-
- /* null handle */
- caught = false;
- try {
- fTree.mergeDeltaChain(null, trees);
- } catch (RuntimeException e) {
- caught = true;
- ex = e;
- } finally {
- assertTrue(ex.getMessage(), caught);
- }
-
- /* non-existent handle */
- caught = false;
- try {
- fTree.mergeDeltaChain(solution.append("bogosity"), trees);
- } catch (RuntimeException e) {
- caught = true;
- ex = e;
- } finally {
- assertTrue(ex.getMessage(), caught);
- }
-
- /* immutable receiver */
- caught = false;
- try {
- fTree.immutable();
- fTree.mergeDeltaChain(solution, trees);
- } catch (RuntimeException e) {
- caught = true;
- ex = e;
- } finally {
- assertTrue(ex.getMessage(), caught);
- }
-}
-/**
- * Tests the mergeDeltaChain method
- */
-public void testMergeDeltaChain() {
- /* create a tree with a whole bunch of operations in project3 */
- ElementTree projectTree = new ElementTree();
- projectTree.createElement(solution, "Dummy");
- projectTree.createElement(project3, "project3");
- ElementTree[] trees = TestUtil.doManyRoutineOperations(projectTree, project3);
-
- /* create a copy for testing purposes */
- ElementTree copyTree = new ElementTree();
- copyTree.createElement(solution, "Dummy");
- copyTree.createElement(project3, "project3");
- ElementTree[] copies = TestUtil.doManyRoutineOperations(copyTree, project3);
-
- /* scramble the order of the project trees */
- TestUtil.scramble(trees, copies);
-
- /* do a bunch of operations on fTree to build a delta chain */
- TestUtil.doRoutineOperations(fTree, solution);
- fTree = fTree.newEmptyDelta();
-
- /* merge the delta chains */
- ElementTree newTree = fTree.mergeDeltaChain(project3, trees);
- assertTrue("returned tree should be different", !(newTree == fTree));
- assertTrue("returned tree should be open", !newTree.isImmutable());
-
- /* make sure old and new trees have same structure */
- for (int i = 0; i < trees.length; i++) {
- TestUtil.assertEqualTrees("testMergeDeltaChain: " + i,
- copies[i].getSubtree(project3),
- trees[i].getSubtree(project3));
- }
-
- TestUtil.assertHasPaths(newTree, TestUtil.getTreePaths());
- TestUtil.assertHasPaths(newTree, new IPath[] {project3});
-}
-/**
- * Performs merge on trees that have nodes in common. The chain
- * being merged should overwrite the receiver.
- */
-public void testMergeOverwrite() {
- /* create a tree with a whole bunch of operations in project3 */
- ElementTree projectTree = new ElementTree();
- projectTree.createElement(solution, "Dummy");
- projectTree.createElement(project3, "project3");
-
- /* form a delta chain on fTree */
- ElementTree[] trees = TestUtil.doManyRoutineOperations(fTree, solution);
-
- /* scramble the order of the project trees */
- TestUtil.scramble(trees);
-
- /* merge the delta chains */
- ElementTree newTree = projectTree.mergeDeltaChain(solution, trees);
-
- assertTrue(!(newTree == projectTree));
- assertTrue(newTree.getElementData(solution).equals("solution"));
- TestUtil.assertTreeStructure(newTree);
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/ElementTreeIteratorTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/ElementTreeIteratorTest.java
deleted file mode 100644
index 22d70ac..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/ElementTreeIteratorTest.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.watson;
-
-import java.util.ArrayList;
-import java.util.Stack;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.watson.*;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-
-/**
- * Unit tests for <code>ElementTreeIterator</code>.
- */
-public class ElementTreeIteratorTest extends WatsonTest {
-public ElementTreeIteratorTest() {
- super(null);
-}
-public ElementTreeIteratorTest(String name) {
- super(name);
-}
-protected void setUp() throws Exception {
-}
-static void setupElementTree(ElementTree tree, int num) {
- final IElementTreeData data = new IElementTreeData() {
- public Object clone() {
- try {
- return super.clone();
- } catch (CloneNotSupportedException e) {
- }
- return null;
- }
- };
- IPath sol= Path.ROOT.append("sol");
- tree.createElement(sol, data);
- for(int p=0;p<num;p++){
- IPath proj = sol.append("proj"+p);
- tree.createElement(proj, data);
- for(int k=0;k<num;k++){
- IPath folder = proj.append("folder"+k);
- tree.createElement(folder, data);
- for(int c=0;c<num;c++){
- IPath file = folder.append("file"+c);
- tree.createElement(file, data);
- }
- }
- }
-}
-
-public void testConcurrentModification() {
- //the dining detectives problem
- ElementTree baseTree = new ElementTree();
- int n= 3;
- setupElementTree(baseTree, n);
- baseTree.immutable();
- final ElementTree tree = baseTree.newEmptyDelta();
- modifyTree(tree);
- final ArrayList elts = new ArrayList();
- final IElementContentVisitor visitor = new IElementContentVisitor() {
- public boolean visitElement(ElementTree tree, IPathRequestor requestor, Object info) {
- elts.add(info);
- return true;
- }
- };
- Thread reader = new Thread(new Runnable() {
- public void run() {
- for (int i = 0; i < 80000; i++) {
- new ElementTreeIterator(tree, Path.ROOT).iterate(visitor);
- }
- }
- }, "Holmes (reader)");
- Thread writer = new Thread(new Runnable() {
- public void run() {
- for (int i = 0; i < 1000; i++) {
- modifyTree(tree);
- recursiveDelete(tree, Path.ROOT);
- setupElementTree(tree, 3);
- }
- }
- }, "Doyle (writer)");
-
- reader.start();
- writer.start();
- //wait for both threads to finish
- try {
- reader.join();
- writer.join();
- } catch (InterruptedException e) {
- }
-}
-public static Test suite() {
- TestSuite suite= new TestSuite(ElementTreeIteratorTest.class);
- return suite;
-}
-/**
- *
- */
-protected void tearDown() throws Exception {
- //ElementTree tests don't use the CoreTest infrastructure
-}
-public void testContentIterator() {
- ElementTree tree = new ElementTree();
- int n= 3;
- setupElementTree(tree, n);
- final ArrayList elts = new ArrayList();
- IElementContentVisitor elementVisitor = new IElementContentVisitor() {
- public boolean visitElement(ElementTree tree, IPathRequestor requestor, Object info) {
- elts.add(requestor.requestPath());
- return true;
- }
- };
- new ElementTreeIterator(tree, Path.ROOT).iterate(elementVisitor);
- assertEquals("1", 2+n+n*n+n*n*n, elts.size());
-
- elts.clear();
- IPath innerElement = Path.ROOT.append("sol").append("proj1");
- new ElementTreeIterator(tree, innerElement).iterate(elementVisitor);
- assertEquals("2", 1+n+n*n, elts.size());
-}
-/**
- * Method deleteChild.
- * @param path
- */
-private void recursiveDelete(ElementTree tree, IPath path) {
- IPath[] children = tree.getChildren(path);
- for (int i = 0; i < children.length; i++) {
- recursiveDelete(tree, children[i]);
- }
- tree.deleteElement(path);
-}
-protected void modifyTree(ElementTree tree) {
- class MyStack extends Stack {
- public void pushAll(Object[] array) {
- for (int i = 0; i < array.length; i++) {
- push(array[i]);
- }
- }
- };
- MyStack toModify = new MyStack();
- IPath[] children = tree.getChildren(Path.ROOT);
- toModify.pushAll(children);
- while (!toModify.isEmpty()) {
- IPath visit = (IPath)toModify.pop();
- tree.openElementData(visit);
- toModify.pushAll(tree.getChildren(visit));
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/ElementTreeSerializationTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/ElementTreeSerializationTest.java
deleted file mode 100644
index f8b844b..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/ElementTreeSerializationTest.java
+++ /dev/null
@@ -1,267 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.watson;
-
-import java.io.*;
-
-import org.eclipse.core.internal.watson.*;
-import org.eclipse.core.runtime.IPath;
-
-public abstract class ElementTreeSerializationTest extends WatsonTest implements IPathConstants {
-
- protected ElementTree fTree;
-
- String root = System.getProperty("user.dir");
- protected File tempFile = new File(root + "/temp/TestFlattening");
-
-
- class WriterThread implements Runnable {
- DataOutputStream fDataOutputStream;
- ElementTreeWriter fWriter;
- public void setStream(DataOutputStream stream){
- fDataOutputStream = stream;
- }
- public void setWriter(ElementTreeWriter writer){
- fWriter = writer;
- }
- public void run(){
- try{
- doWrite(fWriter, fDataOutputStream);
- }
- catch(IOException e) {
- assertTrue("Error writing delta", false);
- e.printStackTrace();
- }
- }
- }
-
- class ReaderThread implements Runnable {
- DataInputStream fDataInputStream;
- ElementTreeReader fReader;
- Object fRefried;
-
- public void setStream(DataInputStream stream) {
- fDataInputStream = stream;
- }
- public void setReader(ElementTreeReader reader) {
- fReader = reader;
- }
- public Object getReconstitutedObject() {
- return fRefried;
- }
- public void run() {
- try{
- fRefried = doRead(fReader, fDataInputStream);
- }
- catch(IOException e) {
- assertTrue("Error reading delta", false);
- e.printStackTrace();
- }
- }
- }
-
- WriterThread writerThread = new WriterThread();
- ReaderThread readerThread = new ReaderThread();
-
- /**
- * The subtree to write
- */
- protected IPath fSubtreePath;
-
- /**
- * The depth of the tree to write.
- */
- protected int fDepth;
-
-public ElementTreeSerializationTest() {
- super(null);
-}
-/**
- * ElementTreeSerializationTests constructor comment.
- * @param name java.lang.String
- */
-public ElementTreeSerializationTest(String name) {
- super(name);
-}
-/**
- * Performs exhaustive tests for all subtrees and all depths
- */
-protected void doExhaustiveTests() {
- IPath[] paths = TestUtil.getTreePaths();
- int[] depths = getTreeDepths();
-
- for (int p = 0; p < paths.length; p++) {
- for (int d = 0; d < depths.length; d++) {
- doTest(paths[p], depths[d]);
- }
- }
-}
-/**
- * Write a flattened element tree to a file and read it back.
- */
-public Object doFileTest() {
- IElementInfoFlattener fac = getFlattener();
-
- Object newTree= null;
- ElementTreeWriter writer = new ElementTreeWriter(fac);
- ElementTreeReader reader = new ElementTreeReader(fac);
- FileOutputStream fos= null;
- FileInputStream fis= null;
- DataOutputStream dos= null;
- DataInputStream dis= null;
-
- /* Write the element tree. */
- try {
- File dir = tempFile.getParentFile();
- dir.mkdirs();
- fos = new FileOutputStream(tempFile);
- dos = new DataOutputStream(fos);
- } catch (IOException e) {
- e.printStackTrace();
- assertTrue("Unable to open ouput file", false);
- }
- try {
- doWrite(writer, dos);
- } catch (IOException e) {
- e.printStackTrace();
- assertTrue("Error writing tree to file", false);
- } finally {
- try {
- dos.flush();
- fos.close();
- } catch (IOException e) {
- e.printStackTrace();
- assertTrue("Unable to close output file!", false);
- }
- }
-
- /* Read the element tree. */
- try {
- fis = new FileInputStream(tempFile);
- dis = new DataInputStream(fis);
- } catch (IOException e) {
- e.printStackTrace();
- assertTrue("Unable to open input file", false);
- }
- try {
- newTree = doRead(reader, dis);
- } catch (IOException e) {
- e.printStackTrace();
- assertTrue("Error reading tree from file", false);
- } finally {
- try {
- fis.close();
- } catch (IOException e) {
- e.printStackTrace();
- assertTrue("Unable to close input file!", false);
- }
- }
- return newTree;
-}
-/** Pipe a flattened element tree from writer to reader threads.
- */
-public Object doPipeTest() {
- IElementInfoFlattener fac = getFlattener();
- Object refried = null;
- ElementTreeWriter w = new ElementTreeWriter(fac);
- ElementTreeReader r = new ElementTreeReader(fac);
- PipedOutputStream pout;
- PipedInputStream pin;
- DataOutputStream oos;
- DataInputStream ois;
-
- /* Pipe the element tree from writer to reader threads. */
- try {
- pout = new PipedOutputStream();
- pin = new PipedInputStream(pout);
- oos = new DataOutputStream(pout); //new FileOutputStream(FILE_NAME));
- ois = new DataInputStream(pin);
- writerThread.setStream(oos);
- readerThread.setStream(ois);
- writerThread.setWriter(w);
- readerThread.setReader(r);
- Thread thread1 = new Thread(writerThread);
- Thread thread2 = new Thread(readerThread);
- thread1.start();
- thread2.start();
- while (thread2.isAlive()) {
- try {
- thread2.join();
- } catch (InterruptedException excp) {
- }
- }
- refried = readerThread.getReconstitutedObject();
- ois.close();
- oos.close();
- } catch (IOException e) {
- e.printStackTrace();
- assertTrue("Unable to open stream:", false);
- }
- return refried;
-}
-/**
- * Performs the serialization activity for this test
- */
-public abstract Object doRead(ElementTreeReader reader, DataInputStream input) throws IOException;
-/**
- * Runs a test for this class at a certain depth and path
- */
-public abstract void doTest(IPath path, int depth);
-/**
- * Performs the serialization activity for this test
- */
-public abstract void doWrite(ElementTreeWriter writer, DataOutputStream output) throws IOException;
-/**
- * Tests the reading and writing of element deltas
- */
-public IElementInfoFlattener getFlattener() {
- return new IElementInfoFlattener() {
- public void writeElement(IPath path, Object data, DataOutput output) throws IOException {
- if (data == null) {
- output.writeUTF("null");
- } else {
- output.writeUTF((String)data);
- }
- }
- public Object readElement(IPath path, DataInput input) throws IOException {
- String data = input.readUTF();
- if ("null".equals(data)) {
- return null;
- } else {
- return data;
- }
- }
- };
-}
-/**
- * Returns all the different possible depth values for this tree.
- * To be conservative, it is okay if some of the returned depths
- * are not possible.
- */
-protected int[] getTreeDepths() {
- return new int[] {-1, 0, 1, 2, 3, 4};
-}
-protected void setUp() throws Exception {
- fTree = TestUtil.createTestElementTree();
- /* default subtree we are interested in */
- fSubtreePath = solution;
-
- /* default depth is the whole tree */
- fDepth = ElementTreeWriter.D_INFINITE;
-}
-/**
- *
- */
-protected void tearDown() throws Exception {
- //ElementTree tests don't use the CoreTest infrastructure
- tempFile.delete();
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/ElementTreeTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/ElementTreeTest.java
deleted file mode 100644
index f3bf17c..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/ElementTreeTest.java
+++ /dev/null
@@ -1,962 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.watson;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.watson.*;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-
-/**
- * Unit tests for <code>ElementTree</code>.
- */
-public class ElementTreeTest extends WatsonTest implements IPathConstants {
- protected ElementTree fTree;
- protected ElementTree fEmptyTree = new ElementTree();
-public ElementTreeTest() {
- super(null);
-}
-public ElementTreeTest(String name) {
- super(name);
-}
-/**
- * Creates a chain of deltas such that the final tree has the same
- * content as the base tree. Returns the final tree.
- */
-protected ElementTree buildDeltaChain(ElementTree baseTree) {
- /* do a bunch of operations to build a chain of deltas */
- ElementTree tree1 = baseTree.newEmptyDelta();
-
- IPath project3 = solution.append("project3");
- tree1.createElement(project3, null);
- tree1.immutable();
- assertTrue(tree1.hasAncestor(baseTree));
-
- ElementTree tree2 = tree1.newEmptyDelta();
- tree2.setElementData(project3, "Hello");
- tree2.immutable();
- assertTrue(tree2.hasAncestor(baseTree));
-
- ElementTree tree3 = tree2.newEmptyDelta();
- tree3.setElementData(project3, null);
- tree3.immutable();
- assertTrue(tree3.hasAncestor(baseTree));
-
- ElementTree tree4 = tree3.newEmptyDelta();
- tree4.deleteElement(project3);
-
- /* tree4 should be same as original tree */
- TestUtil.assertTreeStructure(tree4);
-
- IPath file33 = folder2.append("file33");
- tree4.createElement(file33, null);
- tree4.immutable();
- assertTrue(tree4.hasAncestor(baseTree));
-
- ElementTree tree5 = tree4.newEmptyDelta();
- tree5.setElementData(file33, "Hello");
- tree5.immutable();
- assertTrue(tree5.hasAncestor(baseTree));
-
- ElementTree tree6 = tree5.newEmptyDelta();
- tree6.setElementData(file33, null);
- tree6.immutable();
- assertTrue(tree6.hasAncestor(baseTree));
-
- ElementTree tree7 = tree6.newEmptyDelta();
- tree7.deleteElement(file33);
- tree7.immutable();
- assertTrue(tree7.hasAncestor(baseTree));
-
- /* final tree should be same as original tree */
- TestUtil.assertTreeStructure(tree7);
-
- return tree7;
-}
-/**
- * Tests the getSubtree and createSubtree API calls.
- */
-public void copySubtree(ElementTree oldTree, ElementTree newTree, IPath key) {
- try {
- newTree.createSubtree(key, oldTree.getSubtree(key));
- } catch (IllegalArgumentException e) {
- assertTrue(key.equals(Path.ROOT));
- }
-
- /* recurse on children (redundant, but we're testing) */
- IPath[] children = oldTree.getChildren(key);
- for (int i = 0; i < children.length; i++) {
- copySubtree(oldTree, newTree, children[i]);
- }
-}
-protected void setUp() throws Exception {
- fTree = TestUtil.createTestElementTree();
-}
-public static Test suite() {
- TestSuite suite= new TestSuite(ElementTreeTest.class);
-// suite.addTest(new ElementTreeTest("testRegression1FVVP6L"));
- return suite;
-}
-/**
- *
- */
-protected void tearDown() throws Exception {
- //ElementTree tests don't use the CoreTest infrastructure
-}
-public void testBottomUpCreation() {
-
- /* Create a root with no children. */
- ElementTree tree = new ElementTree();
- IPath rootID = (IPath)Path.ROOT.append("sol1");
- tree.createElement(rootID, "ROOTS");
-
- /* Create two grandchildren */
- ElementTree f1 = new ElementTree("TestFile1", "INFO 1");
- ElementTree f2 = new ElementTree("TestFile2", "INFO 2");
- ElementTree[] filez = {f1, f2};
-
- /* Create a child type containing the grandchildren. */
- ElementTree subtree = new ElementTree("TestProject", "INFO 3", filez);
-
- IPath projectID= rootID.append("TestProject");
- IPath file1ID = projectID.append("TestFile1");
- IPath file2ID = projectID.append("TestFile2");
-
- /* Add the child to the root. */
- tree.createSubtree(projectID, subtree);
- TestUtil.assertHasPaths(tree, new IPath[] {projectID, file1ID, file2ID});
-}
-public void testChildCreation() {
- /* basic child creation is tested during setup... */
- TestUtil.assertTreeStructure(fTree);
-
- /* add to empty tree */
- IPath key = Path.ROOT.append("only"); assertTrue("not includes", !fEmptyTree.includes(key));
- fEmptyTree.createElement(key, new Integer(4));
- assertTrue("includes", fEmptyTree.includes(key));
-
- /* add child of non-existent parent */
- key = Path.ROOT.append("bogus").append("figment");
- assertTrue("not1", !fEmptyTree.includes(key));
- boolean caught = false;
- try {
- fEmptyTree.createElement(key, null);
- } catch (IllegalArgumentException e) {
- caught = true;
- } finally {
- assertTrue("caught1", caught);
- }
-
- /* test creation on an immutable tree */
- key = Path.ROOT.append("only");
- fTree.immutable();
-
- caught = false;
- try {
- fTree.createElement(key, new Integer(4));
- } catch (RuntimeException e) {
- caught = true;
- } finally {
- assertTrue("caught2", caught);
- }
- assertTrue("not includes2", !fTree.includes(key));
-
- /* test creation on delta */
- ElementTree delta = fTree.newEmptyDelta();
- assertTrue("not includes3", !delta.includes(key));
- delta.createElement(key, new Integer(4));
- assertTrue("includes2", delta.includes(key));
- assertTrue("not includes4", !fTree.includes(key));
-
-}
-public void testChildDeletion() {
-
- /* Delete the tree bottom-up */
- IPath[] paths = TestUtil.getTreePaths();
- int numPaths = paths.length;
-
- for (int i = numPaths; --i >=0;) {
- assertTrue("includes"+i, fTree.includes(paths[i]));
- fTree.deleteElement(paths[i]);
- assertTrue("not includes"+i, !fTree.includes(paths[i]));
- }
-
- /* rebuild the tree */
- fTree = TestUtil.createTestElementTree();
-
- /* delete the tree top-down */
- fTree.deleteElement(solution) ;
-
- /* make sure there's nothing left */
- for (int i = 0; i < numPaths; i++) {
- assertTrue("top-down", !fTree.includes(paths[i]));
- }
-
- /* rebuild the fTree */
- fTree= TestUtil.createTestElementTree();
-
- /* delete a folder with children */
- assertTrue("f1", fTree.includes(folder1));
- fTree.deleteElement(folder1);
- assertTrue("!f1", !fTree.includes(folder1));
- assertTrue("!f3", !fTree.includes(folder3));
- assertTrue("!file3", !fTree.includes(file3));
-
-}
-public void testChildReplacement() {
-
- /* "create" an existing element */
- Object newInfo = "New Info";
- fTree.createElement(folder1, newInfo);
-
- /* make sure there isn't an extra child */
- assertEquals("1", 3, fTree.getChildCount(project2));
-
- /* child's info has been replaced */
- assertEquals("2", newInfo, fTree.getElementData(folder1));
-
- /* make sure grandchildren are gone */
- TestUtil.assertNoPaths(fTree, new IPath[] {file2, folder3, folder4});
-
- /* do it all again with null info */
- newInfo = null;
- fTree.createElement(folder1, newInfo);
-
- assertEquals("1", 3, fTree.getChildCount(project2));
- assertEquals("2", null, fTree.getElementData(folder1));
- TestUtil.assertNoPaths(fTree, new IPath[] {file2, folder3, folder4});
-
- /* one more time going from null info to real info */
- newInfo = "New Info";
- fTree.createElement(folder1, newInfo);
-
- assertEquals("1", 3, fTree.getChildCount(project2));
- assertEquals("2", newInfo, fTree.getElementData(folder1));
- TestUtil.assertNoPaths(fTree, new IPath[] {file2, folder3, folder4});
-}
-/**
- * Tests the collapsing API method
- */
-public void testCollapsing() {
- if (true)
- return;
-
- ///* do a bunch of operations to build a chain of deltas */
- //ElementTree deepTree = buildDeltaChain(fTree);
-
- ///* collapse the deep tree one chain at a time */
- //while (deepTree.deltaDepth() > 0) {
- //assert(deepTree.hasAncestor(fTree));
- //deepTree = deepTree.collapsing(1);
- //}
- //TestUtil.assertTreeStructure(deepTree);
-
- ///* build another delta chain */
- //ElementTree deeperTree = buildDeltaChain(deepTree);
-
- ///* collapse by twos */
- //while (deeperTree.deltaDepth() > 0) {
- //assert(deeperTree.hasAncestor(deepTree));
- //if (deeperTree.deltaDepth() > 1) {
- //deeperTree = deeperTree.collapsing(2);
- //} else {
- //deeperTree = deeperTree.collapsing(1);
- //}
- //}
-
- //TestUtil.assertTreeStructure(deeperTree);
-
- ///* build another delta chain */
- //ElementTree deepestTree = buildDeltaChain(deeperTree);
-
- ///* collapse all but one */
- //deepestTree = deepestTree.collapsing(deepestTree.deltaDepth()-1);
- //assert(deepestTree.hasAncestor(deeperTree));
-
- ///* collapse into a single tree with no ancestors */
- //deepestTree = buildDeltaChain(deeperTree);
- //deepestTree = deepestTree.collapsing(deepestTree.deltaDepth());
-
- //TestUtil.assertTreeStructure(deepestTree);
-}
-public void testComputeDeltaWith() {
- /**
- * The following changes will be made to the base tree:
- * - add project 3
- * - delete file1
- * - change data of folder2
- * - add file4 below project2
- * - add file5 below folder1
- * - delete file3
- */
-
- ElementTree newTree = fTree.newEmptyDelta();
- IDeltaFilter filter = TestUtil.getFilter();
-
- IPath project3 = solution.append("project3");
- IPath file4 = project2.append("file4");
- IPath file5 = folder1.append("file5");
-
- newTree.createElement(project3, "project3");
- newTree.deleteElement(file1);
- newTree.createElement(folder2, "ChangedData");
- newTree.createElement(file4, "file4");
- newTree.createElement(file5, "file5");
- newTree.deleteElement(file3);
-
- /* assert the new structure */
- TestUtil.assertHasPaths(newTree, new IPath[] {solution, project1, project2, project3,
- file2, file4, file5, folder1, folder2, folder3, folder4});
- TestUtil.assertNoPaths(newTree, new IPath[] {file1, file3});
-
- /* compute the delta */
- ElementTreeDelta delta = fTree.computeDeltaWith(newTree, TestUtil.getComparator());
-
- /* try asking the delta for bogus elements */
- assertTrue(delta.getElementDelta(Path.ROOT.append("bogosity")) == null);
- assertTrue(delta.getElementDelta(project2.append("bogosity")) == null);
-
- /* assert the delta structure (changes to get from newTree -> fTree) */
- ElementDelta root = delta.getElementDelta(Path.ROOT);
- ElementDelta[] children = root.getAffectedChildren(filter);
- assertTrue(children.length == 1);
-
- children = children[0].getAffectedChildren(filter);
- assertTrue(children.length == 2);
-
- assertTrue(children[0].getPath().equals(project2));
- TestUtil.assertNoChange(children[0].getComparison());
- assertTrue(children[1].getPath().equals(project3));
- TestUtil.assertRemoved(children[1].getComparison());
- assertTrue(children[1].getAffectedChildren(filter).length == 0);
-
- /* children of project2 */
- children = children[0].getAffectedChildren(filter);
- assertTrue(children.length == 4);
-
- assertTrue(children[0].getPath().equals(file1));
- TestUtil.assertAdded(children[0].getComparison());
- assertTrue(children[0].getAffectedChildren(filter).length == 0);
- assertTrue(children[1].getPath().equals(file4));
- TestUtil.assertRemoved(children[1].getComparison());
- assertTrue(children[1].getAffectedChildren(filter).length == 0);
- assertTrue(children[2].getPath().equals(folder1));
- TestUtil.assertNoChange(children[2].getComparison());
- assertTrue(children[3].getPath().equals(folder2));
- TestUtil.assertChanged(children[3].getComparison());
- assertTrue(children[3].getAffectedChildren(filter).length == 0);
-
- /* children of folder1 */
- children = children[2].getAffectedChildren(filter);
- assertTrue(children.length == 2);
-
- assertTrue(children[0].getPath().equals(file5));
- TestUtil.assertRemoved(children[0].getComparison());
- assertTrue(children[0].getAffectedChildren(filter).length == 0);
- assertTrue(children[1].getPath().equals(folder3));
- TestUtil.assertNoChange(children[1].getComparison());
-
- /* children of folder3 */
- children = children[1].getAffectedChildren(filter);
- assertTrue(children.length == 1);
-
- assertTrue(children[0].getPath().equals(file3));
- TestUtil.assertAdded(children[0].getComparison());
- assertTrue(children[0].getAffectedChildren(filter).length == 0);
-}
-/**
- * Same as testComputeDeltaWith, except this time we look at the
- * reverse delta.
- */
-public void testComputeDeltaWith2() {
- /**
- * The following changes will be made to the base tree:
- * - add project 3
- * - delete file1
- * - change data of folder2
- * - add file4 below project2
- * - add file5 below folder1
- * - delete file3
- */
-
- ElementTree newTree = fTree.newEmptyDelta();
- IDeltaFilter filter = TestUtil.getFilter();
-
- IPath project3 = solution.append("project3");
- IPath file4 = project2.append("file4");
- IPath file5 = folder1.append("file5");
-
- newTree.createElement(project3, "project3");
- newTree.deleteElement(file1);
- newTree.createElement(folder2, "ChangedData");
- newTree.createElement(file4, "file4");
- newTree.createElement(file5, "file5");
- newTree.deleteElement(file3);
-
- /* assert the new structure */
- TestUtil.assertHasPaths(newTree, new IPath[] {solution, project1, project2, project3,
- file2, file4, file5, folder1, folder2, folder3, folder4});
- TestUtil.assertNoPaths(newTree, new IPath[] {file1, file3});
-
- /* compute the delta */
- ElementTreeDelta delta = newTree.computeDeltaWith(fTree, TestUtil.getComparator());
-
- /* assert the delta structure (changes to get from fTree -> newTree) */
- ElementDelta root = delta.getElementDelta(Path.ROOT);
- ElementDelta[] children = root.getAffectedChildren(filter);
- assertTrue(children.length == 1);
-
- children = children[0].getAffectedChildren(filter);
- assertTrue(children.length == 2);
-
- assertTrue(children[0].getPath().equals(project2));
- TestUtil.assertNoChange(children[0].getComparison());
- assertTrue(children[1].getPath().equals(project3));
- TestUtil.assertAdded(children[1].getComparison());
- assertTrue(children[1].getAffectedChildren(filter).length == 0);
-
- /* children of project2 */
- children = children[0].getAffectedChildren(filter);
- assertTrue(children.length == 4);
-
- assertTrue(children[0].getPath().equals(file1));
- TestUtil.assertRemoved(children[0].getComparison());
- assertTrue(children[0].getAffectedChildren(filter).length == 0);
- assertTrue(children[1].getPath().equals(file4));
- TestUtil.assertAdded(children[1].getComparison());
- assertTrue(children[1].getAffectedChildren(filter).length == 0);
- assertTrue(children[2].getPath().equals(folder1));
- TestUtil.assertNoChange(children[2].getComparison());
- assertTrue(children[3].getPath().equals(folder2));
- TestUtil.assertChanged(children[3].getComparison());
- assertTrue(children[3].getAffectedChildren(filter).length == 0);
-
- /* children of folder1 */
- children = children[2].getAffectedChildren(filter);
- assertTrue(children.length == 2);
-
- assertTrue(children[0].getPath().equals(file5));
- TestUtil.assertAdded(children[0].getComparison());
- assertTrue(children[0].getAffectedChildren(filter).length == 0);
- assertTrue(children[1].getPath().equals(folder3));
- TestUtil.assertNoChange(children[1].getComparison());
-
- /* children of folder3 */
- children = children[1].getAffectedChildren(filter);
- assertTrue(children.length == 1);
-
- assertTrue(children[0].getPath().equals(file3));
- TestUtil.assertRemoved(children[0].getComparison());
- assertTrue(children[0].getAffectedChildren(filter).length == 0);
-}
-/**
- * Same as testComputeDeltaWith, except this time we perform
- * the delta on an unrelated tree.
- */
-public void testComputeDeltaWith3() {
- /**
- * The following changes will be made to the base tree:
- * - add project 3
- * - delete file1
- * - change data of folder2
- * - add file4 below project2
- * - add file5 below folder1
- * - delete file3
- */
-
- ElementTree newTree = fTree.newEmptyDelta();
- ElementTree copyTree = TestUtil.createTestElementTree();
- IDeltaFilter filter = TestUtil.getFilter();
-
- IPath project3 = solution.append("project3");
- IPath file4 = project2.append("file4");
- IPath file5 = folder1.append("file5");
-
- newTree.createElement(project3, "project3");
- newTree.deleteElement(file1);
- newTree.createElement(folder2, "ChangedData");
- newTree.createElement(file4, "file4");
- newTree.createElement(file5, "file5");
- newTree.deleteElement(file3);
-
- /* assert the new structure */
- TestUtil.assertHasPaths(newTree, new IPath[] {solution, project1, project2, project3,
- file2, file4, file5, folder1, folder2, folder3, folder4});
- TestUtil.assertNoPaths(newTree, new IPath[] {file1, file3});
-
- /* compute the delta */
- ElementTreeDelta delta = newTree.computeDeltaWith(copyTree, TestUtil.getComparator());
-
- /* assert the delta structure (changes to get from fTree -> newTree) */
- ElementDelta root = delta.getElementDelta(Path.ROOT);
- ElementDelta[] children = root.getAffectedChildren(filter);
- assertTrue(children.length == 1);
-
- children = children[0].getAffectedChildren(filter);
- assertTrue(children.length == 2);
-
- assertTrue(children[0].getPath().equals(project2));
- TestUtil.assertNoChange(children[0].getComparison());
- assertTrue(children[1].getPath().equals(project3));
- TestUtil.assertAdded(children[1].getComparison());
- assertTrue(children[1].getAffectedChildren(filter).length == 0);
-
- /* children of project2 */
- children = children[0].getAffectedChildren(filter);
- assertTrue(children.length == 4);
-
- assertTrue(children[0].getPath().equals(file1));
- TestUtil.assertRemoved(children[0].getComparison());
- assertTrue(children[0].getAffectedChildren(filter).length == 0);
- assertTrue(children[1].getPath().equals(file4));
- TestUtil.assertAdded(children[1].getComparison());
- assertTrue(children[1].getAffectedChildren(filter).length == 0);
- assertTrue(children[2].getPath().equals(folder1));
- TestUtil.assertNoChange(children[2].getComparison());
- assertTrue(children[3].getPath().equals(folder2));
- TestUtil.assertChanged(children[3].getComparison());
- assertTrue(children[3].getAffectedChildren(filter).length == 0);
-
- /* children of folder1 */
- children = children[2].getAffectedChildren(filter);
- assertTrue(children.length == 2);
-
- assertTrue(children[0].getPath().equals(file5));
- TestUtil.assertAdded(children[0].getComparison());
- assertTrue(children[0].getAffectedChildren(filter).length == 0);
- assertTrue(children[1].getPath().equals(folder3));
- TestUtil.assertNoChange(children[1].getComparison());
-
- /* children of folder3 */
- children = children[1].getAffectedChildren(filter);
- assertTrue(children.length == 1);
-
- assertTrue(children[0].getPath().equals(file3));
- TestUtil.assertRemoved(children[0].getComparison());
- assertTrue(children[0].getAffectedChildren(filter).length == 0);
-}
-/**
- * Tests the computeDeltaWith(ElementTree, IElementComparator, IPath) method, where
- * the given path is a leaf node.
- */
-public void testComputeLeafDelta() {
- /**
- * The following changes will be made to the base tree:
- * - add project 3
- * - delete file1
- * - change data of folder2
- * - add file4 below project2
- * - add file5 below folder1
- * - delete file3
- */
-
- ElementTree newTree = fTree.newEmptyDelta();
-
- IPath project3 = solution.append("project3");
- IPath file4 = project2.append("file4");
- IPath file5 = folder1.append("file5");
-
- newTree.createElement(project3, "project3");
- newTree.deleteElement(file1);
- newTree.createElement(folder2, "ChangedData");
- newTree.createElement(file4, "file4");
- newTree.createElement(file5, "file5");
- newTree.deleteElement(file3);
-
- /* assert the new structure */
- TestUtil.assertHasPaths(newTree, new IPath[] {solution, project1, project2, project3,
- file2, file4, file5, folder1, folder2, folder3, folder4});
- TestUtil.assertNoPaths(newTree, new IPath[] {file1, file3});
-
- /* compute the delta */
- ElementTreeDelta delta = fTree.computeDeltaWith(newTree, TestUtil.getComparator(), file3);
-
- /* try asking the delta for bogus elements */
- assertTrue(delta.getElementDelta(Path.ROOT.append("bogosity")) == null);
- assertTrue(delta.getElementDelta(project2.append("bogosity")) == null);
-
- /* assert the delta structure (changes to get from newTree -> fTree) */
- ElementDelta root = delta.getElementDelta(Path.ROOT);
- assertTrue(root.getPath().equals(file3));
- TestUtil.assertAdded(root.getComparison());
- assertTrue(root.getAffectedChildren(TestUtil.getFilter()).length == 0);
-}
-/**
- * Tests the computeDeltaWith(ElementTree, IElementComparator, IPath) method, where
- * the given path is project2.
- */
-public void testComputeProjectDelta() {
- /**
- * The following changes will be made to the base tree:
- * - add project 3
- * - delete file1
- * - change data of folder2
- * - add file4 below project2
- * - add file5 below folder1
- * - delete file3
- */
-
- ElementTree newTree = fTree.newEmptyDelta();
- IDeltaFilter filter = TestUtil.getFilter();
-
- IPath project3 = solution.append("project3");
- IPath file4 = project2.append("file4");
- IPath file5 = folder1.append("file5");
-
- newTree.createElement(project3, "project3");
- newTree.deleteElement(file1);
- newTree.createElement(folder2, "ChangedData");
- newTree.createElement(file4, "file4");
- newTree.createElement(file5, "file5");
- newTree.deleteElement(file3);
-
- /* assert the new structure */
- TestUtil.assertHasPaths(newTree, new IPath[] {solution, project1, project2, project3,
- file2, file4, file5, folder1, folder2, folder3, folder4});
- TestUtil.assertNoPaths(newTree, new IPath[] {file1, file3});
-
- /* compute the delta */
- ElementTreeDelta delta = fTree.computeDeltaWith(newTree, TestUtil.getComparator(), project2);
-
- /* try asking the delta for bogus elements */
- assertTrue(delta.getElementDelta(Path.ROOT.append("bogosity")) == null);
- assertTrue(delta.getElementDelta(project2.append("bogosity")) == null);
-
- /* assert the delta structure (changes to get from newTree -> fTree) */
-
- /* the root node should be the project node */
- ElementDelta root = delta.getElementDelta(Path.ROOT);
- TestUtil.assertNoChange(root.getComparison());
- assertTrue(root.getPath().equals(project2));
-
- /* children of project2 */
- ElementDelta[] children = root.getAffectedChildren(filter);
- assertTrue(children.length == 4);
-
- assertTrue(children[0].getPath().equals(file1));
- TestUtil.assertAdded(children[0].getComparison());
- assertTrue(children[0].getAffectedChildren(filter).length == 0);
- assertTrue(children[1].getPath().equals(file4));
- TestUtil.assertRemoved(children[1].getComparison());
- assertTrue(children[1].getAffectedChildren(filter).length == 0);
- assertTrue(children[2].getPath().equals(folder1));
- TestUtil.assertNoChange(children[2].getComparison());
- assertTrue(children[3].getPath().equals(folder2));
- TestUtil.assertChanged(children[3].getComparison());
- assertTrue(children[3].getAffectedChildren(filter).length == 0);
-
- /* children of folder1 */
- children = children[2].getAffectedChildren(filter);
- assertTrue(children.length == 2);
-
- assertTrue(children[0].getPath().equals(file5));
- TestUtil.assertRemoved(children[0].getComparison());
- assertTrue(children[0].getAffectedChildren(filter).length == 0);
- assertTrue(children[1].getPath().equals(folder3));
- TestUtil.assertNoChange(children[1].getComparison());
-
- /* children of folder3 */
- children = children[1].getAffectedChildren(filter);
- assertTrue(children.length == 1);
-
- assertTrue(children[0].getPath().equals(file3));
- TestUtil.assertAdded(children[0].getComparison());
- assertTrue(children[0].getAffectedChildren(filter).length == 0);
-}
-/**
- * Tests the computeDeltaWith(ElementTree, IElementComparator, IPath) method, where
- * the given path is a solution path
- */
-public void testComputeSolutionDelta() {
- /**
- * The following changes will be made to the base tree:
- * - add project 3
- * - delete file1
- * - change data of folder2
- * - add file4 below project2
- * - add file5 below folder1
- * - delete file3
- */
-
- ElementTree newTree = fTree.newEmptyDelta();
- IDeltaFilter filter = TestUtil.getFilter();
-
- IPath project3 = solution.append("project3");
- IPath file4 = project2.append("file4");
- IPath file5 = folder1.append("file5");
-
- newTree.createElement(project3, "project3");
- newTree.deleteElement(file1);
- newTree.createElement(folder2, "ChangedData");
- newTree.createElement(file4, "file4");
- newTree.createElement(file5, "file5");
- newTree.deleteElement(file3);
-
- /* assert the new structure */
- TestUtil.assertHasPaths(newTree, new IPath[] {solution, project1, project2, project3,
- file2, file4, file5, folder1, folder2, folder3, folder4});
- TestUtil.assertNoPaths(newTree, new IPath[] {file1, file3});
-
- /* compute the delta */
- ElementTreeDelta delta = fTree.computeDeltaWith(newTree, TestUtil.getComparator(), solution);
-
- /* try asking the delta for bogus elements */
- assertTrue(delta.getElementDelta(Path.ROOT.append("bogosity")) == null);
- assertTrue(delta.getElementDelta(project2.append("bogosity")) == null);
-
- /* assert the delta structure (changes to get from newTree -> fTree) */
-
- /* the root node should be the solution node */
- ElementDelta root = delta.getElementDelta(Path.ROOT);
- assertEquals(root.getPath(), solution);
- TestUtil.assertNoChange(root.getComparison());
- ElementDelta[] children = root.getAffectedChildren(filter);
- assertTrue(children.length == 2);
-
- assertTrue(children[0].getPath().equals(project2));
- TestUtil.assertNoChange(children[0].getComparison());
- assertTrue(children[1].getPath().equals(project3));
- TestUtil.assertRemoved(children[1].getComparison());
- assertTrue(children[1].getAffectedChildren(filter).length == 0);
-
- /* children of project2 */
- children = children[0].getAffectedChildren(filter);
- assertTrue(children.length == 4);
-
- assertTrue(children[0].getPath().equals(file1));
- TestUtil.assertAdded(children[0].getComparison());
- assertTrue(children[0].getAffectedChildren(filter).length == 0);
- assertTrue(children[1].getPath().equals(file4));
- TestUtil.assertRemoved(children[1].getComparison());
- assertTrue(children[1].getAffectedChildren(filter).length == 0);
- assertTrue(children[2].getPath().equals(folder1));
- TestUtil.assertNoChange(children[2].getComparison());
- assertTrue(children[3].getPath().equals(folder2));
- TestUtil.assertChanged(children[3].getComparison());
- assertTrue(children[3].getAffectedChildren(filter).length == 0);
-
- /* children of folder1 */
- children = children[2].getAffectedChildren(filter);
- assertTrue(children.length == 2);
-
- assertTrue(children[0].getPath().equals(file5));
- TestUtil.assertRemoved(children[0].getComparison());
- assertTrue(children[0].getAffectedChildren(filter).length == 0);
- assertTrue(children[1].getPath().equals(folder3));
- TestUtil.assertNoChange(children[1].getComparison());
-
- /* children of folder3 */
- children = children[1].getAffectedChildren(filter);
- assertTrue(children.length == 1);
-
- assertTrue(children[0].getPath().equals(file3));
- TestUtil.assertAdded(children[0].getComparison());
- assertTrue(children[0].getAffectedChildren(filter).length == 0);
-}
-/**
- * Tests the getSubtree and createSubtree API calls.
- */
-public void testCopySubtrees() {
- ElementTree copy = new ElementTree();
-
- copySubtree(fTree, copy, Path.ROOT);
-
- TestUtil.assertTreeStructure(copy);
- TestUtil.assertTreeStructure(fTree);
-}
-/**
- * Tests the getSubtree and createSubtree API calls.
- */
-public void testCopySubtreesInDelta() {
- ElementTree copy = fTree.newEmptyDelta();
-
- copySubtree(fTree, copy, Path.ROOT);
-
- assertTrue(copy.hasAncestor(fTree));
- TestUtil.assertTreeStructure(copy);
- TestUtil.assertTreeStructure(fTree);
-}
-public void testGetSubtree() {
- /* make sure subtree has same structure as original */
- ElementTree sub = fTree.getSubtree(Path.ROOT);
- TestUtil.assertTreeStructure(sub);
-
-}
-/**
- * Tests the makeComplete API method
- */
-public void testMakeComplete() {
- /* do a bunch of operations to build a chain of deltas */
- ElementTree deepTree = buildDeltaChain(fTree);
-
- assertTrue(deepTree.hasAncestor(fTree));
-
- deepTree.makeComplete();
- assertTrue(deepTree.deltaDepth() == 0);
- assertTrue(deepTree.getParent() == null);
-// assert(!deepTree.hasAncestor(fTree));
- assertTrue(!fTree.hasAncestor(deepTree));
- TestUtil.assertTreeStructure(deepTree);
-}
-/**
- * Regression test for PR:
- * 1EVK1G0: RQSM:ALL - ElementTree.getChildrenOfType() returns deleted elements
- */
- public void testRegression1EVK1G0() {
-
- ElementTree t1 = new ElementTree();
- IPath elementA = Path.ROOT.append("A");
- IPath elementAX = elementA.append("AX");
- IPath elementB = Path.ROOT.append("B");
-
- t1.createElement(elementA, new Object());
- t1.createElement(elementAX, new Object());
- t1.createElement(elementB, new Object());
-
- t1.immutable();
-
- IPath[] roots1 = t1.getChildren(t1.getRoot());
- assertTrue("A included?", t1.includes(elementA));
- assertTrue("AX included?", t1.includes(elementAX));
- assertTrue("B included?", t1.includes(elementB));
- assertTrue("2 roots?", roots1.length == 2);
-
- ElementTree t2 = t1.newEmptyDelta();
-
- t2.deleteElement(elementB);
- IPath[] roots2 = t2.getChildren(t2.getRoot());
-
- t2.deleteElement(elementAX);
- IPath[] kids2 = t2.getChildren(elementA);
-
- assertTrue("A included?", t2.includes(elementA));
- assertTrue("AX deleted?", !t2.includes(elementAX));
- assertTrue("B deleted?", !t2.includes(elementB));
- assertTrue("A has no kids?", kids2.length == 0);
- assertTrue("Only one root?", roots2.length == 1);
-}
-/**
- * Regression test for PR:
- * 1EVWNON: RQSM:ALL - ElementTree.getSubtree() sometimes returns bogus root element ids
- */
-public void testRegression1EVWNON() {
-
- ElementTree t0 = new ElementTree();
- IPath e0 = Path.ROOT.append("ZZProject");
- t0.createElement(e0, new Object());
- t0.immutable();
-
- ElementTree t2 = t0.newEmptyDelta();
- IPath e02 = e0.append("posterchild");
- t2.createElement(e02, new Object());
- ElementTree t2a = t2.getSubtree(e0);
- IPath bogus = t2a.getChildren(t2a.getRoot())[0];
- assertTrue(bogus.lastSegment() != null);
-}
-/**
- * Regression test for PR:
- * 1FVVP6L: ITPCORE:ALL - ElementTree corruption
- */
- public void testRegression1FVVP6L() {
-
- ElementTree t1 = new ElementTree();
- IPath elementA = Path.ROOT.append("A");
- IPath elementB = elementA.append("B");
-
- t1.createElement(elementA, "Element A");
-
- t1.immutable();
- ElementTree t2 = t1.newEmptyDelta();
-
- t2.createElement(elementB, "Element B");
-
- t2.immutable();
- t2 = t2.newEmptyDelta();
-
- t2.deleteElement(elementB);
- t2.createElement(elementB, "New Content");
-
- t2.immutable();
- try {
- //bug should cause runtime exception here
- t1.toDebugString();
- } catch (RuntimeException e) {
- assertTrue("Unexpected runtime exception in test", false);
- }
-}
-public void testSetInfo() {
-
- /* set new info */
- Object solutionInfo = "New Info";
- Object file2Info = Class.class;
- fTree.setElementData(solution, solutionInfo);
- fTree.setElementData(file2, file2Info);
- assertEquals(fTree.getElementData(solution), solutionInfo);
- assertEquals(fTree.getElementData(file2), file2Info);
-
- /* set to null */
- fTree.setElementData(solution, null);
- fTree.setElementData(file2, null);
- assertEquals(fTree.getElementData(solution), null);
- assertEquals(fTree.getElementData(file2), null);
-
- /* reset info */
- fTree.setElementData(solution, solutionInfo);
- fTree.setElementData(file2, file2Info);
- assertEquals(fTree.getElementData(solution), solutionInfo);
- assertEquals(fTree.getElementData(file2), file2Info);
-}
-public void testSetInfoInDelta() {
-
- /* set new info */
- fTree.immutable();
- ElementTree delta = fTree.newEmptyDelta();
-
- Object solutionInfo = "New Info";
- Object file2Info = Class.class;
- delta.setElementData(solution, solutionInfo);
- delta.setElementData(file2, file2Info);
- assertEquals(delta.getElementData(solution), solutionInfo);
- assertEquals(delta.getElementData(file2), file2Info);
-
- /* set to null */
- delta.setElementData(solution, null);
- delta.setElementData(file2, null);
- assertEquals(delta.getElementData(solution), null);
- assertEquals(delta.getElementData(file2), null);
-
- /* reset info */
- delta.setElementData(solution, solutionInfo);
- delta.setElementData(file2, file2Info);
- assertEquals(delta.getElementData(solution), solutionInfo);
- assertEquals(delta.getElementData(file2), file2Info);
-}
-public void testSetInfoInDelta2() {
-
- /* set new info */
- Object solutionInfo = "New Info";
- Object file2Info = Class.class;
- fTree.setElementData(solution, solutionInfo);
- fTree.setElementData(file2, file2Info);
- assertEquals(fTree.getElementData(solution), solutionInfo);
- assertEquals(fTree.getElementData(file2), file2Info);
-
- /* set to null in delta*/
- ElementTree delta = fTree.newEmptyDelta();
- delta.setElementData(solution, null);
- delta.setElementData(file2, null);
- assertEquals(delta.getElementData(solution), null);
- assertEquals(delta.getElementData(file2), null);
- assertEquals(fTree.getElementData(solution), solutionInfo);
- assertEquals(fTree.getElementData(file2), file2Info);
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/IPathConstants.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/IPathConstants.java
deleted file mode 100644
index ae82519..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/IPathConstants.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.watson;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-/**
- * Testing interface containing various paths.
- */
-interface IPathConstants {
-
- /**
- * The following paths are used in the tree created by
- * ElementTreeTestUtilities.createTestElementTree()
- */
- IPath root = Path.ROOT;
- IPath solution = root.append("solution");
- IPath project1 = solution.append("project1");
- IPath project2 = solution.append("project2");
- IPath file1 = project2.append("file1");
- IPath folder1 = project2.append("folder1");
- IPath folder2 = project2.append("folder2");
-
- IPath file2 = folder1.append("file2");
- IPath folder3 = folder1.append("folder3");
- IPath folder4 = folder1.append("folder4");
-
- IPath file3 = folder3.append("file3");
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/PhantomComparator.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/PhantomComparator.java
deleted file mode 100644
index d428c81..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/PhantomComparator.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.watson;
-
-import org.eclipse.core.internal.watson.IElementComparator;
-/**
- * Used in conjunction with PluggableDeltaLogicTests
- */
-public class PhantomComparator extends TestElementComparator implements IElementComparator {
- private static PhantomComparator fSingleton;
-/**
- * Force clients to use the singleton
- */
-protected PhantomComparator() {
-}
-/**
- * Compare based on name and phantom status.
- */
-public int compare(Object old, Object newt) {
- if (old == null && newt == null) {
- return K_NO_CHANGE;
- }
-
- PhantomElementData oldInfo = null, newInfo = null;
- if (old == null) {
- /* ignore added phantoms */
- newInfo = (PhantomElementData)newt;
- return newInfo.isPhantom ? K_NO_CHANGE : CHANGED;
- }
- if (newt == null) {
- /* ignore deleted phantoms */
- oldInfo = (PhantomElementData)old;
- return oldInfo.isPhantom ? K_NO_CHANGE : CHANGED;
- }
-
- try {
- oldInfo = (PhantomElementData)old;
- newInfo = (PhantomElementData)newt;
- } catch (ClassCastException e) {
- }
-
- if (oldInfo.isPhantom) {
- if (newInfo.isPhantom) {
- /* ignore changes to phantoms */
- return K_NO_CHANGE;
- } else {
- /* phantom -> real is an addition */
- return ADDED;
- }
- } else {
- if (newInfo.isPhantom) {
- /* real -> phantom == deletion */
- return REMOVED;
- } else {
- /* not a phantom */
- if (oldInfo.name == null && newInfo.name == null) {
- return K_NO_CHANGE;
- }
- if (oldInfo.name == null || newInfo.name == null) return CHANGED;
- if (oldInfo.name.equals(newInfo.name)) {
- return K_NO_CHANGE;
- } else {
- return CHANGED;
- }
- }
- }
-}
-/**
- * Returns the singleton instance
- */
-public static IElementComparator getComparator() {
- if (fSingleton == null) {
- fSingleton = new PhantomComparator();
- }
- return fSingleton;
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/PhantomElementData.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/PhantomElementData.java
deleted file mode 100644
index 9333b09..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/PhantomElementData.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.watson;
-
-/**
- * Used in conjunction with PluggableDeltaLogicTests
- */
-public class PhantomElementData {
- String name;
- boolean isPhantom;
-/**
- * Creates a new element info for either a phantom or real element
- */
-public PhantomElementData(String name, boolean isPhantom) {
- this.name = name;
- this.isPhantom = isPhantom;
-}
-/**
- * For debugging
- */
-public String toString() {
- StringBuffer buf = new StringBuffer("ElementData(");
- buf.append(isPhantom ? "Phantom, " : "Real, ");
- buf.append(name);
- buf.append(')');
- return buf.toString();
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/PluggableDeltaLogicTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/PluggableDeltaLogicTest.java
deleted file mode 100644
index 0059f3f..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/PluggableDeltaLogicTest.java
+++ /dev/null
@@ -1,211 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.watson;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.watson.*;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-/**
- * This class tests the ElementTreeDelta functionality of allowing
- * the Elmeentree client to specify how deltas appear. For example,
- * the tree can have phantom elements that are ignored when deleted
- * or changed.
- */
-public class PluggableDeltaLogicTest extends WatsonTest implements IPathConstants {
- protected static final IElementComparator fComparator = PhantomComparator.getComparator();
- protected static final IDeltaFilter fFilter = new TestDeltaFilter();
- protected ElementTree fTree;
-public PluggableDeltaLogicTest() {
- super(null);
-}
-public PluggableDeltaLogicTest(String name) {
- super(name);
-}
-/**
- * Creates an ElementTree identical in structure to the superclass'
- * TestElementTree, but with PhantomElementData instead of strings.
- * Initially none of the elements are phantoms.
- */
-static ElementTree createPhantomElementTree() {
-
- ElementTree spooky = new ElementTree();
-
- /* build the phantom tree */
- spooky.createElement(solution, new PhantomElementData("solution", false));
- spooky.createElement(project1, new PhantomElementData("project1", false));
- spooky.createElement(project2, new PhantomElementData("project2", false));
- spooky.createElement(file1, new PhantomElementData("file1", false));
- spooky.createElement(folder1, new PhantomElementData("folder1", false));
- spooky.createElement(folder2, new PhantomElementData("folder2", false));
- spooky.createElement(file2, new PhantomElementData("file2", false));
- spooky.createElement(folder3, new PhantomElementData("folder3", false));
- spooky.createElement(folder4, new PhantomElementData("folder4", false));
- spooky.createElement(file3, new PhantomElementData("file3", false));
-
- return spooky;
-}
-protected void setUp() throws Exception {
- fTree = createPhantomElementTree();
-}
-public static Test suite() {
- TestSuite suite= new TestSuite(PluggableDeltaLogicTest.class);
- return suite;
-}
-/**
- *
- */
-protected void tearDown() throws Exception {
- //ElementTree tests don't use the CoreTest infrastructure
-}
-/**
- * Tests adding a phantom -- should not show up in delta
- */
-public void testAddPhantom() {
- ElementTree deltaTree = fTree.newEmptyDelta();
- PhantomElementData phantomData = new PhantomElementData("data", true);
- IPath project3 = solution.append("project3");
- IPath file4 = folder2.append("file4");
- deltaTree.createElement(project3, phantomData);
- deltaTree.createElement(file4, phantomData);
-
- /* make sure the delta is empty (root has no children) */
- ElementTreeDelta delta = deltaTree.computeDeltaWith(fTree, fComparator);
- ElementDelta rootDelta = delta.getElementDelta(Path.ROOT);
- assertTrue(rootDelta.getAffectedChildren(fFilter).length == 0);
-}
-/**
- * Tests changing a phantom element into a real element.
- * This should appear as an addition in the delta
- */
-public void testConvertFromPhantom() {
- ElementTree oldTree = fTree.newEmptyDelta();
-
- /* convert project1 and folder3 to phantom */
- Object data = new PhantomElementData("CasperTheFriendlyPhantom", true);
- oldTree.setElementData(project1, data);
- oldTree.setElementData(folder3, data);
-
- /* now create a new delta */
- ElementTree newTree = oldTree.newEmptyDelta();
-
- /* set the phantoms to be real */
- data = new PhantomElementData("NotAPhantom", false);
- newTree.setElementData(project1, data);
- newTree.setElementData(folder3, data);
-
- /* analyze the delta */
- ElementTreeDelta delta = newTree.computeDeltaWith(oldTree, fComparator);
-
- ElementDelta rootDelta = delta.getElementDelta(Path.ROOT);
- ElementDelta[] children = rootDelta.getAffectedChildren(fFilter);
-
- /* one solution */
- assertTrue(children.length == 1);
- assertEquals(children[0].getPath(), solution);
- TestUtil.assertNoChange(children[0].getComparison());
-
- /* solution has two children */
- children = children[0].getAffectedChildren(fFilter);
- assertTrue(children.length == 2);
- assertEquals(children[0].getPath(), project1);
- TestUtil.assertAdded(children[0].getComparison());
- assertEquals(children[1].getPath(), project2);
- TestUtil.assertNoChange(children[1].getComparison());
-
- /* project2 has one changed child */
- children = children[1].getAffectedChildren(fFilter);
- assertTrue(children.length == 1);
- assertEquals(children[0].getPath(), folder1);
- TestUtil.assertNoChange(children[0].getComparison());
-
- /* folder1 has one removed child */
- children = children[0].getAffectedChildren(fFilter);
- assertTrue(children.length == 1);
- assertEquals(children[0].getPath(), folder3);
- TestUtil.assertAdded(children[0].getComparison());
-
- /* folder3 has no affected children (phantoms don't have recursive effects) */
- children = children[0].getAffectedChildren(fFilter);
- assertTrue(children.length == 0);
-}
-/**
- * Tests changing a real element into a phantom element.
- * This should appear as a deletion in the delta
- */
-public void testConvertToPhantom() {
- ElementTree newTree = fTree.newEmptyDelta();
-
- /* convert project1 and folder3 to phantom */
- Object data = new PhantomElementData("CasperTheFriendlyPhantom", true);
- newTree.setElementData(project1, data);
- newTree.setElementData(folder3, data);
-
- /* analyze the delta */
- ElementTreeDelta delta = newTree.computeDeltaWith(fTree, fComparator);
-
- ElementDelta rootDelta = delta.getElementDelta(Path.ROOT);
- ElementDelta[] children = rootDelta.getAffectedChildren(fFilter);
-
- /* one solution */
- assertTrue(children.length == 1);
- assertEquals(children[0].getPath(), solution);
- TestUtil.assertNoChange(children[0].getComparison());
-
- /* solution has two children */
- children = children[0].getAffectedChildren(fFilter);
- assertTrue(children.length == 2);
- assertEquals(children[0].getPath(), project1);
- TestUtil.assertRemoved(children[0].getComparison());
- assertEquals(children[1].getPath(), project2);
- TestUtil.assertNoChange(children[1].getComparison());
-
- /* project2 has one changed child */
- children = children[1].getAffectedChildren(fFilter);
- assertTrue(children.length == 1);
- assertEquals(children[0].getPath(), folder1);
- TestUtil.assertNoChange(children[0].getComparison());
-
- /* folder1 has one removed child */
- children = children[0].getAffectedChildren(fFilter);
- assertTrue(children.length == 1);
- assertEquals(children[0].getPath(), folder3);
- TestUtil.assertRemoved(children[0].getComparison());
-
- /* folder3 has no affected children */
- children = children[0].getAffectedChildren(fFilter);
- assertTrue(children.length == 0);
-}
-/**
- * Tests removing a phantom -- should not show up in delta
- */
-public void testRemovePhantom() {
-
- /* first add phantoms to a tree */
- ElementTree oldTree = fTree.newEmptyDelta();
- PhantomElementData phantomData = new PhantomElementData("data", true);
- IPath project3 = solution.append("project3");
- IPath file4 = folder2.append("file4");
- oldTree.createElement(project3, phantomData);
- oldTree.createElement(file4, phantomData);
-
- /* now delete the phantoms */
- ElementTree newTree = oldTree.newEmptyDelta();
- newTree.deleteElement(project3);
- newTree.deleteElement(file4);
-
- /* make sure the delta is empty */
- ElementTreeDelta delta = newTree.computeDeltaWith(oldTree, fComparator);
- ElementDelta rootDelta = delta.getElementDelta(Path.ROOT);
- assertTrue(rootDelta.getAffectedChildren(fFilter).length == 0);
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/TestDeltaFilter.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/TestDeltaFilter.java
deleted file mode 100644
index bd43f35..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/TestDeltaFilter.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.watson;
-
-import org.eclipse.core.internal.watson.IDeltaFilter;
-
-public class TestDeltaFilter implements IDeltaFilter {
-/**
- * TestDeltaFilter constructor comment.
- */
-public TestDeltaFilter() {
- super();
-}
-/**
- * Accepts all flags
- */
-public boolean includeElement(int flag) {
- return true;
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/TestElementComparator.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/TestElementComparator.java
deleted file mode 100644
index 0a436ea..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/TestElementComparator.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.watson;
-
-import org.eclipse.core.internal.dtree.NodeComparison;
-import org.eclipse.core.internal.watson.IElementComparator;
-
-/**
- * This is what you would expect for an element tree comparator.
- * Clients of the element tree that want specific comparison behaviour
- * must define their own element comparator (without subclassing or
- * otherwise extending this comparator). Internal element tree operations
- * rely on the behaviour of this type, and the ElementTree maintainer
- * reserves the right to change its behaviour as necessary.
- */
-public class TestElementComparator implements IElementComparator {
- private static IElementComparator fSingleton;
-
- static final int ADDED = NodeComparison.K_ADDED;
- static final int REMOVED = NodeComparison.K_REMOVED;
- static final int CHANGED = NodeComparison.K_CHANGED;
-/**
- * Force clients to use the singleton
- */
-protected TestElementComparator() {
- super();
-}
-/**
- * Returns the type of change.
- */
-public int compare (Object oldInfo, Object newInfo) {
- if (oldInfo == null) {
- if (newInfo == null) {
- return CHANGED;
- } else {
- return ADDED;
- }
- }
- if (newInfo == null) {
- if (oldInfo == null) {
- return CHANGED;
- } else {
- return REMOVED;
- }
- }
- return testEquality(oldInfo, newInfo) ? K_NO_CHANGE : CHANGED;
-}
-/**
- * Returns the singleton instance
- */
-public static IElementComparator getComparator() {
- if (fSingleton == null) {
- fSingleton = new TestElementComparator();
- }
- return fSingleton;
-}
-/**
- * Makes a comparison based on equality
- */
-protected boolean testEquality(Object oldInfo, Object newInfo) {
- if (oldInfo == null && newInfo == null) return true;
- if (oldInfo == null || newInfo == null) return false;
-
- return oldInfo.equals(newInfo);
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/TestUtil.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/TestUtil.java
deleted file mode 100644
index e0cf6a4..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/TestUtil.java
+++ /dev/null
@@ -1,407 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.watson;
-
-import java.util.Random;
-import java.util.Vector;
-
-import org.eclipse.core.internal.watson.*;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-
-/**
- * Framework for running tests on element tree components.
- * Supplies convenience methods and some representative element trees.
- */
-abstract class TestUtil extends WatsonTest implements IPathConstants {
-private TestUtil(String name) {
- super(name);
-}
- static final IDeltaFilter fFilter = new TestDeltaFilter();
- static final IElementComparator fComparator = TestElementComparator.getComparator();
-
-/**
- * Asserts that the given comparison value has the added
- * bit set, and the changed/removed bits blank
- */
-static void assertAdded(int compare) {
- assertTrue(compare == TestElementComparator.ADDED);
-}
-/**
- * Asserts that the given comparison value has the changed
- * bit set, and the added/removed bits blank
- */
-static void assertChanged(int compare) {
- assertTrue(compare == TestElementComparator.CHANGED);
-}
-/**
- * Asserts that two trees are equal. If they are not
- * an AssertionFailedError is thrown.
- * @param message the detail message for this assertion
- * @param expected the expected value of a tree
- * @param actual the actual value of a tree
- */
-static protected void assertEqualTrees(String message, ElementTree expected, ElementTree actual) {
- assertEqualTrees(message, expected, actual, Path.ROOT, ElementTreeWriter.D_INFINITE);
-}
-/**
- * Asserts that two trees are equal. If they are not
- * an AssertionFailedError is thrown.
- * @param message the detail message for this assertion
- * @param expected the expected value of a tree
- * @param actual the actual value of a tree
- * @param depth The depth to compare to.
- */
-static protected void assertEqualTrees(String message, ElementTree expected, ElementTree actual, int depth) {
- assertEqualTrees(message, expected, actual, Path.ROOT, depth);
-}
-/**
- * Asserts that two trees are equal from the given path downwards. If they are not
- * an AssertionFailedError is thrown.
- * @param message the detail message for this assertion
- * @param expected the expected value of a tree
- * @param actual the actual value of a tree
- */
-static protected void assertEqualTrees(String message, ElementTree expected, ElementTree actual, IPath path) {
- assertEqualTrees(message, expected, actual, path, ElementTreeWriter.D_INFINITE);
-}
-/**
- * Asserts that two trees are equal. If they are not
- * an AssertionFailedError is thrown.
- * @param message the detail message for this assertion
- * @param expected the expected value of a tree
- * @param actual the actual value of a tree
- * @param depth The depth to compare to.
- */
-static protected void assertEqualTrees(String msg, ElementTree expected, ElementTree actual, IPath path, int depth) {
- /* check node at current path */
- assertTrue(msg, expected.includes(path));
- assertTrue(msg, actual.includes(path));
- assertEquals(msg, expected.getElementData(path), actual.getElementData(path));
-
- if (depth != 0) {
- /* get the children */
- IPath[] expectedChildren = expected.getChildren(path);
- IPath[] actualChildren = actual.getChildren(path);
- assertTrue("Number of children",
- expectedChildren.length == actualChildren.length);
-
- int newDepth = depth;
- if (depth != ElementTreeWriter.D_INFINITE) {
- --newDepth;
- }
- for (int i = 0; i < expectedChildren.length; i++) {
- assertEquals("children IDs", expectedChildren[i], actualChildren[i]);
- assertEqualTrees("Recursive call", expected, actual,
- expectedChildren[i], newDepth);
- }
- }
-}
-/**
- * Asserts that the given tree contains all of the given paths
- */
-static protected void assertHasPaths(ElementTree tree, IPath[] paths) {
- for (int i = 0; i < paths.length; i++) {
- assertTrue("assertHasPaths"+i, tree.includes(paths[i]));
- }
-}
-/**
- * Asserts that the given comparison value has the changed
- * bit set, and the added/removed bits blank
- */
-static void assertNoChange(int compare) {
- assertTrue(compare == 0);
-}
-/**
- * Asserts that the given tree doesn not contain all of the given paths
- */
-static protected void assertNoPaths(ElementTree tree, IPath[] paths) {
- for (int i = 0; i < paths.length; i++) {
- assertTrue("assertNoPaths: "+paths[i], !tree.includes(paths[i]));
- }
-}
-/**
- * Asserts that the given comparison value has the removed
- * bit set, and the changed/added bits blank
- */
-static void assertRemoved(int compare) {
- assertTrue(compare == TestElementComparator.REMOVED);
-}
-/**
- * Asserts that the Test ElementTree has its original structure
- */
-static protected void assertTreeStructure(ElementTree tree) {
- assertHasPaths(tree, getTreePaths());
-
- IPath[] children = tree.getChildren(Path.ROOT);
- assertTrue(children.length == 1);
-
- /* solution children */
- children = tree.getChildren(children[0]);
- assertTrue(children.length == 2);
- assertTrue(tree.getChildren(project1).length == 0);
-
- /* project2 children */
- children = tree.getChildren(children[1]);
- assertTrue(children.length == 3);
- assertTrue(tree.getChildren(file1).length == 0);
- assertTrue(tree.getChildren(folder2).length == 0);
-
- /* folder1 children */
- children = tree.getChildren(children[1]);
- assertTrue(children.length == 3);
- assertTrue(tree.getChildren(file2).length == 0);
- assertTrue(tree.getChildren(folder4).length == 0);
-
- /* folder3 children */
- children = tree.getChildren(children[1]);
- assertTrue(children.length == 1);
- assertTrue(tree.getChildren(file3).length == 0);
-}
-static ElementTree createTestElementTree() {
- /**
- * This is a sample element tree on which tests are performed.
- * The Paths in this tree are found in IPathConstants. The tree's
- * basic structure is as follows:
- * solution
- * project1
- * project2
- * file1
- * folder1
- * file2
- * folder3
- * file3
- * folder4
- * folder2
- */
-
- ElementTree tree = new ElementTree();
- tree.createElement(solution, new String("solution"));
- tree.createElement(project1, new String("project1"));
- tree.createElement(project2, new String("project2"));
- tree.createElement(file1, new String("file1"));
- tree.createElement(folder1, new String("folder1"));
- tree.createElement(folder2, new String("folder2"));
- tree.createElement(file2, new String("file2"));
- tree.createElement(folder3, new String("folder3"));
- tree.createElement(folder4, new String("folder4"));
- tree.createElement(file3, new String("file3"));
-
- return tree;
-}
-/**
- * Does several routine operations on the subtree rooted at
- * the given path. Opens a new delta after every operation.
- * Returns an array of all the intermediary ElementTrees.
- */
-static protected ElementTree[] doManyRoutineOperations(ElementTree tree, IPath path) {
- Vector trees = new Vector();
- trees.addElement(tree);
-
- int repeat = 1;
-
- /* create file elements */
- tree = tree.newEmptyDelta();
- IPath[] files = getFilePaths(path);
- for (int i = 0; i < files.length; i++) {
- Object data = files[i].toString();
- tree.createElement(files[i], data);
-
- tree.immutable();
- trees.addElement(tree);
- tree = tree.newEmptyDelta();
- }
-
- /* modify the data of all file elements a few times */
- for (int i = 0; i < repeat; i++) {
- Object data = "data"+i;
- for (int f = 0; f < files.length; f++) {
- tree.setElementData(files[f], data);
- tree.immutable();
- trees.addElement(tree);
- tree = tree.newEmptyDelta();
- }
- }
-
- /* delete all file elements */
- for (int i = 0; i < files.length; i++) {
- tree.deleteElement(files[i]);
- tree.immutable();
- trees.addElement(tree);
- tree = tree.newEmptyDelta();
- }
-
- ElementTree[] results = new ElementTree[trees.size()];
- trees.copyInto(results);
- return results;
-}
-/**
- * Does several routine operations on the subtree rooted at
- * the given path. Returns an array of all the intermediary elementtrees.
- */
-static protected ElementTree[] doRoutineOperations(ElementTree tree, IPath path) {
- Vector trees = new Vector();
- trees.addElement(tree);
-
- int repeat = 1;
-
- /* create file elements */
- tree = tree.newEmptyDelta();
- IPath[] files = getFilePaths(path);
- for (int i = 0; i < files.length; i++) {
- Object data = files[i].toString();
-
- tree.createElement(files[i], data);
- }
-
- tree.immutable();
- trees.addElement(tree);
- tree = tree.newEmptyDelta();
-
- /* modify the data of all file elements a few times */
- for (int i = 0; i < repeat; i++) {
- Object data = "data"+i;
- for (int f = 0; f < files.length; f++) {
- tree.setElementData(files[f], data);
- }
- }
-
- tree.immutable();
- trees.addElement(tree);
- tree = tree.newEmptyDelta();
-
- /* delete all file elements */
- for (int i = 0; i < files.length; i++) {
- tree.deleteElement(files[i]);
- }
-
- tree.immutable();
- trees.addElement(tree);
-
- ElementTree[] results = new ElementTree[trees.size()];
- trees.copyInto(results);
- return results;
-}
-/**
- * Returns an element tree comparator
- */
-static IElementComparator getComparator() {
- return fComparator;
-}
-/**
- * Returns an array of paths below the given path.
- */
-static protected IPath[] getFilePaths(IPath project3) {
- String[] names = getJavaLangUnits();
- IPath[] paths = new IPath[names.length];
- for (int i = 0; i < paths.length; i++) {
- paths[i] = project3.append(names[i]);
- }
- return paths;
-}
-/**
- * Returns an element tree filter
- */
-static IDeltaFilter getFilter() {
- return fFilter;
-}
-/**
- * Returns strings representing javalang classes
- */
-static protected String[] getJavaLangUnits() {
- return new String[] {
- "AbstractMethodError.java",
- "ArithmeticException.java",
- "ArrayIndexOutOfBoundsException.java",
- "ArrayStoreException.java",
- "Boolean.java",
- "Byte.java",
- "Character.java",
- "Class.java",
- "ClassCastException.java",
- "ClassCircularityError.java",
- "ClassFormatError.java",
- "ClassLoader.java",
- "ClassNotFoundException.java",
- "Cloneable.java",
- "CloneNotSupportedException.java",
- "Compiler.java",
- "Double.java",
- "Error.java",
- };
-}
-/**
- * Returns the paths for all the elements in the tree in top-down order
- */
-static protected IPath[] getTreePaths() {
- return new IPath[] {
- solution,
- project1, project2,
- folder1, folder2, folder3, folder4,
- file1, file2, file3};
-}
-/**
- * Randomly scrambles an array.
- */
-static protected void scramble(Object[] first) {
- Random random = new Random(System.currentTimeMillis());
-
- final int len = first.length;
- for (int i = 0; i < len*100; i++) {
- /* get any array offset */
- int off1 = (int)(random.nextFloat() * len);
- if (off1 == len) continue;
-
- /* get another array offset */
- int off2 = (int)(random.nextFloat() * len);
- if (off2 == len) continue;
-
- /* switch */
- Object temp = first[off1];
- first[off1] = first[off2];
- first[off2] = temp;
- }
-}
-/**
- * Randomly scrambles two arrays, ensuring that both
- * arrays undergo the same permutation.
- */
-static protected void scramble(Object[] first, Object[] second) {
- assertTrue(first.length == second.length);
- Random random = new Random(System.currentTimeMillis());
-
- final int len = first.length;
- for (int i = 0; i < len*100; i++) {
- /* get any array offset */
- int off1 = (int)(random.nextFloat() * len);
- if (off1 == len) continue;
-
- /* get another array offset */
- int off2 = (int)(random.nextFloat() * len);
- if (off2 == len) continue;
-
- /* switch */
- Object temp = first[off1];
- first[off1] = first[off2];
- first[off2] = temp;
-
- temp = second[off1];
- second[off1] = second[off2];
- second[off2] = temp;
- }
-}
-
-
-
-
-
-
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/TreeFlatteningTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/TreeFlatteningTest.java
deleted file mode 100644
index bab2956..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/TreeFlatteningTest.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.watson;
-
-import java.io.*;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.watson.*;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-
-/**
- * Unit tests for <code>ElementTreeWriter</code> and
- * <code>ElementTreeReader</code>.
- */
-public class TreeFlatteningTest extends ElementTreeSerializationTest {
-public TreeFlatteningTest() {
-}
-public TreeFlatteningTest(String name) {
- super(name);
-}
-/**
- * Performs the serialization activity for this test
- */
-public Object doRead(ElementTreeReader reader, DataInputStream input) throws IOException {
- return reader.readTree(input);
-}
-/**
- * Runs a test for this class at a certain depth and path
- */
-public void doTest(IPath path, int depth) {
- /* Get an element tree from somewhere. */
- fTree= TestUtil.createTestElementTree();
- fSubtreePath = path;
- fDepth = depth;
-
- ElementTree newTree = (ElementTree)doPipeTest();
-
- TestUtil.assertEqualTrees(this.getClass().toString() + "test0", fTree, newTree, fSubtreePath, fDepth);
-}
-/**
- * Performs the serialization activity for this test
- */
-public void doWrite(ElementTreeWriter writer, DataOutputStream output) throws IOException{
- writer.writeTree(fTree, fSubtreePath, fDepth, output);
-}
-protected void setUp() throws Exception {
- super.setUp();
- fTree = TestUtil.createTestElementTree();
-}
-public static Test suite() {
- TestSuite suite= new TestSuite(TreeFlatteningTest.class);
- return suite;
-}
-public void test0() {
- /* Get an element tree from somewhere. */
- fTree= TestUtil.createTestElementTree();
- ElementTree newTree = (ElementTree)doFileTest();
-
- TestUtil.assertEqualTrees(this.getClass().toString() + "test0", fTree, newTree);
-}
-/**
- * Tests the reading and writing of element deltas
- */
-public void testExhaustive() {
- doExhaustiveTests();
-}
-public void testNullData() {
- /* Get an element tree from somewhere. */
- fTree= TestUtil.createTestElementTree();
- fTree = fTree.newEmptyDelta();
-
- /* set some elements to have null data */
- fTree.setElementData(solution, null);
- fTree.setElementData(folder2, null);
- fTree.immutable();
-
- ElementTree newTree = (ElementTree)doPipeTest();
-
- TestUtil.assertEqualTrees(this.getClass().toString() + "test0", fTree, newTree);
-}
-public void testWriteRoot() {
- /* Get an element tree from somewhere. */
- fTree= TestUtil.createTestElementTree();
- fSubtreePath = Path.ROOT;
-
- ElementTree newTree = (ElementTree)doPipeTest();
-
- TestUtil.assertEqualTrees(this.getClass().toString() + "test0", fTree, newTree, fSubtreePath);
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/WatsonTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/WatsonTest.java
deleted file mode 100644
index 80b8958..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/watson/WatsonTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*******************************************************************************
- * 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.tests.internal.watson;
-
-import junit.framework.TestCase;
-/**
- * Superclass for all tests involving the watson package.
- */
-public abstract class WatsonTest extends TestCase {
-
-/**
- * Constructor for WatsonTest.
- * @param name
- */
-public WatsonTest(String name) {
- super(name);
-}
-/*
- * @see Assert#assert(boolean)
- */
-
-
-/*
- * @see Assert#assert(String, boolean)
- */
-
-
-}
-
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/AllTests.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/AllTests.java
deleted file mode 100644
index ca51b85..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/AllTests.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import junit.framework.*;
-
-public class AllTests extends TestCase {
-/**
- * AllTests constructor comment.
- * @param name java.lang.String
- */
-public AllTests() {
- super(null);
-}
-/**
- * AllTests constructor comment.
- * @param name java.lang.String
- */
-public AllTests(String name) {
- super(name);
-}
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(IFileTest.suite());
- suite.addTest(IFolderTest.suite());
- suite.addTest(IProjectTest.suite());
- suite.addTest(IPathVariableTest.suite());
- suite.addTest(IResourceChangeEventTest.suite());
- suite.addTest(IResourceChangeListenerTest.suite());
- suite.addTest(IResourceDeltaTest.suite());
- suite.addTest(IResourceTest.suite());
- suite.addTest(ISynchronizerTest.suite());
- suite.addTest(IWorkspaceRootTest.suite());
- suite.addTest(IWorkspaceTest.suite());
- suite.addTest(MarkerSetTest.suite());
- suite.addTest(MarkerTest.suite());
- suite.addTest(NatureTest.suite());
- suite.addTest(ProjectOrderTest.suite());
- suite.addTest(ResourceURLTest.suite());
- suite.addTest(TeamPrivateMemberTest.suite());
- suite.addTest(WorkspaceTest.suite());
- suite.addTest(LinkedResourceTest.suite());
- suite.addTest(LinkedResourceWithPathVariableTest.suite());
- return suite;
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/AutomatedTests.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/AutomatedTests.java
deleted file mode 100644
index dfb3f2d..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/AutomatedTests.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import junit.framework.*;
-/**
- * Runs the sniff tests for the build. All tests listed here should
- * be automated.
- */
-public class AutomatedTests extends TestCase {
-
-public AutomatedTests() {
- super(null);
-}
-
-public AutomatedTests(String name) {
- super(name);
-}
-
-public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(org.eclipse.core.tests.internal.alias.AllTests.suite());
- suite.addTest(org.eclipse.core.tests.internal.builders.AllTests.suite());
- suite.addTest(org.eclipse.core.tests.internal.dtree.AllTests.suite());
- suite.addTest(org.eclipse.core.tests.internal.indexing.AllTests.suite());
- suite.addTest(org.eclipse.core.tests.internal.localstore.AllTests.suite());
- suite.addTest(org.eclipse.core.tests.internal.properties.AllTests.suite());
- suite.addTest(org.eclipse.core.tests.internal.resources.AllTests.suite());
- suite.addTest(org.eclipse.core.tests.internal.utils.AllTests.suite());
- suite.addTest(org.eclipse.core.tests.internal.watson.AllTests.suite());
- suite.addTest(org.eclipse.core.tests.resources.AllTests.suite());
- suite.addTest(org.eclipse.core.tests.resources.regression.AllTests.suite());
- return suite;
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/Comparator.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/Comparator.java
deleted file mode 100644
index e648627..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/Comparator.java
+++ /dev/null
@@ -1,201 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import java.util.*;
-
-import org.eclipse.core.resources.ICommand;
-
-/**
- * This class provides static comparison methods for various core
- * objects that do not implement equals.
- */
-public class Comparator {
-public static boolean equals(byte[] b0, byte[] b1){
- if(b0 == b1){
- return true;
- }
-
- if(b0 == null || b1 == null){
- return false;
- }
-
- if(b0.length != b1.length){
- return false;
- }
-
- for(int i = 0; i < b0.length; ++i){
- if(b0[i] != b1[i]){
- return false;
- }
- }
-
- return true;
-}
-public static boolean equals(Object[] obj0, Object[] obj1){
- return equals(obj0, obj1, true);
-}
-public static boolean equals(Object[] obj0, Object[] obj1, boolean isOrderImportant){
- if(obj0 == obj1){
- return true;
- }
-
- if(obj0 == null || obj1 == null){
- return false;
- }
-
- if(obj0.length != obj1.length){
- return false;
- }
-
- if(isOrderImportant){
- for(int i = 0; i < obj0.length; ++i){
- if(!equals(obj0[i], obj1[i])){
- return false;
- }
- }
- } else {
- boolean[] checkList = new boolean[obj0.length];
- for(int i = 0; i < checkList.length; ++i){
- checkList[i] = false;
- }
-
- for(int i = 0; i < obj0.length; ++i){
- boolean found = false;
- for(int j = 0; !found && j < obj1.length; ++j){
- if(!checkList[j] && equals(obj0[i], obj1[j])){
- checkList[j] = true;
- found = true;
- }
- }
- if(!found){
- return false;
- }
- }
- }
-
- return true;
-}
-public static boolean equals(ICommand[] cs0, ICommand[] cs1) {
- if (cs0 == cs1)
- return true;
- if (cs0 == null || cs1 == null)
- return false;
- if (cs0.length != cs1.length)
- return false;
- for (int i = 0; i < cs0.length; ++i) {
- if (!cs0[i].getBuilderName().equals(cs1[i].getBuilderName()))
- return false;
- if (!equals(cs0[i].getArguments(), cs1[i].getArguments()))
- return false;
- }
- return true;
-}
-public static boolean equals(Object obj0, Object obj1) {
- if(obj0 == obj1){
- return true;
- }
-
- if(obj0 == null || obj1 == null){
- return false;
- }
-
- if(obj0 instanceof byte[] && obj1 instanceof byte[]){
- return equals((byte[])obj0, (byte[])obj1);
- } else if(obj0 instanceof Enumeration && obj1 instanceof Enumeration){
- return equals((Enumeration)obj0, (Enumeration)obj1);
- } else if(obj0 instanceof Hashtable && obj1 instanceof Hashtable){
- return equals((Hashtable)obj0, (Hashtable)obj1);
- } else if(obj0 instanceof ICommand[] && obj1 instanceof ICommand[]){
- return equals((ICommand[])obj0, (ICommand[])obj1);
- } else if(obj0 instanceof Object[] && obj1 instanceof Object[]){
- return equals((Object[])obj0, (Object[])obj1);
- } else if(obj0 instanceof Vector && obj1 instanceof Vector){
- return equals((Vector)obj0, (Vector)obj1);
- }
-
- return obj0.equals(obj1);
-}
-public static boolean equals(Enumeration e, Object[] obj){
- return equals(e, obj, true);
-}
-public static boolean equals(Enumeration e, Object[] obj1, boolean isOrderImportant){
- Vector v = new Vector();
-
- while(e.hasMoreElements()){
- v.addElement(e.nextElement());
- }
-
- Object[] obj0 = new Object[v.size()];
- v.copyInto(obj0);
-
- return equals(obj0, obj1, isOrderImportant);
-}
-public static boolean equals(Enumeration e0, Enumeration e1) {
- if(e0 == e1){
- return true;
- }
-
- if(e0 == null || e1 == null){
- return false;
- }
-
- while(e0.hasMoreElements() && e1.hasMoreElements()){
- if (!equals(e0.nextElement(), e1.nextElement())){
- return false;
- }
- }
-
- if(e0.hasMoreElements() || e1.hasMoreElements()){
- return false;
- }
-
- return true;
-}
-public static boolean equals(Hashtable ht0, Hashtable ht1) {
- if(ht0 == ht1){
- return true;
- }
-
- if(ht0 == null || ht1 == null){
- return false;
- }
-
- if(ht0.size() != ht1.size()){
- return false;
- }
-
- Enumeration keys0 = ht0.keys();
- while(keys0.hasMoreElements()){
- Object key = keys0.nextElement();
- if(!equals(ht0.get(key), ht1.get(key))){
- return false;
- }
- }
-
- return true;
-}
-public static boolean equals(Vector c0, Vector c1) {
- if(c0 == c1){
- return true;
- }
-
- if(c0 == null || c1 == null){
- return false;
- }
-
- if(!equals(c0.elements(), c1.elements())){
- return false;
- }
-
- return true;
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IFileTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IFileTest.java
deleted file mode 100644
index 3e8fcdf..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IFileTest.java
+++ /dev/null
@@ -1,901 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import java.io.*;
-import java.util.Enumeration;
-import java.util.Vector;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.boot.BootLoader;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-import org.eclipse.core.tests.harness.FussyProgressMonitor;
-
-public class IFileTest extends EclipseWorkspaceTest {
- IProject[] projects = null;
-
- Vector allFiles = new Vector();
- Vector localOnlyFiles = new Vector();
- Vector workspaceOnlyFiles = new Vector();
- Vector nonExistingFiles = new Vector();
- Vector existingFiles = new Vector();
- Vector outOfSyncFiles = new Vector();
-
- //name of files according to sync category
- public static final String DOES_NOT_EXIST = "DoesNotExistFile";
- public static final String LOCAL_ONLY = "LocalOnlyFile";
- public static final String EXISTING = "ExistingFile";
- public static final String WORKSPACE_ONLY = "WorkspaceOnlyFile";
- public static final String OUT_OF_SYNC = "OutOfSyncFile";
-
- protected static final Boolean[] TRUE_AND_FALSE = new Boolean[] {Boolean.TRUE, Boolean.FALSE};
-// protected static final IProgressMonitor[] PROGRESS_MONITORS = new IProgressMonitor[] {new FussyProgressMonitor(), new CancelingProgressMonitor(), null};
- protected static final IProgressMonitor[] PROGRESS_MONITORS = new IProgressMonitor[] {new FussyProgressMonitor(), null};
-
-public IFileTest() {
-}
-public IFileTest(String name) {
- super(name);
-}
-/**
- * Returns true if the given container exists, and is open
- * if applicable.
- */
-public boolean existsAndOpen(IContainer container) {
- if (!container.exists())
- return false;
- if (container instanceof IFolder) {
- return true;
- }
- if (container instanceof IProject) {
- return ((IProject) container).isOpen();
- }
- fail("Should not get here in FileTest.existsAndOpen");
- return false;
-}
-/**
- * This method creates the necessary resources
- * for the FileTests. The interesting files are
- * placed in vectors that are members of the class.
- */
-protected void generateInterestingFiles() throws CoreException {
- IProject[] projects = interestingProjects();
- for (int i = 0; i < projects.length; i++) {
- IProject project = projects[i];
- //file in project
- generateInterestingFiles(project);
-
- //file in non-existent folder
- generateInterestingFiles(project.getFolder("NonExistentFolder"));
-
- //file in existent folder
- if (project.exists() && project.isOpen()) {
- IFolder folder = project.getFolder("ExistingFolder");
- folder.create(true, true, getMonitor());
- generateInterestingFiles(folder);
- }
- }
-}
-/**
- * Creates some interesting files in the specified container.
- * Adds these files to the appropriate member vectors.
- * Conditions on these files (out of sync, workspace only, etc)
- * will be ensured by refreshFiles
- */
-public void generateInterestingFiles(IContainer container) throws CoreException {
- //non-existent file
- IFile file = container.getFile(new Path(DOES_NOT_EXIST));
- nonExistingFiles.addElement(file);
- allFiles.addElement(file);
-
- //exists in filesystem only
- file = container.getFile(new Path(LOCAL_ONLY));
- localOnlyFiles.addElement(file);
- allFiles.addElement(file);
-
-
- if (existsAndOpen(container)) {
-
- //existing file
- file = container.getFile(new Path(EXISTING));
- existingFiles.addElement(file);
- allFiles.addElement(file);
-
- //exists in workspace only
- file = container.getFile(new Path(WORKSPACE_ONLY));
- workspaceOnlyFiles.addElement(file);
- allFiles.addElement(file);
-
- //exists in both but is out of sync
- file = container.getFile(new Path(OUT_OF_SYNC));
- outOfSyncFiles.addElement(file);
- allFiles.addElement(file);
- }
-}
-/**
- * Returns some interesting files. These files are created
- * during setup.
- */
-public IFile[] interestingFiles() {
- refreshFiles();
- IFile[] result = new IFile[allFiles.size()];
- allFiles.copyInto(result);
- return result;
-}
-/**
- * Creates and returns some interesting projects
- */
-public IProject[] interestingProjects() throws CoreException {
- if(projects == null){
- projects = new IProject[3];
-
- //open project
- IProject openProject = getWorkspace().getRoot().getProject("OpenProject");
- openProject.create(getMonitor());
- openProject.open(getMonitor());
- projects[0]= openProject;
-
- //closed project
- IProject closedProject = getWorkspace().getRoot().getProject("ClosedProject");
- closedProject.create(getMonitor());
- projects[1] =closedProject;
-
- //non-existent project
- projects[2] = getWorkspace().getRoot().getProject("NonExistentProject");
- }
-
- return projects;
-}
-/**
- * Returns some interesting input streams
- */
-public InputStream[] interestingStreams() {
- Vector streams = new Vector();
-
- //empty stream
- ByteArrayInputStream bis = new ByteArrayInputStream(new byte[0]);
- streams.addElement(bis);
-
- // random content
- streams.addElement(getRandomContents());
-
- //large stream
- bis = new ByteArrayInputStream(new byte[10000]);
- streams.addElement(bis);
-
- InputStream[] results = new InputStream[streams.size()];
- streams.copyInto(results);
- return results;
-}
-/**
- * Returns true if the given file is out of sync from the
- * local file system. The file must exist in the workspace.
- */
-public boolean outOfSync(IFile file) {
- return file.getName().equals(OUT_OF_SYNC) || file.getName().equals(WORKSPACE_ONLY);
-}
-/**
- * Makes sure file requirements are met (out of sync, workspace only, etc).
- */
-public void refreshFile(IFile file) {
- if (file.getName().equals(LOCAL_ONLY)) {
- ensureDoesNotExistInWorkspace(file);
- //project must exist to access file system store.
- if (file.getProject().exists()) {
- ensureExistsInFileSystem(file);
- }
- return;
- }
- if (file.getName().equals(WORKSPACE_ONLY)) {
- ensureExistsInWorkspace(file, true);
- ensureDoesNotExistInFileSystem(file);
- return;
- }
- if (file.getName().equals(DOES_NOT_EXIST)) {
- ensureDoesNotExistInWorkspace(file);
- //project must exist to access file system store.
- if (file.getProject().exists()) {
- ensureDoesNotExistInFileSystem(file);
- }
- return;
- }
- if (file.getName().equals(EXISTING)) {
- ensureExistsInWorkspace(file, true);
- return;
- }
- if (file.getName().equals(OUT_OF_SYNC)) {
- ensureExistsInWorkspace(file, true);
- ensureOutOfSync(file);
- return;
- }
-}
-/**
- * Makes sure file requirements are met (out of sync, workspace only, etc).
- */
-public void refreshFiles() {
- for (Enumeration e = allFiles.elements(); e.hasMoreElements();) {
- IFile file = (IFile)e.nextElement();
- refreshFile(file);
- }
-}
-protected void setUp() throws Exception {
- super.setUp();
-
- try {
- generateInterestingFiles();
- } catch (CoreException e) {
- fail("Failed in setup for FileTest", e);
- }
-}
-/**
- * Sets up the test suite for this class
- */
-public static Test suite() {
- return new TestSuite(IFileTest.class);
-
-// TestSuite suite = new TestSuite();
-// suite.addTest(new IFileTest("testAppendContents2"));
-// suite.addTest(new IFileTest("testSetContents3"));
-// return suite;
-}
-protected void tearDown() throws Exception {
- getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
- ensureDoesNotExistInWorkspace(getWorkspace().getRoot());
- super.tearDown();
-}
-public void testAppendContents() {
- IFile target = projects[0].getFile("file1");
- try {
- target.create(getContents("abc"), false, null);
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- try {
- target.appendContents(getContents("def"), false, false, null);
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- InputStream content = null;
- try {
- content = target.getContents(false);
- assertTrue("3.0", compareContent(content, getContents("abcdef")));
- } catch (CoreException e) {
- fail("3.1", e);
- }
-}
-/**
- * Performs black box testing of the following method:
- * void create(InputStream, boolean, IProgressMonitor)
- */
-public void testCreate() throws CoreException {
- Object[][] inputs = new Object[][] {interestingFiles(), interestingStreams(), TRUE_AND_FALSE, PROGRESS_MONITORS};
- new TestPerformer("IFileTest.testCreate") {
- public boolean shouldFail(Object[] args, int count) {
- IFile file = (IFile) args[0];
- IPath fileLocation = file.getLocation();
- boolean force = ((Boolean) args[2]).booleanValue();
- boolean fileExistsInWS = file.exists();
- boolean fileExistsInFS = fileLocation != null && fileLocation.toFile().exists();
-
- // parent must be accessible
- if (!file.getParent().isAccessible())
- return true;
-
- // should never fail if force is true
- if (force && !fileExistsInWS)
- return false;
-
- // file must not exist in WS or on filesystem.
- return fileExistsInWS || fileExistsInFS;
- }
- public Object[] interestingOldState(Object[] args) throws Exception {
- return null;
- }
- public Object invokeMethod(Object[] args, int count) throws Exception {
- IFile file = (IFile) args[0];
- InputStream stream = (InputStream) args[1];
- boolean force = ((Boolean) args[2]).booleanValue();
- IProgressMonitor monitor = (IProgressMonitor) args[3];
- if (monitor instanceof FussyProgressMonitor)
- ((FussyProgressMonitor) monitor).prepare();
- file.create(stream, force, monitor);
- if (monitor instanceof FussyProgressMonitor)
- ((FussyProgressMonitor) monitor).sanityCheck();
- return null;
- }
- public boolean wasSuccess(Object[] args, Object result, Object[] oldState) throws Exception {
- IFile file = (IFile) args[0];
- return file.exists();
- }
- public void cleanUp(Object[] args, int count) {
- IFile file = (IFile) args[0];
- refreshFile(file);
- }
- }
- .performTest(inputs);
-}
-public void testFileCreation(){
- IFile target = projects[0].getFile("file1");
-
- assertTrue("1.0", !target.exists());
- try {
- target.create(null, true, getMonitor());
- } catch (CoreException e) {
- fail("1.1", e);
- }
- assertTrue("1.2", target.exists());
-
- // creation with empty content
- target = projects[0].getFile("file2");
- assertTrue("2.0", !target.exists());
- String contents = "";
- try {
- target.create(getContents(contents), true, getMonitor());
- } catch (CoreException e) {
- fail("2.1", e);
- }
- assertTrue("2.2", target.exists());
- InputStream stream = null;
- try {
- stream = target.getContents(false);
- } catch (CoreException e) {
- fail("2.3", e);
- }
- try {
- assertTrue("2.4", stream.available() == 0);
- } catch (IOException e) {
- fail("2.5", e);
- }
- try {
- stream.close();
- } catch (IOException e) {
- fail("2.55", e);
- }
- try {
- assertTrue("2.6", compareContent(target.getContents(false), getContents(contents)));
- } catch (CoreException e) {
- fail("2.7", e);
- }
-
- // creation with random content
- target = projects[0].getFile("file3");
- assertTrue("3.0", !target.exists());
- contents = getRandomString();
- try {
- target.create(getContents(contents), true, getMonitor());
- } catch (CoreException e) {
- fail("3.1", e);
- }
- assertTrue("3.2", target.exists());
- try {
- assertTrue("3.2", compareContent(target.getContents(false), getContents(contents)));
- } catch (CoreException e) {
- fail("3.3", e);
- }
-
- // try to create a file over a folder that exists
- IFolder folder = projects[0].getFolder("folder1");
- try {
- folder.create(true, true, getMonitor());
- } catch (CoreException e) {
- fail("4.0", e);
- }
- assertTrue("4.1", folder.exists());
- target = projects[0].getFile("folder1");
- try {
- target.create(null, true, getMonitor());
- fail("4.2");
- } catch (CoreException e) {
- }
- assertTrue("4.3", folder.exists());
- assertTrue("4.4", !target.exists());
-
- // try to create a file under a non-existent parent
- folder = projects[0].getFolder("folder2");
- assertTrue("5.0", !folder.exists());
- target = folder.getFile("file4");
- try {
- target.create(null, true, getMonitor());
- fail("5.1");
- } catch (CoreException e) {
- }
- assertTrue("5.2", !folder.exists());
- assertTrue("5.3", !target.exists());
-
- //create from stream that throws exceptions
- target = projects[0].getFile("file2");
- ensureDoesNotExistInWorkspace(target);
- ensureDoesNotExistInFileSystem(target);
-
- InputStream content = new InputStream() {
- public int read() throws IOException {
- throw new IOException();
- }
- };
- try {
- target.create(content, false, getMonitor());
- fail("6.1");
- } catch (CoreException e) {
- }
- assertDoesNotExistInWorkspace("6.2", target);
- assertDoesNotExistInFileSystem("6.3", target);
-
-
- // cleanup
- folder = projects[0].getFolder("folder1");
- try {
- folder.delete(false, getMonitor());
- } catch (CoreException e) {
- fail("7.0", e);
- }
- IFile file = projects[0].getFile("file1");
- try {
- file.delete(false, getMonitor());
- } catch (CoreException e) {
- fail("7.1", e);
- }
- file = projects[0].getFile("file2");
- try {
- file.delete(false, getMonitor());
- } catch (CoreException e) {
- fail("7.2", e);
- }
- file = projects[0].getFile("file3");
- try {
- file.delete(false, getMonitor());
- } catch (CoreException e) {
- fail("7.3", e);
- }
-}
-public void testFileDeletion() throws Throwable {
- IFile target = projects[0].getFile("file1");
- target.create(null, true, getMonitor());
- assertTrue("1.0", target.exists());
- target.delete(true, getMonitor());
- assertTrue("1.1", !target.exists());
-}
-public void testFileEmptyDeletion() throws Throwable {
- IFile target = projects[0].getFile("file1");
- target.create(getContents(""), true, getMonitor());
- assertTrue("1.0", target.exists());
- target.delete(true, getMonitor());
- assertTrue("1.1", !target.exists());
-}
-public void testFileInFolderCreation() {
-
- IFolder folder = projects[0].getFolder("folder1");
- try {
- folder.create(false, true, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- IFile target = folder.getFile("file1");
- try {
- target.create(getRandomContents(), true, getMonitor());
- assertTrue("1.1", target.exists());
- } catch (CoreException e) {
- fail("1.2", e);
- }
-}
-public void testFileInFolderCreation1() throws Throwable {
- IFolder folder = projects[0].getFolder("folder1");
- folder.create(false, true, null);
-
- IFile target = folder.getFile("file1");
- target.create(getRandomContents(), true, getMonitor());
- assertTrue("1.0", target.exists());
-}
-public void testFileInFolderCreation2() {
-
- IFolder folder = projects[0].getFolder("folder1");
- try {
- folder.create(false, true, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- IFile target = folder.getFile("file1");
- try {
- target.create(getRandomContents(), true, getMonitor());
- assertTrue("1.1", target.exists());
- } catch (CoreException e) {
- fail("1.2", e);
- }
-}
-public void testFileMove() throws Throwable {
- IFile target = projects[0].getFile("file1");
- target.create(getRandomContents(), true, getMonitor());
-
- IFile destination = projects[0].getFile("file2");
- target.move(destination.getFullPath(), true, getMonitor());
-
- assertTrue("1.0", destination.exists());
- assertTrue("1.1", !target.exists());
-}
-public void testFileOverFolder() throws Throwable {
- IFolder existing = projects[0].getFolder("ExistingFolder");
- IFile target = projects[0].getFile("ExistingFolder");
-
- try {
- target.create(null, true, getMonitor());
- fail("Should not be able to create file over folder");
- } catch (CoreException e) {
- assertTrue("1.1", existing.exists());
- return;
- }
-}
-/**
- * Performs black box testing of the following method:
- * InputStream getContents()
- */
-public void testGetContents() {
- Object[][] inputs = new Object[][] {interestingFiles()};
- new TestPerformer("IFileTest.testGetContents") {
- public boolean shouldFail(Object[] args, int count) {
- IFile file = (IFile) args[0];
-
- //file must exist
- if (!file.exists()) {
- return true;
- }
-
- //file must be in sync
- if (outOfSync(file)) {
- return true;
- }
- return false;
- }
- public Object[] interestingOldState(Object[] args) throws Exception {
- return null;
- }
- public Object invokeMethod(Object[] args, int count) throws Exception {
- IFile file = (IFile) args[0];
- return file.getContents(false);
- }
- public boolean wasSuccess(Object[] args, Object result, Object[] oldState) throws Exception {
- IFile file = (IFile) args[0];
- InputStream contents = (InputStream) result;
- boolean returnVal = file.exists() && contents != null;
- contents.close();
- return returnVal;
- }
- public void cleanUp(Object[] args, int count) {
- IFile file = (IFile) args[0];
- refreshFile(file);
- }
- }
- .performTest(inputs);
-}
-public void testGetContents2() throws IOException {
- IFile target = projects[0].getFile("file1");
- String testString = getRandomString();
- try {
- target.create(null, false, null);
- target.setContents(getContents(testString), true, false, getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- ensureOutOfSync(target);
-
- InputStream content = null;
- try {
- try {
- content = target.getContents(false);
- } finally {
- if (content != null)
- content.close();
- }
- fail("1.0");
- } catch (CoreException e) {
- }
-
- try {
- try {
- content = target.getContents(true);
- } finally {
- if (content != null)
- content.close();
- }
- } catch (CoreException e) {
- fail("2.1", e);
- }
-
- try {
- try {
- content = target.getContents(false);
- } finally {
- if (content != null)
- content.close();
- }
- fail("3.0");
- } catch (CoreException e) {
- }
- content = new InputStream() {
- public int read() throws IOException {
- throw new IOException();
- }
- };
- try {
- target.setContents(content, IResource.NONE, getMonitor());
- fail("4.1");
- } catch (CoreException e) {
- }
- assertExistsInWorkspace("4.2", target);
- assertExistsInFileSystem("4.3", target);
-
-}
-
-/**
- * Tests creation and manipulation of file names that are reserved on some platforms.
- */
-public void testInvalidFileNames() {
- IProject project = projects[0];
-
- //should not be able to create a file with invalid path on any platform
- String[] names = new String[] {":", "", "/"};
- for (int i = 0; i < names.length; i++) {
- try {
- project.getFile(names[i]);
- fail("0.99");
- } catch (RuntimeException e) {
- //should fail
- }
- }
-
- //do some tests with invalid names
- names = new String[0];
- if (BootLoader.getOS().equals(BootLoader.OS_WIN32)) {
- //invalid windows names
- names = new String[] {"prn", "nul", "con", "aux", "clock$", "com1",
- "com2", "com3", "com4", "com5", "com6", "com7", "com8", "com9",
- "lpt1", "lpt2", "lpt3", "lpt4", "lpt5", "lpt6", "lpt7", "lpt8", "lpt9",
- "AUX", "con.foo", "LPT4.txt", "*", "?", "\"", "<", ">", "|"};
- } else {
- //invalid names on non-windows platforms
- names = new String[] {};
- }
- for (int i = 0; i < names.length; i++) {
- IFile file = project.getFile(names[i]);
- assertTrue("1.0 " + names[i], !file.exists());
- try {
- file.create(getRandomContents(), true, getMonitor());
- fail("1.1 " + names[i]);
- } catch (CoreException e) {
- }
- assertTrue("1.2 " + names[i], !file.exists());
- }
-
- //do some tests with valid names that are *almost* invalid
- if (BootLoader.getOS().equals(BootLoader.OS_WIN32)) {
- //these names are valid on windows
- names = new String[] {"hello.prn.txt", "null", "con3", "foo.aux", "lpt0",
- "com0", "com10", "lpt10", ",", "'", ";"};
- } else {
- //these names are valid on non-windows platforms
- names = new String[] {"prn", "nul", "con", "aux", "clock$",
- "com1", "com2", "com3", "com4", "com5", "com6", "com7",
- "com8", "com9", "lpt1", "lpt2", "lpt3", "lpt4", "lpt5", "lpt6",
- "lpt7", "lpt8", "lpt9", "AUX", "con.foo", "LPT4.txt", "*",
- "?", "\"", "<", ">", "|", "hello.prn.txt", "null", "con3", "foo.aux",
- "lpt0", "com0", "com10", "lpt10", ",", "'", ";"};
- }
- for (int i = 0; i < names.length; i++) {
- IFile file = project.getFile(names[i]);
- assertTrue("2.0 " + names[i], !file.exists());
- try {
- file.create(getRandomContents(), true, getMonitor());
- } catch (CoreException e) {
- fail("2.1 " + names[i], e);
- }
- assertTrue("2.2 " + names[i], file.exists());
- }
-}
-
-/**
- * Performs black box testing of the following method:
- * void setContents(InputStream, boolean, IProgressMonitor)
- */
-public void testSetContents1() {
- Object[][] inputs = new Object[][] {interestingFiles(), interestingStreams(), TRUE_AND_FALSE, PROGRESS_MONITORS};
- new TestPerformer("IFileTest.testSetContents1") {
- public boolean shouldFail(Object[] args, int count) {
- IFile file = (IFile) args[0];
- boolean force = ((Boolean) args[2]).booleanValue();
-
- //file must exist
- if (!file.exists()) {
- return true;
- }
-
- //file must be in sync if force is false
- if (!force && outOfSync(file)) {
- return true;
- }
- return false;
- }
- public Object[] interestingOldState(Object[] args) throws Exception {
- return null;
- }
- public Object invokeMethod(Object[] args, int count) throws Exception {
- IFile file = (IFile) args[0];
- InputStream stream = (InputStream) args[1];
- boolean force = ((Boolean) args[2]).booleanValue();
- IProgressMonitor monitor = (IProgressMonitor) args[3];
- if (monitor instanceof FussyProgressMonitor)
- ((FussyProgressMonitor) monitor).prepare();
- file.setContents(stream, force, false, monitor);
- if (monitor instanceof FussyProgressMonitor)
- ((FussyProgressMonitor) monitor).sanityCheck();
- return null;
- }
- public boolean wasSuccess(Object[] args, Object result, Object[] oldState) throws Exception {
- IFile file = (IFile) args[0];
- return file.exists();
- }
- public void cleanUp(Object[] args, int count) {
- IFile file = (IFile) args[0];
- refreshFile(file);
- }
- }
- .performTest(inputs);
-}
-public void testSetContents2() throws Throwable {
- IFile target = projects[0].getFile("file1");
- target.create(null, false, null);
-
- String testString = getRandomString();
- target.setContents(getContents(testString), true, false, getMonitor());
-
- InputStream content = null;
- try {
- content = target.getContents(false);
- assertTrue("get not equal set", compareContent(content, getContents(testString)));
- } finally {
- content.close();
- }
-}
-public void testSetContents3() {
-}
-public void testAppendContents2() {
- IFile file = projects[0].getFile("file1");
- ensureDoesNotExistInWorkspace(file);
-
- // If force=true, IFile is non-local, file exists in local file system:
- // make IFile local, append contents (the thinking being that this file,
- // though marked non-local, was in fact local awaiting discovery; so
- // force=true says we it is ok to make file local and proceed as per normal)
- try {
- // setup
- file.create(null, false, getMonitor());
- assertTrue("1.0", !file.isLocal(IResource.DEPTH_ZERO));
- assertTrue("1.1", !file.getLocation().toFile().exists());
- ensureExistsInFileSystem(file);
- assertTrue("1.2", !file.isLocal(IResource.DEPTH_ZERO));
- } catch (CoreException e) {
- fail("1.3", e);
- }
- try {
- file.appendContents(getRandomContents(), IResource.FORCE, getMonitor());
- } catch (CoreException e) {
- fail("1.4", e);
- }
- assertTrue("1.5", file.isLocal(IResource.DEPTH_ZERO));
- assertTrue("1.6", file.getLocation().toFile().exists());
- // cleanup
- ensureDoesNotExistInWorkspace(file);
-
- // If force=true, IFile is non-local, file does not exist in local file system:
- // fail - file not local (this file is not local for real - cannot append
- // something to a file that you don't have)
- try {
- // setup
- file.create(null, false, getMonitor());
- assertTrue("2.0", !file.isLocal(IResource.DEPTH_ZERO));
- assertTrue("2.1", !file.getLocation().toFile().exists());
- } catch (CoreException e) {
- fail("2.2", e);
- }
- try {
- file.appendContents(getRandomContents(), IResource.FORCE, getMonitor());
- fail("2.3");
- } catch (CoreException e) {
- // should fail
- }
- assertTrue("2.4", !file.isLocal(IResource.DEPTH_ZERO));
- // cleanup
- ensureDoesNotExistInWorkspace(file);
-
- // If force=false, IFile is non-local, file exists in local file system:
- // fail - file not local
- try {
- // setup
- file.create(null, false, getMonitor());
- assertTrue("3.0", !file.isLocal(IResource.DEPTH_ZERO));
- assertTrue("3.1", !file.getLocation().toFile().exists());
- ensureExistsInFileSystem(file);
- assertTrue("3.2", !file.isLocal(IResource.DEPTH_ZERO));
- } catch (CoreException e) {
- fail("3.3", e);
- }
- try {
- file.appendContents(getRandomContents(), IResource.NONE, getMonitor());
- fail("3.4");
- } catch (CoreException e) {
- // should fail
- }
- assertTrue("3.5", !file.isLocal(IResource.DEPTH_ZERO));
- // cleanup
- ensureDoesNotExistInWorkspace(file);
-
- // If force=false, IFile is non-local, file does not exist in local file system:
- // fail - file not local
- try {
- // setup
- file.create(null, false, getMonitor());
- assertTrue("4.0", !file.isLocal(IResource.DEPTH_ZERO));
- assertTrue("4.1", !file.getLocation().toFile().exists());
- } catch (CoreException e) {
- fail("4.2", e);
- }
- try {
- file.appendContents(getRandomContents(), IResource.NONE, getMonitor());
- fail("4.3");
- } catch (CoreException e) {
- // should fail
- }
- assertTrue("4.4", !file.isLocal(IResource.DEPTH_ZERO));
- // cleanup
- ensureDoesNotExistInWorkspace(file);
-}
-public void testSetGetFolderPersistentProperty() throws Throwable {
- IResource target = getWorkspace().getRoot().getFile(new Path("/Project/File.txt"));
- String value = "this is a test property value";
- QualifiedName name = new QualifiedName("itp-test", "testProperty");
- // getting/setting persistent properties on non-existent resources should throw an exception
- ensureDoesNotExistInWorkspace(target);
- try {
- target.getPersistentProperty(name);
- fail("1.0");
- } catch (CoreException e) {
- //this should happen
- }
- try {
- target.setPersistentProperty(name, value);
- fail("1.1");
- } catch (CoreException e) {
- //this should happen
- }
-
- ensureExistsInWorkspace(target, true);
- target.setPersistentProperty(name, value);
- // see if we can get the property
- assertTrue("2.0", ((String) target.getPersistentProperty(name)).equals(value));
- // see what happens if we get a non-existant property
- name = new QualifiedName("itp-test", "testNonProperty");
- assertNull("2.1", target.getPersistentProperty(name));
-
- //set a persistent property with null qualifier
- name = new QualifiedName(null, "foo");
- try {
- target.setPersistentProperty(name, value);
- fail("3.0");
- } catch (CoreException e) {
- //expect an exception
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IFolderTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IFolderTest.java
deleted file mode 100644
index 78489d2..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IFolderTest.java
+++ /dev/null
@@ -1,331 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.boot.BootLoader;
-import org.eclipse.core.internal.localstore.CoreFileSystemLibrary;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-public class IFolderTest extends EclipseWorkspaceTest {
-public IFolderTest() {
-}
-public IFolderTest(String name) {
- super(name);
-}
-protected void setUp() throws Exception {
- super.setUp();
-}
-public static Test suite() {
- return new TestSuite(IFolderTest.class);
-}
-protected void tearDown() throws Exception {
- getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
- ensureDoesNotExistInWorkspace(getWorkspace().getRoot());
- super.tearDown();
-}
-public void testChangeCase() {
- IProject project = getWorkspace().getRoot().getProject("Project");
- IFolder before = project.getFolder("folder");
- IFolder after = project.getFolder("Folder");
- IFile beforeFile = before.getFile("file");
- IFile afterFile= after.getFile("file");
-
- // create the resources and set some content in a file that will be moved.
- ensureExistsInWorkspace(before, true);
- try {
- beforeFile.create(getRandomContents(), false, getMonitor());
- } catch (CoreException e) {
- fail("0.99", e);
- }
-
- // Be sure the resources exist and then move them.
- assertExistsInWorkspace("1.0", before);
- assertExistsInWorkspace("1.1", beforeFile);
- assertDoesNotExistInWorkspace("1.2", after);
- assertDoesNotExistInWorkspace("1.3", afterFile);
- try {
- before.move(after.getFullPath(), IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("1.99", e);
- }
-
- assertDoesNotExistInWorkspace("1.2", before);
- assertDoesNotExistInWorkspace("1.3", beforeFile);
- assertExistsInWorkspace("1.0", after);
- assertExistsInWorkspace("1.1", afterFile);
-}
-public void testCopyMissingFolder() {
- //tests copying a folder that is missing from the file system
- IProject project = getWorkspace().getRoot().getProject("Project");
- IFolder before = project.getFolder("OldFolder");
- IFolder after = project.getFolder("NewFolder");
- ensureExistsInWorkspace(project, true);
- ensureExistsInWorkspace(before, true);
- ensureDoesNotExistInFileSystem(before);
-
- try {
- //should fail because 'before' does not exist in the filesystem
- before.copy(after.getFullPath(), IResource.FORCE, getMonitor());
- fail("1.0");
- } catch (CoreException e) {
- //should fail
- }
- //the destination should not exist, because the source does not exist
- assertTrue("1.1", !before.exists());
- assertTrue("1.2", !after.exists());
-}
-public void testFolderCreation() throws Exception {
- // basic folder creation
- IProject project = getWorkspace().getRoot().getProject("Project");
- ensureExistsInWorkspace(project, true);
-
- IFolder target = project.getFolder("Folder1");
- try {
- assertTrue("1.0", !target.exists());
- target.create(true, true, getMonitor());
- assertTrue("1.1", target.exists());
- } catch (CoreException e) {
- fail("1.2", e);
- }
-
- // nested folder creation
- IFolder nestedTarget = target.getFolder("Folder2");
- try {
- assertTrue("2.0", !nestedTarget.exists());
- nestedTarget.create(true, true, getMonitor());
- assertTrue("2.1", nestedTarget.exists());
- } catch (CoreException e) {
- fail("2.2", e);
- }
-
- // try to create a folder that already exists
- try {
- assertTrue("3.0", target.exists());
- target.create(true, true, getMonitor());
- fail("3.1");
- } catch (CoreException e) {
- assertTrue("3.2", target.exists());
- }
-
- // try to create a folder over a file that exists
- IFile file = target.getFile("File1");
- target = target.getFolder("File1");
- try {
- file.create(getRandomContents(), true, getMonitor());
- assertTrue("4.0", file.exists());
- } catch (CoreException e) {
- fail("4.1", e);
- }
-
- try {
- target.create(true, true, getMonitor());
- fail("5.0");
- } catch (CoreException e) {
- assertTrue("5.1", file.exists());
- assertTrue("5.2", !target.exists());
- }
-
- // try to create a folder on a project (one segment) path
- try {
- target = getWorkspace().getRoot().getFolder(new Path("/Folder3"));
- fail("6.0");
- } catch (IllegalArgumentException e) {
- }
-
- // try to create a folder as a child of a file
- file = project.getFile("File2");
- try {
- file.create(null, true, getMonitor());
- } catch (CoreException e) {
- fail("7.0", e);
- }
-
- target = project.getFolder("File2/Folder4");
- try {
- assertTrue("7.1", !target.exists());
- target.create(true, true, getMonitor());
- fail("7.2");
- } catch (CoreException e) {
- assertTrue("7.3", file.exists());
- assertTrue("7.4", !target.exists());
- }
-
- // try to create a folder under a non-existant parent
- IFolder folder = project.getFolder("Folder5");
- target = folder.getFolder("Folder6");
- try {
- assertTrue("8.0", !folder.exists());
- target.create(true, true, getMonitor());
- fail("8.1");
- } catch (CoreException e) {
- assertTrue("8.2", !folder.exists());
- assertTrue("8.3", !target.exists());
- }
-}
-public void testFolderDeletion() throws Throwable {
- IProject project = getWorkspace().getRoot().getProject("Project");
- IResource[] before = buildResources(project, new String[] {"c/", "c/b/", "c/x", "c/b/y", "c/b/z"});
- ensureExistsInWorkspace(before, true);
- //
- assertExistsInWorkspace(before);
- project.getFolder("c").delete(true, getMonitor());
- assertDoesNotExistInWorkspace("1.0", before);
-}
-public void testFolderMove() throws Throwable {
- IProject project = getWorkspace().getRoot().getProject("Project");
- IResource[] before = buildResources(project, new String[] {"b/", "b/b/", "b/x", "b/b/y", "b/b/z"});
- IResource[] after = buildResources(project, new String[] {"a/", "a/b/", "a/x", "a/b/y", "a/b/z"});
-
- // create the resources and set some content in a file that will be moved.
- ensureExistsInWorkspace(before, true);
- String content = getRandomString();
- IFile file = project.getFile(new Path("b/b/z"));
- file.setContents(getContents(content), true, false, getMonitor());
-
- // Be sure the resources exist and then move them.
- assertExistsInWorkspace("1.0", before);
- project.getFolder("b").move(project.getFullPath().append("a"), true, getMonitor());
-
- //
- assertDoesNotExistInWorkspace("2.0", before);
- assertExistsInWorkspace(after);
- file = project.getFile(new Path("a/b/z"));
- assertTrue("2.1", compareContent(getContents(content), file.getContents(false)));
-}
-public void testFolderOverFile() throws Throwable {
- IPath path = new Path("/Project/File");
- IFile existing = getWorkspace().getRoot().getFile(path);
- ensureExistsInWorkspace(existing, true);
- IFolder target = getWorkspace().getRoot().getFolder(path);
- try {
- target.create(true, true, getMonitor());
- fail("1.0 Should not be able to create folder over a file");
- } catch (CoreException e) {
- assertTrue("2.0", existing.exists());
- }
-}
-/**
- * Tests creation and manipulation of folder names that are reserved on some platforms.
- */
-public void testInvalidFolderNames() {
- IProject project = getWorkspace().getRoot().getProject("Project");
- ensureExistsInWorkspace(project, true);
-
- //do some tests with invalid names
- String[] names = new String[0];
- if (BootLoader.getOS().equals(BootLoader.OS_WIN32)) {
- //invalid windows names
- names = new String[] {"prn", "nul", "con", "aux", "clock$", "com1",
- "com2", "com3", "com4", "com5", "com6", "com7", "com8", "com9",
- "lpt1", "lpt2", "lpt3", "lpt4", "lpt5", "lpt6", "lpt7", "lpt8", "lpt9",
- "AUX", "con.foo", "LPT4.txt", "*", "?", "\"", "<", ">", "|"};
- } else {
- //invalid names on non-windows platforms
- names = new String[] {};
- }
-
- for (int i = 0; i < names.length; i++) {
- IFolder folder = project.getFolder(names[i]);
- assertTrue("1.0 " + names[i], !folder.exists());
- try {
- folder.create(true, true, getMonitor());
- fail("1.1 " + names[i]);
- } catch (CoreException e) {
- }
- assertTrue("1.2 " + names[i], !folder.exists());
- }
-
- //do some tests with valid names that are *almost* invalid
- if (BootLoader.getOS().equals(BootLoader.OS_WIN32)) {
- //these names are valid on windows
- names = new String[] {"hello.prn.txt", "null", "con3", "foo.aux", "lpt0",
- "com0", "com10", "lpt10", ",", "'", ";"};
- } else {
- //these names are valid on non-windows platforms
- names = new String[] {"prn", "nul", "con", "aux", "clock$",
- "com1", "com2", "com3", "com4", "com5", "com6", "com7",
- "com8", "com9", "lpt1", "lpt2", "lpt3", "lpt4", "lpt5", "lpt6",
- "lpt7", "lpt8", "lpt9", "AUX", "con.foo", "LPT4.txt", "*",
- "?", "\"", "<", ">", "|", "hello.prn.txt", "null", "con3", "foo.aux",
- "lpt0", "com0", "com10", "lpt10", ",", "'", ";"};
- }
- for (int i = 0; i < names.length; i++) {
- IFolder folder = project.getFolder(names[i]);
- assertTrue("2.0 " + names[i], !folder.exists());
- try {
- folder.create(true, true, getMonitor());
- } catch (CoreException e) {
- fail("2.1 " + names[i], e);
- }
- assertTrue("2.2 " + names[i], folder.exists());
- }
-}
-
-public void testLeafFolderMove() throws Exception {
- IProject project = getWorkspace().getRoot().getProject("Project");
- IFolder source = project.getFolder("Folder1");
- ensureExistsInWorkspace(source, true);
- IFolder dest = project.getFolder("Folder2");
- source.move(dest.getFullPath(), true, getMonitor());
- assertExistsInWorkspace("1.0", dest);
- assertDoesNotExistInWorkspace("1.1", source);
-}
-public void testReadOnlyFolderCopy() throws Exception {
- // We need to know whether or not we can unset the read-only flag
- // in order to perform this test.
- if (!CoreFileSystemLibrary.usingNatives())
- return;
- IProject project = getWorkspace().getRoot().getProject("Project");
- IFolder source = project.getFolder("Folder1");
- ensureExistsInWorkspace(source, true);
- source.setReadOnly(true);
- IFolder dest = project.getFolder("Folder2");
- source.copy(dest.getFullPath(), true, getMonitor());
- assertExistsInWorkspace("1.0", dest);
- assertExistsInWorkspace("1.1", source);
- assertTrue("1.2", dest.isReadOnly());
-
- // cleanup - ensure that the files can be deleted.
- source.setReadOnly(false);
- dest.setReadOnly(false);
-}
-public void testSetGetFolderPersistentProperty() throws Throwable {
- IResource target = getWorkspace().getRoot().getFolder(new Path("/Project/Folder"));
- String value = "this is a test property value";
- QualifiedName name = new QualifiedName("itp-test", "testProperty");
- // getting/setting persistent properties on non-existent resources should throw an exception
- ensureDoesNotExistInWorkspace(target);
- try {
- target.getPersistentProperty(name);
- fail("1.0");
- } catch (CoreException e) {
- //this should happen
- }
- try {
- target.setPersistentProperty(name, value);
- fail("1.1");
- } catch (CoreException e) {
- //this should happen
- }
-
- ensureExistsInWorkspace(target, true);
- target.setPersistentProperty(name, value);
- // see if we can get the property
- assertTrue("2.0", ((String) target.getPersistentProperty(name)).equals(value));
- // see what happens if we get a non-existant property
- name = new QualifiedName("itp-test", "testNonProperty");
- assertNull("2.1", target.getPersistentProperty(name));
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IPathVariableTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IPathVariableTest.java
deleted file mode 100644
index 441283b..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IPathVariableTest.java
+++ /dev/null
@@ -1,441 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import java.util.*;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-/**
- * Tests path variables.
- */
-public class IPathVariableTest extends EclipseWorkspaceTest {
- IPathVariableManager manager = getWorkspace().getPathVariableManager();
-
- class PathVariableChangeVerifier implements IPathVariableChangeListener {
- class VerificationFailedException extends Exception {
- VerificationFailedException(String message) {
- super(message);
- }
- }
- class Event {
- int type;
- String name;
- IPath value;
- Event(int type, String name, IPath value) {
- this.type = type;
- this.name = name;
- this.value = value;
- }
- public boolean equals(Object obj) {
- if (obj == null || !(obj instanceof Event))
- return false;
- Event that = (Event) obj;
- if (this.type != that.type || !this.name.equals(that.name))
- return false;
- if (this.value == null)
- return that.value == null;
- else
- return this.value.equals(that.value);
- }
- public String toString() {
- StringBuffer buffer = new StringBuffer();
- buffer.append("Event(");
- buffer.append("type: ");
- buffer.append(stringForType(type));
- buffer.append(" name: ");
- buffer.append(name);
- buffer.append(" value: ");
- buffer.append(value);
- buffer.append(")");
- return buffer.toString();
- }
- String stringForType(int type) {
- switch (type) {
- case IPathVariableChangeEvent.VARIABLE_CREATED :
- return "CREATED";
- case IPathVariableChangeEvent.VARIABLE_CHANGED :
- return "CHANGED";
- case IPathVariableChangeEvent.VARIABLE_DELETED :
- return "DELETED";
- default :
- return "UNKNOWN";
- }
- }
- }
- List expected = new ArrayList();
- List actual = new ArrayList();
- void addExpectedEvent(int type, String name, IPath value) {
- expected.add(new Event(type, name, value));
- }
- void verify() throws VerificationFailedException {
- String message;
- if (expected.size() != actual.size()) {
- message = "Expected size: " + expected.size() + " does not equal actual size: " + actual.size() + "\n";
- message += dump();
- throw new VerificationFailedException(message);
- }
- for (Iterator i = expected.iterator(); i.hasNext();) {
- Event e = (Event) i.next();
- if (!actual.contains(e)) {
- message = "Expected and actual results differ.\n";
- message += dump();
- throw new VerificationFailedException(message);
- }
- }
- }
- void reset() {
- expected = new ArrayList();
- actual = new ArrayList();
- }
- public void pathVariableChanged(IPathVariableChangeEvent event) {
- actual.add(new Event(event.getType(), event.getVariableName(), event.getValue()));
- }
- String dump() {
- StringBuffer buffer = new StringBuffer();
- buffer.append("Expected:\n");
- for (Iterator i = expected.iterator(); i.hasNext();)
- buffer.append("\t" + i.next() + "\n");
- buffer.append("Actual:\n");
- for (Iterator i = actual.iterator(); i.hasNext();)
- buffer.append("\t" + i.next() + "\n");
- return buffer.toString();
- }
- }
-
- /**
- * Default constructor for this class.
- */
- public IPathVariableTest() {
- }
- /**
- * Constructor for the class.
- */
- public IPathVariableTest(String name) {
- super(name);
- }
- /**
- * Return the tests to run.
- *
- * @see org.eclipse.core.tests.harness.EclipseWorkspaceTest#suite()
- */
- public static Test suite() {
- return new TestSuite(IPathVariableTest.class);
- }
- /**
- * Test IPathVariableManager#getPathVariableNames
- */
- public void testGetPathVariableNames() {
- String[] names = null;
-
- // should be empty to start
- assertTrue("0.0", manager.getPathVariableNames().length == 0);
-
- // add one
- try {
- manager.setValue("one", getRandomLocation());
- } catch (CoreException e) {
- fail("1.0", e);
- }
- names = manager.getPathVariableNames();
- assertTrue("1.1", names.length == 1);
- assertTrue("1.2", names[0].equals("one"));
-
- // add another
- try {
- manager.setValue("two", Path.ROOT);
- } catch (CoreException e) {
- fail("2.0", e);
- }
- names = manager.getPathVariableNames();
- assertTrue("2.1", names.length == 2);
- assertTrue("2.2", contains(names, "one"));
- assertTrue("2.3", contains(names, "two"));
-
- // remove one
- try {
- manager.setValue("one", null);
- } catch (CoreException e) {
- fail("3.0", e);
- }
- names = manager.getPathVariableNames();
- assertTrue("3.1", names.length == 1);
- assertTrue("3.2", names[0].equals("two"));
-
- // remove the last one
- try {
- manager.setValue("two", null);
- } catch (CoreException e) {
- fail("4.0", e);
- }
- names = manager.getPathVariableNames();
- assertTrue("4.1", names.length == 0);
- }
- /**
- * Test IPathVariableManager#getValue and IPathVariableManager#setValue
- */
- public void testGetSetValue() {
- IPath pathOne = new Path("c:\\temp");
- IPath pathTwo = new Path("/tmp/backup");
- //add device if neccessary
- pathTwo = new Path(pathTwo.toFile().getAbsolutePath());
- IPath pathOneEdit = new Path("d:/foobar");
-
- // nothing to begin with
- assertNull("0.0", manager.getValue("one"));
-
- // add a value to the table
- try {
- manager.setValue("one", pathOne);
- } catch (CoreException e) {
- fail("1.0", e);
- }
- IPath value = manager.getValue("one");
- assertNotNull("1.1", value);
- assertTrue("1.2", pathOne.equals(value));
-
- // add another value
- try {
- manager.setValue("two", pathTwo);
- } catch (CoreException e) {
- fail("2.0", e);
- }
- value = manager.getValue("two");
- assertNotNull("2.1", value);
- assertTrue("2.2", pathTwo.equals(value));
-
- // edit the first value
- try {
- manager.setValue("one", pathOneEdit);
- } catch (CoreException e) {
- fail("3.0", e);
- }
- value = manager.getValue("one");
- assertNotNull("3.1", value);
- assertTrue("3.2", pathOneEdit.equals(value));
-
- // setting with value == null will remove
- try {
- manager.setValue("one", null);
- } catch (CoreException e) {
- fail("4.0", e);
- }
- assertNull("4.1", manager.getValue("one"));
-
- // set values with bogus names
- try {
- manager.setValue("ECLIPSE$HOME", Path.ROOT);
- fail("5.0 Accepted invalid variable name in setValue()");
- } catch (CoreException ce) {
- // success
- }
-
- // set value with relative path
- try {
- manager.setValue("one", new Path("foo/bar"));
- fail("5.0 Accepted invalid variable value in setValue()");
- } catch (CoreException ce) {
- // success
- }
-
- // set invalid value (with invalid segment)
- String invalidPathString = "/a/\\:/b";
- IPath invalidPath = new Path(invalidPathString);
- assertTrue("6.0",invalidPath.isAbsolute());
- assertTrue("6.1",!Path.EMPTY.isValidPath(invalidPath.toString()));
- assertTrue("6.2", !manager.validateValue(invalidPath).isOK());
- try {
- manager.setValue("one", invalidPath);
- fail("6.3 Accepted invalid variable value in setValue()");
- } catch (CoreException ce) {
- // success
- }
-
- }
- /**
- * Test IPathVariableManager#isDefined
- */
- public void testIsDefined() {
- assertTrue("0.0", !manager.isDefined("one"));
- try {
- manager.setValue("one", Path.ROOT);
- } catch (CoreException e) {
- fail("1.0", e);
- }
- assertTrue("1.1", manager.isDefined("one"));
- try {
- manager.setValue("one", null);
- } catch (CoreException e) {
- fail("2.0", e);
- }
- assertTrue("2.1", !manager.isDefined("one"));
- }
- /**
- * Test IPathVariableManager#resolvePath
- */
- public void testResolvePath() {
- IPath pathOne = new Path("c:/temp/foo");
- IPath pathTwo = new Path("/tmp/backup");
- //add device if neccessary
- pathTwo = new Path(pathTwo.toFile().getAbsolutePath());
-
- try {
- manager.setValue("one", pathOne);
- } catch (CoreException e) {
- fail("0.1", e);
- }
- try {
- manager.setValue("two", pathTwo);
- } catch (CoreException e) {
- fail("0.2", e);
- }
-
- // one substitution
- IPath path = new Path("one/bar");
- IPath expected = new Path("c:/temp/foo/bar");
- IPath actual = manager.resolvePath(path);
- assertEquals("1.0", expected, actual);
-
- // another substitution
- path = new Path("two/myworld");
- expected = new Path("/tmp/backup/myworld");
- expected = new Path(expected.toFile().getAbsolutePath());
- actual = manager.resolvePath(path);
- assertEquals("2.0", expected, actual);
-
- // variable not defined
- path = new Path("three/nothere");
- expected = path;
- actual = manager.resolvePath(path);
- assertEquals("3.0", expected, actual);
-
- // device
- path = new Path("c:/one");
- expected = path;
- actual = manager.resolvePath(path);
- assertEquals("4.0", expected, actual);
-
- // device2
- path = new Path("c:two");
- expected = path;
- actual = manager.resolvePath(path);
- assertEquals("5.0", expected, actual);
-
- // absolute
- path = new Path("/one");
- expected = path;
- actual = manager.resolvePath(path);
- assertEquals("6.0", expected, actual);
-
- // null
- path = null;
- assertNull("7.0", manager.resolvePath(path));
-
- }
- /**
- * Test IPathVariableManager#testValidateName
- */
- public void testValidateName() {
-
- // valid names
- assertTrue("0.0", manager.validateName("ECLIPSEHOME").isOK());
- assertTrue("0.1", manager.validateName("ECLIPSE_HOME").isOK());
- assertTrue("0.2", manager.validateName("ECLIPSE_HOME_1").isOK());
- assertTrue("0.3", manager.validateName("_").isOK());
-
- // invalid names
- assertTrue("1.0", !manager.validateName("1FOO").isOK());
- assertTrue("1.1", !manager.validateName("FOO%BAR").isOK());
- assertTrue("1.2", !manager.validateName("FOO$BAR").isOK());
- assertTrue("1.3", !manager.validateName(" FOO").isOK());
- assertTrue("1.4", !manager.validateName("FOO ").isOK());
-
- }
- /**
- * Test IPathVariableManager#addChangeListener and IPathVariableManager#removeChangeListener
- */
- public void testListeners() {
- PathVariableChangeVerifier listener = new PathVariableChangeVerifier();
- manager.addChangeListener(listener);
- IPath pathOne = new Path("/tmp/foobar");
- //add device if neccessary
- pathOne = new Path(pathOne.toFile().getAbsolutePath());
- IPath pathOneEdit = pathOne.append("myworld");
-
- try {
-
- // add a variable
- try {
- manager.setValue("one", pathOne);
- } catch (CoreException e) {
- fail("1.0", e);
- }
- listener.addExpectedEvent(IPathVariableChangeEvent.VARIABLE_CREATED, "one", pathOne);
- try {
- listener.verify();
- } catch (PathVariableChangeVerifier.VerificationFailedException e) {
- fail("1.1", e);
- }
-
- // change a variable
- listener.reset();
- try {
- manager.setValue("one", pathOneEdit);
- } catch (CoreException e) {
- fail("2.0", e);
- }
- listener.addExpectedEvent(IPathVariableChangeEvent.VARIABLE_CHANGED, "one", pathOneEdit);
- try {
- listener.verify();
- } catch (PathVariableChangeVerifier.VerificationFailedException e) {
- fail("2.1", e);
- }
-
- // remove a variable
- listener.reset();
- try {
- manager.setValue("one", null);
- } catch (CoreException e) {
- fail("3.0", e);
- }
- listener.addExpectedEvent(IPathVariableChangeEvent.VARIABLE_DELETED, "one", null);
- try {
- listener.verify();
- } catch (PathVariableChangeVerifier.VerificationFailedException e) {
- fail("3.1", e);
- }
-
- } finally {
- manager.removeChangeListener(listener);
- }
- }
-
- boolean contains(Object[] array, Object obj) {
- for (int i = 0; i < array.length; i++)
- if (array[i].equals(obj))
- return true;
- return false;
- }
- /**
- * Ensure there are no path variables in the workspace.
- */
- protected void tearDown() throws Exception {
- super.tearDown();
- String[] names = manager.getPathVariableNames();
- for (int i = 0; i < names.length; i++) {
- manager.setValue(names[i], null);
- }
- }
-
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IProjectTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IProjectTest.java
deleted file mode 100644
index cbfb8e7..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IProjectTest.java
+++ /dev/null
@@ -1,2469 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import java.util.*;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.boot.BootLoader;
-import org.eclipse.core.internal.resources.Workspace;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-public class IProjectTest extends EclipseWorkspaceTest {
-public IProjectTest() {
-}
-public IProjectTest(String name) {
- super(name);
-}
-public void setGetPersistentProperty(IResource target) throws CoreException {
- String value = "this is a test property value";
- QualifiedName name = new QualifiedName("itp-test", "testProperty");
- target.setPersistentProperty(name, value);
- // see if we can get the property
- assertTrue("get not equal set", ((String) target.getPersistentProperty(name)).equals(value));
- // see what happens if we get a non-existant property
- name = new QualifiedName("eclipse-test", "testNonProperty");
- assertNull("non-existant persistent property not missing", target.getPersistentProperty(name));
-}
-protected void setUp() throws Exception {
- super.setUp();
-}
-public static Test suite() {
- return new TestSuite(IProjectTest.class);
-
-// TestSuite suite = new TestSuite();
-// suite.addTest(new IProjectTest("testCopy"));
-// return suite;
-}
-protected void tearDown() throws Exception {
- super.tearDown();
- //FIXME: This refresh may fail in the future if the .project file has been deleted
- getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
- ensureDoesNotExistInWorkspace(getWorkspace().getRoot());
-}
-/**
- * Tests the API method IProject#hasNature.
- */
-public void testHasNature() {
- IWorkspace ws = ResourcesPlugin.getWorkspace();
- IProject project = ws.getRoot().getProject("Project");
-
- //hasNature on non-existent project should fail
- try {
- project.hasNature(NATURE_SIMPLE);
- fail("1.0");
- } catch (CoreException e) {
- }
- try {
- project.hasNature(NATURE_MISSING);
- fail("1.1");
- } catch (CoreException e) {
- }
- try {
- project.create(getMonitor());
- } catch (CoreException e) {
- fail("1.99", e);
- }
- //hasNature on closed project should fail
- try {
- project.hasNature(NATURE_SIMPLE);
- fail("2.0");
- } catch (CoreException e) {
- }
- try {
- project.hasNature(NATURE_MISSING);
- fail("2.1");
- } catch (CoreException e) {
- }
- try {
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("2.99", e);
- }
- //hasNature on open project with no natures
- try {
- assertTrue("3.0", !project.hasNature(NATURE_SIMPLE));
- assertTrue("3.1", !project.hasNature(NATURE_MISSING));
- assertTrue("3.2", !project.hasNature(NATURE_EARTH));
- } catch (CoreException e) {
- fail("3.99", e);
- }
- try {
- IProjectDescription desc = project.getDescription();
- desc.setNatureIds(new String[] {NATURE_SIMPLE});
- project.setDescription(desc, getMonitor());
- } catch (CoreException e) {
- fail("4.99", e);
- }
- //hasNature on open project with natures
- try {
- assertTrue("5.0", project.hasNature(NATURE_SIMPLE));
- assertTrue("5.1", !project.hasNature(NATURE_MISSING));
- assertTrue("5.2", !project.hasNature(NATURE_EARTH));
- } catch (CoreException e) {
- fail("5.99", e);
- }
-}
-/**
- * Note that project copying is tested more thoroughly by IResourceTest#testCopy.
- */
-public void testCopy() {
- IProject project = getWorkspace().getRoot().getProject("Source");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- project.createMarker(IMarker.TASK);
- IProject destination = getWorkspace().getRoot().getProject("Destination");
-
- assertTrue("1.0", !destination.exists());
- project.copy(destination.getFullPath(), IResource.NONE, getMonitor());
- assertTrue("1.1", destination.exists());
- assertEquals("1.2", 0, destination.findMarkers(IMarker.TASK, true, IResource.DEPTH_INFINITE).length);
- } catch(CoreException e) {
- fail("1.99", e);
- }
-}
-public void testDescriptionConstant() {
- assertEquals("1.0", ".project", IProjectDescription.DESCRIPTION_FILE_NAME);
-}
-/**
- * Tests creation and manipulation of projects names that are reserved on some platforms.
- */
-public void testInvalidProjectNames() {
- IWorkspaceRoot root = getWorkspace().getRoot();
-
- //should not be able to create a project with invalid path on any platform
- String[] names = new String[] {":", "", "/"};
- for (int i = 0; i < names.length; i++) {
- try {
- root.getProject(names[i]);
- fail("0.99");
- } catch (RuntimeException e) {
- //should fail
- }
- }
- //do some tests with invalid names
- names = new String[0];
- if (BootLoader.getOS().equals(BootLoader.OS_WIN32)) {
- //invalid windows names
- names = new String[] {"prn", "nul", "con", "aux", "clock$", "com1",
- "com2", "com3", "com4", "com5", "com6", "com7", "com8", "com9",
- "lpt1", "lpt2", "lpt3", "lpt4", "lpt5", "lpt6", "lpt7", "lpt8", "lpt9",
- "AUX", "con.foo", "LPT4.txt","*", "?", "\"", "<", ">", "|"};
- } else {
- //invalid names on non-windows platforms
- names = new String[] {};
- }
- for (int i = 0; i < names.length; i++) {
- IProject project = root.getProject(names[i]);
- assertTrue("1.0 " + names[i], !project.exists());
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- fail("1.1 " + names[i]);
- } catch (CoreException e) {
- }
- assertTrue("1.2 " + names[i], !project.exists());
- assertTrue("1.3 " + names[i], !project.isOpen());
- }
-
- //do some tests with valid names that are *almost* invalid
- if (BootLoader.getOS().equals(BootLoader.OS_WIN32)) {
- //these names are valid on windows
- names = new String[] {"hello.prn.txt", "null", "con3", "foo.aux", "lpt0",
- "com0", "com10", "lpt10", ",", "'", ";"};
- } else {
- //these names are valid on non-windows platforms
- names = new String[] {"prn", "nul", "con", "aux", "clock$",
- "com1", "com2", "com3", "com4", "com5", "com6", "com7",
- "com8", "com9", "lpt1", "lpt2", "lpt3", "lpt4", "lpt5", "lpt6",
- "lpt7", "lpt8", "lpt9", "AUX", "con.foo", "LPT4.txt", "*",
- "?", "\"", "<", ">", "|", "hello.prn.txt", "null", "con3", "foo.aux",
- "lpt0", "com0", "com10", "lpt10", ",", "'", ";"};
- }
- for (int i = 0; i < names.length; i++) {
- IProject project = root.getProject(names[i]);
- assertTrue("2.0 " + names[i], !project.exists());
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("2.1 " + names[i], e);
- }
- assertTrue("2.2 " + names[i], project.exists());
- assertTrue("2.3 " + names[i], project.isOpen());
- }
-}
-/**
- * Tests the API method IProject#isNatureEnabled.
- */
-public void testIsNatureEnabled() {
- IWorkspace ws = ResourcesPlugin.getWorkspace();
- IProject project = ws.getRoot().getProject("Project");
-
- //isNatureEnabled on non-existent project should fail
- try {
- project.isNatureEnabled(NATURE_SIMPLE);
- fail("1.0");
- } catch (CoreException e) {
- }
- try {
- project.isNatureEnabled(NATURE_MISSING);
- fail("1.1");
- } catch (CoreException e) {
- }
- try {
- project.create(getMonitor());
- } catch (CoreException e) {
- fail("1.99", e);
- }
- //isNatureEnabled on closed project should fail
- try {
- project.isNatureEnabled(NATURE_SIMPLE);
- fail("2.0");
- } catch (CoreException e) {
- }
- try {
- project.isNatureEnabled(NATURE_MISSING);
- fail("2.1");
- } catch (CoreException e) {
- }
- try {
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("2.99", e);
- }
- //isNatureEnabled on open project with no natures
- try {
- assertTrue("3.0", !project.isNatureEnabled(NATURE_SIMPLE));
- assertTrue("3.1", !project.isNatureEnabled(NATURE_MISSING));
- assertTrue("3.2", !project.isNatureEnabled(NATURE_EARTH));
- } catch (CoreException e) {
- fail("3.99", e);
- }
- try {
- IProjectDescription desc = project.getDescription();
- desc.setNatureIds(new String[] {NATURE_SIMPLE});
- project.setDescription(desc, getMonitor());
- } catch (CoreException e) {
- fail("4.99", e);
- }
- //isNatureEnabled on open project with natures
- try {
- assertTrue("5.0", project.isNatureEnabled(NATURE_SIMPLE));
- assertTrue("5.1", !project.isNatureEnabled(NATURE_MISSING));
- assertTrue("5.2", !project.isNatureEnabled(NATURE_EARTH));
- } catch (CoreException e) {
- fail("5.99", e);
- }
-}
-
-public void testWorkspaceNotificationDelete() {
- final int[] count = new int[1];
- IResourceChangeListener listener = new IResourceChangeListener() {
- public void resourceChanged(IResourceChangeEvent event) {
- assertEquals("1.0", IResourceChangeEvent.PRE_DELETE, event.getType());
- count[0]++;
- assertEquals("1.1", IResource.PROJECT, event.getResource().getType());
- assertTrue("1.2", event.getResource().exists());
- }
- };
- getWorkspace().addResourceChangeListener(listener, IResourceChangeEvent.PRE_DELETE);
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("1.3", e);
- }
- assertTrue("1.4", project.exists());
- try {
- project.delete(IResource.FORCE, getMonitor());
- } catch (CoreException e) {
- fail("1.5", e);
- }
- assertEquals("1.6", 1, count[0]);
- assertTrue("1.7", !project.exists());
- getWorkspace().removeResourceChangeListener(listener);
-}
-public void testWorkspaceNotificationMove() {
- final int[] count = new int[1];
- IResourceChangeListener listener = new IResourceChangeListener() {
- public void resourceChanged(IResourceChangeEvent event) {
- assertEquals("1.0", IResourceChangeEvent.PRE_DELETE, event.getType());
- count[0]++;
- assertEquals("1.1", IResource.PROJECT, event.getResource().getType());
- assertTrue("1.2", event.getResource().exists());
- }
- };
- getWorkspace().addResourceChangeListener(listener, IResourceChangeEvent.PRE_DELETE);
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("1.3", e);
- }
- assertTrue("1.4", project.exists());
- try {
- project.move(new Path("MyNewProject"), IResource.FORCE, getMonitor());
- } catch (CoreException e) {
- fail("1.5", e);
- }
- assertEquals("1.6", 1, count[0]);
- assertTrue("1.7", !project.exists());
- getWorkspace().removeResourceChangeListener(listener);
-}
-public void testWorkspaceNotificationClose() {
- final int[] count = new int[1];
- IResourceChangeListener listener = new IResourceChangeListener() {
- public void resourceChanged(IResourceChangeEvent event) {
- assertEquals("1.0", IResourceChangeEvent.PRE_CLOSE, event.getType());
- count[0]++;
- assertEquals("1.1", IResource.PROJECT, event.getResource().getType());
- assertTrue("1.2", event.getResource().exists());
- assertTrue("1.3", ((IProject) event.getResource()).isOpen());
- }
- };
- getWorkspace().addResourceChangeListener(listener, IResourceChangeEvent.PRE_CLOSE);
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("1.4", e);
- }
- assertTrue("1.5", project.exists());
- assertTrue("1.6", project.isOpen());
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("1.7", e);
- }
- assertEquals("1.8", 1, count[0]);
- assertTrue("1.9", project.exists());
- assertTrue("1.10", !project.isOpen());
- getWorkspace().removeResourceChangeListener(listener);
-}
-
-
-public void testProjectCloseOpen() {
- IProject target = getWorkspace().getRoot().getProject("Project");
- ensureExistsInWorkspace(target, true);
- IFolder folder = target.getFolder("Folder");
- ensureExistsInWorkspace(folder, true);
-
- try {
- target.close(getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
- assertTrue("1.1", target.exists());
- assertTrue("1.2", !target.isOpen());
- assertTrue("1.3", !folder.exists());
-
- try {
- target.open(getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
- assertTrue("2.1", target.isOpen());
- assertTrue("2.2", folder.exists());
-}
-public void testProjectCopyVariations() {
- IProject project, destProject;
- IResource[] resources;
- IResource destination, source, sourceChild, destChild;
- String[] children;
- QualifiedName qname = new QualifiedName("com.example", "myProperty");
- String actual = null;
- String value = "this is my property value.";
-
- // copy a project via the copy(IPath) API
- project = getWorkspace().getRoot().getProject("SourceProject");
- source = project;
- children = new String[] { "/1/", "/1/2" };
- resources = buildResources(project, children);
- ensureExistsInWorkspace(project, true);
- ensureExistsInWorkspace(resources, true);
- destination = getWorkspace().getRoot().getProject("DestProject");
- assertDoesNotExistInWorkspace("1.0", destination);
- // set a property to copy
- sourceChild = resources[1];
- try {
- sourceChild.setPersistentProperty(qname, value);
- } catch (CoreException e) {
- fail("1.1", e);
- }
- try {
- source.copy(destination.getFullPath(), false, getMonitor());
- } catch (CoreException e) {
- fail("1.2", e);
- }
- assertExistsInWorkspace("1.3", project);
- assertExistsInWorkspace("1.4", resources);
- resources = buildResources((IProject) destination, children);
- assertExistsInWorkspace("1.5", destination);
- assertExistsInWorkspace("1.6", resources);
- // ensure the properties were copied ok
- destChild = resources[1];
- try {
- actual = destChild.getPersistentProperty(qname);
- } catch (CoreException e) {
- fail("1.7", e);
- }
- assertNotNull("1.8", actual);
- assertEquals("1.9", value, actual);
- // cleanup
- try {
- getWorkspace().getRoot().delete(false, getMonitor());
- } catch (CoreException e) {
- fail("1.10", e);
- }
-
- // copy a project via the copy(IProjectDescription) API
- project = getWorkspace().getRoot().getProject("SourceProject");
- source = project;
- children = new String[] { "/1/", "/1/2" };
- resources = buildResources(project, children);
- ensureExistsInWorkspace(project, true);
- ensureExistsInWorkspace(resources, true);
- destination = getWorkspace().getRoot().getProject("DestProject");
- IProjectDescription description = getWorkspace().newProjectDescription(destination.getName());
- assertDoesNotExistInWorkspace("2.0", destination);
- // set a property to copy
- sourceChild = resources[1];
- try {
- sourceChild.setPersistentProperty(qname, value);
- } catch (CoreException e) {
- fail("2.1", e);
- }
- try {
- ((IProject) source).copy(description, false, getMonitor());
- } catch (CoreException e) {
- fail("2.2", e);
- }
- assertExistsInWorkspace("2.3", project);
- assertExistsInWorkspace("2.4", resources);
- resources = buildResources((IProject) destination, children);
- assertExistsInWorkspace("2.5", destination);
- assertExistsInWorkspace("2.6", resources);
- // ensure the properties were copied ok
- destChild = resources[1];
- try {
- actual = destChild.getPersistentProperty(qname);
- } catch (CoreException e) {
- fail("2.7", e);
- }
- assertNotNull("2.8", actual);
- assertEquals("2.9", value, actual);
- // cleanup
- try {
- getWorkspace().getRoot().delete(false, getMonitor());
- } catch (CoreException e) {
- fail("2.10", e);
- }
-
- // create the source project, copy it to a be a folder under another project.
- // This isn't allowed so catch the exception.
- project = getWorkspace().getRoot().getProject("SourceProject");
- source = project;
- children = new String[] { "/1/", "/1/2" };
- resources = buildResources(project, children);
- destProject = getWorkspace().getRoot().getProject("DestProject");
- destination = destProject.getFolder("MyFolder");
- ensureExistsInWorkspace(new IResource[] { project, destProject }, true);
- ensureExistsInWorkspace(resources, true);
- assertDoesNotExistInWorkspace("3.0", destination);
- try {
- source.copy(destination.getFullPath(), true, getMonitor());
- fail("3.1");
- } catch (CoreException e) {
- }
- try {
- getWorkspace().getRoot().delete(false, getMonitor());
- } catch (CoreException e) {
- fail("3.99", e);
- }
-
- // create a source folder and copy it to be a project.
- // This isn't allowed so catch the exception
- project = getWorkspace().getRoot().getProject("SourceProject");
- children = new String[] { "/1/", "/1/2" };
- source = project.getFolder("1");
- resources = buildResources(project, children);
- destination = getWorkspace().getRoot().getProject("DestProject");
- ensureExistsInWorkspace(project, true);
- ensureExistsInWorkspace(resources, true);
- assertDoesNotExistInWorkspace("4.0", destination);
- try {
- source.copy(destination.getFullPath(), true, getMonitor());
- fail("4.1");
- } catch (CoreException e) {
- }
- // cleanup
- try {
- getWorkspace().getRoot().delete(true, getMonitor());
- } catch (CoreException e) {
- fail("4.99", e);
- }
-}
-public void testProjectCreateOpenCloseDelete() {
- IProject target = getWorkspace().getRoot().getProject("Project");
- try {
- target.create(getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
- assertTrue("1.1", target.exists());
-
- try {
- target.open(getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
- assertTrue("2.1", target.isOpen());
-
- try {
- target.close(getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
- assertTrue("3.1", !target.isOpen());
-
- try {
- target.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("4.0", e);
- }
- assertTrue("4.1", !target.exists());
-}
-public void testProjectCreation() {
- IProject target = getWorkspace().getRoot().getProject("Project");
-
- try {
- target.create(getMonitor());
- assertTrue("1.0", target.exists());
- } catch (CoreException e) {
- fail("1.1", e);
- }
-
- try {
- target.open(getMonitor());
- assertTrue("2.0", target.isOpen());
- } catch (CoreException e) {
- fail("2.1", e);
- }
-}
-/**
- * Tests for IProject.delete where:
- * - project is OPEN
- * - content area is the DEFAULT
- * - resources are IN_SYNC with the file system
- */
-public void testProjectDeletionOpenDefaultInSync() {
- IProject project = getWorkspace().getRoot().getProject("Project");
- IFile file = project.getFile("myfile.txt");
- IPath projectLocation, fileLocation;
-
- /* ======================================================================
- * Force = TRUE
- * Delete content = ALWAYS
- * =======================================================================*/
- ensureExistsInWorkspace(new IResource[] {project, file}, true);
- projectLocation = project.getLocation();
- fileLocation = file.getLocation();
- assertTrue("1.0", project.exists());
- assertTrue("1.1", file.exists());
- try {
- int updateFlags = IResource.FORCE;
- updateFlags |= IResource.ALWAYS_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("1.2", e);
- }
- assertTrue("1.3", !project.exists());
- assertTrue("1.4", !file.exists());
- assertTrue("1.5", !projectLocation.toFile().exists());
- assertTrue("1.6", !fileLocation.toFile().exists());
-
- /* ======================================================================
- * Force = FALSE
- * Delete content = ALWAYS
- * =======================================================================*/
- ensureExistsInWorkspace(new IResource[] {project, file}, true);
- projectLocation = project.getLocation();
- fileLocation = file.getLocation();
- assertTrue("2.0", project.exists());
- assertTrue("2.1", file.exists());
- try {
- int updateFlags = IResource.ALWAYS_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("2.2", e);
- }
- assertTrue("2.3", !project.exists());
- assertTrue("2.4", !file.exists());
- assertTrue("2.5", !projectLocation.toFile().exists());
- assertTrue("2.6", !fileLocation.toFile().exists());
-
- /* ======================================================================
- * Force = TRUE
- * Delete content = NEVER
- * =======================================================================*/
- ensureExistsInWorkspace(new IResource[] {project, file}, true);
- projectLocation = project.getLocation();
- fileLocation = file.getLocation();
- assertTrue("3.0", project.exists());
- assertTrue("3.1", file.exists());
- try {
- int updateFlags = IResource.FORCE;
- updateFlags |= IResource.NEVER_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("3.2", e);
- }
- assertTrue("3.3", !project.exists());
- assertTrue("3.4", !file.exists());
- assertTrue("3.5", projectLocation.toFile().exists());
- assertTrue("3.6", fileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = FALSE
- * Delete content = NEVER
- * =======================================================================*/
- ensureExistsInWorkspace(new IResource[] {project, file}, true);
- projectLocation = project.getLocation();
- fileLocation = file.getLocation();
- assertTrue("4.0", project.exists());
- assertTrue("4.1", file.exists());
- try {
- int updateFlags = IResource.NEVER_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("4.2", e);
- }
- assertTrue("4.3", !project.exists());
- assertTrue("4.4", !file.exists());
- assertTrue("4.5", projectLocation.toFile().exists());
- assertTrue("4.6", fileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = TRUE
- * Delete content = DEFAULT
- * =======================================================================*/
- ensureExistsInWorkspace(new IResource[] {project, file}, true);
- projectLocation = project.getLocation();
- fileLocation = file.getLocation();
- assertTrue("5.0", project.exists());
- assertTrue("5.1", file.exists());
- try {
- int updateFlags = IResource.FORCE;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("5.2", e);
- }
- assertTrue("5.3", !project.exists());
- assertTrue("5.4", !file.exists());
- assertTrue("5.5", !projectLocation.toFile().exists());
- assertTrue("5.6", !fileLocation.toFile().exists());
-
- /* ======================================================================
- * Force = FALSE
- * Delete content = DEFAULT
- * =======================================================================*/
- ensureExistsInWorkspace(new IResource[] {project, file}, true);
- projectLocation = project.getLocation();
- fileLocation = file.getLocation();
- assertTrue("6.0", project.exists());
- assertTrue("6.1", file.exists());
- try {
- int updateFlags = IResource.NONE;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("6.2", e);
- }
- assertTrue("6.3", !project.exists());
- assertTrue("6.4", !file.exists());
- assertTrue("6.5", !projectLocation.toFile().exists());
- assertTrue("6.6", !fileLocation.toFile().exists());
-}
-/**
- * Tests for IProject.delete where:
- * - project is OPEN
- * - content area is USER-DEFINED
- * - resources are IN_SYNC with the file system
- */
-public void testProjectDeletionOpenUserDefinedInSync() {
- IProject project = getWorkspace().getRoot().getProject("Project");
- IFile file = project.getFile("myfile.txt");
- IPath projectLocation, fileLocation;
- IProjectDescription description = getWorkspace().newProjectDescription(project.getName());
- Set pathsToDelete = new HashSet(6);
-
- try {
- /* ======================================================================
- * Force = TRUE
- * Delete content = ALWAYS
- * =======================================================================*/
- projectLocation = new Path(System.getProperty("user.dir")).append(Long.toString(System.currentTimeMillis()));
- pathsToDelete.add(projectLocation);
- description.setLocation(projectLocation);
- ensureExistsInWorkspace(project, description);
- ensureExistsInWorkspace(file, true);
- fileLocation = file.getLocation();
- assertTrue("1.2", project.exists());
- assertTrue("1.3", file.exists());
- try {
- int updateFlags = IResource.FORCE;
- updateFlags |= IResource.ALWAYS_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("1.4", e);
- }
- assertTrue("1.5", !project.exists());
- assertTrue("1.6", !file.exists());
- // don't want to delete the actual directory when its user-defined, but the files in
- // it should be deleted
- assertTrue("1.7", projectLocation.toFile().exists());
- assertTrue("1.8", !fileLocation.toFile().exists());
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = FALSE
- * Delete content = ALWAYS
- * =======================================================================*/
- projectLocation = new Path(System.getProperty("user.dir")).append(Long.toString(System.currentTimeMillis()));
- pathsToDelete.add(projectLocation);
- description.setLocation(projectLocation);
- ensureExistsInWorkspace(project, description);
- ensureExistsInWorkspace(file, true);
- fileLocation = file.getLocation();
- assertTrue("2.2", project.exists());
- assertTrue("2.3", file.exists());
- try {
- int updateFlags = IResource.ALWAYS_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("2.4", e);
- }
- assertTrue("2.5", !project.exists());
- assertTrue("2.6", !file.exists());
- // don't want to delete the actual directory when its user-defined, but the files in
- // it should be deleted
- assertTrue("2.7", projectLocation.toFile().exists());
- assertTrue("2.8", !fileLocation.toFile().exists());
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = TRUE
- * Delete content = NEVER
- * =======================================================================*/
- projectLocation = new Path(System.getProperty("user.dir")).append(Long.toString(System.currentTimeMillis()));
- pathsToDelete.add(projectLocation);
- description.setLocation(projectLocation);
- ensureExistsInWorkspace(project, description);
- ensureExistsInWorkspace(file, true);
- fileLocation = file.getLocation();
- assertTrue("3.2", project.exists());
- assertTrue("3.3", file.exists());
- try {
- int updateFlags = IResource.FORCE;
- updateFlags |= IResource.NEVER_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("3.4", e);
- }
- assertTrue("3.5", !project.exists());
- assertTrue("3.6", !file.exists());
- assertTrue("3.7", projectLocation.toFile().exists());
- assertTrue("3.8", fileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = FALSE
- * Delete content = NEVER
- * =======================================================================*/
- projectLocation = new Path(System.getProperty("user.dir")).append(Long.toString(System.currentTimeMillis()));
- pathsToDelete.add(projectLocation);
- description.setLocation(projectLocation);
- ensureExistsInWorkspace(project, description);
- ensureExistsInWorkspace(file, true);
- fileLocation = file.getLocation();
- assertTrue("4.2", project.exists());
- assertTrue("4.3", file.exists());
- try {
- int updateFlags = IResource.NEVER_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("4.4", e);
- }
- assertTrue("4.5", !project.exists());
- assertTrue("4.6", !file.exists());
- assertTrue("4.7", projectLocation.toFile().exists());
- assertTrue("4.8", fileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = TRUE
- * Delete content = DEFAULT
- * =======================================================================*/
- projectLocation = new Path(System.getProperty("user.dir")).append(Long.toString(System.currentTimeMillis()));
- pathsToDelete.add(projectLocation);
- description.setLocation(projectLocation);
- ensureExistsInWorkspace(project, description);
- ensureExistsInWorkspace(new IResource[] {project, file}, true);
- fileLocation = file.getLocation();
- assertTrue("5.2", project.exists());
- assertTrue("5.3", file.exists());
- try {
- int updateFlags = IResource.FORCE;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("5.4", e);
- }
- assertTrue("5.5", !project.exists());
- assertTrue("5.6", !file.exists());
- // don't delete the directory itself since the location is user-defined, but delete the contents
- assertTrue("5.7", projectLocation.toFile().exists());
- assertTrue("5.8", !fileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = FALSE
- * Delete content = DEFAULT
- * =======================================================================*/
- projectLocation = new Path(System.getProperty("user.dir")).append(Long.toString(System.currentTimeMillis()));
- pathsToDelete.add(projectLocation);
- description.setLocation(projectLocation);
- ensureExistsInWorkspace(project, description);
- ensureExistsInWorkspace(file, true);
- fileLocation = file.getLocation();
- assertTrue("6.2", project.exists());
- assertTrue("6.3", file.exists());
- try {
- int updateFlags = IResource.NONE;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("6.4", e);
- }
- assertTrue("6.5", !project.exists());
- assertTrue("6.6", !file.exists());
- // don't delete the directory itself since its user-defined, but delete the contents
- assertTrue("6.7", projectLocation.toFile().exists());
- assertTrue("6.8", !fileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
- } finally {
- for (Iterator i=pathsToDelete.iterator(); i.hasNext();) {
- Workspace.clear(((IPath) i.next()).toFile());
- }
- }
-}
-/**
- * Tests for IProject.delete where:
- * - project is CLOSED
- * - content area is USER-DEFINED
- * - resources are IN_SYNC with the file system
- */
-public void testProjectDeletionClosedUserDefinedInSync() {
- IProject project = getWorkspace().getRoot().getProject("Project");
- IFile file = project.getFile("myfile.txt");
- IPath projectLocation, fileLocation;
- IProjectDescription description = getWorkspace().newProjectDescription(project.getName());
- Set pathsToDelete = new HashSet(6);
-
- try {
- /* ======================================================================
- * Force = TRUE
- * Delete content = ALWAYS
- * =======================================================================*/
- projectLocation = new Path(System.getProperty("user.dir")).append(Long.toString(System.currentTimeMillis()));
- pathsToDelete.add(projectLocation);
- description.setLocation(projectLocation);
- ensureExistsInWorkspace(project, description);
- ensureExistsInWorkspace(file, true);
- fileLocation = file.getLocation();
- assertTrue("1.2", project.exists());
- assertTrue("1.3", file.exists());
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("1.4", e);
- }
- try {
- int updateFlags = IResource.FORCE;
- updateFlags |= IResource.ALWAYS_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("1.5", e);
- }
- assertTrue("1.6", !project.exists());
- assertTrue("1.7", !file.exists());
- // don't want to delete the actual directory when its user-defined, but the files in
- // it should be deleted
- assertTrue("1.8", projectLocation.toFile().exists());
- assertTrue("1.9", !fileLocation.toFile().exists());
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = FALSE
- * Delete content = ALWAYS
- * =======================================================================*/
- projectLocation = new Path(System.getProperty("user.dir")).append(Long.toString(System.currentTimeMillis()));
- pathsToDelete.add(projectLocation);
- description.setLocation(projectLocation);
- ensureExistsInWorkspace(project, description);
- ensureExistsInWorkspace(file, true);
- fileLocation = file.getLocation();
- assertTrue("2.2", project.exists());
- assertTrue("2.3", file.exists());
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("2.4", e);
- }
- try {
- int updateFlags = IResource.ALWAYS_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("2.5", e);
- }
- assertTrue("2.6", !project.exists());
- assertTrue("2.7", !file.exists());
- // don't want to delete the actual directory when its user-defined, but the files in
- // it should be deleted
- assertTrue("2.8", projectLocation.toFile().exists());
- assertTrue("2.9", !fileLocation.toFile().exists());
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = TRUE
- * Delete content = NEVER
- * =======================================================================*/
- projectLocation = new Path(System.getProperty("user.dir")).append(Long.toString(System.currentTimeMillis()));
- pathsToDelete.add(projectLocation);
- description.setLocation(projectLocation);
- ensureExistsInWorkspace(project, description);
- ensureExistsInWorkspace(file, true);
- fileLocation = file.getLocation();
- assertTrue("3.2", project.exists());
- assertTrue("3.3", file.exists());
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("3.4", e);
- }
- try {
- int updateFlags = IResource.FORCE;
- updateFlags |= IResource.NEVER_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("3.5", e);
- }
- assertTrue("3.6", !project.exists());
- assertTrue("3.7", !file.exists());
- assertTrue("3.8", projectLocation.toFile().exists());
- assertTrue("3.9", fileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = FALSE
- * Delete content = NEVER
- * =======================================================================*/
- projectLocation = new Path(System.getProperty("user.dir")).append(Long.toString(System.currentTimeMillis()));
- pathsToDelete.add(projectLocation);
- description.setLocation(projectLocation);
- ensureExistsInWorkspace(project, description);
- ensureExistsInWorkspace(file, true);
- fileLocation = file.getLocation();
- assertTrue("4.2", project.exists());
- assertTrue("4.3", file.exists());
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("4.4", e);
- }
- try {
- int updateFlags = IResource.NEVER_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("4.5", e);
- }
- assertTrue("4.6", !project.exists());
- assertTrue("4.7", !file.exists());
- assertTrue("4.8", projectLocation.toFile().exists());
- assertTrue("4.9", fileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = TRUE
- * Delete content = DEFAULT
- * =======================================================================*/
- projectLocation = new Path(System.getProperty("user.dir")).append(Long.toString(System.currentTimeMillis()));
- pathsToDelete.add(projectLocation);
- description.setLocation(projectLocation);
- ensureExistsInWorkspace(project, description);
- ensureExistsInWorkspace(new IResource[] {project, file}, true);
- fileLocation = file.getLocation();
- assertTrue("5.2", project.exists());
- assertTrue("5.3", file.exists());
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("5.4", e);
- }
- try {
- int updateFlags = IResource.FORCE;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("5.5", e);
- }
- assertTrue("5.6", !project.exists());
- assertTrue("5.7", !file.exists());
- assertTrue("5.8", projectLocation.toFile().exists());
- assertTrue("5.9", fileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = FALSE
- * Delete content = DEFAULT
- * =======================================================================*/
- projectLocation = new Path(System.getProperty("user.dir")).append(Long.toString(System.currentTimeMillis()));
- pathsToDelete.add(projectLocation);
- description.setLocation(projectLocation);
- ensureExistsInWorkspace(project, description);
- ensureExistsInWorkspace(file, true);
- fileLocation = file.getLocation();
- assertTrue("6.2", project.exists());
- assertTrue("6.3", file.exists());
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("6.4", e);
- }
- try {
- int updateFlags = IResource.NONE;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("6.5", e);
- }
- assertTrue("6.6", !project.exists());
- assertTrue("6.7", !file.exists());
- assertTrue("6.8", projectLocation.toFile().exists());
- assertTrue("6.9", fileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
- } finally {
- for (Iterator i=pathsToDelete.iterator(); i.hasNext();) {
- Workspace.clear(((IPath) i.next()).toFile());
- }
- }
-}
-/**
- * Tests for IProject.delete where:
- * - project is OPEN
- * - content area is USER-DEFINED
- * - resources are OUT_OF_SYNC with the file system
- */
-public void testProjectDeletionOpenUserDefinedOutOfSync() {
- IProject project = getWorkspace().getRoot().getProject("Project");
- IFile file = project.getFile("myfile.txt");
- IFile otherFile = project.getFile("myotherfile.txt");
- IPath projectLocation, fileLocation, otherFileLocation;
- IProjectDescription description = getWorkspace().newProjectDescription(project.getName());
- Set pathsToDelete = new HashSet(6);
-
- try {
- /* ======================================================================
- * Force = TRUE
- * Delete content = ALWAYS
- * =======================================================================*/
- projectLocation = new Path(System.getProperty("user.dir")).append(Long.toString(System.currentTimeMillis()));
- pathsToDelete.add(projectLocation);
- description.setLocation(projectLocation);
- ensureExistsInWorkspace(project, description);
- ensureExistsInWorkspace(file, true);
- ensureExistsInFileSystem(otherFile);
- fileLocation = file.getLocation();
- otherFileLocation = otherFile.getLocation();
- assertTrue("1.0", project.exists());
- assertTrue("1.1", file.exists());
- assertTrue("1.2", !otherFile.exists());
- try {
- int updateFlags = IResource.FORCE;
- updateFlags |= IResource.ALWAYS_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("1.3", e);
- }
- assertTrue("1.4", !project.exists());
- assertTrue("1.5", !file.exists());
- assertTrue("1.6", !otherFile.exists());
- // don't want to delete the actual directory when its user-defined, but the files in
- // it should be deleted
- assertTrue("1.7", projectLocation.toFile().exists());
- assertTrue("1.8", !fileLocation.toFile().exists());
- assertTrue("1.9", !otherFileLocation.toFile().exists());
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = FALSE
- * Delete content = ALWAYS
- * =======================================================================*/
- projectLocation = new Path(System.getProperty("user.dir")).append(Long.toString(System.currentTimeMillis()));
- pathsToDelete.add(projectLocation);
- description.setLocation(projectLocation);
- ensureExistsInWorkspace(project, description);
- ensureExistsInWorkspace(file, true);
- ensureExistsInFileSystem(otherFile);
- fileLocation = file.getLocation();
- otherFileLocation = otherFile.getLocation();
- assertTrue("2.0", project.exists());
- assertTrue("2.1", file.exists());
- assertTrue("2.2", !otherFile.exists());
- try {
- int updateFlags = IResource.ALWAYS_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("2.3", e);
- }
- assertTrue("2.4", !project.exists());
- assertTrue("2.5", !file.exists());
- assertTrue("2.6", !otherFile.exists());
- // don't want to delete the actual directory when its user-defined, but the files in
- // it should be deleted
- assertTrue("2.7", projectLocation.toFile().exists());
- assertTrue("2.8", !fileLocation.toFile().exists());
- assertTrue("2.9", !otherFileLocation.toFile().exists());
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = TRUE
- * Delete content = NEVER
- * =======================================================================*/
- projectLocation = new Path(System.getProperty("user.dir")).append(Long.toString(System.currentTimeMillis()));
- pathsToDelete.add(projectLocation);
- description.setLocation(projectLocation);
- ensureExistsInWorkspace(project, description);
- ensureExistsInWorkspace(file, true);
- ensureExistsInFileSystem(otherFile);
- fileLocation = file.getLocation();
- otherFileLocation = otherFile.getLocation();
- assertTrue("3.0", project.exists());
- assertTrue("3.1", file.exists());
- assertTrue("3.2", !otherFile.exists());
- try {
- int updateFlags = IResource.FORCE;
- updateFlags |= IResource.NEVER_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("3.3", e);
- }
- assertTrue("3.4", !project.exists());
- assertTrue("3.5", !file.exists());
- assertTrue("3.6", !otherFile.exists());
- assertTrue("3.7", projectLocation.toFile().exists());
- assertTrue("3.8", fileLocation.toFile().exists());
- assertTrue("3.9", otherFileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = FALSE
- * Delete content = NEVER
- * =======================================================================*/
- projectLocation = new Path(System.getProperty("user.dir")).append(Long.toString(System.currentTimeMillis()));
- pathsToDelete.add(projectLocation);
- description.setLocation(projectLocation);
- ensureExistsInWorkspace(project, description);
- ensureExistsInWorkspace(file, true);
- ensureExistsInFileSystem(otherFile);
- fileLocation = file.getLocation();
- otherFileLocation = otherFile.getLocation();
- assertTrue("4.0", project.exists());
- assertTrue("4.1", file.exists());
- assertTrue("4.2", !otherFile.exists());
- try {
- int updateFlags = IResource.NEVER_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("4.3", e);
- }
- assertTrue("4.4", !project.exists());
- assertTrue("4.5", !file.exists());
- assertTrue("4.6", !otherFile.exists());
- assertTrue("4.7", projectLocation.toFile().exists());
- assertTrue("4.8", fileLocation.toFile().exists());
- assertTrue("4.9", otherFileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = TRUE
- * Delete content = DEFAULT
- * =======================================================================*/
- projectLocation = new Path(System.getProperty("user.dir")).append(Long.toString(System.currentTimeMillis()));
- pathsToDelete.add(projectLocation);
- description.setLocation(projectLocation);
- ensureExistsInWorkspace(project, description);
- ensureExistsInWorkspace(new IResource[] {project, file}, true);
- ensureExistsInFileSystem(otherFile);
- fileLocation = file.getLocation();
- otherFileLocation = otherFile.getLocation();
- assertTrue("5.0", project.exists());
- assertTrue("5.1", file.exists());
- assertTrue("5.2", !otherFile.exists());
- try {
- int updateFlags = IResource.FORCE;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("5.3", e);
- }
- assertTrue("5.4", !project.exists());
- assertTrue("5.5", !file.exists());
- assertTrue("5.6", !otherFile.exists());
- // don't delete the directory itself since the location is user-defined, but delete the contents
- assertTrue("5.7", projectLocation.toFile().exists());
- assertTrue("5.8", !fileLocation.toFile().exists());
- assertTrue("5.9", !otherFileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = FALSE
- * Delete content = DEFAULT
- * =======================================================================*/
- projectLocation = new Path(System.getProperty("user.dir")).append(Long.toString(System.currentTimeMillis()));
- pathsToDelete.add(projectLocation);
- description.setLocation(projectLocation);
- ensureExistsInWorkspace(project, description);
- ensureExistsInWorkspace(file, true);
- ensureExistsInFileSystem(otherFile);
- fileLocation = file.getLocation();
- otherFileLocation = otherFile.getLocation();
- assertTrue("6.0", project.exists());
- assertTrue("6.1", file.exists());
- assertTrue("6.2", !otherFile.exists());
- try {
- int updateFlags = IResource.NONE;
- project.delete(updateFlags, getMonitor());
- fail("6.3");
- } catch (CoreException e) {
- }
- assertTrue("6.4", project.exists());
- // delete was best effort so this file should be gone.
- assertTrue("6.5", !file.exists());
- assertTrue("6.6", !otherFile.exists());
- // don't delete the directory itself since its user-defined, but delete the contents
- assertTrue("6.7", projectLocation.toFile().exists());
- assertTrue("6.8", !fileLocation.toFile().exists());
- assertTrue("6.9", otherFileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
- } finally {
- for (Iterator i=pathsToDelete.iterator(); i.hasNext();) {
- Workspace.clear(((IPath) i.next()).toFile());
- }
- }
-}
-/**
- * Tests for IProject.delete where:
- * - project is CLOSED
- * - content area is USER-DEFINED
- * - resources are OUT_OF_SYNC with the file system
- */
-public void testProjectDeletionClosedUserDefinedOutOfSync() {
- IProject project = getWorkspace().getRoot().getProject("Project");
- IFile file = project.getFile("myfile.txt");
- IFile otherFile = project.getFile("myotherfile.txt");
- IPath projectLocation, fileLocation, otherFileLocation;
- IProjectDescription description = getWorkspace().newProjectDescription(project.getName());
- Set pathsToDelete = new HashSet(6);
-
- try {
- /* ======================================================================
- * Force = TRUE
- * Delete content = ALWAYS
- * =======================================================================*/
- projectLocation = new Path(System.getProperty("user.dir")).append(Long.toString(System.currentTimeMillis()));
- pathsToDelete.add(projectLocation);
- description.setLocation(projectLocation);
- ensureExistsInWorkspace(project, description);
- ensureExistsInWorkspace(file, true);
- ensureExistsInFileSystem(otherFile);
- fileLocation = file.getLocation();
- otherFileLocation = otherFile.getLocation();
- assertTrue("1.0", project.exists());
- assertTrue("1.1", file.exists());
- assertTrue("1.2", !otherFile.exists());
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("1.3", e);
- }
- try {
- int updateFlags = IResource.FORCE;
- updateFlags |= IResource.ALWAYS_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("1.4", e);
- }
- assertTrue("1.5", !project.exists());
- assertTrue("1.6", !file.exists());
- assertTrue("1.7", !otherFile.exists());
- // don't want to delete the actual directory when its user-defined, but the files in
- // it should be deleted
- assertTrue("1.8", projectLocation.toFile().exists());
- assertTrue("1.9", !fileLocation.toFile().exists());
- assertTrue("1.10", !otherFileLocation.toFile().exists());
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = FALSE
- * Delete content = ALWAYS
- * =======================================================================*/
- projectLocation = new Path(System.getProperty("user.dir")).append(Long.toString(System.currentTimeMillis()));
- pathsToDelete.add(projectLocation);
- description.setLocation(projectLocation);
- ensureExistsInWorkspace(project, description);
- ensureExistsInWorkspace(file, true);
- ensureExistsInFileSystem(otherFile);
- fileLocation = file.getLocation();
- otherFileLocation = otherFile.getLocation();
- assertTrue("2.0", project.exists());
- assertTrue("2.1", file.exists());
- assertTrue("2.2", !otherFile.exists());
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("2.3", e);
- }
- try {
- int updateFlags = IResource.ALWAYS_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("2.4", e);
- }
- assertTrue("2.5", !project.exists());
- assertTrue("2.6", !file.exists());
- assertTrue("2.7", !otherFile.exists());
- // don't want to delete the actual directory when its user-defined, but the files in
- // it should be deleted
- assertTrue("2.8", projectLocation.toFile().exists());
- assertTrue("2.9", !fileLocation.toFile().exists());
- assertTrue("2.10", !otherFileLocation.toFile().exists());
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = TRUE
- * Delete content = NEVER
- * =======================================================================*/
- projectLocation = new Path(System.getProperty("user.dir")).append(Long.toString(System.currentTimeMillis()));
- pathsToDelete.add(projectLocation);
- description.setLocation(projectLocation);
- ensureExistsInWorkspace(project, description);
- ensureExistsInWorkspace(file, true);
- ensureExistsInFileSystem(otherFile);
- fileLocation = file.getLocation();
- otherFileLocation = otherFile.getLocation();
- assertTrue("3.0", project.exists());
- assertTrue("3.1", file.exists());
- assertTrue("3.2", !otherFile.exists());
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("3.3", e);
- }
- try {
- int updateFlags = IResource.FORCE;
- updateFlags |= IResource.NEVER_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("3.4", e);
- }
- assertTrue("3.5", !project.exists());
- assertTrue("3.6", !file.exists());
- assertTrue("3.7", !otherFile.exists());
- assertTrue("3.8", projectLocation.toFile().exists());
- assertTrue("3.9", fileLocation.toFile().exists());
- assertTrue("3.10", otherFileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = FALSE
- * Delete content = NEVER
- * =======================================================================*/
- projectLocation = new Path(System.getProperty("user.dir")).append(Long.toString(System.currentTimeMillis()));
- pathsToDelete.add(projectLocation);
- description.setLocation(projectLocation);
- ensureExistsInWorkspace(project, description);
- ensureExistsInWorkspace(file, true);
- ensureExistsInFileSystem(otherFile);
- fileLocation = file.getLocation();
- otherFileLocation = otherFile.getLocation();
- assertTrue("4.0", project.exists());
- assertTrue("4.1", file.exists());
- assertTrue("4.2", !otherFile.exists());
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("4.3", e);
- }
- try {
- int updateFlags = IResource.NEVER_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("4.4", e);
- }
- assertTrue("4.5", !project.exists());
- assertTrue("4.6", !file.exists());
- assertTrue("4.7", !otherFile.exists());
- assertTrue("4.8", projectLocation.toFile().exists());
- assertTrue("4.9", fileLocation.toFile().exists());
- assertTrue("4.10", otherFileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = TRUE
- * Delete content = DEFAULT
- * =======================================================================*/
- projectLocation = new Path(System.getProperty("user.dir")).append(Long.toString(System.currentTimeMillis()));
- pathsToDelete.add(projectLocation);
- description.setLocation(projectLocation);
- ensureExistsInWorkspace(project, description);
- ensureExistsInWorkspace(new IResource[] {project, file}, true);
- ensureExistsInFileSystem(otherFile);
- fileLocation = file.getLocation();
- otherFileLocation = otherFile.getLocation();
- assertTrue("5.0", project.exists());
- assertTrue("5.1", file.exists());
- assertTrue("5.2", !otherFile.exists());
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("5.3", e);
- }
- try {
- int updateFlags = IResource.FORCE;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("5.4", e);
- }
- assertTrue("5.5", !project.exists());
- assertTrue("5.6", !file.exists());
- assertTrue("5.7", !otherFile.exists());
- // don't delete the directory itself since the location is user-defined, but delete the contents
- assertTrue("5.8", projectLocation.toFile().exists());
- assertTrue("5.9", fileLocation.toFile().exists());
- assertTrue("5.10", otherFileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = FALSE
- * Delete content = DEFAULT
- * =======================================================================*/
- projectLocation = new Path(System.getProperty("user.dir")).append(Long.toString(System.currentTimeMillis()));
- pathsToDelete.add(projectLocation);
- description.setLocation(projectLocation);
- ensureExistsInWorkspace(project, description);
- ensureExistsInWorkspace(file, true);
- ensureExistsInFileSystem(otherFile);
- fileLocation = file.getLocation();
- otherFileLocation = otherFile.getLocation();
- assertTrue("6.0", project.exists());
- assertTrue("6.1", file.exists());
- assertTrue("6.2", !otherFile.exists());
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("6.3", e);
- }
- try {
- int updateFlags = IResource.NONE;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("6.4", e);
- }
- assertTrue("6.5", !project.exists());
- // delete was best effort so this file should be gone.
- assertTrue("6.6", !file.exists());
- assertTrue("6.7", !otherFile.exists());
- // don't delete the directory itself since its user-defined, but delete the contents
- assertTrue("6.8", projectLocation.toFile().exists());
- assertTrue("6.9", fileLocation.toFile().exists());
- assertTrue("6.10", otherFileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
- } finally {
- for (Iterator i=pathsToDelete.iterator(); i.hasNext();) {
- Workspace.clear(((IPath) i.next()).toFile());
- }
- }
-}
-public void ensureExistsInWorkspace(final IProject project, final IProjectDescription description) {
- if (project == null)
- return;
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- project.create(description, monitor);
- project.open(monitor);
- }
- };
- try {
- getWorkspace().run(body, null);
- } catch (CoreException e) {
- fail("#ensureExistsInWorkspace(IProject, IProjectDescription): " + project.getFullPath(), e);
- }
-}
-/**
- * Tests for IProject.delete where:
- * - project is CLOSED
- * - content area is the DEFAULT
- * - resources are IN_SYNC with the file system
- */
-public void testProjectDeletionClosedDefaultInSync() {
- IProject project = getWorkspace().getRoot().getProject("Project");
- IFile file = project.getFile("myfile.txt");
- IFile otherFile = project.getFile("myotherfile.txt");
- IPath projectLocation, fileLocation, otherFileLocation;
-
- /* ======================================================================
- * Force = TRUE
- * Delete content = ALWAYS
- * =======================================================================*/
- ensureExistsInWorkspace(new IResource[] {project, file, otherFile}, true);
- projectLocation = project.getLocation();
- fileLocation = file.getLocation();
- otherFileLocation = otherFile.getLocation();
- assertTrue("1.0", project.exists());
- assertTrue("1.1", file.exists());
- assertTrue("1.2", otherFile.exists());
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("1.3", e);
- }
- assertTrue("1.4", project.exists());
- assertTrue("1.5", !project.isOpen());
- assertTrue("1.6", !project.isAccessible());
- assertTrue("1.7", !file.exists());
- assertTrue("1.8", !otherFile.exists());
- try {
- int updateFlags = IResource.FORCE;
- updateFlags |= IResource.ALWAYS_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("1.9", e);
- }
- assertTrue("1.10", !project.exists());
- assertTrue("1.11", !file.exists());
- assertTrue("1.12", !otherFile.exists());
- assertTrue("1.13", !projectLocation.toFile().exists());
- assertTrue("1.14", !fileLocation.toFile().exists());
- assertTrue("1.15", !otherFileLocation.toFile().exists());
-
- /* ======================================================================
- * Force = FALSE
- * Delete content = ALWAYS
- * =======================================================================*/
- ensureExistsInWorkspace(new IResource[] {project, file, otherFile}, true);
- projectLocation = project.getLocation();
- fileLocation = file.getLocation();
- otherFileLocation = otherFile.getLocation();
- assertTrue("2.0", project.exists());
- assertTrue("2.1", file.exists());
- assertTrue("2.2", otherFile.exists());
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("2.3", e);
- }
- assertTrue("2.4", project.exists());
- assertTrue("2.5", !project.isOpen());
- assertTrue("2.6", !project.isAccessible());
- assertTrue("2.7", !file.exists());
- assertTrue("2.8", !otherFile.exists());
- try {
- int updateFlags = IResource.ALWAYS_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("2.9", e);
- }
- assertTrue("2.10", !project.exists());
- assertTrue("2.11", !file.exists());
- assertTrue("2.12", !otherFile.exists());
- assertTrue("2.13", !projectLocation.toFile().exists());
- assertTrue("2.14", !fileLocation.toFile().exists());
- assertTrue("2.15", !otherFileLocation.toFile().exists());
-
- /* ======================================================================
- * Force = TRUE
- * Delete content = NEVER
- * =======================================================================*/
- ensureExistsInWorkspace(new IResource[] {project, file, otherFile}, true);
- projectLocation = project.getLocation();
- fileLocation = file.getLocation();
- otherFileLocation = otherFile.getLocation();
- assertTrue("3.0", project.exists());
- assertTrue("3.1", file.exists());
- assertTrue("3.2", otherFile.exists());
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("3.3", e);
- }
- assertTrue("3.4", project.exists());
- assertTrue("3.5", !project.isOpen());
- assertTrue("3.6", !project.isAccessible());
- assertTrue("3.7", !file.exists());
- assertTrue("3.8", !otherFile.exists());
- try {
- int updateFlags = IResource.FORCE;
- updateFlags |= IResource.NEVER_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("3.9", e);
- }
- assertTrue("3.10", !project.exists());
- assertTrue("3.11", !file.exists());
- assertTrue("3.12", !otherFile.exists());
- assertTrue("3.13", projectLocation.toFile().exists());
- assertTrue("3.14", fileLocation.toFile().exists());
- assertTrue("3.15", otherFileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = FALSE
- * Delete content = NEVER
- * =======================================================================*/
- ensureExistsInWorkspace(new IResource[] {project, file, otherFile}, true);
- projectLocation = project.getLocation();
- fileLocation = file.getLocation();
- otherFileLocation = otherFile.getLocation();
- assertTrue("4.0", project.exists());
- assertTrue("4.1", file.exists());
- assertTrue("4.2", otherFile.exists());
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("4.3", e);
- }
- assertTrue("4.4", project.exists());
- assertTrue("4.5", !project.isOpen());
- assertTrue("4.6", !project.isAccessible());
- assertTrue("4.7", !file.exists());
- assertTrue("4.8", !otherFile.exists());
- try {
- int updateFlags = IResource.NEVER_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("4.9", e);
- }
- assertTrue("4.10", !project.exists());
- assertTrue("4.11", !file.exists());
- assertTrue("4.12", !otherFile.exists());
- assertTrue("4.13", projectLocation.toFile().exists());
- assertTrue("4.14", fileLocation.toFile().exists());
- assertTrue("4.15", otherFileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = TRUE
- * Delete content = DEFAULT
- * =======================================================================*/
- ensureExistsInWorkspace(new IResource[] {project, file, otherFile}, true);
- projectLocation = project.getLocation();
- fileLocation = file.getLocation();
- otherFileLocation = otherFile.getLocation();
- assertTrue("5.0", project.exists());
- assertTrue("5.1", file.exists());
- assertTrue("5.2", otherFile.exists());
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("5.3", e);
- }
- assertTrue("5.4", project.exists());
- assertTrue("5.5", !project.isOpen());
- assertTrue("5.6", !project.isAccessible());
- assertTrue("5.7", !file.exists());
- assertTrue("5.8", !otherFile.exists());
- try {
- int updateFlags = IResource.FORCE;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("5.9", e);
- }
- assertTrue("5.10", !project.exists());
- assertTrue("5.11", !file.exists());
- assertTrue("5.12", !otherFile.exists());
- assertTrue("5.13", projectLocation.toFile().exists());
- assertTrue("5.14", fileLocation.toFile().exists());
- assertTrue("5.15", otherFileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = FALSE
- * Delete content = DEFAULT
- * =======================================================================*/
- ensureExistsInWorkspace(new IResource[] {project, file, otherFile}, true);
- projectLocation = project.getLocation();
- fileLocation = file.getLocation();
- otherFileLocation = otherFile.getLocation();
- assertTrue("6.0", project.exists());
- assertTrue("6.1", file.exists());
- assertTrue("6.2", otherFile.exists());
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("6.3", e);
- }
- assertTrue("6.4", project.exists());
- assertTrue("6.5", !project.isOpen());
- assertTrue("6.6", !project.isAccessible());
- assertTrue("6.7", !file.exists());
- assertTrue("6.8", !otherFile.exists());
- try {
- int updateFlags = IResource.NONE;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("6.9", e);
- }
- assertTrue("6.10", !project.exists());
- assertTrue("6.11", !file.exists());
- assertTrue("6.12", !otherFile.exists());
- assertTrue("6.13", projectLocation.toFile().exists());
- assertTrue("6.14", fileLocation.toFile().exists());
- assertTrue("6.15", otherFileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
-}
-/**
- * Tests for IProject.delete where:
- * - project is CLOSED
- * - content area is the DEFAULT
- * - resources are OUT_OF_SYNC with the file system
- */
-public void testProjectDeletionClosedDefaultOutOfSync() {
- IProject project = getWorkspace().getRoot().getProject("Project");
- IFile file = project.getFile("myfile.txt");
- IFile otherFile = project.getFile("myotherfile.txt");
- IPath projectLocation, fileLocation, otherFileLocation;
-
- /* ======================================================================
- * Force = TRUE
- * Delete content = ALWAYS
- * =======================================================================*/
- ensureExistsInWorkspace(new IResource[] {project, file}, true);
- projectLocation = project.getLocation();
- fileLocation = file.getLocation();
- otherFileLocation = otherFile.getLocation();
- assertTrue("1.0", project.exists());
- assertTrue("1.1", file.exists());
- assertTrue("1.2", !otherFile.exists());
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("1.3", e);
- }
- try {
- createFileInFileSystem(otherFileLocation);
- } catch(CoreException e) {
- fail("1.4", e);
- }
- assertTrue("1.5", otherFileLocation.toFile().exists());
- assertTrue("1.6", project.exists());
- assertTrue("1.7", !project.isOpen());
- assertTrue("1.8", !project.isAccessible());
- assertTrue("1.9", !file.exists());
- assertTrue("1.10", !otherFile.exists());
- try {
- int updateFlags = IResource.FORCE;
- updateFlags |= IResource.ALWAYS_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("1.11", e);
- }
- assertTrue("1.12", !project.exists());
- assertTrue("1.13", !file.exists());
- assertTrue("1.14", !otherFile.exists());
- assertTrue("1.15", !projectLocation.toFile().exists());
- assertTrue("1.16", !fileLocation.toFile().exists());
- assertTrue("1.17", !otherFileLocation.toFile().exists());
-
- /* ======================================================================
- * Force = FALSE
- * Delete content = ALWAYS
- * =======================================================================*/
- ensureExistsInWorkspace(new IResource[] {project, file}, true);
- projectLocation = project.getLocation();
- fileLocation = file.getLocation();
- otherFileLocation = otherFile.getLocation();
- assertTrue("2.0", project.exists());
- assertTrue("2.1", file.exists());
- assertTrue("2.2", !otherFile.exists());
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("2.3", e);
- }
- try {
- createFileInFileSystem(otherFileLocation);
- } catch(CoreException e) {
- fail("2.4", e);
- }
- assertTrue("2.5", otherFileLocation.toFile().exists());
- assertTrue("2.6", project.exists());
- assertTrue("2.7", !project.isOpen());
- assertTrue("2.8", !project.isAccessible());
- assertTrue("2.9", !file.exists());
- assertTrue("2.10", !otherFile.exists());
- try {
- int updateFlags = IResource.ALWAYS_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("2.11", e);
- }
- assertTrue("2.12", !project.exists());
- assertTrue("2.13", !file.exists());
- assertTrue("2.14", !otherFile.exists());
- assertTrue("2.15", !projectLocation.toFile().exists());
- assertTrue("2.16", !fileLocation.toFile().exists());
- assertTrue("2.17", !otherFileLocation.toFile().exists());
-
- /* ======================================================================
- * Force = TRUE
- * Delete content = NEVER
- * =======================================================================*/
- ensureExistsInWorkspace(new IResource[] {project, file}, true);
- projectLocation = project.getLocation();
- fileLocation = file.getLocation();
- otherFileLocation = otherFile.getLocation();
- assertTrue("3.0", project.exists());
- assertTrue("3.1", file.exists());
- assertTrue("3.2", !otherFile.exists());
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("3.3", e);
- }
- try {
- createFileInFileSystem(otherFileLocation);
- } catch(CoreException e) {
- fail("3.4", e);
- }
- assertTrue("3.5", otherFileLocation.toFile().exists());
- assertTrue("3.6", project.exists());
- assertTrue("3.7", !project.isOpen());
- assertTrue("3.8", !project.isAccessible());
- assertTrue("3.9", !file.exists());
- assertTrue("3.10", !otherFile.exists());
- try {
- int updateFlags = IResource.FORCE;
- updateFlags |= IResource.NEVER_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("3.11", e);
- }
- assertTrue("3.12", !project.exists());
- assertTrue("3.13", !file.exists());
- assertTrue("3.14", !otherFile.exists());
- assertTrue("3.15", projectLocation.toFile().exists());
- assertTrue("3.16", fileLocation.toFile().exists());
- assertTrue("3.17", otherFileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = FALSE
- * Delete content = NEVER
- * =======================================================================*/
- ensureExistsInWorkspace(new IResource[] {project, file}, true);
- projectLocation = project.getLocation();
- fileLocation = file.getLocation();
- otherFileLocation = otherFile.getLocation();
- assertTrue("4.0", project.exists());
- assertTrue("4.1", file.exists());
- assertTrue("4.2", !otherFile.exists());
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("4.3", e);
- }
- try {
- createFileInFileSystem(otherFileLocation);
- } catch(CoreException e) {
- fail("4.4", e);
- }
- assertTrue("4.5", otherFileLocation.toFile().exists());
- assertTrue("4.6", project.exists());
- assertTrue("4.7", !project.isOpen());
- assertTrue("4.8", !project.isAccessible());
- assertTrue("4.9", !file.exists());
- assertTrue("4.10", !otherFile.exists());
- try {
- int updateFlags = IResource.NEVER_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("4.11", e);
- }
- assertTrue("4.12", !project.exists());
- assertTrue("4.13", !file.exists());
- assertTrue("4.14", !otherFile.exists());
- assertTrue("4.15", projectLocation.toFile().exists());
- assertTrue("4.16", fileLocation.toFile().exists());
- assertTrue("4.17", otherFileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = TRUE
- * Delete content = DEFAULT
- * =======================================================================*/
- ensureExistsInWorkspace(new IResource[] {project, file}, true);
- projectLocation = project.getLocation();
- fileLocation = file.getLocation();
- otherFileLocation = otherFile.getLocation();
- assertTrue("5.0", project.exists());
- assertTrue("5.1", file.exists());
- assertTrue("5.2", !otherFile.exists());
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("5.3", e);
- }
- try {
- createFileInFileSystem(otherFileLocation);
- } catch(CoreException e) {
- fail("5.4", e);
- }
- assertTrue("5.5", otherFileLocation.toFile().exists());
- assertTrue("5.6", project.exists());
- assertTrue("5.7", !project.isOpen());
- assertTrue("5.8", !project.isAccessible());
- assertTrue("5.9", !file.exists());
- assertTrue("5.10", !otherFile.exists());
- try {
- int updateFlags = IResource.FORCE;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("5.11", e);
- }
- assertTrue("5.12", !project.exists());
- assertTrue("5.13", !file.exists());
- assertTrue("5.14", !otherFile.exists());
- assertTrue("5.15", projectLocation.toFile().exists());
- assertTrue("5.16", fileLocation.toFile().exists());
- assertTrue("5.17", otherFileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = FALSE
- * Delete content = DEFAULT
- * =======================================================================*/
- ensureExistsInWorkspace(new IResource[] {project, file}, true);
- projectLocation = project.getLocation();
- fileLocation = file.getLocation();
- otherFileLocation = otherFile.getLocation();
- assertTrue("6.0", project.exists());
- assertTrue("6.1", file.exists());
- assertTrue("6.2", !otherFile.exists());
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("6.3", e);
- }
- try {
- createFileInFileSystem(otherFileLocation);
- } catch(CoreException e) {
- fail("6.4", e);
- }
- assertTrue("6.5", otherFileLocation.toFile().exists());
- assertTrue("6.6", project.exists());
- assertTrue("6.7", !project.isOpen());
- assertTrue("6.8", !project.isAccessible());
- assertTrue("6.9", !file.exists());
- assertTrue("6.10", !otherFile.exists());
- try {
- int updateFlags = IResource.NONE;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("6.11", e);
- }
- assertTrue("6.12", !project.exists());
- assertTrue("6.13", !file.exists());
- assertTrue("6.14", !otherFile.exists());
- assertTrue("6.15", projectLocation.toFile().exists());
- assertTrue("6.16", fileLocation.toFile().exists());
- assertTrue("6.17", otherFileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
-}
-/**
- * Tests for IProject.delete where:
- * - project is OPEN
- * - content area is the DEFAULT
- * - resources are OUT_OF_SYNC with the file system
- */
-public void testProjectDeletionOpenDefaultOutOfSync() {
- IProject project = getWorkspace().getRoot().getProject("Project");
- IFile file = project.getFile("myfile.txt");
- IPath projectLocation, fileLocation;
-
- /* ======================================================================
- * Force = TRUE
- * Delete content = ALWAYS
- * =======================================================================*/
- ensureExistsInWorkspace(project, true);
- ensureExistsInFileSystem(file);
- projectLocation = project.getLocation();
- fileLocation = file.getLocation();
- assertTrue("1.0", project.exists());
- assertTrue("1.1", !file.exists());
- try {
- int updateFlags = IResource.FORCE;
- updateFlags |= IResource.ALWAYS_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("1.2", e);
- }
- assertTrue("1.3", !project.exists());
- assertTrue("1.4", !file.exists());
- assertTrue("1.5", !projectLocation.toFile().exists());
- assertTrue("1.6", !fileLocation.toFile().exists());
-
- /* ======================================================================
- * Force = FALSE
- * Delete content = ALWAYS (always_delete_content over-rides FORCE flag)
- * =======================================================================*/
- ensureExistsInWorkspace(project, true);
- ensureExistsInFileSystem(file);
- projectLocation = project.getLocation();
- fileLocation = file.getLocation();
- assertTrue("2.0", project.exists());
- assertTrue("2.1", !file.exists());
- try {
- int updateFlags = IResource.ALWAYS_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("2.2", e);
- }
- assertTrue("2.3", !project.exists());
- assertTrue("2.4", !file.exists());
- assertTrue("2.5", !projectLocation.toFile().exists());
- assertTrue("2.6", !fileLocation.toFile().exists());
-
- /* ======================================================================
- * Force = TRUE
- * Delete content = NEVER
- * =======================================================================*/
- ensureExistsInWorkspace(project, true);
- ensureExistsInFileSystem(file);
- projectLocation = project.getLocation();
- fileLocation = file.getLocation();
- assertTrue("3.0", project.exists());
- assertTrue("3.1", !file.exists());
- try {
- int updateFlags = IResource.FORCE;
- updateFlags |= IResource.NEVER_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("3.2", e);
- }
- assertTrue("3.3", !project.exists());
- assertTrue("3.4", !file.exists());
- assertTrue("3.5", projectLocation.toFile().exists());
- assertTrue("3.6", fileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = FALSE
- * Delete content = NEVER
- * =======================================================================*/
- ensureExistsInWorkspace(project, true);
- ensureExistsInFileSystem(file);
- projectLocation = project.getLocation();
- fileLocation = file.getLocation();
- assertTrue("4.0", project.exists());
- assertTrue("4.1", !file.exists());
- try {
- int updateFlags = IResource.NEVER_DELETE_PROJECT_CONTENT;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("4.2", e);
- }
- assertTrue("4.3", !project.exists());
- assertTrue("4.4", !file.exists());
- assertTrue("4.5", projectLocation.toFile().exists());
- assertTrue("4.6", fileLocation.toFile().exists());
- // cleanup
- Workspace.clear(projectLocation.toFile());
-
- /* ======================================================================
- * Force = TRUE
- * Delete content = DEFAULT
- * =======================================================================*/
- ensureExistsInWorkspace(project, true);
- ensureExistsInFileSystem(file);
- projectLocation = project.getLocation();
- fileLocation = file.getLocation();
- assertTrue("5.0", project.exists());
- assertTrue("5.1", !file.exists());
- try {
- int updateFlags = IResource.FORCE;
- project.delete(updateFlags, getMonitor());
- } catch (CoreException e) {
- fail("5.2", e);
- }
- assertTrue("5.3", !project.exists());
- assertTrue("5.4", !file.exists());
- assertTrue("5.5", !projectLocation.toFile().exists());
- assertTrue("5.6", !fileLocation.toFile().exists());
-
- /* ======================================================================
- * Force = FALSE
- * Delete content = DEFAULT
- * =======================================================================*/
- ensureExistsInWorkspace(project, true);
- ensureExistsInFileSystem(file);
- projectLocation = project.getLocation();
- fileLocation = file.getLocation();
- assertTrue("6.0", project.exists());
- assertTrue("6.1", !file.exists());
- try {
- int updateFlags = IResource.NONE;
- project.delete(updateFlags, getMonitor());
- fail("6.2");
- } catch (CoreException e) {
- }
- assertTrue("6.3", project.exists());
- assertTrue("6.4", !file.exists());
- assertTrue("6.5", projectLocation.toFile().exists());
- assertTrue("6.6", fileLocation.toFile().exists());
-}
-
-
-public void testProjectLocationValidation() {
-
- // validation of the initial project should be ok
- IProject project1 = getWorkspace().getRoot().getProject("Project1");
- IPath root = getWorkspace().getRoot().getLocation().removeLastSegments(1).append("temp");
- IPath path = root.append("foo");
- assertTrue("1.0", getWorkspace().validateProjectLocation(project1, path).isOK());
- // but not if its in the default default area
- path = Platform.getLocation().append(project1.getName());
- assertTrue("1.1", !getWorkspace().validateProjectLocation(project1, path).isOK());
- // create the first project with its default default mapping
- try {
- project1.create(getMonitor());
- } catch (CoreException e) {
- fail("1.2", e);
- }
-
- // create the second project with a non-default mapping
- IProjectDescription desc = getWorkspace().newProjectDescription("Project2");
- IProject project2 = getWorkspace().getRoot().getProject("Project2");
- path = root.append("project2");
- assertTrue("2.0", getWorkspace().validateProjectLocation(project2, path).isOK());
- desc.setLocation(path);
- try {
- project2.create(desc, getMonitor());
- } catch (CoreException e) {
- fail("2.1", e);
- }
-
- // create a third project with the default default location
- IProject project3 = getWorkspace().getRoot().getProject("Project3");
- try {
- project3.create(getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
- // it should be ok to re-set a current project's location.
- path = root.append("project3");
- assertTrue("3.1", getWorkspace().validateProjectLocation(project3, path).isOK());
-
- // other cases
- assertTrue("4.0", !getWorkspace().validateProjectLocation(project3, root).isOK());
- assertTrue("4.1", !getWorkspace().validateProjectLocation(project3, root.append("project2")).isOK());
- assertTrue("4.2", !getWorkspace().validateProjectLocation(project3, root.append("project2/foo")).isOK());
- assertTrue("4.3", getWorkspace().validateProjectLocation(project3, null).isOK());
-
- try {
- project1.delete(true, getMonitor());
- project2.delete(true, getMonitor());
- project3.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("20.1", e);
- }
-}
-public void testProjectMoveContent() {
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- String[] children = new String[] { "/1/", "/1/2" };
- IResource[] resources = buildResources(project, children);
- ensureExistsInWorkspace(project, true);
- ensureExistsInWorkspace(resources, true);
- Set pathsToDelete = new HashSet(5);
-
- try {
- // move the project content
- IProjectDescription destination = null;
- try {
- destination = project.getDescription();
- } catch (CoreException e) {
- fail("1.0", e);
- }
- IPath oldPath = project.getLocation();
- IPath newPath = new Path(System.getProperty("user.dir")).append(Long.toString(System.currentTimeMillis()));
- pathsToDelete.add(newPath);
- destination.setLocation(newPath);
- try {
- project.move(destination, false, getMonitor());
- } catch (CoreException e) {
- fail("1.1", e);
- }
- newPath = project.getLocation();
-
- // ensure that the new description was set correctly and the locations
- // aren't the same
- assertTrue("2.0", !oldPath.equals(newPath));
-
- // make sure all the resources still exist.
- IResourceVisitor visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- assertExistsInWorkspace("2.1." + resource.getFullPath(), resource);
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor);
- } catch (CoreException e) {
- fail("2.2", e);
- }
- } finally {
- for (Iterator i=pathsToDelete.iterator(); i.hasNext();) {
- Workspace.clear(((IPath) i.next()).toFile());
- }
- }
-}
-public void testProjectMoveVariations() {
- IProject project, destProject;
- IResource[] resources;
- IResource destination, source, sourceChild, destChild;
- String[] children;
- IMarker[] markers = null;
- String actual = null;
- QualifiedName qname = new QualifiedName("com.example", "myProperty");
- String value = "this is my property value.";
-
- // rename a project via the move(IPath) API
- project = getWorkspace().getRoot().getProject("SourceProject");
- source = project;
- children = new String[] { "/1/", "/1/2" };
- resources = buildResources(project, children);
- ensureExistsInWorkspace(project, true);
- ensureExistsInWorkspace(resources, true);
- destination = getWorkspace().getRoot().getProject("DestProject");
- assertDoesNotExistInWorkspace("1.0", destination);
- // set a property to move
- sourceChild = resources[1];
- try {
- sourceChild.setPersistentProperty(qname, value);
- } catch (CoreException e) {
- fail("1.1", e);
- }
- // create a marker to be moved
- try {
- sourceChild.createMarker(IMarker.PROBLEM);
- } catch (CoreException e) {
- fail("1.2", e);
- }
- try {
- source.move(destination.getFullPath(), false, getMonitor());
- } catch (CoreException e) {
- fail("1.3", e);
- }
- assertDoesNotExistInWorkspace("1.4", project);
- assertDoesNotExistInWorkspace("1.5", resources);
- resources = buildResources((IProject) destination, children);
- assertExistsInWorkspace("1.6", destination);
- assertExistsInWorkspace("1.7", resources);
- // ensure properties are moved too
- destChild = resources[1];
- try {
- actual = destChild.getPersistentProperty(qname);
- } catch (CoreException e) {
- fail("1.6", e);
- }
- assertNotNull("1.7", actual);
- assertEquals("1.8", value, actual);
- // ensure the marker was moved
- try {
- markers = destChild.findMarkers(null, true, IResource.DEPTH_ZERO);
- } catch (CoreException e) {
- fail("1.9", e);
- }
- assertEquals("1.10", 1, markers.length);
- // cleanup
- try {
- getWorkspace().getRoot().delete(false, getMonitor());
- } catch (CoreException e) {
- fail("1.11", e);
- }
-
- // rename a project via the move(IProjectDescription) API
- project = getWorkspace().getRoot().getProject("SourceProject");
- source = project;
- children = new String[] { "/1/", "/1/2" };
- resources = buildResources(project, children);
- ensureExistsInWorkspace(project, true);
- ensureExistsInWorkspace(resources, true);
- // set a property to move
- sourceChild = resources[1];
- try {
- sourceChild.setPersistentProperty(qname, value);
- } catch (CoreException e) {
- fail("2.1", e);
- }
- // create a marker to be moved
- try {
- sourceChild.createMarker(IMarker.PROBLEM);
- } catch (CoreException e) {
- fail("2.2", e);
- }
- destination = getWorkspace().getRoot().getProject("DestProject");
- IProjectDescription description = getWorkspace().newProjectDescription(destination.getName());
- assertDoesNotExistInWorkspace("2.3", destination);
- try {
- ((IProject) source).move(description, false, getMonitor());
- } catch (CoreException e) {
- fail("2.4", e);
- }
- assertDoesNotExistInWorkspace("2.5", project);
- assertDoesNotExistInWorkspace("2.6", resources);
- resources = buildResources((IProject) destination, children);
- assertExistsInWorkspace("2.7", destination);
- assertExistsInWorkspace("2.8", resources);
- // ensure properties are moved too
- destChild = resources[1];
- try {
- actual = destChild.getPersistentProperty(qname);
- } catch (CoreException e) {
- fail("2.9", e);
- }
- assertNotNull("2.10", actual);
- assertEquals("2.11", value, actual);
- // ensure the marker was moved
- try {
- markers = destChild.findMarkers(null, true, IResource.DEPTH_ZERO);
- } catch (CoreException e) {
- fail("2.12", e);
- }
- assertEquals("2.13", 1, markers.length);
- // cleanup
- try {
- getWorkspace().getRoot().delete(false, getMonitor());
- } catch (CoreException e) {
- fail("2.14", e);
- }
-
- // create the source project, move it to a be a folder under another project,
- // This is no longer allowed so ignore the error.
- project = getWorkspace().getRoot().getProject("SourceProject");
- source = project;
- destProject = getWorkspace().getRoot().getProject("DestProject");
- destination = destProject.getFolder("MyFolder");
- try {
- source.move(destination.getFullPath(), true, getMonitor());
- fail("3.3");
- } catch (CoreException e) {
- }
-
- // create a source folder and move it to be a project.
- // This is no longer allowed so ignore the error.
- project = getWorkspace().getRoot().getProject("MySourceProject");
- children = new String[] { "/1/", "/1/2" };
- source = project.getFolder("1");
- resources = buildResources(project, children);
- destination = getWorkspace().getRoot().getProject("MyDestProject");
- try {
- source.move(destination.getFullPath(), true, getMonitor());
- fail("4.3");
- } catch (CoreException e) {
- }
-}
-public void testProjectReferences() {
- IProject target = getWorkspace().getRoot().getProject("Project1");
- ensureExistsInWorkspace(target, true);
-
- IProject project = getWorkspace().getRoot().getProject("Project2");
- ensureExistsInWorkspace(project, true);
-
- try {
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- IProjectDescription description = null;
- try {
- description = project.getDescription();
- } catch (CoreException e) {
- fail("1.0", e);
- }
- description.setReferencedProjects(new IProject[] { target });
- try {
- project.setDescription(description, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
- assertTrue("2.1", target.getReferencingProjects().length == 1);
-
- //get references for a non-existent project
- try {
- getWorkspace().getRoot().getProject("DoesNotExist").getReferencedProjects();
- fail("3.0");
- } catch (CoreException e1) {
- //should fail
- }
-}
-public void testSetGetProjectPersistentProperty() {
- IProject target = getWorkspace().getRoot().getProject("Project");
- ensureExistsInWorkspace(target, true);
- try {
- setGetPersistentProperty(target);
- } catch (CoreException e) {
- fail("1.0", e);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceChangeEventTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceChangeEventTest.java
deleted file mode 100644
index 795737d..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceChangeEventTest.java
+++ /dev/null
@@ -1,230 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-/**
- * This class tests the public API of IResourceChangeEvent.
- */
-public class IResourceChangeEventTest extends EclipseWorkspaceTest {
- /* some random resource handles */
- protected IProject project1;
- protected IProject project2;
- protected IFolder folder1;//below project2
- protected IFolder folder2;//below folder1
- protected IFolder folder3;//same as file1
- protected IFile file1;//below folder1
- protected IFile file2;//below folder1
- protected IFile file3;//below folder2
- protected IMarker marker1;//on file1
- protected IMarker marker2;//on file1
- protected IMarker marker3;//on file1
-
- protected IResource[] allResources;
-public IResourceChangeEventTest() {
-}
-public IResourceChangeEventTest(String name) {
- super(name);
-}
-/**
- * Sets up the fixture, for example, open a network connection.
- * This method is called before a test is executed.
- */
-protected void setUp() throws Exception {
- super.setUp();
-
- // Create some resource handles
- project1 = getWorkspace().getRoot().getProject("Project" + 1);
- project2 = getWorkspace().getRoot().getProject("Project" + 2);
- folder1 = project1.getFolder("Folder" + 1);
- folder2 = folder1.getFolder("Folder" + 2);
- folder3 = folder1.getFolder("Folder" + 3);
- file1 = folder1.getFile("File" + 1);
- file2 = folder1.getFile("File" + 2);
- file3 = folder2.getFile("File" + 3);
- allResources = new IResource[] {project1, project2,
- folder1, folder2, folder3, file1, file2, file3};
-
- // Create and open the resources
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- ensureExistsInWorkspace(allResources, true);
- marker2 = file2.createMarker(IMarker.BOOKMARK);
- marker3 = file3.createMarker(IMarker.BOOKMARK);
- }
- };
- try {
- getWorkspace().run(body, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-}
-public static Test suite() {
- return new TestSuite(IResourceChangeEventTest.class);
-}
-/**
- * Tears down the fixture, for example, close a network connection.
- * This method is called after a test is executed.
- */
-protected void tearDown() throws Exception {
- super.tearDown();
- ensureDoesNotExistInWorkspace(getWorkspace().getRoot());
-}
-/**
- * Tests the IResourceChangeEvent#findMarkerDeltas method.
- */
-public void testFindMarkerDeltas() {
- /*
- * The following changes will occur:
- * - add marker1
- * - remove marker2
- * - change marker3
- */
- IResourceChangeListener listener = new IResourceChangeListener() {
- public void resourceChanged(IResourceChangeEvent event) {
- //bookmark type, no subtypes
- IMarkerDelta[] deltas = event.findMarkerDeltas(IMarker.BOOKMARK, false);
- verifyDeltas(deltas);
-
- //bookmark type, with subtypes
- deltas = event.findMarkerDeltas(IMarker.BOOKMARK, true);
- verifyDeltas(deltas);
-
- //marker type, no subtypes
- deltas = event.findMarkerDeltas(IMarker.MARKER, false);
- assertNotNull("10.0", deltas);
- assertTrue("10.1", deltas.length == 0);
-
- //marker type, with subtypes
- deltas = event.findMarkerDeltas(IMarker.MARKER, true);
- verifyDeltas(deltas);
-
- //problem type, with subtypes
- deltas = event.findMarkerDeltas(IMarker.PROBLEM, true);
- assertNotNull("12.0", deltas);
- assertTrue("12.1", deltas.length == 0);
-
- //all types, include subtypes
- deltas = event.findMarkerDeltas(null, true);
- verifyDeltas(deltas);
-
- //all types, no subtypes
- deltas = event.findMarkerDeltas(null, false);
- verifyDeltas(deltas);
- }
- };
- getWorkspace().addResourceChangeListener(listener);
-
- //do the work
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- marker1 = file1.createMarker(IMarker.BOOKMARK);
- marker2.delete();
- marker3.setAttribute("Foo", true);
- }
- };
- try {
- getWorkspace().run(body, getMonitor());
- } catch (CoreException e) {
- fail("Exception1", e);
- } finally {
- getWorkspace().removeResourceChangeListener(listener);
- }
-}
-public void testFindMarkerDeltasInEmptyDelta() {
- /*
- * The following changes will occur:
- * - change file1
- */
- IResourceChangeListener listener = new IResourceChangeListener() {
- public void resourceChanged(IResourceChangeEvent event) {
- //bookmark type, no subtypes
- IMarkerDelta[] deltas = event.findMarkerDeltas(IMarker.BOOKMARK, false);
- assertNotNull("1.0", deltas);
- assertTrue("1.1", deltas.length == 0);
-
- //bookmark type, with subtypes
- deltas = event.findMarkerDeltas(IMarker.BOOKMARK, true);
- assertNotNull("2.0", deltas);
- assertTrue("2.1", deltas.length == 0);
-
- //marker type, no subtypes
- deltas = event.findMarkerDeltas(IMarker.MARKER, false);
- assertNotNull("3.0", deltas);
- assertTrue("3.1", deltas.length == 0);
-
- //marker type, with subtypes
- deltas = event.findMarkerDeltas(IMarker.MARKER, true);
- assertNotNull("4.0", deltas);
- assertTrue("4.1", deltas.length == 0);
-
- //problem type, with subtypes
- deltas = event.findMarkerDeltas(IMarker.PROBLEM, true);
- assertNotNull("5.0", deltas);
- assertTrue("5.1", deltas.length == 0);
-
- //all types, include subtypes
- deltas = event.findMarkerDeltas(null, true);
- assertNotNull("6.0", deltas);
- assertTrue("6.1", deltas.length == 0);
-
- //all types, no subtypes
- deltas = event.findMarkerDeltas(null, false);
- assertNotNull("7.0", deltas);
- assertTrue("7.1", deltas.length == 0);
- }
- };
- getWorkspace().addResourceChangeListener(listener);
-
- //do the work
- try {
- file1.setContents(getRandomContents(), true, true, getMonitor());
- } catch (CoreException e) {
- fail("Exception2", e);
- } finally {
- getWorkspace().removeResourceChangeListener(listener);
- }
-}
-/**
- * Verifies that the marker deltas have the right changes.
- */
-protected void verifyDeltas(IMarkerDelta[] deltas) {
- assertNotNull("1.0", deltas);
- assertTrue("1.1", deltas.length == 3);
- //delta order is not defined..
- boolean found1 = false, found2 = false, found3 = false;
- for (int i = 0; i < deltas.length; i++) {
- assertTrue("kind" + i, deltas[i].getType().equals(IMarker.BOOKMARK));
- long id = deltas[i].getId();
- if (id == marker1.getId()) {
- found1 = true;
- assertTrue("2.0", deltas[i].getKind() == IResourceDelta.ADDED);
- } else if (id == marker2.getId()) {
- found2 = true;
- assertTrue("3.0", deltas[i].getKind() == IResourceDelta.REMOVED);
- } else if (id == marker3.getId()) {
- found3 = true;
- assertTrue("4.0", deltas[i].getKind() == IResourceDelta.CHANGED);
- } else {
- assertTrue("4.99", false);
- }
- }
- assertTrue("5.0", found1);
- assertTrue("5.1", found2);
- assertTrue("5.2", found3);
-}
-}
-
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceChangeListenerTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceChangeListenerTest.java
deleted file mode 100644
index 2e6153f..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceChangeListenerTest.java
+++ /dev/null
@@ -1,1291 +0,0 @@
-/*******************************************************************************
- * 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
- * tammo.freese@offis.de - tests for swapping files and folders
- ******************************************************************************/
-package org.eclipse.core.tests.resources;
-
-import java.io.ByteArrayInputStream;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.resources.Workspace;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-public class IResourceChangeListenerTest extends EclipseWorkspaceTest {
-
- protected static final String VERIFIER_NAME = "TestListener";
- IFile file1; //below folder1
- IFile file2; //below folder1
- IFile file3; //below folder2
- IFolder folder1; //below project2
- IFolder folder2; //below folder1
- IFolder folder3; //same as file1
-
- /* some random resource handles */
- IProject project1;
- IFile project1MetaData;
- IProject project2;
- IFile project2MetaData;
- ResourceDeltaVerifier verifier;
- public static Test suite() {
- // TestSuite suite = new TestSuite();
- // suite.addTest(new IResourceChangeListenerTest("testMoveProject1"));
- // return suite;
-
- return new TestSuite(IResourceChangeListenerTest.class);
- }
- public IResourceChangeListenerTest() {
- }
- public IResourceChangeListenerTest(String name) {
- super(name);
- }
- public void _testBenchMark_1GBYQEZ() {
- // start with a clean workspace
- getWorkspace().removeResourceChangeListener(verifier);
- try {
- getWorkspace().getRoot().delete(false, getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- // create the listener
- IResourceChangeListener listener = new IResourceChangeListener() {
- public int fCounter;
- public void resourceChanged(IResourceChangeEvent event) {
- try {
- System.out.println("Start");
- for (int i = 0; i < 10; i++) {
- fCounter = 0;
- long start = System.currentTimeMillis();
- IResourceDelta delta = event.getDelta();
- delta.accept(new IResourceDeltaVisitor() {
- public boolean visit(IResourceDelta delta2) throws CoreException {
- fCounter++;
- return true;
- }
- });
- long end = System.currentTimeMillis();
- System.out.println(" Number of deltas: " + fCounter + ". Time needed: " + (end - start));
- }
- System.out.println("End");
- } catch (CoreException e) {
- fail("1.0", e);
- }
- }
- };
-
- // add the listener
- getWorkspace().addResourceChangeListener(listener);
-
- // setup the test data
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- IProject project = getWorkspace().getRoot().getProject("Test");
- IProjectDescription description = getWorkspace().newProjectDescription(project.getName());
- IPath root = getWorkspace().getRoot().getLocation();
- IPath contents = root.append("temp/testing");
- description.setLocation(contents);
- project.create(description, getMonitor());
- project.open(getMonitor());
- project.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- }
- };
- try {
- getWorkspace().run(body, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- // touch all resources (so that they appear in the delta)
- body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- IResourceVisitor visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- resource.touch(getMonitor());
- return true;
- }
- };
- getWorkspace().getRoot().accept(visitor);
- }
- };
- try {
- getWorkspace().run(body, getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
-
- // un-register our listener
- getWorkspace().removeResourceChangeListener(listener);
- }
- /**
- * Tests that the builder is receiving an appropriate delta
- * @see SortBuilderPlugin
- * @see SortBuilder
- */
- public void assertDelta() {
- assertTrue(verifier.getMessage(), verifier.isDeltaValid());
- }
- /**
- * Asserts that a manual traversal of the delta does not find the given resources.
- */
- void assertNotDeltaIncludes(String message, IResourceDelta delta, IResource[] resources) {
- try {
- IResource deltaResource = delta.getResource();
- for (int i = 0; i < resources.length; i++) {
- assertTrue(message, !deltaResource.equals(resources[i]));
- }
- IResourceDelta[] children = delta.getAffectedChildren();
- for (int i = 0; i < children.length; i++) {
- assertNotDeltaIncludes(message, children[i], resources);
- }
- } catch (RuntimeException e) {
- fail(message, e);
- }
- }
- /**
- * Asserts that a visitor traversal of the delta does not find the given resources.
- */
- void assertNotDeltaVisits(final String message, IResourceDelta delta, final IResource[] resources) {
- try {
- delta.accept(new IResourceDeltaVisitor() {
- public boolean visit(IResourceDelta delta2) throws CoreException {
- IResource deltaResource = delta2.getResource();
- for (int i = 0; i < resources.length; i++) {
- assertTrue(message, !deltaResource.equals(resources[i]));
- }
- return true;
- }
- });
- } catch (CoreException e) {
- fail(message, e);
- } catch (RuntimeException e) {
- fail(message, e);
- }
- }
- /**
- * Runs code to handle a core exception
- */
- protected void handleCoreException(CoreException e) {
- assertTrue("CoreException: " + e.getMessage(), false);
- }
- /**
- * Sets up the fixture, for example, open a network connection.
- * This method is called before a test is executed.
- */
- protected void setUp() throws Exception {
- super.setUp();
-
- // Create some resource handles
- project1 = getWorkspace().getRoot().getProject("Project" + 1);
- project2 = getWorkspace().getRoot().getProject("Project" + 2);
- folder1 = project1.getFolder("Folder" + 1);
- folder2 = folder1.getFolder("Folder" + 2);
- folder3 = folder1.getFolder("File" + 1);
- file1 = folder1.getFile("File" + 1);
- file2 = folder1.getFile("File" + 2);
- file3 = folder2.getFile("File" + 1);
- project1MetaData = project1.getFile(IProjectDescription.DESCRIPTION_FILE_NAME);
- project2MetaData = project2.getFile(IProjectDescription.DESCRIPTION_FILE_NAME);
-
- // Create and open a project, folder and file
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- project1.create(getMonitor());
- project1.open(getMonitor());
- folder1.create(true, true, getMonitor());
- file1.create(getRandomContents(), true, getMonitor());
- }
- };
- verifier = new ResourceDeltaVerifier();
- getWorkspace().addResourceChangeListener(verifier, IResourceChangeEvent.POST_CHANGE);
- try {
- getWorkspace().run(body, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
- verifier.reset();
- }
- /**
- * Tears down the fixture, for example, close a network connection.
- * This method is called after a test is executed.
- */
- protected void tearDown() throws Exception {
- super.tearDown();
- ensureDoesNotExistInWorkspace(getWorkspace().getRoot());
- getWorkspace().removeResourceChangeListener(verifier);
- }
- /*
- * Create a resource change listener and register it for POST_AUTO_BUILD events.
- * Ensure that you are able to modify the workspace tree.
- */
- public void test_1GDK9OG() {
- // create the resource change listener
- IResourceChangeListener listener = new IResourceChangeListener() {
- public void resourceChanged(final IResourceChangeEvent event) {
- try {
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- // modify the tree.
- IResourceDeltaVisitor visitor = new IResourceDeltaVisitor() {
- public boolean visit(IResourceDelta delta) throws CoreException {
- IResource resource = delta.getResource();
- try {
- resource.touch(getMonitor());
- } catch (RuntimeException e) {
- throw e;
- }
- resource.createMarker(IMarker.PROBLEM);
- return true;
- }
- };
- event.getDelta().accept(visitor);
- }
- };
- getWorkspace().run(body, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
- }
- };
- // register the listener with the workspace.
- getWorkspace().addResourceChangeListener(listener, IResourceChangeEvent.POST_AUTO_BUILD);
- try {
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- // cause a delta by touching all resources
- final IResourceVisitor visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- resource.touch(getMonitor());
- return true;
- }
- };
- public void run(IProgressMonitor monitor) throws CoreException {
- getWorkspace().getRoot().accept(visitor);
- }
- };
- getWorkspace().run(body, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- } finally {
- // cleanup: ensure that the listener is removed
- getWorkspace().removeResourceChangeListener(listener);
- }
- }
- /*
- * Create a resource change listener and register it for POST_CHANGE events.
- * Ensure that you are NOT able to modify the workspace tree.
- */
- public void testBug45996() {
- // create the resource change listener
- IResourceChangeListener listener = new IResourceChangeListener() {
- public void resourceChanged(final IResourceChangeEvent event) {
- boolean failed = false;
- try {
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- // modify the tree.
- IResourceDeltaVisitor visitor = new IResourceDeltaVisitor() {
- public boolean visit(IResourceDelta delta) throws CoreException {
- IResource resource = delta.getResource();
- try {
- resource.touch(getMonitor());
- } catch (RuntimeException e) {
- throw e;
- }
- resource.createMarker(IMarker.PROBLEM);
- return true;
- }
- };
- event.getDelta().accept(visitor);
- }
- };
- getWorkspace().run(body, getMonitor());
- } catch (CoreException e) {
- //should fail
- failed = true;
- }
- assertTrue("1.0", failed);
-
- }
- };
- // register the listener with the workspace.
- getWorkspace().addResourceChangeListener(listener, IResourceChangeEvent.POST_CHANGE);
- try {
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- // cause a delta by touching all resources
- final IResourceVisitor visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- resource.touch(getMonitor());
- return true;
- }
- };
- public void run(IProgressMonitor monitor) throws CoreException {
- getWorkspace().getRoot().accept(visitor);
- }
- };
- getWorkspace().run(body, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- } finally {
- // cleanup: ensure that the listener is removed
- getWorkspace().removeResourceChangeListener(listener);
- }
- }
- public void testAddAndRemoveFile() {
- try {
- verifier.reset();
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor m) throws CoreException {
- m.beginTask("Creating and deleting", 100);
- try {
- file2.create(getRandomContents(), true, new SubProgressMonitor(m, 50));
- file2.delete(true, new SubProgressMonitor(m, 50));
- } finally {
- m.done();
- }
- }
- }, getMonitor());
- //should not have been verified since there was no change
- assertTrue("Unexpected notification on no change", !verifier.hasBeenNotified());
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
- public void testAddAndRemoveFolder() {
- try {
- verifier.reset();
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor m) throws CoreException {
- m.beginTask("Creating and deleting", 100);
- try {
- folder2.create(true, true, new SubProgressMonitor(m, 50));
- folder2.delete(true, new SubProgressMonitor(m, 50));
- } finally {
- m.done();
- }
- }
- }, getMonitor());
- //should not have been verified since there was no change
- assertTrue("Unexpected notification on no change", !verifier.hasBeenNotified());
-
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
- public void testAddFile() {
- try {
- verifier.addExpectedChange(file2, IResourceDelta.ADDED, 0);
- file2.create(getRandomContents(), true, getMonitor());
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
- public void testAddFileAndFolder() {
- try {
- verifier.addExpectedChange(folder2, IResourceDelta.ADDED, 0);
- verifier.addExpectedChange(file3, IResourceDelta.ADDED, 0);
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor m) throws CoreException {
- m.beginTask("Creating folder and file", 100);
- try {
- folder2.create(true, true, new SubProgressMonitor(m, 50));
- file3.create(getRandomContents(), true, new SubProgressMonitor(m, 50));
- } finally {
- m.done();
- }
- }
- }, getMonitor());
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
- public void testAddFolder() {
- try {
- verifier.addExpectedChange(folder2, IResourceDelta.ADDED, 0);
- folder2.create(true, true, getMonitor());
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
- public void testAddProject() {
- try {
- verifier.addExpectedChange(project2, IResourceDelta.ADDED, 0);
- verifier.addExpectedChange(project2MetaData, IResourceDelta.ADDED, 0);
- project2.create(getMonitor());
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
- public void testChangeFile() {
- try {
- /* change file1's contents */
- verifier.addExpectedChange(file1, IResourceDelta.CHANGED, IResourceDelta.CONTENT);
- file1.setContents(getRandomContents(), true, false, getMonitor());
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
- public void testChangeFileToFolder() {
- try {
- /* change file1 into a folder */
- verifier.addExpectedChange(file1, IResourceDelta.CHANGED, IResourceDelta.CONTENT | IResourceDelta.TYPE | IResourceDelta.REPLACED);
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor m) throws CoreException {
- m.beginTask("Deleting and Creating", 100);
- try {
- file1.delete(true, new SubProgressMonitor(m, 50));
- folder3.create(true, true, new SubProgressMonitor(m, 50));
- } finally {
- m.done();
- }
- }
- }, getMonitor());
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
- public void testChangeFolderToFile() {
- try {
- /* change to a folder */
- verifier.reset();
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor m) throws CoreException {
- file1.delete(true, getMonitor());
- folder3.create(true, true, getMonitor());
- }
- }, null);
-
- /* now change back to a file and verify */
- verifier.addExpectedChange(file1, IResourceDelta.CHANGED, IResourceDelta.CONTENT | IResourceDelta.TYPE | IResourceDelta.REPLACED);
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor m) throws CoreException {
- m.beginTask("Deleting and Creating", 100);
- try {
- folder3.delete(true, new SubProgressMonitor(m, 50));
- file1.create(getRandomContents(), true, new SubProgressMonitor(m, 50));
- } finally {
- m.done();
- }
- }
- }, getMonitor());
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
- public void testChangeProject() {
- try {
- verifier.reset();
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor m) throws CoreException {
- project2.create(getMonitor());
- project2.open(getMonitor());
- }
- }, null);
-
- IProjectDescription desc = project2.getDescription();
- desc.setReferencedProjects(new IProject[] { project1 });
- verifier.addExpectedChange(project2, IResourceDelta.CHANGED, IResourceDelta.DESCRIPTION);
- verifier.addExpectedChange(project2MetaData, IResourceDelta.CHANGED, IResourceDelta.CONTENT);
- project2.setDescription(desc, IResource.FORCE, getMonitor());
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
- public void testCloseOpenReplaceFile() {
- try {
- // FIXME: how to do this?
- //workspace.save(getMonitor());
- //workspace.close(getMonitor());
- //workspace.open(getMonitor());
- verifier.reset();
- getWorkspace().addResourceChangeListener(verifier);
-
- /* change file1's contents */
- verifier.addExpectedChange(file1, IResourceDelta.CHANGED, IResourceDelta.REPLACED | IResourceDelta.CONTENT);
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor m) throws CoreException {
- m.beginTask("Deleting and Creating", 100);
- try {
- file1.delete(true, new SubProgressMonitor(m, 50));
- file1.create(getRandomContents(), true, new SubProgressMonitor(m, 50));
- } finally {
- m.done();
- }
- }
- }, getMonitor());
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
- public void testDeleteInPostBuildListener() {
- // create the resource change listener
- IResourceChangeListener listener = new IResourceChangeListener() {
- public void resourceChanged(final IResourceChangeEvent event) {
- try {
- event.getDelta().accept(new IResourceDeltaVisitor() {
- public boolean visit(IResourceDelta delta) throws CoreException {
- IResource resource = delta.getResource();
- if (resource.getType() == IResource.FILE) {
- try {
- ((IFile) resource).delete(true, true, null);
- } catch (RuntimeException e) {
- throw e;
- }
- }
- return true;
- }
- });
- } catch (CoreException e) {
- fail("1.0", e);
- }
- }
- };
- // register the listener with the workspace.
- getWorkspace().addResourceChangeListener(listener, IResourceChangeEvent.POST_AUTO_BUILD);
- try {
- getWorkspace().run(new IWorkspaceRunnable() {
- // cause a delta by touching all resources
- public void run(IProgressMonitor monitor) throws CoreException {
- getWorkspace().getRoot().accept(new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- resource.touch(getMonitor());
- return true;
- }
- });
- }
- }, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- } finally {
- // cleanup: ensure that the listener is removed
- getWorkspace().removeResourceChangeListener(listener);
- }
- }
- /**
- * Tests deleting a file, then moving another file to that deleted location.
- * See bug 27527.
- */
- public void testDeleteMoveFile() {
- try {
- verifier.reset();
- file2.create(getRandomContents(), IResource.NONE, getMonitor());
- verifier.reset();
- int flags = IResourceDelta.REPLACED | IResourceDelta.MOVED_FROM | IResourceDelta.CONTENT;
- verifier.addExpectedChange(file1, IResourceDelta.CHANGED, flags, file2.getFullPath(), null);
- verifier.addExpectedChange(file2, IResourceDelta.REMOVED, IResourceDelta.MOVED_TO, null, file1.getFullPath());
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor m) throws CoreException {
- m.beginTask("deleting and moving", 100);
- try {
- file1.delete(IResource.NONE, new SubProgressMonitor(m, 50));
- file2.move(file1.getFullPath(), IResource.NONE, new SubProgressMonitor(m, 50));
- } finally {
- m.done();
- }
- }
- }, getMonitor());
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
- public void testDeleteProject() throws CoreException {
- //test that marker deltas are fired when projects are deleted
- verifier.reset();
- final IMarker marker = project1.createMarker(IMarker.TASK);
- class Listener1 implements IResourceChangeListener {
- public boolean done = false;
- public void resourceChanged(IResourceChangeEvent event) {
- done = true;
- IMarkerDelta[] deltas = event.findMarkerDeltas(IMarker.TASK, false);
- assertEquals("1.0", 1, deltas.length);
- assertEquals("1.1", marker.getId(), deltas[0].getId());
- assertEquals("1.2", IResourceDelta.REMOVED, deltas[0].getKind());
- synchronized (this) {
- notifyAll();
- }
- }
- };
- Listener1 listener = new Listener1();
- try {
- getWorkspace().addResourceChangeListener(listener, IResourceChangeEvent.POST_CHANGE);
- project1.delete(true, false, getMonitor());
- synchronized (listener) {
- int i = 0;
- while (!listener.done) {
- try {
- listener.wait(1000);
- } catch (InterruptedException e) {
- }
- assertTrue("2.0", ++i < 60);
- }
- }
- } finally {
- getWorkspace().removeResourceChangeListener(listener);
- }
- }
- /**
- * Tests that phantom members don't show up in resource deltas when
- * standard traversal and visitor are used.
- */
- public void testHiddenPhantomChanges() {
- final IWorkspace workspace = getWorkspace();
- final IFolder phantomFolder = project1.getFolder("PhantomFolder");
- final IFile phantomFile = folder1.getFile("PhantomFile");
- final IResource[] phantomResources = new IResource[] { phantomFolder, phantomFile };
- final QualifiedName partner = new QualifiedName("Test", "Infected");
- IResourceChangeListener listener = new IResourceChangeListener() {
- public void resourceChanged(IResourceChangeEvent event) {
- //make sure the delta doesn't include the phantom members
- assertNotDeltaIncludes("1.0", event.getDelta(), phantomResources);
- //make sure a visitor does not find phantom members
- assertNotDeltaVisits("1.1", event.getDelta(), phantomResources);
- }
- };
- workspace.addResourceChangeListener(listener);
- workspace.getSynchronizer().add(partner);
- ensureDoesNotExistInWorkspace(phantomResources);
- try {
- //create a phantom folder
- workspace.run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- workspace.getSynchronizer().setSyncInfo(partner, phantomFolder, new byte[] {1});
- }
- }, getMonitor());
- //create children in phantom folder
- IFile fileInFolder = phantomFolder.getFile("FileInPrivateFolder");
- workspace.getSynchronizer().setSyncInfo(partner, fileInFolder, new byte[] {1});
- //modify children in phantom folder
- workspace.getSynchronizer().setSyncInfo(partner, fileInFolder, new byte[] {2});
- //delete children in phantom folder
- workspace.getSynchronizer().flushSyncInfo(partner, fileInFolder, IResource.DEPTH_INFINITE);
- //delete phantom folder and change some other file
- workspace.run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- phantomFolder.delete(IResource.NONE, getMonitor());
- file1.setContents(getRandomContents(), IResource.NONE, getMonitor());
- }
- }, getMonitor());
- //create phantom file
- workspace.run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- workspace.getSynchronizer().setSyncInfo(partner, phantomFile, new byte[] {2});
- }
- }, getMonitor());
- //modify phantom file
- workspace.getSynchronizer().setSyncInfo(partner, phantomFile, new byte[] {3});
- //delete phantom file
- workspace.getSynchronizer().flushSyncInfo(partner, phantomFile, IResource.DEPTH_INFINITE);
- } catch (CoreException e) {
- handleCoreException(e);
- } finally {
- workspace.removeResourceChangeListener(listener);
- }
- }
- /**
- * Tests that team private members don't show up in resource deltas when
- * standard traversal and visitor are used.
- */
- public void testHiddenTeamPrivateChanges() {
- IWorkspace workspace = getWorkspace();
- final IFolder teamPrivateFolder = project1.getFolder("TeamPrivateFolder");
- final IFile teamPrivateFile = folder1.getFile("TeamPrivateFile");
- final IResource[] privateResources = new IResource[] { teamPrivateFolder, teamPrivateFile };
- IResourceChangeListener listener = new IResourceChangeListener() {
- public void resourceChanged(IResourceChangeEvent event) {
- //make sure the delta doesn't include the team private members
- assertNotDeltaIncludes("1.0", event.getDelta(), privateResources);
- //make sure a visitor does not find team private members
- assertNotDeltaVisits("1.1", event.getDelta(), privateResources);
- }
- };
- workspace.addResourceChangeListener(listener);
- try {
- //create a team private folder
- workspace.run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- teamPrivateFolder.create(true, true, getMonitor());
- teamPrivateFolder.setTeamPrivateMember(true);
- }
- }, getMonitor());
- //create children in team private folder
- IFile fileInFolder = teamPrivateFolder.getFile("FileInPrivateFolder");
- fileInFolder.create(getRandomContents(), true, getMonitor());
- //modify children in team private folder
- fileInFolder.setContents(getRandomContents(), IResource.NONE, getMonitor());
- //delete children in team private folder
- fileInFolder.delete(IResource.NONE, getMonitor());
- //delete team private folder and change some other file
- workspace.run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- teamPrivateFolder.delete(IResource.NONE, getMonitor());
- file1.setContents(getRandomContents(), IResource.NONE, getMonitor());
- }
- }, getMonitor());
- //create team private file
- workspace.run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- teamPrivateFile.create(getRandomContents(), true, getMonitor());
- teamPrivateFile.setTeamPrivateMember(true);
- }
- }, getMonitor());
- //modify team private file
- teamPrivateFile.setContents(getRandomContents(), IResource.NONE, getMonitor());
- //delete team private file
- teamPrivateFile.delete(IResource.NONE, getMonitor());
- } catch (CoreException e) {
- handleCoreException(e);
- } finally {
- workspace.removeResourceChangeListener(listener);
- }
- }
- public void testModifyMoveFile() {
- try {
- verifier.addExpectedChange(folder2, IResourceDelta.ADDED, 0);
- verifier.addExpectedChange(file1, IResourceDelta.REMOVED, IResourceDelta.MOVED_TO, null, file3.getFullPath());
- verifier.addExpectedChange(file3, IResourceDelta.ADDED, IResourceDelta.MOVED_FROM | IResourceDelta.CONTENT, file1.getFullPath(), null);
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor m) throws CoreException {
- m.beginTask("Creating and moving", 100);
- try {
- folder2.create(true, true, new SubProgressMonitor(m, 50));
- file1.setContents(getRandomContents(), IResource.NONE, getMonitor());
- file1.move(file3.getFullPath(), true, new SubProgressMonitor(m, 50));
- } finally {
- m.done();
- }
- }
- }, getMonitor());
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
- public void testMoveFile() {
- try {
- verifier.addExpectedChange(folder2, IResourceDelta.ADDED, 0);
- verifier.addExpectedChange(file1, IResourceDelta.REMOVED, IResourceDelta.MOVED_TO, null, file3.getFullPath());
- verifier.addExpectedChange(file3, IResourceDelta.ADDED, IResourceDelta.MOVED_FROM, file1.getFullPath(), null);
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor m) throws CoreException {
- m.beginTask("Creating and moving", 100);
- try {
- folder2.create(true, true, new SubProgressMonitor(m, 50));
- file1.move(file3.getFullPath(), true, new SubProgressMonitor(m, 50));
- } finally {
- m.done();
- }
- }
- }, getMonitor());
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
- /**
- * Regression test for bug 42514
- */
- public void testMoveFileDeleteFolder() {
- try {
- //file2 moved to file1, and colliding folder3 is deleted
- file1.delete(IResource.NONE, null);
- file2.create(getRandomContents(), IResource.NONE, null);
- folder3.create(IResource.NONE, true, null);
- verifier.reset();
- verifier.addExpectedChange(file2, IResourceDelta.REMOVED, IResourceDelta.MOVED_TO, null, file1.getFullPath());
- int flags = IResourceDelta.MOVED_FROM | IResourceDelta.REPLACED | IResourceDelta.TYPE | IResourceDelta.CONTENT;
- verifier.addExpectedChange(file1, IResourceDelta.CHANGED, flags, file2.getFullPath(), null);
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor m) throws CoreException {
- m.beginTask("Deleting and moving", 100);
- try {
- folder3.delete(IResource.FORCE, new SubProgressMonitor(m, 50));
- file2.move(file1.getFullPath(), true, new SubProgressMonitor(m, 50));
- } finally {
- m.done();
- }
- }
- }, getMonitor());
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
- public void testMoveFileAddMarker() {
- try {
- verifier.addExpectedChange(folder2, IResourceDelta.ADDED, 0);
- verifier.addExpectedChange(file1, IResourceDelta.REMOVED, IResourceDelta.MOVED_TO, null, file3.getFullPath());
- verifier.addExpectedChange(file3, IResourceDelta.ADDED, IResourceDelta.MOVED_FROM | IResourceDelta.MARKERS, file1.getFullPath(), null);
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor m) throws CoreException {
- m.beginTask("Creating and moving", 100);
- try {
- folder2.create(true, true, new SubProgressMonitor(m, 50));
- file1.move(file3.getFullPath(), true, new SubProgressMonitor(m, 50));
- file3.createMarker(IMarker.TASK);
- } finally {
- m.done();
- }
- }
- }, getMonitor());
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
-
- public void testMoveModifyFile() {
- try {
- verifier.addExpectedChange(folder2, IResourceDelta.ADDED, 0);
- verifier.addExpectedChange(file1, IResourceDelta.REMOVED, IResourceDelta.MOVED_TO, null, file3.getFullPath());
- verifier.addExpectedChange(file3, IResourceDelta.ADDED, IResourceDelta.MOVED_FROM | IResourceDelta.CONTENT, file1.getFullPath(), null);
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor m) throws CoreException {
- m.beginTask("Creating and moving", 100);
- try {
- folder2.create(true, true, new SubProgressMonitor(m, 50));
- file1.move(file3.getFullPath(), true, new SubProgressMonitor(m, 50));
- file3.setContents(getRandomContents(), IResource.NONE, getMonitor());
- } finally {
- m.done();
- }
- }
- }, getMonitor());
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
-
- public void testMoveMoveFile() {
- file2 = project1.getFile("File2");
- file3 = project1.getFile("File3");
-
- try {
- verifier.addExpectedChange(file1, IResourceDelta.REMOVED, IResourceDelta.MOVED_TO, null, file3.getFullPath());
- verifier.addExpectedChange(file3, IResourceDelta.ADDED, IResourceDelta.MOVED_FROM, file1.getFullPath(), null);
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor m) throws CoreException {
- m.beginTask("moving and moving file", 100);
- try {
- file1.move(file2.getFullPath(), false, null);
- file2.move(file3.getFullPath(), false, null);
- } finally {
- m.done();
- }
- }
- }, getMonitor());
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
-
- public void testMoveMoveFolder() {
- folder2 = project1.getFolder("Folder2");
- folder3 = project1.getFolder("Folder3");
- file3 = folder3.getFile(file1.getName());
-
- try {
-
- verifier.addExpectedChange(folder1, IResourceDelta.REMOVED, IResourceDelta.MOVED_TO, null, folder3.getFullPath());
- verifier.addExpectedChange(folder3, IResourceDelta.ADDED, IResourceDelta.MOVED_FROM, folder1.getFullPath(), null);
- verifier.addExpectedChange(file1, IResourceDelta.REMOVED, IResourceDelta.MOVED_TO, null, file3.getFullPath());
- verifier.addExpectedChange(file3, IResourceDelta.ADDED, IResourceDelta.MOVED_FROM, file1.getFullPath(), null);
-
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor m) throws CoreException {
- m.beginTask("moving and moving folder", 100);
- try {
- folder1.move(folder2.getFullPath(), false, null);
- folder2.move(folder3.getFullPath(), false, null);
- } finally {
- m.done();
- }
- }
- }, getMonitor());
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
- /**
- * Move a project via rename.
- * Note that the DESCRIPTION flag should be set in the delta for the
- * destination only.
- */
- public void testMoveProject1() {
- try {
- verifier.reset();
- verifier.addExpectedChange(project1, IResourceDelta.REMOVED, IResourceDelta.MOVED_TO, null, project2.getFullPath());
- verifier.addExpectedChange(project1.getFile(".project"), IResourceDelta.REMOVED, IResourceDelta.MOVED_TO, null, project2.getFile(".project").getFullPath());
- verifier.addExpectedChange(folder1, IResourceDelta.REMOVED, IResourceDelta.MOVED_TO, null, project2.getFolder(folder1.getProjectRelativePath()).getFullPath());
- verifier.addExpectedChange(file1, IResourceDelta.REMOVED, IResourceDelta.MOVED_TO, null, project2.getFile(file1.getProjectRelativePath()).getFullPath());
-
- verifier.addExpectedChange(project2, IResourceDelta.ADDED, IResourceDelta.OPEN | IResourceDelta.DESCRIPTION | IResourceDelta.MOVED_FROM, project1.getFullPath(), null);
- verifier.addExpectedChange(project2.getFile(".project"), IResourceDelta.ADDED, IResourceDelta.CONTENT | IResourceDelta.MOVED_FROM, project1.getFile(".project").getFullPath(), null);
- verifier.addExpectedChange(project2.getFolder(folder1.getProjectRelativePath()), IResourceDelta.ADDED, IResourceDelta.MOVED_FROM, folder1.getFullPath(), null);
- verifier.addExpectedChange(project2.getFile(file1.getProjectRelativePath()), IResourceDelta.ADDED, IResourceDelta.MOVED_FROM, file1.getFullPath(), null);
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor m) throws CoreException {
- m.beginTask("Creating and moving", 100);
- try {
- project1.move(project2.getFullPath(), IResource.NONE, new SubProgressMonitor(m, 50));
- } finally {
- m.done();
- }
- }
- }, getMonitor());
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
- /**
- * Move a project via a location change only.
- * Note that the DESCRIPTION flag should be set in the delta.
- */
- public void testMoveProject2() {
- final IPath path = getRandomLocation();
- try {
- verifier.addExpectedChange(project1, IResourceDelta.CHANGED, IResourceDelta.DESCRIPTION);
- verifier.addExpectedChange(project1.getFile(".project"), IResourceDelta.CHANGED, IResourceDelta.CONTENT);
-
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor m) throws CoreException {
- m.beginTask("Creating and moving", 100);
- try {
- IProjectDescription desc = project1.getDescription();
- desc.setLocation(path);
- project1.move(desc, IResource.NONE, new SubProgressMonitor(m, 50));
- } finally {
- m.done();
- }
- }
- }, getMonitor());
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- } finally {
- Workspace.clear(path.toFile());
- }
- }
- public void testMulti() {
-
- class Listener1 implements IResourceChangeListener {
- public boolean done = false;
- public void resourceChanged(IResourceChangeEvent event) {
- assertEquals("1.0", IResourceChangeEvent.POST_CHANGE, event.getType());
- done = true;
- }
- }
-
- class Listener2 extends Listener1 implements IResourceChangeListener {
- public void resourceChanged(IResourceChangeEvent event) {
- assertEquals("2.0", IResourceChangeEvent.POST_AUTO_BUILD, event.getType());
- done = true;
- }
- }
-
- Listener1 listener1 = new Listener1();
- Listener2 listener2 = new Listener2();
-
- getWorkspace().addResourceChangeListener(listener1, IResourceChangeEvent.POST_CHANGE);
- getWorkspace().addResourceChangeListener(listener2, IResourceChangeEvent.POST_AUTO_BUILD);
- try {
- try {
- project1.touch(getMonitor());
- } catch (CoreException e) {
- handleCoreException(e);
- }
-
- int i = 0;
- while (!(listener1.done && listener2.done)) {
- //timeout if the listeners are never called
- assertTrue("3.0", ++i < 600);
- try {
- Thread.sleep(100);
- } catch (InterruptedException e1) {
- }
- }
- } finally {
- getWorkspace().removeResourceChangeListener(listener1);
- getWorkspace().removeResourceChangeListener(listener2);
- }
- }
-
- public void testRemoveFile() {
- try {
- verifier.addExpectedChange(file1, IResourceDelta.REMOVED, 0);
- file1.delete(true, getMonitor());
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
- public void testRemoveFileAndFolder() {
- try {
- verifier.addExpectedChange(folder1, IResourceDelta.REMOVED, 0);
- verifier.addExpectedChange(file1, IResourceDelta.REMOVED, 0);
- folder1.delete(true, getMonitor());
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
- public void testReplaceFile() {
- try {
- /* change file1's contents */
- verifier.addExpectedChange(file1, IResourceDelta.CHANGED, IResourceDelta.REPLACED | IResourceDelta.CONTENT);
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor m) throws CoreException {
- m.beginTask("Deleting and Creating", 100);
- try {
- file1.delete(true, new SubProgressMonitor(m, 50));
- file1.create(getRandomContents(), true, new SubProgressMonitor(m, 50));
- } finally {
- m.done();
- }
- }
- }, getMonitor());
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
-
- public void testReplaceFolderWithFolder() {
- try {
- folder2 = project1.getFolder("Folder2");
- folder3 = project1.getFolder("Folder3");
- verifier.reset();
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor m) throws CoreException {
- file1.delete(false, null);
- folder2.create(false, true, null);
- }
- }, null);
- verifier.reset();
-
- verifier.addExpectedChange(folder1, IResourceDelta.REMOVED, IResourceDelta.MOVED_TO, null, folder2.getFullPath());
- int flags = IResourceDelta.MOVED_FROM | IResourceDelta.MOVED_TO | IResourceDelta.REPLACED | IResourceDelta.CONTENT;
- verifier.addExpectedChange(folder2, IResourceDelta.CHANGED, flags, folder1.getFullPath(), folder3.getFullPath());
- verifier.addExpectedChange(folder3, IResourceDelta.ADDED, IResourceDelta.MOVED_FROM, folder2.getFullPath(), null);
-
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor m) throws CoreException {
- m.beginTask("replace folder with folder", 100);
- try {
- folder2.move(folder3.getFullPath(), false, null);
- folder1.move(folder2.getFullPath(), false, null);
- } finally {
- m.done();
- }
- }
- }, getMonitor());
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
- public void testSetLocal() {
- try {
- verifier.reset();
- //set local on a file that is already local -- should be no change
- file1.setLocal(true, IResource.DEPTH_INFINITE, getMonitor());
- assertTrue("Unexpected notification on no change", !verifier.hasBeenNotified());
-
- //set non-local, still shouldn't appear in delta
- verifier.reset();
- file1.setLocal(false, IResource.DEPTH_INFINITE, getMonitor());
- assertTrue("Unexpected notification on no change", !verifier.hasBeenNotified());
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
-
- public void testSwapFiles() {
- try {
- file1 = project1.getFile("File1");
- file2 = project1.getFile("File2");
- file3 = project1.getFile("File3");
-
- verifier.reset();
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor m) throws CoreException {
- file1.create(new ByteArrayInputStream(new byte[] { 65 }), false, null);
- file2.create(new ByteArrayInputStream(new byte[] { 67 }), false, null);
- }
- }, null);
- verifier.reset();
-
- final int flags = IResourceDelta.MOVED_FROM | IResourceDelta.MOVED_TO | IResourceDelta.REPLACED | IResourceDelta.CONTENT;
- verifier.addExpectedChange(file1, IResourceDelta.CHANGED, flags, file2.getFullPath(), file2.getFullPath());
- verifier.addExpectedChange(file2, IResourceDelta.CHANGED, flags, file1.getFullPath(), file1.getFullPath());
-
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor m) throws CoreException {
- m.beginTask("swap files", 100);
- try {
- file1.move(file3.getFullPath(), false, null);
- file2.move(file1.getFullPath(), false, null);
- file3.move(file2.getFullPath(), false, null);
- } finally {
- m.done();
- }
- }
- }, getMonitor());
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
- public void testSwapFolders() {
- try {
- verifier.reset();
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor m) throws CoreException {
- folder2 = project1.getFolder("Folder2");
- folder3 = project1.getFolder("Folder3");
- file1.delete(false, null);
- folder2.create(false, true, null);
- }
- }, null);
- verifier.reset();
-
- final int flags = IResourceDelta.MOVED_FROM | IResourceDelta.MOVED_TO | IResourceDelta.REPLACED | IResourceDelta.CONTENT;
- verifier.addExpectedChange(folder1, IResourceDelta.CHANGED, flags, folder2.getFullPath(), folder2.getFullPath());
- verifier.addExpectedChange(folder2, IResourceDelta.CHANGED, flags, folder1.getFullPath(), folder1.getFullPath());
-
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor m) throws CoreException {
- m.beginTask("swap folders", 100);
- try {
- folder1.move(folder3.getFullPath(), false, null);
- folder2.move(folder1.getFullPath(), false, null);
- folder3.move(folder2.getFullPath(), false, null);
- } finally {
- m.done();
- }
- }
- }, getMonitor());
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
- /**
- * Asserts that the delta is correct for changes to team private members.
- */
- public void testTeamPrivateChanges() {
- IWorkspace workspace = getWorkspace();
- final IFolder teamPrivateFolder = project1.getFolder("TeamPrivateFolder");
- final IFile teamPrivateFile = folder1.getFile("TeamPrivateFile");
- try {
- //create a team private folder
- verifier.reset();
- verifier.addExpectedChange(teamPrivateFolder, IResourceDelta.ADDED, 0);
- workspace.run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- teamPrivateFolder.create(true, true, getMonitor());
- teamPrivateFolder.setTeamPrivateMember(true);
- }
- }, getMonitor());
- assertDelta();
- verifier.reset();
-
- //create children in team private folder
- IFile fileInFolder = teamPrivateFolder.getFile("FileInPrivateFolder");
- verifier.addExpectedChange(fileInFolder, IResourceDelta.ADDED, 0);
- fileInFolder.create(getRandomContents(), true, getMonitor());
- assertDelta();
- verifier.reset();
-
- //modify children in team private folder
- verifier.addExpectedChange(fileInFolder, IResourceDelta.CHANGED, IResourceDelta.CONTENT);
- fileInFolder.setContents(getRandomContents(), IResource.NONE, getMonitor());
- assertDelta();
- verifier.reset();
-
- //delete children in team private folder
- verifier.addExpectedChange(fileInFolder, IResourceDelta.REMOVED, 0);
- fileInFolder.delete(IResource.NONE, getMonitor());
- assertDelta();
- verifier.reset();
-
- //delete team private folder and change some other file
- verifier.addExpectedChange(teamPrivateFolder, IResourceDelta.REMOVED, 0);
- verifier.addExpectedChange(file1, IResourceDelta.CHANGED, IResourceDelta.CONTENT);
- workspace.run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- teamPrivateFolder.delete(IResource.NONE, getMonitor());
- file1.setContents(getRandomContents(), IResource.NONE, getMonitor());
- }
- }, getMonitor());
- assertDelta();
- verifier.reset();
-
- //create team private file
- verifier.addExpectedChange(teamPrivateFile, IResourceDelta.ADDED, 0);
- workspace.run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- teamPrivateFile.create(getRandomContents(), true, getMonitor());
- teamPrivateFile.setTeamPrivateMember(true);
- }
- }, getMonitor());
- assertDelta();
- verifier.reset();
-
- //modify team private file
- verifier.addExpectedChange(teamPrivateFile, IResourceDelta.CHANGED, IResourceDelta.CONTENT);
- teamPrivateFile.setContents(getRandomContents(), IResource.NONE, getMonitor());
- assertDelta();
- verifier.reset();
-
- //delete team private file
- verifier.addExpectedChange(teamPrivateFile, IResourceDelta.REMOVED, 0);
- teamPrivateFile.delete(IResource.NONE, getMonitor());
- assertDelta();
- verifier.reset();
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
- public void testTwoFileChanges() {
- try {
- verifier.addExpectedChange(file1, IResourceDelta.CHANGED, IResourceDelta.CONTENT);
- verifier.addExpectedChange(file2, IResourceDelta.ADDED, 0);
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor m) throws CoreException {
- m.beginTask("setting contents and creating", 100);
- try {
- file1.setContents(getRandomContents(), true, false, new SubProgressMonitor(m, 50));
- file2.create(getRandomContents(), true, new SubProgressMonitor(m, 50));
- } finally {
- m.done();
- }
- }
- }, getMonitor());
- assertDelta();
- } catch (CoreException e) {
- handleCoreException(e);
- }
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceDeltaTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceDeltaTest.java
deleted file mode 100644
index e168ff6..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceDeltaTest.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-/**
- * Tests the public API of IResourceDelta
- */
-public class IResourceDeltaTest extends EclipseWorkspaceTest {
- /* some random resource handles */
- protected IProject project1;
- protected IProject project2;
- protected IFolder folder1;//below project2
- protected IFolder folder2;//below folder1
- protected IFolder folder3;//same as file1
- protected IFile file1;//below folder1
- protected IFile file2;//below folder1
- protected IFile file3;//below folder2
- protected IFile file4;//below folder1
- protected IResource[] allResources;
-public IResourceDeltaTest() {
-}
-public IResourceDeltaTest(String name) {
- super(name);
-}
-/**
- * Sets up the fixture, for example, open a network connection.
- * This method is called before a test is executed.
- */
-protected void setUp() throws Exception {
- super.setUp();
-
- // Create some resource handles
- project1 = getWorkspace().getRoot().getProject("Project" + 1);
- project2 = getWorkspace().getRoot().getProject("Project" + 2);
- folder1 = project1.getFolder("Folder" + 1);
- folder2 = folder1.getFolder("Folder" + 2);
- folder3 = folder1.getFolder("Folder" + 3);
- file1 = folder1.getFile("File" + 1);
- file2 = folder1.getFile("File" + 2);
- file3 = folder2.getFile("File" + 3);
- file4 = folder1.getFile("File" + 4);//doesn't exist initially
- allResources = new IResource[] {project1, project2,
- folder1, folder2, folder3, file1, file2, file3};
-
- // Create and open the resources
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- ensureExistsInWorkspace(allResources, true);
- }
- };
- try {
- getWorkspace().run(body, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-}
-public static Test suite() {
- return new TestSuite(IResourceDeltaTest.class);
-}
-/**
- * Tears down the fixture, for example, close a network connection.
- * This method is called after a test is executed.
- */
-protected void tearDown() throws Exception {
- super.tearDown();
- ensureDoesNotExistInWorkspace(getWorkspace().getRoot());
-}
-/**
- * Tests the IResourceDelta#findMember method.
- */
-public void testFindMember() {
- /*
- * The following changes will occur:
- * - change file1
- * - delete folder2 (which deletes file3)
- * - add file4 below folder1
- */
- IResourceChangeListener listener = new IResourceChangeListener() {
- public void resourceChanged(IResourceChangeEvent event) {
- //delta relative to root
- IResourceDelta delta = event.getDelta();
- assertNotNull("1.0", delta.findMember(project1.getFullPath()));
- assertNotNull("1.1", delta.findMember(file1.getFullPath()));
- assertNotNull("1.2", delta.findMember(folder2.getFullPath()));
- assertNotNull("1.3", delta.findMember(file3.getFullPath()));
- assertNotNull("1.4", delta.findMember(file4.getFullPath()));
- assertNull("1.5", delta.findMember(project2.getFullPath()));
- assertNull("1.6", delta.findMember(file2.getFullPath()));
- assertNull("1.7", delta.findMember(folder3.getFullPath()));
-
- //delta relative to project
- delta = delta.findMember(project1.getFullPath());
- assertNotNull("2.1", delta.findMember(file1.getProjectRelativePath()));
- assertNotNull("2.2", delta.findMember(folder2.getProjectRelativePath()));
- assertNotNull("2.3", delta.findMember(file3.getProjectRelativePath()));
- assertNotNull("2.4", delta.findMember(file4.getProjectRelativePath()));
- assertNull("2.5", delta.findMember(project2.getFullPath()));
- assertNull("2.6", delta.findMember(file2.getProjectRelativePath()));
- assertNull("2.7", delta.findMember(folder3.getProjectRelativePath()));
- assertNull("2.8", delta.findMember(project1.getFullPath()));
- assertNull("2.9", delta.findMember(file1.getFullPath()));
-
- //delta with no children
- delta = delta.findMember(file1.getProjectRelativePath());
- assertEquals("3.1", delta, delta.findMember(Path.ROOT));
- assertNull("3.2", delta.findMember(new Path("foo")));
- }
- };
- getWorkspace().addResourceChangeListener(listener);
-
- //do the work
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- file1.setContents(getRandomContents(), true, true, getMonitor());
- folder2.delete(true, getMonitor());
- file4.create(getRandomContents(), true, getMonitor());
- }
- };
- try {
- getWorkspace().run(body, getMonitor());
- } catch (CoreException e) {
- fail("Exception1", e);
- } finally {
- getWorkspace().removeResourceChangeListener(listener);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceTest.java
deleted file mode 100644
index 09d178c..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceTest.java
+++ /dev/null
@@ -1,1868 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import java.io.File;
-import java.util.*;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.eclipse.core.internal.localstore.CoreFileSystemLibrary;
-import org.eclipse.core.internal.resources.Workspace;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.*;
-
-public class IResourceTest extends EclipseWorkspaceTest {
- static boolean noSideEffects = false;
- protected static IResource[] interestingResources;
- protected static Set nonExistingResources = new HashSet();
- protected static Set unsynchronizedResources = new HashSet();
- protected static IPath[] interestingPaths;
-
- protected static final Boolean[] TRUE_AND_FALSE = new Boolean[] { Boolean.TRUE, Boolean.FALSE };
- protected static final Boolean[] FALSE_AND_TRUE = new Boolean[] { Boolean.FALSE, Boolean.TRUE };
- protected static final IProgressMonitor[] PROGRESS_MONITORS = new IProgressMonitor[] { new FussyProgressMonitor(), new CancelingProgressMonitor(), null };
-
- /* the delta verifier */
- ResourceDeltaVerifier verifier;
-
- /**
- * Resource only exists in the workspace. It has been deleted from the
- * filesystem manually
- */
- protected static final int S_WORKSPACE_ONLY = 0;
-
- /**
- * Resource exists in the filesystem only. It has been added to the
- * filesystem manually since the last local refresh.
- */
- protected static final int S_FILESYSTEM_ONLY = 1;
-
- /**
- * Resource exists in the filesytem and workspace, and is in sync */
- protected static final int S_UNCHANGED = 2;
-
- /**
- * Resource exists in both filesystem and workspace, but has been changed
- * in the filesystem since the last sync. This only applies to files.
- */
- protected static final int S_CHANGED = 3;
-
- /**
- * Resource does not exist in filesystem or workspace. */
- protected static final int S_DOES_NOT_EXIST = 4;
-
- /**
- * Resource is a folder in the workspace, but has been converted to a file
- * in the filesystem.
- */
- protected static final int S_FOLDER_TO_FILE = 5;
-
- /**
- * Resource is a file in the workspace, but has been converted to a folder
- * in the filesystem.
- */
- protected static final int S_FILE_TO_FOLDER = 6;
- public IResourceTest() {
- }
- public IResourceTest(String name) {
- super(name);
- }
- /**
- * Returns interesting resources for refresh local / sync tests. */
- protected IResource[] buildInterestingResources() {
- IProject emptyProject = getWorkspace().getRoot().getProject("EmptyProject");
- IProject fullProject = getWorkspace().getRoot().getProject("FullProject");
- //resource pattern is: empty file, empty folder, full folder, repeat
- // with full folder
- IResource[] resources = buildResources(fullProject, new String[] { "1", "2/", "3/", "3/1", "3/2/", "3/3/", "3/3/1", "3/3/2/" });
-
- IResource[] result = new IResource[resources.length + 3];
- result[0] = getWorkspace().getRoot();
- result[1] = emptyProject;
- result[2] = fullProject;
- System.arraycopy(resources, 0, result, 3, resources.length);
- ensureExistsInWorkspace(result, true);
- return result;
- }
- private IResource[] buildSampleResources(IContainer root) throws CoreException {
- // do not change the example resources unless you change references to
- // specific indices in setUp()
- IResource[] result =
- buildResources(
- root,
- new String[] {
- "1/",
- "1/1/",
- "1/1/1/",
- "1/1/1/1",
- "1/1/2/",
- "1/1/2/1/",
- "1/1/2/2/",
- "1/1/2/3/",
- "1/2/",
- "1/2/1",
- "1/2/2",
- "1/2/3/",
- "1/2/3/1",
- "1/2/3/2",
- "1/2/3/3",
- "1/2/3/4",
- "2",
- "2" });
- ensureExistsInWorkspace(result, true);
- result[result.length - 1] = root.getFolder(new Path("2/"));
- nonExistingResources.add(result[result.length - 1]);
-
- IResource[] deleted = buildResources(root, new String[] { "1/1/2/1/", "1/2/3/1" });
- ensureDoesNotExistInWorkspace(deleted);
- for (int i = 0; i < deleted.length; ++i) {
- nonExistingResources.add(deleted[i]);
- }
- //out of sync
- IResource[] unsynchronized = buildResources(root, new String[] { "1/2/3/3" });
- ensureOutOfSync(unsynchronized[0]);
- unsynchronizedResources.add(unsynchronized[0]);
-
- //filesystem only
- unsynchronized = buildResources(root, new String[] { "1/1/2/2/1" });
- ensureExistsInFileSystem(unsynchronized);
- unsynchronizedResources.add(unsynchronized[0]);
- return result;
- }
- /**
- * Checks that the after state is as expected.
- * @param receiver the resource that was the receiver of the refreshLocal
- * call
- * @param target the resource that was out of sync
- */
- protected boolean checkAfterState(IResource receiver, IResource target, int state, int depth) {
- assertTrue(verifier.getMessage(), verifier.isDeltaValid());
- switch (state) {
- case S_FILESYSTEM_ONLY :
- assertExistsInFileSystem(target);
- //if receiver was a parent, then refreshLocal
- //will have added the target
- if (hasParent(target, receiver, depth) || target.equals(receiver)) {
- assertExistsInWorkspace(target);
- } else {
- assertDoesNotExistInWorkspace(target);
- }
- break;
- case S_UNCHANGED :
- case S_CHANGED :
- assertExistsInWorkspace(target);
- assertExistsInFileSystem(target);
- break;
- case S_WORKSPACE_ONLY :
- assertDoesNotExistInFileSystem(target);
- //if receiver was a parent, then refreshLocal
- //will have deleted the target
- if (hasParent(target, receiver, depth) || target.equals(receiver)) {
- assertDoesNotExistInWorkspace(target);
- } else {
- assertExistsInWorkspace(target);
- }
- break;
- case S_DOES_NOT_EXIST :
- assertDoesNotExistInWorkspace(target);
- assertDoesNotExistInFileSystem(target);
- break;
- case S_FOLDER_TO_FILE :
- break;
- case S_FILE_TO_FOLDER :
- break;
- }
- return true;
- }
- public void cleanUpAfterRefreshTest(Object[] args) {
- IResource receiver = (IResource) args[0];
- IResource target = (IResource) args[1];
- int state = ((Integer) args[2]).intValue();
- int depth = ((Integer) args[3]).intValue();
- if (!makesSense(receiver, target, state, depth))
- return;
- try {
- getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
- } catch (CoreException e) {
- fail("Exception tearing down in cleanUpAfterRefreshTest", e);
- }
- //target may have changed gender
- IResource changedTarget = getWorkspace().getRoot().findMember(target.getFullPath());
- if (changedTarget != null && changedTarget.getType() != target.getType())
- ensureDoesNotExistInWorkspace(changedTarget);
- ensureExistsInWorkspace(interestingResources, true);
- }
- /**
- * @return Set
- * @param File
- */
- static protected Set getAllFilesForDirectory(File dir) {
- Set result = new HashSet(50);
- String[] members = dir.list();
- if (members != null) {
- for (int i = 0; i < members.length; i++) {
- File member = new File(dir, members[i]);
- result.add(member);
- if (member.isDirectory()) {
- result.addAll(getAllFilesForDirectory(member));
- }
- }
- }
- return result;
- }
- /**
- * @return Set
- * @param resource IResource
- */
- static protected Set getAllFilesForResource(IResource resource, boolean considerUnsyncLocalFiles) throws CoreException {
- Set result = new HashSet(50);
- if (resource.getLocation() != null && (resource.getType() != IResource.PROJECT || ((IProject) resource).isOpen())) {
- java.io.File file = resource.getLocation().toFile();
- if (considerUnsyncLocalFiles) {
- if (file.exists()) {
- result.add(file);
- if (file.isDirectory()) {
- result.addAll(getAllFilesForDirectory(file));
- }
- }
- } else {
- if (resource.exists()) {
- result.add(file);
- if (resource.getType() != IResource.FILE) {
- IContainer container = (IContainer) resource;
- IResource[] children = container.members();
- for (int i = 0; i < children.length; i++) {
- IResource member = children[i];
- result.addAll(getAllFilesForResource(member, considerUnsyncLocalFiles));
- }
- }
- }
- }
- }
- return result;
- }
- /**
- * @return Set
- * @param resource IResource
- */
- static protected Set getAllResourcesForResource(IResource resource) throws CoreException {
- Set result = new HashSet(50);
- if (resource.exists()) {
- result.add(resource);
- if (resource.getType() != IResource.FILE) {
- IContainer container = (IContainer) resource;
- IResource[] children = container.members();
- for (int i = 0; i < children.length; i++) {
- IResource member = children[i];
- result.addAll(getAllResourcesForResource(member));
- }
- }
- }
- return result;
- }
- /**
- * Returns an array of all projects in the given resource array. */
- protected IProject[] getProjects(IResource[] resources) {
- ArrayList list = new ArrayList();
- for (int i = 0; i < resources.length; i++) {
- if (resources[i].getType() == IResource.PROJECT) {
- list.add(resources[i]);
- }
- }
- return (IProject[]) list.toArray(new IProject[list.size()]);
- }
- /**
- * Returns true if resource1 has parent resource2, in range of the given
- * depth. This is basically asking if refreshLocal on resource2 with depth
- * "depth" will hit resource1.
- */
- protected boolean hasParent(IResource resource1, IResource resource2, int depth) {
- if (depth == IResource.DEPTH_ZERO)
- return false;
- if (depth == IResource.DEPTH_ONE) {
- return resource2.equals(resource1.getParent());
- }
- IResource parent = resource1.getParent();
- while (parent != null) {
- if (parent.equals(resource2)) {
- return true;
- }
- parent = parent.getParent();
- }
- return false;
- }
- /**
- * Returns interesting resource states. */
- protected Integer[] interestingDepths() {
- return new Integer[] { new Integer(IResource.DEPTH_ZERO), new Integer(IResource.DEPTH_ONE), new Integer(IResource.DEPTH_INFINITE)};
- }
-
- /**
- * Returns interesting resource states. */
- protected Integer[] interestingStates() {
- return new Integer[] { new Integer(S_WORKSPACE_ONLY), new Integer(S_FILESYSTEM_ONLY), new Integer(S_UNCHANGED), new Integer(S_CHANGED), new Integer(S_DOES_NOT_EXIST),
- // new Integer(S_FOLDER_TO_FILE),
- // new Integer(S_FILE_TO_FOLDER),
- };
- }
- protected boolean isFile(IResource r) {
- return r.getType() == IResource.FILE;
- }
- protected boolean isFolder(IResource r) {
- return r.getType() == IResource.FOLDER;
- }
- protected boolean isProject(IResource r) {
- return r.getType() == IResource.PROJECT;
- }
- /**
- * Returns true if this combination of arguments makes sense. */
- protected boolean makesSense(IResource receiver, IResource target, int state, int depth) {
- /* don't allow projects or the root as targets */
- if (target.getType() == IResource.PROJECT || target.getType() == IResource.ROOT) {
- return false;
- }
-
- /* target cannot be a parent of receiver */
- if (hasParent(receiver, target, IResource.DEPTH_INFINITE)) {
- return false;
- }
-
- /* target can only take certain forms for some states */
- switch (state) {
- case S_WORKSPACE_ONLY :
- return true;
- case S_FILESYSTEM_ONLY :
- return true;
- case S_UNCHANGED :
- return true;
- case S_CHANGED :
- return isFile(target);
- case S_DOES_NOT_EXIST :
- return true;
- case S_FOLDER_TO_FILE :
- return isFolder(target);
- case S_FILE_TO_FOLDER :
- return isFile(target);
- }
-
- return true;
- }
- protected void setUp() throws Exception {
- super.setUp();
- IWorkspaceDescription description = getWorkspace().getDescription();
- description.setAutoBuilding(false);
- getWorkspace().setDescription(description);
-
- if (noSideEffects) {
- noSideEffects = false;
- return;
- }
-
- try {
- // open project
- IProject openProject = getWorkspace().getRoot().getProject("openProject");
- openProject.create(null);
- openProject.open(null);
- IResource[] resourcesInOpenProject = buildSampleResources(openProject);
-
- // closed project
- IProject closedProject = getWorkspace().getRoot().getProject("closedProject");
- closedProject.create(null);
- closedProject.open(null);
- IResource[] resourcesInClosedProject = buildSampleResources(closedProject);
- closedProject.close(null);
-
- // non-existant project
- IProject nonExistingProject = getWorkspace().getRoot().getProject("nonExistingProject");
- nonExistingProject.create(null);
- nonExistingProject.open(null);
- nonExistingProject.delete(true, null);
-
- Vector resources = new Vector();
- resources.addElement(openProject);
- for (int i = 0; i < resourcesInOpenProject.length; i++) {
- resources.addElement(resourcesInOpenProject[i]);
- }
-
- resources.addElement(closedProject);
- for (int i = 0; i < resourcesInClosedProject.length; i++) {
- resources.addElement(resourcesInClosedProject[i]);
- nonExistingResources.add(resourcesInClosedProject[i]);
- }
-
- resources.addElement(nonExistingProject);
- nonExistingResources.add(nonExistingProject);
-
- interestingResources = new IResource[resources.size()];
- resources.copyInto(interestingResources);
-
- String[] interestingPathnames =
- new String[] {
- "1/",
- "1/1/",
- "1/1/1/",
- "1/1/1/1",
- "1/1/2/1/",
- "1/1/2/2/",
- "1/1/2/3/",
- "1/2/",
- "1/2/1",
- "1/2/2",
- "1/2/3/",
- "1/2/3/1",
- "1/2/3/2",
- "1/2/3/3",
- "1/2/3/4",
- "2",
- "2/1",
- "2/2",
- "2/3",
- "2/4",
- "2/1/",
- "2/2/",
- "2/3/",
- "2/4/",
- "..",
- "." };
- interestingPaths = new IPath[interestingPathnames.length];
- for (int i = 0; i < interestingPathnames.length; i++) {
- interestingPaths[i] = new Path(interestingPathnames[i]);
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- throw ex;
- }
- }
- /**
- * Sets up the workspace and filesystem for this test. */
- protected void setupBeforeState(IResource receiver, IResource target, int state, int depth, boolean addVerifier) throws CoreException {
- if (addVerifier) {
- /* install the verifier */
- if (verifier == null) {
- verifier = new ResourceDeltaVerifier();
- getWorkspace().addResourceChangeListener(verifier);
- }
- }
-
- /* the target's parents must exist */
- ensureExistsInWorkspace(target.getParent(), true);
- switch (state) {
- case S_WORKSPACE_ONLY :
- ensureExistsInWorkspace(target, true);
- ensureDoesNotExistInFileSystem(target);
- if (addVerifier) {
- verifier.reset();
- // we only get a delta if the receiver of refreshLocal
- // is a parent of the changed resource, or they're the same
- // resource.
- if (hasParent(target, receiver, depth) || target.equals(receiver))
- verifier.addExpectedDeletion(target);
- }
- break;
- case S_FILESYSTEM_ONLY :
- ensureDoesNotExistInWorkspace(target);
- ensureExistsInFileSystem(target);
- if (addVerifier) {
- verifier.reset();
- // we only get a delta if the receiver of refreshLocal
- // is a parent of the changed resource, or they're the same
- // resource.
- if (hasParent(target, receiver, depth) || target.equals(receiver))
- verifier.addExpectedChange(target, IResourceDelta.ADDED, 0);
- }
- break;
- case S_UNCHANGED :
- ensureExistsInWorkspace(target, true);
- if (addVerifier)
- verifier.reset();
- break;
- case S_CHANGED :
- ensureExistsInWorkspace(target, true);
- ensureOutOfSync(target);
- if (addVerifier) {
- verifier.reset();
- // we only get a delta if the receiver of refreshLocal
- // is a parent of the changed resource, or they're the same
- // resource.
- if (hasParent(target, receiver, depth) || target.equals(receiver))
- verifier.addExpectedChange(target, IResourceDelta.CHANGED, IResourceDelta.CONTENT);
- }
- break;
- case S_DOES_NOT_EXIST :
- ensureDoesNotExistInWorkspace(target);
- ensureDoesNotExistInFileSystem(target);
- if (addVerifier)
- verifier.reset();
- break;
- case S_FOLDER_TO_FILE :
- ensureExistsInWorkspace(target, true);
- ensureDoesNotExistInFileSystem(target);
- IPath location = target.getLocation();
- createFileInFileSystem(location);
- if (addVerifier) {
- verifier.reset();
- // we only get a delta if the receiver of refreshLocal
- // is a parent of the changed resource, or they're the same
- // resource.
- if (hasParent(target, receiver, depth) || target.equals(receiver))
- verifier.addExpectedChange(target, IResourceDelta.CHANGED, IResourceDelta.REPLACED | IResourceDelta.TYPE | IResourceDelta.CONTENT);
- }
- break;
- case S_FILE_TO_FOLDER :
- ensureExistsInWorkspace(target, true);
- ensureDoesNotExistInFileSystem(target);
- target.getLocation().toFile().mkdirs();
- if (addVerifier) {
- verifier.reset();
- // we only get a delta if the receiver of refreshLocal
- // is a parent of the changed resource, or they're the same
- // resource.
- if (hasParent(target, receiver, depth) || target.equals(receiver))
- verifier.addExpectedChange(target, IResourceDelta.CHANGED, IResourceDelta.REPLACED | IResourceDelta.TYPE | IResourceDelta.CONTENT);
- }
- break;
- }
- }
- public static Test suite() {
- return new TestSuite(IResourceTest.class);
-
-// TestSuite suite = new TestSuite();
-// suite.addTest(new IResourceTest("testSetLocalTimeStamp"));
-// return suite;
- }
- protected void tearDown() throws Exception {
- if (noSideEffects)
- return;
- if (verifier != null)
- getWorkspace().removeResourceChangeListener(verifier);
- getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
- ensureDoesNotExistInWorkspace(getWorkspace().getRoot());
- interestingPaths = null;
- interestingResources = null;
- super.tearDown();
- }
- /**
- * Performs black box testing of the following method: void
- * accept(IResourceVisitor)
- */
- public void testAccept2() {
- noSideEffects = true;
-
- class LoggingResourceVisitor implements IResourceVisitor {
- Vector visitedResources = new Vector();
- void clear() {
- visitedResources.removeAllElements();
- }
- void recordVisit(IResource r) {
- visitedResources.addElement(r);
- }
- public boolean visit(IResource r) {
- throw new RuntimeException("this class is abstract");
- }
- };
-
- final LoggingResourceVisitor deepVisitor = new LoggingResourceVisitor() {
- public boolean visit(IResource r) {
- recordVisit(r);
- return true;
- }
- };
-
- final LoggingResourceVisitor shallowVisitor = new LoggingResourceVisitor() {
- public boolean visit(IResource r) {
- recordVisit(r);
- return false;
- }
- };
-
- LoggingResourceVisitor[] interestingVisitors = new LoggingResourceVisitor[] { shallowVisitor, deepVisitor };
- Object[][] inputs = new Object[][] { interestingResources, interestingVisitors, TRUE_AND_FALSE, };
- new TestPerformer("IResourceTest.testAccept2") {
- public boolean shouldFail(Object[] args, int count) {
- deepVisitor.clear();
- shallowVisitor.clear();
- IResource resource = (IResource) args[0];
- return nonExistingResources.contains(resource);
- }
- public Object[] interestingOldState(Object[] args) {
- return null;
- }
- public Object invokeMethod(Object[] args, int count) throws Exception {
- IResource resource = (IResource) args[0];
- IResourceVisitor visitor = (IResourceVisitor) args[1];
- Boolean includePhantoms = (Boolean) args[2];
- resource.accept(visitor, IResource.DEPTH_INFINITE, includePhantoms.booleanValue());
- return null;
- }
- public boolean wasSuccess(Object[] args, Object result, Object[] oldState) {
- IResource resource = (IResource) args[0];
- LoggingResourceVisitor visitor = (LoggingResourceVisitor) args[1];
- //Boolean includePhantoms = (Boolean) args[2];
- Vector visitedResources = visitor.visitedResources;
- if (visitor == shallowVisitor) {
- return visitedResources.size() == 1 && visitedResources.elementAt(0).equals(resource);
- } else if (visitor == deepVisitor) {
- if (resource.getType() == IResource.FILE) {
- return visitedResources.size() == 1 && visitedResources.elementAt(0).equals(resource);
- } else {
- IContainer container = (IContainer) resource;
- int memberCount = 0;
- try {
- memberCount = memberCount + container.members().length;
- } catch (CoreException ex) {
- return false;
- }
- return visitedResources.size() >= memberCount + 1 && visitedResources.elementAt(0).equals(resource);
- }
- } else {
- return false;
- }
- }
- }
- .performTest(inputs);
- }
- /**
- * This method tests the IResource.refreshLocal() operation */
- public void testAddLocalProject() throws CoreException {
- /**
- * Add a project in the filesystem, but not in the workspace */
-
- IProject project1 = getWorkspace().getRoot().getProject("Project");
- project1.create(getMonitor());
- project1.open(getMonitor());
-
- IProject project2 = getWorkspace().getRoot().getProject("NewProject");
-
- IPath projectPath = project1.getLocation().removeLastSegments(1).append("NewProject");
- projectPath.toFile().mkdirs();
-
- project1.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- project2.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- }
-
- /**
- * Tests various resource constants. */
- public void testConstants() {
-
- // IResource constants (all have fixed values)
- assertEquals("1.0", 0, IResource.NONE);
-
- assertEquals("2.1", 0x1, IResource.FILE);
- assertEquals("2.2", 0x2, IResource.FOLDER);
- assertEquals("2.3", 0x4, IResource.PROJECT);
- assertEquals("2.4", 0x8, IResource.ROOT);
-
- assertEquals("3.1", 0, IResource.DEPTH_ZERO);
- assertEquals("3.2", 1, IResource.DEPTH_ONE);
- assertEquals("3.1", 2, IResource.DEPTH_INFINITE);
-
- assertEquals("4.1", -1, IResource.NULL_STAMP);
-
- assertEquals("5.1", 0x1, IResource.FORCE);
- assertEquals("5.2", 0x2, IResource.KEEP_HISTORY);
- assertEquals("5.3", 0x4, IResource.ALWAYS_DELETE_PROJECT_CONTENT);
- assertEquals("5.4", 0x8, IResource.NEVER_DELETE_PROJECT_CONTENT);
-
- // IContainer constants (all have fixed values)
- assertEquals("6.1", 0x1, IContainer.INCLUDE_PHANTOMS);
- assertEquals("6.2", 0x2, IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
-
- }
-
- /**
- * Performs black box testing of the following method: void copy(IPath,
- * boolean, IProgressMonitor)
- */
- public void testCopy() {
- //add markers to all resources ... markers should not be copied
- try {
- getWorkspace().getRoot().accept(new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- if (resource.isAccessible())
- resource.createMarker(IMarker.TASK);
- return true;
- }
- });
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- Object[][] inputs = new Object[][] { interestingResources, interestingPaths, TRUE_AND_FALSE, PROGRESS_MONITORS };
- new TestPerformer("IResourceTest.testCopy") {
- public boolean shouldFail(Object[] args, int count) {
- IResource resource = (IResource) args[0];
- IPath destination = (IPath) args[1];
- //Boolean force = (Boolean) args[2];
- if (!resource.isAccessible())
- return true;
- if (isProject(resource) && destination.segmentCount() > 1 && !getWorkspace().validatePath(destination.toString(), IResource.FOLDER).isOK())
- return true;
- java.io.File destinationParent =
- destination.isAbsolute() ? destination.removeLastSegments(1).toFile() : resource.getLocation().removeLastSegments(1).append(destination.removeLastSegments(1)).toFile();
- java.io.File destinationFile = destination.isAbsolute() ? destination.toFile() : resource.getLocation().removeLastSegments(1).append(destination).removeTrailingSeparator().toFile();
- return !destinationParent.exists() || !destinationParent.isDirectory() || destinationFile.exists() || destinationFile.toString().startsWith(resource.getLocation().toFile().toString());
- }
- public Object[] interestingOldState(Object[] args) {
- return null;
- }
- public Object invokeMethod(Object[] args, int count) throws Exception {
- IResource resource = (IResource) args[0];
- IPath destination = (IPath) args[1];
- Boolean force = (Boolean) args[2];
- IProgressMonitor monitor = (IProgressMonitor) args[3];
- if (monitor instanceof FussyProgressMonitor)
- ((FussyProgressMonitor) monitor).prepare();
- resource.copy(destination, force.booleanValue(), monitor);
- if (monitor instanceof FussyProgressMonitor)
- ((FussyProgressMonitor) monitor).sanityCheck();
- return null;
- }
- public boolean wasSuccess(Object[] args, Object result, Object[] oldState) throws CoreException {
- IResource source = (IResource) args[0];
- IPath destination = (IPath) args[1];
- //ensure the destination exists
- //"Relative paths are considered to be relative to the
- // container of the resource being copied."
- IPath path = destination.isAbsolute() ? destination : source.getParent().getFullPath().append(destination);
- IResource copy = getWorkspace().getRoot().findMember(path);
- if (copy == null)
- return false;
- if (!copy.exists())
- return false;
- //markers are never copied, so ensure copy has none
- if (copy.findMarkers(IMarker.TASK, true, IResource.DEPTH_INFINITE).length > 0)
- return false;
- return true;
- }
- }
- .performTest(inputs);
- }
- /**
- * Performs black box testing of the following method: void delete(boolean,
- * IProgressMonitor)
- */
- public void testDelete() {
- Object[][] inputs = new Object[][] { FALSE_AND_TRUE, PROGRESS_MONITORS, interestingResources };
- new TestPerformer("IResourceTest.testDelete") {
- public boolean shouldFail(Object[] args, int count) {
- Boolean force = (Boolean) args[0];
- IResource resource = (IResource) args[2];
- if (force.booleanValue() || !resource.exists())
- return false;
- if (resource.getType() == IResource.PROJECT) {
- IProject project = (IProject) resource;
- try {
- if (!project.isOpen())
- return false;
- IResource[] children = project.members();
- for (int i = 0; i < children.length; i++) {
- IResource member = children[i];
- if (shouldFail(new Object[] { args[0], args[1], member }, count))
- return true;
- }
- } catch (CoreException ex) {
- ex.printStackTrace();
- throw new RuntimeException("there is a problem in the testing method 'shouldFail'");
- }
- return false;
- }
- final boolean[] hasUnsynchronizedResources = new boolean[] { false };
- try {
- resource.accept(new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- File target = resource.getLocation().toFile();
- if (target.exists() != resource.exists()) {
- hasUnsynchronizedResources[0] = true;
- return false;
- }
- if (target.isFile() != (resource.getType() == IResource.FILE)) {
- hasUnsynchronizedResources[0] = true;
- return false;
- }
- if (unsynchronizedResources.contains(resource)) {
- hasUnsynchronizedResources[0] = true;
- return false;
- }
- if (target.isFile())
- return false;
- String[] list = target.list();
- if (list == null)
- return true;
- IContainer container = (IContainer) resource;
- for (int i = 0; i < list.length; i++) {
- File file = new File(target, list[i]);
- IResource child = file.isFile() ? (IResource) container.getFile(new Path(list[i])) : container.getFolder(new Path(list[i]));
- if (!child.exists())
- visit(child);
- }
- return true;
- }
- });
- } catch (Exception ex) {
- ex.printStackTrace();
- throw new RuntimeException("there is a problem in the testing method 'shouldFail'");
- }
- return hasUnsynchronizedResources[0];
- }
- public Object[] interestingOldState(Object[] args) throws Exception {
- Boolean force = (Boolean) args[0];
- IResource resource = (IResource) args[2];
- return new Object[] { new Boolean(resource.isAccessible()), getAllFilesForResource(resource, force.booleanValue()), getAllResourcesForResource(resource)};
- }
- public Object invokeMethod(Object[] args, int count) throws Exception {
- Boolean force = (Boolean) args[0];
- IProgressMonitor monitor = (IProgressMonitor) args[1];
- IResource resource = (IResource) args[2];
- if (monitor instanceof FussyProgressMonitor)
- ((FussyProgressMonitor) monitor).prepare();
- resource.delete(force.booleanValue(), monitor);
- if (monitor instanceof FussyProgressMonitor)
- ((FussyProgressMonitor) monitor).sanityCheck();
- return null;
- }
- public boolean wasSuccess(Object[] args, Object result, Object[] oldState) throws Exception {
- Boolean force = (Boolean) args[0];
- IResource resource = (IResource) args[2];
- //oldState[0] : was resource accessible before the invocation?
- //oldState[1] : all files that should have been deleted from
- // the file system
- //oldState[2] : all resources that should have been deleted
- // from the workspace
- if (resource.getType() != IResource.PROJECT && ((Boolean) oldState[0]).booleanValue()) {
- // check the parent's members, deleted resource should not
- // be a member
- IResource[] children = ((IContainer) getWorkspace().getRoot().findMember(resource.getFullPath().removeLastSegments(1))).members();
- for (int i = 0; i < children.length; i++) {
- if (resource == children[i])
- return false;
- }
- }
- if (!getAllFilesForResource(resource, force.booleanValue()).isEmpty())
- return false;
- Set oldFiles = (Set) oldState[1];
- for (Iterator i = oldFiles.iterator(); i.hasNext();) {
- File oldFile = (File) i.next();
- if (oldFile.exists())
- return false;
- }
- Set oldResources = (Set) oldState[2];
- for (Iterator i = oldResources.iterator(); i.hasNext();) {
- IResource oldResource = (IResource) i.next();
- if (oldResource.exists() || getWorkspace().getRoot().findMember(oldResource.getFullPath()) != null)
- return false;
- }
- return true;
- }
- }
- .performTest(inputs);
- }
- /**
- * Performs black box testing of the following methods: isDerived() and
- * setDerived(boolean)
- */
- public void testDerived() {
- IWorkspaceRoot root = getWorkspace().getRoot();
- IProject project = root.getProject("Project");
- IFolder folder = project.getFolder("folder");
- IFile file = folder.getFile("target");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- folder.create(true, true, getMonitor());
- file.create(getRandomContents(), true, getMonitor());
-
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- // all resources have independent derived flag; all non-derived by
- // default; check each type
- try {
-
- // root - cannot be marked as derived
- assertTrue("2.1.1", !root.isDerived());
- assertTrue("2.1.2", !project.isDerived());
- assertTrue("2.1.3", !folder.isDerived());
- assertTrue("2.1.4", !file.isDerived());
- root.setDerived(true);
- assertTrue("2.2.1", !root.isDerived());
- assertTrue("2.2.2", !project.isDerived());
- assertTrue("2.2.3", !folder.isDerived());
- assertTrue("2.2.4", !file.isDerived());
- root.setDerived(false);
- assertTrue("2.3.1", !root.isDerived());
- assertTrue("2.3.2", !project.isDerived());
- assertTrue("2.3.3", !folder.isDerived());
- assertTrue("2.3.4", !file.isDerived());
-
- // project - cannot be marked as derived
- project.setDerived(true);
- assertTrue("3.1.1", !root.isDerived());
- assertTrue("3.1.2", !project.isDerived());
- assertTrue("3.1.3", !folder.isDerived());
- assertTrue("3.1.4", !file.isDerived());
- project.setDerived(false);
- assertTrue("3.2.1", !root.isDerived());
- assertTrue("3.2.2", !project.isDerived());
- assertTrue("3.2.3", !folder.isDerived());
- assertTrue("3.2.4", !file.isDerived());
-
- // folder
- folder.setDerived(true);
- assertTrue("4.1.1", !root.isDerived());
- assertTrue("4.1.2", !project.isDerived());
- assertTrue("4.1.3", folder.isDerived());
- assertTrue("4.1.4", !file.isDerived());
- folder.setDerived(false);
- assertTrue("4.2.1", !root.isDerived());
- assertTrue("4.2.2", !project.isDerived());
- assertTrue("4.2.3", !folder.isDerived());
- assertTrue("4.2.4", !file.isDerived());
-
- // file
- file.setDerived(true);
- assertTrue("5.1.1", !root.isDerived());
- assertTrue("5.1.2", !project.isDerived());
- assertTrue("5.1.3", !folder.isDerived());
- assertTrue("5.1.4", file.isDerived());
- file.setDerived(false);
- assertTrue("5.2.1", !root.isDerived());
- assertTrue("5.2.2", !project.isDerived());
- assertTrue("5.2.3", !folder.isDerived());
- assertTrue("5.2.4", !file.isDerived());
-
- } catch (CoreException e) {
- fail("6.0", e);
- }
-
- /* remove trash */
- try {
- project.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("7.0", e);
- }
-
- // isDerived should return false when resource does not exist
- assertTrue("8.1", !project.isDerived());
- assertTrue("8.2", !folder.isDerived());
- assertTrue("8.3", !file.isDerived());
-
- // setDerived should fail when resource does not exist
- try {
- project.setDerived(false);
- assertTrue("9.1", false);
- } catch (CoreException e) {
- // pass
- }
- try {
- folder.setDerived(false);
- assertTrue("9.2", false);
- } catch (CoreException e) {
- // pass
- }
- try {
- file.setDerived(false);
- assertTrue("9.3", false);
- } catch (CoreException e) {
- // pass
- }
- } /**
- * Performs black box testing of the following method: boolean
- * equals(Object)
- */
- public void testEquals() {
- noSideEffects = true;
- Object[][] inputs = new Object[][] { interestingResources, interestingResources };
- new TestPerformer("IResourceTest.testEquals") {
- public boolean shouldFail(Object[] args, int count) {
- return false;
- }
- public Object[] interestingOldState(Object[] args) throws Exception {
- return null;
- }
- public Object invokeMethod(Object[] args, int count) throws Exception {
- IResource resource0 = (IResource) args[0];
- IResource resource1 = (IResource) args[1];
- return resource0.equals(resource1) ? Boolean.TRUE : Boolean.FALSE;
- }
- public boolean wasSuccess(Object[] args, Object result, Object[] oldState) throws Exception {
- IResource resource0 = (IResource) args[0];
- IResource resource1 = (IResource) args[1];
- boolean booleanResult = ((Boolean) result).booleanValue();
- boolean expectedResult =
- resource0.getFullPath().equals(resource1.getFullPath()) && resource0.getType() == resource1.getType() && resource0.getWorkspace().equals(resource1.getWorkspace());
- if (booleanResult) {
- assertTrue("hashCode should be equal if equals returns true", resource0.hashCode() == resource1.hashCode());
- }
- return booleanResult == expectedResult;
- }
- }
- .performTest(inputs);
- }
- /**
- * Performs black box testing of the following method: boolean exists() */
- public void testExists() {
- noSideEffects = true;
-
- Object[][] inputs = new Object[][] { interestingResources };
- new TestPerformer("IResourceTest.testExists") {
- public boolean shouldFail(Object[] args, int count) {
- return false;
- }
- public Object[] interestingOldState(Object[] args) throws Exception {
- return null;
- }
- public Object invokeMethod(Object[] args, int count) throws Exception {
- IResource resource = (IResource) args[0];
- return resource.exists() ? Boolean.TRUE : Boolean.FALSE;
- }
- public boolean wasSuccess(Object[] args, Object result, Object[] oldState) throws Exception {
- boolean booleanResult = ((Boolean) result).booleanValue();
- IResource resource = (IResource) args[0];
- return booleanResult != nonExistingResources.contains(resource);
- }
- }
- .performTest(inputs);
- }
- /**
- * Performs black box testing of the following method: IPath getLocation() */
- public void testGetLocation() {
- if (true)
- return;
- noSideEffects = true;
- Object[][] inputs = new Object[][] { interestingResources };
- new TestPerformer("IResourceTest.testGetLocation") {
- public boolean shouldFail(Object[] args, int count) {
- return false;
- }
- public Object[] interestingOldState(Object[] args) {
- return null;
- }
- public Object invokeMethod(Object[] args, int count) throws Exception {
- IResource resource = (IResource) args[0];
- return resource.getLocation();
- }
- public boolean wasSuccess(Object[] args, Object result, Object[] oldState) {
- IResource resource = (IResource) args[0];
- IPath resultPath = (IPath) result;
- if (resource.getType() == IResource.PROJECT) {
- if (!resource.exists())
- return resultPath == null;
- return resultPath != null;
- }
- if (!resource.isAccessible())
- return resultPath == null;
- return resultPath != null;
- }
- }
- .performTest(inputs);
- }
- /**
- * Performs black box testing of the following method: IPath
- * getRawLocation()
- */
- public void testGetRawLocation() {
- IProject project = getWorkspace().getRoot().getProject("Project");
- IFolder topFolder = project.getFolder("TopFolder");
- IFile topFile = project.getFile("TopFile");
- IFile deepFile = topFolder.getFile("DeepFile");
- IResource[] allResources = new IResource[] { project, topFolder, topFile, deepFile };
-
- //non existing project
- assertNull("2.0", project.getRawLocation());
-
- //resources in non-existing project
- assertNull("2.1", topFolder.getRawLocation());
- assertNull("2.2", topFile.getRawLocation());
- assertNull("2.3", deepFile.getRawLocation());
-
- ensureExistsInWorkspace(allResources, true);
- //open project
- assertNull("2.0", project.getRawLocation());
- //resources in open project
- assertEquals("2.1", Platform.getLocation().append(topFolder.getFullPath()), topFolder.getRawLocation());
- assertEquals("2.2", Platform.getLocation().append(topFile.getFullPath()), topFile.getRawLocation());
- assertEquals("2.3", Platform.getLocation().append(deepFile.getFullPath()), deepFile.getRawLocation());
-
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("1.99", e);
- }
- //closed project
- assertNull("3.0", project.getRawLocation());
- //resource in closed project
- assertEquals("3.1", Platform.getLocation().append(topFolder.getFullPath()), topFolder.getRawLocation());
- assertEquals("3.2", Platform.getLocation().append(topFile.getFullPath()), topFile.getRawLocation());
- assertEquals("3.3", Platform.getLocation().append(deepFile.getFullPath()), deepFile.getRawLocation());
-
- IPath projectLocation = getRandomLocation();
- IPath folderLocation = getRandomLocation();
- IPath fileLocation = getRandomLocation();
- IPath variableLocation = getRandomLocation();
- final String variableName = "IResourceTest_VariableName";
- IPathVariableManager varMan = getWorkspace().getPathVariableManager();
- try {
- varMan.setValue(variableName, variableLocation);
- project.open(getMonitor());
- IProjectDescription description = project.getDescription();
- description.setLocation(projectLocation);
- project.move(description, IResource.NONE, getMonitor());
-
- //open project not in default location
- assertEquals("4.0", projectLocation, project.getRawLocation());
- //resource in open project not in default location
- assertEquals("4.1", projectLocation.append(topFolder.getProjectRelativePath()), topFolder.getRawLocation());
- assertEquals("4.2", projectLocation.append(topFile.getProjectRelativePath()), topFile.getRawLocation());
- assertEquals("4.3", projectLocation.append(deepFile.getProjectRelativePath()), deepFile.getRawLocation());
-
- project.close(getMonitor());
-
- //closed project not in default location
- assertEquals("5.0", projectLocation, project.getRawLocation());
- //resource in closed project not in default location
- assertEquals("5.1", projectLocation.append(topFolder.getProjectRelativePath()), topFolder.getRawLocation());
- assertEquals("5.2", projectLocation.append(topFile.getProjectRelativePath()), topFile.getRawLocation());
- assertEquals("5.3", projectLocation.append(deepFile.getProjectRelativePath()), deepFile.getRawLocation());
-
- project.open(getMonitor());
- ensureDoesNotExistInWorkspace(topFolder);
- ensureDoesNotExistInWorkspace(topFile);
- createFileInFileSystem(fileLocation);
- folderLocation.toFile().mkdirs();
- topFolder.createLink(folderLocation, IResource.NONE, getMonitor());
- topFile.createLink(fileLocation, IResource.NONE, getMonitor());
- ensureExistsInWorkspace(deepFile, true);
-
- //linked file
- assertEquals("6.0", fileLocation, topFile.getRawLocation());
- //linked folder
- assertEquals("6.1", folderLocation, topFolder.getRawLocation());
- //resource below linked folder
- assertEquals("6.2", folderLocation.append(deepFile.getName()), deepFile.getRawLocation());
-
- project.close(getMonitor());
-
- //linked file in closed project (should default to project
- // location)
- assertEquals("7.0", projectLocation.append(topFile.getProjectRelativePath()), topFile.getRawLocation());
- //linked folder in closed project
- assertEquals("7.1", projectLocation.append(topFolder.getProjectRelativePath()), topFolder.getRawLocation());
- //resource below linked folder in closed project
- assertEquals("7.3", projectLocation.append(deepFile.getProjectRelativePath()), deepFile.getRawLocation());
-
- project.open(getMonitor());
- IPath variableFolderLocation = new Path(variableName).append("/VarFolderName");
- IPath variableFileLocation = new Path(variableName).append("/VarFileName");
- ensureDoesNotExistInWorkspace(topFolder);
- ensureDoesNotExistInWorkspace(topFile);
- createFileInFileSystem(varMan.resolvePath(variableFileLocation));
- varMan.resolvePath(variableFolderLocation).toFile().mkdirs();
- topFolder.createLink(variableFolderLocation, IResource.NONE, getMonitor());
- topFile.createLink(variableFileLocation, IResource.NONE, getMonitor());
- ensureExistsInWorkspace(deepFile, true);
-
- //linked file with variable
- assertEquals("8.0", variableFileLocation, topFile.getRawLocation());
- //linked folder with variable
- assertEquals("8.1", variableFolderLocation, topFolder.getRawLocation());
- //resource below linked folder with variable
- assertEquals("8.3", varMan.resolvePath(variableFolderLocation).append(deepFile.getName()), deepFile.getRawLocation());
-
- project.close(getMonitor());
-
- //linked file in closed project with variable
- assertEquals("9.0", projectLocation.append(topFile.getProjectRelativePath()), topFile.getRawLocation());
- //linked folder in closed project with variable
- assertEquals("9.1", projectLocation.append(topFolder.getProjectRelativePath()), topFolder.getRawLocation());
- //resource below linked folder in closed project with variable
- assertEquals("9.3", projectLocation.append(deepFile.getProjectRelativePath()), deepFile.getRawLocation());
- } catch (CoreException e) {
- fail("99.99", e);
- } finally {
- try {
- getWorkspace().getRoot().delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, getMonitor());
- varMan.setValue(variableName, null);
- } catch (CoreException e) {
- }
- Workspace.clear(projectLocation.toFile());
- Workspace.clear(folderLocation.toFile());
- Workspace.clear(fileLocation.toFile());
- Workspace.clear(variableLocation.toFile());
- }
- }
- public void testGetModificationStamp() {
- // cleanup auto-created resources
- try {
- getWorkspace().getRoot().delete(true, getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- // setup
- IResource[] resources = buildResources(getWorkspace().getRoot(), new String[] { "/1/", "/1/1", "/1/2", "/1/3", "/2/", "/2/1" });
- final Map table = new HashMap(resources.length);
-
- for (int i = 0; i < resources.length; i++) {
- IResource resource = resources[i];
- if (resource.getType() != IResource.ROOT)
- assertEquals("1.0." + resource.getFullPath(), IResource.NULL_STAMP, resource.getModificationStamp());
- }
-
- // create the project(s). the resources should still have null
- // modification stamp
- IProject[] projects = getProjects(resources);
- IProject project;
- for (int i = 0; i < projects.length; i++) {
- project = projects[i];
- try {
- project.create(getMonitor());
- } catch (CoreException e) {
- fail("2.0." + project.getFullPath(), e);
- }
- assertEquals("2.1." + project.getFullPath(), IResource.NULL_STAMP, project.getModificationStamp());
- }
-
- // open the project(s) and create the resources. none should have a
- // null stamp anymore.
- for (int i = 0; i < projects.length; i++) {
- project = projects[i];
- assertEquals("3.1." + project.getFullPath(), IResource.NULL_STAMP, project.getModificationStamp());
- try {
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("3.2", e);
- }
- assertTrue("3.3." + project.getFullPath(), project.getModificationStamp() != IResource.NULL_STAMP);
- // cache the value for later use
- table.put(project.getFullPath(), new Long(project.getModificationStamp()));
- }
- for (int i = 0; i < resources.length; i++) {
- IResource resource = resources[i];
- if (resource.getType() != IResource.PROJECT) {
- assertEquals("3.4." + resource.getFullPath(), IResource.NULL_STAMP, resource.getModificationStamp());
- ensureExistsInWorkspace(resource, true);
- assertTrue("3.5." + resource.getFullPath(), resource.getModificationStamp() != IResource.NULL_STAMP);
- // cache the value for later use
- table.put(resource.getFullPath(), new Long(resource.getModificationStamp()));
- }
- }
-
- // close the projects. now all resources should have a null stamp again
- for (int i = 0; i < projects.length; i++) {
- project = projects[i];
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("4.0." + project.getFullPath(), e);
- }
- }
- for (int i = 0; i < resources.length; i++) {
- IResource resource = resources[i];
- if (resource.getType() != IResource.ROOT)
- assertEquals("4.1." + resource.getFullPath(), IResource.NULL_STAMP, resource.getModificationStamp());
- }
-
- // re-open the projects. all resources should have the same stamps
- for (int i = 0; i < projects.length; i++) {
- project = projects[i];
- try {
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("5.0." + project.getFullPath(), e);
- }
- }
- for (int i = 0; i < resources.length; i++) {
- IResource resource = resources[i];
- if (resource.getType() != IResource.PROJECT) {
- Object v = table.get(resource.getFullPath());
- assertNotNull("5.1." + resource.getFullPath(), v);
- long old = ((Long) v).longValue();
- assertEquals("5.2." + resource.getFullPath(), old, resource.getModificationStamp());
- }
- }
-
- // touch all the resources. this will update the modification stamp
- final Map tempTable = new HashMap(resources.length);
- for (int i = 0; i < resources.length; i++) {
- IResource resource = resources[i];
- if (resource.getType() != IResource.ROOT) {
- try {
- resource.touch(getMonitor());
- } catch (CoreException e) {
- fail("6.2", e);
- }
- long stamp = resource.getModificationStamp();
- Object v = table.get(resource.getFullPath());
- assertNotNull("6.0." + resource.getFullPath(), v);
- long old = ((Long) v).longValue();
- assertTrue("6.1." + resource.getFullPath(), old != stamp);
- // cache for next time
- tempTable.put(resource.getFullPath(), new Long(stamp));
- }
- }
- table.clear();
- table.putAll(tempTable);
-
- // mark all resources as non-local. all non-local resources have a null
- // stamp
- try {
- getWorkspace().getRoot().setLocal(false, IResource.DEPTH_INFINITE, getMonitor());
- } catch (CoreException e) {
- fail("7.1", e);
- }
- IResourceVisitor visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- //projects and root are always local
- if (resource.getType() == IResource.ROOT || resource.getType() == IResource.PROJECT) {
- assertTrue("7.2" + resource.getFullPath(), IResource.NULL_STAMP != resource.getModificationStamp());
- } else {
- assertEquals("7.3." + resource.getFullPath(), IResource.NULL_STAMP, resource.getModificationStamp());
- }
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor, IResource.DEPTH_INFINITE, false);
- } catch (CoreException e) {
- fail("7.4", e);
- }
-
- // mark all resources as local. none should have a null stamp and it
- // should be different than
- // the last one
- try {
- getWorkspace().getRoot().setLocal(true, IResource.DEPTH_INFINITE, getMonitor());
- } catch (CoreException e) {
- fail("8.1", e);
- }
- tempTable.clear();
- for (int i = 0; i < resources.length; i++) {
- IResource resource = resources[i];
- if (resource.getType() != IResource.ROOT) {
- long stamp = resource.getModificationStamp();
- assertTrue("8.2." + resource.getFullPath(), stamp != IResource.NULL_STAMP);
- Object v = table.get(resource.getFullPath());
- assertNotNull("8.3." + resource.getFullPath(), v);
- long old = ((Long) v).longValue();
- assertTrue("8.4." + resource.getFullPath(), old != IResource.NULL_STAMP);
- tempTable.put(resource.getFullPath(), new Long(stamp));
- }
- }
- table.clear();
- table.putAll(tempTable);
- //set local on resources that are already local, this should not
- // affect the modification stamp
- try {
- getWorkspace().getRoot().setLocal(true, IResource.DEPTH_INFINITE, getMonitor());
- } catch (CoreException e) {
- fail("9.1", e);
- }
- for (int i = 0; i < resources.length; i++) {
- IResource resource = resources[i];
- if (resource.getType() != IResource.ROOT) {
- long newStamp = resource.getModificationStamp();
- assertTrue("9.2." + resource.getFullPath(), newStamp != IResource.NULL_STAMP);
- Object v = table.get(resource.getFullPath());
- assertNotNull("9.3." + resource.getFullPath(), v);
- long oldStamp = ((Long) v).longValue();
- assertEquals("9.4." + resource.getFullPath(), oldStamp, newStamp);
- }
- }
-
- // delete all the resources so we can start over.
- try {
- getWorkspace().getRoot().delete(true, getMonitor());
- } catch (CoreException e) {
- fail("10.0", e);
- }
-
- // none of the resources exist yet so all the modification stamps
- // should be null
- for (int i = 0; i < resources.length; i++) {
- IResource resource = resources[i];
- if (resource.getType() != IResource.ROOT)
- assertEquals("10.1" + resource.getFullPath(), IResource.NULL_STAMP, resource.getModificationStamp());
- }
-
- // create all the resources (non-local) and ensure all stamps are null
- ensureExistsInWorkspace(resources, false);
- for (int i = 0; i < resources.length; i++) {
- IResource resource = resources[i];
- switch (resource.getType()) {
- case IResource.ROOT :
- break;
- case IResource.PROJECT :
- assertTrue("11.1." + resource.getFullPath(), resource.getModificationStamp() != IResource.NULL_STAMP);
- break;
- default :
- assertEquals("11.2." + resource.getFullPath(), IResource.NULL_STAMP, resource.getModificationStamp());
- break;
- }
- }
- // now make all resources local and re-check stamps
- try {
- getWorkspace().getRoot().setLocal(true, IResource.DEPTH_INFINITE, getMonitor());
- } catch (CoreException e) {
- fail("12.0", e);
- }
- visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- if (resource.getType() != IResource.ROOT)
- assertTrue("12.1." + resource.getFullPath(), IResource.NULL_STAMP != resource.getModificationStamp());
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor, IResource.DEPTH_INFINITE, false);
- } catch (CoreException e) {
- fail("12.2", e);
- }
- }
- /**
- * This method tests the IResource.isSynchronized() operation */
- public void testIsSynchronized() {
- //don't need auto-created resources
- try {
- getWorkspace().getRoot().delete(true, true, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- interestingResources = buildInterestingResources();
- Object[][] args = new Object[][] { interestingResources, interestingResources, interestingStates(), interestingDepths()};
- new TestPerformer("IResourceTest.testRefreshLocal") {
- public Object invokeMethod(Object[] args, int count) throws CoreException {
- IResource receiver = (IResource) args[0];
- IResource target = (IResource) args[1];
- int state = ((Integer) args[2]).intValue();
- int depth = ((Integer) args[3]).intValue();
- if (!makesSense(receiver, target, state, depth))
- return null;
- setupBeforeState(receiver, target, state, depth, false);
- boolean result = receiver.isSynchronized(depth);
- return result ? Boolean.TRUE : Boolean.FALSE;
- }
- public boolean wasSuccess(Object[] args, Object result, Object[] oldState) {
- if (result == null)
- return true; //combination didn't make sense
- boolean bResult = ((Boolean) result).booleanValue();
- IResource receiver = (IResource) args[0];
- IResource target = (IResource) args[1];
- int state = ((Integer) args[2]).intValue();
- int depth = ((Integer) args[3]).intValue();
-
- //only !synchronized if target is same as or child of receiver
- if (!(receiver.equals(target) || hasParent(target, receiver, depth)))
- return bResult;
- switch (state) {
- case S_UNCHANGED :
- case S_DOES_NOT_EXIST :
- //these cases correspond to being in sync
- return bResult;
- case S_WORKSPACE_ONLY :
- case S_FILESYSTEM_ONLY :
- case S_CHANGED :
- case S_FOLDER_TO_FILE :
- case S_FILE_TO_FOLDER :
- //these cases correspond to being out of sync
- return !bResult;
- default :
- //shouldn't be possible
- return false;
- }
- }
- public boolean shouldFail(Object[] args, int count) {
- return false;
- }
- public void cleanUp(Object[] args, int count) {
- cleanUpAfterRefreshTest(args);
- }
- }
- .performTest(args);
- }
- /**
- * Performs black box testing of the following method: void move(IPath,
- * boolean, IProgressMonitor)
- */
- public void testMove() {
- Object[][] inputs = new Object[][] { interestingResources, interestingPaths, TRUE_AND_FALSE, PROGRESS_MONITORS };
- new TestPerformer("IResourceTest.testMove") {
- public boolean shouldFail(Object[] args, int count) {
- IResource resource = (IResource) args[0];
- IPath destination = (IPath) args[1];
- // Boolean force = (Boolean) args[2];
- if (!resource.isAccessible())
- return true;
- if (isProject(resource)) {
- if (destination.isAbsolute() ? destination.segmentCount() != 2 : destination.segmentCount() != 1)
- return true;
- return !getWorkspace().validateName(destination.segment(0), IResource.PROJECT).isOK();
- }
- File destinationParent =
- destination.isAbsolute() ? destination.removeLastSegments(1).toFile() : resource.getLocation().removeLastSegments(1).append(destination.removeLastSegments(1)).toFile();
- File destinationFile = destination.isAbsolute() ? destination.toFile() : resource.getLocation().removeLastSegments(1).append(destination).removeTrailingSeparator().toFile();
- return !destinationParent.exists() || !destinationParent.isDirectory() || destinationFile.exists() || destinationFile.toString().startsWith(resource.getLocation().toFile().toString());
- }
- public Object[] interestingOldState(Object[] args) {
- return null;
- }
- public Object invokeMethod(Object[] args, int count) throws Exception {
- IResource resource = (IResource) args[0];
- IPath destination = (IPath) args[1];
- Boolean force = (Boolean) args[2];
- IProgressMonitor monitor = (IProgressMonitor) args[3];
- if (monitor instanceof FussyProgressMonitor)
- ((FussyProgressMonitor) monitor).prepare();
- resource.move(destination, force.booleanValue(), monitor);
- if (monitor instanceof FussyProgressMonitor)
- ((FussyProgressMonitor) monitor).sanityCheck();
- return null;
- }
- public boolean wasSuccess(Object[] args, Object result, Object[] oldState) {
- return true;
- }
- }
- .performTest(inputs);
- }
- public void testMultiCreation() {
-
- final IProject project = getWorkspace().getRoot().getProject("bar");
- final IResource[] resources = buildResources(project, new String[] { "a/", "a/b" });
- // create the project. Have to do this outside the resource operation
- // to ensure that things are setup properly (e.g., add the delta
- // listener)
- try {
- project.create(null);
- project.open(null);
- } catch (CoreException e) {
- fail("1.2", e);
- }
- assertExistsInWorkspace("1.3", project);
- // define an operation which will create a bunch of resources including
- // a project.
- for (int i = 0; i < resources.length; i++) {
- IResource resource = resources[i];
- try {
- switch (resource.getType()) {
- case IResource.FILE :
- ((IFile) resource).create(null, false, getMonitor());
- break;
- case IResource.FOLDER :
- ((IFolder) resource).create(false, true, getMonitor());
- break;
- case IResource.PROJECT :
- ((IProject) resource).create(getMonitor());
- break;
- }
- } catch (CoreException e) {
- fail("1.4: " + resource.getFullPath(), e);
- }
- }
- assertExistsInWorkspace("1.5", resources);
- try {
- project.delete(true, false, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
- }
- /**
- * Test that opening an closing a project does not affect the description
- * file.
- */
- public void testProjectDescriptionFileModification() throws CoreException {
- IProject project = getWorkspace().getRoot().getProject("P1");
- IFile file = project.getFile(IProjectDescription.DESCRIPTION_FILE_NAME);
- project.create(null);
- project.open(null);
- long stamp = file.getModificationStamp();
- project.close(null);
- project.open(null);
- assertEquals(stamp, file.getModificationStamp());
- }
- public void testReadOnly() {
- // We need to know whether or not we can unset the read-only flag
- // in order to perform this test.
- if (!CoreFileSystemLibrary.usingNatives())
- return;
- IProject project = getWorkspace().getRoot().getProject("Project");
- IFile file = project.getFile("target");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- file.create(getRandomContents(), true, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- // file
- assertTrue("1.0", !file.isReadOnly());
- file.setReadOnly(true);
- assertTrue("1.2", file.isReadOnly());
- file.setReadOnly(false);
- assertTrue("1.4", !file.isReadOnly());
-
- // folder
- assertTrue("2.0", !project.isReadOnly());
- project.setReadOnly(true);
- assertTrue("2.2", project.isReadOnly());
- project.setReadOnly(false);
- assertTrue("2.4", !project.isReadOnly());
-
- /* remove trash */
- try {
- project.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
- }
- /**
- * This method tests the IResource.refreshLocal() operation */
- public void testRefreshLocal() {
- //don't need auto-created resources
- try {
- getWorkspace().getRoot().delete(true, true, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- interestingResources = buildInterestingResources();
- Object[][] args = new Object[][] { interestingResources, interestingResources, interestingStates(), interestingDepths()};
- new TestPerformer("IResourceTest.testRefreshLocal") {
- public Object invokeMethod(Object[] args, int count) throws CoreException {
- IResource receiver = (IResource) args[0];
- IResource target = (IResource) args[1];
- int state = ((Integer) args[2]).intValue();
- int depth = ((Integer) args[3]).intValue();
- if (!makesSense(receiver, target, state, depth))
- return null;
- setupBeforeState(receiver, target, state, depth, true);
- receiver.refreshLocal(depth, getMonitor());
- return Boolean.TRUE;
- }
- public boolean wasSuccess(Object[] args, Object result, Object[] oldState) {
- if (result == null)
- return true; //permutation didn't make sense
- IResource receiver = (IResource) args[0];
- IResource target = (IResource) args[1];
- int state = ((Integer) args[2]).intValue();
- int depth = ((Integer) args[3]).intValue();
- return checkAfterState(receiver, target, state, depth);
- }
- public boolean shouldFail(Object[] args, int count) {
- return false;
- }
- public void cleanUp(Object[] args, int count) {
- cleanUpAfterRefreshTest(args);
- }
- }
- .performTest(args);
- }
- public void testRefreshLocalWithDepth() {
- IProject project = getWorkspace().getRoot().getProject("Project");
- IFolder folder = project.getFolder("Folder");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- folder.create(true, true, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- String[] hierarchy = { "Folder/", "Folder/Folder/", "Folder/Folder/Folder/", "Folder/Folder/Folder/Folder/" };
- IResource[] resources = buildResources(folder, hierarchy);
- ensureExistsInFileSystem(resources);
- assertDoesNotExistInWorkspace("3.0", resources);
-
- try {
- folder.refreshLocal(IResource.DEPTH_ONE, getMonitor());
- } catch (CoreException e) {
- fail("4.0", e);
- }
-
- assertExistsInWorkspace("5.0", folder.getFolder("Folder"));
- assertDoesNotExistInWorkspace("5.1", folder.getFolder("Folder/Folder"));
- }
- /**
- * This method tests the IResource.refreshLocal() operation */
- public void testRefreshWithMissingParent() throws CoreException {
- /**
- * Add a folder and file to the filesystem. Call refreshLocal on the
- * file, when neither of them exist in the workspace.
- */
- IProject project1 = getWorkspace().getRoot().getProject("Project");
- project1.create(getMonitor());
- project1.open(getMonitor());
-
- IFolder folder = project1.getFolder("Folder");
- IFile file = folder.getFile("File");
-
- ensureExistsInFileSystem(file);
-
- file.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- }
- /**
- * This method tests the IResource.setLocalTimeStamp() operation */
- public void testSetLocalTimeStamp() {
- //don't need auto-created resources
- try {
- getWorkspace().getRoot().delete(true, true, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- interestingResources = buildInterestingResources();
- Long[] interestingTimes = new Long[] { new Long(-1), new Long(System.currentTimeMillis()-1000), new Long(System.currentTimeMillis()-100), new Long(System.currentTimeMillis()), new Long(Integer.MAX_VALUE * 512L)};
- Object[][] args = new Object[][] { interestingResources, interestingTimes };
- new TestPerformer("IResourceTest.testRefreshLocal") {
- public Object invokeMethod(Object[] args, int count) throws CoreException {
- IResource receiver = (IResource) args[0];
- long time = ((Long) args[1]).longValue();
- long actual = receiver.setLocalTimeStamp(time);
- return new Long(actual);
- }
- public boolean wasSuccess(Object[] args, Object result, Object[] oldState) {
- IResource receiver = (IResource) args[0];
- if (receiver.getType() == IResource.ROOT)
- return true;
- long time = ((Long) args[1]).longValue();
- long actual = ((Long) result).longValue();
- if (actual != receiver.getLocalTimeStamp())
- return false;
- if (Math.abs(actual - time) > 2000)
- return false;
- return true;
- }
- public boolean shouldFail(Object[] args, int count) {
- long time = ((Long) args[1]).longValue();
- return time < 0;
- }
- public void cleanUp(Object[] args, int count) {
- }
- }
- .performTest(args);
- }
-
- /**
- * Performs black box testing of the following methods:
- * isTeamPrivateMember() and setTeamPrivateMember(boolean)
- */
- public void testTeamPrivateMember() {
- IWorkspaceRoot root = getWorkspace().getRoot();
- IProject project = root.getProject("Project");
- IFolder folder = project.getFolder("folder");
- IFile file = folder.getFile("target");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- folder.create(true, true, getMonitor());
- file.create(getRandomContents(), true, getMonitor());
-
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- // all resources have independent team private member flag
- // all non-TPM by default; check each type
- try {
-
- // root - cannot be made team private member
- assertTrue("2.1.1", !root.isTeamPrivateMember());
- assertTrue("2.1.2", !project.isTeamPrivateMember());
- assertTrue("2.1.3", !folder.isTeamPrivateMember());
- assertTrue("2.1.4", !file.isTeamPrivateMember());
- root.setTeamPrivateMember(true);
- assertTrue("2.2.1", !root.isTeamPrivateMember());
- assertTrue("2.2.2", !project.isTeamPrivateMember());
- assertTrue("2.2.3", !folder.isTeamPrivateMember());
- assertTrue("2.2.4", !file.isTeamPrivateMember());
- root.setTeamPrivateMember(false);
- assertTrue("2.3.1", !root.isTeamPrivateMember());
- assertTrue("2.3.2", !project.isTeamPrivateMember());
- assertTrue("2.3.3", !folder.isTeamPrivateMember());
- assertTrue("2.3.4", !file.isTeamPrivateMember());
-
- // project - cannot be made team private member
- project.setTeamPrivateMember(true);
- assertTrue("3.1.1", !root.isTeamPrivateMember());
- assertTrue("3.1.2", !project.isTeamPrivateMember());
- assertTrue("3.1.3", !folder.isTeamPrivateMember());
- assertTrue("3.1.4", !file.isTeamPrivateMember());
- project.setTeamPrivateMember(false);
- assertTrue("3.2.1", !root.isTeamPrivateMember());
- assertTrue("3.2.2", !project.isTeamPrivateMember());
- assertTrue("3.2.3", !folder.isTeamPrivateMember());
- assertTrue("3.2.4", !file.isTeamPrivateMember());
-
- // folder
- folder.setTeamPrivateMember(true);
- assertTrue("4.1.1", !root.isTeamPrivateMember());
- assertTrue("4.1.2", !project.isTeamPrivateMember());
- assertTrue("4.1.3", folder.isTeamPrivateMember());
- assertTrue("4.1.4", !file.isTeamPrivateMember());
- folder.setTeamPrivateMember(false);
- assertTrue("4.2.1", !root.isTeamPrivateMember());
- assertTrue("4.2.2", !project.isTeamPrivateMember());
- assertTrue("4.2.3", !folder.isTeamPrivateMember());
- assertTrue("4.2.4", !file.isTeamPrivateMember());
-
- // file
- file.setTeamPrivateMember(true);
- assertTrue("5.1.1", !root.isTeamPrivateMember());
- assertTrue("5.1.2", !project.isTeamPrivateMember());
- assertTrue("5.1.3", !folder.isTeamPrivateMember());
- assertTrue("5.1.4", file.isTeamPrivateMember());
- file.setTeamPrivateMember(false);
- assertTrue("5.2.1", !root.isTeamPrivateMember());
- assertTrue("5.2.2", !project.isTeamPrivateMember());
- assertTrue("5.2.3", !folder.isTeamPrivateMember());
- assertTrue("5.2.4", !file.isTeamPrivateMember());
-
- } catch (CoreException e) {
- fail("6.0", e);
- }
-
- /* remove trash */
- try {
- project.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("7.0", e);
- }
-
- // isTeamPrivateMember should return false when resource does not exist
- assertTrue("8.1", !project.isTeamPrivateMember());
- assertTrue("8.2", !folder.isTeamPrivateMember());
- assertTrue("8.3", !file.isTeamPrivateMember());
-
- // setTeamPrivateMember should fail when resource does not exist
- try {
- project.setTeamPrivateMember(false);
- assertTrue("9.1", false);
- } catch (CoreException e) {
- // pass
- }
- try {
- folder.setTeamPrivateMember(false);
- assertTrue("9.2", false);
- } catch (CoreException e) {
- // pass
- }
- try {
- file.setTeamPrivateMember(false);
- assertTrue("9.3", false);
- } catch (CoreException e) {
- // pass
- }
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ISynchronizerTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ISynchronizerTest.java
deleted file mode 100644
index cdd8914..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ISynchronizerTest.java
+++ /dev/null
@@ -1,1009 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import java.io.*;
-import java.io.File;
-import java.util.*;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.resources.*;
-import org.eclipse.core.internal.watson.IPathRequestor;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-//
-public class ISynchronizerTest extends EclipseWorkspaceTest {
- public static int NUMBER_OF_PARTNERS = 100;
- public IResource[] resources;
-public ISynchronizerTest() {
-}
-public ISynchronizerTest(String name) {
- super(name);
-}
-protected void assertEquals(String message, byte[] b1, byte[] b2) {
- assertTrue(message, b1.length == b2.length);
- for (int i = 0; i < b1.length; i++)
- assertTrue(message, b1[i] == b2[i]);
-}
-/**
- * Return a string array which defines the hierarchy of a tree.
- * Folder resources must have a trailing slash.
- */
-public String[] defineHierarchy() {
- return new String[] { "/", "1/", "1/1", "1/2/", "1/2/1", "1/2/2/", "2/", "2/1", "2/2/", "2/2/1", "2/2/2/" };
-}
-/*
- * Internal method used for flushing all sync information for a particular resource
- * and its children.
- */
-protected void flushAllSyncInfo(final IResource root) throws CoreException {
- assertNotNull(root);
-
- final ISynchronizer synchronizer = getWorkspace().getSynchronizer();
- final QualifiedName[] partners = synchronizer.getPartners();
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- IResourceVisitor visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- for (int i = 0; i < partners.length; i++)
- synchronizer.setSyncInfo(partners[i], resource, null);
- return true;
- }
- };
- root.accept(visitor, IResource.DEPTH_INFINITE, true);
- }
- };
- getWorkspace().run(body, null);
-}
-public void setUp() throws Exception {
- super.setUp();
- resources = createHierarchy();
-}
-public static Test suite() {
- TestSuite suite = new TestSuite(ISynchronizerTest.class);
- return suite;
-}
-public void tearDown() throws Exception {
- // remove all registered sync partners so we don't create
- // phantoms when we delete
- QualifiedName[] names = getWorkspace().getSynchronizer().getPartners();
- for (int i = 0; i < names.length; i++)
- getWorkspace().getSynchronizer().remove(names[i]);
-
- // delete the root and everything under it
- super.tearDown();
-}
-public void testDeleteResources() {
- final QualifiedName qname = new QualifiedName("org.eclipse.core.tests.resources", "myTarget");
- final ISynchronizer synchronizer = ResourcesPlugin.getWorkspace().getSynchronizer();
-
- // register the target so now we should be able to do stuff
- synchronizer.add(qname);
-
- // setup the sync bytes
- final Hashtable table = new Hashtable(10);
- IResourceVisitor visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- if (resource.getType() == IResource.ROOT)
- return true;
- byte[] b = getRandomString().getBytes();
- table.put(resource.getFullPath(), b);
- synchronizer.setSyncInfo(qname, resource, b);
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor);
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- // get the info and ensure its the same
- visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- try {
- byte[] actual = synchronizer.getSyncInfo(qname, resource);
- if (resource.getType() == IResource.ROOT) {
- assertNull("1.0." + resource.getFullPath(), actual);
- return true;
- } else
- assertNotNull("1.1." + resource.getFullPath(), actual);
- byte[] expected = (byte[]) table.get(resource.getFullPath());
- assertEquals("1.2." + resource.getFullPath(), expected, actual);
- } catch (CoreException e) {
- fail("1.3." + resource.getFullPath(), e);
- }
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor);
- } catch (CoreException e) {
- fail("1.4", e);
- }
-
- // delete all resources under the projects.
- final IProject[] projects = getWorkspace().getRoot().getProjects();
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- for (int i = 0; i < projects.length; i++) {
- IResource[] children = projects[i].members();
- for (int j = 0; j < children.length; j++)
- children[j].delete(false, getMonitor());
- }
- }
- };
- try {
- getWorkspace().run(body, getMonitor());
- } catch (CoreException e) {
- fail("2.99", e);
- }
-
- // sync info should remain for the resources since they are now phantoms
- visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- try {
- byte[] actual = synchronizer.getSyncInfo(qname, resource);
- if (resource.getType() == IResource.ROOT) {
- assertNull("3.0", actual);
- return true;
- } else
- assertNotNull("3.1." + resource.getFullPath(), actual);
- byte[] expected = (byte[]) table.get(resource.getFullPath());
- assertEquals("3.2." + resource.getFullPath(), expected, actual);
- } catch (CoreException e) {
- fail("3.3." + resource.getFullPath(), e);
- }
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor);
- } catch (CoreException e) {
- fail("3.4", e);
- }
-
- // delete the projects
- for (int i = 0; i < projects.length; i++) {
- try {
- projects[i].delete(false, getMonitor());
- } catch (CoreException e) {
- ResourcesPlugin.getPlugin().getLog().log(e.getStatus());
- fail("4.0", e);
- }
- }
-
- // sync info should be gone since projects can't become phantoms
- visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- try {
- assertNull("5.0." + resource.getFullPath(), synchronizer.getSyncInfo(qname, resource));
- } catch (CoreException e) {
- fail("5.1." + resource.getFullPath(), e);
- }
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor);
- } catch (CoreException e) {
- fail("5.2", e);
- }
-}
-public void testDeleteResources2() {
- final QualifiedName qname = new QualifiedName("org.eclipse.core.tests.resources", "myTarget");
- final ISynchronizer synchronizer = ResourcesPlugin.getWorkspace().getSynchronizer();
-
- // register the target so now we should be able to do stuff
- synchronizer.add(qname);
-
- // setup the sync bytes
- final Hashtable table = new Hashtable(10);
- IResourceVisitor visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- if (resource.getType() == IResource.ROOT)
- return true;
- byte[] b = getRandomString().getBytes();
- table.put(resource.getFullPath(), b);
- synchronizer.setSyncInfo(qname, resource, b);
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor);
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- // get the info and ensure its the same
- visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- try {
- byte[] actual = synchronizer.getSyncInfo(qname, resource);
- if (resource.getType() == IResource.ROOT) {
- assertNull("1.0." + resource.getFullPath(), actual);
- return true;
- } else
- assertNotNull("1.1." + resource.getFullPath(), actual);
- byte[] expected = (byte[]) table.get(resource.getFullPath());
- assertEquals("1.2." + resource.getFullPath(), expected, actual);
- } catch (CoreException e) {
- fail("1.3." + resource.getFullPath(), e);
- }
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor);
- } catch (CoreException e) {
- fail("1.4", e);
- }
-
- // delete all resources under the projects.
- final IProject[] projects = getWorkspace().getRoot().getProjects();
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- for (int i = 0; i < projects.length; i++) {
- IResource[] children = projects[i].members();
- for (int j = 0; j < children.length; j++) {
- if (!children[j].getName().equals(IProjectDescription.DESCRIPTION_FILE_NAME))
- children[j].delete(false, getMonitor());
- }
- }
- }
- };
- try {
- getWorkspace().run(body, getMonitor());
- } catch (CoreException e) {
- fail("2.99", e);
- }
-
- // sync info should remain for the resources since they are now phantoms
- visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- try {
- byte[] actual = synchronizer.getSyncInfo(qname, resource);
- if (resource.getType() == IResource.ROOT) {
- assertNull("3.0", actual);
- return true;
- } else
- assertNotNull("3.1." + resource.getFullPath(), actual);
- byte[] expected = (byte[]) table.get(resource.getFullPath());
- assertEquals("3.2." + resource.getFullPath(), expected, actual);
- } catch (CoreException e) {
- fail("3.3." + resource.getFullPath(), e);
- }
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor);
- } catch (CoreException e) {
- fail("3.4", e);
- }
-
- // remove the sync info for the immediate children of the projects.
- body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- for (int i = 0; i < projects.length; i++) {
- IResource[] children = projects[i].members(true);
- for (int j = 0; j < children.length; j++)
- synchronizer.setSyncInfo(qname, children[j], null);
- }
- }
- };
- try {
- getWorkspace().run(body, getMonitor());
- } catch (CoreException e) {
- fail("4.99", e);
- }
-
- // there should be no sync info for any resources except the project
- visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- int type = resource.getType();
- if (type == IResource.ROOT || type == IResource.PROJECT)
- return true;
- if (type == IResource.FILE && resource.getParent().getType() == IResource.PROJECT && resource.getName().equals(IProjectDescription.DESCRIPTION_FILE_NAME))
- return true;
- assertNull("5.0." + resource.getFullPath(), synchronizer.getSyncInfo(qname, resource));
- return true;
- }
- };
-
- try {
- getWorkspace().getRoot().accept(visitor, IResource.DEPTH_INFINITE, true);
- } catch (CoreException e) {
- fail("5.99", e);
- }
-}
-public void testMoveResource() {
- final QualifiedName qname = new QualifiedName("org.eclipse.core.tests.resources", "myTarget");
- final ISynchronizer synchronizer = ResourcesPlugin.getWorkspace().getSynchronizer();
-
- // cleanup auto-created resources
- try {
- getWorkspace().getRoot().delete(true, getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- // setup
- IResource[] resources = buildResources(getWorkspace().getRoot(), new String[] { "/Foo", "/Foo/file.txt" });
- IProject project = (IProject) resources[0];
- IFile source = (IFile) resources[1];
- // create in workspace
- ensureExistsInWorkspace(resources, true);
-
- // register partner and add sync info
- synchronizer.add(qname);
- byte[] b = new byte[] { 1, 2, 3, 4 };
- try {
- synchronizer.setSyncInfo(qname, source, b);
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- // move the file
- IFile destination = project.getFile("newFile.txt");
- try {
- source.move(destination.getFullPath(), true, getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
-
- // check sync info
- try {
- byte[] old = synchronizer.getSyncInfo(qname, source);
- assertNotNull("4.0", old);
- assertEquals("4.1", b, old);
- assertNull("4.2", synchronizer.getSyncInfo(qname, destination));
- } catch (CoreException e) {
- fail("4.3", e);
- }
-}
-public void testMoveResource2() {
- final QualifiedName qname = new QualifiedName("org.eclipse.core.tests.resources", "myTarget");
- final ISynchronizer synchronizer = ResourcesPlugin.getWorkspace().getSynchronizer();
-
- // cleanup auto-created resources
- try {
- getWorkspace().getRoot().delete(true, getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- // setup
- IResource[] resources = buildResources(getWorkspace().getRoot(), new String[] { "/Foo", "/Foo/file.txt" });
- IProject sourceProject = (IProject) resources[0];
- IFile sourceFile = (IFile) resources[1];
- // create in workspace
- ensureExistsInWorkspace(resources, true);
-
- // register partner and add sync info
- synchronizer.add(qname);
- byte[] b = new byte[] { 1, 2, 3, 4 };
- try {
- synchronizer.setSyncInfo(qname, sourceProject, b);
- synchronizer.setSyncInfo(qname, sourceFile, b);
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- // move the file
- IFile destFile = sourceProject.getFile("newFile.txt");
- try {
- sourceFile.move(destFile.getFullPath(), true, getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
-
- // check sync info
- try {
- byte[] old = synchronizer.getSyncInfo(qname, sourceFile);
- assertNotNull("4.0", old);
- assertEquals("4.1", b, old);
- assertNull("4.2", synchronizer.getSyncInfo(qname, destFile));
- } catch (CoreException e) {
- fail("4.3", e);
- }
-
- // move the file back
- try {
- destFile.move(sourceFile.getFullPath(), true, getMonitor());
- } catch (CoreException e) {
- fail("5.0", e);
- }
-
- // check the sync info
- try {
- byte[] old = synchronizer.getSyncInfo(qname, sourceFile);
- assertNotNull("6.0", old);
- assertEquals("6.1", b, old);
- assertNull("6.2", synchronizer.getSyncInfo(qname, destFile));
- } catch (CoreException e) {
- fail("6.3", e);
- }
-
- // rename the file and ensure that the sync info is moved with it
- IProject destProject = getWorkspace().getRoot().getProject("newProject");
- try {
- sourceProject.move(destProject.getFullPath(), true, getMonitor());
- } catch (CoreException e) {
- fail("7.0", e);
- }
- try {
- assertNull("7.1", synchronizer.getSyncInfo(qname, sourceProject));
- assertNull("7.2", synchronizer.getSyncInfo(qname, sourceFile));
- byte[] old = synchronizer.getSyncInfo(qname, destProject.getFile(sourceFile.getName()));
- assertNotNull("7.3", old);
- assertEquals("7.4", b, old);
- old = synchronizer.getSyncInfo(qname, destProject);
- assertNotNull("7.5", old);
- assertEquals("7.6", b, old);
- } catch (CoreException e) {
- fail("7.3", e);
- }
-
-}
-public void testRegistration() {
- // setup
- QualifiedName[] partners = new QualifiedName[NUMBER_OF_PARTNERS];
- for (int i = 0; i < NUMBER_OF_PARTNERS; i++) {
- QualifiedName name = new QualifiedName("org.eclipse.core.deployment", "myTarget" + i);
- partners[i] = name;
- }
- ISynchronizer synchronizer = ResourcesPlugin.getWorkspace().getSynchronizer();
-
- // register the targets...twice to ensure dups aren't registered
- for (int i = 0; i < NUMBER_OF_PARTNERS; i++) {
- synchronizer.add(partners[i]);
- synchronizer.add(partners[i]);
- }
-
- // get the array of targets
- QualifiedName[] list = synchronizer.getPartners();
- assertNotNull("3.0", list);
- assertEquals("3.1", NUMBER_OF_PARTNERS, list.length);
-
- // unregister all targets
- for (int i = 0; i < NUMBER_OF_PARTNERS; i++)
- synchronizer.remove(partners[i]);
- assertEquals("4.0", 0, synchronizer.getPartners().length);
-}
-public void testSave() {
- final Hashtable table = new Hashtable(10);
- final QualifiedName qname = new QualifiedName("org.eclipse.core.tests.resources", "myTarget");
- final Synchronizer synchronizer = (Synchronizer) ResourcesPlugin.getWorkspace().getSynchronizer();
-
- // register the sync partner and set the sync info on the resources
- synchronizer.add(qname);
- IResourceVisitor visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- if (resource.getType() == IResource.ROOT)
- return true;
- try {
- byte[] b = getRandomString().getBytes();
- synchronizer.setSyncInfo(qname, resource, b);
- table.put(resource.getFullPath(), b);
- } catch (CoreException e) {
- fail("0.0." + resource.getFullPath(), e);
- }
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor);
- } catch (CoreException e) {
- fail("0.1", e);
- }
-
- // write out the data
- File file = Platform.getLocation().append(".testsyncinfo").toFile();
- OutputStream fileOutput = null;
- DataOutputStream o1 = null;
- try {
- fileOutput = new FileOutputStream(file);
- o1 = new DataOutputStream(fileOutput);
- } catch (IOException e) {
- if (fileOutput != null)
- try {
- fileOutput.close();
- } catch (IOException e2) {
- }
- fail("1.0", e);
- }
- final DataOutputStream output = o1;
- final List list = new ArrayList(5);
- visitor = new IResourceVisitor() {
- public boolean visit(final IResource resource) throws CoreException {
- try {
- ResourceInfo info = ((Resource) resource).getResourceInfo(false, false);
- if (info == null)
- return true;
- IPathRequestor requestor = new IPathRequestor() {
- public IPath requestPath() {
- return resource.getFullPath();
- }
- public String requestName() {
- return resource.getName();
- }
- };
- synchronizer.saveSyncInfo(info, requestor, output, list);
- } catch (IOException e) {
- fail("1.1", e);
- }
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor);
- } catch (CoreException e) {
- fail("1.2", e);
- } finally {
- try {
- output.close();
- } catch (IOException e) {
- fail("1.3", e);
- }
- }
-
- // flush the sync info in memory
- try {
- flushAllSyncInfo(getWorkspace().getRoot());
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- // read in the data
- try {
- InputStream fileInput = new FileInputStream(file);
- final DataInputStream input = new DataInputStream(fileInput);
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- SyncInfoReader reader = new SyncInfoReader((Workspace) getWorkspace(), synchronizer);
- try {
- reader.readSyncInfo(input);
- } catch (IOException e) {
- fail("3.0", e);
- }
- }
- };
- try {
- getWorkspace().run(body, getMonitor());
- } finally {
- try {
- input.close();
- } catch (IOException e) {
- fail("3.1", e);
- }
- }
- } catch (FileNotFoundException e) {
- fail("3.2", e);
- } catch (CoreException e) {
- fail("3.3", e);
- }
-
- // confirm the sync bytes are the same
- visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- byte[] actual = synchronizer.getSyncInfo(qname, resource);
- if (resource.getType() == IResource.ROOT) {
- assertNull("4.0", actual);
- return true;
- } else
- assertNotNull("4.1." + resource.getFullPath(), actual);
- byte[] expected = (byte[]) table.get(resource.getFullPath());
- assertEquals("4.2." + resource.getFullPath(), expected, actual);
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor);
- } catch (CoreException e) {
- fail("4.3", e);
- }
-}
-public void testSnap() {
-/*
- final Hashtable table = new Hashtable(10);
- final QualifiedName qname = new QualifiedName("org.eclipse.core.tests.resources", "myTarget");
- final Synchronizer synchronizer = (Synchronizer) ResourcesPlugin.getWorkspace().getSynchronizer();
-
- // register the sync partner and set the sync info on the resources
- synchronizer.add(qname);
- IResourceVisitor visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- if (resource.getType() == IResource.ROOT)
- return true;
- try {
- byte[] b = getRandomString().getBytes();
- synchronizer.setSyncInfo(qname, resource, b);
- table.put(resource.getFullPath(), b);
- } catch (CoreException e) {
- fail("0.0." + resource.getFullPath(), e);
- }
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor);
- } catch (CoreException e) {
- fail("0.1", e);
- }
-
- // write out the data
- File file = Platform.getLocation().append(".testsyncinfo.snap").toFile();
- SafeChunkyOutputStream safeOutput = null;
- DataOutputStream o1 = null;
- try {
- safeOutput = new SafeChunkyOutputStream(file);
- o1 = new DataOutputStream(safeOutput);
- } catch (IOException e) {
- if (safeOutput != null)
- try {
- safeOutput.close();
- } catch (IOException e2) {
- }
- fail("1.0", e);
- }
- final DataOutputStream output = o1;
- visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- try {
- synchronizer.snapSyncInfo(resource, output);
- } catch (IOException e) {
- fail("1.1", e);
- }
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor);
- safeOutput.succeed();
- } catch (CoreException e) {
- fail("1.2", e);
- } catch (IOException e) {
- fail("1.3", e);
- } finally {
- try {
- output.close();
- } catch (IOException e) {
- fail("1.4", e);
- }
- }
-
- // flush the sync info in memory
- try {
- flushAllSyncInfo(getWorkspace().getRoot());
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- // read in the data
- try {
- InputStream safeInput = new SafeChunkyInputStream(file);
- final DataInputStream input = new DataInputStream(safeInput);
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- SyncInfoSnapReader reader = new SyncInfoSnapReader((Workspace) getWorkspace(), synchronizer);
- try {
- reader.readSyncInfo(input);
- } catch (IOException e) {
- fail("3.0", e);
- }
- }
- };
- try {
- getWorkspace().run(body, getMonitor());
- } finally {
- try {
- input.close();
- } catch (IOException e) {
- fail("3.1", e);
- }
- }
- } catch (FileNotFoundException e) {
- fail("3.2", e);
- } catch (IOException e) {
- fail("3.3", e);
- } catch (CoreException e) {
- fail("3.4", e);
- }
-
- // confirm the sync bytes are the same
- visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- byte[] actual = synchronizer.getSyncInfo(qname, resource);
- if (resource.getType() == IResource.ROOT) {
- assertNull("4.0", actual);
- return true;
- } else
- assertNotNull("4.1." + resource.getFullPath(), actual);
- byte[] expected = (byte[]) table.get(resource.getFullPath());
- assertEquals("4.2." + resource.getFullPath(), expected, actual);
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor);
- } catch (CoreException e) {
- fail("4.3", e);
- }
-*/
-}
-public void testSyncInfo() {
- final QualifiedName qname = new QualifiedName("org.eclipse.core.tests.resources", "myTarget");
- final ISynchronizer synchronizer = ResourcesPlugin.getWorkspace().getSynchronizer();
-
- // setup the sync bytes
- final Hashtable table = new Hashtable(10);
- IResourceVisitor visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- if (resource.getType() == IResource.ROOT)
- return true;
- byte[] b = getRandomString().getBytes();
- table.put(resource.getFullPath(), b);
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor);
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- // should not be able to set sync info before the target has been registered.
- visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- if (resource.getType() == IResource.ROOT)
- return true;
- try {
- synchronizer.setSyncInfo(qname, resource, (byte[]) table.get(resource.getFullPath()));
- assertTrue("1.0." + resource.getFullPath(), false);
- } catch (CoreException e) {
- }
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor);
- } catch (CoreException e) {
- fail("1.1", e);
- }
-
- // should not be able to get sync info before the target has been registered
- visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- try {
- synchronizer.getSyncInfo(qname, resource);
- assertTrue("2.0." + resource.getFullPath(), false);
- } catch (CoreException e) {
- }
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor);
- } catch (CoreException e) {
- fail("2.1", e);
- }
-
- // register the target so now we should be able to do stuff
- synchronizer.add(qname);
-
- // there shouldn't be any info yet
- visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- try {
- byte[] actual = synchronizer.getSyncInfo(qname, resource);
- assertNull("3.0." + resource.getFullPath(), actual);
- } catch (CoreException e) {
- fail("3.1." + resource.getFullPath(), e);
- }
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor);
- } catch (CoreException e) {
- fail("3.2", e);
- }
-
- // set the sync info
- visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- try {
- synchronizer.setSyncInfo(qname, resource, (byte[]) table.get(resource.getFullPath()));
- } catch (CoreException e) {
- fail("4.0." + resource.getFullPath(), e);
- }
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor);
- } catch (CoreException e) {
- fail("4.1", e);
- }
-
- // get the info and ensure its the same
- visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- try {
- byte[] actual = synchronizer.getSyncInfo(qname, resource);
- if (resource.getType() == IResource.ROOT) {
- assertNull("5.0", actual);
- return true;
- } else
- assertNotNull("5.1." + resource.getFullPath(), actual);
- byte[] expected = (byte[]) table.get(resource.getFullPath());
- assertEquals("5.2." + resource.getFullPath(), expected, actual);
- } catch (CoreException e) {
- fail("5.3." + resource.getFullPath(), e);
- }
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor);
- } catch (CoreException e) {
- fail("5.4", e);
- }
-
- // change the info and then set it
- visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- if (resource.getType() == IResource.ROOT)
- return true;
- try {
- byte[] b = getRandomString().getBytes();
- synchronizer.setSyncInfo(qname, resource, b);
- table.put(resource.getFullPath(), b);
- } catch (CoreException e) {
- fail("6.0", e);
- }
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor);
- } catch (CoreException e) {
- fail("6.1", e);
- }
-
- // get the new info
- visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- try {
- byte[] actual = synchronizer.getSyncInfo(qname, resource);
- if (resource.getType() == IResource.ROOT) {
- assertNull("7.0", actual);
- return true;
- } else
- assertNotNull("7.1." + resource.getFullPath(), actual);
- byte[] expected = (byte[]) table.get(resource.getFullPath());
- assertEquals("7.2." + resource.getFullPath(), expected, actual);
- } catch (CoreException e) {
- fail("7.3." + resource.getFullPath(), e);
- }
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor);
- } catch (CoreException e) {
- fail("7.4", e);
- }
-
- // cleanup
- synchronizer.remove(qname);
-
- // should not be able to get sync info because the target has been unregistered
- visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- try {
- synchronizer.getSyncInfo(qname, resource);
- assertTrue("9.0." + resource.getFullPath(), false);
- } catch (CoreException e) {
- }
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor);
- } catch (CoreException e) {
- fail("9.1", e);
- }
-}
-/**
- * Removes resources, sets sync info to <code>null</code> and ensures the
- * phantoms do not exist any more (see bug 3024)
- */
-public void testPhantomRemoval() {
- final QualifiedName partner = new QualifiedName("org.eclipse.core.tests.resources", "myTarget");
- final IWorkspace workspace = getWorkspace();
- final ISynchronizer synchronizer = workspace.getSynchronizer();
-
- // set up
- synchronizer.add(partner);
- IProject project = workspace.getRoot().getProject("MyProject");
- IFolder folder = project.getFolder("foo");
- IFile file1 = folder.getFile("file1.txt");
- IFile file2 = folder.getFile("file2.txt");
- ensureExistsInWorkspace(new IResource[] {file1, file2}, true);
-
- // sets sync info for the folder and its children
- try {
- synchronizer.setSyncInfo(partner, folder, getRandomString().getBytes());
- synchronizer.setSyncInfo(partner, file1, getRandomString().getBytes());
- synchronizer.setSyncInfo(partner, file2, getRandomString().getBytes());
- } catch (CoreException ce) {
- fail("1.0",ce);
- }
-
- // 1) tests with one child first
- assertTrue("1.1", file1.exists());
- assertTrue("1.2", !file1.isPhantom());
- // deletes file
- try {
- file1.delete(true,getMonitor());
- } catch (CoreException ce) {
- fail("2.0",ce);
- }
- // file is now a phantom resource
- assertTrue("2.1", !file1.exists());
- assertTrue("2.2", file1.isPhantom());
- // removes sync info
- try {
- synchronizer.setSyncInfo(partner, file1, null);
- } catch (CoreException ce) {
- fail("3.0",ce);
- }
- // phantom should not exist any more
- assertTrue("3.1", !file1.exists());
- assertTrue("3.2", !file1.isPhantom());
-
- // 2) tests with the folder and remaining child
- assertTrue("4.1", folder.exists());
- assertTrue("4.2", !folder.isPhantom());
- assertTrue("4.3", file2.exists());
- assertTrue("4.4", !file2.isPhantom());
- // deletes the folder and its only child
- try {
- folder.delete(true,getMonitor());
- } catch (CoreException ce) {
- fail("5.0",ce);
- }
- // both resources are now phantom resources
- assertTrue("5.1", !folder.exists());
- assertTrue("5.2", folder.isPhantom());
- assertTrue("5.3", !file2.exists());
- assertTrue("5.4", file2.isPhantom());
- // removes only folder sync info
- try {
- synchronizer.setSyncInfo(partner, folder, null);
- } catch (CoreException ce) {
- fail("6.0",ce);
- }
- // phantoms should not exist any more
- assertTrue("6.1", !folder.exists());
- assertTrue("6.2", !folder.isPhantom());
- assertTrue("6.3", !file2.exists());
- assertTrue("6.4", !file2.isPhantom());
-
- // clean-up
- synchronizer.remove(partner);
- ensureDoesNotExistInWorkspace(project);
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IWorkspaceRootTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IWorkspaceRootTest.java
deleted file mode 100644
index ff08fae..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IWorkspaceRootTest.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-public class IWorkspaceRootTest extends EclipseWorkspaceTest {
-public IWorkspaceRootTest() {
- super();
-}
-public IWorkspaceRootTest(String name) {
- super(name);
-}
-public static Test suite() {
- return new TestSuite(IWorkspaceRootTest.class);
-}
-protected void tearDown() throws Exception {
- IProject[] projects = getWorkspace().getRoot().getProjects();
- getWorkspace().delete(projects, true, null);
-}
-/**
- * Tests the API method findContainersForLocation.
- */
-public void testFindContainersForLocation() {
-}
-/**
- * Tests the API method findFilesForLocation.
- */
-public void testFindFilesForLocation() {
-}
-/**
- * Tests the API method getContainerForLocation.
- */
-public void testGetContainerForLocation() {
- IWorkspaceRoot root = getWorkspace().getRoot();
- assertEquals("1.0", root, root.getContainerForLocation(root.getLocation()));
-
-}
-/**
- * Tests the API method getFileForLocation
- */
-public void testGetFileForLocation() {
- IWorkspaceRoot root = getWorkspace().getRoot();
- assertTrue("1.0", root.getFileForLocation(root.getLocation()) == null);
-}
-public void testPersistentProperty() {
- IWorkspaceRoot root = getWorkspace().getRoot();
- String value = "this is a test property value";
- QualifiedName name = new QualifiedName("test", "testProperty");
- try {
- root.setPersistentProperty(name, value);
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- try {
- String storedValue = (String) root.getPersistentProperty(name);
- assertEquals("2.0", value, storedValue);
- } catch (CoreException e) {
- fail("2.1", e);
- }
-
- try {
- name = new QualifiedName("test", "testNonProperty");
- String storedValue = (String) root.getPersistentProperty(name);
- assertEquals("3.0", null, storedValue);
- } catch (CoreException e) {
- fail("3.1", e);
- }
-}
-/**
- * Since reading a persistent property doesn't normally happen inside an
- * operation, try it inside an operation to make sure it still works.
- * (See bug 14179).
- */
-public void testPersistentPropertyInRunnable() {
- final IWorkspaceRoot root = getWorkspace().getRoot();
- final String value = "this is a test property value";
- final QualifiedName name = new QualifiedName("test", "testProperty");
- try {
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- root.setPersistentProperty(name, value);
- }
- }, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- try {
- final String[] storedValue = new String[1];
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- storedValue[0] = (String) root.getPersistentProperty(name);
- }
- }, getMonitor());
- assertEquals("2.0", value, storedValue[0]);
- } catch (CoreException e) {
- fail("2.1", e);
- }
-
- try {
- final QualifiedName name2 = new QualifiedName("test", "testNonProperty");
- final String[] storedValue = new String[1];
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- storedValue[0] = (String) root.getPersistentProperty(name2);
- }
- }, getMonitor());
- assertEquals("3.0", null, storedValue[0]);
- } catch (CoreException e) {
- fail("3.1", e);
- }
-}
-public void testRefreshLocal() {
- IWorkspaceRoot root = getWorkspace().getRoot();
- IProject project = root.getProject("Project");
- ensureExistsInWorkspace(project, true);
- try {
- project.close(getMonitor());
- } catch(CoreException e) {
- fail("1.0", e);
- }
- //refreshing the root shouldn't fail
- try {
- root.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- } catch(CoreException e) {
- fail("1.1", e);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IWorkspaceTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IWorkspaceTest.java
deleted file mode 100644
index c62084b..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IWorkspaceTest.java
+++ /dev/null
@@ -1,1105 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.boot.BootLoader;
-import org.eclipse.core.internal.localstore.CoreFileSystemLibrary;
-import org.eclipse.core.internal.resources.TestingSupport;
-import org.eclipse.core.internal.resources.Workspace;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-public class IWorkspaceTest extends EclipseWorkspaceTest {
-
-public IWorkspaceTest() {
-}
-public IWorkspaceTest(String name) {
- super(name);
-}
-public String[] defineHierarchy() {
- return new String[] {
- "/",
- "/Project/",
- "/Project/Folder/",
- "/Project/Folder/File",
- };
-}
-/**
- * Returns the nature descriptor with the given Id, or null if not found
- */
-protected IProjectNatureDescriptor findNature(IProjectNatureDescriptor[] descriptors, String id) {
- for (int i = 0; i < descriptors.length; i++) {
- if (descriptors[i].getNatureId().equals(id)) {
- return descriptors[i];
- }
- }
- return null;
-}
-
-public static Test suite() {
- TestSuite suite = new TestSuite(IWorkspaceTest.class);
- return suite;
-}
-protected void setUp() throws Exception {
- super.setUp();
-}
-protected void tearDown() throws Exception {
- getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
- ensureDoesNotExistInWorkspace(getWorkspace().getRoot());
- super.tearDown();
-}
-/**
- * Tests handling of runnables that throw OperationCanceledException.
- */
-public void testCancelRunnable() {
- boolean cancelled = false;
- try {
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) {
- throw new OperationCanceledException();
- }
- }, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- } catch (OperationCanceledException e) {
- cancelled = true;
- }
- assertTrue("2.0", cancelled);
-}
-/**
- * Performs black box testing of the following method:
- * IStatus copy([IResource, IPath, boolean, IProgressMonitor)
- * See also testMultiCopy()
- */
-public void testCopy() throws CoreException {
- IResource[] resources = buildResources();
- IProject project = (IProject)resources[1];
- IFolder folder = (IFolder)resources[2];
- IFile file = (IFile)resources[3];
- IFile file2 = folder.getFile("File2");
- IFile file3 = folder.getFile("File3");
- IFolder folder2 = project.getFolder("Folder2");
- IFolder folderCopy = folder2.getFolder("Folder");
- IFile fileCopy = folder2.getFile("File");
- IFile file2Copy = folder2.getFile("File2");
-
- /********** FAILURE CASES ***********/
-
- //project not open
- try {
- getWorkspace().copy(new IResource[] {file}, folder.getFullPath(), false, getMonitor());
- fail("0.0");
- } catch (CoreException e) {
- }
- createHierarchy();
-
- //copy to bogus destination
- try {
- getWorkspace().copy(new IResource[] {file}, folder2.getFullPath().append("figment"), false, getMonitor());
- fail("1.0");
- } catch (CoreException e) {
- }
-
- //copy to non-existent destination
- try {
- getWorkspace().copy(new IResource[] {file}, folder2.getFullPath(), false, getMonitor());
- fail("1.1");
- } catch (CoreException e) {
- }
-
- //create the destination
- try {
- folder2.create(false, true, getMonitor());
- } catch (CoreException e) {
- fail("1.2", e);
- }
-
- //source file doesn't exist
- try {
- getWorkspace().copy(new IResource[] {file2}, folder2.getFullPath(), false, getMonitor());
- fail("1.3");
- } catch (CoreException e) {
- }
-
- //some source files don't exist
- try {
- getWorkspace().copy(new IResource[] {file, file2}, folder2.getFullPath(), false, getMonitor());
- fail("1.4");
- } catch (CoreException e) {
- }
-
- //make sure the first copy worked
- assertTrue("1.5", fileCopy.exists());
- try {
- fileCopy.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("1.6", e);
- }
-
- // create the files
- IFile projectFile = project.getFile("ProjectPhile");
- try {
- file2.create(getRandomContents(), false, getMonitor());
- file3.create(getRandomContents(), false, getMonitor());
- projectFile.create(getRandomContents(), false, getMonitor());
- } catch (CoreException e) {
- fail("1.7", e);
- }
-
- //source files aren't siblings
- try {
- getWorkspace().copy(new IResource[] {file, projectFile}, folder2.getFullPath(), false, getMonitor());
- fail("1.8");
- } catch (CoreException e) {
- }
-
- //source files contains duplicates
- try {
- getWorkspace().copy(new IResource[] {file, file2, file}, folder2.getFullPath(), false, getMonitor());
- fail("1.9");
- } catch (CoreException e) {
- }
-
- //source can't be prefix of destination
- try {
- IFolder folder3 = folder2.getFolder("Folder3");
- folder3.create(false, true, getMonitor());
- getWorkspace().copy(new IResource[] {folder2}, folder3.getFullPath(), false, getMonitor());
- fail("2.0");
- } catch (CoreException e) {
- }
-
- //target exists
- try {
- file2Copy.create(getRandomContents(), false, getMonitor());
- getWorkspace().copy(new IResource[] {file, file2}, folder2.getFullPath(), false, getMonitor());
- fail("2.1");
- } catch (CoreException e) {
- }
- ensureDoesNotExistInWorkspace(file2Copy);
- ensureDoesNotExistInFileSystem(file2Copy);
-
- //make sure the first copy worked
- fileCopy = folder2.getFile("File");
- assertTrue("2.2", fileCopy.exists());
- try {
- fileCopy.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("2.3", e);
- }
-
- //resource out of sync with filesystem
- ensureOutOfSync(file);
- try {
- getWorkspace().copy(new IResource[] {file}, folder2.getFullPath(), false, getMonitor());
- fail("2.5");
- } catch (CoreException e) {
- }
-
- // make sure "file" is in sync.
- file.refreshLocal(IResource.DEPTH_ZERO, null);
- /********** NON FAILURE CASES ***********/
-
- //empty resource list
- try {
- getWorkspace().copy(new IResource[] {}, folder2.getFullPath(), false, getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- } catch (ArrayIndexOutOfBoundsException e) {
- fail("Fails because of 1FTXL69", e);
- }
-
- //copy single file
- try {
- getWorkspace().copy(new IResource[] {file}, folder2.getFullPath(), false, getMonitor());
- } catch (CoreException e) {
- fail("3.1", e);
- }
- assertTrue("3.2", fileCopy.exists());
- ensureDoesNotExistInWorkspace(fileCopy);
- ensureDoesNotExistInFileSystem(fileCopy);
-
- //copy two files
- try {
- getWorkspace().copy(new IResource[] {file, file2}, folder2.getFullPath(), false, getMonitor());
- } catch (CoreException e) {
- fail("3.3", e);
- }
- assertTrue("3.4", fileCopy.exists());
- assertTrue("3.5", file2Copy.exists());
- ensureDoesNotExistInWorkspace(fileCopy);
- ensureDoesNotExistInWorkspace(file2Copy);
- ensureDoesNotExistInFileSystem(fileCopy);
- ensureDoesNotExistInFileSystem(file2Copy);
-
- //copy a folder
- try {
- getWorkspace().copy(new IResource[] {folder}, folder2.getFullPath(), false, getMonitor());
- } catch (CoreException e) {
- fail("3.6", e);
- }
- assertTrue("3.7", folderCopy.exists());
- try {
- assertTrue("3.8", folderCopy.members().length > 0);
- } catch (CoreException e) {
- fail("3.9", e);
- }
- ensureDoesNotExistInWorkspace(folderCopy);
- ensureDoesNotExistInFileSystem(folderCopy);
-}
-/**
- * Performs black box testing of the following method:
- * IStatus delete([IResource, boolean, IProgressMonitor)
- */
-public void testDelete() throws CoreException {
- IResource[] resources = buildResources();
- IProject project = (IProject)resources[1];
- IFolder folder = (IFolder)resources[2];
- IFile file = (IFile)resources[3];
-
- //delete non-existent resources
- assertTrue(getWorkspace().delete(new IResource[] {project, folder, file}, false, getMonitor()).isOK());
- assertTrue(getWorkspace().delete(new IResource[] {file}, false, getMonitor()).isOK());
- assertTrue(getWorkspace().delete(new IResource[] {}, false, getMonitor()).isOK());
- createHierarchy();
-
- //delete existing resources
- resources = new IResource[] {file, project, folder};
- assertTrue(getWorkspace().delete(resources, false, getMonitor()).isOK());
- // assertDoesNotExistInFileSystem(resources);
- assertDoesNotExistInWorkspace(resources);
- createHierarchy();
- resources = new IResource[] {file};
- assertTrue(getWorkspace().delete(resources, false, getMonitor()).isOK());
- assertDoesNotExistInFileSystem(resources);
- assertDoesNotExistInWorkspace(resources);
- file.create(getRandomContents(), false, getMonitor());
- resources = new IResource[] {};
- assertTrue(getWorkspace().delete(resources, false, getMonitor()).isOK());
- assertDoesNotExistInFileSystem(resources);
- assertDoesNotExistInWorkspace(resources);
- createHierarchy();
-
- //delete a combination of existing and non-existent resources
- IProject fakeProject = getWorkspace().getRoot().getProject("pigment");
- IFolder fakeFolder = fakeProject.getFolder("ligament");
- resources = new IResource[] {file, folder, fakeFolder, project, fakeProject};
- assertTrue(getWorkspace().delete(resources, false, getMonitor()).isOK());
- // assertDoesNotExistInFileSystem(resources);
- assertDoesNotExistInWorkspace(resources);
- createHierarchy();
- resources = new IResource[] {fakeProject, file};
- assertTrue(getWorkspace().delete(resources, false, getMonitor()).isOK());
- assertDoesNotExistInFileSystem(resources);
- assertDoesNotExistInWorkspace(resources);
- file.create(getRandomContents(), false, getMonitor());
- resources = new IResource[] {fakeProject};
- assertTrue(getWorkspace().delete(resources, false, getMonitor()).isOK());
- // assertDoesNotExistInFileSystem(resources);
- assertDoesNotExistInWorkspace(resources);
- createHierarchy();
-}
-/**
- * Performs black box testing of the following method:
- * IProjectNatureDescriptor[] getNatureDescriptors()
- */
-public void testGetNatureDescriptors() {
- //NOTE: see static fields for description of available test natures
- IProjectNatureDescriptor[] descriptors = getWorkspace().getNatureDescriptors();
-
- IProjectNatureDescriptor current = findNature(descriptors, NATURE_SIMPLE);
- assertTrue("2.0", current != null);
- assertEquals("2.1", NATURE_SIMPLE, current.getNatureId());
- assertEquals("2.2", "Simple", current.getLabel());
- assertEquals("2.3", 0, current.getRequiredNatureIds().length);
- assertEquals("2.4", 0, current.getNatureSetIds().length);
-
- current = findNature(descriptors, NATURE_SNOW);
- assertTrue("3.0", current != null);
- assertEquals("3.1", NATURE_SNOW, current.getNatureId());
- assertEquals("3.2", "Snow", current.getLabel());
- String[] required = current.getRequiredNatureIds();
- assertEquals("3.3", 1, required.length);
- assertEquals("3.4", NATURE_WATER, required[0]);
- String[] sets = current.getNatureSetIds();
- assertEquals("3.5", 1, sets.length);
- assertEquals("3.6", SET_OTHER, sets[0]);
-
- current = findNature(descriptors, NATURE_WATER);
- assertTrue("4.0", current != null);
- assertEquals("4.1", NATURE_WATER, current.getNatureId());
- assertEquals("4.2", "Water", current.getLabel());
- required = current.getRequiredNatureIds();
- assertEquals("4.3", 0, required.length);
- sets = current.getNatureSetIds();
- assertEquals("4.4", 1, sets.length);
- assertEquals("4.5", SET_STATE, sets[0]);
-
- current = findNature(descriptors, NATURE_EARTH);
- assertTrue("5.0", current != null);
- assertEquals("5.1", NATURE_EARTH, current.getNatureId());
- assertEquals("5.2", "Earth", current.getLabel());
- required = current.getRequiredNatureIds();
- assertEquals("5.3", 0, required.length);
- sets = current.getNatureSetIds();
- assertEquals("5.4", 1, sets.length);
- assertEquals("5.5", SET_STATE, sets[0]);
-
- current = findNature(descriptors, NATURE_MUD);
- assertTrue("6.0", current != null);
- assertEquals("6.1", NATURE_MUD, current.getNatureId());
- assertEquals("6.2", "Mud", current.getLabel());
- required = current.getRequiredNatureIds();
- assertEquals("6.3", 2, required.length);
- //water and earth are required for mud
- if (required[0].equals(NATURE_WATER)) {
- assertEquals("6.4", NATURE_EARTH, required[1]);
- } else {
- assertEquals("6.5", NATURE_EARTH, required[0]);
- assertEquals("6.6", NATURE_WATER, required[0]);
- }
- sets = current.getNatureSetIds();
- assertEquals("6.7", 1, sets.length);
- assertEquals("6.8", SET_OTHER, sets[0]);
-
- current = findNature(descriptors, NATURE_INVALID);
- assertTrue("7.0", current != null);
- assertEquals("7.1", NATURE_INVALID, current.getNatureId());
- assertEquals("7.2", "", current.getLabel());
- required = current.getRequiredNatureIds();
- assertEquals("7.3", 0, required.length);
- sets = current.getNatureSetIds();
- assertEquals("7.4", 0, sets.length);
-
- current = findNature(descriptors, NATURE_CYCLE1);
- assertTrue("8.0", current != null);
- assertEquals("8.1", NATURE_CYCLE1, current.getNatureId());
- assertEquals("8.2", "Cycle1", current.getLabel());
- required = current.getRequiredNatureIds();
- assertEquals("8.3", 1, required.length);
- assertEquals("8.4", NATURE_CYCLE2, required[0]);
- sets = current.getNatureSetIds();
- assertEquals("8.5", 0, sets.length);
-
- current = findNature(descriptors, NATURE_CYCLE2);
- assertTrue("5.0", current != null);
- assertEquals("9.1", NATURE_CYCLE2, current.getNatureId());
- assertEquals("9.2", "Cycle2", current.getLabel());
- required = current.getRequiredNatureIds();
- assertEquals("9.3", 1, required.length);
- assertEquals("9.4", NATURE_CYCLE3, required[0]);
- sets = current.getNatureSetIds();
- assertEquals("9.5", 0, sets.length);
-
- current = findNature(descriptors, NATURE_CYCLE3);
- assertTrue("10.0", current != null);
- assertEquals("10.1", NATURE_CYCLE3, current.getNatureId());
- assertEquals("10.2", "Cycle3", current.getLabel());
- required = current.getRequiredNatureIds();
- assertEquals("10.3", 1, required.length);
- assertEquals("10.4", NATURE_CYCLE1, required[0]);
- sets = current.getNatureSetIds();
- assertEquals("10.5", 0, sets.length);
-}
-/**
- * Performs black box testing of the following method:
- * IProjectNatureDescriptor getNatureDescriptor(String)
- */
-public void testGetNatureDescriptor() {
- //NOTE: see static fields for description of available test natures
- IWorkspace ws = getWorkspace();
-
- IProjectNatureDescriptor current = ws.getNatureDescriptor(NATURE_SIMPLE);
- assertTrue("2.0", current != null);
- assertEquals("2.1", NATURE_SIMPLE, current.getNatureId());
- assertEquals("2.2", "Simple", current.getLabel());
- assertEquals("2.3", 0, current.getRequiredNatureIds().length);
- assertEquals("2.4", 0, current.getNatureSetIds().length);
-
- current = ws.getNatureDescriptor(NATURE_SNOW);
- assertTrue("3.0", current != null);
- assertEquals("3.1", NATURE_SNOW, current.getNatureId());
- assertEquals("3.2", "Snow", current.getLabel());
- String[] required = current.getRequiredNatureIds();
- assertEquals("3.3", 1, required.length);
- assertEquals("3.4", NATURE_WATER, required[0]);
- String[] sets = current.getNatureSetIds();
- assertEquals("3.5", 1, sets.length);
- assertEquals("3.6", SET_OTHER, sets[0]);
-
- current = ws.getNatureDescriptor(NATURE_WATER);
- assertTrue("4.0", current != null);
- assertEquals("4.1", NATURE_WATER, current.getNatureId());
- assertEquals("4.2", "Water", current.getLabel());
- required = current.getRequiredNatureIds();
- assertEquals("4.3", 0, required.length);
- sets = current.getNatureSetIds();
- assertEquals("4.4", 1, sets.length);
- assertEquals("4.5", SET_STATE, sets[0]);
-
- current = ws.getNatureDescriptor(NATURE_EARTH);
- assertTrue("5.0", current != null);
- assertEquals("5.1", NATURE_EARTH, current.getNatureId());
- assertEquals("5.2", "Earth", current.getLabel());
- required = current.getRequiredNatureIds();
- assertEquals("5.3", 0, required.length);
- sets = current.getNatureSetIds();
- assertEquals("5.4", 1, sets.length);
- assertEquals("5.5", SET_STATE, sets[0]);
-
- current = ws.getNatureDescriptor(NATURE_MUD);
- assertTrue("6.0", current != null);
- assertEquals("6.1", NATURE_MUD, current.getNatureId());
- assertEquals("6.2", "Mud", current.getLabel());
- required = current.getRequiredNatureIds();
- assertEquals("6.3", 2, required.length);
- //water and earth are required for mud
- if (required[0].equals(NATURE_WATER)) {
- assertEquals("6.4", NATURE_EARTH, required[1]);
- } else {
- assertEquals("6.5", NATURE_EARTH, required[0]);
- assertEquals("6.6", NATURE_WATER, required[0]);
- }
- sets = current.getNatureSetIds();
- assertEquals("6.7", 1, sets.length);
- assertEquals("6.8", SET_OTHER, sets[0]);
-
- current = ws.getNatureDescriptor(NATURE_INVALID);
- assertTrue("7.0", current != null);
- assertEquals("7.1", NATURE_INVALID, current.getNatureId());
- assertEquals("7.2", "", current.getLabel());
- required = current.getRequiredNatureIds();
- assertEquals("7.3", 0, required.length);
- sets = current.getNatureSetIds();
- assertEquals("7.4", 0, sets.length);
-
- current = ws.getNatureDescriptor(NATURE_CYCLE1);
- assertTrue("8.0", current != null);
- assertEquals("8.1", NATURE_CYCLE1, current.getNatureId());
- assertEquals("8.2", "Cycle1", current.getLabel());
- required = current.getRequiredNatureIds();
- assertEquals("8.3", 1, required.length);
- assertEquals("8.4", NATURE_CYCLE2, required[0]);
- sets = current.getNatureSetIds();
- assertEquals("8.5", 0, sets.length);
-
- current = ws.getNatureDescriptor(NATURE_CYCLE2);
- assertTrue("5.0", current != null);
- assertEquals("9.1", NATURE_CYCLE2, current.getNatureId());
- assertEquals("9.2", "Cycle2", current.getLabel());
- required = current.getRequiredNatureIds();
- assertEquals("9.3", 1, required.length);
- assertEquals("9.4", NATURE_CYCLE3, required[0]);
- sets = current.getNatureSetIds();
- assertEquals("9.5", 0, sets.length);
-
- current = ws.getNatureDescriptor(NATURE_CYCLE3);
- assertTrue("10.0", current != null);
- assertEquals("10.1", NATURE_CYCLE3, current.getNatureId());
- assertEquals("10.2", "Cycle3", current.getLabel());
- required = current.getRequiredNatureIds();
- assertEquals("10.3", 1, required.length);
- assertEquals("10.4", NATURE_CYCLE1, required[0]);
- sets = current.getNatureSetIds();
- assertEquals("10.5", 0, sets.length);
-}
-/**
- * Performs black box testing of the following method:
- * IPath getPluginStateLocation(IPluginDescriptor)
- */
-public void testGetPluginStateLocation() throws CoreException {
- IPluginDescriptor coreDescriptor = Platform.getPluginRegistry().getPluginDescriptor("org.eclipse.core.resources");
- IPluginDescriptor builderDescriptor = Platform.getPluginRegistry().getPluginDescriptor("org.eclipse.core.tests.resources");
- assertTrue("0.9", builderDescriptor != null);
-
- IPath coreLocation = coreDescriptor.getPlugin().getStateLocation();
- assertTrue("1.0", coreLocation.toFile().exists());
-
- IPath builderLocation = builderDescriptor.getPlugin().getStateLocation();
- assertTrue("1.1", builderLocation.toFile().exists());
-}
-/**
- * Performs black box testing of the following method:
- * IStatus move([IResource, IPath, boolean, IProgressMonitor)
- */
-public void testMove() throws CoreException {
- /* create folders and files */
- IProject project = getWorkspace().getRoot().getProject("project");
- IFolder folder = project.getFolder("folder");
- IFile file = project.getFile("file.txt");
- IFile anotherFile = project.getFile("anotherFile.txt");
- IFile oneMoreFile = project.getFile("oneMoreFile.txt");
- ensureExistsInWorkspace(new IResource[] {project, folder, file, anotherFile, oneMoreFile}, true);
-
- /* normal case */
- IResource[] resources = {file, anotherFile, oneMoreFile};
- getWorkspace().move(resources, folder.getFullPath(), true, getMonitor());
- assertTrue("1.1", !file.exists());
- assertTrue("1.2", !anotherFile.exists());
- assertTrue("1.3", !oneMoreFile.exists());
- assertTrue("1.4", folder.getFile(file.getName()).exists());
- assertTrue("1.5", folder.getFile(anotherFile.getName()).exists());
- assertTrue("1.6", folder.getFile(oneMoreFile.getName()).exists());
-
- /* test duplicates */
- resources = new IResource[] {folder.getFile(file.getName()), folder.getFile(anotherFile.getName()), folder.getFile(oneMoreFile.getName()), folder.getFile(oneMoreFile.getName())};
- IStatus status = getWorkspace().move(resources, project.getFullPath(), true, getMonitor());
- assertTrue("2.1", status.isOK());
- assertTrue("2.3", file.exists());
- assertTrue("2.4", anotherFile.exists());
- assertTrue("2.5", oneMoreFile.exists());
- assertTrue("2.6", !folder.getFile(file.getName()).exists());
- assertTrue("2.7", !folder.getFile(anotherFile.getName()).exists());
- assertTrue("2.8", !folder.getFile(oneMoreFile.getName()).exists());
-
- /* test no simblings */
- resources = new IResource[] {file, anotherFile, oneMoreFile, project};
- boolean ok = false;
- try {
- getWorkspace().move(resources, folder.getFullPath(), true, getMonitor());
- } catch (CoreException e) {
- ok = true;
- status = e.getStatus();
- }
- assertTrue("3.0", ok);
- assertTrue("3.1", !status.isOK());
- assertTrue("3.2", status.getChildren().length == 1);
- assertTrue("3.3", !file.exists());
- assertTrue("3.4", !anotherFile.exists());
- assertTrue("3.5", !oneMoreFile.exists());
- assertTrue("3.6", folder.getFile(file.getName()).exists());
- assertTrue("3.7", folder.getFile(anotherFile.getName()).exists());
- assertTrue("3.8", folder.getFile(oneMoreFile.getName()).exists());
-
- /* inexisting resource */
- resources = new IResource[] {folder.getFile(file.getName()), folder.getFile(anotherFile.getName()), folder.getFile("inexisting"), folder.getFile(oneMoreFile.getName())};
- ok = false;
- try {
- getWorkspace().move(resources, project.getFullPath(), true, getMonitor());
- } catch (CoreException e) {
- ok = true;
- status = e.getStatus();
- }
- assertTrue("4.0", ok);
- assertTrue("4.1", !status.isOK());
- assertTrue("4.3", file.exists());
- assertTrue("4.4", anotherFile.exists());
- assertTrue("4.5", oneMoreFile.exists());
- assertTrue("4.6", !folder.getFile(file.getName()).exists());
- assertTrue("4.7", !folder.getFile(anotherFile.getName()).exists());
- assertTrue("4.8", !folder.getFile(oneMoreFile.getName()).exists());
-}
-/**
- * Another test method for IWorkspace.copy(). See also testCopy
- */
-public void testMultiCopy() throws CoreException {
- /* create common objects */
- IResource[] resources = buildResources();
- IProject project = (IProject)resources[1];
- IFolder folder = (IFolder)resources[2];
-
- /* create folder and file */
- ensureExistsInWorkspace(folder, true);
- ensureExistsInFileSystem(folder);
- IFile file1 = project.getFile("file.txt");
- ensureExistsInWorkspace(file1, true);
- ensureExistsInFileSystem(file1);
- IFile anotherFile = project.getFile("anotherFile.txt");
- ensureExistsInWorkspace(anotherFile, true);
- ensureExistsInFileSystem(anotherFile);
- IFile oneMoreFile = project.getFile("oneMoreFile.txt");
- ensureExistsInWorkspace(oneMoreFile, true);
- ensureExistsInFileSystem(oneMoreFile);
-
- /* normal case */
- resources = new IResource[] {file1, anotherFile, oneMoreFile};
- getWorkspace().copy(resources, folder.getFullPath(), true, getMonitor());
- assertTrue("1.1", file1.exists());
- assertTrue("1.2", anotherFile.exists());
- assertTrue("1.3", oneMoreFile.exists());
- assertTrue("1.4", folder.getFile(file1.getName()).exists());
- assertTrue("1.5", folder.getFile(anotherFile.getName()).exists());
- assertTrue("1.6", folder.getFile(oneMoreFile.getName()).exists());
- ensureDoesNotExistInWorkspace(folder.getFile(file1.getName()));
- ensureDoesNotExistInWorkspace(folder.getFile(anotherFile.getName()));
- ensureDoesNotExistInWorkspace(folder.getFile(oneMoreFile.getName()));
- ensureDoesNotExistInFileSystem(folder.getFile(file1.getName()));
- ensureDoesNotExistInFileSystem(folder.getFile(anotherFile.getName()));
- ensureDoesNotExistInFileSystem(folder.getFile(oneMoreFile.getName()));
-
- /* test duplicates */
- resources = new IResource[] {file1, anotherFile, oneMoreFile, file1};
- getWorkspace().copy(resources, folder.getFullPath(), true, getMonitor());
- assertTrue("2.2", file1.exists());
- assertTrue("2.3", anotherFile.exists());
- assertTrue("2.4", oneMoreFile.exists());
- assertTrue("2.5", folder.getFile(file1.getName()).exists());
- assertTrue("2.6", folder.getFile(anotherFile.getName()).exists());
- assertTrue("2.7", folder.getFile(oneMoreFile.getName()).exists());
- ensureDoesNotExistInWorkspace(folder.getFile(file1.getName()));
- ensureDoesNotExistInWorkspace(folder.getFile(anotherFile.getName()));
- ensureDoesNotExistInWorkspace(folder.getFile(oneMoreFile.getName()));
- ensureDoesNotExistInFileSystem(folder.getFile(file1.getName()));
- ensureDoesNotExistInFileSystem(folder.getFile(anotherFile.getName()));
- ensureDoesNotExistInFileSystem(folder.getFile(oneMoreFile.getName()));
-
- /* test no siblings */
- resources = new IResource[] {file1, anotherFile, oneMoreFile, project};
- IStatus status = null;
- boolean ok = false;
- try {
- getWorkspace().copy(resources, folder.getFullPath(), true, getMonitor());
- } catch (CoreException e) {
- ok = true;
- status = e.getStatus();
- }
- assertTrue("3.0", ok);
- assertTrue("3.1", !status.isOK());
- assertTrue("3.2", status.getChildren().length == 1);
- assertTrue("3.3", file1.exists());
- assertTrue("3.4", anotherFile.exists());
- assertTrue("3.5", oneMoreFile.exists());
- assertTrue("3.6", folder.getFile(file1.getName()).exists());
- assertTrue("3.7", folder.getFile(anotherFile.getName()).exists());
- assertTrue("3.8", folder.getFile(oneMoreFile.getName()).exists());
- ensureDoesNotExistInWorkspace(folder.getFile(file1.getName()));
- ensureDoesNotExistInWorkspace(folder.getFile(anotherFile.getName()));
- ensureDoesNotExistInWorkspace(folder.getFile(oneMoreFile.getName()));
- ensureDoesNotExistInFileSystem(folder.getFile(file1.getName()));
- ensureDoesNotExistInFileSystem(folder.getFile(anotherFile.getName()));
- ensureDoesNotExistInFileSystem(folder.getFile(oneMoreFile.getName()));
-
- /* inexisting resource */
- resources = new IResource[] {file1, anotherFile, project.getFile("inexisting"), oneMoreFile};
- ok = false;
- try {
- getWorkspace().copy(resources, folder.getFullPath(), true, getMonitor());
- } catch (CoreException e) {
- ok = true;
- status = e.getStatus();
- }
- assertTrue("4.0", ok);
- assertTrue("4.1", !status.isOK());
- assertTrue("4.2", file1.exists());
- assertTrue("4.3", anotherFile.exists());
- assertTrue("4.4", oneMoreFile.exists());
- assertTrue("4.5", folder.getFile(file1.getName()).exists());
- assertTrue("4.6", folder.getFile(anotherFile.getName()).exists());
- assertTrue("4.7 Fails because of 1FVFOOQ", folder.getFile(oneMoreFile.getName()).exists());
-
- /* copy projects should not be allowed */
- IResource destination = getWorkspace().getRoot().getProject("destination");
- ok = false;
- try {
- getWorkspace().copy(new IResource[] {project}, destination.getFullPath(), true, getMonitor());
- } catch (CoreException e) {
- ok = true;
- status = e.getStatus();
- }
- assertTrue("5.0", ok);
- assertTrue("5.1", !status.isOK());
- assertTrue("5.2", status.getChildren().length == 1);
-}
-public void testMultiCreation() throws Throwable {
- final IProject project = getWorkspace().getRoot().getProject("bar");
- final IResource[] resources = buildResources(project, new String[] {"a/", "a/b"});
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- project.create(null);
- project.open(null);
- // define an operation which will create a bunch of resources including a project.
- for (int i = 0; i < resources.length; i++) {
- IResource resource = resources[i];
- switch (resource.getType()) {
- case IResource.FILE :
- ((IFile) resource).create(null, false, getMonitor());
- break;
- case IResource.FOLDER :
- ((IFolder) resource).create(false, true, getMonitor());
- break;
- case IResource.PROJECT :
- ((IProject) resource).create(getMonitor());
- break;
- }
- }
- }
- };
- getWorkspace().run(body, getMonitor());
- assertExistsInWorkspace(project);
- assertExistsInWorkspace(resources);
-}
-public void testMultiDeletion() throws Throwable {
- IProject project = getWorkspace().getRoot().getProject("testProject");
- IResource[] before = buildResources(project, new String[] {"c/", "c/b/", "c/x", "c/b/y", "c/b/z"});
- ensureExistsInWorkspace(before, true);
- //
- assertExistsInWorkspace(before);
- getWorkspace().delete(before, true, getMonitor());
- assertDoesNotExistInWorkspace(before);
-}
-/**
- * Test thread safety of the API method IWorkspace.setDescription.
- */
-public void testMultiSetDescription() {
- final int THREAD_COUNT = 2;
- final CoreException[] errorPointer = new CoreException[1];
- Thread[] threads = new Thread[THREAD_COUNT];
- for (int i = 0; i < THREAD_COUNT; i++) {
- threads[i] = new Thread(new Runnable() {
- public void run() {
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
- IWorkspaceDescription description = workspace.getDescription();
- for (int j = 0; j < 100; j++) {
- description.setAutoBuilding(false);
- try {
- workspace.setDescription(description);
- } catch (CoreException e) {
- errorPointer[0] = e;
- return;
- }
- description.setAutoBuilding(true);
- try {
- workspace.setDescription(description);
- } catch (CoreException e) {
- errorPointer[0] = e;
- return;
- }
- }
- }
- }, "Autobuild " + i);
- threads[i].start();
- }
- for (int i = 0; i < threads.length; i++) {
- try {
- threads[i].join();
- } catch (InterruptedException e) {
- }
- }
- if (errorPointer[0] != null)
- fail("1.0", errorPointer[0]);
-}
-/**
- * Test API method IWorkspace.setDescription.
- */
-public void testSave() {
- //ensure save returns a warning if a project's .project file is deleted.
- IProject project = getWorkspace().getRoot().getProject("Broken");
- ensureExistsInWorkspace(project, true);
- //wait for snapshot before modifying file
- TestingSupport.waitForSnapshot();
- IFile descriptionFile = project.getFile(IProjectDescription.DESCRIPTION_FILE_NAME);
- try {
- descriptionFile.delete(IResource.NONE, null);
- IStatus result = getWorkspace().save(true, getMonitor());
- assertTrue("1.0", result.getSeverity() == IStatus.WARNING);
- } catch (CoreException e) {
- fail("1.99", e);
- }
-
-}
-
-/**
- * Performs black box testing of the following method:
- * String[] sortNatureSet(String[])
- */
-public void testSortNatureSet() {
- //NOTE: see static fields for description of available test natures
- IWorkspace ws = getWorkspace();
-
- //invalid sets shouldn't fail
- String[][] invalid = getInvalidNatureSets();
- for (int i = 0; i < invalid.length; i++) {
- String[] sorted = ws.sortNatureSet(invalid[i]);
- assertTrue("0.0", sorted != null);
- //set may grow if it contained duplicates
- assertTrue("0.1", sorted.length <= invalid[i].length);
- }
- String[] sorted = ws.sortNatureSet(new String[] {});
- assertEquals("1.0", 0, sorted.length);
-
- sorted = ws.sortNatureSet(new String[] {NATURE_SIMPLE});
- assertEquals("2.0", 1, sorted.length);
- assertEquals("2.1", NATURE_SIMPLE, sorted[0]);
-
- sorted = ws.sortNatureSet(new String[] {NATURE_SNOW, NATURE_WATER});
- assertEquals("3.0", 2, sorted.length);
- assertEquals("3.1", NATURE_WATER, sorted[0]);
- assertEquals("3.2", NATURE_SNOW, sorted[1]);
-
- sorted = ws.sortNatureSet(new String[] {NATURE_WATER, NATURE_SIMPLE, NATURE_SNOW});
- assertEquals("4.0", 3, sorted.length);
- //three valid sorts: water, snow, simple; water, simple, snow; simple, water, snow
- boolean first = sorted[0].equals(NATURE_WATER) && sorted[1].equals(NATURE_SNOW) && sorted[2].equals(NATURE_SIMPLE);
- boolean second = sorted[0].equals(NATURE_WATER) && sorted[1].equals(NATURE_SIMPLE) && sorted[2].equals(NATURE_SNOW);
- boolean third= sorted[0].equals(NATURE_SIMPLE) && sorted[1].equals(NATURE_WATER) && sorted[2].equals(NATURE_SNOW);
- assertTrue("4.1", first || second || third);
-}
-public void testValidateEdit() {
- // We need to know whether or not we can unset the read-only flag
- // in order to perform this test.
- if (!CoreFileSystemLibrary.usingNatives())
- return;
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- IFile file = project.getFile("myfile.txt");
- ensureExistsInWorkspace(new IResource[] {project, file}, true);
- IStatus result = getWorkspace().validateEdit(new IFile[] {file}, null);
- assertTrue("1.0", result.isOK());
- file.setReadOnly(true);
- result = getWorkspace().validateEdit(new IFile[] {file}, null);
- assertEquals("1.1", IStatus.ERROR, result.getSeverity());
-// assertEquals("1.2", IResourceStatus.READ_ONLY_LOCAL, result.getCode());
- // remove the read-only status so test cleanup will work ok
- file.setReadOnly(false);
-}
-public void testValidateLinkLocation() {
- //TODO
- //see also: some tests in LinkedResourceWithPathVariableTest
-}
-/**
- * Performs black box testing of the following method:
- * IStatus validateName(String, int)
- */
-public void testValidateName() {
- /* normal name */
- assertTrue("1.1", getWorkspace().validateName("abcdef", IResource.FILE).isOK());
- /* invalid characters (windows only) */
- if (BootLoader.getOS().equals(BootLoader.OS_WIN32)) {
- assertTrue("2.1", !(getWorkspace().validateName("dsa:sf", IResource.FILE).isOK()));
- assertTrue("2.2", !(getWorkspace().validateName("*dsasf", IResource.FILE).isOK()));
- assertTrue("2.3", !(getWorkspace().validateName("?dsasf", IResource.FILE).isOK()));
- assertTrue("2.4", !(getWorkspace().validateName("\"dsasf", IResource.FILE).isOK()));
- assertTrue("2.5", !(getWorkspace().validateName("<dsasf", IResource.FILE).isOK()));
- assertTrue("2.6", !(getWorkspace().validateName(">dsasf", IResource.FILE).isOK()));
- assertTrue("2.7", !(getWorkspace().validateName("|dsasf", IResource.FILE).isOK()));
- assertTrue("2.8", !(getWorkspace().validateName("\"dsasf", IResource.FILE).isOK()));
- }
- /* invalid characters on all platforms */
- assertTrue("2.9", !(getWorkspace().validateName("/dsasf", IResource.FILE).isOK()));
- assertTrue("2.10", !(getWorkspace().validateName("\\dsasf", IResource.FILE).isOK()));
-
- /* dots */
- assertTrue("3.1", !(getWorkspace().validateName(".", IResource.FILE).isOK()));
- assertTrue("3.2", !(getWorkspace().validateName("..", IResource.FILE).isOK()));
- assertTrue("3.3", !(getWorkspace().validateName("...", IResource.FILE).isOK()));
- assertTrue("3.4", !(getWorkspace().validateName("....", IResource.FILE).isOK()));
- assertTrue("3.5", getWorkspace().validateName("....abc", IResource.FILE).isOK());
- assertTrue("3.6", getWorkspace().validateName("abc....def", IResource.FILE).isOK());
- assertTrue("3.7", !(getWorkspace().validateName("abc....", IResource.FILE).isOK()));
-}
-/**
- * Performs black box testing of the following method:
- * IStatus validateNatureSet(String[])
- */
-public void testValidateNatureSet() {
- //NOTE: see static fields for description of available test natures
- IWorkspace ws = getWorkspace();
-
- String[][] invalid = getInvalidNatureSets();
- for (int i = 0; i < invalid.length; i++) {
- IStatus result = ws.validateNatureSet(invalid[i]);
- assertTrue("invalid (severity): " + i, !result.isOK());
- assertTrue("invalid (code): " + i, result.getCode() != IStatus.OK);
- }
- String[][] valid = getValidNatureSets();
- for (int i = 0; i < valid.length; i++) {
- IStatus result = ws.validateNatureSet(valid[i]);
- assertTrue("valid (severity): " + i, result.isOK());
- assertTrue("valid (code): " + i, result.getCode() == IStatus.OK);
- }
-}
-/**
- * Performs black box testing of the following method:
- * IStatus validatePath(String, int)
- */
-public void testValidatePath() {
- /* normal path */
- assertTrue("1.1", getWorkspace().validatePath("/one/two/three/four/", IResource.FILE | IResource.FOLDER).isOK());
-
- /* invalid characters (windows only) */
- if (BootLoader.getOS().equals(BootLoader.OS_WIN32)) {
- assertTrue("2.1", !(getWorkspace().validatePath("\\dsa:sf", IResource.FILE).isOK()));
- assertTrue("2.2", !(getWorkspace().validatePath("/abc/*dsasf", IResource.FILE).isOK()));
- assertTrue("2.3", !(getWorkspace().validatePath("/abc/?dsasf", IResource.FILE).isOK()));
- assertTrue("2.4", !(getWorkspace().validatePath("/abc/\"dsasf", IResource.FILE).isOK()));
- assertTrue("2.5", !(getWorkspace().validatePath("/abc/<dsasf", IResource.FILE).isOK()));
- assertTrue("2.6", !(getWorkspace().validatePath("/abc/>dsasf", IResource.FILE).isOK()));
- assertTrue("2.7", !(getWorkspace().validatePath("/abc/|dsasf", IResource.FILE).isOK()));
- assertTrue("2.8", !(getWorkspace().validatePath("/abc/\"dsasf", IResource.FILE).isOK()));
- }
-
- /* dots */
- assertTrue("3.1", !(getWorkspace().validatePath("/abc/.../defghi", IResource.FILE).isOK()));
- assertTrue("3.2", !(getWorkspace().validatePath("/abc/..../defghi", IResource.FILE).isOK()));
- assertTrue("3.3", !(getWorkspace().validatePath("/abc/def..../ghi", IResource.FILE).isOK()));
- assertTrue("3.4", getWorkspace().validatePath("/abc/....def/ghi", IResource.FILE).isOK());
- assertTrue("3.5", getWorkspace().validatePath("/abc/def....ghi/jkl", IResource.FILE).isOK());
-
- /* test hiding incorrect characters using .. and device separator : */
- assertTrue("4.1", getWorkspace().validatePath("/abc/.?./../def/as", IResource.FILE).isOK());
- assertTrue("4.2", getWorkspace().validatePath("/abc/;*?\"'/../def/safd", IResource.FILE).isOK());
- assertTrue("4.3", !(getWorkspace().validatePath("/abc;*?\"':/def/asdf/sadf", IResource.FILE).isOK()));
-
- /* other invalid paths */
- assertTrue("5.1", !(getWorkspace().validatePath("/", IResource.FILE).isOK()));
- assertTrue("5.2", !(getWorkspace().validatePath("\\", IResource.FILE).isOK()));
- assertTrue("5.3", !(getWorkspace().validatePath("", IResource.FILE).isOK()));
- assertTrue("5.4", !(getWorkspace().validatePath("device:/abc/123", IResource.FILE).isOK()));
-
- /* test types / segments */
- assertTrue("6.6", getWorkspace().validatePath("/asf", IResource.PROJECT).isOK());
- assertTrue("6.7", !(getWorkspace().validatePath("/asf", IResource.FILE).isOK()));
- // note this is value for a file OR project (note the logical OR)
- assertTrue("6.8", getWorkspace().validatePath("/asf", IResource.PROJECT | IResource.FILE).isOK());
- assertTrue("6.10", getWorkspace().validatePath("/project/.metadata", IResource.FILE).isOK());
- // FIXME: Should this be valid?
- assertTrue("6.11", getWorkspace().validatePath("/.metadata/project", IResource.FILE).isOK());
-}
-/**
- * Performs black box testing of the following method:
- * IStatus validateProjectLocation(IProject, IPath)
- */
-public void testValidateProjectLocation() {
- IWorkspace workspace = getWorkspace();
- IProject project = workspace.getRoot().getProject("Project");
-
- /* normal path */
- assertTrue("1.1", workspace.validateProjectLocation(project, new Path("/one/two/three/four/")).isOK());
-
- /* invalid characters (windows only) */
- if (BootLoader.getOS().equals(BootLoader.OS_WIN32)) {
- assertTrue("2.1", !(workspace.validateProjectLocation(project, new Path("d:\\dsa:sf")).isOK()));
- assertTrue("2.2", !(workspace.validateProjectLocation(project, new Path("/abc/*dsasf")).isOK()));
- assertTrue("2.3", !(workspace.validateProjectLocation(project, new Path("/abc/?dsasf")).isOK()));
- assertTrue("2.4", !(workspace.validateProjectLocation(project, new Path("/abc/\"dsasf")).isOK()));
- assertTrue("2.5", !(workspace.validateProjectLocation(project, new Path("/abc/<dsasf")).isOK()));
- assertTrue("2.6", !(workspace.validateProjectLocation(project, new Path("/abc/>dsasf")).isOK()));
- assertTrue("2.7", !(workspace.validateProjectLocation(project, new Path("/abc/|dsasf")).isOK()));
- assertTrue("2.8", !(workspace.validateProjectLocation(project, new Path("/abc/\"dsasf")).isOK()));
- }
-
- /* dots */
- assertTrue("3.1", !(workspace.validateProjectLocation(project, new Path("/abc/.../defghi")).isOK()));
- assertTrue("3.2", !(workspace.validateProjectLocation(project, new Path("/abc/..../defghi")).isOK()));
- assertTrue("3.3", !(workspace.validateProjectLocation(project, new Path("/abc/def..../ghi")).isOK()));
- assertTrue("3.4", workspace.validateProjectLocation(project, new Path("/abc/....def/ghi")).isOK());
- assertTrue("3.5", workspace.validateProjectLocation(project, new Path("/abc/def....ghi/jkl")).isOK());
-
- /* test hiding incorrect characters using .. and device separator : */
- assertTrue("4.1", workspace.validateProjectLocation(project, new Path("/abc/.?./../def/as")).isOK());
- assertTrue("4.2", workspace.validateProjectLocation(project, new Path("/abc/;*?\"'/../def/safd")).isOK());
- assertTrue("4.3", !(workspace.validateProjectLocation(project, new Path("c:/abc;*?\"':/def/asdf/sadf")).isOK()));
-
- // cannot overlap the platform directory
- IPath platformLocation = Platform.getLocation();
- assertTrue("5.1", !(workspace.validateProjectLocation(project, new Path(platformLocation.getDevice(), "/")).isOK()));
- assertTrue("5.2", !(workspace.validateProjectLocation(project, new Path(platformLocation.getDevice(), "\\")).isOK()));
- assertTrue("5.3", !(workspace.validateProjectLocation(project, new Path(platformLocation.getDevice(), "")).isOK()));
- assertTrue("5.4", !(workspace.validateProjectLocation(project, platformLocation).isOK()));
- assertTrue("5.5", !(workspace.validateProjectLocation(project, platformLocation.append("foo")).isOK()));
-
- //can overlap platform directory on another device
- IPath anotherDevice = platformLocation.setDevice("nowear:");
- assertTrue("6.1", workspace.validateProjectLocation(project, new Path("nowear:", "/")).isOK());
- assertTrue("6.2", workspace.validateProjectLocation(project, new Path("nowear:", "\\")).isOK());
- assertTrue("6.4", workspace.validateProjectLocation(project, anotherDevice).isOK());
- assertTrue("6.5", workspace.validateProjectLocation(project, anotherDevice.append("foo")).isOK());
-
- //cannot be a relative path
- assertTrue("7.1", !workspace.validateProjectLocation(project, new Path("nowear:", "")).isOK());
- assertTrue("7.2", !workspace.validateProjectLocation(project, new Path("c:")).isOK());
- assertTrue("7.3", !workspace.validateProjectLocation(project, new Path("c:foo")).isOK());
- assertTrue("7.4", !workspace.validateProjectLocation(project, new Path("foo/bar")).isOK());
- assertTrue("7.5", !workspace.validateProjectLocation(project, new Path("c:foo/bar")).isOK());
-
- //may be relative to an existing path variable
- final String PATH_VAR_NAME = "FOOVAR";
- final IPath PATH_VAR_VALUE = getRandomLocation();
- try {
- try {
- IPath varPath = new Path(PATH_VAR_NAME);
- workspace.getPathVariableManager().setValue(PATH_VAR_NAME, PATH_VAR_VALUE);
- assertTrue("8.1", workspace.validateProjectLocation(project, varPath).isOK());
- assertTrue("8.2", workspace.validateProjectLocation(project, varPath.append("test")).isOK());
- assertTrue("8.3", workspace.validateProjectLocation(project, varPath.append("test/ing")).isOK());
- } finally {
- workspace.getPathVariableManager().setValue(PATH_VAR_NAME, null);
- }
- } catch (CoreException e) {
- fail("8.99", e);
- }
-
- //cannot overlap with another project's location
- String tempDir = System.getProperty("java.io.tmpdir");
- IPath openProjectLocation = new Path(tempDir).append("OpenProject");
- IProject open = workspace.getRoot().getProject("OpenProject");
- IProjectDescription openDesc = workspace.newProjectDescription(open.getName());
- openDesc.setLocation(openProjectLocation);
- IPath closedProjectLocation = new Path(tempDir).append("ClosedProject");
- IProject closed = workspace.getRoot().getProject("ClosedProject");
- IProjectDescription closedDesc= workspace.newProjectDescription(closed.getName());
- closedDesc.setLocation(closedProjectLocation);
- try{
- open.create(openDesc, null);
- open.open(null);
- closed.create(closedDesc, null);
- } catch (CoreException e) {
- fail("9.99", e);
- }
- IPath linkLocation = getRandomLocation();
- try {
- //indirect test: setting the project description may validate location, which shouldn't complain
- IProjectDescription desc = open.getDescription();
- desc.setReferencedProjects(new IProject[] {project});
- open.setDescription(desc, IResource.FORCE, getMonitor());
-
- assertTrue("9.1", !workspace.validateProjectLocation(project, openProjectLocation).isOK());
- assertTrue("9.2", !workspace.validateProjectLocation(project, closedProjectLocation).isOK());
-
- //for an existing project, it cannot overlap itself, but it its own location is valid
- assertTrue("9.3", workspace.validateProjectLocation(open, openProjectLocation).isOK());
- assertTrue("9.4", !workspace.validateProjectLocation(open, openProjectLocation.append("sub")).isOK());
-
- //an existing project cannot overlap the location of any linked resource in that project
- linkLocation.toFile().mkdirs();
- assertTrue("10.1", workspace.validateProjectLocation(open, linkLocation).isOK());
- IFolder link = open.getFolder("link");
- link.createLink(linkLocation, IResource.NONE, getMonitor());
- assertTrue("10.2", !workspace.validateProjectLocation(open, linkLocation).isOK());
- assertTrue("10.3", !workspace.validateProjectLocation(open, linkLocation.append("sub")).isOK());
-
- //however another project can overlap an existing link location
- assertTrue("10.4", workspace.validateProjectLocation(project, linkLocation).isOK());
-
- } catch (CoreException e) {
- fail("9.99", e);
- } finally {
- Workspace.clear(linkLocation.toFile());
- //make sure we clean up project directories
- try {
- open.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, getMonitor());
- open.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, getMonitor());
- } catch (CoreException e) {
- }
- ensureDoesNotExistInFileSystem(openProjectLocation.toFile());
- ensureDoesNotExistInFileSystem(closedProjectLocation.toFile());
- }
-
- // FIXME: Should this be valid?
- assertTrue("23.1", workspace.validateProjectLocation(project, new Path("/asf")).isOK());
- assertTrue("23.2", workspace.validateProjectLocation(project, new Path("/project/.metadata")).isOK());
- // FIXME: Should this be valid?
- assertTrue("23.3", workspace.validateProjectLocation(project, new Path("/.metadata/project")).isOK());
-
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedResourceTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedResourceTest.java
deleted file mode 100644
index 9305203..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedResourceTest.java
+++ /dev/null
@@ -1,1148 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import java.io.IOException;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.boot.BootLoader;
-import org.eclipse.core.internal.resources.Workspace;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.*;
-
-/**
- * Tests the following API methods:
- * IFile#createLink
- * IFolder#createLink
- *
- * This test supports both variable-based and non-variable-based locations.
- * Although the method used for creating random locations
- * <code>EclipseWorkspaceTest#getRandomLocation()</code> never returns variable-
- * based paths, this method is overriden in the derived class
- * <code>LinkedResourceWithPathVariable</code> to always return variable-based
- * paths.
- *
- * To support variable-based paths wherever a file system location is used, it
- * is mandatory first to resolve it and only then using it, except in calls to
- * <code>IFile#createLink</code> and <code>IFolder#createLink</code> and when
- * the location is obtained using <code>IResource#getLocation()</code>.
- */
-public class LinkedResourceTest extends EclipseWorkspaceTest {
- protected IProject existingProject;
- protected IProject otherExistingProject;
- protected IProject closedProject;
- protected IProject nonExistingProject;
- protected IFolder existingFolderInExistingProject;
- protected IFolder existingFolderInExistingFolder;
- protected IFolder nonExistingFolderInExistingProject;
- protected IFolder nonExistingFolderInOtherExistingProject;
- protected IFolder nonExistingFolderInNonExistingProject;
- protected IFolder nonExistingFolderInExistingFolder;
- protected IFolder nonExistingFolderInNonExistingFolder;
- protected IFile existingFileInExistingProject;
- protected IFile nonExistingFileInExistingProject;
- protected IFile nonExistingFileInOtherExistingProject;
- protected IFile nonExistingFileInExistingFolder;
- protected IPath existingLocation;
- protected IPath nonExistingLocation;
- protected IPath localFile;
- protected String childName = "File.txt";
-
- public LinkedResourceTest() {
- super();
- }
- public LinkedResourceTest(String name) {
- super(name);
- }
- public static Test suite() {
- return new TestSuite(LinkedResourceTest.class);
- }
-
- protected void doCleanup() throws Exception {
- ensureExistsInWorkspace(
- new IResource[] { existingProject, otherExistingProject, closedProject, existingFolderInExistingProject, existingFolderInExistingFolder, existingFileInExistingProject },
- true);
- closedProject.close(getMonitor());
- ensureDoesNotExistInWorkspace(
- new IResource[] {
- nonExistingProject,
- nonExistingFolderInExistingProject,
- nonExistingFolderInExistingFolder,
- nonExistingFolderInOtherExistingProject,
- nonExistingFolderInNonExistingProject,
- nonExistingFolderInNonExistingFolder,
- nonExistingFileInExistingProject,
- nonExistingFileInOtherExistingProject,
- nonExistingFileInExistingFolder });
- ensureDoesNotExistInFileSystem(resolvePath(nonExistingLocation).toFile());
- resolvePath(existingLocation).toFile().mkdirs();
- createFileInFileSystem(resolvePath(localFile), getRandomContents());
- }
- /**
- * Maybe overridden in subclasses that use path variables.
- */
- protected IPath resolvePath(IPath path) {
- return path;
- }
- protected void setUp() throws Exception {
- super.setUp();
- existingProject = getWorkspace().getRoot().getProject("ExistingProject");
- otherExistingProject = getWorkspace().getRoot().getProject("OtherExistingProject");
- closedProject = getWorkspace().getRoot().getProject("ClosedProject");
- existingFolderInExistingProject = existingProject.getFolder("existingFolderInExistingProject");
- existingFolderInExistingFolder = existingFolderInExistingProject.getFolder("existingFolderInExistingFolder");
- nonExistingFolderInExistingProject = existingProject.getFolder("nonExistingFolderInExistingProject");
- nonExistingFolderInOtherExistingProject = otherExistingProject.getFolder("nonExistingFolderInOtherExistingProject");
- nonExistingFolderInNonExistingFolder = nonExistingFolderInExistingProject.getFolder("nonExistingFolderInNonExistingFolder");
- nonExistingFolderInExistingFolder = existingFolderInExistingProject.getFolder("nonExistingFolderInExistingFolder");
-
- nonExistingProject = getWorkspace().getRoot().getProject("NonProject");
- nonExistingFolderInNonExistingProject = nonExistingProject.getFolder("nonExistingFolderInNonExistingProject");
-
- existingFileInExistingProject = existingProject.getFile("existingFileInExistingProject");
- nonExistingFileInExistingProject = existingProject.getFile("nonExistingFileInExistingProject");
- nonExistingFileInOtherExistingProject = otherExistingProject.getFile("nonExistingFileInOtherExistingProject");
- nonExistingFileInExistingFolder = existingFolderInExistingProject.getFile("nonExistingFileInExistingFolder");
- existingLocation = getRandomLocation();
- nonExistingLocation = getRandomLocation();
- localFile = existingLocation.append(childName);
- doCleanup();
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- Workspace.clear(resolvePath(existingLocation).toFile());
- Workspace.clear(resolvePath(nonExistingLocation).toFile());
- }
- /**
- * Tests creation of a linked resource whose corresponding file system
- * path does not exist. This should suceed but no operations will be
- * available on the resulting resource.
- */
- public void testAllowMissingLocal() {
- //get a non-existing location
- IPath location = getRandomLocation();
- IFolder folder = nonExistingFolderInExistingProject;
-
- //try to create without the flag (should fail)
- try {
- folder.createLink(location, IResource.NONE, getMonitor());
- fail("1.0");
- } catch (CoreException e) {
- //should fail
- }
-
- //now try to create with the flag (should suceed)
- try {
- folder.createLink(location, IResource.ALLOW_MISSING_LOCAL, getMonitor());
- } catch (CoreException e) {
- fail("1.1", e);
- }
- assertEquals("1.2", resolvePath(location), folder.getLocation());
- assertTrue("1.3", !resolvePath(location).toFile().exists());
- //getting children should suceed (and be empty)
- try {
- assertEquals("1.4", 0, folder.members().length);
- } catch (CoreException e) {
- fail("1.5", e);
- }
- //delete should suceed
- try {
- folder.delete(IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("1.6", e);
- }
-
- //try to create with local path that can never exist
- if (BootLoader.getOS().equals(BootLoader.OS_WIN32))
- location = new Path("b:\\does\\not\\exist");
- else
- location = new Path("/dev/null/does/not/exist");
- try {
- folder.createLink(location, IResource.NONE, getMonitor());
- fail("2.1");
- } catch (CoreException e) {
- //should fail
- }
- try {
- folder.createLink(location, IResource.ALLOW_MISSING_LOCAL, getMonitor());
- } catch (CoreException e) {
- fail("2.2", e);
- }
- assertEquals("2.3", location, folder.getLocation());
- assertTrue("2.4", !location.toFile().exists());
- // creating child should fail
- try {
- folder.getFile("abc.txt").create(getRandomContents(), IResource.NONE, getMonitor());
- fail("2.5");
- } catch (CoreException e) {
- //should fail
- }
- }
- /**
- * Tests case where a resource in the file system cannot be added to the workspace
- * because it is blocked by a linked resource of the same name.
- */
- public void testBlockedFolder() {
- //create local folder that will be blocked
- ensureExistsInFileSystem(nonExistingFolderInExistingProject);
- IFile blockedFile = nonExistingFolderInExistingProject.getFile("BlockedFile");
- try {
- createFileInFileSystem(blockedFile.getLocation(), getRandomContents());
- } catch (IOException e) {
- fail("1.0", e);
- }
- try {
- //link the folder elsewhere
- nonExistingFolderInExistingProject.createLink(existingLocation, IResource.NONE, getMonitor());
- //refresh the project
- existingProject.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- } catch (CoreException e) {
- fail("1.1", e);
- }
-
- //the blocked file should not exist in the workspace
- assertTrue("1.2", !blockedFile.exists());
- assertTrue("1.3", nonExistingFolderInExistingProject.exists());
- assertTrue("1.4", nonExistingFolderInExistingProject.getFile(childName).exists());
- assertEquals("1.5", nonExistingFolderInExistingProject.getLocation(), resolvePath(existingLocation));
-
- //now delete the link
- try {
- nonExistingFolderInExistingProject.delete(IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("1.99", e);
- }
- //the blocked file and the linked folder should not exist in the workspace
- assertTrue("2.0", !blockedFile.exists());
- assertTrue("2.1", !nonExistingFolderInExistingProject.exists());
- assertTrue("2.2", !nonExistingFolderInExistingProject.getFile(childName).exists());
- assertEquals("2.3", nonExistingFolderInExistingProject.getLocation(), existingProject.getLocation().append(nonExistingFolderInExistingProject.getName()));
-
- //now refresh again to discover the blocked resource
- try {
- existingProject.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- } catch (CoreException e) {
- fail("2.99", e);
- }
-
- //the blocked file should now exist
- assertTrue("3.0", blockedFile.exists());
- assertTrue("3.1", nonExistingFolderInExistingProject.exists());
- assertTrue("3.2", !nonExistingFolderInExistingProject.getFile(childName).exists());
- assertEquals("3.3", nonExistingFolderInExistingProject.getLocation(), existingProject.getLocation().append(nonExistingFolderInExistingProject.getName()));
-
- //attempting to link again will fail because the folder exists in the workspace
- try {
- nonExistingFolderInExistingProject.createLink(existingLocation, IResource.NONE, getMonitor());
- fail("3.4");
- } catch (CoreException e) {
- //expected
- }
- }
- /**
- * This test creates a linked folder resource, then changes the directory in
- * the file system to be a file. On refresh, the linked resource should
- * still exist, should have the correct gender, and still be a linked
- * resource.
- */
- public void testChangeLinkGender() {
- IFolder folder = nonExistingFolderInExistingProject;
- IFile file = folder.getProject().getFile(folder.getProjectRelativePath());
- IPath resolvedLocation = resolvePath(existingLocation);
- try {
- folder.createLink(existingLocation, IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("0.99", e);
- }
- ensureDoesNotExistInFileSystem(resolvedLocation.toFile());
- try {
- createFileInFileSystem(resolvedLocation, getRandomContents());
- } catch (IOException e) {
- fail("1.99", e);
- }
- try {
- folder.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- } catch (CoreException e) {
- fail("2.99", e);
- }
-
- assertTrue("3.0", !folder.exists());
- assertTrue("3.1", file.exists());
- assertTrue("3.2", file.isLinked());
- assertEquals("3.3", resolvedLocation, file.getLocation());
-
- //change back to folder
- ensureDoesNotExistInFileSystem(resolvedLocation.toFile());
- resolvedLocation.toFile().mkdirs();
-
- try {
- folder.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- } catch (CoreException e) {
- fail("3.99", e);
- }
- assertTrue("4.0", folder.exists());
- assertTrue("4.1", !file.exists());
- assertTrue("4.2", folder.isLinked());
- assertEquals("4.3", resolvedLocation, folder.getLocation());
- }
-
- public void testCopyFile() {
- final IFile source = nonExistingFileInExistingProject;
- IResource[] destinationResources = new IResource[] { existingProject, closedProject, nonExistingFileInOtherExistingProject, nonExistingFileInExistingFolder };
- Boolean[] deepCopy = new Boolean[] { Boolean.TRUE, Boolean.FALSE };
- IProgressMonitor[] monitors = new IProgressMonitor[] { new FussyProgressMonitor(), new CancelingProgressMonitor(), null };
- Object[][] inputs = new Object[][] { destinationResources, deepCopy, monitors };
- new TestPerformer("LinkedResourceTest.testCopyFile") {
- protected static final String CANCELED = "canceled";
- public boolean shouldFail(Object[] args, int count) {
- IResource destination = (IResource) args[0];
- boolean isDeep = ((Boolean) args[1]).booleanValue();
- IProgressMonitor monitor = (IProgressMonitor)args[2];
- if (monitor instanceof CancelingProgressMonitor)
- return false;
- IResource parent = destination.getParent();
- if (!isDeep && (parent == null || parent.getType() != IResource.PROJECT))
- return true;
- if (!parent.isAccessible())
- return true;
- if (destination.exists())
- return true;
- //passed all failure cases so it should suceed
- return false;
- }
- public Object invokeMethod(Object[] args, int count) throws Exception {
- IResource destination = (IResource) args[0];
- boolean isDeep = ((Boolean) args[1]).booleanValue();
- IProgressMonitor monitor = (IProgressMonitor) args[2];
- if (monitor instanceof FussyProgressMonitor)
- ((FussyProgressMonitor) monitor).prepare();
- try {
- source.createLink(localFile, IResource.NONE, null);
- source.copy(destination.getFullPath(), isDeep ? IResource.NONE : IResource.SHALLOW, monitor);
- } catch (OperationCanceledException e) {
- return CANCELED;
- }
- if (monitor instanceof FussyProgressMonitor)
- ((FussyProgressMonitor) monitor).sanityCheck();
- return null;
- }
- public boolean wasSuccess(Object[] args, Object result, Object[] oldState) throws Exception {
- IResource destination = (IResource) args[0];
- boolean isDeep = ((Boolean) args[1]).booleanValue();
- IProgressMonitor monitor = (IProgressMonitor) args[2];
- if (result == CANCELED)
- return monitor instanceof CancelingProgressMonitor;
- if (!destination.exists())
- return false;
- //destination should only be linked for a shallow copy
- if (isDeep) {
- if (destination.isLinked())
- return false;
- if (source.getLocation().equals(destination.getLocation()))
- return false;
- if (!destination.getProject().getLocation().isPrefixOf(destination.getLocation()))
- return false;
- } else {
- if (!destination.isLinked())
- return false;
- if (!source.getLocation().equals(destination.getLocation()))
- return false;
- assertEquals("1.0", source.getRawLocation(), destination.getRawLocation());
- }
- return true;
- }
- public void cleanUp(Object[] args, int count) {
- super.cleanUp(args, count);
- try {
- doCleanup();
- } catch (Exception e) {
- fail("invocation " + count + " failed to cleanup", e);
- }
- }
- }
- .performTest(inputs);
- }
-
- public void testCopyFolder() {
- final IFolder source = nonExistingFolderInExistingProject;
- IResource[] destinationResources =
- new IResource[] { existingProject, closedProject, nonExistingProject, existingFolderInExistingProject, nonExistingFolderInOtherExistingProject, nonExistingFolderInExistingFolder };
- Boolean[] deepCopy = new Boolean[] { Boolean.TRUE, Boolean.FALSE };
- IProgressMonitor[] monitors = new IProgressMonitor[] { new FussyProgressMonitor(), new CancelingProgressMonitor(), null };
- Object[][] inputs = new Object[][] { destinationResources, deepCopy, monitors };
- new TestPerformer("LinkedResourceTest.testCopyFolder") {
- protected static final String CANCELED = "canceled";
- public boolean shouldFail(Object[] args, int count) {
- IResource destination = (IResource) args[0];
- boolean isDeep = ((Boolean) args[1]).booleanValue();
- IProgressMonitor monitor = (IProgressMonitor)args[2];
- if (monitor instanceof CancelingProgressMonitor)
- return false;
- IResource parent = destination.getParent();
- if (destination.getType() == IResource.PROJECT)
- return true;
- if (!isDeep && (parent == null || parent.getType() != IResource.PROJECT))
- return true;
- if (!parent.isAccessible())
- return true;
- if (destination.exists())
- return true;
- //passed all failure case so it should suceed
- return false;
- }
- public Object invokeMethod(Object[] args, int count) throws Exception {
- IResource destination = (IResource) args[0];
- boolean isDeep = ((Boolean) args[1]).booleanValue();
- IProgressMonitor monitor = (IProgressMonitor) args[2];
- if (monitor instanceof FussyProgressMonitor)
- ((FussyProgressMonitor) monitor).prepare();
- try {
- source.createLink(existingLocation, IResource.NONE, null);
- source.copy(destination.getFullPath(), isDeep ? IResource.NONE : IResource.SHALLOW, monitor);
- } catch (OperationCanceledException e) {
- return CANCELED;
- }
- if (monitor instanceof FussyProgressMonitor)
- ((FussyProgressMonitor) monitor).sanityCheck();
- return null;
- }
- public boolean wasSuccess(Object[] args, Object result, Object[] oldState) throws Exception {
- IResource destination = (IResource) args[0];
- boolean isDeep = ((Boolean) args[1]).booleanValue();
- IProgressMonitor monitor = (IProgressMonitor) args[2];
- if (result == CANCELED)
- return monitor instanceof CancelingProgressMonitor;
- if (!destination.exists())
- return false;
- //destination should only be linked for a shallow copy
- if (isDeep) {
- if (destination.isLinked())
- return false;
- if (source.getLocation().equals(destination.getLocation()))
- return false;
- if (!destination.getProject().getLocation().isPrefixOf(destination.getLocation()))
- return false;
- } else {
- if (!destination.isLinked())
- return false;
- if (!source.getLocation().equals(destination.getLocation()))
- return false;
- assertEquals("1.0", source.getRawLocation(), destination.getRawLocation());
- }
- return true;
- }
- public void cleanUp(Object[] args, int count) {
- super.cleanUp(args, count);
- try {
- doCleanup();
- } catch (Exception e) {
- fail("invocation " + count + " failed to cleanup", e);
- }
- }
- }
- .performTest(inputs);
- }
- /**
- * Tests copying a linked file resource that doesn't exist in the filesystem
- */
- public void testCopyMissingFile() {
- IPath location = getRandomLocation();
- IFile linkedFile = nonExistingFileInExistingProject;
- try {
- linkedFile.createLink(location, IResource.ALLOW_MISSING_LOCAL, getMonitor());
- } catch (CoreException e) {
- fail("1.99", e);
- }
-
- IFile dest = existingProject.getFile("FailedCopyDest");
- try {
- linkedFile.copy(dest.getFullPath(), IResource.NONE, getMonitor());
- fail("2.0");
- } catch (CoreException e1) {
- //should fail
- }
- assertTrue("2.1", !dest.exists());
- try {
- linkedFile.copy(dest.getFullPath(), IResource.FORCE, getMonitor());
- fail("2.2");
- } catch (CoreException e1) {
- //should fail
- }
- assertTrue("2.3", !dest.exists());
- }
- /**
- * Tests copying a linked folder that doesn't exist in the filesystem
- */
- public void testCopyMissingFolder() {
- IPath location = getRandomLocation();
- IFolder linkedFolder = nonExistingFolderInExistingProject;
- try {
- linkedFolder.createLink(location, IResource.ALLOW_MISSING_LOCAL, getMonitor());
- } catch (CoreException e) {
- fail("1.99", e);
- }
-
- IFolder dest = existingProject.getFolder("FailedCopyDest");
- try {
- linkedFolder.copy(dest.getFullPath(), IResource.NONE, getMonitor());
- fail("2.0");
- } catch (CoreException e1) {
- //should fail
- }
- assertTrue("2.1", !dest.exists());
- try {
- linkedFolder.copy(dest.getFullPath(), IResource.FORCE, getMonitor());
- fail("2.2");
- } catch (CoreException e1) {
- //should fail
- }
- assertTrue("2.3", !dest.exists());
- }
- public void testCopyProjectWithLinks() {
- IPath fileLocation = getRandomLocation();
- IFile linkedFile = nonExistingFileInExistingProject;
- IFolder linkedFolder = nonExistingFolderInExistingProject;
- try {
- try {
- createFileInFileSystem(resolvePath(fileLocation));
- linkedFolder.createLink(existingLocation, IResource.NONE, getMonitor());
- linkedFile.createLink(fileLocation, IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- //copy the project
- IProject destination = getWorkspace().getRoot().getProject("CopyTargetProject");
- try {
- existingProject.copy(destination.getFullPath(), IResource.SHALLOW, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- IFile newFile = destination.getFile(linkedFile.getProjectRelativePath());
- assertTrue("3.0", newFile.isLinked());
- assertEquals("3.1", linkedFile.getLocation(), newFile.getLocation());
-
- IFolder newFolder = destination.getFolder(linkedFolder.getProjectRelativePath());
- assertTrue("4.0", newFolder.isLinked());
- assertEquals("4.1", linkedFolder.getLocation(), newFolder.getLocation());
-
- //test project deep copy
- try {
- destination.delete(IResource.NONE, getMonitor());
- existingProject.copy(destination.getFullPath(), IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("5.0", e);
- }
- assertTrue("5.1", !newFile.isLinked());
- assertEquals("5.2", destination.getLocation().append(newFile.getProjectRelativePath()), newFile.getLocation());
- assertTrue("5.3", !newFolder.isLinked());
- assertEquals("5.4", destination.getLocation().append(newFolder.getProjectRelativePath()), newFolder.getLocation());
-
- //test copy project when linked resources don't exist with force=false
- try {
- destination.delete(IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("5.99", e);
- }
- assertTrue("6.0", resolvePath(fileLocation).toFile().delete());
-
- try {
- existingProject.copy(destination.getFullPath(), IResource.NONE, getMonitor());
- fail("6.1");
- } catch (CoreException e) {
- //should fail
- }
- //all members except the missing link should have been copied
- assertTrue("6.2", destination.exists());
- assertTrue("6.2.1", !destination.getFile(linkedFile.getName()).exists());
- try {
- IResource[] srcChildren = existingProject.members();
- for (int i = 0; i < srcChildren.length; i++) {
- if (!srcChildren[i].equals(linkedFile))
- assertNotNull("6.3." + i, destination.findMember(srcChildren[i].getProjectRelativePath()));
- }
- } catch (CoreException e) {
- fail("6.4", e);
- }
- //test copy project when linked resources don't exist with force=true
- //this should mostly suceed, but still throw an exception indicating
- //a resource could not be copied because its location was missing
- try {
- destination.delete(IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("6.5", e);
- }
- try {
- existingProject.copy(destination.getFullPath(), IResource.FORCE, getMonitor());
- fail("6.6");
- } catch (CoreException e) {
- //should fail
- }
- assertTrue("6.7", destination.exists());
- assertTrue("6.7.1", !destination.getFile(linkedFile.getName()).exists());
- //all members except the missing link should have been copied
- try {
- IResource[] srcChildren = existingProject.members();
- for (int i = 0; i < srcChildren.length; i++) {
- if (!srcChildren[i].equals(linkedFile))
- assertNotNull("6.8." + i, destination.findMember(srcChildren[i].getProjectRelativePath()));
- }
- } catch (CoreException e) {
- fail("6.99", e);
- }
- } finally {
- Workspace.clear(resolvePath(fileLocation).toFile());
- }
- }
- public void testDeepMoveProjectWithLinks() {
- IPath fileLocation = getRandomLocation();
- IFile file = nonExistingFileInExistingProject;
- IFolder folder = nonExistingFolderInExistingProject;
- IFile childFile = folder.getFile(childName);
- IResource[] oldResources = new IResource[] { file, folder, existingProject, childFile };
- try {
- try {
- createFileInFileSystem(resolvePath(fileLocation));
- folder.createLink(existingLocation, IResource.NONE, getMonitor());
- file.createLink(fileLocation, IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- //move the project
- IProject destination = getWorkspace().getRoot().getProject("MoveTargetProject");
- IFile newFile = destination.getFile(file.getProjectRelativePath());
- IFolder newFolder = destination.getFolder(folder.getProjectRelativePath());
- IFile newChildFile = newFolder.getFile(childName);
- IResource[] newResources = new IResource[] { destination, newFile, newFolder, newChildFile };
-
- assertDoesNotExistInWorkspace("2.0", destination);
-
- try {
- existingProject.move(destination.getFullPath(), IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("2.1", e);
- }
- assertExistsInWorkspace("3.0", newResources);
- assertDoesNotExistInWorkspace("3.1", oldResources);
- assertTrue("3.2", existingProject.isSynchronized(IResource.DEPTH_INFINITE));
- assertTrue("3.3", destination.isSynchronized(IResource.DEPTH_INFINITE));
-
- assertTrue("3.4", !newFile.isLinked());
- assertEquals("3.5", destination.getLocation().append(newFile.getProjectRelativePath()), newFile.getLocation());
-
- assertTrue("3.6", !newFolder.isLinked());
- assertEquals("3.7", destination.getLocation().append(newFolder.getProjectRelativePath()), newFolder.getLocation());
-
- assertTrue("3.8", destination.isSynchronized(IResource.DEPTH_INFINITE));
- } finally {
- Workspace.clear(resolvePath(fileLocation).toFile());
- }
- }
- /**
- * Tests deleting and then recreating a project
- */
- public void testDeleteProjectWithLinks() {
- IFolder link = nonExistingFolderInExistingProject;
- try {
- link.createLink(existingLocation, IResource.NONE, getMonitor());
- existingProject.delete(IResource.NEVER_DELETE_PROJECT_CONTENT, getMonitor());
- existingProject.create(getMonitor());
- } catch (CoreException e) {
- fail("0.99", e);
- }
-
- //link should not exist until the project is open
- assertTrue("1.0", !link.exists());
-
- try {
- existingProject.open(getMonitor());
- } catch (CoreException e) {
- fail("1.99", e);
- }
-
- //link should now exist
- assertTrue("2.0", link.exists());
- assertTrue("2.1", link.isLinked());
- assertEquals("2.2", resolvePath(existingLocation), link.getLocation());
- }
- /**
- * Automated test of IFile#createLink
- */
- public void testLinkFile() {
- IResource[] interestingResources = new IResource[] { existingFileInExistingProject, nonExistingFileInExistingProject, nonExistingFileInExistingFolder };
- IPath[] interestingLocations = new IPath[] { existingLocation, nonExistingLocation };
- IProgressMonitor[] monitors = new IProgressMonitor[] { new FussyProgressMonitor(), new CancelingProgressMonitor(), null };
- Object[][] inputs = new Object[][] { interestingResources, interestingLocations, monitors };
- new TestPerformer("LinkedResourceTest.testLinkFile") {
- protected static final String CANCELED = "cancelled";
- public boolean shouldFail(Object[] args, int count) {
- IResource resource = (IResource) args[0];
- IPath location = (IPath) args[1];
- IProgressMonitor monitor = (IProgressMonitor)args[2];
- if (monitor instanceof CancelingProgressMonitor)
- return false;
- //This resource already exists in the workspace
- if (resource.exists())
- return true;
- IPath resolvedLocation = resolvePath(location);
- //The corresponding location in the local file system does not exist.
- if (!resolvedLocation.toFile().exists())
- return true;
- //The workspace contains a resource of a different type at the same path as this resource
- if (getWorkspace().getRoot().findMember(resource.getFullPath()) != null)
- return true;
- //The parent of this resource does not exist.
- if (!resource.getParent().isAccessible())
- return true;
- //The parent of this resource is not an open project
- if (resource.getParent().getType() != IResource.PROJECT)
- return true;
- //The name of this resource is not valid (according to IWorkspace.validateName)
- if (!getWorkspace().validateName(resource.getName(), IResource.FOLDER).isOK())
- return true;
- //The corresponding location in the local file system is occupied by a directory (as opposed to a file)
- if (resolvedLocation.toFile().isDirectory())
- return true;
- //passed all failure case so it should suceed
- return false;
- }
- public Object invokeMethod(Object[] args, int count) throws Exception {
- IFile file = (IFile) args[0];
- IPath location = (IPath) args[1];
- IProgressMonitor monitor = (IProgressMonitor) args[2];
- if (monitor instanceof FussyProgressMonitor)
- ((FussyProgressMonitor) monitor).prepare();
- try {
- file.createLink(location, IResource.NONE, monitor);
- } catch (OperationCanceledException e) {
- return CANCELED;
- }
- if (monitor instanceof FussyProgressMonitor)
- ((FussyProgressMonitor) monitor).sanityCheck();
- return null;
- }
- public boolean wasSuccess(Object[] args, Object result, Object[] oldState) throws Exception {
- IFile resource = (IFile) args[0];
- IPath location = (IPath) args[1];
- IProgressMonitor monitor = (IProgressMonitor)args[2];
- if (result == CANCELED)
- return monitor instanceof CancelingProgressMonitor;
- IPath resolvedLocation = resolvePath(location);
- if (!resource.exists() || !resolvedLocation.toFile().exists())
- return false;
- if (!resource.getLocation().equals(resolvedLocation))
- return false;
- if (!resource.isSynchronized(IResource.DEPTH_INFINITE))
- return false;
- return true;
- }
- public void cleanUp(Object[] args, int count) {
- super.cleanUp(args, count);
- try {
- doCleanup();
- } catch (Exception e) {
- fail("invocation " + count + " failed to cleanup", e);
- }
- }
- }
- .performTest(inputs);
- }
- /**
- * Automated test of IFolder#createLink
- */
- public void testLinkFolder() {
- IResource[] interestingResources =
- new IResource[] {
- existingFolderInExistingProject,
- existingFolderInExistingFolder,
- nonExistingFolderInExistingProject,
- nonExistingFolderInNonExistingProject,
- nonExistingFolderInNonExistingFolder };
- IPath[] interestingLocations = new IPath[] { existingLocation, nonExistingLocation };
- IProgressMonitor[] monitors = new IProgressMonitor[] { new FussyProgressMonitor(), new CancelingProgressMonitor(), null };
- Object[][] inputs = new Object[][] { interestingResources, interestingLocations, monitors };
- new TestPerformer("LinkedResourceTest.testLinkFolder") {
- protected static final String CANCELED = "cancelled";
- public boolean shouldFail(Object[] args, int count) {
- IResource resource = (IResource) args[0];
- IPath location = (IPath) args[1];
- IProgressMonitor monitor = (IProgressMonitor)args[2];
- if (monitor instanceof CancelingProgressMonitor)
- return false;
- //This resource already exists in the workspace
- if (resource.exists())
- return true;
- //The corresponding location in the local file system does not exist.
- if (!resolvePath(location).toFile().exists())
- return true;
- //The workspace contains a resource of a different type at the same path as this resource
- if (getWorkspace().getRoot().findMember(resource.getFullPath()) != null)
- return true;
- //The parent of this resource does not exist.
- if (!resource.getParent().isAccessible())
- return true;
- //The parent of this resource is not an open project
- if (resource.getParent().getType() != IResource.PROJECT)
- return true;
- //The name of this resource is not valid (according to IWorkspace.validateName)
- if (!getWorkspace().validateName(resource.getName(), IResource.FOLDER).isOK())
- return true;
- //The corresponding location in the local file system is occupied by a file (as opposed to a directory)
- if (resolvePath(location).toFile().isFile())
- return true;
- //passed all failure case so it should suceed
- return false;
- }
- public Object invokeMethod(Object[] args, int count) throws Exception {
- IFolder folder = (IFolder) args[0];
- IPath location = (IPath) args[1];
- IProgressMonitor monitor = (IProgressMonitor) args[2];
- if (monitor instanceof FussyProgressMonitor)
- ((FussyProgressMonitor) monitor).prepare();
- try {
- folder.createLink(location, IResource.NONE, monitor);
- } catch (OperationCanceledException e) {
- return CANCELED;
- }
- if (monitor instanceof FussyProgressMonitor)
- ((FussyProgressMonitor) monitor).sanityCheck();
- return null;
- }
- public boolean wasSuccess(Object[] args, Object result, Object[] oldState) throws Exception {
- IFolder resource = (IFolder) args[0];
- IPath location = (IPath) args[1];
- IProgressMonitor monitor = (IProgressMonitor)args[2];
- if (result == CANCELED)
- return monitor instanceof CancelingProgressMonitor;
- IPath resolvedLocation = resolvePath(location);
- if (!resource.exists() || !resolvedLocation.toFile().exists())
- return false;
- if (!resource.getLocation().equals(resolvedLocation))
- return false;
- //ensure child exists
- if (!resource.getFile(childName).exists())
- return false;
- return true;
- }
- public void cleanUp(Object[] args, int count) {
- super.cleanUp(args, count);
- try {
- doCleanup();
- } catch (Exception e) {
- fail("invocation " + count + " failed to cleanup", e);
- }
- }
- }
- .performTest(inputs);
-
- }
- public void testMoveFile() {
- final IFile source = nonExistingFileInExistingProject;
- IResource[] destinationResources = new IResource[] { existingProject, closedProject, nonExistingFileInOtherExistingProject, nonExistingFileInExistingFolder };
- Boolean[] deepCopy = new Boolean[] { Boolean.TRUE, Boolean.FALSE };
- IProgressMonitor[] monitors = new IProgressMonitor[] { new FussyProgressMonitor(), new CancelingProgressMonitor(), null };
- Object[][] inputs = new Object[][] { destinationResources, deepCopy, monitors };
- new TestPerformer("LinkedResourceTest.testMoveFile") {
- protected static final String CANCELED = "cancelled";
- public boolean shouldFail(Object[] args, int count) {
- IResource destination = (IResource) args[0];
- boolean isDeep = ((Boolean) args[1]).booleanValue();
- IProgressMonitor monitor = (IProgressMonitor)args[2];
- if (monitor instanceof CancelingProgressMonitor)
- return false;
- IResource parent = destination.getParent();
- if (!isDeep && (parent == null || parent.getType() != IResource.PROJECT))
- return true;
- if (!parent.isAccessible())
- return true;
- if (destination.exists())
- return true;
- //passed all failure case so it should suceed
- return false;
- }
- public Object invokeMethod(Object[] args, int count) throws Exception {
- IResource destination = (IResource) args[0];
- boolean isDeep = ((Boolean) args[1]).booleanValue();
- IProgressMonitor monitor = (IProgressMonitor) args[2];
- if (monitor instanceof FussyProgressMonitor)
- ((FussyProgressMonitor) monitor).prepare();
- try {
- source.createLink(localFile, IResource.NONE, null);
- source.move(destination.getFullPath(), isDeep ? IResource.NONE : IResource.SHALLOW, monitor);
- } catch (OperationCanceledException e) {
- return CANCELED;
- }
- if (monitor instanceof FussyProgressMonitor)
- ((FussyProgressMonitor) monitor).sanityCheck();
- return null;
- }
- public boolean wasSuccess(Object[] args, Object result, Object[] oldState) throws Exception {
- IResource destination = (IResource) args[0];
- boolean isDeep = ((Boolean) args[1]).booleanValue();
- IProgressMonitor monitor = (IProgressMonitor)args[2];
- if (result == CANCELED)
- return monitor instanceof CancelingProgressMonitor;
- if (!destination.exists())
- return false;
- //destination should only be linked for a shallow move
- if (isDeep) {
- if (destination.isLinked())
- return false;
- if (resolvePath(localFile).equals(destination.getLocation()))
- return false;
- if (!destination.getProject().getLocation().isPrefixOf(destination.getLocation()))
- return false;
- } else {
- if (!destination.isLinked())
- return false;
- if (!resolvePath(localFile).equals(destination.getLocation()))
- return false;
- }
- return true;
- }
- public void cleanUp(Object[] args, int count) {
- super.cleanUp(args, count);
- try {
- doCleanup();
- } catch (Exception e) {
- fail("invocation " + count + " failed to cleanup", e);
- }
- }
- }
- .performTest(inputs);
- }
-
- public void testMoveFolder() {
- IResource[] sourceResources = new IResource[] { nonExistingFolderInExistingProject };
- IResource[] destinationResources =
- new IResource[] { existingProject, closedProject, nonExistingProject, existingFolderInExistingProject, nonExistingFolderInOtherExistingProject, nonExistingFolderInExistingFolder };
- IProgressMonitor[] monitors = new IProgressMonitor[] { new FussyProgressMonitor(), new CancelingProgressMonitor(), null };
- Object[][] inputs = new Object[][] { sourceResources, destinationResources, monitors };
- new TestPerformer("LinkedResourceTest.testMoveFolder") {
- protected static final String CANCELED = "cancelled";
- public boolean shouldFail(Object[] args, int count) {
- IResource destination = (IResource) args[1];
- IProgressMonitor monitor = (IProgressMonitor)args[2];
- if (monitor instanceof CancelingProgressMonitor)
- return false;
- IResource parent = destination.getParent();
- if (parent == null || parent.getType() != IResource.PROJECT)
- return true;
- if (!parent.isAccessible())
- return true;
- if (destination.exists())
- return true;
- //passed all failure case so it should suceed
- return false;
- }
- public Object invokeMethod(Object[] args, int count) throws Exception {
- IFolder source = (IFolder) args[0];
- IResource destination = (IResource) args[1];
- IProgressMonitor monitor = (IProgressMonitor) args[2];
- if (monitor instanceof FussyProgressMonitor)
- ((FussyProgressMonitor) monitor).prepare();
- try {
- source.createLink(existingLocation, IResource.NONE, null);
- source.move(destination.getFullPath(), IResource.SHALLOW, monitor);
- } catch (OperationCanceledException e) {
- return CANCELED;
- }
- if (monitor instanceof FussyProgressMonitor)
- ((FussyProgressMonitor) monitor).sanityCheck();
- return null;
- }
- public boolean wasSuccess(Object[] args, Object result, Object[] oldState) throws Exception {
- IResource destination = (IResource) args[1];
- IProgressMonitor monitor = (IProgressMonitor)args[2];
- if (result == CANCELED)
- return monitor instanceof CancelingProgressMonitor;
- if (!destination.exists())
- return false;
- if (!destination.isLinked())
- return false;
- if (!resolvePath(existingLocation).equals(destination.getLocation()))
- return false;
- return true;
- }
- public void cleanUp(Object[] args, int count) {
- super.cleanUp(args, count);
- try {
- doCleanup();
- } catch (Exception e) {
- fail("invocation " + count + " failed to cleanup", e);
- }
- }
- }
- .performTest(inputs);
- }
- /**
- * Tests moving a linked file resource that doesn't exist in the filesystem
- */
- public void testMoveMissingFile() {
- IPath location = getRandomLocation();
- IFile linkedFile = nonExistingFileInExistingProject;
- try {
- linkedFile.createLink(location, IResource.ALLOW_MISSING_LOCAL, getMonitor());
- } catch (CoreException e) {
- fail("1.99", e);
- }
-
- IFile dest = existingProject.getFile("FailedMoveDest");
- try {
- linkedFile.move(dest.getFullPath(), IResource.NONE, getMonitor());
- fail("2.0");
- } catch (CoreException e1) {
- //should fail
- }
- assertTrue("2.1", !dest.exists());
- try {
- linkedFile.move(dest.getFullPath(), IResource.FORCE, getMonitor());
- fail("2.2");
- } catch (CoreException e1) {
- //should fail
- }
- assertTrue("2.3", !dest.exists());
- }
- /**
- * Tests moving a linked folder that doesn't exist in the filesystem
- */
- public void testMoveMissingFolder() {
- IPath location = getRandomLocation();
- IFolder linkedFolder = nonExistingFolderInExistingProject;
- try {
- linkedFolder.createLink(location, IResource.ALLOW_MISSING_LOCAL, getMonitor());
- } catch (CoreException e) {
- fail("1.99", e);
- }
-
- IFolder dest = existingProject.getFolder("FailedMoveDest");
- try {
- linkedFolder.move(dest.getFullPath(), IResource.NONE, getMonitor());
- fail("2.0");
- } catch (CoreException e1) {
- //should fail
- }
- assertTrue("2.1", !dest.exists());
- try {
- linkedFolder.move(dest.getFullPath(), IResource.FORCE, getMonitor());
- fail("2.2");
- } catch (CoreException e1) {
- //should fail
- }
- assertTrue("2.3", !dest.exists());
- }
- public void testMoveProjectWithLinks() {
- IPath fileLocation = getRandomLocation();
- IFile file = nonExistingFileInExistingProject;
- IFolder folder = nonExistingFolderInExistingProject;
- IFile childFile = folder.getFile(childName);
- IResource[] oldResources = new IResource[] { file, folder, existingProject, childFile };
- try {
- try {
- createFileInFileSystem(resolvePath(fileLocation));
- folder.createLink(existingLocation, IResource.NONE, getMonitor());
- file.createLink(fileLocation, IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- //move the project
- IProject destination = getWorkspace().getRoot().getProject("MoveTargetProject");
- IFile newFile = destination.getFile(file.getProjectRelativePath());
- IFolder newFolder = destination.getFolder(folder.getProjectRelativePath());
- IFile newChildFile = newFolder.getFile(childName);
- IResource[] newResources = new IResource[] { destination, newFile, newFolder, newChildFile };
-
- assertDoesNotExistInWorkspace("2.0", destination);
-
- try {
- existingProject.move(destination.getFullPath(), IResource.SHALLOW, getMonitor());
- } catch (CoreException e) {
- fail("2.1", e);
- }
- assertExistsInWorkspace("3.0", newResources);
- assertDoesNotExistInWorkspace("3.1", oldResources);
-
- assertTrue("3.2", newFile.isLinked());
- assertEquals("3.3", resolvePath(fileLocation), newFile.getLocation());
-
- assertTrue("3.4", newFolder.isLinked());
- assertEquals("3.5", resolvePath(existingLocation), newFolder.getLocation());
-
- assertTrue("3.6", destination.isSynchronized(IResource.DEPTH_INFINITE));
-
- //now do a deep move back to the original project
- try {
- destination.move(existingProject.getFullPath(), IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("5.0", e);
- }
- assertExistsInWorkspace("5.1", oldResources);
- assertDoesNotExistInWorkspace("5.2", newResources);
- assertTrue("5.3", !file.isLinked());
- assertTrue("5.4", !folder.isLinked());
- assertEquals("5.5", existingProject.getLocation().append(file.getProjectRelativePath()), file.getLocation());
- assertEquals("5.6", existingProject.getLocation().append(folder.getProjectRelativePath()), folder.getLocation());
- assertTrue("5.7", existingProject.isSynchronized(IResource.DEPTH_INFINITE));
- assertTrue("5.8", destination.isSynchronized(IResource.DEPTH_INFINITE));
- } finally {
- Workspace.clear(resolvePath(fileLocation).toFile());
- }
- }
- public void testNatureVeto() {
- //note: simpleNature has the link veto turned on.
-
- //test create link on project with nature veto
- try {
- IProjectDescription description = existingProject.getDescription();
- description.setNatureIds(new String[] { NATURE_SIMPLE });
- existingProject.setDescription(description, IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
- try {
- nonExistingFolderInExistingProject.createLink(existingLocation, IResource.NONE, getMonitor());
- fail("1.1");
- } catch (CoreException e) {
- //should fail
- }
- try {
- nonExistingFileInExistingProject.createLink(localFile, IResource.NONE, getMonitor());
- fail("1.2");
- } catch (CoreException e) {
- //should fail
- }
-
- //test add nature with veto to project that already has link
- try {
- existingProject.delete(IResource.FORCE, getMonitor());
- existingProject.create(getMonitor());
- existingProject.open(getMonitor());
- nonExistingFolderInExistingProject.createLink(existingLocation, IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
- try {
- IProjectDescription description = existingProject.getDescription();
- description.setNatureIds(new String[] { NATURE_SIMPLE });
- existingProject.setDescription(description, IResource.NONE, getMonitor());
- fail("3.0");
- } catch (CoreException e) {
- //should fail
- }
- }
-
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedResourceWithPathVariableTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedResourceWithPathVariableTest.java
deleted file mode 100644
index ee87e95..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedResourceWithPathVariableTest.java
+++ /dev/null
@@ -1,472 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-
-/**
- * This class extends <code>LinkedResourceTest</code> in order to use
- * randomly generated locations that are always variable-based.
- * TODO: add tests specific to linking resources using path variables (then
- * removing the variable, change the variable value, etc)
- */
-public class LinkedResourceWithPathVariableTest extends LinkedResourceTest {
-
- private final static String VARIABLE_NAME = "ROOT";
-
- public LinkedResourceWithPathVariableTest() {
- super();
- }
- public LinkedResourceWithPathVariableTest(String name) {
- super(name);
- }
- public static Test suite() {
- return new TestSuite(LinkedResourceWithPathVariableTest.class);
- }
- protected void setUp() throws Exception {
- IPath base = Platform.getLocation().removeLastSegments(1);
- getWorkspace().getPathVariableManager().setValue(VARIABLE_NAME, base);
- super.setUp();
- }
- protected void tearDown() throws Exception {
- getWorkspace().getPathVariableManager().setValue(VARIABLE_NAME, null);
- super.tearDown();
- }
- /**
- * @see org.eclipse.core.tests.harness.EclipseWorkspaceTest#getRandomLocation()
- */
- public IPath getRandomLocation() {
- IPathVariableManager pathVars = getWorkspace().getPathVariableManager();
- //low order bits are current time, high order bits are static counter
- IPath parent = new Path(VARIABLE_NAME);
- final long mask = 0x00000000FFFFFFFFL;
- long segment = (((long) ++nextLocationCounter) << 32) | (System.currentTimeMillis() & mask);
- IPath path = parent.append(Long.toString(segment));
- while (pathVars.resolvePath(path).toFile().exists()) {
- try {
- Thread.sleep(10);
- } catch (InterruptedException e) {
- }
- segment = (((long) ++nextLocationCounter) << 32) | (System.currentTimeMillis() & mask);
- path = parent.append(Long.toString(segment));
- }
- return path;
- }
- /**
- * @see LinkedResourceTest#resolvePath(org.eclipse.core.runtime.IPath)
- */
- protected IPath resolvePath(IPath path) {
- return getWorkspace().getPathVariableManager().resolvePath(path);
- }
-
-
- /**
- * Tests a scenario where a variable used in a linked file location is
- * removed.
- */
- public void testFileVariableRemoved() {
- final IPathVariableManager manager = getWorkspace().getPathVariableManager();
-
- IFile file = nonExistingFileInExistingProject;
- IPath existingValue = manager.getValue(VARIABLE_NAME);
-
- // creates a variable-based location
- IPath variableBasedLocation = getRandomLocation();
-
- // the file should not exist yet
- assertDoesNotExistInWorkspace("1.0", file);
-
- try {
- file.createLink(variableBasedLocation, IResource.ALLOW_MISSING_LOCAL, null);
- } catch (CoreException e) {
- fail("1.1", e);
- }
- try {
- file.setContents(getContents("contents for a file"), IResource.FORCE, null);
- } catch (CoreException e) {
- fail("1.2", e);
- }
-
- // now the file exists in both workspace and file system
- assertExistsInWorkspace("2.0", file);
- assertExistsInFileSystem("2.1", file);
-
- // removes the variable - the location will be undefined (null)
- try {
- manager.setValue(VARIABLE_NAME, null);
- } catch (CoreException e) {
- fail("3.0", e);
- }
- assertExistsInWorkspace("3,1", file);
-
- //refresh local - should not fail or make the link disappear
- try {
- file.refreshLocal(IResource.DEPTH_ONE, getMonitor());
- file.getProject().refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- } catch (CoreException e) {
- fail("3.2");
- }
-
- assertExistsInWorkspace("3.3", file);
-
- // try to change resource's contents
- try {
- file.setContents(getContents("new contents"), IResource.NONE, null);
- // Resource has no-defined location - should fail
- fail("3.4");
- } catch (CoreException re) {
- // success: resource had no defined location
- }
-
- assertExistsInWorkspace("3.5", file);
- // the location is null
- assertNull("3.6", file.getLocation());
-
- // try validating another link location while there is a link with null location
- IFile other = existingProject.getFile("OtherVar");
- getWorkspace().validateLinkLocation(other, getRandomLocation());
-
- // re-creates the variable with its previous value
- try {
- manager.setValue(VARIABLE_NAME, existingValue);
- } catch (CoreException e) {
- fail("4.0", e);
- }
-
- assertExistsInWorkspace("5.0", file);
- assertNotNull("5.1", file.getLocation());
- assertExistsInFileSystem("5.2", file);
- // the contents must be the original ones
- try {
- assertTrue("5.3", compareContent(file.getContents(true), getContents("contents for a file")));
- } catch (CoreException e) {
- fail("5.4", e);
- }
- }
-
- /**
- * Tests a scenario where a variable used in a linked folder location is
- * removed.
- */
- public void testFolderVariableRemoved() {
- final IPathVariableManager manager = getWorkspace().getPathVariableManager();
-
- IFolder folder = nonExistingFolderInExistingProject;
- IFile childFile = folder.getFile(childName);
- IPath existingValue = manager.getValue(VARIABLE_NAME);
-
- // creates a variable-based location
- IPath variableBasedLocation = getRandomLocation();
-
- // the file should not exist yet
- assertDoesNotExistInWorkspace("1.0", folder);
-
- try {
- folder.createLink(variableBasedLocation, IResource.ALLOW_MISSING_LOCAL, null);
- childFile.create(getRandomContents(), IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("1.1", e);
- }
- try {
- childFile.setContents(getContents("contents for a file"), IResource.FORCE, null);
- } catch (CoreException e) {
- fail("1.2", e);
- }
-
- // now the file exists in both workspace and file system
- assertExistsInWorkspace("2.0", folder);
- assertExistsInWorkspace("2.1", childFile);
- assertExistsInFileSystem("2.2", folder);
- assertExistsInFileSystem("2.3", childFile);
-
- // removes the variable - the location will be undefined (null)
- try {
- manager.setValue(VARIABLE_NAME, null);
- } catch (CoreException e) {
- fail("3.0", e);
- }
- assertExistsInWorkspace("3.1", folder);
-
- //refresh local - should not fail but should cause link's children to disappear
- try {
- folder.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- folder.getProject().refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- } catch (CoreException e) {
- fail("3.2", e);
- }
- assertExistsInWorkspace("3.3", folder);
- assertDoesNotExistInWorkspace("3.4", childFile);
-
- //try to copy a file to the folder
- IFile destination = folder.getFile(existingFileInExistingProject.getName());
- try {
- existingFileInExistingProject.copy(destination.getFullPath(), IResource.NONE, getMonitor());
- //should fail
- fail("3.5");
- } catch (CoreException e) {
- //expected
- }
- assertTrue("3.6", !destination.exists());
-
- //try to create a sub-file
- try {
- destination.create(getRandomContents(), IResource.NONE, getMonitor());
- //shoudl fail
- fail("3.7");
- } catch (CoreException e) {
- //expected
- }
-
- //try to create a sub-folder
- IFolder subFolder = folder.getFolder("SubFolder");
- try {
- subFolder.create(IResource.NONE, true, getMonitor());
- //should fail
- fail("3.8");
- } catch (CoreException e) {
- //expected
- }
-
- // try to change resource's contents
- try {
- childFile.setContents(getContents("new contents"), IResource.NONE, null);
- // Resource has no-defined location - should fail
- fail("4.0");
- } catch (CoreException re) {
- // success: resource had no defined location
- }
-
- assertExistsInWorkspace("4.1", folder);
- // the location is null
- assertNull("4.2", folder.getLocation());
-
- // re-creates the variable with its previous value
- try {
- manager.setValue(VARIABLE_NAME, existingValue);
- } catch (CoreException e) {
- fail("5.0", e);
- }
-
- assertExistsInWorkspace("6.0", folder);
- assertNotNull("6.1", folder.getLocation());
- assertExistsInFileSystem("6.2", folder);
- assertDoesNotExistInWorkspace("6.3", childFile);
- assertExistsInFileSystem("6.4", childFile);
-
- //refresh should recreate the child
- try {
- folder.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- } catch (CoreException e) {
- fail("7.0", e);
- }
- assertExistsInWorkspace("7.1", folder);
- assertExistsInWorkspace("7.2", childFile);
- }
- /**
- * Tests scenario where links are relative to undefined variables
- */
- public void testUndefinedVariable() {
- IPath folderLocation = new Path("NOVAR/folder");
- IPath fileLocation = new Path("NOVAR/abc.txt");
- IFile testFile = existingProject.getFile("UndefinedVar.txt");
- IFolder testFolder = existingProject.getFolder("UndefinedVarTest");
-
- //should fail to create links
- try {
- testFile.createLink(fileLocation, IResource.NONE, getMonitor());
- fail("1.0");
- } catch (CoreException e) {
- //should fail
- }
- try {
- testFolder.createLink(folderLocation, IResource.NONE, getMonitor());
- fail("1.1");
- } catch (CoreException e) {
- //should fail
- }
-
- //validate method should return warning
- assertTrue("1.2", getWorkspace().validateLinkLocation(testFolder, folderLocation).getSeverity() == IStatus.WARNING);
- assertTrue("1.3", getWorkspace().validateLinkLocation(testFile, fileLocation).getSeverity() == IStatus.WARNING);
-
- //should suceed with ALLOW_MISSING_LOCAL
- try {
- testFile.createLink(fileLocation, IResource.ALLOW_MISSING_LOCAL, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
- try {
- testFolder.createLink(folderLocation, IResource.ALLOW_MISSING_LOCAL, getMonitor());
- } catch (CoreException e) {
- fail("2.1", e);
- }
-
- //copy should fail
- IPath copyFileDestination = existingProject.getFullPath().append("CopyFileDest");
- IPath copyFolderDestination = existingProject.getFullPath().append("CopyFolderDest");
-
- try {
- testFile.copy(copyFileDestination, IResource.NONE, getMonitor());
- fail("3.0");
- } catch (CoreException e) {
- //should fail
- }
- try {
- testFolder.copy(copyFolderDestination, IResource.NONE, getMonitor());
- fail("3.1");
- } catch (CoreException e) {
- //should fail
- }
-
- //move should fail
- IPath moveFileDestination = existingProject.getFullPath().append("MoveFileDest");
- IPath moveFolderDestination = existingProject.getFullPath().append("MoveFolderDest");
-
- try {
- testFile.move(moveFileDestination, IResource.NONE, getMonitor());
- fail("4.0");
- } catch (CoreException e) {
- //should fail
- }
- try {
- testFolder.move(moveFolderDestination, IResource.NONE, getMonitor());
- fail("4.1");
- } catch (CoreException e) {
- //should fail
- }
-
- //refresh local should suceed
- try {
- testFile.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- testFolder.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- testFile.refreshLocal(IResource.DEPTH_ZERO, getMonitor());
- testFolder.refreshLocal(IResource.DEPTH_ZERO, getMonitor());
- existingProject.refreshLocal(IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("5.0", e);
- }
-
- //renaming the project shallow is ok
- try {
- IProject project = testFolder.getProject();
- IProjectDescription desc = project.getDescription();
- desc.setName("moveDest");
- project.move(desc, IResource.SHALLOW | IResource.FORCE, getMonitor());
- } catch (CoreException e) {
- fail("6.0");
- }
-
- //delete should suceed
- try {
- testFile.delete(IResource.NONE, getMonitor());
- testFolder.delete(IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("9.0", e);
- }
- }
- /**
- * Tests a scenario where a variable used in a linked file location is
- * changed.
- */
- public void testVariableChanged() {
- final IPathVariableManager manager = getWorkspace().getPathVariableManager();
-
- IPath existingValue = manager.getValue(VARIABLE_NAME);
-
- IFile file = nonExistingFileInExistingProject;
-
- // creates a variable-based location
- IPath variableBasedLocation = getRandomLocation();
-
- // the file should not exist yet
- assertDoesNotExistInWorkspace("1.0", file);
-
- try {
- file.createLink(variableBasedLocation, IResource.ALLOW_MISSING_LOCAL, getMonitor());
- } catch (CoreException e) {
- fail("1.1", e);
- }
- try {
- file.setContents(getContents("contents for a file"), IResource.FORCE, getMonitor());
- } catch (CoreException e) {
- fail("1.2", e);
- }
-
- // now the file exists in both workspace and file system
- assertExistsInWorkspace("2.0", file);
- assertExistsInFileSystem("2.1", file);
-
- // changes the variable value - the file location will change
- try {
- manager.setValue(VARIABLE_NAME, super.getRandomLocation());
- } catch (CoreException e) {
- fail("2.2", e);
- }
-
- // try to change resource's contents
- try {
- file.setContents(getContents("new contents"), IResource.NONE, getMonitor());
- // Resource was out of sync - should not be able to change
- fail("3.0");
- } catch (CoreException e) {
- assertEquals("3.1", IResourceStatus.OUT_OF_SYNC_LOCAL, e.getStatus().getCode());
- }
-
- assertExistsInWorkspace("3.2", file);
- // the location is different - does not exist anymore
- assertDoesNotExistInFileSystem("3.3", file);
-
- // successfuly changes resource's contents (using IResource.FORCE)
- try {
- file.setContents(getContents("contents in different location"), IResource.FORCE, getMonitor());
- } catch (CoreException e) {
- fail("4.0", e);
- }
-
- // now the file exists in a different location
- assertExistsInFileSystem("4.1", file);
-
- // its location must have changed reflecting the variable change
- IPath expectedNewLocation = manager.resolvePath(variableBasedLocation);
- IPath actualNewLocation = file.getLocation();
- assertEquals("4.2", expectedNewLocation, actualNewLocation);
-
- // its contents are as just set
- try {
- assertTrue("4.3", compareContent(file.getContents(), getContents("contents in different location")));
- } catch (CoreException e) {
- fail("4.4", e);
- }
-
- // clean-up
- ensureDoesNotExistInFileSystem(file);
-
- // restore the previous value
- try {
- manager.setValue(VARIABLE_NAME, existingValue);
- } catch (CoreException e) {
- fail("5.0", e);
- }
-
- assertExistsInWorkspace("5.1", file);
- assertExistsInFileSystem("5.2", file);
- // the contents must be the original ones
- try {
- assertTrue("5.3", compareContent(file.getContents(true), getContents("contents for a file")));
- } catch (CoreException e) {
- fail("5.4", e);
- }
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkerAttributeChangeListener.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkerAttributeChangeListener.java
deleted file mode 100644
index 515dd57..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkerAttributeChangeListener.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import junit.framework.Assert;
-import junit.framework.AssertionFailedError;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-
-/**
- * This class works by recording the current state of given markers,
- * then verifying that the marker deltas accurately reflect the old
- * marker state.
- */
-public class MarkerAttributeChangeListener extends Assert implements IResourceChangeListener {
- //Map of (Long(id) -> Map of (String(attribute key) -> Object(attribute value)))
- private Map attributeMap = new HashMap();
-
- //cache the exception because it can't be thrown from a listener
- private AssertionFailedError error;
-
- public void expectChanges(IMarker marker) throws CoreException {
- expectChanges(new IMarker[] {marker});
- }
- public void expectChanges(IMarker[] markers) throws CoreException {
- error = null;
- attributeMap.clear();
-
- for (int i = 0; i < markers.length; i++) {
- attributeMap.put(new Long(markers[i].getId()), markers[i].getAttributes());
- }
- }
- /**
- * @see IResourceChangeListener#resourceChanged(IResourceChangeEvent)
- */
- public void resourceChanged(IResourceChangeEvent event) {
- IMarkerDelta[] deltas = event.findMarkerDeltas(null, true);
- try {
- checkDelta(deltas);
- } catch (AssertionFailedError e) {
- error = e;
- }
- }
- private void checkDelta(IMarkerDelta[] deltas) throws AssertionFailedError {
- assertEquals("wrong number of changes", attributeMap.size(), deltas.length);
- for (int i = 0; i < deltas.length; i++) {
- Map values = (Map)attributeMap.get(new Long(deltas[i].getId()));
- assertEquals("Changes different from expecations", deltas[i].getAttributes(), values);
- }
- }
- /**
- * Verifies that the delta was as expected. Throws an appropriate
- * assertion failure if the delta did not meet expectations.
- */
- public void verifyChanges() {
- if (error != null) {
- throw error;
- }
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkerSetTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkerSetTest.java
deleted file mode 100644
index d63dc0b..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkerSetTest.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import java.util.Arrays;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.resources.*;
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-public class MarkerSetTest extends EclipseWorkspaceTest {
-
- /** True if debug info should be logged */
- private boolean debug = false;
-/**
- * Need a zero argument constructor to satisfy the test harness.
- * This constructor should not do any real work nor should it be
- * called by user code.
- */
-public MarkerSetTest() {
-}
-/**
- * Creates a new markers test.
- */
-public MarkerSetTest(String name) {
- super(name);
-}
-public void assertEquals(String message, IMarkerSetElement[] array1, IMarkerSetElement[] array2) {
- assertNotNull(message, array1);
- assertNotNull(message, array2);
- assertEquals(message, array1.length, array2.length);
- IMarkerSetElement[] m1 = new IMarkerSetElement[array1.length];
- System.arraycopy(array1, 0, m1, 0, array1.length);
- IMarkerSetElement[] m2 = new IMarkerSetElement[array2.length];
- System.arraycopy(array2, 0, m2, 0, array2.length);
- java.util.Comparator compare = new java.util.Comparator() {
- public int compare(Object o1, Object o2) {
- long id1 = ((IMarkerSetElement) o1).getId();
- long id2 = ((IMarkerSetElement) o2).getId();
- if (id1 == id2)
- return 0;
- return id1 < id2 ? -1 : 1;
- }
- };
- Arrays.sort(m1, compare);
- Arrays.sort(m2, compare);
- for (int i = 0; i < m1.length; i++)
- assertEquals(message, m1[i].getId(), m2[i].getId());
-}
-/**
- * Configures the markers test suite.
- */
-public static Test suite() {
- return new TestSuite(MarkerSetTest.class);
-
- //TestSuite suite = new TestSuite();
- //suite.addTest(new MarkerSetTest("_testPR"));
- //return suite;
-}
-public void testAdd() {
-
- // create the objects to insert into the set
- MarkerSet set = new MarkerSet();
- int max = 100;
- MarkerInfo info = null;
- MarkerInfo[] infos = new MarkerInfo[max];
- for (int i = 0; i < max; i++) {
- info = new MarkerInfo();
- info.setId((long) i);
- info.setType(IMarker.PROBLEM);
- info.setAttribute(IMarker.MESSAGE, getRandomString());
- infos[i] = info;
- }
-
- // add each info to the set
- for (int i = 0; i < infos.length; i++) {
- info = infos[i];
- set.add(info);
- assertTrue("2.0." + i, set.contains(info.getId()));
- assertEquals("2.1." + i, i + 1, set.size());
- }
-
- // make sure they are all still there
- assertEquals("3.0", max, set.size());
- for (int i = 0; i < infos.length; i++) {
- info = infos[i];
- assertTrue("3.1." + i, set.contains(info.getId()));
- assertNotNull("3.2." + i, set.get(info.getId()));
- }
-}
-public void testElements() {
-
- // populate the set
- MarkerSet set = new MarkerSet();
- int max = 100;
- MarkerInfo info = null;
- MarkerInfo[] infos = new MarkerInfo[max];
- for (int i = 0; i < max; i++) {
- info = new MarkerInfo();
- info.setId((long) i);
- info.setType(IMarker.PROBLEM);
- info.setAttribute(IMarker.MESSAGE, getRandomString());
- infos[i] = info;
- }
- set.addAll(infos);
- assertEquals("1.0", max, set.size());
-
- // remove each element
- assertEquals("2.0", set.elements(), infos);
-}
-public void testRemove() {
-
- // populate the set
- MarkerSet set = new MarkerSet();
- int max = 100;
- MarkerInfo info = null;
- MarkerInfo[] infos = new MarkerInfo[max];
- for (int i = 0; i < max; i++) {
- info = new MarkerInfo();
- info.setId((long) i);
- info.setType(IMarker.PROBLEM);
- info.setAttribute(IMarker.MESSAGE, getRandomString());
- infos[i] = info;
- }
- set.addAll(infos);
- assertEquals("1.0", max, set.size());
-
- // remove each element
- for (int i = max - 1; i >= 0; i--) {
- info = infos[i];
- set.remove(info);
- assertTrue("2.0." + i, !set.contains(info.getId()));
- assertEquals("2.1," + i, i, set.size());
- // check that the others still exist
- for (int j = 0; j < i; j++)
- assertTrue("2.2." + j, set.contains(infos[j].getId()));
- }
-
- // all gone?
- assertEquals("3.0", 0, set.size());
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkerTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkerTest.java
deleted file mode 100644
index 1491dde..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkerTest.java
+++ /dev/null
@@ -1,1874 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import java.io.*;
-import java.io.File;
-import java.util.*;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.resources.*;
-import org.eclipse.core.internal.watson.IPathRequestor;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-public class MarkerTest extends EclipseWorkspaceTest {
-
- public static final String TRANSIENT_MARKER = "org.eclipse.core.tests.resources.transientmarker";
-
- /** The collection of resources used for testing. */
- IResource[] resources;
-
-/**
- * Need a zero argument constructor to satisfy the test harness.
- * This constructor should not do any real work nor should it be
- * called by user code.
- */
-public MarkerTest() {
-}
-/**
- * Creates a new markers test.
- */
-public MarkerTest(String name) {
- super(name);
-}
-/**
- * Tests the appearance of marker changes in the resource delta.
- */
-public void _testMarkerChangesInDelta3() {
- log("TestMarkerChangesInDelta3");
-
- // Create and register a listener.
- final MarkersChangeListener listener = new MarkersChangeListener();
- getWorkspace().addResourceChangeListener(listener);
-
- try {
- IResource resource = getWorkspace().getRoot().findMember("1");
- IResource destinationResource = null;
- IResource child;
- IResource destinationChild;
- IPath destination;
- IMarker[] markers = new IMarker[4];
-
- // MOVE the resource
- try {
- destination = resource.getFullPath().removeLastSegments(1).append(resource.getFullPath().lastSegment() + "new");
- markers[0] = resource.createMarker(IMarker.BOOKMARK);
- child = ((IProject) resource).members()[0];
- markers[1] = child.createMarker(IMarker.TASK);
- listener.reset();
- resource.move(destination, false, getMonitor());
- destinationResource = getWorkspace().getRoot().findMember(destination);
- markers[2] = destinationResource.getMarker(0);
- destinationChild = ((IProject) destinationResource).findMember(child.getName());
- markers[3] = destinationChild.getMarker(0);
- assertEquals("1.1." + resource.getFullPath(), 4, listener.numAffectedResources());
- assertTrue("1.2." + resource.getFullPath(), listener.checkChanges(resource, null, new IMarker[] { markers[0] }, null));
- assertTrue("1.3." + resource.getFullPath(), listener.checkChanges(child, null, new IMarker[] { markers[1] }, null));
- assertTrue("1.4." + destinationResource.getFullPath(), listener.checkChanges(destinationResource, new IMarker[] { markers[2] }, null, null));
- assertTrue("1.5." + destinationResource.getFullPath(), listener.checkChanges(destinationChild, new IMarker[] { markers[3] }, null, null));
- } catch (CoreException e) {
- fail("1.99", e);
- }
-
- // COPY the resource and look at the deltas
- try {
- resource = getWorkspace().getRoot().findMember("2");
- destination = resource.getFullPath().removeLastSegments(1).append(resource.getFullPath().lastSegment() + "copy");
- markers[0] = resource.createMarker(IMarker.BOOKMARK);
- listener.reset();
- resource.copy(destination, false, getMonitor());
- destinationResource = getWorkspace().getRoot().findMember(destination);
- markers[1] = destinationResource.getMarker(0);
- assertEquals("2.1." + resource.getFullPath(), 1, listener.numAffectedResources());
- assertTrue("2.3." + destinationResource.getFullPath(), listener.checkChanges(destinationResource, new IMarker[] { markers[1] }, null, null));
- } catch (CoreException e) {
- fail("2.99", e);
- }
-
- // delete all markers for a clean run next time
- try {
- getWorkspace().getRoot().deleteMarkers(null, true, IResource.DEPTH_INFINITE);
- } catch (CoreException e) {
- fail("99.99", e);
- }
- } finally {
- getWorkspace().removeResourceChangeListener(listener);
- }
-}
-public void _testPerformanceManyResources() {
- log("testPerformanceManyResources");
- long start;
- long stop;
-
- // cleanup old resources and create our own
- IResource[] resources = null;
- try {
- getWorkspace().getRoot().delete(false, getMonitor());
- resources = createLargeHierarchy();
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- // header info
- final int markersPerResource = 20;
- final int numMarkers = resources.length * markersPerResource;
- display("\nNumber of resources: " + resources.length);
- display("Markers per resource: " + markersPerResource);
- display("Total Number of Markers: " + numMarkers);
-
- // Create an array with a bunch of markers.
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- IResourceVisitor visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- for (int i = 0; i < markersPerResource; i++)
- resource.createMarker(IMarker.PROBLEM);
- return true;
- }
- };
- getWorkspace().getRoot().accept(visitor);
- }
- };
- try {
- start = System.currentTimeMillis();
- getWorkspace().run(body, getMonitor());
- stop = System.currentTimeMillis();
- display("Task: creating markers");
- display(start, stop);
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- // gather the markers for use. don't time this one.
- final IMarker[] markers = new IMarker[numMarkers];
- try {
- IMarker[] temp = getWorkspace().getRoot().findMarkers(null, true, IResource.DEPTH_INFINITE);
- assertEquals("0.1", numMarkers, temp.length);
- for (int i = 0; i < temp.length; i++)
- markers[i] = temp[i];
- } catch (CoreException e) {
- fail("0.2", e);
- }
-
- // create attributes on each marker
- body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- for (int i = 0; i < markers.length; i++)
- markers[i].setAttribute(IMarker.MESSAGE, getRandomString());
- }
- };
- try {
- start = System.currentTimeMillis();
- getWorkspace().run(body, getMonitor());
- stop = System.currentTimeMillis();
- display("Task: setting an attribute on each marker");
- display(start, stop);
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- // get the attribute from each marker
- body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- for (int i = 0; i < markers.length; i++)
- markers[i].getAttribute(IMarker.MESSAGE);
- }
- };
- try {
- start = System.currentTimeMillis();
- getWorkspace().run(body, getMonitor());
- stop = System.currentTimeMillis();
- display("Task: getting an attribute on each marker");
- display(start, stop);
- } catch (CoreException e) {
- fail("2.0", e);
- }
-}
-public void _testPerformanceOneResource() {
- log("testPerformanceOneResource");
- long start;
- long stop;
- final int numMarkers = 4000;
-
- // header info
- display("Number of resources: 1");
- display("Number of Markers: " + numMarkers);
-
- // Create an array with a bunch of markers.
- final IMarker markers[] = new IMarker[numMarkers];
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- IResource resource = getWorkspace().getRoot();
- for (int i = 0; i < markers.length; i++) {
- markers[i] = resource.createMarker(IMarker.PROBLEM);
- }
- }
- };
- try {
- start = System.currentTimeMillis();
- getWorkspace().run(body, getMonitor());
- stop = System.currentTimeMillis();
- display("Task: creating markers");
- display(start, stop);
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- // create attributes on each marker
- body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- for (int i = 0; i < markers.length; i++)
- markers[i].setAttribute(IMarker.MESSAGE, getRandomString());
- }
- };
- try {
- start = System.currentTimeMillis();
- getWorkspace().run(body, getMonitor());
- stop = System.currentTimeMillis();
- display("Task: setting an attribute on each marker");
- display(start, stop);
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- java.util.Comparator c = new java.util.Comparator() {
- public int compare(Object o1, Object o2) {
- try {
- String name1 = (String) ((IMarker) o1).getAttribute(IMarker.MESSAGE);
- String name2 = (String) ((IMarker) o2).getAttribute(IMarker.MESSAGE);
- if (name1 == null)
- name1 = "";
- if (name2 == null)
- name2 = "";
- int result = name1.compareToIgnoreCase(name2);
- return result;
- } catch (CoreException e) {
- fail("2.0", e);
- }
- // avoid compiler error
- return -1;
- }
- };
- start = System.currentTimeMillis();
- Arrays.sort(markers, c);
- stop = System.currentTimeMillis();
- display("Task: sort arrays based on MESSAGE attribute");
- display(start, stop);
-}
-/**
- * Test a specific PR case.
- */
-public void _testPR() {
- log("_testPR");
-
- try {
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- IResource resource = getWorkspace().getRoot().getProjects()[0].members()[0];
- resource.createMarker(IMarker.BOOKMARK);
- IPath destination = resource.getFullPath().removeLastSegments(1).append(resource.getName() + "new");
- resource.move(destination, true, getMonitor());
- IResource dest = getWorkspace().getRoot().findMember(destination);
- dest.move(resource.getFullPath(), true, getMonitor());
- }
- };
- getWorkspace().run(body, getMonitor());
- } catch (CoreException e) {
- fail("99.9", e);
- }
-
-}
-protected void addChildren(ArrayList result, IPath root, int breadth, int depth) {
- for (int i = 1; i < breadth + 1; i++) {
- IPath child = root.append(i + "");
- if (depth == 0) {
- result.add(child.toString());
- return;
- }
- child = child.addTrailingSeparator();
- result.add(child.toString());
- addChildren(result, child, breadth, depth - 1);
- }
-}
-protected void assertDoesNotExist(String message, IMarker[] markers) {
- for (int i = 0; i < markers.length; i++)
- assertDoesNotExist(message, markers[i]);
-}
-protected void assertDoesNotExist(String message, IMarker marker) {
- assertTrue(message, !marker.exists());
-}
-
-/**
- * Asserts that the given collection of expected markers contains
- * the same markers as the given collection of actual markers. The
- * markers do not have to be in the same order.
- */
-protected void assertEquals(String message, IMarker[] expectedMarkers, IMarker[] actualMarkers) {
- int n = expectedMarkers.length;
- if (n != actualMarkers.length)
- fail(message);
- boolean[] seen = new boolean[n];
- for (int i = 0; i < n; ++i) {
- boolean found = false;
- for (int j = 0; j < n; ++j) {
- if (!seen[j] && equals(expectedMarkers[i], actualMarkers[j])) {
- found = true;
- seen[j] = true;
- break;
- }
- }
- if (!found) {
- fail(message);
- }
- }
-}
-protected void assertEquals(String message, Map map, Object[] keys, Object[] values) {
- assertEquals(message, keys.length, values.length);
- assertEquals(message, keys.length, map.size());
- for (Iterator i = map.keySet().iterator(); i.hasNext();) {
- Object key = i.next();
- Object value = map.get(key);
- boolean found = false;
- for (int j = 0; !found && j < keys.length; j++) {
- if (keys[j].equals(key)) {
- found = true;
- if (!values[j].equals(value))
- fail(message);
- }
- }
- if (!found)
- assertTrue(message, false);
- }
-}
-protected void assertExists(String message, IMarker[] markers) {
- for (int i = 0; i < markers.length; i++)
- assertExists(message, markers[i]);
-}
-protected void assertExists(String message, IMarker marker) {
- assertTrue(message, marker.exists());
-}
-public IResource[] createLargeHierarchy() throws CoreException {
- ArrayList result = new ArrayList();
- result.add("/");
- new MarkerTest().addChildren(result, Path.ROOT, 3, 4);
- String[] names = (String[]) result.toArray(new String[result.size()]);
- IResource[] resources = buildResources(getWorkspace().getRoot(), names);
- ensureExistsInWorkspace(resources, true);
- return resources;
-}
-protected IMarker[] createMarkers(IResource[] hosts, String type) throws CoreException {
- IMarker[] result = new IMarker[hosts.length];
- for (int i = 0; i < hosts.length; i++) {
- result[i] = hosts[i].createMarker(type);
- }
- return result;
-}
-/**
- * Return a string array which defines the hierarchy of a tree.
- * Folder resources must have a trailing slash.
- */
-public String[] defineHierarchy() {
- return new String[] { "/", "1/", "1/1", "1/2/", "1/2/1", "1/2/2/", "2/", "2/1", "2/2/", "2/2/1", "2/2/2/" };
-}
-public void display(long start, long stop) {
- display("Start: " + start);
- display("Stop: " + stop);
- display("Duration: " + (stop - start));
-}
-public void display(String message) {
- System.out.println(message);
-}
-/**
- * Returns whether the given markers are equal.
- */
-public static boolean equals(IMarker a, IMarker b) {
- try {
- if (a.getType() != b.getType())
- return false;
- if (a.getId() != b.getId())
- return false;
- return true;
- } catch (CoreException e) {
- return false;
- }
-}
-/**
- * Returns whether two object are both null, or both non-null and equal.
- */
-protected static boolean equalsOrNull(Object a, Object b) {
- return a == b || (a != null && b != null && a.equals(b));
-}
-public void setUp() throws Exception {
- super.setUp();
- try {
- resources = createHierarchy();
- } catch (CoreException e) {
- fail("#setUp", e);
- }
-}
-/**
- * Configures the markers test suite.
- */
-public static Test suite() {
- return new TestSuite(MarkerTest.class);
-
-// TestSuite suite = new TestSuite();
-// suite.addTest(new MarkerTest("testMarkerDeltasMove"));
-// return suite;
-}
-public void tearDown() throws Exception {
- super.tearDown();
- try {
- getWorkspace().getRoot().delete(true, null);
- } catch (CoreException e) {
- fail("#tearDown", e);
- }
-}
-/**
- * Tests whether markers correctly copy with resources.
- */
-public void testCopyResource() {
- log("TestCopyResource");
-}
-public void testCreateMarker() {
- log("TestCreateMarker");
-
- // Create and register a listener.
- MarkersChangeListener listener = new MarkersChangeListener();
- getWorkspace().addResourceChangeListener(listener);
-
- // create markers on our hierarchy of resources
- for (int i = 0; i < resources.length; i++) {
- listener.reset();
- IResource resource = resources[i];
- IMarker[] markers = new IMarker[3];
- try {
- markers[0] = resource.createMarker(IMarker.PROBLEM);
- markers[1] = resource.createMarker(IMarker.BOOKMARK);
- markers[2] = resource.createMarker(IMarker.TASK);
- assertExists("1.0." + resource.getFullPath(), markers);
- } catch (CoreException e) {
- fail("1.1." + resource.getFullPath(), e);
- }
- assertEquals("1.2." + resource.getFullPath(), 1, listener.numAffectedResources());
- assertTrue("1.3." + resource.getFullPath(), listener.checkChanges(resource, markers, null, null));
-
- // expect an AssertionFailedException from a null type
- try {
- resource.createMarker(null);
- fail("2.0." + resource.getFullPath());
- } catch (CoreException e) {
- fail("2.1." + resource.getFullPath(), e);
- } catch (RuntimeException e) {
- }
- }
-
- // try creating a marker on a resource which does't exist
- IResource testResource = getWorkspace().getRoot().getFile(new Path("non/existant/resource"));
- assertTrue("3.0", !testResource.exists());
- try {
- testResource.createMarker(IMarker.PROBLEM);
- fail("3.1");
- } catch (CoreException e) {
- }
-
- // cleanup
- getWorkspace().removeResourceChangeListener(listener);
-}
-public void testCreationTime() {
-
- for (int i=0; i<resources.length; i++) {
- IMarker marker = null;
- try {
- marker = resources[i].createMarker(IMarker.PROBLEM);
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- // make sure the marker has a non-zero creation time
- try {
- assertTrue("1.0." + i, 0 != marker.getCreationTime());
- } catch (CoreException e) {
- fail("1.1", e);
- }
- }
-}
-public void testDeleteMarker() {
- log("TestDeleteMarker");
- IMarker marker = null;
-
- // Create and register a listener.
- MarkersChangeListener listener = new MarkersChangeListener();
- getWorkspace().addResourceChangeListener(listener);
-
- // for each resource in the hierarchy do...
- for (int i = 0; i < resources.length; i++) {
- IResource resource = resources[i];
-
- // create the marker, assert that it exists, and then remove it
- try {
- listener.reset();
- marker = resource.createMarker(IMarker.PROBLEM);
- assertEquals("2.0." + resource.getFullPath(), 1, listener.numAffectedResources());
- assertTrue("2.1." + resource.getFullPath(), listener.checkChanges(resource, new IMarker[] { marker }, null, null));
- } catch (CoreException e) {
- fail("2.2." + resource.getFullPath(), e);
- }
- assertExists("2.3." + resource.getFullPath(), marker);
- try {
- listener.reset();
- marker.delete();
- assertDoesNotExist("2.4." + resource.getFullPath(), marker);
- assertEquals("2.5." + resource.getFullPath(), 1, listener.numAffectedResources());
- assertTrue("2.6." + resource.getFullPath(), listener.checkChanges(resource, null, new IMarker[] { marker }, null));
- } catch (CoreException e) {
- fail("2.7." + resource.getFullPath(), e);
- }
-
- // Check that a non-existant marker can be removed
- try {
- marker.delete();
- } catch (CoreException e) {
- fail("3.0." + resource.getFullPath(), e);
- }
-
- // create multiple markers, assert they exist, and then remove them.
- IMarker[] markers = new IMarker[3];
- try {
- markers[0] = resource.createMarker(IMarker.BOOKMARK);
- assertExists("4.0." + resource.getFullPath(), markers[0]);
- markers[1] = resource.createMarker(IMarker.TASK);
- assertExists("4.1." + resource.getFullPath(), markers[1]);
- markers[2] = resource.createMarker(IMarker.PROBLEM);
- assertExists("4.2." + resource.getFullPath(), markers[2]);
- } catch (CoreException e) {
- fail("4.3." + resource.getFullPath(), e);
- }
- try {
- listener.reset();
- getWorkspace().deleteMarkers(markers);
- assertEquals("4.4." + resource.getFullPath(), 1, listener.numAffectedResources());
- assertTrue("4.5." + resource.getFullPath(), listener.checkChanges(resource, null, markers, null));
- } catch (CoreException e) {
- fail("4.6." + resource.getFullPath(), e);
- }
- assertDoesNotExist("4.7." + resource.getFullPath(), markers);
- }
-
- // cleanup
- getWorkspace().removeResourceChangeListener(listener);
-}
-public void testDeleteMarkers() {
- log("TestDeleteMarkers");
- IMarker[] markers = null;
- try {
- markers = createMarkers(resources, IMarker.PROBLEM);
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- // Check that a collection of markers can be removed.
- try {
- getWorkspace().deleteMarkers(markers);
- } catch (CoreException e) {
- fail("1.0", e);
- }
- for (int i = 0; i < markers.length; i++)
- assertTrue("1.1", !markers[i].exists());
-
- // Check that an empty collection of markers can be removed.
- try {
- getWorkspace().deleteMarkers(new IMarker[0]);
- } catch (CoreException e) {
- fail("1.2", e);
- }
-}
-public void testFindMarkers() {
- log("TestFindMarkers");
-
- // test finding some markers which actually exist
- IMarker[] markers = null;
- try {
- markers = createMarkers(resources, IMarker.PROBLEM);
- } catch (CoreException e) {
- fail("0.0", e);
- }
- try {
- IMarker[] found = getWorkspace().getRoot().findMarkers(IMarker.PROBLEM, false, IResource.DEPTH_INFINITE);
- assertEquals("1.0", markers, found);
- } catch (CoreException e) {
- fail("1.1", e);
- }
- try {
- IMarker[] found = getWorkspace().getRoot().findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
- assertEquals("1.2", markers, found);
- } catch (CoreException e) {
- fail("1.3", e);
- }
-
- // test finding some markers which don't exist
- try {
- IMarker[] found = getWorkspace().getRoot().findMarkers(IMarker.BOOKMARK, false, IResource.DEPTH_INFINITE);
- assertTrue("2.0", found.length == 0);
- } catch (CoreException e) {
- fail("2.1", e);
- }
-
- // add more markers and do a search on all marker types
- Vector allMarkers = new Vector(markers.length * 3);
- for (int i = 0; i < markers.length; i++)
- allMarkers.add(markers[i]);
- try {
- markers = createMarkers(resources, IMarker.BOOKMARK);
- } catch (CoreException e) {
- fail("3.0", e);
- }
- for (int i = 0; i < markers.length; i++)
- allMarkers.add(markers[i]);
- try {
- markers = createMarkers(resources, IMarker.TASK);
- } catch (CoreException e) {
- fail("3.1", e);
- }
- for (int i = 0; i < markers.length; i++)
- allMarkers.add(markers[i]);
- try {
- IMarker[] found = getWorkspace().getRoot().findMarkers(null, false, IResource.DEPTH_INFINITE);
- assertEquals("3.2", (IMarker[]) allMarkers.toArray(new IMarker[allMarkers.size()]), found);
- } catch (CoreException e) {
- fail("3.3", e);
- }
- try {
- IMarker[] found = getWorkspace().getRoot().findMarkers(IMarker.MARKER, true, IResource.DEPTH_INFINITE);
- assertEquals("3.4", (IMarker[]) allMarkers.toArray(new IMarker[allMarkers.size()]), found);
- } catch (CoreException e) {
- fail("3.5", e);
- }
-}
-public void test_10989() {
- log("test_10989");
-
- try {
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- project.create(null);
- project.open(null);
- IFile file = project.getFile("foo.txt");
- file.create(getRandomContents(), true, null);
- file.createMarker(IMarker.PROBLEM);
- IMarker[] found = file.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ZERO);
- assertEquals("1.0", 1, found.length);
- found = file.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
- assertEquals("1.1", 1, found.length);
- project.delete(true, true, null);
- } catch (CoreException e) {
- fail("1.99", e);
- }
-}
-/**
- * Tests the appearance of marker changes in the resource delta.
- */
-public void testMarkerChangesInDelta() {
- log("TestMarkerChangesInDelta");
-
- // Create and register a listener.
- MarkersChangeListener listener = new MarkersChangeListener();
- getWorkspace().addResourceChangeListener(listener);
-
- try {
- IResource resource;
- IMarker[] markers;
- IMarker marker;
- for (int i = 0; i < resources.length; i++) {
- resource = resources[i];
- markers = new IMarker[3];
-
- // ADD a marker
- listener.reset();
- try {
- markers[0] = resource.createMarker(IMarker.PROBLEM);
- assertExists("1.0." + resource.getFullPath(), markers[0]);
- assertEquals("1.1." + resource.getFullPath(), 1, listener.numAffectedResources());
- assertTrue("1.2." + resource.getFullPath(), listener.checkChanges(resource, new IMarker[] { markers[0] }, null, null));
- } catch (CoreException e) {
- fail("1.99." + resource.getFullPath(), e);
- }
-
- // ADD more markers to the same resource
- listener.reset();
- try {
- markers[1] = resource.createMarker(IMarker.BOOKMARK);
- markers[2] = resource.createMarker(IMarker.TASK);
- assertExists("2.0." + resource.getFullPath(), new IMarker[] { markers[1], markers[2] });
- assertEquals("2.1." + resource.getFullPath(), 1, listener.numAffectedResources());
- assertTrue("2.2." + resource.getFullPath(), listener.checkChanges(resource, new IMarker[] { markers[1], markers[2] }, null, null));
- } catch (CoreException e) {
- fail("2.99." + resource.getFullPath(), e);
- }
-
- // CHANGE a marker
- listener.reset();
- try {
- markers[0].setAttribute(IMarker.MESSAGE, "My text.");
- assertEquals("3.0." + resource.getFullPath(), 1, listener.numAffectedResources());
- assertTrue("3.1." + resource.getFullPath(), listener.checkChanges(resource, null, null, new IMarker[] { markers[0] }));
- } catch (CoreException e) {
- fail("3.99." + resource.getFullPath(), e);
- }
-
- // CHANGE more markers
- listener.reset();
- try {
- markers[1].setAttribute(IMarker.SEVERITY, "Low");
- markers[2].setAttribute(IMarker.PRIORITY, "Normal");
- assertEquals("4.0." + resource.getFullPath(), 1, listener.numAffectedResources());
- assertTrue("4.1." + resource.getFullPath(), listener.checkChanges(resource, null, null, new IMarker[] { markers[1], markers[2] }));
- } catch (CoreException e) {
- fail("4.99." + resource.getFullPath(), e);
- }
-
- // DELETE a marker
- listener.reset();
- try {
- markers[0].delete();
- assertDoesNotExist("5.0." + resource.getFullPath(), markers[0]);
- assertEquals("5.1." + resource.getFullPath(), 1, listener.numAffectedResources());
- assertTrue("5.2." + resource.getFullPath(), listener.checkChanges(resource, null, new IMarker[] { markers[0] }, null));
- } catch (CoreException e) {
- fail("5.99." + resource.getFullPath(), e);
- }
-
- // DELETE more markers
- listener.reset();
- try {
- resource.deleteMarkers(null, false, IResource.DEPTH_ZERO);
- assertDoesNotExist("6.0." + resource.getFullPath(), new IMarker[] { markers[1], markers[2] });
- assertEquals("6.1." + resource.getFullPath(), 1, listener.numAffectedResources());
- assertTrue("6.2." + resource.getFullPath(), listener.checkChanges(resource, null, new IMarker[] { markers[1], markers[2] }, null));
- } catch (CoreException e) {
- fail("6.99." + resource.getFullPath(), e);
- }
-
- // ADD, REMOVE and CHANGE markers
- try {
- markers[0] = resource.createMarker(IMarker.PROBLEM);
- markers[1] = resource.createMarker(IMarker.BOOKMARK);
- listener.reset();
- markers[0].delete();
- assertDoesNotExist("7.0." + resource.getFullPath(), markers[0]);
- markers[1].setAttribute(IMarker.MESSAGE, getRandomString());
- markers[2] = resource.createMarker(IMarker.TASK);
- assertEquals("7.1." + resource.getFullPath(), 1, listener.numAffectedResources());
- assertTrue("7.2." + resource.getFullPath(), listener.checkChanges(resource, new IMarker[] { markers[2] }, new IMarker[] { markers[0] }, new IMarker[] { markers[1] }));
- } catch (CoreException e) {
- fail("7.99." + resource.getFullPath(), e);
- }
- }
-
- // DELETE the resource and see what the marker delta is
- try {
- resource = getWorkspace().getRoot();
- resource.deleteMarkers(null, true, IResource.DEPTH_INFINITE);
- marker = resource.createMarker(IMarker.BOOKMARK);
- listener.reset();
- resource.delete(true, getMonitor());
- assertDoesNotExist("8.0", marker);
- assertTrue("8.1", listener.checkChanges(resource, null, new IMarker[] { marker }, null));
- } catch (CoreException e) {
- fail("8.99", e);
- }
-
- } finally {
- getWorkspace().removeResourceChangeListener(listener);
- }
-}
-/**
- * Tests the appearance of marker changes in the resource delta.
- * Particularly, checks that the MarkerDelta attributes reflect the
- * state of the marker before the change occurred.
- */
-public void testMarkerDeltaAttributes() {
- log("testMarkerDeltaAttributes");
-
- // create markers on various resources
- final IMarker[] markers = new IMarker[3];
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- markers[0] = resources[0].createMarker(IMarker.BOOKMARK);
- markers[1] = resources[1].createMarker(IMarker.BOOKMARK);
- markers[1].setAttribute(IMarker.CHAR_START, 5);
- markers[2] = resources[2].createMarker(IMarker.PROBLEM);
- markers[2].setAttribute(IMarker.DONE, true);
- markers[2].setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
- markers[2].setAttribute(IMarker.MESSAGE, "Hello");
- }
- };
- try {
- getWorkspace().run(body, getMonitor());
- } catch (CoreException e) {
- fail("0.99", e);
- }
-
- //create the attribute change listener
- MarkerAttributeChangeListener listener = new MarkerAttributeChangeListener();
- getWorkspace().addResourceChangeListener(listener);
- try {
- //add a new attribute
- listener.expectChanges(markers[0]);
- markers[0].setAttribute(IMarker.MESSAGE, "Message");
- listener.verifyChanges();
-
- //change an attribute
- listener.expectChanges(markers[0]);
- markers[0].setAttribute(IMarker.MESSAGE, "NewMessage");
- listener.verifyChanges();
-
- //remove an attribute
- listener.expectChanges(markers[0]);
- markers[0].setAttribute(IMarker.MESSAGE, null);
- listener.verifyChanges();
-
- //add attribute to marker that already has attributes
- listener.expectChanges(markers[2]);
- markers[2].setAttribute(IMarker.CHAR_END, 5);
- listener.verifyChanges();
-
- //add+change
- listener.expectChanges(markers[1]);
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- markers[1].setAttribute(IMarker.CHAR_START, 5);
- markers[1].setAttribute(IMarker.CHAR_END, 10);
- }
- }, getMonitor());
- listener.verifyChanges();
-
- //change+remove same marker
- listener.expectChanges(markers[1]);
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- markers[1].setAttribute(IMarker.CHAR_START, 5);
- markers[1].setAttribute(IMarker.CHAR_START, null);
- }
- }, getMonitor());
- listener.verifyChanges();
-
- //change multiple markers
- listener.expectChanges(markers);
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- markers[0].setAttribute(IMarker.CHAR_START, 5);
- markers[1].setAttribute(IMarker.CHAR_START, 10);
- markers[2].setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_LOW);
- }
- }, getMonitor());
- listener.verifyChanges();
- } catch (CoreException e) {
- fail("1.99", e);
- } finally {
- getWorkspace().removeResourceChangeListener(listener);
- }
-}
-/**
- * Tests the appearance of marker changes in the resource delta.
- */
-public void testMarkerDeltasCopyResource() {
- log("testMarkerDeltasCopyResource");
-
- // Create and register a listener.
- final MarkersChangeListener listener = new MarkersChangeListener();
- getWorkspace().addResourceChangeListener(listener);
-
- try {
- // create markers on all the non-project resources
- final Hashtable table = new Hashtable(1);
- final int[] count = new int[1];
- count[0] = 0;
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- IResourceVisitor visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- if (resource.getType() == IResource.ROOT || resource.getType() == IResource.PROJECT)
- return true;
- IMarker marker = resource.createMarker(IMarker.BOOKMARK);
- table.put(resource, marker);
- count[0]++;
- return true;
- }
- };
- getWorkspace().getRoot().accept(visitor);
- }
- };
- try {
- getWorkspace().run(body, getMonitor());
- } catch (CoreException e) {
- fail("0.99", e);
- }
- listener.reset();
-
- // copy all non-project resources
- try {
- IProject[] projects = getWorkspace().getRoot().getProjects();
- for (int i = 0; i < projects.length; i++) {
- IResource[] children = projects[i].members();
- for (int j = 0; j < children.length; j++) {
- IPath destination = new Path(children[j].getName() + "copy");
- children[j].copy(destination, true, getMonitor());
- }
- }
- } catch (CoreException e) {
- fail("1.99", e);
- }
-
- // verify marker deltas
-// IResourceVisitor visitor = new IResourceVisitor() {
-// public boolean visit(IResource resource) throws CoreException {
-// if (resource.getType() == IResource.ROOT || resource.getType() == IResource.PROJECT)
-// return true;
-// if (!resource.getName().endsWith("copy"))
-// return false;
-// String name = resource.getFullPath().segment(0);
-// IPath path = new Path(name.substring(0, name.length() - 4)).makeAbsolute();
-// path = path.append(resource.getFullPath().removeFirstSegments(1));
-// IResource oldResource = ((Workspace) getWorkspace()).newResource(path, resource.getType());
-// IMarker marker = (IMarker) table.get(oldResource);
-// assertNotNull("2.1." + oldResource.getFullPath(), marker);
-// IMarker[] markers = resource.findMarkers(null, true, IResource.DEPTH_ZERO);
-// assertEquals("2.2." + resource.getFullPath(), 1, markers.length);
-// assertEquals("2.3." + resource.getFullPath(), marker.getId(), markers[0].getId());
-// assertTrue("2.4." + resource.getFullPath(), listener.checkChanges(resource, new IMarker[] { markers[0] }, null, null));
-// return true;
-// }
-// };
- // marker deltas should not appear after a resource copy
- //assertEquals("2.5", count[0], listener.numAffectedResources());
- assertEquals("2.5", 0, listener.numAffectedResources());
- //try {
- //getWorkspace().getRoot().accept(visitor);
- //} catch (CoreException e) {
- //fail("2.99", e);
- //}
- } finally {
- getWorkspace().removeResourceChangeListener(listener);
- }
-}
-/**
- * Tests the appearance of marker changes in the resource delta.
- */
-public void testMarkerDeltasMerge() {
- log("testMarkerDeltasMerge");
-
- // Create and register a listener.
- final MarkersChangeListener listener = new MarkersChangeListener();
- getWorkspace().addResourceChangeListener(listener);
-
- try {
- for (int i = 0; i < resources.length; i++) {
- final IResource resource = resources[i];
-
- // ADD + REMOVE = nothing
- try {
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- listener.reset();
- IMarker marker = resource.createMarker(IMarker.PROBLEM);
- assertExists("1.0." + resource.getFullPath(), marker);
- marker.delete();
- assertDoesNotExist("1.1." + resource.getFullPath(), marker);
- }
- };
- getWorkspace().run(body, getMonitor());
- assertEquals("1.2." + resource.getFullPath(), 0, listener.numAffectedResources());
- assertTrue("1.3." + resource.getFullPath(), listener.checkChanges(resource, null, null, null));
- } catch (CoreException e) {
- fail("1.99." + resource.getFullPath(), e);
- }
-
- // ADD + CHANGE = ADD
- try {
- // cannot re-assign variable value within the code below, so must
- // put our marker value inside an array and set the element.
- final IMarker[] markers = new IMarker[1];
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- listener.reset();
- markers[0] = resource.createMarker(IMarker.PROBLEM);
- assertExists("2.0." + resource.getFullPath(), markers[0]);
- markers[0].setAttribute(IMarker.MESSAGE, "my message text");
- assertEquals("2.1." + resource.getFullPath(), "my message text", markers[0].getAttribute(IMarker.MESSAGE));
- }
- };
- getWorkspace().run(body, getMonitor());
- assertEquals("2.2." + resource.getFullPath(), 1, listener.numAffectedResources());
- assertTrue("2.3." + resource.getFullPath(), listener.checkChanges(resource, new IMarker[] { markers[0] }, null, null));
- } catch (CoreException e) {
- fail("2.99." + resource.getFullPath(), e);
- }
-
- // REMOVE + ADD = CHANGE
- //try {
- //final IMarker[] markers = new IMarker[1];
- //markers[0] = resource.createMarker(IMarker.PROBLEM);
- //assertExists("3.0." + resource.getFullPath(), markers[0]);
- //IWorkspaceRunnable body = new IWorkspaceRunnable() {
- //public void run(IProgressMonitor monitor) throws CoreException {
- //listener.reset();
- //markers[0].delete();
- //assertDoesNotExist("3.1." + resource.getFullPath(), markers[0]);
- //markers[0] = resource.createMarker(IMarker.PROBLEM);
- //assertExists("3.2." + resource.getFullPath(), markers[0]);
- //}
- //};
- //getWorkspace().run(body, getMonitor());
- //assertEquals("3.3." + resource.getFullPath(), 1, listener.numAffectedResources());
- //assert("3.4." + resource.getFullPath(), listener.checkChanges(resource, null, null, new IMarker[] { markers[0] }));
- //} catch (CoreException e) {
- //fail("3.99." + resource.getFullPath(), e);
- //}
-
- // CHANGE + CHANGE = CHANGE
- try {
- final IMarker[] markers = new IMarker[1];
- markers[0] = resource.createMarker(IMarker.PROBLEM);
- assertExists("4.0." + resource.getFullPath(), markers[0]);
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- listener.reset();
- markers[0].setAttribute(IMarker.MESSAGE, "my message text");
- assertEquals("4.1." + resource.getFullPath(), "my message text", markers[0].getAttribute(IMarker.MESSAGE));
- markers[0].setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
- assertEquals("4.2." + resource.getFullPath(), IMarker.PRIORITY_HIGH, ((Integer) markers[0].getAttribute(IMarker.PRIORITY)).intValue());
- }
- };
- getWorkspace().run(body, getMonitor());
- assertEquals("4.3." + resource.getFullPath(), 1, listener.numAffectedResources());
- assertTrue("4.4." + resource.getFullPath(), listener.checkChanges(resource, null, null, new IMarker[] { markers[0] }));
- } catch (CoreException e) {
- fail("4.99." + resource.getFullPath(), e);
- }
-
- // CHANGE + REMOVE = REMOVE
- try {
- final IMarker[] markers = new IMarker[1];
- markers[0] = resource.createMarker(IMarker.PROBLEM);
- assertExists("5.0." + resource.getFullPath(), markers[0]);
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- listener.reset();
- markers[0].setAttribute(IMarker.MESSAGE, "my message text");
- assertEquals("5.1." + resource.getFullPath(), "my message text", markers[0].getAttribute(IMarker.MESSAGE));
- markers[0].delete();
- assertDoesNotExist("5.2." + resource.getFullPath(), markers[0]);
- }
- };
- getWorkspace().run(body, getMonitor());
- assertEquals("5.3." + resource.getFullPath(), 1, listener.numAffectedResources());
- assertTrue("5.4." + resource.getFullPath(), listener.checkChanges(resource, null, new IMarker[] { markers[0] }, null));
- } catch (CoreException e) {
- fail("5.99." + resource.getFullPath(), e);
- }
-
- // cleanup after each iteration
- try {
- resource.deleteMarkers(null, true, IResource.DEPTH_ZERO);
- } catch (CoreException e) {
- fail("99.99", e);
- }
- }
- } finally {
- getWorkspace().removeResourceChangeListener(listener);
- }
-}
-/**
- * Tests the appearance of marker changes in the resource delta.
- */
-public void testMarkerDeltasMoveFolder() {
- log("testMarkerDeltasMoveFolder");
-
- IWorkspaceRoot root = getWorkspace().getRoot();
- final IProject project = root.getProject("MyProject");
- IFolder folder = project.getFolder("folder");
- IFile file = project.getFile("file.txt");
- IFile subFile = folder.getFile("subFile.txt");
- ensureExistsInWorkspace(new IResource[] {project, folder, file, subFile}, true);
- IFolder destFolder = project.getFolder("myOtherFolder");
- IFile destSubFile = destFolder.getFile(subFile.getName());
- IMarker folderMarker = null;
- IMarker subFileMarker = null;
- IMarker[] markers = null;
-
- // Create and register a listener.
- final MarkersChangeListener listener = new MarkersChangeListener();
- getWorkspace().addResourceChangeListener(listener);
-
- try {
- // create markers on the resources
- try {
- folderMarker = folder.createMarker(IMarker.BOOKMARK);
- } catch(CoreException e) {
- fail("1.0", e);
- }
- try {
- subFileMarker = subFile.createMarker(IMarker.BOOKMARK);
- } catch(CoreException e) {
- fail("1.1", e);
- }
- listener.reset();
-
- // move the files
- try {
- folder.move(destFolder.getFullPath(), IResource.FORCE, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- // verify marker deltas
- assertTrue("3.1", listener.checkChanges(folder, null, new IMarker[] {folderMarker}, null));
- try {
- markers = destFolder.findMarkers(null, true, IResource.DEPTH_ZERO);
- } catch(CoreException e) {
- fail("3.2", e);
- }
- assertEquals("3.3", 1, markers.length);
- assertEquals("3.4", folderMarker.getId(), markers[0].getId());
- assertTrue("3.5", listener.checkChanges(destFolder, new IMarker[] {markers[0]}, null, null));
-
- assertTrue("3.7", listener.checkChanges(subFile, null, new IMarker[] {subFileMarker}, null));
- try {
- markers = destSubFile.findMarkers(null, true, IResource.DEPTH_ZERO);
- } catch(CoreException e) {
- fail("3.8", e);
- }
- assertEquals("3.9", 1, markers.length);
- assertEquals("3.10", subFileMarker.getId(), markers[0].getId());
- assertTrue("3.11", listener.checkChanges(destSubFile, new IMarker[] {markers[0]}, null, null));
-
- } finally {
- getWorkspace().removeResourceChangeListener(listener);
- }
-}
-/**
- * Tests the appearance of marker changes in the resource delta.
- */
-public void testMarkerDeltasMoveFile() {
- log("testMarkerDeltasMoveFile");
- IWorkspaceRoot root = getWorkspace().getRoot();
- final IProject project = root.getProject("MyProject");
- IFolder folder = project.getFolder("folder");
- IFile file = project.getFile("file.txt");
- IFile subFile = folder.getFile("subFile.txt");
- ensureExistsInWorkspace(new IResource[] {project, folder, file, subFile} , true);
- IFile destFile = folder.getFile(file.getName());
- IFile destSubFile = project.getFile(subFile.getName());
- IMarker fileMarker = null;
- IMarker subFileMarker = null;
- IMarker[] markers = null;
-
- // Create and register a listener.
- final MarkersChangeListener listener = new MarkersChangeListener();
- getWorkspace().addResourceChangeListener(listener);
-
- try {
- // create markers on the resources
- try {
- fileMarker = file.createMarker(IMarker.BOOKMARK);
- } catch(CoreException e) {
- fail("1.0", e);
- }
- try {
- subFileMarker = subFile.createMarker(IMarker.BOOKMARK);
- } catch(CoreException e) {
- fail("1.1", e);
- }
- listener.reset();
-
- // move the files
- try {
- file.move(destFile.getFullPath(), IResource.FORCE, getMonitor());
- subFile.move(destSubFile.getFullPath(), IResource.FORCE, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- // verify marker deltas
- assertTrue("3.1", listener.checkChanges(file, null, new IMarker[] {fileMarker}, null));
- try {
- markers = destFile.findMarkers(null, true, IResource.DEPTH_ZERO);
- } catch(CoreException e) {
- fail("3.2", e);
- }
- assertEquals("3.3", 1, markers.length);
- assertEquals("3.4", fileMarker.getId(), markers[0].getId());
- assertTrue("3.5", listener.checkChanges(destFile, new IMarker[] {markers[0]}, null, null));
-
- assertTrue("3.7", listener.checkChanges(subFile, null, new IMarker[] {subFileMarker}, null));
- try {
- markers = destSubFile.findMarkers(null, true, IResource.DEPTH_ZERO);
- } catch(CoreException e) {
- fail("3.8", e);
- }
- assertEquals("3.9", 1, markers.length);
- assertEquals("3.10", subFileMarker.getId(), markers[0].getId());
- assertTrue("3.11", listener.checkChanges(destSubFile, new IMarker[] {markers[0]}, null, null));
-
- } finally {
- getWorkspace().removeResourceChangeListener(listener);
- }
-}
-
-/**
- * Tests the appearance of marker changes in the resource delta.
- */
-public void testMarkerDeltasMoveProject() {
- log("testMarkerDeltasMoveProject");
-
- // Create and register a listener.
- final MarkersChangeListener listener = new MarkersChangeListener();
- getWorkspace().addResourceChangeListener(listener);
-
- try {
- // create markers on all the resources
- final Hashtable table = new Hashtable(1);
- final int[] count = new int[1];
- count[0] = 0;
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- IResourceVisitor visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- if (resource.getType() == IResource.ROOT)
- return true;
- IMarker marker = resource.createMarker(IMarker.BOOKMARK);
- table.put(resource, marker);
- count[0]++;
- return true;
- }
- };
- getWorkspace().getRoot().accept(visitor);
- }
- };
- try {
- getWorkspace().run(body, getMonitor());
- } catch (CoreException e) {
- fail("0.99", e);
- }
- listener.reset();
-
- // move all resources
- IProject[] projects = getWorkspace().getRoot().getProjects();
- for (int i = 0; i < projects.length; i++) {
- IPath destination = new Path(projects[i].getName() + "move");
- try {
- projects[i].move(destination, true, getMonitor());
- } catch (CoreException e) {
- fail("1.99", e);
- }
- }
-
- // verify marker deltas
- IResourceVisitor visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- if (resource.getType() == IResource.ROOT)
- return true;
- String name = resource.getFullPath().segment(0);
- IPath path = new Path(name.substring(0, name.length() - 4)).makeAbsolute();
- path = path.append(resource.getFullPath().removeFirstSegments(1));
- IResource oldResource = ((Workspace) getWorkspace()).newResource(path, resource.getType());
- IMarker marker = (IMarker) table.get(oldResource);
- assertNotNull("2.1." + oldResource.getFullPath(), marker);
- assertTrue("2.2." + oldResource.getFullPath(), listener.checkChanges(oldResource, null, new IMarker[] { marker }, null));
- IMarker[] markers = resource.findMarkers(null, true, IResource.DEPTH_ZERO);
- assertEquals("2.3." + resource.getFullPath(), 1, markers.length);
- assertEquals("2.4." + resource.getFullPath(), marker.getId(), markers[0].getId());
- assertTrue("2.5." + resource.getFullPath(), listener.checkChanges(resource, new IMarker[] { markers[0] }, null, null));
- return true;
- }
- };
- assertEquals("2.6", count[0] * 2, listener.numAffectedResources());
- try {
- getWorkspace().getRoot().accept(visitor);
- } catch (CoreException e) {
- fail("2.99", e);
- }
- } finally {
- getWorkspace().removeResourceChangeListener(listener);
- }
-}
-public void testMarkerSave() {
- log("TestMarkerSave");
-
- IMarker[] newMarkers = null;
- IMarker[] expected = null;
- try {
- newMarkers = createMarkers(resources, IMarker.PROBLEM);
- expected = new IMarker[newMarkers.length * 3];
- for (int i = 0; i < newMarkers.length; i++)
- expected[i] = newMarkers[i];
- newMarkers = createMarkers(resources, IMarker.BOOKMARK);
- for (int i = 0; i < newMarkers.length; i++)
- expected[i + newMarkers.length] = newMarkers[i];
- newMarkers = createMarkers(resources, IMarker.TASK);
- for (int i = 0; i < newMarkers.length; i++)
- expected[i + (newMarkers.length * 2)] = newMarkers[i];
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- final MarkerManager manager = ((Workspace) getWorkspace()).getMarkerManager();
-
- // write all the markers to the output stream
- File file = Platform.getLocation().append(".testmarkers").toFile();
- OutputStream fileOutput = null;
- DataOutputStream o1 = null;
- try {
- fileOutput = new FileOutputStream(file);
- o1 = new DataOutputStream(fileOutput);
- } catch (IOException e) {
- if (fileOutput != null)
- try {
- fileOutput.close();
- } catch (IOException e2) {
- }
- fail("2.0", e);
- }
- final DataOutputStream output = o1;
- final List list = new ArrayList(5);
- IResourceVisitor visitor = new IResourceVisitor() {
- public boolean visit(final IResource resource) throws CoreException {
- try {
- ResourceInfo info = ((Resource) resource).getResourceInfo(false, false);
- if (info == null)
- return true;
- IPathRequestor requestor = new IPathRequestor() {
- public IPath requestPath() {
- return resource.getFullPath();
- }
- public String requestName() {
- return resource.getName();
- }
- };
- manager.save(info, requestor, output, list);
- } catch (IOException e) {
- fail("2.1", e);
- }
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor);
- } catch (CoreException e) {
- fail("2.2", e);
- } finally {
- try {
- output.close();
- } catch (IOException e) {
- fail("2.3", e);
- }
- }
-
- // delete all markers resources
- try {
- getWorkspace().getRoot().deleteMarkers(null, true, IResource.DEPTH_INFINITE);
- } catch (CoreException e) {
- fail("3.0", e);
- }
- assertDoesNotExist("3.1", expected);
-
- // read in the markers from the file
- try {
- InputStream fileInput = new FileInputStream(file);
- final DataInputStream input = new DataInputStream(fileInput);
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- MarkerReader reader = new MarkerReader((Workspace) getWorkspace());
- try {
- reader.read(input, true);
- } catch (IOException e) {
- fail("4.0", e);
- }
- }
- };
- try {
- getWorkspace().run(body, getMonitor());
- } finally {
- try {
- input.close();
- } catch (IOException e) {
- fail("4.1", e);
- }
- }
- } catch (FileNotFoundException e) {
- fail("4.2", e);
- } catch (CoreException e) {
- fail("4.3", e);
- }
-
- // assert that the markers retrieved are the same as the ones we used
- // to have
- try {
- assertExists("5.0", expected);
- IMarker[] actual = getWorkspace().getRoot().findMarkers(null, false, IResource.DEPTH_INFINITE);
- assertEquals("5.1", expected, actual);
- } catch (CoreException e) {
- fail("5.2", e);
- }
-
- // cleanup
- assertTrue("6.0", file.delete());
-}
-public void testMarkerSaveTransient() {
- log("TestMarkerSaveTransient");
-
- // create the markers on the resources. create both transient
- // and persistent markers.
- final ArrayList persistentMarkers = new ArrayList();
- IResourceVisitor visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- IMarker marker = resource.createMarker(IMarker.PROBLEM);
- persistentMarkers.add(marker);
- marker = resource.createMarker(IMarker.BOOKMARK);
- persistentMarkers.add(marker);
- marker = resource.createMarker(TRANSIENT_MARKER);
- // create a transient marker of a persistent type
- marker = resource.createMarker(IMarker.BOOKMARK);
- marker.setAttribute(IMarker.TRANSIENT, Boolean.TRUE);
- // create a marker of a persistent type and set TRANSIENT as false (should be persisted)
- marker = resource.createMarker(IMarker.BOOKMARK);
- marker.setAttribute(IMarker.TRANSIENT, Boolean.FALSE);
- persistentMarkers.add(marker);
- // create a marker of a transient type and set TRANSIENT to false (should NOT be persisted)
- marker = resource.createMarker(TRANSIENT_MARKER);
- marker.setAttribute(IMarker.TRANSIENT, Boolean.FALSE);
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor);
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- final MarkerManager manager = ((Workspace) getWorkspace()).getMarkerManager();
- IMarker[] expected = (IMarker[]) persistentMarkers.toArray(new IMarker[persistentMarkers.size()]);
-
- // write all the markers to the output stream
- File file = Platform.getLocation().append(".testmarkers").toFile();
- OutputStream fileOutput = null;
- DataOutputStream o1 = null;
- try {
- fileOutput = new FileOutputStream(file);
- o1 = new DataOutputStream(fileOutput);
- } catch (IOException e) {
- if (fileOutput != null)
- try {
- fileOutput.close();
- } catch (IOException e2) {
- }
- fail("2.0", e);
- }
- final DataOutputStream output = o1;
- final List list = new ArrayList(5);
- visitor = new IResourceVisitor() {
- public boolean visit(final IResource resource) throws CoreException {
- try {
- ResourceInfo info = ((Resource) resource).getResourceInfo(false, false);
- if (info == null)
- return true;
- IPathRequestor requestor = new IPathRequestor() {
- public IPath requestPath() {
- return resource.getFullPath();
- }
- public String requestName() {
- return resource.getName();
- }
- };
- manager.save(info, requestor, output, list);
- } catch (IOException e) {
- fail("2.1", e);
- }
- return true;
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor);
- } catch (CoreException e) {
- fail("2.2", e);
- } finally {
- try {
- output.close();
- } catch (IOException e) {
- fail("2.3", e);
- }
- }
-
- // delete all markers resources
- try {
- getWorkspace().getRoot().deleteMarkers(null, true, IResource.DEPTH_INFINITE);
- } catch (CoreException e) {
- fail("3.0", e);
- }
- assertDoesNotExist("3.1", expected);
-
- // read in the markers from the file
- try {
- InputStream fileInput = new FileInputStream(file);
- final DataInputStream input = new DataInputStream(fileInput);
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- MarkerReader reader = new MarkerReader((Workspace) getWorkspace());
- try {
- reader.read(input, true);
- } catch (IOException e) {
- fail("4.0", e);
- }
- }
- };
- try {
- getWorkspace().run(body, getMonitor());
- } finally {
- try {
- input.close();
- } catch (IOException e) {
- fail("4.1", e);
- }
- }
- } catch (FileNotFoundException e) {
- fail("4.2", e);
- } catch (CoreException e) {
- fail("4.3", e);
- }
-
- // assert that the markers retrieved are the same as the ones we used
- // to have
- try {
- assertExists("5.0", expected);
- IMarker[] actual = getWorkspace().getRoot().findMarkers(null, false, IResource.DEPTH_INFINITE);
- assertEquals("5.1", expected, actual);
- } catch (CoreException e) {
- fail("5.2", e);
- }
-
- // cleanup
- assertTrue("6.0", file.delete());
-}
-/**
- * Tests whether markers correctly move with resources.
- */
-public void testMoveResource() {
- log("TestMoveResource");
-}
-/*
- * Test for PR: "1FWT3V5: ITPCORE:WINNT - Task view shows entries for closed projects"
- */
-public void testProjectCloseOpen() {
- log("testProjectCloseOpen");
- IProject project = null;
- IMarker marker = null;
-
- // create a marker on the project
- project = getWorkspace().getRoot().getProjects()[0];
- try {
- marker = project.createMarker(IMarker.BOOKMARK);
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- // ensure that the marker was created
- assertTrue("2.0", marker.exists());
-
- // close the project
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
-
- // now the marker should be inaccessible
- assertTrue("", !marker.exists());
-
- // open the project
- try {
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("4.0", e);
- }
-
- // the marker re-appears
- assertTrue("5.0", marker.exists());
-}
-public void testSetGetAttribute() {
- log("testSetGetAttribute");
-
- for (int i = 0; i < resources.length; i++) {
- IResource resource = resources[i];
- IMarker marker = null;
-
- // getting a non-existant attribute should return null
- try {
- marker = resource.createMarker(IMarker.PROBLEM);
- } catch (CoreException e) {
- fail("1.0", e);
- }
- try {
- assertNull("1.1." + resource.getFullPath(), marker.getAttribute(IMarker.MESSAGE));
- } catch (CoreException e) {
- fail("1.2." + resource.getFullPath(), e);
- }
-
- // set an attribute, get its value, then remove it
- String testMessage = getRandomString();
- try {
- marker.setAttribute(IMarker.MESSAGE, testMessage);
- Object value = marker.getAttribute(IMarker.MESSAGE);
- assertEquals("2.0." + resource.getFullPath(), testMessage, (String) value);
- marker.setAttribute(IMarker.MESSAGE, null);
- value = marker.getAttribute(IMarker.MESSAGE);
- assertNull("2.1." + resource.getFullPath(), value);
- } catch (CoreException e) {
- fail("2.2." + resource.getFullPath(), e);
- }
-
- // set more attributes, get their values, then remove one
- try {
- String[] keys = new String[] { IMarker.LOCATION, IMarker.SEVERITY, IMarker.DONE };
- Object[] values = new Object[3];
- values[0] = getRandomString();
- values[1] = new Integer(5);
- values[2] = Boolean.FALSE;
- marker.setAttributes(keys, values);
- Object[] found = marker.getAttributes(keys);
- assertEquals("3.0." + resource.getFullPath(), values, found);
- marker.setAttribute(IMarker.SEVERITY, null);
- values[1] = null;
- found = marker.getAttributes(keys);
- assertEquals("3.1." + resource.getFullPath(), values, found);
- values[1] = new Integer(5);
- marker.setAttribute(IMarker.SEVERITY, values[1]);
- Map all = marker.getAttributes();
- assertEquals("3.2." + resource.getFullPath(), all, keys, values);
- } catch (CoreException e) {
- fail("3.2." + resource.getFullPath(), e);
- }
-
- // try sending null as args
- try {
- marker.getAttribute(null);
- fail("4.0");
- } catch (CoreException e) {
- fail("4.1." + resource.getFullPath(), e);
- } catch (NullPointerException e) {
- fail("4.2", e);
- } catch (RuntimeException e) {
- }
- try {
- marker.getAttributes(null);
- fail("4.3");
- } catch (CoreException e) {
- fail("4.4." + resource.getFullPath(), e);
- } catch (NullPointerException e) {
- fail("4.5", e);
- } catch (RuntimeException e) {
- }
- try {
- marker.setAttribute(null, getRandomString());
- fail("4.6");
- } catch (CoreException e) {
- fail("4.7." + resource.getFullPath(), e);
- } catch (NullPointerException e) {
- fail("4.8", e);
- } catch (RuntimeException e) {
- }
- try {
- marker.setAttributes(null, new String[] { getRandomString()});
- fail("4.9");
- } catch (CoreException e) {
- fail("4.10." + resource.getFullPath(), e);
- } catch (NullPointerException e) {
- fail("4.11", e);
- } catch (RuntimeException e) {
- }
- try {
- marker.setAttributes(new String[] { IMarker.MESSAGE }, null);
- fail("4.12");
- } catch (CoreException e) {
- fail("4.13." + resource.getFullPath(), e);
- } catch (NullPointerException e) {
- fail("4.14", e);
- } catch (RuntimeException e) {
- }
- //set attributes on deleted marker
- try {
- marker.delete();
- } catch(CoreException e) {
- fail("5.0", e);
- }
- try {
- marker.setAttribute(IMarker.MESSAGE, "Hello");
- fail("5.1");
- } catch (CoreException e) {
- }
- try {
- marker.setAttributes(new String[] {IMarker.LINE_NUMBER}, new Object[] {new Integer(4)});
- fail("5.2");
- } catch (CoreException e) {
- }
- try {
- HashMap attributes = new HashMap();
- attributes.put(IMarker.MESSAGE, "Hello");
- marker.setAttributes(attributes);
- fail("5.3");
- } catch (CoreException e) {
- }
- }
-}
-public void testSetGetAttribute2() {
- log("testSetGetAttribute2");
-
- for (int i = 0; i < resources.length; i++) {
- IResource resource = resources[i];
- IMarker marker = null;
-
- // getting a non-existant attribute should return null or the specified default
- try {
- marker = resource.createMarker(IMarker.PROBLEM);
- } catch (CoreException e) {
- fail("0.0" + resource.getFullPath(), e);
- }
- try {
- // #getAttribute(Object)
- assertNull("1.0." + resource.getFullPath(), marker.getAttribute(IMarker.MESSAGE));
- // #getAttribute(String, String)
- assertEquals("1.1." + resource.getFullPath(), "default", marker.getAttribute(IMarker.MESSAGE, "default"));
- // #getAttribute(String, boolean)
- assertEquals("1.2." + resource.getFullPath(), true, marker.getAttribute(IMarker.MESSAGE, true));
- // #getAttribute(String, int)
- assertEquals("1.3." + resource.getFullPath(), 5, marker.getAttribute(IMarker.MESSAGE, 5));
- // #getAttributes()
- assertNull("1.4." + resource.getFullPath(), marker.getAttributes());
- // #getAttributes(String[])
- assertTrue("1.5." + resource.getFullPath(), marker.getAttributes(new String[] { IMarker.MESSAGE })[0] == null);
- } catch (CoreException e) {
- fail("1.99." + resource.getFullPath(), e);
- }
-
- // set an attribute, get its value, then remove it
- String testMessage = getRandomString();
- try {
- marker.setAttribute(IMarker.MESSAGE, testMessage);
- Object value = marker.getAttribute(IMarker.MESSAGE);
- assertEquals("2.0." + resource.getFullPath(), testMessage, (String) value);
- marker.setAttribute(IMarker.MESSAGE, null);
- value = marker.getAttribute(IMarker.MESSAGE);
- assertNull("2.1." + resource.getFullPath(), value);
- } catch (CoreException e) {
- fail("2.2." + resource.getFullPath(), e);
- }
-
- // set more attributes, get their values, then remove one
- try {
- String[] keys = new String[] { IMarker.LOCATION, IMarker.SEVERITY, IMarker.DONE };
- Object[] values = new Object[3];
- values[0] = getRandomString();
- values[1] = new Integer(5);
- values[2] = Boolean.FALSE;
- marker.setAttributes(keys, values);
- Object[] found = marker.getAttributes(keys);
- assertEquals("3.0." + resource.getFullPath(), values, found);
- marker.setAttribute(IMarker.SEVERITY, null);
- values[1] = null;
- found = marker.getAttributes(keys);
- assertEquals("3.1." + resource.getFullPath(), values, found);
- values[1] = new Integer(5);
- marker.setAttribute(IMarker.SEVERITY, values[1]);
- Map all = marker.getAttributes();
- assertEquals("3.2." + resource.getFullPath(), all, keys, values);
- } catch (CoreException e) {
- fail("3.2." + resource.getFullPath(), e);
- }
-
- // try sending null as args
- try {
- // #getAttribute(String)
- marker.getAttribute(null);
- fail("4.0");
- } catch (CoreException e) {
- fail("4.1." + resource.getFullPath(), e);
- } catch (NullPointerException e) {
- fail("4.2", e);
- } catch (RuntimeException e) {
- }
- try {
- // #getAttribute(String, String)
- marker.getAttribute(null, "default");
- fail("4.3");
- } catch (NullPointerException e) {
- fail("4.5", e);
- } catch (RuntimeException e) {
- }
- try {
- // #getAttribute(String, boolean)
- marker.getAttribute(null, true);
- fail("4.6");
- } catch (NullPointerException e) {
- fail("4.8", e);
- } catch (RuntimeException e) {
- }
- try {
- // #getAttribute(String, int)
- marker.getAttribute(null, 5);
- fail("4.9");
- } catch (NullPointerException e) {
- fail("4.11", e);
- } catch (RuntimeException e) {
- }
- try {
- // #getAttributes(String[])
- marker.getAttributes(null);
- fail("4.12");
- } catch (CoreException e) {
- fail("4.13." + resource.getFullPath(), e);
- } catch (NullPointerException e) {
- fail("4.14", e);
- } catch (RuntimeException e) {
- }
- try {
- // #setAttribute(String, Object)
- marker.setAttribute(null, getRandomString());
- fail("4.15");
- } catch (CoreException e) {
- fail("4.16." + resource.getFullPath(), e);
- } catch (NullPointerException e) {
- fail("4.17", e);
- } catch (RuntimeException e) {
- }
- try {
- // #setAttributes(String[], Object[])
- marker.setAttributes(null, new String[] { getRandomString()});
- fail("4.18");
- } catch (CoreException e) {
- fail("4.19." + resource.getFullPath(), e);
- } catch (NullPointerException e) {
- fail("4.20", e);
- } catch (RuntimeException e) {
- }
- try {
- // #setAttributes(String[], Object[])
- marker.setAttributes(new String[] { IMarker.MESSAGE }, null);
- fail("4.21");
- } catch (CoreException e) {
- fail("4.22." + resource.getFullPath(), e);
- } catch (NullPointerException e) {
- fail("4.23", e);
- } catch (RuntimeException e) {
- }
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkersChangeListener.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkersChangeListener.java
deleted file mode 100644
index 158483c..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkersChangeListener.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import java.util.Hashtable;
-import java.util.Vector;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-
-/**
- * A support class for the marker tests.
- */
-public class MarkersChangeListener implements IResourceChangeListener {
- protected Hashtable changes;
-public MarkersChangeListener() {
- reset();
-}
-/**
- * Returns whether the changes for the given resource (or null for the workspace)
- * are exactly the added, removed and changed markers given. The arrays may be null.
- */
-public boolean checkChanges(IResource resource, IMarker[] added, IMarker[] removed, IMarker[] changed) {
- IPath path = resource == null ? Path.ROOT : resource.getFullPath();
- Vector v = (Vector) changes.get(path);
- if (v == null)
- v = new Vector();
- int numChanges = (added == null ? 0 : added.length) + (removed == null ? 0 : removed.length) + (changed == null ? 0 : changed.length);
- if (numChanges != v.size())
- return false;
- for (int i = 0; i < v.size(); ++i) {
- IMarkerDelta delta = (IMarkerDelta) v.elementAt(i);
- switch (delta.getKind()) {
- case IResourceDelta.ADDED :
- if (!contains(added, delta.getMarker()))
- return false;
- break;
- case IResourceDelta.REMOVED :
- if (!contains(removed, delta.getMarker()))
- return false;
- break;
- case IResourceDelta.CHANGED :
- if (!contains(changed, delta.getMarker()))
- return false;
- break;
- default :
- throw new Error();
- }
- }
- return true;
-}
-/**
- * Returns whether the given marker is contained in the given list of markers.
- */
-protected boolean contains(IMarker[] markers, IMarker marker) {
- if (markers != null) {
- for (int i = 0; i < markers.length; ++i) {
- if (markers[i].equals(marker))
- return true;
- }
- }
- return false;
-}
-/**
- * Returns the number of resources (or the workspace) which have had marker changes since last reset.
- */
-public int numAffectedResources() {
- return changes.size();
-}
-public void reset() {
- changes = new Hashtable(11);
-}
-/**
- * Notification from the workspace. Extract the marker changes.
- */
-public void resourceChanged(IResourceChangeEvent event) {
- resourceChanged(event.getDelta());
-}
-/**
- * Recurse over the delta, extracting marker changes.
- */
-protected void resourceChanged(IResourceDelta delta) {
- if (delta == null)
- return;
- if ((delta.getFlags() & IResourceDelta.MARKERS) != 0) {
- IPath path = delta.getFullPath();
- Vector v = (Vector) changes.get(path);
- if (v == null) {
- v = new Vector();
- changes.put(path, v);
- }
- IMarkerDelta[] markerDeltas = delta.getMarkerDeltas();
- for (int i = 0; i < markerDeltas.length; ++i) {
- v.addElement(markerDeltas[i]);
- }
- }
- IResourceDelta[] children = delta.getAffectedChildren();
- for (int i = 0; i < children.length; ++i) {
- resourceChanged(children[i]);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NatureTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NatureTest.java
deleted file mode 100644
index e233ceb..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NatureTest.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-/**
- * Tests all aspects of project natures. These tests only
- * exercise API classes and methods. Note that the nature-related
- * APIs on IWorkspace are tested by IWorkspaceTest.
- */
-public class NatureTest extends EclipseWorkspaceTest {
-/**
- * Constructor for NatureTest.
- */
-public NatureTest() {
- super();
-}
-/**
- * Constructor for NatureTest.
- * @param name
- */
-public NatureTest(String name) {
- super(name);
-}
-public static Test suite() {
- return new TestSuite(NatureTest.class);
-}
-/**
- * Sets the given set of natures for the project. If success
- * does not match the "shouldFail" argument, an assertion error
- * with the given message is thrown.
- */
-protected void setNatures(String message, boolean shouldFail, IProject project, String[] natures) {
- try {
- IProjectDescription desc = project.getDescription();
- desc.setNatureIds(natures);
- project.setDescription(desc, getMonitor());
- if (shouldFail)
- fail(message);
- } catch (CoreException e) {
- if (!shouldFail)
- fail(message, e);
- }
-}
-protected void tearDown() throws Exception {
- super.tearDown();
- getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
- ensureDoesNotExistInWorkspace(getWorkspace().getRoot());
-}
-/**
- * Tests invalid additions to the set of natures for a project.
- */
-public void testInvalidAdditions() {
- IWorkspace ws = ResourcesPlugin.getWorkspace();
- IProject project = ws.getRoot().getProject("Project");
- ensureExistsInWorkspace(project, true);
- setNatures("1.0", false, project, new String[] {NATURE_SIMPLE});
-
- //Adding a nature that is not available.
- setNatures("2.0", true, project, new String[] {NATURE_SIMPLE, NATURE_MISSING});
- try {
- assertTrue("2.1", project.hasNature(NATURE_SIMPLE));
- assertTrue("2.2", !project.hasNature(NATURE_MISSING));
- assertTrue("2.3", project.isNatureEnabled(NATURE_SIMPLE));
- assertTrue("2.4", !project.isNatureEnabled(NATURE_MISSING));
- } catch (CoreException e) {
- fail("2.99", e);
- }
- //Adding a nature that has a missing prerequisite.
- setNatures("3.0", true, project, new String[] {NATURE_SIMPLE, NATURE_SNOW});
- try {
- assertTrue("3.1", project.hasNature(NATURE_SIMPLE));
- assertTrue("3.2", !project.hasNature(NATURE_SNOW));
- assertTrue("3.3", project.isNatureEnabled(NATURE_SIMPLE));
- assertTrue("3.4", !project.isNatureEnabled(NATURE_SNOW));
- } catch (CoreException e) {
- fail("3.99", e);
- }
- //Adding a nature that creates a duplicated set member.
- setNatures("4.0", false, project, new String[] {NATURE_EARTH});
- setNatures("4.1", true, project, new String[] {NATURE_EARTH, NATURE_WATER});
- try {
- assertTrue("3.1", project.hasNature(NATURE_EARTH));
- assertTrue("3.2", !project.hasNature(NATURE_WATER));
- assertTrue("3.3", project.isNatureEnabled(NATURE_EARTH));
- assertTrue("3.4", !project.isNatureEnabled(NATURE_WATER));
- } catch (CoreException e) {
- fail("3.99", e);
- }
-}
-/**
- * Tests invalid removals from the set of natures for a project.
- */
-public void testInvalidRemovals() {
- IWorkspace ws = ResourcesPlugin.getWorkspace();
- IProject project = ws.getRoot().getProject("Project");
- ensureExistsInWorkspace(project, true);
-
- //Removing a nature that still has dependents.
- setNatures("1.0", false, project, new String[] {NATURE_WATER, NATURE_SNOW});
- setNatures("2.0", true, project, new String[] {NATURE_SNOW});
- try {
- assertTrue("2.1", project.hasNature(NATURE_WATER));
- assertTrue("2.2", project.hasNature(NATURE_SNOW));
- assertTrue("2.3", project.isNatureEnabled(NATURE_WATER));
- assertTrue("2.4", project.isNatureEnabled(NATURE_SNOW));
- } catch (CoreException e) {
- fail("2.99", e);
- }
-
-}
-/**
- * Test simple addition and removal of natures.
- */
-public void testSimpleNature() {
- IWorkspace ws = ResourcesPlugin.getWorkspace();
- IProject project = ws.getRoot().getProject("Project");
- ensureExistsInWorkspace(project, true);
-
- String[][] valid = getValidNatureSets();
- for (int i = 0; i < valid.length; i++) {
- setNatures("valid: " + i, false, project, valid[i]);
- }
- //configure a valid nature before starting invalid tests
- String[] currentSet = new String[] {NATURE_SIMPLE};
- setNatures("1.0", false, project, currentSet);
-
- //now do invalid tests and ensure simple nature is still configured
- String[][] invalid = getInvalidNatureSets();
- for (int i = 0; i < invalid.length; i++) {
- setNatures("invalid: " + i, true, project, invalid[i]);
- try {
- assertTrue("2.0", project.hasNature(NATURE_SIMPLE));
- assertTrue("2.1", !project.hasNature(NATURE_EARTH));
- assertTrue("2.2", project.isNatureEnabled(NATURE_SIMPLE));
- assertTrue("2.3", !project.isNatureEnabled(NATURE_EARTH));
- assertEquals("2.4", project.getDescription().getNatureIds(), currentSet);
- } catch (CoreException e) {
- fail("2.99", e);
- }
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectOrderTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectOrderTest.java
deleted file mode 100644
index f2f2e5e..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ProjectOrderTest.java
+++ /dev/null
@@ -1,549 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import java.util.*;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-/**
- * Performs black box testing of the following API methods:
- * <code>IWorkspace.computeProjectOrder(IProject[])</code>
- * <code>IWorkspace.computePrerequisiteOrder(IProject[])</code>
- */
-public class ProjectOrderTest extends EclipseWorkspaceTest {
-
- public ProjectOrderTest() {
- }
- public ProjectOrderTest(String name) {
- super(name);
- }
- public static Test suite() {
- TestSuite suite = new TestSuite(ProjectOrderTest.class);
- return suite;
- }
-
- /**
- * Adds a project reference from the given source project, which must
- * be accessible, to the given target project, which need not be accessible.
- * Does nothing if the source project already has a project reference
- * to the target project.
- *
- * @param source the source project; must be accessible
- * @param target the target project; need not be accessible
- */
- void addProjectReference(IProject source, IProject target) {
- try {
- IProjectDescription pd = source.getDescription();
- IProject[] a = pd.getReferencedProjects();
- Set x = new HashSet();
- x.addAll(Arrays.asList(a));
- x.add(target);
- IProject[] r = new IProject[x.size()];
- x.toArray(r);
- pd.setReferencedProjects(r);
- source.setDescription(pd, null);
- } catch (CoreException e) {
- assertTrue("", false);
- }
- }
-
- /**
- * P0, P1<-P2<-P3<-P4, P5
- */
- public void test0() {
- IWorkspace ws = getWorkspace();
- IWorkspaceRoot root = ws.getRoot();
- IProject p0 = root.getProject("p0");
- IProject p1 = root.getProject("p1");
- IProject p2 = root.getProject("p2");
- IProject p3 = root.getProject("p3");
- IProject p4 = root.getProject("p4");
- IProject p5 = root.getProject("p5");
-
- try {
- p0.create(null);
- p0.open(null);
- p1.create(null);
- p1.open(null);
- p2.create(null);
- p2.open(null);
- p3.create(null);
- p3.open(null);
- p4.create(null);
- p4.open(null);
- p5.create(null);
- p5.open(null);
-
- addProjectReference(p2, p1);
- addProjectReference(p3, p2);
- addProjectReference(p4, p3);
-
- IProject[] projects = new IProject[] { p4, p3, p2, p5, p1, p0 };
- IProject[][] oldOrder = ws.computePrerequisiteOrder(projects);
- assertTrue("0.1", oldOrder[1].length == 0);
- List x = Arrays.asList(oldOrder[0]);
- assertTrue("0.2", x.size() == 6);
- assertTrue("0.3", x.indexOf(p0) >= 0);
- assertTrue("0.4", x.indexOf(p1) >= 0);
- assertTrue("0.5", x.indexOf(p5) >= 0);
- assertTrue("0.6", x.indexOf(p2) > x.indexOf(p1));
- assertTrue("0.7", x.indexOf(p3) > x.indexOf(p2));
- assertTrue("0.8", x.indexOf(p4) > x.indexOf(p3));
-
- IWorkspace.ProjectOrder order = ws.computeProjectOrder(projects);
- x = Arrays.asList(order.projects);
- assertTrue("0.9", !order.hasCycles);
- assertTrue("0.10", order.knots.length == 0);
- assertTrue("0.11", x.size() == 6);
- assertTrue("0.12", x.indexOf(p0) < x.indexOf(p1)); //alpha
- assertTrue("0.13", x.indexOf(p2) > x.indexOf(p1)); //ref
- assertTrue("0.14", x.indexOf(p3) > x.indexOf(p2)); //ref
- assertTrue("0.15", x.indexOf(p4) > x.indexOf(p3)); //ref
- assertTrue("0.16", x.indexOf(p5) > x.indexOf(p4)); //alpha
- } catch (CoreException e) {
- assertTrue("0.0", false);
- }
- }
-
- public void test1() {
- IWorkspace ws = getWorkspace();
- IWorkspaceRoot root = ws.getRoot();
- IProject p0 = root.getProject("p0");
- IProject p1 = root.getProject("p1");
-
- IProject[] projects = new IProject[] {
- };
- IProject[][] oldOrder = ws.computePrerequisiteOrder(projects);
- List x = Arrays.asList(oldOrder[0]);
- assertTrue("1.1", oldOrder[1].length == 0);
- assertTrue("1.2", x.size() == 0);
-
- // no projects
- IWorkspace.ProjectOrder order = ws.computeProjectOrder(projects);
- x = Arrays.asList(order.projects);
- assertTrue("1.3", !order.hasCycles);
- assertTrue("1.4", order.knots.length == 0);
- assertTrue("1.5", x.size() == 0);
-
- // 1 project
- try {
- // open projects show up
- p0.create(null);
- p0.open(null);
- projects = new IProject[] { p0 };
- oldOrder = ws.computePrerequisiteOrder(projects);
- x = Arrays.asList(oldOrder[0]);
- assertTrue("1.6.1", oldOrder[1].length == 0);
- assertTrue("1.6.2", x.size() == 1);
- assertTrue("1.6.3", x.indexOf(p0) >= 0);
-
- order = ws.computeProjectOrder(projects);
- x = Arrays.asList(order.projects);
- assertTrue("1.6.4", !order.hasCycles);
- assertTrue("1.6.5", order.knots.length == 0);
- assertTrue("1.6.6", x.size() == 1);
- assertTrue("1.6.7", x.indexOf(p0) >= 0);
-
- // closed projects do not show up
- p0.close(null);
- projects = new IProject[] { p0 };
- oldOrder = ws.computePrerequisiteOrder(projects);
- x = Arrays.asList(oldOrder[0]);
- assertTrue("1.6,8", oldOrder[1].length == 0);
- assertTrue("1.6.9", x.size() == 0);
-
- order = ws.computeProjectOrder(projects);
- x = Arrays.asList(order.projects);
- assertTrue("1.6.10", !order.hasCycles);
- assertTrue("1.6.11", order.knots.length == 0);
- assertTrue("1.6.12", x.size() == 0);
-
- // non-existent projects do not show up either
- projects = new IProject[] { p0, p1 };
- oldOrder = ws.computePrerequisiteOrder(projects);
- x = Arrays.asList(oldOrder[0]);
- assertTrue("1.6.13", oldOrder[1].length == 0);
- assertTrue("1.6.14", x.size() == 0);
-
- order = ws.computeProjectOrder(projects);
- x = Arrays.asList(order.projects);
- assertTrue("1.6.15", !order.hasCycles);
- assertTrue("1.6.16", order.knots.length == 0);
- assertTrue("1.6.17", x.size() == 0);
-
- p0.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, null);
- } catch (CoreException e) {
- assertTrue("1.6.0", false);
- }
-
- // 2 projects no references
- try {
- // open projects show up
- p0.create(null);
- p0.open(null);
- p1.create(null);
- p1.open(null);
-
- projects = new IProject[] { p1, p0 };
- oldOrder = ws.computePrerequisiteOrder(projects);
- x = Arrays.asList(oldOrder[0]);
- assertTrue("1.7.1", oldOrder[1].length == 0);
- assertTrue("1.7.2", x.size() == 2);
- assertTrue("1.7.3", x.indexOf(p0) >= 0);
- assertTrue("1.7.4", x.indexOf(p1) >= 0);
-
- order = ws.computeProjectOrder(projects);
- x = Arrays.asList(order.projects);
- assertTrue("1.7.5", x.size() == 2);
- assertTrue("1.7.6", x.indexOf(p0) >= 0);
- assertTrue("1.7.7", x.indexOf(p1) >= 0);
- // alpha order
- assertTrue("1.7.8", x.indexOf(p0) < x.indexOf(p1));
- assertTrue("1.7.9", !order.hasCycles);
- assertTrue("1.7.10", order.knots.length == 0);
-
- // closed projects do not show up
- p0.close(null);
- oldOrder = ws.computePrerequisiteOrder(projects);
- x = Arrays.asList(oldOrder[0]);
- assertTrue("1.7.11", oldOrder[1].length == 0);
- assertTrue("1.7.12", x.size() == 1);
- assertTrue("1.7.13", x.indexOf(p0) < 0);
- assertTrue("1.7.14", x.indexOf(p1) >= 0);
-
- order = ws.computeProjectOrder(projects);
- x = Arrays.asList(order.projects);
- assertTrue("1.7.15", !order.hasCycles);
- assertTrue("1.7.16", order.knots.length == 0);
- assertTrue("1.7.17", x.size() == 1);
- assertTrue("1.7.18", x.indexOf(p0) < 0);
- assertTrue("1.7.19", x.indexOf(p1) >= 0);
-
- p0.open(null);
- p1.close(null);
- oldOrder = ws.computePrerequisiteOrder(projects);
- x = Arrays.asList(oldOrder[0]);
- assertTrue("1.7.20", oldOrder[1].length == 0);
- assertTrue("1.7.21", x.size() == 1);
- assertTrue("1.7.22", x.indexOf(p0) >= 0);
- assertTrue("1.7.23", x.indexOf(p1) < 0);
-
- order = ws.computeProjectOrder(projects);
- x = Arrays.asList(order.projects);
- assertTrue("1.7.24", !order.hasCycles);
- assertTrue("1.7.25", order.knots.length == 0);
- assertTrue("1.7.26", x.size() == 1);
- assertTrue("1.7.27", x.indexOf(p0) >= 0);
- assertTrue("1.7.28", x.indexOf(p1) < 0);
-
- p0.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, null);
- p1.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, null);
- } catch (CoreException e) {
- assertTrue("1.7.0", false);
- }
-
- // 2 projects: "p0" refs "p1"
- try {
- p0.create(null);
- p0.open(null);
- p1.create(null);
- p1.open(null);
- addProjectReference(p0, p1);
-
- projects = new IProject[] { p1, p0 };
- oldOrder = ws.computePrerequisiteOrder(projects);
- x = Arrays.asList(oldOrder[0]);
- assertTrue("1.8.1", oldOrder[1].length == 0);
- assertTrue("1.8.2", x.size() == 2);
- assertTrue("1.8.3", x.indexOf(p0) >= 0);
- assertTrue("1.8.4", x.indexOf(p1) >= 0);
- assertTrue("1.8.5", x.indexOf(p0) > x.indexOf(p1));
-
- order = ws.computeProjectOrder(projects);
- x = Arrays.asList(order.projects);
- assertTrue("1.8.6", x.size() == 2);
- assertTrue("1.8.7", x.indexOf(p0) >= 0);
- assertTrue("1.8.8", x.indexOf(p1) >= 0);
- assertTrue("1.8.9", x.indexOf(p0) > x.indexOf(p1));
- assertTrue("1.8.10", !order.hasCycles);
- assertTrue("1.8.11", order.knots.length == 0);
-
- p0.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, null);
- p1.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, null);
- } catch (CoreException e) {
- assertTrue("1.8.0", false);
- }
-
- // 2 projects: "p1" refs "p0"
- try {
- p0.create(null);
- p0.open(null);
- p1.create(null);
- p1.open(null);
- addProjectReference(p1, p0);
-
- projects = new IProject[] { p1, p0 };
- oldOrder = ws.computePrerequisiteOrder(projects);
- x = Arrays.asList(oldOrder[0]);
- assertTrue("1.9.1", oldOrder[1].length == 0);
- assertTrue("1.9.2", x.size() == 2);
- assertTrue("1.9.3", x.indexOf(p0) >= 0);
- assertTrue("1.9.4", x.indexOf(p1) >= 0);
- assertTrue("1.9.5", x.indexOf(p1) > x.indexOf(p0));
-
- order = ws.computeProjectOrder(projects);
- x = Arrays.asList(order.projects);
- assertTrue("1.9.6", !order.hasCycles);
- assertTrue("1.9.7", order.knots.length == 0);
- assertTrue("1.9.8", x.size() == 2);
- assertTrue("1.9.9", x.indexOf(p0) >= 0);
- assertTrue("1.9.10", x.indexOf(p1) >= 0);
- assertTrue("1.9.11", x.indexOf(p1) > x.indexOf(p0));
-
- p0.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, null);
- p1.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, null);
- } catch (CoreException e) {
- assertTrue("1.9.0", false);
- }
-
- // 2 projects: "p0" refs "p1" and "p1" refs "p0"
- try {
- // open projects show up
- p0.create(null);
- p0.open(null);
- p1.create(null);
- p1.open(null);
- addProjectReference(p1, p0);
- addProjectReference(p0, p1);
-
- projects = new IProject[] { p1, p0 };
- oldOrder = ws.computePrerequisiteOrder(projects);
- x = Arrays.asList(oldOrder[0]);
- List unordered = Arrays.asList(oldOrder[1]);
- assertTrue("1.10.1", oldOrder[1].length == 2);
- assertTrue("1.10.2", x.size() == 0);
- assertTrue("1.10.3", unordered.size() == 2);
- assertTrue("1.10.4", unordered.indexOf(p0) >= 0);
- assertTrue("1.10.5", unordered.indexOf(p1) >= 0);
-
- order = ws.computeProjectOrder(projects);
- x = Arrays.asList(order.projects);
- assertTrue("1.10.6", order.hasCycles);
- assertTrue("1.10.7", order.knots.length == 1);
- assertTrue("1.10.8", x.size() == 2);
- assertTrue("1.10.9", x.indexOf(p0) >= 0);
- assertTrue("1.10.10", x.indexOf(p1) >= 0);
- List knot = Arrays.asList(order.knots[0]);
- assertTrue("1.10.11", knot.size() == 2);
- assertTrue("1.10.12", knot.indexOf(p0) >= 0);
- assertTrue("1.10.13", knot.indexOf(p1) >= 0);
-
- // closing one breaks the cycle
- p0.close(null);
- oldOrder = ws.computePrerequisiteOrder(projects);
- x = Arrays.asList(oldOrder[0]);
- assertTrue("1.10.14", oldOrder[1].length == 0);
- assertTrue("1.10.15", x.size() == 1);
- assertTrue("1.10.16", x.indexOf(p1) >= 0);
-
- order = ws.computeProjectOrder(projects);
- x = Arrays.asList(order.projects);
- assertTrue("1.10.17", !order.hasCycles);
- assertTrue("1.10.18", order.knots.length == 0);
- assertTrue("1.10.19", x.size() == 1);
- assertTrue("1.10.20", x.indexOf(p1) >= 0);
-
- // closing other instead breaks the cycle
- p0.open(null);
- p1.close(null);
- oldOrder = ws.computePrerequisiteOrder(projects);
- x = Arrays.asList(oldOrder[0]);
- assertTrue("1.10.21", oldOrder[1].length == 0);
- assertTrue("1.10.22", x.size() == 1);
- assertTrue("1.10.23", x.indexOf(p0) >= 0);
-
- order = ws.computeProjectOrder(projects);
- x = Arrays.asList(order.projects);
- assertTrue("1.10.24", !order.hasCycles);
- assertTrue("1.10.25", order.knots.length == 0);
- assertTrue("1.10.26", x.size() == 1);
- assertTrue("1.10.27", x.indexOf(p0) >= 0);
-
- // reopening both brings back the cycle
- p1.open(null);
- oldOrder = ws.computePrerequisiteOrder(projects);
- x = Arrays.asList(oldOrder[0]);
- unordered = Arrays.asList(oldOrder[1]);
- assertTrue("1.10.28", oldOrder[1].length == 2);
- assertTrue("1.10.29", x.size() == 0);
- assertTrue("1.10.30", unordered.size() == 2);
- assertTrue("1.10.31", unordered.indexOf(p0) >= 0);
- assertTrue("1.10.32", unordered.indexOf(p1) >= 0);
-
- order = ws.computeProjectOrder(projects);
- x = Arrays.asList(order.projects);
- assertTrue("1.10.33", order.hasCycles);
- assertTrue("1.10.34", order.knots.length == 1);
- assertTrue("1.10.35", x.size() == 2);
- assertTrue("1.10.36", x.indexOf(p0) >= 0);
- assertTrue("1.10.37", x.indexOf(p1) >= 0);
- knot = Arrays.asList(order.knots[0]);
- assertTrue("1.10.38", knot.size() == 2);
- assertTrue("1.10.39", knot.indexOf(p0) >= 0);
- assertTrue("1.10.40", knot.indexOf(p1) >= 0);
-
- p0.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, null);
- p1.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, null);
- } catch (CoreException e) {
- assertTrue("1.10.41", false);
- }
- }
-
- /**
- * Introduction to Algorithms
- * Cormen, Leiserson, Rivest
- * Figure 23.9(b)
- */
- public void test2() {
- IWorkspace ws = getWorkspace();
- IWorkspaceRoot root = ws.getRoot();
- IProject a = root.getProject("a");
- IProject b = root.getProject("b");
- IProject c = root.getProject("c");
- IProject d = root.getProject("d");
- IProject e = root.getProject("e");
- IProject f = root.getProject("f");
- IProject g = root.getProject("g");
- IProject h = root.getProject("h");
-
- try {
- a.create(null);
- a.open(null);
- b.create(null);
- b.open(null);
- c.create(null);
- c.open(null);
- d.create(null);
- d.open(null);
- e.create(null);
- e.open(null);
- f.create(null);
- f.open(null);
- g.create(null);
- g.open(null);
- h.create(null);
- h.open(null);
-
- // knot 1
- addProjectReference(b, a);
- addProjectReference(a, e);
- addProjectReference(e, b);
-
- // knot 2
- addProjectReference(c, d);
- addProjectReference(d, c);
-
- // knot 3
- addProjectReference(f, g);
- addProjectReference(g, f);
-
- // self-reference
- addProjectReference(h, h);
-
- // inter-knot references
- addProjectReference(c, b);
- addProjectReference(f, b);
- addProjectReference(g, c);
- addProjectReference(h, d);
- addProjectReference(h, g);
-
- IProject[] projects = new IProject[] { a, b, c, d, e, f, g, h };
- IProject[][] oldOrder = ws.computePrerequisiteOrder(projects);
- List x = Arrays.asList(oldOrder[0]);
- List unordered = Arrays.asList(oldOrder[1]);
- assertTrue("2.1", x.size() == 1);
- assertTrue("2.2", x.indexOf(h) >= 0);
- assertTrue("2.3", unordered.size() == 7);
- assertTrue("2.4", unordered.indexOf(a) >= 0);
- assertTrue("2.5", unordered.indexOf(b) >= 0);
- assertTrue("2.6", unordered.indexOf(c) >= 0);
- assertTrue("2.7", unordered.indexOf(d) >= 0);
- assertTrue("2.8", unordered.indexOf(e) >= 0);
- assertTrue("2.9", unordered.indexOf(f) >= 0);
- assertTrue("2.10", unordered.indexOf(g) >= 0);
-
- IWorkspace.ProjectOrder order = ws.computeProjectOrder(projects);
- x = Arrays.asList(order.projects);
- assertTrue("2.11", x.size() == 8);
- assertTrue("2.12", x.indexOf(a) >= 0);
- assertTrue("2.13", x.indexOf(b) >= 0);
- assertTrue("2.14", x.indexOf(c) >= 0);
- assertTrue("2.15", x.indexOf(d) >= 0);
- assertTrue("2.16", x.indexOf(e) >= 0);
- assertTrue("2.17", x.indexOf(f) >= 0);
- assertTrue("2.18", x.indexOf(g) >= 0);
- assertTrue("2.19", x.indexOf(h) >= 0);
- // {a, b, e} < {c,d} < {f, g} < {h}
- assertTrue("2.20", x.indexOf(b) < x.indexOf(c));
- assertTrue("2.21", x.indexOf(b) < x.indexOf(d));
- assertTrue("2.22", x.indexOf(a) < x.indexOf(c));
- assertTrue("2.23", x.indexOf(a) < x.indexOf(d));
- assertTrue("2.24", x.indexOf(e) < x.indexOf(c));
- assertTrue("2.25", x.indexOf(e) < x.indexOf(d));
- assertTrue("2.26", x.indexOf(c) < x.indexOf(f));
- assertTrue("2.27", x.indexOf(c) < x.indexOf(g));
- assertTrue("2.28", x.indexOf(d) < x.indexOf(f));
- assertTrue("2.29", x.indexOf(d) < x.indexOf(g));
- assertTrue("2.30", x.indexOf(f) < x.indexOf(h));
- assertTrue("2.31", x.indexOf(g) < x.indexOf(h));
- assertTrue("2.32", order.hasCycles);
- assertTrue("2.33", order.knots.length == 3);
- List k1 = Arrays.asList(order.knots[0]);
- List k2 = Arrays.asList(order.knots[1]);
- List k3 = Arrays.asList(order.knots[2]);
- // sort 3 groups
- if (k2.indexOf(b) >= 0) {
- List temp = k1;
- k1 = k2;
- k2 = temp;
- } else if (k3.indexOf(b) >= 0) {
- List temp = k1;
- k1 = k3;
- k3 = temp;
- }
- if (k3.indexOf(c) >= 0) {
- List temp = k2;
- k2 = k3;
- k3 = temp;
- }
- // knot 1
- assertTrue("2.34", k1.size() == 3);
- assertTrue("2.35", k1.indexOf(a) >= 0);
- assertTrue("2.36", k1.indexOf(b) >= 0);
- assertTrue("2.37", k1.indexOf(e) >= 0);
- // knot 2
- assertTrue("2.38", k2.size() == 2);
- assertTrue("2.39", k2.indexOf(c) >= 0);
- assertTrue("2.40", k2.indexOf(d) >= 0);
- // knot 3
- assertTrue("2.41", k3.size() == 2);
- assertTrue("2.42", k3.indexOf(f) >= 0);
- assertTrue("2.43", k3.indexOf(g) >= 0);
- } catch (CoreException ex) {
- assertTrue("2.4.0", false);
- }
- }
-
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceDeltaVerifier.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceDeltaVerifier.java
deleted file mode 100644
index 9bac4b1..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceDeltaVerifier.java
+++ /dev/null
@@ -1,757 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import java.util.Enumeration;
-import java.util.Hashtable;
-
-import junit.framework.Assert;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-
-/**
- * Verifies the state of an <code>IResourceDelta</code> by comparing
- * it with a client's expectations. The delta is considered valid
- * if it contains exactly the set of changes expected by the client,
- * and parents of those changes.
- *
- * <p>Example usage:
- * <code>
- * ResourceDeltaVerifier verifier = new ResourceDeltaComparer();
- * IResourceChangeListener listener = (IResourceChangeListener)verifier;
- * IWorkspace workspace = ResourcesPlugin.getWorkspace();
- * IProject proj = workspace.getRoot().getProject("MyProject");
- * // Assume the project is accessible
- * workspace.addResourceChangeListener(listener);
- * verifier.addExpectedChange(proj, REMOVED, 0);
- * try {
- * proj.delete(true, true, null);
- * } catch(CoreException e){
- * fail("1.0", e);
- * }
- * assert("2.0 "+verifier.getMessage(), verifier.isDeltaValid());
- * </code>
- */
-public class ResourceDeltaVerifier extends Assert implements IResourceChangeListener{
- private class ExpectedChange {
- IResource fResource;
- IPath movedFromPath;
- IPath movedToPath;
- int fKind;
- int fChangeFlags;
-
- public ExpectedChange(IResource resource, int kind, int changeFlags, IPath movedFromPath, IPath movedToPath){
- fResource = resource;
- fKind = kind;
- fChangeFlags = changeFlags;
- this.movedFromPath = movedFromPath;
- this.movedToPath = movedToPath;
- }
-
- public int getChangeFlags(){
- return fChangeFlags;
- }
-
- public IPath getMovedFromPath(){
- if((fChangeFlags & IResourceDelta.MOVED_FROM) != 0){
- return movedFromPath;
- } else {
- return null;
- }
- }
-
- public IPath getMovedToPath(){
- if((fChangeFlags & IResourceDelta.MOVED_TO) != 0){
- return movedToPath;
- } else {
- return null;
- }
- }
-
- public IResource getResource(){
- return fResource;
- }
-
- public int getKind(){
- return fKind;
- }
-
- public String toString() {
- StringBuffer buf = new StringBuffer("ExpectedChange(");
- buf.append(fResource);
- buf.append(", ");
- buf.append(convertKind(fKind));
- buf.append(", ");
- buf.append(convertChangeFlags(fChangeFlags));
- buf.append(")");
- return buf.toString();
- }
-
-
- }
-
- /**
- * Table of IPath -> ExpectedChange
- */
- private Hashtable fExpectedChanges = new Hashtable();
- boolean fIsDeltaValid = true;
- private StringBuffer fMessage = new StringBuffer();
- /**
- * The verifier can be in one of three states. In the initial
- * state, the verifier is still receiving inputs via the
- * addExpectedChange() methods, and the state is RECEIVING_INPUTS.
- * After a call to verifyDelta(), the state becomes DELTA_VERIFIED
- * The verifier remains in the second state for any number of delta
- * verifications. When a getMessage() or isDeltaValid() method is
- * called, the verification completes, and the state becomes
- * VERIFICATION_COMPLETE. While in this state, any number of
- * getMessage() and isDeltaValid() methods can be called.
- * While in the third state, any call to addExpectedChange()
- * resets the verifier and puts it back in its RECEIVING_INPUTS state.
- */
- private static final int RECEIVING_INPUTS = 0;
- private static final int DELTA_VERIFIED = 1;
- private static final int VERIFICATION_COMPLETE= 2;
-
- private int fState = RECEIVING_INPUTS;
-/**
- * @see #addExpectedChange
- */
-public void addExpectedChange(IResource[] resources, int status, int changeFlags) {
- for (int i = 0; i < resources.length; i++)
- addExpectedChange(resources[i], null, status, changeFlags, null, null);
-}
-/**
- * Adds an expected deletion for the given resource and all children.
- */
-public void addExpectedDeletion(IResource resource) {
- addExpectedChange(resource, IResourceDelta.REMOVED, 0);
- if (resource instanceof IContainer) {
- try {
- IResource[] children = ((IContainer)resource).members(IContainer.INCLUDE_PHANTOMS | IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
- for (int i = 0; i < children.length; i++) {
- addExpectedDeletion(children[i]);
- }
- } catch (CoreException e) {
- e.printStackTrace();
- fail("Failed to get children in addExpectedDeletion");
- }
- }
-}
-/**
- * Signals to the comparer that the given resource is expected to
- * change in the specified way. The change flags should be set to
- * zero if no change is expected.
- * @param resource the resource that is expected to change
- * @param status the type of change (ADDED, REMOVED, CHANGED)
- * @param changeFlags the type of change (CONTENT, SYNC, etc)
- * @see IResourceConstants
- */
-public void addExpectedChange(IResource resource, int status, int changeFlags){
- addExpectedChange(resource, null, status, changeFlags, null, null);
-}
-/**
- * Signals to the comparer that the given resource is expected to
- * change in the specified way. The change flags should be set to
- * zero if no change is expected.
- * @param resource the resource that is expected to change
- * @param status the type of change (ADDED, REMOVED, CHANGED)
- * @param changeFlags the type of change (CONTENT, SYNC, etc)
- * @param movedPath or null
- * @see IResourceConstants
- */
-public void addExpectedChange(IResource resource, int status, int changeFlags, IPath movedFromPath, IPath movedToPath){
- addExpectedChange(resource, null, status, changeFlags, movedFromPath, movedToPath);
-}
-/**
- * Signals to the comparer that the given resource is expected to
- * change in the specified way. The change flags should be set to
- * zero if no change is expected.
- * @param resource the resource that is expected to change
- * @param topLevelParent Do not added expected changes above this parent
- * @param status the type of change (ADDED, REMOVED, CHANGED)
- * @param changeFlags the type of change (CONTENT, SYNC, etc)
- * @param movedPath or null
- * @see IResourceConstants
- */
-public void addExpectedChange(IResource resource, IResource topLevelParent, int status, int changeFlags){
- addExpectedChange(resource, topLevelParent, status, changeFlags, null, null);
-}
-/**
- * Signals to the comparer that the given resource is expected to
- * change in the specified way. The change flags should be set to
- * zero if no change is expected.
- * @param resource the resource that is expected to change
- * @param topLevelParent Do not added expected changes above this parent
- * @param status the type of change (ADDED, REMOVED, CHANGED)
- * @param changeFlags the type of change (CONTENT, SYNC, etc)
- * @param movedPath or null
- * @see IResourceConstants
- */
-public void addExpectedChange(IResource resource, IResource topLevelParent, int status, int changeFlags, IPath movedFromPath, IPath movedToPath) {
- resetIfNecessary();
-
- ExpectedChange expectedChange = new ExpectedChange(resource, status, changeFlags, movedFromPath, movedToPath);
- fExpectedChanges.put(resource.getFullPath(), expectedChange);
-
- // Add changes for all resources above this one and limited by the topLevelParent
- IResource parentResource = resource.getParent();
- IResource limit = (topLevelParent == null) ? null : topLevelParent.getParent();
- while (parentResource != null && !parentResource.equals(limit)) {
- //change table is keyed by resource path
- IPath key = parentResource.getFullPath();
- if (fExpectedChanges.get(key) == null) {
- ExpectedChange parentExpectedChange = new ExpectedChange(parentResource, IResourceDelta.CHANGED, 0, null, null);
- fExpectedChanges.put(key, parentExpectedChange);
- }
- parentResource = parentResource.getParent();
- }
-}
-private void checkChanges(IResourceDelta delta){
- IResource resource = delta.getResource();
-
- ExpectedChange expectedChange =
- (ExpectedChange)fExpectedChanges.remove(resource.getFullPath());
-
- int status = delta.getKind();
- int changeFlags = delta.getFlags();
-
- if (status == IResourceDelta.NO_CHANGE)
- return;
-
- if(expectedChange == null){
- recordMissingExpectedChange(status, changeFlags);
- } else {
- int expectedStatus = expectedChange.getKind();
- int expectedChangeFlags = expectedChange.getChangeFlags();
- if(status != expectedStatus || changeFlags != expectedChangeFlags){
- recordConflictingChange(expectedStatus, status, expectedChangeFlags, changeFlags);
- }
- }
-}
-private void checkChildren(IResourceDelta delta){
- IResourceDelta[] affectedChildren = delta.getAffectedChildren(IResourceDelta.ALL_WITH_PHANTOMS, IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
- IResourceDelta[] addedChildren = delta.getAffectedChildren(IResourceDelta.ADDED, IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
- IResourceDelta[] changedChildren = delta.getAffectedChildren(IResourceDelta.CHANGED, IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
- IResourceDelta[] removedChildren = delta.getAffectedChildren(IResourceDelta.REMOVED, IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
-
- Hashtable h = new Hashtable(affectedChildren.length + 1);
-
- for(int i = 0; i < addedChildren.length; ++i){
- IResourceDelta childDelta1 = addedChildren[i];
- IResource childResource = childDelta1.getResource();
- IResourceDelta childDelta2 = (IResourceDelta)h.get(childResource);
- if(childDelta2 != null){
- recordDuplicateChild(childResource.getFullPath(), childDelta2.getKind(), childDelta1.getKind(), IResourceDelta.ADDED);
- } else {
- h.put(childResource, childDelta1);
- }
- if(childDelta1.getKind() != IResourceDelta.ADDED){
- recordIllegalChild(childResource.getFullPath(), IResourceDelta.ADDED, childDelta1.getKind());
- }
- }
-
- for(int i = 0; i < changedChildren.length; ++i){
- IResourceDelta childDelta1 = changedChildren[i];
- IResource childResource = childDelta1.getResource();
- IResourceDelta childDelta2 = (IResourceDelta)h.get(childResource);
- if(childDelta2 != null){
- recordDuplicateChild(childResource.getFullPath(), childDelta2.getKind(), childDelta1.getKind(), IResourceDelta.CHANGED);
- } else {
- h.put(childResource, childDelta1);
- }
- if(childDelta1.getKind() != IResourceDelta.CHANGED){
- recordIllegalChild(childResource.getFullPath(), IResourceDelta.CHANGED, childDelta1.getKind());
- }
- }
-
- for(int i = 0; i < removedChildren.length; ++i){
- IResourceDelta childDelta1 = removedChildren[i];
- IResource childResource = childDelta1.getResource();
- IResourceDelta childDelta2 = (IResourceDelta)h.get(childResource);
- if(childDelta2 != null){
- recordDuplicateChild(childResource.getFullPath(), childDelta2.getKind(), childDelta1.getKind(), IResourceDelta.REMOVED);
- } else {
- h.put(childResource, childDelta1);
- }
- if(childDelta1.getKind() !=IResourceDelta.REMOVED){
- recordIllegalChild(childResource.getFullPath(), IResourceDelta.REMOVED, childDelta1.getKind());
- }
- }
-
- for(int i = 0; i < affectedChildren.length; ++i){
- IResourceDelta childDelta1 = affectedChildren[i];
- IResource childResource = childDelta1.getResource();
- IResourceDelta childDelta2 = (IResourceDelta)h.remove(childResource);
- if(childDelta2 == null) {
- int kind = childDelta1.getKind();
- //these kinds should have been added to h earlier
- if (kind == IResourceDelta.ADDED || kind == IResourceDelta.REMOVED || kind == IResourceDelta.CHANGED) {
- recordMissingChild(childResource.getFullPath(), childDelta1.getKind(), false);
- }
- }
- }
-
- Enumeration keys = h.keys();
- while(keys.hasMoreElements()){
- IResource childResource = (IResource)keys.nextElement();
- IResourceDelta childDelta = (IResourceDelta)h.get(childResource);
- recordMissingChild(childResource.getFullPath(), childDelta.getKind(), true);
- }
-
- for(int i = 0; i < affectedChildren.length; ++i){
- internalVerifyDelta(affectedChildren[i]);
- }
-
- keys = h.keys();
- while(keys.hasMoreElements()){
- IResource childResource = (IResource)keys.nextElement();
- IResourceDelta childDelta = (IResourceDelta)h.get(childResource);
- internalVerifyDelta(childDelta);
- }
-}
-private void checkPaths(IResourceDelta delta){
- IResource resource = delta.getResource();
-
- IPath expectedFullPath = resource.getFullPath();
- IPath actualFullPath = delta.getFullPath();
- if(!expectedFullPath.equals(actualFullPath)){
- recordConflictingFullPaths(expectedFullPath, actualFullPath);
- }
-
- IPath expectedProjectRelativePath = resource.getProjectRelativePath();
- IPath actualProjectRelativePath = delta.getProjectRelativePath();
- if(expectedProjectRelativePath != actualProjectRelativePath){
- if(expectedProjectRelativePath == null || !expectedProjectRelativePath.equals(actualProjectRelativePath)){
- recordConflictingProjectRelativePaths(expectedProjectRelativePath, actualProjectRelativePath);
- }
- }
-
- ExpectedChange expectedChange =
- (ExpectedChange)fExpectedChanges.get(resource.getFullPath());
-
- if(expectedChange != null){
- IPath expectedMovedFromPath = expectedChange.getMovedFromPath();
- IPath actualMovedFromPath = delta.getMovedFromPath();
- if(expectedMovedFromPath != actualMovedFromPath){
- if(expectedMovedFromPath == null || !expectedMovedFromPath.equals(actualMovedFromPath)){
- recordConflictingMovedFromPaths(expectedMovedFromPath, actualMovedFromPath);
- }
- }
-
- IPath expectedMovedToPath = expectedChange.getMovedToPath();
- IPath actualMovedToPath = delta.getMovedToPath();
- if(expectedMovedToPath != actualMovedToPath){
- if(expectedMovedToPath == null || !expectedMovedToPath.equals(actualMovedToPath)){
- recordConflictingMovedToPaths(expectedMovedToPath, actualMovedToPath);
- }
- }
- }
-}
-String convertChangeFlags(int changeFlags){
- if (changeFlags == 0) {
- return "0";
- }
- StringBuffer buf = new StringBuffer();
-
- if((changeFlags & IResourceDelta.CONTENT) != 0){
- changeFlags ^= IResourceDelta.CONTENT;
- buf.append("CONTENT | ");
- }
- if((changeFlags & IResourceDelta.MOVED_FROM) != 0){
- changeFlags ^= IResourceDelta.MOVED_FROM;
- buf.append("MOVED_FROM | ");
- }
- if((changeFlags & IResourceDelta.MOVED_TO) != 0){
- changeFlags ^= IResourceDelta.MOVED_TO;
- buf.append("MOVED_TO | ");
- }
- if((changeFlags & IResourceDelta.OPEN) != 0){
- changeFlags ^= IResourceDelta.OPEN;
- buf.append("OPEN | ");
- }
- if((changeFlags & IResourceDelta.TYPE) != 0){
- changeFlags ^= IResourceDelta.TYPE;
- buf.append("TYPE | ");
- }
- if((changeFlags & IResourceDelta.MARKERS) != 0){
- changeFlags ^= IResourceDelta.MARKERS;
- buf.append("MARKERS | ");
- }
- if((changeFlags & IResourceDelta.REPLACED) != 0){
- changeFlags ^= IResourceDelta.REPLACED;
- buf.append("REPLACED | ");
- }
-
- if(changeFlags != 0){
- buf.append(changeFlags);
- buf.append(" | ");
- }
-
- String result = buf.toString();
-
- if(result.length() != 0){
- result = result.substring(0, result.length() - 3);
- }
-
- return result;
-}
-String convertKind(int kind){
- switch(kind){
- case IResourceDelta.ADDED: return "ADDED";
- case IResourceDelta.CHANGED: return "CHANGED";
- case IResourceDelta.REMOVED: return "REMOVED";
- case IResourceDelta.ADDED_PHANTOM: return "ADDED_PHANTOM";
- case IResourceDelta.REMOVED_PHANTOM: return "REMOVED_PHANTOM";
- default: return "Unknown(" + kind + ")";
- }
-}
-/**
- * Called to cleanup internal state and make sure expectations
- * are met after iterating over a resource delta.
- */
-private void finishVerification(){
- Hashtable resourcePaths = new Hashtable();
-
- Enumeration keys = fExpectedChanges.keys();
- while(keys.hasMoreElements()){
- Object key = keys.nextElement();
- resourcePaths.put(key, key);
- }
-
- keys = resourcePaths.keys();
- while(keys.hasMoreElements()){
- IPath resourcePath = (IPath)keys.nextElement();
-
- fMessage.append("Checking expectations for ");
- fMessage.append(resourcePath);
- fMessage.append("\n");
-
- ExpectedChange expectedChange = (ExpectedChange)fExpectedChanges.remove(resourcePath);
- if(expectedChange != null){
- recordMissingActualChange(expectedChange.getKind(), expectedChange.getChangeFlags());
- }
- }
-}
-/**
- * Returns a message that describes the result of the resource
- * delta verification checks.
- */
-public String getMessage(){
- if (fState == RECEIVING_INPUTS) {
- if (hasExpectedChanges()) {
- fail("Verifier has not yet been given a resource delta");
- } else {
- fState = DELTA_VERIFIED;
- }
- }
- if (fState == DELTA_VERIFIED) {
- finishVerification();
- fState = VERIFICATION_COMPLETE;
- }
- return fMessage.toString();
-}
-/**
- * Returns true if this verifier has received a delta notification
- * since the last reset, and false otherwise.
- */
-public boolean hasBeenNotified() {
- return fState == DELTA_VERIFIED;
-}
-/**
- * Returns true if this verifier currently has an expected
- * changes, and false otherwise.
- */
-public boolean hasExpectedChanges() {
- return !fExpectedChanges.isEmpty();
-}
-/**
- * Compares the given delta with the expected changes. Recursively
- * compares child deltas.
- */
-void internalVerifyDelta(IResourceDelta delta){
- try {
- // FIXME: bogus
- if (delta == null)
- return;
- fMessage.append("Verifying delta for ");
- fMessage.append(delta.getFullPath());
- fMessage.append("\n");
-
- /* don't check changes for the workspace */
- if (delta.getResource() != null) {
- checkPaths(delta);
- checkChanges(delta);
- }
- checkChildren(delta);
- } catch (Exception e) {
- e.printStackTrace();
- fMessage.append("Exception during event notification:" + e.getMessage());
- fIsDeltaValid = false;
- }
-}
-/**
- * Returns whether the resource delta passed all verification
- * checks.
- */
-public boolean isDeltaValid(){
- if (fState == RECEIVING_INPUTS) {
- if (hasExpectedChanges()) {
- fail("Verifier has not yet been given a resource delta");
- } else {
- fState = DELTA_VERIFIED;
- }
- }
- if (fState == DELTA_VERIFIED) {
- finishVerification();
- fState = VERIFICATION_COMPLETE;
- }
- return fIsDeltaValid;
-}
-/**
- * Tests message formatting. This main method does not represent the
- * intended use of the ResourceDeltaVerifier. See the class comment
- * for instructions on using the verifier.
- */
-public static void main(String[] args){
- ResourceDeltaVerifier comparer = new ResourceDeltaVerifier();
-
- int status = IResourceDelta.CHANGED;
- int changeFlags = IResourceDelta.CONTENT;
- int expectedStatus = IResourceDelta.CHANGED;
- int actualStatus = IResourceDelta.REMOVED;
- int expectedChangeFlags = IResourceDelta.OPEN;
- int actualChangeFlags = 0;
- int formerChildStatus = expectedStatus;
- int latterChildStatus = actualStatus;
-
- IPath path = new Path("/a/b/c");
- IPath path2 = new Path("/a/b/d");
- IPath expectedFullPath = path;
- IPath actualFullPath = path2;
- IPath expectedMovedFromPath = path;
- IPath actualMovedFromPath = path2;
- IPath expectedMovedToPath = path;
- IPath actualMovedToPath = path2;
- IPath expectedProjectRelativePath = new Path("b/c");
- IPath actualProjectRelativePath = new Path("b/d");
-
- comparer.fMessage.append("Checking delta for ");
- comparer.fMessage.append(path);
- comparer.fMessage.append("\n");
-
- comparer.recordConflictingChange(expectedStatus, actualStatus, expectedChangeFlags, actualChangeFlags);
- comparer.recordConflictingFullPaths(expectedFullPath, actualFullPath);
- comparer.recordConflictingMovedFromPaths(expectedMovedFromPath, actualMovedFromPath);
- comparer.recordConflictingMovedToPaths(expectedMovedToPath, actualMovedToPath);
- comparer.recordConflictingProjectRelativePaths(expectedProjectRelativePath, actualProjectRelativePath);
- comparer.recordDuplicateChild(path, formerChildStatus, latterChildStatus, expectedStatus);
- comparer.recordIllegalChild(path, expectedStatus, actualStatus);
- comparer.recordMissingActualChange(status, changeFlags);
- comparer.recordMissingChild(path, status, true);
- comparer.recordMissingChild(path, status, false);
- comparer.recordMissingExpectedChange(status, changeFlags);
-
- System.out.print(comparer.fMessage.toString());
-}
-private void recordConflictingChange(int expectedKind, int kind, int expectedChangeFlags, int changeFlags){
- fIsDeltaValid = false;
-
- fMessage.append("\tConflicting change\n");
-
- if(expectedKind != kind){
- fMessage.append("\t\tExpected kind: <");
- fMessage.append(convertKind(expectedKind));
- fMessage.append("> actual kind: <");
- fMessage.append(convertKind(kind));
- fMessage.append(">\n");
- }
-
- if(expectedChangeFlags != changeFlags){
- fMessage.append("\t\tExpected change flags: <");
- fMessage.append(convertChangeFlags(expectedChangeFlags));
- fMessage.append("> actual change flags: <");
- fMessage.append(convertChangeFlags(changeFlags));
- fMessage.append(">\n");
- }
-}
-private void recordConflictingFullPaths(IPath expectedFullPath, IPath actualFullPath) {
- fIsDeltaValid = false;
-
- fMessage.append("\tConflicting full paths\n");
-
- fMessage.append("\t\tExpected full path: ");
- fMessage.append(expectedFullPath);
- fMessage.append("\n");
-
- fMessage.append("\t\tActual full path: ");
- fMessage.append(actualFullPath);
- fMessage.append("\n");
-}
-private void recordConflictingMovedFromPaths(IPath expectedMovedFromPath, IPath actualMovedFromPath) {
- fIsDeltaValid = false;
-
- fMessage.append("\tConflicting moved from paths\n");
-
- fMessage.append("\t\tExpected moved from path: ");
- fMessage.append(expectedMovedFromPath);
- fMessage.append("\n");
-
- fMessage.append("\t\tActual moved from path: ");
- fMessage.append(actualMovedFromPath);
- fMessage.append("\n");
-}
-private void recordConflictingMovedToPaths(IPath expectedMovedToPath, IPath actualMovedToPath) {
- fIsDeltaValid = false;
-
- fMessage.append("\tConflicting moved to paths\n");
-
- fMessage.append("\t\tExpected moved to path: ");
- fMessage.append(expectedMovedToPath);
- fMessage.append("\n");
-
- fMessage.append("\t\tActual moved to path: ");
- fMessage.append(actualMovedToPath);
- fMessage.append("\n");
-}
-private void recordConflictingProjectRelativePaths(IPath expectedProjectRelativePath, IPath actualProjectRelativePath) {
- fIsDeltaValid = false;
-
- fMessage.append("\tConflicting project relative paths\n");
-
- fMessage.append("\t\tExpected project relative path: ");
- fMessage.append(expectedProjectRelativePath);
- fMessage.append("\n");
-
- fMessage.append("\t\tActual project relative path: ");
- fMessage.append(actualProjectRelativePath);
- fMessage.append("\n");
-}
-private void recordDuplicateChild(IPath path, int formerChildKind, int latterChildKind, int expectedKind){
- fIsDeltaValid = false;
-
- fMessage.append("\tDuplicate child: ");
- fMessage.append(path);
- fMessage.append("\n");
-
- fMessage.append("\t\tProduced by IResourceDelta.get");
-
- switch(expectedKind){
- case IResourceDelta.ADDED: fMessage.append("Added"); break;
- case IResourceDelta.CHANGED: fMessage.append("Changed"); break;
- case IResourceDelta.REMOVED: fMessage.append("Removed"); break;
- }
-
- fMessage.append("Children()\n");
-
- fMessage.append("\t\tFormer child's status: ");
- fMessage.append(convertKind(formerChildKind));
- fMessage.append("\n");
-
- fMessage.append("\t\tLatter child's status: ");
- fMessage.append(convertKind(latterChildKind));
- fMessage.append("\n");
-}
-private void recordIllegalChild(IPath path, int expectedKind, int actualKind){
- fIsDeltaValid = false;
-
- fMessage.append("\tIllegal child: ");
- fMessage.append(path);
- fMessage.append("\n");
-
- fMessage.append("\t\tProduced by IResourceDelta.get");
-
- switch(expectedKind){
- case IResourceDelta.ADDED: fMessage.append("Added"); break;
- case IResourceDelta.CHANGED: fMessage.append("Changed"); break;
- case IResourceDelta.REMOVED: fMessage.append("Removed"); break;
- }
-
- fMessage.append("Children()\n");
-
- fMessage.append("\t\tIlleagal child's status: ");
- fMessage.append(convertKind(actualKind));
- fMessage.append("\n");
-}
-private void recordMissingActualChange(int kind, int changeFlags){
- fIsDeltaValid = false;
-
- fMessage.append("\tMissing actual change\n");
- fMessage.append("\t\tExpected kind: <");
- fMessage.append(convertKind(kind));
- fMessage.append(">\n");
- fMessage.append("\t\tExpected change flags: <");
- fMessage.append(convertChangeFlags(changeFlags));
- fMessage.append(">\n");
-}
-private void recordMissingChild(IPath path, int kind, boolean isMissingFromAffectedChildren){
- fIsDeltaValid = false;
-
- fMessage.append("\tMissing child: ");
- fMessage.append(path);
- fMessage.append("\n");
-
- fMessage.append("\t\tfrom IResourceDelta.getAffectedChildren(");
-
- if (!isMissingFromAffectedChildren) {
- switch(kind) {
- case IResourceDelta.ADDED: fMessage.append("ADDED"); break;
- case IResourceDelta.CHANGED: fMessage.append("CHANGED"); break;
- case IResourceDelta.REMOVED: fMessage.append("REMOVED"); break;
- default: fMessage.append(kind);
- }
- }
-
- fMessage.append(")\n");
-}
-private void recordMissingExpectedChange(int kind, int changeFlags){
- fIsDeltaValid = false;
-
- fMessage.append("\tMissing expected change\n");
- fMessage.append("\t\tActual kind: <");
- fMessage.append(convertKind(kind));
- fMessage.append(">\n");
- fMessage.append("\t\tActual change flags: <");
- fMessage.append(convertChangeFlags(changeFlags));
- fMessage.append(">\n");
-}
-/**
- * Resets the listener to its initial state.
- */
-public void reset(){
- fExpectedChanges.clear();
- fIsDeltaValid = true;
- fMessage.setLength(0);
- fState = RECEIVING_INPUTS;
-}
-private void resetIfNecessary(){
- if(fState == DELTA_VERIFIED){
- reset();
- }
-}
-/**
- * Part of the <code>IResourceChangedListener</code> interface.
- * @see IResourceChangedListener
- */
-public void resourceChanged(IResourceChangeEvent e){
- verifyDelta(e.getDelta());
-}
-/**
- * Compares the given delta with the expected changes. Recursively
- * compares child deltas.
- */
-public void verifyDelta(IResourceDelta delta){
- internalVerifyDelta(delta);
- fState = DELTA_VERIFIED;
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceMappingTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceMappingTest.java
deleted file mode 100644
index 9ef6e38..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceMappingTest.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.resources.Workspace;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-/**
- * Tests use of IResourceMappings on projects.
- */
-public class ResourceMappingTest extends EclipseWorkspaceTest {
-public ResourceMappingTest() {
- super();
-}
-public ResourceMappingTest(String name) {
- super(name);
-}
-public static Test suite() {
- return new TestSuite(ResourceMappingTest.class);
-}
-/**
- * Tests the location of mapped resources.
- */
-public void testResourceLocation() {
- assertTrue("not yet implemented", false);
- //create some common resources
- IProject project = getWorkspace().getRoot().getProject("Project1");
- IFolder mappedFolder = project.getFolder("Folder1");
- IFolder unmappedFolder = project.getFolder("Folder2");
- IFolder folderInMappedFolder = mappedFolder.getFolder("Folder3");
- IFile fileInMappedFolder = mappedFolder.getFile("File1");
- IFile fileInUnmappedFolder = unmappedFolder.getFile("File2");
- IFile mappedFile = project.getFile("File3");
- IFile unmappedFile = project.getFile("File4");
- IResource[] allResources= new IResource[] {project, mappedFolder, unmappedFolder,
- folderInMappedFolder, fileInMappedFolder, fileInUnmappedFolder, mappedFile, unmappedFile};
-
- //Scenario 1: project in default area with no mappings
- ensureExistsInWorkspace(allResources, true);
- for (int i = 0; i < allResources.length; i++) {
- assertEquals("1." + i, Platform.getLocation().append(allResources[i].getFullPath()), allResources[i].getLocation());
- }
- ensureDoesNotExistInWorkspace(allResources);
-
- //Scenario 2: project in default area, mapped resources
- IProjectDescription description = getWorkspace().newProjectDescription(project.getName());
- IPath folderLocation = getRandomLocation();
- IPath fileLocation = getRandomLocation();
-// description.addMapping(description.newMapping(mappedFolder.getName(), folderLocation));
-// description.addMapping(description.newMapping(mappedFile.getName(), fileLocation));
- try {
- project.create(description, getMonitor());
- project.open(getMonitor());
- ensureExistsInWorkspace(allResources, true);
-
- assertEquals("2.1", Platform.getLocation().append(project.getName()), project.getLocation());
- assertEquals("2.2", folderLocation, mappedFolder.getLocation());
- assertEquals("2.3", project.getLocation().append(unmappedFolder.getName()), unmappedFolder.getLocation());
- assertEquals("2.4", folderLocation.append(folderInMappedFolder.getName()), folderInMappedFolder.getLocation());
- assertEquals("2.5", folderLocation.append(fileInMappedFolder.getName()), fileInMappedFolder.getLocation());
- assertEquals("2.6", fileLocation, mappedFile.getLocation());
- assertEquals("2.7", project.getLocation().append(unmappedFile.getName()), unmappedFile.getLocation());
- } catch (CoreException e) {
- fail ("2.99", e);
- } finally {
- Workspace.clear(folderLocation.toFile());
- Workspace.clear(fileLocation.toFile());
- }
- ensureDoesNotExistInWorkspace(allResources);
-
- //Scenario 3: project in custom area, no mappings
- description = getWorkspace().newProjectDescription(project.getName());
- IPath projectLocation = getRandomLocation();
- description.setLocation(projectLocation);
- try {
- project.create(description, getMonitor());
- project.open(getMonitor());
- ensureExistsInWorkspace(allResources, true);
- for (int i = 0; i < allResources.length; i++) {
- assertEquals("3." + i,
- projectLocation.append(allResources[i].getProjectRelativePath()),
- allResources[i].getLocation());
- }
- } catch (CoreException e) {
- fail ("3.99", e);
- } finally {
- Workspace.clear(projectLocation.toFile());
- }
- ensureDoesNotExistInWorkspace(allResources);
-
- //Scenario 4: project in custom area, mapped resources
- description = getWorkspace().newProjectDescription(project.getName());
- projectLocation = getRandomLocation();
- folderLocation = getRandomLocation();
- fileLocation = getRandomLocation();
- description.setLocation(projectLocation);
-// description.addMapping(description.newMapping(mappedFolder.getName(), folderLocation));
-// description.addMapping(description.newMapping(mappedFile.getName(), fileLocation));
- try {
- project.create(description, getMonitor());
- project.open(getMonitor());
- ensureExistsInWorkspace(allResources, true);
-
- assertEquals("2.1", projectLocation, project.getLocation());
- assertEquals("2.2", folderLocation, mappedFolder.getLocation());
- assertEquals("2.3", projectLocation.append(unmappedFolder.getName()), unmappedFolder.getLocation());
- assertEquals("2.4", folderLocation.append(folderInMappedFolder.getName()), folderInMappedFolder.getLocation());
- assertEquals("2.5", folderLocation.append(fileInMappedFolder.getName()), fileInMappedFolder.getLocation());
- assertEquals("2.6", fileLocation, mappedFile.getLocation());
- assertEquals("2.7", projectLocation.append(unmappedFile.getName()), unmappedFile.getLocation());
- } catch (CoreException e) {
- fail ("4.99", e);
- } finally {
- Workspace.clear(projectLocation.toFile());
- Workspace.clear(folderLocation.toFile());
- Workspace.clear(fileLocation.toFile());
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceURLTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceURLTest.java
deleted file mode 100644
index 3d44618..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceURLTest.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.*;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-public class ResourceURLTest extends EclipseWorkspaceTest {
- static boolean noSideEffects = false;
- protected static IResource[] interestingResources;
- protected static Set nonExistingResources = new HashSet();
- protected static Map unsynchronizedResources = new HashMap();
- protected static IPath[] interestingPaths;
-
-/**
- * Need a zero argument constructor to satisfy the test harness.
- * This constructor should not do any real work nor should it be
- * called by user code.
- */
-public ResourceURLTest() {
-}
-public ResourceURLTest(String name) {
- super(name);
-}
-
-public void cleanup() throws Throwable {
- getWorkspace().getRoot().delete(true, true, null);
-}
-
-/**
- * Returns a collection of string paths describing the standard
- * resource hierarchy for this test. In the string forms, folders are
- * represented as having trailing separators ('/'). All other resources
- * are files. It is generally assumed that this hierarchy will be
- * inserted under some solution and project structure.
- */
-public String[] defineHierarchy() {
- return new String[] {"/", "/1/", "/1/1", "/1/2", "/1/3", "/2/", "/2/1", "/2/2", "/2/3", "/3/", "/3/1", "/3/2", "/3/3", "/4/", "/5"};
-}
-protected IProject getTestProject() {
- return getWorkspace().getRoot().getProject("testProject");
-}
-protected IProject getTestProject2() {
- return getWorkspace().getRoot().getProject("testProject2");
-}
-
-public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(new ResourceURLTest("testNonExistantURLs"));
- suite.addTest(new ResourceURLTest("testBasicURLs"));
- suite.addTest(new ResourceURLTest("testExternalURLs"));
- suite.addTest(new ResourceURLTest("cleanup"));
- return suite;
-}
-protected void tearDown() throws Exception {
- // overwrite the superclass and do nothing since our test methods build on each other
-}
-
-private URL getURL(IPath path) throws Throwable {
- return new URL("platform:/resource" + path.makeAbsolute().toString());
-}
-private URL getURL(IResource resource) throws Throwable {
- return getURL(resource.getFullPath());
-}
-
-private void checkURL(IResource resource) throws Throwable {
- URL url = getURL(resource);
- String file = new Path(Platform.resolve(url).getFile()).toString();
- String metric = resource.getLocation().toString();
- assertEquals(file, metric);
-}
-public void testBasicURLs() throws Throwable {
- IResource[] resources = buildResources();
- ensureExistsInWorkspace(resources, true);
- for (int i = 0; i < resources.length; i++) {
- checkURL(resources[i]);
- }
-}
-public void testNonExistantURLs() throws Throwable {
- IResource[] resources = buildResources();
- for (int i = 1; i < resources.length; i++) {
- try {
- checkURL(resources[i]);
- fail("1.0");
- } catch (IOException e) {
- }
- }
-}
-public void testExternalURLs() throws Throwable {
- IProject project = getWorkspace().getRoot().getProject("test");
- IProjectDescription desc = getWorkspace().newProjectDescription("test");
- desc.setLocation(Platform.getLocation().append("../testproject"));
- project.create(desc, null);
- project.open(null);
- IResource[] resources = buildResources(project, defineHierarchy());
- ensureExistsInWorkspace(resources, true);
- for (int i = 0; i < resources.length; i++) {
- checkURL(resources[i]);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceVisitorVerifier.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceVisitorVerifier.java
deleted file mode 100644
index d1fe13b..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/ResourceVisitorVerifier.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import java.util.*;
-import junit.framework.Assert;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IResourceVisitor;
-import org.eclipse.core.runtime.CoreException;
-
-public class ResourceVisitorVerifier extends Assert implements IResourceVisitor {
- Set expected;
- StringBuffer message;
- boolean success = true;
- boolean verified = false;
-public ResourceVisitorVerifier() {
- super();
- reset();
-}
-public void addExpected(IResource resource) {
- expected.add(resource);
-}
-public void addExpected(IResource[] resources) {
- for (int i=0; i<resources.length; i++)
- expected.add(resources[i]);
-}
-public boolean visit(IResource resource) throws CoreException {
- boolean included = expected.remove(resource);
- if (!included) {
- success = false;
- log(resource.getFullPath() + " was not expected.");
- }
- return true;
-}
-private void log(String text) {
- message.append("\n" + text);
-}
-private void verify() {
- if (verified)
- return;
- // Add messages for the resources which weren't visited but were expected.
- for (Iterator i=expected.iterator(); i.hasNext();) {
- success = false;
- log(((IResource) i.next()).getFullPath() + " was not visited.");
- }
- verified = true;
-}
-public boolean isValid() {
- verify();
- return success;
-}
-public String getMessage() {
- return message.toString();
-}
-public void reset() {
- expected = new HashSet();
- message = new StringBuffer();
- verified = false;
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/TeamPrivateMemberTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/TeamPrivateMemberTest.java
deleted file mode 100644
index 0bbdaf7..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/TeamPrivateMemberTest.java
+++ /dev/null
@@ -1,813 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-public class TeamPrivateMemberTest extends EclipseWorkspaceTest {
-public TeamPrivateMemberTest() {
-}
-public TeamPrivateMemberTest(String name) {
- super(name);
-}
-public static Test suite() {
- return new TestSuite(TeamPrivateMemberTest.class);
-}
-
-public void testRefreshLocal() {
- IWorkspaceRoot root = getWorkspace().getRoot();
- IProject project = root.getProject("MyProject");
- IFolder folder = project.getFolder("folder");
- IFile file = project.getFile("file.txt");
- IFile subFile = folder.getFile("subfile.txt");
- IResource[] resources = new IResource[] {project, folder, file, subFile};
- ensureExistsInWorkspace(resources, true);
-
- ResourceDeltaVerifier listener = new ResourceDeltaVerifier();
- listener.addExpectedChange(subFile, IResourceDelta.CHANGED, IResourceDelta.CONTENT);
- getWorkspace().addResourceChangeListener(listener);
- try {
- setTeamPrivateMember("3.0", folder, true, IResource.DEPTH_ZERO);
- ensureOutOfSync(subFile);
- try {
- project.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- assertTrue(listener.getMessage(), listener.isDeltaValid());
- } catch(CoreException e) {
- fail("3.1", e);
- }
- } finally {
- getWorkspace().removeResourceChangeListener(listener);
- }
-}
-/**
- * Resources which are marked as team private members should always be found.
- */
-public void testFindMember() {
- IWorkspaceRoot root = getWorkspace().getRoot();
- IProject project = root.getProject("MyProject");
- IFolder folder = project.getFolder("folder");
- IFile file = project.getFile("file.txt");
- IFile subFile = folder.getFile("subfile.txt");
- IResource[] resources = new IResource[] {project, folder, file, subFile};
- ensureExistsInWorkspace(resources, true);
-
- // no team private members
- assertEquals("1.0", project, root.findMember(project.getFullPath()));
- assertEquals("1.1", folder, root.findMember(folder.getFullPath()));
- assertEquals("1.2", file, root.findMember(file.getFullPath()));
- assertEquals("1.3", subFile, root.findMember(subFile.getFullPath()));
-
- // the folder is team private
- setTeamPrivateMember("2.0", folder, true, IResource.DEPTH_ZERO);
- assertEquals("2.1", project, root.findMember(project.getFullPath()));
- assertEquals("2.2", folder, root.findMember(folder.getFullPath()));
- assertEquals("2.3", file, root.findMember(file.getFullPath()));
- assertEquals("2.4", subFile, root.findMember(subFile.getFullPath()));
-
- // all are team private
- setTeamPrivateMember("3.0", project, true, IResource.DEPTH_INFINITE);
- assertEquals("3.1", project, root.findMember(project.getFullPath()));
- assertEquals("3.2", folder, root.findMember(folder.getFullPath()));
- assertEquals("3.3", file, root.findMember(file.getFullPath()));
- assertEquals("3.4", subFile, root.findMember(subFile.getFullPath()));
-}
-/**
- * Resources which are marked as team private members are not included in #members
- * calls unless specifically included by calling #members(IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS)
- */
-public void testMembers() {
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- IFolder folder = project.getFolder("folder");
- IFile file = project.getFile("file.txt");
- IFile subFile = folder.getFile("subfile.txt");
- IResource[] resources = new IResource[] {project, folder, file, subFile};
- IResource[] members = null;
- ensureExistsInWorkspace(resources, true);
-
- // Initial values should be false.
- assertTeamPrivateMember("1.0", project, false, IResource.DEPTH_INFINITE);
-
- // Check the calls to #members
- try {
- members = project.members();
- } catch(CoreException e) {
- fail("2.0", e);
- }
- // +1 for the project description file
- assertEquals("2.1", 3, members.length);
- try {
- members = folder.members();
- } catch(CoreException e) {
- }
- assertEquals("2.3", 1, members.length);
-
- // Set the values.
- setTeamPrivateMember("3.0", project, true, IResource.DEPTH_INFINITE);
- assertTeamPrivateMember("3.1", project, true, IResource.DEPTH_INFINITE);
-
- // Check the values
- assertTeamPrivateMember("4.0", project, true, IResource.DEPTH_INFINITE);
-
- // Check the calls to #members
- try {
- members = project.members();
- } catch(CoreException e) {
- fail("5.0", e);
- }
- assertEquals("5.1", 0, members.length);
- try {
- members = folder.members();
- } catch(CoreException e) {
- fail("5.2", e);
- }
- assertEquals("5.3", 0, members.length);
-
- // FIXME: add the tests for #members(int)
-
- // reset to false
- setTeamPrivateMember("6.0", project, false, IResource.DEPTH_INFINITE);
- assertTeamPrivateMember("6.1", project, false, IResource.DEPTH_INFINITE);
-
- // Check the calls to members(IResource.NONE);
- try {
- members = project.members(IResource.NONE);
- } catch(CoreException e) {
- fail("7.0", e);
- }
- // +1 for the project description file
- assertEquals("7.1", 3, members.length);
- try {
- members = project.members(IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
- } catch(CoreException e) {
- fail("7.2", e);
- }
- // +1 for the project description file
- assertEquals("7.3", 3, members.length);
- try {
- members = folder.members();
- } catch (CoreException e) {
- fail("7.4", e);
- }
- assertEquals("7.5", 1, members.length);
-
- // Set one of the children to be TEAM_PRIVATE and try again
- setTeamPrivateMember("8.0", folder, true, IResource.DEPTH_ZERO);
- try {
- members = project.members();
- } catch(CoreException e) {
- fail("8.1", e);
- }
- // +1 for project description, -1 for team private folder
- assertEquals("8.2", 2, members.length);
- try {
- members = folder.members();
- } catch(CoreException e) {
- fail("8.3", e);
- }
- assertEquals("8.4", 1, members.length);
- try {
- members = project.members(IResource.NONE);
- } catch(CoreException e) {
- fail("8.5", e);
- }
- // +1 for project description, -1 for team private folder
- assertEquals("8.6", 2, members.length);
- try {
- members = folder.members();
- } catch(CoreException e) {
- fail("8.7", e);
- }
- assertEquals("8.8", 1, members.length);
- try {
- members = project.members(IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
- } catch(CoreException e) {
- fail("8.9", e);
- }
- // +1 for project description
- assertEquals("8.10", 3, members.length);
- try {
- members = folder.members();
- } catch(CoreException e) {
- fail("8.11", e);
- }
- assertEquals("8.12", 1, members.length);
-
- // Set all the resources to be team private
- setTeamPrivateMember("9.0", project, true, IResource.DEPTH_INFINITE);
- assertTeamPrivateMember("9.1", project, true, IResource.DEPTH_INFINITE);
- try {
- members = project.members(IResource.NONE);
- } catch(CoreException e) {
- fail("9.2", e);
- }
- assertEquals("9.3", 0, members.length);
- try {
- members = folder.members(IResource.NONE);
- } catch(CoreException e) {
- fail("9.4", e);
- }
- assertEquals("9.5", 0, members.length);
- try {
- members = project.members(IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
- } catch(CoreException e) {
- fail("9.6", e);
- }
- // +1 for project description
- assertEquals("9.7", 3, members.length);
- try {
- members = folder.members(IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
- } catch(CoreException e) {
- fail("9.8", e);
- }
- assertEquals("9.9", 1, members.length);
-}
-/**
- * Test to ensure that team private values are persisted across project close/open.
- */
-public void testProjectCloseOpen() {
- // FIXME:
-}
-/**
- * Resources which are marked as team private members should not be visited by
- * resource visitors.
- */
-public void testAccept() {
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- IFolder folder = project.getFolder("folder");
- IFile file = project.getFile("file.txt");
- IFile subFile = folder.getFile("subfile.txt");
- IResource[] resources = new IResource[] {project, folder, file, subFile};
- ensureExistsInWorkspace(resources, true);
- IResource description = project.getFile(IProjectDescription.DESCRIPTION_FILE_NAME);
-
- // default case, no team private members
- ResourceVisitorVerifier visitor = new ResourceVisitorVerifier();
- visitor.addExpected(resources);
- visitor.addExpected(description);
- try {
- project.accept(visitor);
- } catch(CoreException e) {
- fail("1.0", e);
- }
- assertTrue("1.1." + visitor.getMessage(), visitor.isValid());
-
- visitor.reset();
- visitor.addExpected(resources);
- visitor.addExpected(description);
- try {
- project.accept(visitor, IResource.DEPTH_INFINITE, IResource.NONE);
- } catch(CoreException e) {
- fail("1.2", e);
- }
- assertTrue("1.3." + visitor.getMessage(), visitor.isValid());
-
- visitor.reset();
- visitor.addExpected(resources);
- visitor.addExpected(description);
- try {
- project.accept(visitor, IResource.DEPTH_INFINITE, IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
- } catch(CoreException e) {
- fail("1.4", e);
- }
- assertTrue("1.5." + visitor.getMessage(), visitor.isValid());
-
- // set the folder to be team private. It and its children should
- // be ignored by the visitor
- setTeamPrivateMember("2.0", folder, true, IResource.DEPTH_ZERO);
- visitor.reset();
- visitor.addExpected(project);
- visitor.addExpected(file);
- visitor.addExpected(description);
- try {
- project.accept(visitor);
- } catch(CoreException e) {
- fail("2.1", e);
- }
- assertTrue("2.2." + visitor.getMessage(), visitor.isValid());
-
- visitor.reset();
- visitor.addExpected(project);
- visitor.addExpected(file);
- visitor.addExpected(description);
- try {
- project.accept(visitor, IResource.DEPTH_INFINITE, IResource.NONE);
- } catch(CoreException e) {
- fail("2.3", e);
- }
- assertTrue("2.4." + visitor.getMessage(), visitor.isValid());
- // should see all resources if we include the flag
- visitor.reset();
- visitor.addExpected(resources);
- visitor.addExpected(description);
- try {
- project.accept(visitor, IResource.DEPTH_INFINITE, IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
- } catch(CoreException e) {
- fail("2.5", e);
- }
- assertTrue("2.6." + visitor.getMessage(), visitor.isValid());
- // should NOT visit the folder and its members if we call accept on it directly
- visitor.reset();
- try {
- folder.accept(visitor);
- } catch(CoreException e) {
- fail("2.7", e);
- }
- assertTrue("2.8." + visitor.getMessage(), visitor.isValid());
-
- visitor.reset();
- try {
- folder.accept(visitor, IResource.DEPTH_INFINITE, IResource.NONE);
- } catch(CoreException e) {
- fail("2.9", e);
- }
- assertTrue("2.10." + visitor.getMessage(), visitor.isValid());
-
- visitor.reset();
- visitor.addExpected(folder);
- visitor.addExpected(subFile);
- try {
- folder.accept(visitor, IResource.DEPTH_INFINITE, IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
- } catch(CoreException e) {
- fail("2.11", e);
- }
- assertTrue("2.11." + visitor.getMessage(), visitor.isValid());
-
- // now set all file/folder resources to be team private.
- setTeamPrivateMember("3.0", project, true, IResource.DEPTH_INFINITE);
- assertTeamPrivateMember("3.1", project, true, IResource.DEPTH_INFINITE);
- visitor.reset();
- // projects are never team private
- visitor.addExpected(project);
- try {
- project.accept(visitor);
- } catch(CoreException e) {
- fail("3.2", e);
- }
- assertTrue("3.3." + visitor.getMessage(), visitor.isValid());
-
- visitor.reset();
- visitor.addExpected(project);
- try {
- project.accept(visitor, IResource.DEPTH_INFINITE, IResource.NONE);
- } catch(CoreException e) {
- fail("3.4", e);
- }
- assertTrue("3.5." + visitor.getMessage(), visitor.isValid());
- // should see all resources if we include the flag
- visitor.reset();
- visitor.addExpected(resources);
- visitor.addExpected(description);
- try {
- project.accept(visitor, IResource.DEPTH_INFINITE, IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
- } catch(CoreException e) {
- fail("3.6", e);
- }
- assertTrue("3.7." + visitor.getMessage(), visitor.isValid());
-}
-public void testCopy() {
- IWorkspaceRoot root = getWorkspace().getRoot();
- IProject project = root.getProject("MyProject");
- IFolder folder = project.getFolder("folder");
- IFile file = project.getFile("file.txt");
- IFile subFile = folder.getFile("subfile.txt");
- IResource[] resources = new IResource[] {project, folder, file, subFile};
- ensureExistsInWorkspace(resources, true);
-
- // handles to the destination resources
- IProject destProject = root.getProject("MyOtherProject");
- IFolder destFolder = destProject.getFolder(folder.getName());
- IFile destFile = destProject.getFile(file.getName());
- IFile destSubFile = destFolder.getFile(subFile.getName());
- IResource[] destResources = new IResource[] {destProject, destFolder, destFile, destSubFile};
- ensureDoesNotExistInWorkspace(destResources);
-
- // set a folder to be team private
- setTeamPrivateMember("1.0", folder, true, IResource.DEPTH_ZERO);
- // copy the project
- int flags = IResource.FORCE;
- try {
- project.copy(destProject.getFullPath(), flags, getMonitor());
- } catch(CoreException e) {
- fail("1.1", e);
- }
- assertExistsInWorkspace("1.2", resources);
- assertExistsInWorkspace("1.3", destResources);
-
- // Do it again and but just copy the folder
- ensureDoesNotExistInWorkspace(destResources);
- ensureExistsInWorkspace(resources, true);
- ensureExistsInWorkspace(destProject, true);
- setTeamPrivateMember("2.0", folder, true, IResource.DEPTH_ZERO);
- try {
- folder.copy(destFolder.getFullPath(), flags, getMonitor());
- } catch(CoreException e) {
- fail("2.1", e);
- }
- assertExistsInWorkspace("2.2", new IResource[] {folder, subFile});
- assertExistsInWorkspace("2.3", new IResource[] {destFolder, destSubFile});
-
- // set all the resources to be team private
- // copy the project
- ensureDoesNotExistInWorkspace(destResources);
- ensureExistsInWorkspace(resources, true);
- setTeamPrivateMember("3.0", project, true, IResource.DEPTH_INFINITE);
- try {
- project.copy(destProject.getFullPath(), flags, getMonitor());
- } catch(CoreException e) {
- fail("3.1", e);
- }
- assertExistsInWorkspace("3.2", resources);
- assertExistsInWorkspace("3.3", destResources);
-
- // do it again but only copy the folder
- ensureDoesNotExistInWorkspace(destResources);
- ensureExistsInWorkspace(resources, true);
- ensureExistsInWorkspace(destProject, true);
- setTeamPrivateMember("4.0", project, true, IResource.DEPTH_INFINITE);
- try {
- folder.copy(destFolder.getFullPath(), flags, getMonitor());
- } catch(CoreException e) {
- fail("4.1", e);
- }
- assertExistsInWorkspace("4.2", new IResource[] {folder, subFile});
- assertExistsInWorkspace("4.3", new IResource[] {destFolder, destSubFile});
-}
-public void testMove() {
- IWorkspaceRoot root = getWorkspace().getRoot();
- IProject project = root.getProject("MyProject");
- IFolder folder = project.getFolder("folder");
- IFile file = project.getFile("file.txt");
- IFile subFile = folder.getFile("subfile.txt");
- IResource[] resources = new IResource[] {project, folder, file, subFile};
- ensureExistsInWorkspace(resources, true);
-
- // handles to the destination resources
- IProject destProject = root.getProject("MyOtherProject");
- IFolder destFolder = destProject.getFolder(folder.getName());
- IFile destFile = destProject.getFile(file.getName());
- IFile destSubFile = destFolder.getFile(subFile.getName());
- IResource[] destResources = new IResource[] {destProject, destFolder, destFile, destSubFile};
- ensureDoesNotExistInWorkspace(destResources);
-
- // set a folder to be team private
- setTeamPrivateMember("1.0", folder, true, IResource.DEPTH_ZERO);
- // move the project
- int flags = IResource.FORCE;
- try {
- project.move(destProject.getFullPath(), flags, getMonitor());
- } catch(CoreException e) {
- fail("1.1", e);
- }
- assertDoesNotExistInWorkspace("1.2", resources);
- assertExistsInWorkspace("1.3", destResources);
-
- // Do it again and but just move the folder
- ensureDoesNotExistInWorkspace(destResources);
- ensureExistsInWorkspace(resources, true);
- ensureExistsInWorkspace(destProject, true);
- setTeamPrivateMember("2.0", folder, true, IResource.DEPTH_ZERO);
- try {
- folder.move(destFolder.getFullPath(), flags, getMonitor());
- } catch(CoreException e) {
- fail("2.1", e);
- }
- assertDoesNotExistInWorkspace("2.2", new IResource[] {folder, subFile});
- assertExistsInWorkspace("2.3", new IResource[] {destFolder, destSubFile});
-
- // set all the resources to be team private
- // move the project
- ensureDoesNotExistInWorkspace(destResources);
- ensureExistsInWorkspace(resources, true);
- setTeamPrivateMember("3.0", project, true, IResource.DEPTH_INFINITE);
- try {
- project.move(destProject.getFullPath(), flags, getMonitor());
- } catch(CoreException e) {
- fail("3.1", e);
- }
- assertDoesNotExistInWorkspace("3.2", resources);
- assertExistsInWorkspace("3.3", destResources);
-
- // do it again but only move the folder
- ensureDoesNotExistInWorkspace(destResources);
- ensureExistsInWorkspace(resources, true);
- ensureExistsInWorkspace(destProject, true);
- setTeamPrivateMember("4.0", project, true, IResource.DEPTH_INFINITE);
- try {
- folder.move(destFolder.getFullPath(), flags, getMonitor());
- } catch(CoreException e) {
- fail("4.1", e);
- }
- assertDoesNotExistInWorkspace("4.2", new IResource[] {folder, subFile});
- assertExistsInWorkspace("4.3", new IResource[] {destFolder, destSubFile});
-}
-public void testDelete() {
- IWorkspaceRoot root = getWorkspace().getRoot();
- IProject project = root.getProject("MyProject");
- IFolder folder = project.getFolder("folder");
- IFile file = project.getFile("file.txt");
- IFile subFile = folder.getFile("subfile.txt");
- IResource[] resources = new IResource[] {project, folder, file, subFile};
- ensureExistsInWorkspace(resources, true);
-
- // default behaviour with no team private members
- int flags = IResource.ALWAYS_DELETE_PROJECT_CONTENT | IResource.FORCE;
- // delete the project
- try {
- project.delete(flags, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
- assertDoesNotExistInWorkspace("1.1", resources);
- // delete a file
- ensureExistsInWorkspace(resources, true);
- try {
- file.delete(flags, getMonitor());
- } catch (CoreException e) {
- fail("1.2", e);
- }
- assertDoesNotExistInWorkspace("1.3", file);
- assertExistsInWorkspace("1.4", new IResource[] {project, folder, subFile});
- // delete a folder
- ensureExistsInWorkspace(resources, true);
- try {
- folder.delete(flags, getMonitor());
- } catch(CoreException e) {
- fail("1.5", e);
- }
- assertDoesNotExistInWorkspace("1.6", new IResource[] {folder, subFile});
- assertExistsInWorkspace("1.7", new IResource[] {project, file});
-
- // set one child to be team private
- ensureExistsInWorkspace(resources, true);
- setTeamPrivateMember("2.0", folder, true, IResource.DEPTH_ZERO);
- // delete the project
- try {
- project.delete(flags, getMonitor());
- } catch (CoreException e) {
- fail("2.1", e);
- }
- assertDoesNotExistInWorkspace("2.2", resources);
- // delete a folder
- ensureExistsInWorkspace(resources, true);
- setTeamPrivateMember("2.3", folder, true, IResource.DEPTH_ZERO);
- try {
- folder.delete(flags, getMonitor());
- } catch(CoreException e) {
- fail("2.4", e);
- }
- assertDoesNotExistInWorkspace("2.5", new IResource[] {folder, subFile});
- assertExistsInWorkspace("2.6", new IResource[] {project, file});
-
- // set all resources to be team private
- ensureExistsInWorkspace(resources, true);
- setTeamPrivateMember("3.0", project, true, IResource.DEPTH_INFINITE);
- // delete the project
- try {
- project.delete(flags, getMonitor());
- } catch (CoreException e) {
- fail("3.1", e);
- }
- assertDoesNotExistInWorkspace("3.2", resources);
- // delete a file
- ensureExistsInWorkspace(resources, true);
- setTeamPrivateMember("3.3", project, true, IResource.DEPTH_INFINITE);
- try {
- file.delete(flags, getMonitor());
- } catch (CoreException e) {
- fail("3.4", e);
- }
- assertDoesNotExistInWorkspace("3.5", file);
- assertExistsInWorkspace("3.6", new IResource[] {project, folder, subFile});
- // delete a folder
- ensureExistsInWorkspace(resources, true);
- setTeamPrivateMember("3.7", project, true, IResource.DEPTH_INFINITE);
- try {
- folder.delete(flags, getMonitor());
- } catch(CoreException e) {
- fail("3.8", e);
- }
- assertDoesNotExistInWorkspace("3.9", new IResource[] {folder, subFile});
- assertExistsInWorkspace("3.10", new IResource[] {project, file});
-}
-
-public void testDeltas() {
- IWorkspaceRoot root = getWorkspace().getRoot();
- final IProject project = root.getProject("MyProject");
- final IFolder folder = project.getFolder("folder");
- IFile file = project.getFile("file.txt");
- IFile subFile = folder.getFile("subfile.txt");
- IFile description = project.getFile(IProjectDescription.DESCRIPTION_FILE_NAME);
- final IResource[] resources = new IResource[] {project, folder, file, subFile};
-
- final ResourceDeltaVerifier listener = new ResourceDeltaVerifier();
- getWorkspace().addResourceChangeListener(listener);
- try {
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- ensureExistsInWorkspace(resources, true);
- }
- };
- try {
- listener.addExpectedChange(resources, IResourceDelta.ADDED, IResource.NONE);
- listener.addExpectedChange(project, IResourceDelta.ADDED, IResourceDelta.OPEN);
- listener.addExpectedChange(description, IResourceDelta.ADDED, IResource.NONE);
- getWorkspace().run(body, getMonitor());
- assertTrue("1.0." + listener.getMessage(), listener.isDeltaValid());
- ensureDoesNotExistInWorkspace(resources);
- } catch(CoreException e) {
- fail("1.1", e);
- }
- } finally {
- getWorkspace().removeResourceChangeListener(listener);
- }
-
- // set the folder to be team private and do the same test
- getWorkspace().addResourceChangeListener(listener);
- try {
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- ensureExistsInWorkspace(resources, true);
- setTeamPrivateMember("2.0", folder, true, IResource.DEPTH_ZERO);
- }
- };
- try {
- listener.reset();
- listener.addExpectedChange(resources, IResourceDelta.ADDED, IResource.NONE);
- listener.addExpectedChange(project, IResourceDelta.ADDED, IResourceDelta.OPEN);
- listener.addExpectedChange(description, IResourceDelta.ADDED, IResource.NONE);
- getWorkspace().run(body, getMonitor());
- assertTrue("2.1." + listener.getMessage(), listener.isDeltaValid());
- ensureDoesNotExistInWorkspace(resources);
- } catch(CoreException e) {
- fail("2.2", e);
- }
- } finally {
- getWorkspace().removeResourceChangeListener(listener);
- }
-
- // set all resources to be team private and do the same test
- getWorkspace().addResourceChangeListener(listener);
- try {
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- ensureExistsInWorkspace(resources, true);
- setTeamPrivateMember("3.0", project, true, IResource.DEPTH_INFINITE);
- }
- };
- try {
- listener.reset();
- listener.addExpectedChange(resources, IResourceDelta.ADDED, IResource.NONE);
- listener.addExpectedChange(project, IResourceDelta.ADDED, IResourceDelta.OPEN);
- listener.addExpectedChange(description, IResourceDelta.ADDED, IResource.NONE);
- getWorkspace().run(body, getMonitor());
- assertTrue("3.1." + listener.getMessage(), listener.isDeltaValid());
- ensureDoesNotExistInWorkspace(resources);
- } catch(CoreException e) {
- fail("3.2", e);
- }
- } finally {
- getWorkspace().removeResourceChangeListener(listener);
- }
-}
-/**
- * Resources which are marked as team private members return TRUE
- * in all calls to #exists.
- */
-public void testExists() {
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- IFolder folder = project.getFolder("folder");
- IFile file = project.getFile("file.txt");
- IFile subFile = folder.getFile("subfile.txt");
- IResource[] resources = new IResource[] {project, folder, file, subFile};
- ensureExistsInWorkspace(resources, true);
-
- // Check to see if all the resources exist in the workspace tree.
- assertExistsInWorkspace("1.0", resources);
-
- // set a folder to be a team private member
- setTeamPrivateMember("2.0", folder, true, IResource.DEPTH_ZERO);
- assertTeamPrivateMember("2.1", folder, true, IResource.DEPTH_ZERO);
- assertExistsInWorkspace("2.2", resources);
-
- // set all resources to be team private
- setTeamPrivateMember("3.0", project, true, IResource.DEPTH_INFINITE);
- assertTeamPrivateMember("3.1", project, true, IResource.DEPTH_INFINITE);
- assertExistsInWorkspace("3.2", resources);
-}
-/**
- * Test the set and get methods for team private members.
- */
-public void testSetGet() {
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- IFolder folder = project.getFolder("folder");
- IFile file = project.getFile("file.txt");
- IFile subFile = folder.getFile("subfile.txt");
- IResource[] resources = new IResource[] {project, folder, file, subFile};
-
- // Trying to set the value on non-existing resources will fail
- for (int i=0; i<resources.length; i++) {
- try {
- resources[i].setTeamPrivateMember(true);
- fail("0.0." + resources[i].getFullPath());
- } catch(CoreException e) {
- }
- }
-
- // create the resources
- ensureExistsInWorkspace(resources, true);
-
- // Initial values should be false.
- for (int i=0; i<resources.length; i++) {
- IResource resource = resources[i];
- assertTrue("1.0: " + resource.getFullPath(), !resource.isTeamPrivateMember());
- }
-
- // Now set the values.
- for (int i = 0; i < resources.length; i++) {
- IResource resource = resources[i];
- try {
- resource.setTeamPrivateMember(true);
- } catch (CoreException e) {
- fail("2.0: " + resource.getFullPath(), e);
- }
- }
-
- // The values should be true for files and folders, false otherwise.
- for (int i = 0; i < resources.length; i++) {
- IResource resource = resources[i];
- switch (resource.getType()) {
- case IResource.FILE:
- case IResource.FOLDER:
- assertTrue("3.0: " + resource.getFullPath(), resource.isTeamPrivateMember());
- break;
- case IResource.PROJECT:
- case IResource.ROOT:
- assertTrue("3.1: " + resource.getFullPath(), !resource.isTeamPrivateMember());
- break;
- }
- }
-
- // Clear the values.
- for (int i = 0; i < resources.length; i++) {
- IResource resource = resources[i];
- try {
- resource.setTeamPrivateMember(false);
- } catch (CoreException e) {
- fail("4.0: " + resource.getFullPath(), e);
- }
- }
-
- // Values should be false again.
- for (int i=0; i<resources.length; i++) {
- IResource resource = resources[i];
- assertTrue("5.0: " + resource.getFullPath(), !resource.isTeamPrivateMember());
- }
-}
-protected void assertTeamPrivateMember(final String message, IResource root, final boolean value, int depth) {
- IResourceVisitor visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- boolean expected = false;
- if (resource.getType() == IResource.FILE || resource.getType() == IResource.FOLDER)
- expected = value;
- assertEquals(message + resource.getFullPath(), expected, resource.isTeamPrivateMember());
- return true;
- }
- };
- try {
- root.accept(visitor, depth, IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
- } catch(CoreException e) {
- fail(message + "resource.accept", e);
- }
-}
-protected void setTeamPrivateMember(final String message, IResource root, final boolean value, int depth) {
- IResourceVisitor visitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- try {
- resource.setTeamPrivateMember(value);
- } catch(CoreException e) {
- fail(message + resource.getFullPath(), e);
- }
- return true;
- }
- };
- try {
- root.accept(visitor, depth, IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
- } catch(CoreException e) {
- fail(message + "resource.accept", e);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/TestPerformer.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/TestPerformer.java
deleted file mode 100644
index f861a50..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/TestPerformer.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import java.util.Random;
-
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-import org.eclipse.core.tests.harness.FussyProgressMonitor;
-/**
- * Abstract superclass of inner classes used for black-box testing
- * For debugging certain failure cases, insert a breakpoint in performTestRecursiveLoop
- * according to the comment in that method.
- */
-abstract public class TestPerformer {
- private int count = 0;
- String name = null;
-/**
- * TestPerformer constructor comment.
- */
-public TestPerformer(String name) {
- super();
- this.name = name;
-}
-public void cleanUp(Object[] args, int count) {
-}
-public Object[] interestingOldState(Object[] args) throws Exception {
- //subclasses should override to hold onto interesting old state
- return null;
-}
-abstract public Object invokeMethod(Object[] args, int count) throws Exception;
-final public void performTest(Object[][] inputs) {
- // call helper method
- int permutations = 1;
- for (int i = 0; i < inputs.length; i++) {
- permutations = permutations * inputs[i].length;
- if (inputs[i].length > 2) {
- scramble(inputs[i]);
- }
- }
-// System.out.println("\nTesting " + permutations + " permutations of " + name);
- performTestRecursiveLoop(inputs, new Object[inputs.length], 0);
-}
-/**
- * Loop through imaginary (nth) index variable, setting args[nth] to inputs[nth][i].
- * Then invoke method if nth==inputs.length-1, otherwise do recursive call
- * with incremented nth.
- */
-private void performTestRecursiveLoop(Object[][] inputs, Object[] args, int nth) {
- for (int i = 0; i < inputs[nth].length; i++) {
- args[nth] = inputs[nth][i];
- if (nth == inputs.length - 1) {
- // breakpoint goes here, may be conditional on name and count, e.g.:
- // name.equals("IResourceTest.testMove") && count==2886
- if (shouldFail(args, count)) {
- try {
- invokeMethod(args, count);
- EclipseWorkspaceTest.assertTrue("invocation " + count + " should fail, but it doesn't", false);
- } catch (Exception ex) {
- }
- } else {
- Object[] oldState = null;
- try {
- oldState = interestingOldState(args);
- } catch (Exception ex) {
- ex.printStackTrace();
- throw new RuntimeException("call to interestingOldState failed");
- }
- Object result = null;
- try {
- result = invokeMethod(args, count);
- } catch (FussyProgressMonitor.FussyProgressAssertionFailed fussyEx) {
- EclipseWorkspaceTest.assertTrue("invocation " + count + ": " + fussyEx.getMessage(), false);
- } catch (Exception ex) {
- EclipseWorkspaceTest.assertTrue("invocation " + count + " failed with " + ex, false);
- }
- boolean success = false;
- try {
- success = wasSuccess(args, result, oldState);
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- EclipseWorkspaceTest.assertTrue("invocation " + count + " did not produce desired result", success);
- }
- cleanUp(args, count);
- count++;
- } else {
- performTestRecursiveLoop(inputs, args, nth + 1);
- }
- }
-}
-/**
- * scrambles an array in a deterministic manner (note the constant seed...).
- */
-static protected void scramble(Object[] first) {
- Random random = new Random(4711);
-
- final int len = first.length;
- for (int i = 0; i < len*100; i++) {
- /* get any array offset */
- int off1 = (int)(random.nextFloat() * len);
- if (off1 == len) continue;
-
- /* get another array offset */
- int off2 = (int)(random.nextFloat() * len);
- if (off2 == len) continue;
-
- /* switch */
- Object temp = first[off1];
- first[off1] = first[off2];
- first[off2] = temp;
- }
-}
-abstract public boolean shouldFail(Object[] args, int count);
-abstract public boolean wasSuccess(Object[] args, Object result, Object[] oldState) throws Exception;
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/WorkspaceTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/WorkspaceTest.java
deleted file mode 100644
index 6745761..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/WorkspaceTest.java
+++ /dev/null
@@ -1,345 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources;
-
-import java.io.InputStream;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-/**
- * This class should be refactored into the black box tests for
- * solution, project, folder and file.
- */
-public class WorkspaceTest extends EclipseWorkspaceTest {
-/**
- * Need a zero argument constructor to satisfy the test harness.
- * This constructor should not do any real work nor should it be
- * called by user code.
- */
-public WorkspaceTest() {
-}
-public WorkspaceTest(String name) {
- super(name);
-}
-public void cleanup() throws Throwable {
- IProject target = getWorkspace().getRoot().getProject("foo");
- target.delete(true, true, null);
- //don't close the workspace because other tests running later will need it.
-}
-/**
- * Returns a collection of string paths describing the standard
- * resource hierarchy for this test. In the string forms, folders are
- * represented as having trailing separators ('/'). All other resources
- * are files. It is generally assumed that this hierarchy will be
- * inserted under some solution and project structure.
- */
-public String[] defineHierarchy() {
- return new String[] {"/", "/1/", "/1/1", "/1/2", "/1/3", "/2/", "/2/1", "/2/2", "/2/3", "/3/", "/3/1", "/3/2", "/3/3", "/4/", "/5"};
-}
-protected IProject getTestProject() {
- return getWorkspace().getRoot().getProject("testProject");
-}
-protected IProject getTestProject2() {
- return getWorkspace().getRoot().getProject("testProject2");
-}
-public void setGetPersistentProperty(IResource target) throws Throwable {
- String value = "this is a test property value";
- QualifiedName name = new QualifiedName("itp-test", "testProperty");
- target.setPersistentProperty(name, value);
- // see if we can get the property
- assertTrue("get not equal set", ((String) target.getPersistentProperty(name)).equals(value));
- // see what happens if we get a non-existant property
- name = new QualifiedName("itp-test", "testNonProperty");
- assertNull("non-existant persistent property not missing", target.getPersistentProperty(name));
-}
-public static Test suite() {
- TestSuite suite = new TestSuite();
- // test the basic create operations
- suite.addTest(new WorkspaceTest("testProjectCreation"));
- suite.addTest(new WorkspaceTest("testFolderCreation"));
- suite.addTest(new WorkspaceTest("testFileCreation"));
- suite.addTest(new WorkspaceTest("testFileInFolderCreation"));
- suite.addTest(new WorkspaceTest("testSetContents"));
- suite.addTest(new WorkspaceTest("testFileOverFolder"));
- suite.addTest(new WorkspaceTest("testFolderOverFile"));
- suite.addTest(new WorkspaceTest("testProjectCreateOpenCloseDelete"));
- suite.addTest(new WorkspaceTest("testProjectReferences"));
-
- // test closing and reopening
- suite.addTest(new WorkspaceTest("testProjectCloseOpen"));
-
- // test persistent properties on all the different resource types.
- suite.addTest(new WorkspaceTest("testSetGetProjectPersistentProperty"));
- suite.addTest(new WorkspaceTest("testSetGetFolderPersistentProperty"));
- suite.addTest(new WorkspaceTest("testSetGetFilePersistentProperty"));
-
- // test moves
- suite.addTest(new WorkspaceTest("testSimpleMove"));
- suite.addTest(new WorkspaceTest("testFileMove"));
- suite.addTest(new WorkspaceTest("testLeafFolderMove"));
- suite.addTest(new WorkspaceTest("testFolderMove"));
-
- // create a bunch of things at once
- suite.addTest(new WorkspaceTest("testMultiCreation"));
-
- // test deletions
- suite.addTest(new WorkspaceTest("testFolderDeletion"));
- suite.addTest(new WorkspaceTest("testFileDeletion"));
- suite.addTest(new WorkspaceTest("testFileEmptyDeletion"));
- suite.addTest(new WorkspaceTest("testMultiDeletion"));
- suite.addTest(new WorkspaceTest("testProjectDeletion"));
-
- suite.addTest(new WorkspaceTest("cleanup"));
- return suite;
-}
-protected void tearDown() throws Exception {
- // overwrite the superclass and do nothing since our test methods build on each other
-}
-public void testFileCreation() throws Throwable {
- IPath path = new Path("/testProject/testFile");
- IFile target = getWorkspace().getRoot().getFile(path);
- target.create(null, true, getMonitor());
- assertTrue(target.exists());
-}
-public void testFileDeletion() throws Throwable {
- IPath path = new Path("/testProject/testFileForDelete");
- IFile target = getWorkspace().getRoot().getFile(path);
- target.create(null, true, getMonitor());
- assertTrue(target.exists());
- target.delete(true, getMonitor());
- assertTrue(!target.exists());
-}
-public void testFileEmptyDeletion() throws Throwable {
- IPath path = new Path("/testProject/testFileForDelete2");
- IFile target = getWorkspace().getRoot().getFile(path);
- target.create(getContents(""), true, getMonitor());
- assertTrue(target.exists());
- target.delete(true, getMonitor());
- assertTrue(!target.exists());
-}
-public void testFileInFolderCreation() throws Throwable {
- IPath path = new Path("/testProject/testFolder/testFile2");
- IFile target = getWorkspace().getRoot().getFile(path);
- target.create(getRandomContents(), true, getMonitor());
- assertTrue(target.exists());
-}
-public void testFileMove() throws Throwable {
- IPath path = new Path("/testProject/targetFile");
- IFile target = getWorkspace().getRoot().getFile(path);
- target.create(getRandomContents(), true, getMonitor());
- IFile destination = getWorkspace().getRoot().getFile(new Path("/testProject/movedFile"));
- target.move(destination.getFullPath(), true, getMonitor());
- assertTrue(destination.exists());
- assertTrue(!target.exists());
-}
-public void testFileOverFolder() throws Throwable {
- IPath path = new Path("/testProject/testFolder");
- IFolder existing = getWorkspace().getRoot().getFolder(path);
- assertTrue(existing.exists());
- IFile target = getWorkspace().getRoot().getFile(path);
- try {
- target.create(null, true, getMonitor());
- } catch (CoreException e) {
- assertTrue(existing.exists());
- return;
- }
- fail("Should not be able to create file over folder");
-}
-public void testFolderCreation() throws Throwable {
- IPath path = new Path("/testProject/testFolder");
- IFolder target = getWorkspace().getRoot().getFolder(path);
- target.create(true, true, getMonitor());
- assertTrue(target.exists());
-}
-public void testFolderDeletion() throws Throwable {
- IProject project = getTestProject();
- IResource[] before = buildResources(project, new String[] {"c/", "c/b/", "c/x", "c/b/y", "c/b/z"});
- ensureExistsInWorkspace(before, true);
- //
- assertExistsInWorkspace(before);
- project.getFolder("c").delete(true, getMonitor());
- assertDoesNotExistInWorkspace(before);
-}
-public void testFolderMove() throws Throwable {
- IProject project = getTestProject();
- IResource[] before = buildResources(project, new String[] {"b/", "b/b/", "b/x", "b/b/y", "b/b/z"});
- IResource[] after = buildResources(project, new String[] {"a/", "a/b/", "a/x", "a/b/y", "a/b/z"});
-
- // create the resources and set some content in a file that will be moved.
- ensureExistsInWorkspace(before, true);
- String content = getRandomString();
- IFile file = project.getFile(new Path("b/b/z"));
- file.setContents(getContents(content), true, false, getMonitor());
-
- // Be sure the resources exist and then move them.
- assertExistsInWorkspace(before);
- project.getFolder("b").move(project.getFullPath().append("a"), true, getMonitor());
-
- //
- assertDoesNotExistInWorkspace(before);
- assertExistsInWorkspace(after);
- file = project.getFile(new Path("a/b/z"));
- assertTrue("get not equal set", compareContent(getContents(content), file.getContents(false)));
-}
-public void testFolderOverFile() throws Throwable {
- IPath path = new Path("/testProject/testFile");
- IFile existing = getWorkspace().getRoot().getFile(path);
- assertTrue(existing.exists());
- IFolder target = getWorkspace().getRoot().getFolder(path);
- try {
- target.create(true, true, getMonitor());
- } catch (CoreException e) {
- assertTrue(existing.exists());
- return;
- }
- fail("Should not be able to create folder over a file");
-}
-public void testLeafFolderMove() throws Throwable {
- IProject project = getTestProject();
- IFolder source = project.getFolder("testFolder");
- IFolder dest = project.getFolder("movedFolder");
- //
- source.move(dest.getFullPath(), true, getMonitor());
- assertExistsInWorkspace(dest);
- assertDoesNotExistInWorkspace(source);
-}
-public void testMultiCreation() throws Throwable {
- final IProject project = getWorkspace().getRoot().getProject("bar");
- final IResource[] resources = buildResources(project, new String[] { "a/", "a/b" });
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- if (!project.exists())
- project.create(null);
- if (!project.isOpen())
- project.open(null);
- // define an operation which will create a bunch of resources including a project.
- for (int i = 0; i < resources.length; i++) {
- IResource resource = resources[i];
- switch (resource.getType()) {
- case IResource.FILE :
- ((IFile) resource).create(null, false, getMonitor());
- break;
- case IResource.FOLDER :
- ((IFolder) resource).create(false, true, getMonitor());
- break;
- case IResource.PROJECT :
- ((IProject) resource).create(getMonitor());
- break;
- }
- }
- }
- };
- getWorkspace().run(body, getMonitor());
- assertExistsInWorkspace(project);
- assertExistsInWorkspace(resources);
-}
-public void testMultiDeletion() throws Throwable {
- IProject project = getTestProject();
- IResource[] before = buildResources(project, new String[] {"c/", "c/b/", "c/x", "c/b/y", "c/b/z"});
- ensureExistsInWorkspace(before, true);
- //
- assertExistsInWorkspace(before);
- getWorkspace().delete(before, true, getMonitor());
- assertDoesNotExistInWorkspace(before);
-}
-public void testProjectCloseOpen() throws Throwable {
- IProject target = getTestProject();
- target.close(getMonitor());
- assertTrue(target.exists());
- assertTrue(!target.isOpen());
- assertTrue(!target.getFolder("testFolder").exists());
- target.open(getMonitor());
- assertTrue(target.isOpen());
- assertTrue(target.getFolder("testFolder").exists());
-}
-public void testProjectCreateOpenCloseDelete() throws Throwable {
- IProject target = getTestProject2();
- target.create(null, getMonitor());
- assertTrue(target.exists());
- target.open(getMonitor());
- assertTrue(target.isOpen());
- target.close(getMonitor());
- assertTrue(!target.isOpen());
- target.delete(true, getMonitor());
- assertTrue(!target.exists());
-}
-public void testProjectCreation() throws Throwable {
- IProject target = getTestProject();
- target.create(null, getMonitor());
- assertTrue(target.exists());
- target.open(getMonitor());
- assertTrue(target.isOpen());
-}
-public void testProjectDeletion() throws Throwable {
- IProject target = getTestProject();
- target.delete(true, getMonitor());
- assertTrue("Project Deletion failed", !target.exists());
-}
-public void testProjectReferences() throws Throwable {
- IProject target = getTestProject2();
- target.create(null, getMonitor());
- assertTrue(target.exists());
- IProject project = getTestProject();
- IProjectDescription description = project.getDescription();
- description.setReferencedProjects(new IProject[] { target });
- project.setDescription(description, getMonitor());
- assertTrue(target.getReferencingProjects().length == 1);
-
- target.delete(true, getMonitor());
- assertTrue(!target.exists());
-}
-public void testSetContents() throws Throwable {
- IPath path = new Path("/testProject/testFile");
- IFile target = getWorkspace().getRoot().getFile(path);
- String testString = getRandomString();
- target.setContents(getContents(testString), true, false, getMonitor());
- InputStream content = null;
- try {
- content = target.getContents(false);
- assertTrue("get not equal set", compareContent(content, getContents(testString)));
- } finally {
- content.close();
- }
-}
-public void testSetGetFilePersistentProperty() throws Throwable {
- IResource target = getWorkspace().getRoot().getFile(new Path ("/testProject/testFile"));
- setGetPersistentProperty(target);
-}
-public void testSetGetFolderPersistentProperty() throws Throwable {
- IResource target = getWorkspace().getRoot().getFolder(new Path("/testProject/testFolder"));
- setGetPersistentProperty(target);
-}
-public void testSetGetProjectPersistentProperty() throws Throwable {
- IResource target = getWorkspace().getRoot().getProject("/testProject");
- setGetPersistentProperty(target);
-}
-public void testSetProperty() throws Throwable {
- IPath path = new Path("/testProject/testFile");
- IFile target = getWorkspace().getRoot().getFile(path);
- String value = "this is a test property value";
- QualifiedName name = new QualifiedName("itp-test", "testProperty");
- target.setPersistentProperty(name, value);
- assertTrue("get not equal set", ((String) target.getPersistentProperty(name)).equals(value));
-}
-public void testSimpleMove() throws Throwable {
- IPath path = new Path("/testProject/simpleFile");
- IFile target = getWorkspace().getRoot().getFile(path);
- target.create(getRandomContents(), true, getMonitor());
- IFile destination = getWorkspace().getRoot().getFile(new Path("/testProject/newSimpleFile"));
- target.move(destination.getFullPath(), true, getMonitor());
- assertTrue(destination.exists());
- assertTrue(!target.exists());
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/perf/BenchElementTree.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/perf/BenchElementTree.java
deleted file mode 100644
index 1cd6046..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/perf/BenchElementTree.java
+++ /dev/null
@@ -1,557 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.perf;
-
-
-import java.util.Vector;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.watson.DefaultElementComparator;
-import org.eclipse.core.internal.watson.ElementTree;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.tests.harness.CorePerformanceTest;
-
-/**
- * Benchmarks for <code>ElementTree</code>.
- */
-public class BenchElementTree extends CorePerformanceTest {
- static String[] javaLangUnits = {
- "AbstractMethodError.java",
- "ArithmeticException.java",
- "ArrayIndexOutOfBoundsException.java",
- "ArrayStoreException.java",
- "Boolean.java",
- "Byte.java",
- "Character.java",
- "Class.java",
- "ClassCastException.java",
- "ClassCircularityError.java",
- "ClassFormatError.java",
- "ClassLoader.java",
- "ClassNotFoundException.java",
- "Cloneable.java",
- "CloneNotSupportedException.java",
- "Compiler.java",
- "Double.java",
- "Error.java",
- "Exception.java",
- "ExceptionInInitializerError.java",
- "Float.java",
- "FloatingDecimal.java",
- "IllegalAccessError.java",
- "IllegalAccessException.java",
- "IllegalArgumentException.java",
- "IllegalMonitorStateException.java",
- "IllegalStateException.java",
- "IllegalThreadStateException.java",
- "IncompatibleClassChangeError.java",
- "IndexOutOfBoundsException.java",
- "InstantiationError.java",
- "InstantiationException.java",
- "Integer.java",
- "InternalError.java",
- "InterruptedException.java",
- "LinkageError.java",
- "Long.java",
- "Math.java",
- "NegativeArraySizeException.java",
- "NoClassDefFoundError.java",
- "NoSuchFieldError.java",
- "NoSuchFieldException.java",
- "NoSuchMethodError.java",
- "NoSuchMethodException.java",
- "NullPointerException.java",
- "Number.java",
- "NumberFormatException.java",
- "Object.java",
- "OutOfMemoryError.java",
- "Process.java",
- "Runnable.java",
- "Runtime.java",
- "RuntimeException.java",
- "SecurityException.java",
- "SecurityManager.java",
- "Short.java",
- "StackOverflowError.java",
- "String.java",
- "StringBuffer.java",
- "StringIndexOutOfBoundsException.java",
- "System.java",
- "Thread.java",
- "ThreadDeath.java",
- "ThreadGroup.java",
- "Throwable.java",
- "UnknownError.java",
- "UnsatisfiedLinkError.java",
- "VerifyError.java",
- "VirtualMachineError.java",
- "Void.java"
- };
-
- static final IPath solution = Path.ROOT.append("solution");
- static final IPath project = solution.append("project");
- static final IPath folder = project.append("folder");
- static final IPath[] files = getFilePaths();
-
-public BenchElementTree() {
-}
-public BenchElementTree(String name) {
- super(name);
-}
-/**
- * Tests the performance of the createElement operation.
- */
-public void benchCreateElement() {
-
- final int repeat = 400;
- final int count = repeat * (files.length + 3);
-
- startBench();
-
- for (int rep = repeat; --rep >= 0;) {
- createTestTree(false);
- }
-
- stopBench("benchCreateElement", count);
-}
-/**
- * Tests the performance of the deleteElement operation.
- */
-public void benchDeleteElement() {
- final int repeat = 400;
-
- /* create copies of the original tree */
- ElementTree[] trees = new ElementTree[repeat];
- for (int i = 0; i < repeat; i++) {
- trees[i] = createTestTree(false);
- }
-
- startBench();
- for (int rep = repeat; --rep >= 0;) {
- for (int i = 0, len = files.length; i < len; ++i) {
- trees[rep].deleteElement(files[i]);
- }
- }
-
- stopBench("benchDeleteElement", repeat * files.length);
-}
-/**
- * Bench calculation of deltas between two trees
- */
-public void benchDeltaLargeTreeFewChanges() {
- ElementTree oldTree = createLargeTree();
- ElementTree newTree = doRoutineOperationsOnLargeTree(oldTree);
-
- startBench();
- int repeat = 1000;
- for (int i = 0; i < repeat; i++) {
- newTree.computeDeltaWith(oldTree, DefaultElementComparator.getComparator());
- }
-
- stopBench("benchDeltaLargeTreeFewChanges", repeat);
-}
-/**
- * Bench calculation of deltas between two trees
- */
-public void benchDeltaLargeTreeManyChangesInOneLayer() {
- ElementTree oldTree = createLargeTree();
- ElementTree newTree = doManyRoutineOperationsOnLargeTree(oldTree);
-
- startBench();
- int repeat = 50;
- for (int i = 0; i < repeat; i++) {
- newTree.computeDeltaWith(oldTree, DefaultElementComparator.getComparator());
- }
-
- stopBench("benchDeltaLargeTreeManyChangesInOneLayer", repeat);
-}
-/**
- * Bench calculation of deltas between two trees
- */
-public void benchDeltaSmallTreeManyChangesInSeperateLayers() {
- ElementTree oldTree = createTestTree(false);
- ElementTree newTree = doRoutineOperations(oldTree);
-
- startBench();
- int repeat = 100;
- for (int i = 0; i < repeat; i++) {
- newTree.computeDeltaWith(oldTree, DefaultElementComparator.getComparator());
- }
-
- stopBench("benchDeltaSmallTreeManyChangesInSeperateLayers", repeat);
-}
-/**
- * Tests the performance of the getElementData operation.
- */
-public void benchGetElementData() {
- final int repeat = 500;
-
- ElementTree tree = createTestTree(false);
-
- startBench();
-
- for (int rep = repeat; --rep >= 0;) {
- for (int i = 0, len = files.length; i < len; ++i) {
- tree.getElementData(files[i]);
- }
- }
-
- stopBench("benchGetElementData", repeat * files.length);
-}
-/**
- * Tests the performance of the mergeDeltaChain operation.
- */
-public void benchMergeDeltaChain() {
- final int repeat = 50;
-
- /* creat all the test trees */
- ElementTree[] bases = new ElementTree[repeat];
- ElementTree[][] chains = new ElementTree[repeat][];
- for (int i = 0; i < repeat; i++) {
- bases[i] = createTestTree(true);
- chains[i] = buildDeltaChain(createTestTree(false));
- }
- startBench();
-
- for (int i = repeat; --i >=0;) {
- bases[i].mergeDeltaChain(folder, chains[i]);
- }
-
- stopBench("benchMergeDeltaChain", repeat);
-}
-/**
- * Bench calculation of deltas between two trees
- */
-public void benchReverseDeltaLargeTreeFewChanges() {
- ElementTree oldTree = createLargeTree();
- ElementTree newTree = doRoutineOperationsOnLargeTree(oldTree);
-
- startBench();
- int repeat = 1000;
- for (int i = 0; i < repeat; i++) {
- oldTree.computeDeltaWith(newTree, DefaultElementComparator.getComparator());
- }
-
- stopBench("benchReverseDeltaLargeTreeFewChanges", repeat);
-}
-/**
- * Bench calculation of deltas between two trees
- */
-public void benchReverseDeltaLargeTreeManyChangesInOneLayer() {
- ElementTree oldTree = createLargeTree();
- ElementTree newTree = doManyRoutineOperationsOnLargeTree(oldTree);
-
- startBench();
- int repeat = 25;
- for (int i = 0; i < repeat; i++) {
- oldTree.computeDeltaWith(newTree, DefaultElementComparator.getComparator());
- }
-
- stopBench("benchReverseDeltaLargeTreeManyChangesInOneLayer", repeat);
-}
-/**
- * Bench calculation of deltas between two trees
- */
-public void benchReverseDeltaSmallTreeManyChangesInSeperateLayers() {
- ElementTree oldTree = createTestTree(false);
- ElementTree newTree = doRoutineOperations(oldTree);
-
- startBench();
- int repeat = 20;
- for (int i = 0; i < repeat; i++) {
- oldTree.computeDeltaWith(newTree, DefaultElementComparator.getComparator());
- }
-
- stopBench("benchReverseDeltaSmallTreeManyChangesInSeperateLayers", repeat);
-}
-/**
- * Tests a typical series of ElementTree operations, where
- * a new delta is generated for each operation.
- */
-public void benchRoutineOperations() {
- final int repeat = 75;
-
- int opCount = 0;
- startBench();
-
- for (int i = 0; i < repeat; i++) {
- opCount += doRoutineOperations();
- }
-
- stopBench("benchRoutineOperations", opCount);
-}
-/**
- * Tests the performance of the setElementData operation.
- */
-public void benchSetElementData() {
- ElementTree tree = createTestTree(false);
- Object data = new Object();
-
- startBench();
-
- for (int rep = 500; --rep >= 0;) {
- for (int i = 0, len = files.length; i < len; ++i) {
- tree.setElementData(files[i], data);
- }
- }
-
- stopBench("benchSetElementData", 500 * files.length);
-}
-/**
- * Does several routine operations on the given tree.
- * Returns an array of all the intermediary elementtrees.
- */
-private ElementTree[] buildDeltaChain(ElementTree tree) {
- Vector trees = new Vector();
- trees.addElement(tree);
-
- int repeat = 1;
-
- /* create file elements */
- tree = tree.newEmptyDelta();
- IPath[] files = getFilePaths();
- for (int i = 0; i < files.length; i++) {
- Object data = files[i].toString();
- tree.createElement(files[i], data);
-
- tree.immutable();
- trees.addElement(tree);
- tree = tree.newEmptyDelta();
- }
-
-
- /* modify the data of all file elements a few times */
- for (int i = 0; i < repeat; i++) {
- Object data = "data"+i;
- for (int f = 0; f < files.length; f++) {
- tree.setElementData(files[f], data);
-
- tree.immutable();
- trees.addElement(tree);
- tree = tree.newEmptyDelta();
- }
- }
-
- /* delete all file elements */
- for (int i = 0; i < files.length; i++) {
- tree.deleteElement(files[i]);
- tree.immutable();
- trees.addElement(tree);
- tree = tree.newEmptyDelta();
- }
-
- ElementTree[] results = new ElementTree[trees.size()];
- trees.copyInto(results);
- return results;
-}
-/**
- * Creates a very large tree (> 10000 elements).
- * Tree is complete tree of depth 4, fan out 10.
- */
-private ElementTree createLargeTree() {
- int elementsPerDepth = 10;
- ElementTree tree = new ElementTree();
- Object data = new Object();
-
- //create strings
- String[] names = new String[elementsPerDepth];
- for (int i = 0; i < elementsPerDepth; i++) {
- names[i] = Integer.toString(i);
- }
-
- for (int i = 0; i < elementsPerDepth; i++) {
- IPath ipath = Path.ROOT.append(names[i]);
- tree.createElement(ipath, data);
- for (int j = 0; j < elementsPerDepth; j++) {
- IPath jpath = ipath.append(names[j]);
- tree.createElement(jpath, data);
- for (int k = 0; k < elementsPerDepth; k++) {
- IPath kpath = jpath.append(names[k]);
- tree.createElement(kpath, data);
- for (int l = 0; l < elementsPerDepth; l++) {
- IPath lpath = kpath.append(names[l]);
- tree.createElement(lpath, data);
- }
- }
- }
- }
- return tree;
-}
-/**
- * Creates a test element tree. If withDeltas is true,
- * a new delta is created after each operation.
- */
-private ElementTree createTestTree(boolean withDeltas) {
- ElementTree tree = new ElementTree();
- Object data = new Object();
-
- tree.createElement(solution, data);
-
- if (withDeltas) {
- tree.immutable();
- tree = tree.newEmptyDelta();
- }
- tree.createElement(project, data);
- if (withDeltas) {
- tree.immutable();
- tree = tree.newEmptyDelta();
- }
- tree.createElement(folder, data);
-
- for (int i = 0, len = javaLangUnits.length; i < len; ++i) {
- if (withDeltas) {
- tree.immutable();
- tree = tree.newEmptyDelta();
- }
- IPath file = folder.append(javaLangUnits[i]);
- tree.createElement(file, data);
- }
- return tree;
-}
-/**
- * Tests a typical series of ElementTree operations, where
- * a new delta is generated for each operation.
- * Returns the resulting element tree.
- */
-private ElementTree doManyRoutineOperationsOnLargeTree(ElementTree tree) {
- ElementTree newTree = tree.newEmptyDelta();
-
- int elementsPerDepth = tree.getChildCount(Path.ROOT);
- Object data = new Object();
- //create strings
- String[] names = new String[elementsPerDepth];
- for (int i = 0; i < elementsPerDepth; i++) {
- names[i] = Integer.toString(i);
- }
-
- //add 1000 elements (simulate large import)
- for (int i = 0; i < elementsPerDepth; i++) {
- IPath ipath = Path.ROOT.append(names[i]);
- for (int j = 0; j < elementsPerDepth; j++) {
- IPath jpath = ipath.append(names[j]);
- for (int k = 0; k < elementsPerDepth; k++) {
- IPath kpath = jpath.append("new" + names[k]);
- newTree.createElement(kpath, data);
- }
- }
- }
- newTree.immutable();
- return newTree;
-}
-/**
- * Tests a typical series of ElementTree operations, where
- * a new delta is generated for each operation.
- * Returns the number of basic ElementTree operations performed.
- */
-private int doRoutineOperations() {
- ElementTree tree = createTestTree(true);
- int repeat = 1;
-
- /* modify the data of all file elements a few times */
- for (int i = 0; i < repeat; i++) {
- Object data = "data"+i;
- for (int f = 0; f < files.length; f++) {
- tree = tree.newEmptyDelta();
- tree.setElementData(files[f], data);
- tree.immutable();
- }
- }
-
- /* delete all file elements */
- for (int i = 0; i < files.length; i++) {
- tree = tree.newEmptyDelta();
- tree.deleteElement(files[i]);
- tree.immutable();
- }
-
- return (repeat + 2) * files.length;
-}
-/**
- * Tests a typical series of ElementTree operations, where
- * a new delta is generated for each operation.
- * Returns the resulting element tree.
- */
-private ElementTree doRoutineOperations(ElementTree tree) {
- int repeat = 3;
-
- /* modify the data of all file elements a few times */
- for (int i = 0; i < repeat; i++) {
- Object data = "data"+i;
- for (int f = 0; f < files.length; f++) {
- tree = tree.newEmptyDelta();
- tree.setElementData(files[f], data);
- tree.immutable();
- }
- }
- return tree;
-}
-/**
- * Tests a typical series of ElementTree operations, where
- * a new delta is generated for each operation.
- * Returns the resulting element tree.
- */
-private ElementTree doRoutineOperationsOnLargeTree(ElementTree tree) {
- int elementsPerDepth = tree.getChildCount(Path.ROOT);
- //create strings
- String[] names = new String[elementsPerDepth];
- for (int i = 0; i < elementsPerDepth; i++) {
- names[i] = Integer.toString(i);
- }
-
- //do about ten changes -- small incremental change
- for (int i = 0; i < elementsPerDepth; i++) {
- IPath ipath = Path.ROOT.append(names[i]);
- tree = tree.newEmptyDelta();
- tree.setElementData(ipath, ipath.toString());
- tree.immutable();
- }
- return tree;
-}
-static IPath[] getFilePaths() {
- IPath[] jcuIDs = new IPath[javaLangUnits.length];
- for (int i = 0, len = javaLangUnits.length; i < len; ++i) {
- jcuIDs[i] = folder.append(javaLangUnits[i]);
- }
- return jcuIDs;
-}
-/**
- * The environment should be set-up in the main method.
- */
-protected void setUp() throws Exception {
- //benchmarks don't use the core testing infrastructure
-}
-public static Test suite() {
- TestSuite suite= new TestSuite();
-
- suite.addTest(new BenchElementTree("benchCreateElement"));
- suite.addTest(new BenchElementTree("benchDeleteElement"));
- suite.addTest(new BenchElementTree("benchDeltaLargeTreeFewChanges"));
- suite.addTest(new BenchElementTree("benchDeltaLargeTreeManyChangesInOneLayer"));
- suite.addTest(new BenchElementTree("benchDeltaSmallTreeManyChangesInSeperateLayers"));
- suite.addTest(new BenchElementTree("benchGetElementData"));
-// suite.addTest(new BenchElementTree("benchMergeDeltaChain"));
- suite.addTest(new BenchElementTree("benchReverseDeltaLargeTreeFewChanges"));
- suite.addTest(new BenchElementTree("benchReverseDeltaLargeTreeManyChangesInOneLayer"));
- suite.addTest(new BenchElementTree("benchReverseDeltaSmallTreeManyChangesInSeperateLayers"));
- suite.addTest(new BenchElementTree("benchRoutineOperations"));
- suite.addTest(new BenchElementTree("benchSetElementData"));
-
- return suite;
-}
-/**
- *
- */
-protected void tearDown() throws Exception {
- //ElementTree tests don't use the CoreTest infrastructure
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/perf/BenchLocalStoreTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/perf/BenchLocalStoreTest.java
deleted file mode 100644
index 4931573..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/perf/BenchLocalStoreTest.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.perf;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.eclipse.core.internal.localstore.HistoryStore;
-import org.eclipse.core.internal.resources.Workspace;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFileState;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.tests.harness.CorePerformanceTest;
-
-
-public class BenchLocalStoreTest extends CorePerformanceTest {
-
- public BenchLocalStoreTest() {
- super();
- }
- public BenchLocalStoreTest(String name) {
- super(name);
- }
- public static Test suite() {
-// TestSuite suite = new TestSuite();
-// suite.addTest(new BenchLocalStoreTest("testBug28603"));
-// return suite;
- return new TestSuite(BenchLocalStoreTest.class);
- }
- protected void tearDown() throws Exception {
- super.tearDown();
- wipeHistoryStore();
- }
- public void testBug28603() {
- // paths to mimic files in the workspace
- IProject project = getWorkspace().getRoot().getProject("myproject");
- IFolder folder1 = project.getFolder("myfolder1");
- IFolder folder2 = project.getFolder("myfolder2");
- IFile file1 = folder1.getFile("myfile.txt");
- IFile file2 = folder2.getFile(file1.getName());
-
- ensureExistsInWorkspace(new IResource[] {project, folder1, folder2}, true);
- try {
- file1.create(getRandomContents(), IResource.FORCE, getMonitor());
- file1.setContents(getRandomContents(), IResource.FORCE | IResource.KEEP_HISTORY, getMonitor());
- file1.setContents(getRandomContents(), IResource.FORCE | IResource.KEEP_HISTORY, getMonitor());
- file1.setContents(getRandomContents(), IResource.FORCE | IResource.KEEP_HISTORY, getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
- int maxStates = ResourcesPlugin.getWorkspace().getDescription().getMaxFileStates();
-
- IFileState[] states = null;
- try {
- states = file1.getHistory(getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
- assertEquals("1.1", 3, states.length);
- int currentStates = 3;
- long totalMoveTime = 0L;
- int totalMoves = 0;
-
- for (int i = 0; i < maxStates + 10; i++) {
- long start = 0L;
- long stop = 0L;
- try {
- states = file1.getHistory(getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
- assertEquals("2.1 file1 states", currentStates, states.length);
- try {
- start = System.currentTimeMillis();
- file1.move(file2.getFullPath(), true, true, getMonitor());
- stop = System.currentTimeMillis();
- } catch (CoreException e) {
- fail("2.2", e);
- }
- totalMoveTime += stop - start;
- totalMoves++;
- System.out.println("move: " + file1.getFullPath() + " to " + file2.getFullPath() + " took: " + (stop - start) + "ms");
-
- try {
- states = file2.getHistory(getMonitor());
- } catch (CoreException e) {
- fail("2.3", e);
- }
- currentStates = currentStates < maxStates ? currentStates + 1 : maxStates;
- assertEquals("2.4 file2 states", currentStates, states.length);
- try {
- start = System.currentTimeMillis();
- file2.move(file1.getFullPath(), true, true, getMonitor());
- stop = System.currentTimeMillis();
- } catch (CoreException e) {
- fail("2.5", e);
- }
- totalMoveTime += stop - start;
- totalMoves++;
- try {
- states = file1.getHistory(getMonitor());
- } catch (CoreException e) {
- fail("2.6", e);
- }
- currentStates = currentStates < maxStates ? currentStates + 1 : maxStates;
- assertEquals("2.7 file1 states", currentStates, states.length);
-
- System.out.println("move: " + file2.getFullPath() + " to " + file1.getFullPath() + " took: " + (stop - start) + "ms");
- }
- System.out.println("\nAverage move time = " + totalMoveTime/totalMoves + "ms over " + totalMoves + " moves.");
-
- }
- /*
- * This little helper method makes sure that the history store is
- * completely clean after it is invoked. If a history store entry or
- * a file is left, it may become part of the history for another file in
- * another test (if this file has the same name).
- */
- private void wipeHistoryStore() {
- HistoryStore store = ((Workspace) getWorkspace()).getFileSystemManager().getHistoryStore();
- // Remove all the entries from the history store index. Note that
- // this does not cause the history store states to be removed.
- store.removeAll();
- // Now make sure all the states are really removed.
- store.removeGarbage();
- }
-
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/perf/BenchMiscWorkspace.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/perf/BenchMiscWorkspace.java
deleted file mode 100644
index 03802f2..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/perf/BenchMiscWorkspace.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.perf;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.tests.harness.CorePerformanceTest;
-
-public class BenchMiscWorkspace extends CorePerformanceTest {
-public static Test suite() {
- TestSuite suite= new TestSuite();
- suite.addTest(new BenchMiscWorkspace("benchNoOp"));
- return suite;
-}
-/**
- * Constructor for BenchMiscWorkspace.
- */
-public BenchMiscWorkspace() {
- super();
-}
-/**
- * Constructor for BenchMiscWorkspace.
- * @param name
- */
-public BenchMiscWorkspace(String name) {
- super(name);
-}
-/**
- * Benchmarks performing many empty operations.
- */
-public void benchNoOp() throws Exception {
- final int REPEAT = 100000;
- IWorkspace ws = ResourcesPlugin.getWorkspace();
-
- IWorkspaceRunnable noop = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- }
- };
- startBench();
- for (int i = 0; i < REPEAT; i++) {
- ws.run(noop, null);
- }
- stopBench("benchNoOp", REPEAT);
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/perf/BenchWorkspace.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/perf/BenchWorkspace.java
deleted file mode 100644
index 29dee55..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/perf/BenchWorkspace.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.perf;
-
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.internal.resources.Workspace;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.tests.harness.CorePerformanceTest;
-
-public class BenchWorkspace extends CorePerformanceTest {
- IProject project;
- private static final int NUM_FOLDERS = 400;//must be multiple of 10
- private static final int FILES_PER_FOLDER = 20;
- /**
- * No-arg constructor to satisfy test harness.
- */
- public BenchWorkspace() {
- }
- /**
- * Standard test case constructor
- */
- public BenchWorkspace(String testName) {
- super(testName);
- }
- public static Test suite() {
- TestSuite suite= new TestSuite();
- suite.addTest(new BenchWorkspace("benchCountResources"));
- return suite;
- }
- public void benchCountResources() {
- Workspace workspace = (Workspace)getWorkspace();
- int count = 0;
- startBench();
- for (int i = 0; i < 100; i++) {
- count = workspace.countResources(project.getFullPath(), IResource.DEPTH_INFINITE, true);
- }
- stopBench("benchCountResources", 100);
- System.out.println("Count: " + count);
- }
- public void benchCountResourcesDuringOperation() {
- final Workspace workspace = (Workspace)getWorkspace();
- IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- //touch all files
- workspace.getRoot().accept(new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- resource.touch(null);
- return true;
- }
- });
- //now count the resources in the dirty workspace
- int count = 0;
- startBench();
- for (int i = 0; i < 10; i++) {
- count = workspace.countResources(project.getFullPath(), IResource.DEPTH_INFINITE, true);
- }
- stopBench("benchCountResources", 10);
- System.out.println("Count: " + count);
- }
- };
- try {
- workspace.run(runnable, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
- }
- public String[] defineHierarchy() {
- //define a hierarchy with NUM_FOLDERS folders, NUM_FILES files.
- String[] names = new String[NUM_FOLDERS * (FILES_PER_FOLDER+1)];
- //create the folders
- final int MAX_DEPTH = 10;
- final int MAX_SPAN = NUM_FOLDERS/MAX_DEPTH;
- int i = 0;
- for (int depth = 0; depth < MAX_DEPTH; depth++) {
- for (int span = 0; span < MAX_SPAN; span++) {
- if (depth == 0) {
- names[i] = "TestProject/" + Integer.toString(span) + "/";
- } else {
- names[i] = names[i-MAX_SPAN] + Integer.toString(span) + "/";
- }
- i++;
- }
- }
- //create files for each folder
- for (int folder = 0; folder < NUM_FOLDERS; folder++) {
- for (int file = 0; file < FILES_PER_FOLDER; file++) {
- names[i++] = names[folder] + "file" + Integer.toString(file);
- }
- }
- return names;
- }
- /**
- * @see EclipseWorkspaceTest#setUp()
- */
- protected void setUp() throws Exception {
- super.setUp();
-
- IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- //create resources
- project = getWorkspace().getRoot().getProject("TestProject");
- project.create(null);
- project.open(null);
- IResource[] resources = buildResources(project, defineHierarchy());
- ensureExistsInWorkspace(resources, true);
- }
- };
- try {
- getWorkspace().run(runnable, null);
- } catch (CoreException e) {
- fail("1.0", e);
- }
- }
- /**
- * @see TestCase#tearDown()
- */
- protected void tearDown() throws Exception {
- super.tearDown();
- project.delete(true, true, null);
- }
-}
-
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/perf/MarkerPerformanceTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/perf/MarkerPerformanceTest.java
deleted file mode 100644
index ee91cc2..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/perf/MarkerPerformanceTest.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.perf;
-
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.CorePerformanceTest;
-
-public class MarkerPerformanceTest extends CorePerformanceTest {
- IProject project;
- IFile file;
- IMarker[] markers;
- final int NUM_MARKERS = 5000;
- final int REPEAT = 100;
- /**
- * No-arg constructor to satisfy test harness.
- */
- public MarkerPerformanceTest() {
- }
- /**
- * Standard test case constructor
- */
- public MarkerPerformanceTest(String testName) {
- super(testName);
- }
- public static Test suite() {
- TestSuite suite= new TestSuite();
- suite.addTest(new MarkerPerformanceTest("benchSetAttributes1"));
- suite.addTest(new MarkerPerformanceTest("benchSetAttributes2"));
- return suite;
- }
- public void benchSetAttributes1() {
- //benchmark setting many attributes in a single operation
- IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- //set all attributes for each marker
- for (int i = 0; i < NUM_MARKERS; i++) {
- for (int j = 0; j < REPEAT; j++) {
- markers[i].setAttribute("attrib", "hello");
- }
- }
- }
- };
- System.out.println("Starting setAttributes1");
- startBench();
- try {
- getWorkspace().run(runnable, null);
- } catch (CoreException e) {
- fail("2.0", e);
- }
- stopBench("benchSetAttributes1", REPEAT*NUM_MARKERS);
- }
- public void benchSetAttributes2() {
- //benchmark setting many attributes in a single operation
- IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- //set one attribute per marker, repeat for all attributes
- for (int j = 0; j < REPEAT; j++) {
- for (int i = 0; i < NUM_MARKERS; i++) {
- markers[i].setAttribute("attrib", "hello");
- }
- }
- }
- };
-
- System.out.println("Starting setAttributes2");
- startBench();
- try {
- getWorkspace().run(runnable, null);
- } catch (CoreException e) {
- fail("2.0", e);
- }
- stopBench("benchSetAttributes2", REPEAT*NUM_MARKERS);
- }
- /**
- * @see EclipseWorkspaceTest#setUp()
- */
- protected void setUp() throws Exception {
- super.setUp();
-
- final IMarker[] createdMarkers = new IMarker[NUM_MARKERS];
- IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- //create resources
- project = getWorkspace().getRoot().getProject("TestProject");
- project.create(null);
- project.open(null);
- file = project.getFile(Path.ROOT.append("file.txt"));
- file.create(getRandomContents(), true, null);
- //create markers
- for (int i = 0; i < NUM_MARKERS; i++) {
- createdMarkers[i] = file.createMarker(IMarker.BOOKMARK);
- }
- }
- };
-
- try {
- getWorkspace().run(runnable, null);
- } catch (CoreException e) {
- fail("1.0", e);
- }
- markers = createdMarkers;
- }
- /**
- * @see TestCase#tearDown()
- */
- protected void tearDown() throws Exception {
- super.tearDown();
- project.delete(true, true, null);
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/perf/WorkspacePerformanceTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/perf/WorkspacePerformanceTest.java
deleted file mode 100644
index 0cb46e3..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/perf/WorkspacePerformanceTest.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.perf;
-
-import java.io.ByteArrayInputStream;
-import java.util.Random;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.tests.harness.CorePerformanceTest;
-
-/**
- * Basic performance calculations for standard workspace operations.
- */
-public class WorkspacePerformanceTest extends CorePerformanceTest {
- private static final String chars = "abcdefghijklmnopqrstuvwxyz";
- private static final String COPYING_TIMER = "COPYING_TIMER";
- private static final String CREATING_TIMER = "CREATING_TIMER";
- private static final String DELETING_TIMER = "DELETING_TIMER";
- private static final String MOVING_TIMER = "MOVING_TIMER";
-
- private static final String OVERALL_TIMER = "OVERALL_TIMER";
- private static final int TOTAL_RESOURCES = 10000;
- private static final int TREE_WIDTH = 10;
-
- public static Test suite() {
- return new TestSuite(WorkspacePerformanceTest.class);
- }
-
- private final Random random = new Random();
- public WorkspacePerformanceTest() {
- super();
- }
- public WorkspacePerformanceTest(String name) {
- super(name);
- }
- private IFolder copyFolder(IFolder source) throws CoreException {
- IFolder destination = source.getProject().getFolder("CopyDestination");
- source.copy(destination.getFullPath(), IResource.NONE, getMonitor());
- return destination;
- }
- private byte[] createBytes(int length) {
- byte[] bytes = new byte[length];
- random.nextBytes(bytes);
- return bytes;
- }
- /**
- * Creates and returns a folder with lots of contents
- */
- private IFolder createFolder(IFolder topFolder) throws CoreException {
- topFolder.create(IResource.NONE, true, getMonitor());
-
- //tree depth is log of total resource count with the width as the log base
- int depth = (int) (Math.log(TOTAL_RESOURCES) / Math.log(TREE_WIDTH));
- recursiveCreateChildren(topFolder, depth - 1);
- return topFolder;
- }
- private String createString(int length) {
- StringBuffer buf = new StringBuffer(length);
- //fill the string with random characters up to the desired length
- for (int i = 0; i < length; i++) {
- buf.append(chars.charAt(random.nextInt(chars.length())));
- }
- return buf.toString();
- }
- public void doTestWorkspaceOperations() throws CoreException {
- startTimer(OVERALL_TIMER);
- final IProject project = getWorkspace().getRoot().getProject("Project");
- project.create(getMonitor());
- project.open(getMonitor());
- final IFolder topFolder = project.getFolder("TopFolder");
-
- //create the project contents
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- startTimer(CREATING_TIMER);
- createFolder(topFolder);
- stopTimer(CREATING_TIMER);
- }
- }, getMonitor());
-
- //copy the project contents
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- startTimer(COPYING_TIMER);
- copyFolder(topFolder);
- stopTimer(COPYING_TIMER);
- }
- }, getMonitor());
-
- //move the project contents
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- startTimer(MOVING_TIMER);
- moveFolder(topFolder);
- stopTimer(MOVING_TIMER);
- }
- }, getMonitor());
-
- //delete the project contents
- getWorkspace().run(new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- startTimer(DELETING_TIMER);
- project.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, getMonitor());
- stopTimer(DELETING_TIMER);
- }
- }, getMonitor());
-
- stopTimer(OVERALL_TIMER);
- }
- private IFolder moveFolder(IFolder source) throws CoreException {
- IFolder destination = source.getProject().getFolder("MoveDestination");
- source.move(destination.getFullPath(), IResource.NONE, getMonitor());
- return destination;
- }
- /**
- * Create children of the given folder, and recurse to the given depth
- */
- private void recursiveCreateChildren(IFolder parentFolder, int depth) throws CoreException {
- //create TREE_WIDTH files
- for (int i = 0; i < TREE_WIDTH; i++) {
- IFile file = parentFolder.getFile(createString(10));
- file.create(new ByteArrayInputStream(createBytes(5000)), IResource.NONE, getMonitor());
- }
- if (depth <= 0)
- return;
- //create TREE_WIDTH folders
- for (int i = 0; i < TREE_WIDTH; i++) {
- IFolder folder = parentFolder.getFolder(createString(6));
- folder.create(IResource.NONE, true, getMonitor());
- recursiveCreateChildren(folder, depth - 1);
- }
- }
- public void testPerformance() {
-// String fileName = "c:\\temp\\" + getClassName() + "_" + System.currentTimeMillis() + ".html";
-// java.io.File logFile = new java.io.File(fileName);
-// LoggingPerformanceTestResult result = new LoggingPerformanceTestResult(logFile);
-// new WorkspacePerformanceTest("doTestWorkspaceOperations").run(result);
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/AllTests.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/AllTests.java
deleted file mode 100644
index f615c19..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/AllTests.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.regression;
-
-import junit.framework.*;
-
-public class AllTests extends TestCase {
-/**
- * AllTests constructor comment.
- * @param name java.lang.String
- */
-public AllTests() {
- super(null);
-}
-/**
- * AllTests constructor comment.
- * @param name java.lang.String
- */
-public AllTests(String name) {
- super(name);
-}
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(Bug_6708.suite());
- suite.addTest(IFileTest.suite());
- suite.addTest(IFolderTest.suite());
- suite.addTest(IProjectTest.suite());
- suite.addTest(IResourceTest.suite());
- suite.addTest(IWorkspaceTest.suite());
- suite.addTest(LocalStoreRegressionTests.suite());
- suite.addTest(NLTest.suite());
- suite.addTest(PR_1GEAB3C_Test.suite());
- suite.addTest(PR_1GH2B0N_Test.suite());
- suite.addTest(PR_1GHOM0N_Test.suite());
- suite.addTest(Bug_25457.suite());
- suite.addTest(Bug_26294.suite());
- suite.addTest(Bug_27271.suite());
- suite.addTest(Bug_28981.suite());
- suite.addTest(Bug_29116.suite());
- suite.addTest(Bug_29671.suite());
- suite.addTest(Bug_32076.suite());
- return suite;
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_25457.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_25457.java
deleted file mode 100644
index b36c7c7..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_25457.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.regression;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.boot.BootLoader;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-/**
- * Tests regression of bug 25457. In this case, attempting to move a project
- * that is only a case change, where the move fails due to another handle being
- * open on a file in the hierarchy, would cause deletion of the source.
- */
-public class Bug_25457 extends EclipseWorkspaceTest {
- public static Test suite() {
- return new TestSuite(Bug_25457.class);
- }
- public Bug_25457() {
- super();
- }
- public Bug_25457(String name) {
- super(name);
- }
- public void testFile() {
- //this test only works on windows
- if (!BootLoader.getOS().equals(BootLoader.OS_WIN32))
- return;
- IProject source = getWorkspace().getRoot().getProject("project");
- IFile sourceFile = source.getFile("file.txt");
- IFile destFile = source.getFile("File.txt");
- ensureExistsInWorkspace(source, true);
- ensureExistsInWorkspace(sourceFile, true);
-
- //open a stream in the source to cause the rename to fail
- InputStream stream = null;
- try {
- try {
- stream = sourceFile.getContents();
- } catch (CoreException e) {
- fail("0.99", e);
- }
- //try to rename the file (should fail)
- try {
- sourceFile.move(destFile.getFullPath(), IResource.NONE, getMonitor());
- fail("1.99");
- } catch (CoreException e1) {
- //should fail
- }
- //ensure source still exists
- assertTrue("2.0", source.exists());
- assertTrue("2.1", sourceFile.exists());
-
- //ensure destination file does not exist
- assertTrue("2.2", !destFile.exists());
-
- } finally {
- if (stream != null) {
- try {
- stream.close();
- } catch (IOException e) {
- fail("9.99", e);
- }
- }
- }
- }
- public void testFolder() {
- //this test only works on windows
- if (!BootLoader.getOS().equals(BootLoader.OS_WIN32))
- return;
- IProject source = getWorkspace().getRoot().getProject("SourceProject");
- IFolder sourceFolder = source.getFolder("folder");
- IFile sourceFile = sourceFolder.getFile("Important.txt");
- IFolder destFolder = source.getFolder("Folder");
- IFile destFile = destFolder.getFile("Important.txt");
- ensureExistsInWorkspace(source, true);
- ensureExistsInWorkspace(sourceFolder, true);
- ensureExistsInWorkspace(sourceFile, true);
-
- //open a stream in the source to cause the rename to fail
- InputStream stream = null;
- try {
- try {
- stream = sourceFile.getContents();
- } catch (CoreException e) {
- fail("0.99", e);
- }
- //try to rename the project (should fail)
- try {
- sourceFolder.move(destFolder.getFullPath(), IResource.NONE, getMonitor());
- fail("1.99");
- } catch (CoreException e1) {
- //should fail
- }
- //ensure source still exists
- assertTrue("2.0", source.exists());
- assertTrue("2.1", sourceFolder.exists());
- assertTrue("2.2", sourceFile.exists());
-
- //ensure destination does not exist
- assertTrue("2.3", !destFolder.exists());
- assertTrue("2.4", !destFile.exists());
-
- } finally {
- if (stream != null) {
- try {
- stream.close();
- } catch (IOException e) {
- fail("9.99", e);
- }
- }
- }
- }
- public void testProject() {
- //this test only works on windows
- if (!BootLoader.getOS().equals(BootLoader.OS_WIN32))
- return;
- IProject source = getWorkspace().getRoot().getProject("project");
- IProject destination = getWorkspace().getRoot().getProject("Project");
- IFile sourceFile = source.getFile("Important.txt");
- IFile destFile = destination.getFile("Important.txt");
- ensureExistsInWorkspace(source, true);
- ensureExistsInWorkspace(sourceFile, true);
-
- //open a stream in the source to cause the rename to fail
- InputStream stream = null;
- try {
- try {
- stream = sourceFile.getContents();
- } catch (CoreException e) {
- fail("1.99", e);
- }
- //try to rename the project (should fail)
- try {
- source.move(destination.getFullPath(), IResource.NONE, getMonitor());
- fail("1.99");
- } catch (CoreException e1) {
- //should fail
- }
- //ensure source still exists
- assertTrue("2.0", source.exists());
- assertTrue("2.1", sourceFile.exists());
-
- //ensure destination does not exist
- assertTrue("2.2", !destination.exists());
- assertTrue("2.3", !destFile.exists());
-
- } finally {
- if (stream != null) {
- try {
- stream.close();
- } catch (IOException e) {
- fail("9.99", e);
- }
- }
- }
-
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_26294.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_26294.java
deleted file mode 100644
index d67e994..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_26294.java
+++ /dev/null
@@ -1,457 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.regression;
-
-import java.io.*;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.eclipse.core.boot.BootLoader;
-import org.eclipse.core.internal.localstore.CoreFileSystemLibrary;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-/**
- * A parent container (projects and folders) would become out-of-sync if any of
- * its children could not be deleted for some reason. These platform-
- * specific test cases ensure that it does not happen.
- */
-public class Bug_26294 extends EclipseWorkspaceTest {
-
- public Bug_26294(String name) {
- super(name);
- }
- public static Test suite() {
- return new TestSuite(Bug_26294.class);
- }
- /**
- * Tries to delete an open project containing an irremovable file.
- * Works only for Windows.
- */
- public void testDeleteOpenProjectWindows() {
- if (!(BootLoader.getOS().equals(BootLoader.OS_WIN32)))
- return;
-
- IProject project = null;
- InputStream input = null;
- File projectRoot = null;
- try {
- IWorkspace workspace = getWorkspace();
- project = workspace.getRoot().getProject("MyProject");
- IFolder folder = project.getFolder("a_folder");
- IFile file1 = folder.getFile("file1.txt");
- IFile file2 = project.getFile("file2.txt");
- IFile file3 = folder.getFile("file3.txt");
-
- ensureExistsInWorkspace(new IResource[] { file1, file2, file3 }, true);
- projectRoot = project.getLocation().toFile();
-
- // opens a file so it cannot be removed on Windows
- try {
- input = file1.getContents();
- } catch (CoreException ce) {
- ce.printStackTrace();
- fail("1.0");
- }
-
- IFile projectFile = project.getFile(new Path(".project"));
- assertTrue("1.2", projectFile.exists());
- assertTrue("1.3", projectFile.isSynchronized(IResource.DEPTH_INFINITE));
-
- try {
- project.delete(IResource.FORCE, getMonitor());
- fail("2.0 - should have failed");
- } catch (CoreException ce) {
- // success - a file couldn't be removed
- }
- assertTrue("2.1", project.exists());
- assertTrue("2.2", file1.exists());
- assertTrue("2.3", !file2.exists());
- assertTrue("2.4", !file3.exists());
- assertTrue("2.5", folder.exists());
- assertTrue("2.6", !projectFile.exists());
- assertTrue("2.7", project.isSynchronized(IResource.DEPTH_INFINITE));
-
- try {
- input.close();
- } catch (IOException ioe) {
- ioe.printStackTrace();
- fail("3.0", ioe);
- }
-
- assertTrue("3.5", project.isSynchronized(IResource.DEPTH_INFINITE));
- try {
- project.delete(IResource.FORCE, getMonitor());
- } catch (CoreException ce) {
- ce.printStackTrace();
- fail("4.0", ce);
- }
-
- assertTrue("5.1", !project.exists());
- assertTrue("5.2", !file1.exists());
- assertTrue("5.3", file1.isSynchronized(IResource.DEPTH_INFINITE));
- assertTrue("5.4", project.isSynchronized(IResource.DEPTH_INFINITE));
-
- assertTrue("6.0", !projectRoot.exists());
- } finally {
- try {
- if (input != null)
- input.close();
- } catch (IOException e) {
- fail("7.0", e);
- } finally {
- if (projectRoot != null)
- ensureDoesNotExistInFileSystem(projectRoot);
- }
- }
- }
- /**
- * Tries to delete an open project containing an irremovable file.
- * Works only for Linux with natives.
- */
- public void testDeleteOpenProjectLinux() {
- if (!(BootLoader.getOS().equals(BootLoader.OS_LINUX) && CoreFileSystemLibrary.usingNatives()))
- return;
-
- IProject project = null;
- File projectRoot = null;
- IFolder folder = null;
- try {
- IWorkspace workspace = getWorkspace();
- project = workspace.getRoot().getProject("MyProject");
- folder = project.getFolder("a_folder");
- IFile file1 = folder.getFile("file1.txt");
- IFile file2 = project.getFile("file2.txt");
-
- ensureExistsInWorkspace(new IResource[] { file1, file2 }, true);
- projectRoot = project.getLocation().toFile();
-
- // marks folder as read-only so its files cannot be deleted on Linux
- folder.setReadOnly(true);
-
- IFile projectFile = project.getFile(new Path(".project"));
- assertTrue("1.2", projectFile.exists());
- assertTrue("1.3", projectFile.isSynchronized(IResource.DEPTH_INFINITE));
-
- try {
- project.delete(IResource.FORCE, getMonitor());
- fail("2.0 - should have failed");
- } catch (CoreException ce) {
- // success - a file couldn't be removed
- }
- assertTrue("2.1", project.exists());
- assertTrue("2.2", file1.exists());
- assertTrue("2.3", !file2.exists());
- assertTrue("2.5", folder.exists());
- assertTrue("2.6", !projectFile.exists());
- assertTrue("2.7", project.isSynchronized(IResource.DEPTH_INFINITE));
-
- folder.setReadOnly(false);
-
- assertTrue("3.5", project.isSynchronized(IResource.DEPTH_INFINITE));
- try {
- project.delete(IResource.FORCE, getMonitor());
- } catch (CoreException ce) {
- ce.printStackTrace();
- fail("4.0", ce);
- }
-
- assertTrue("5.1", !project.exists());
- assertTrue("5.2", !file1.exists());
- assertTrue("5.3", file1.isSynchronized(IResource.DEPTH_INFINITE));
- assertTrue("5.4", project.isSynchronized(IResource.DEPTH_INFINITE));
-
- assertTrue("6.0", !projectRoot.exists());
- } finally {
- if (folder != null && folder.exists())
- folder.setReadOnly(false);
- if (projectRoot != null)
- ensureDoesNotExistInFileSystem(projectRoot);
- }
- }
-
- /**
- * Tries to delete a closed project containing an irremovable file.
- * Works only for Windows.
- */
- public void testDeleteClosedProjectWindows() {
- if (!BootLoader.getOS().equals(BootLoader.OS_WIN32))
- return;
-
- IProject project = null;
- InputStream input = null;
- File projectRoot = null;
- IFile file1 = null;
- try {
- IWorkspace workspace = getWorkspace();
- project = workspace.getRoot().getProject("MyProject");
- IFolder folder = project.getFolder("a_folder");
- file1 = folder.getFile("file1.txt");
- IFile file2 = project.getFile("file2.txt");
- IFile file3 = folder.getFile("file3.txt");
-
- ensureExistsInWorkspace(new IResource[] { file1, file2, file3 }, true);
-
- projectRoot = project.getLocation().toFile();
-
- // opens a file so it cannot be removed on Windows
- try {
- input = file1.getContents();
- } catch (CoreException ce) {
- ce.printStackTrace();
- fail("1.0");
- }
-
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("1.1", e);
- }
-
- try {
- project.delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, getMonitor());
- fail("2.0 - should have failed");
- } catch (CoreException ce) {
- // success - a file couldn't be removed
- }
- assertTrue("2.1", project.exists());
- assertTrue("2.7", project.isSynchronized(IResource.DEPTH_INFINITE));
-
- try {
- input.close();
- } catch (IOException ioe) {
- ioe.printStackTrace();
- fail("3.0", ioe);
- }
-
- assertTrue("3.5", project.isSynchronized(IResource.DEPTH_INFINITE));
- try {
- project.delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, getMonitor());
- } catch (CoreException ce) {
- ce.printStackTrace();
- fail("4.0", ce);
- }
-
- assertTrue("5.1", !project.exists());
- assertTrue("5.3", project.isSynchronized(IResource.DEPTH_INFINITE));
- assertTrue("6.0", !projectRoot.exists());
- } finally {
- try {
- if (input != null)
- input.close();
- } catch (IOException e) {
- fail("7.0", e);
- } finally {
- if (projectRoot != null)
- ensureDoesNotExistInFileSystem(projectRoot);
- }
- }
- }
- /**
- * Tries to delete a closed project containing an irremovable file.
- * Works only for Linux with natives.
- */
- public void testDeleteClosedProjectLinux() {
- if (!(BootLoader.getOS().equals(BootLoader.OS_LINUX) && CoreFileSystemLibrary.usingNatives()))
- return;
-
- IProject project = null;
- File projectRoot = null;
- IFolder folder = null;
- try {
- IWorkspace workspace = getWorkspace();
- project = workspace.getRoot().getProject("MyProject");
- folder = project.getFolder("a_folder");
- IFile file1 = folder.getFile("file1.txt");
- IFile file2 = project.getFile("file2.txt");
-
- ensureExistsInWorkspace(new IResource[] { file1, file2 }, true);
-
- projectRoot = project.getLocation().toFile();
-
- // marks folder as read-only so its files cannot be removed on Linux
- folder.setReadOnly(true);
-
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("1.1", e);
- }
-
- try {
- project.delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, getMonitor());
- fail("2.0 - should have failed");
- } catch (CoreException ce) {
- // success - a file couldn't be removed
- }
- assertTrue("2.1", project.exists());
- assertTrue("2.7", project.isSynchronized(IResource.DEPTH_INFINITE));
-
- folder.setReadOnly(false);
-
- assertTrue("3.5", project.isSynchronized(IResource.DEPTH_INFINITE));
- try {
- project.delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, getMonitor());
- } catch (CoreException ce) {
- ce.printStackTrace();
- fail("4.0", ce);
- }
-
- assertTrue("5.1", !project.exists());
- assertTrue("5.3", project.isSynchronized(IResource.DEPTH_INFINITE));
- assertTrue("6.0", !projectRoot.exists());
- } finally {
- if (folder != null && folder.exists())
- folder.setReadOnly(false);
- if (projectRoot != null)
- ensureDoesNotExistInFileSystem(projectRoot);
- }
- }
-
- /**
- * Tries to delete a folder containing an irremovable file.
- * Works only for Windows.
- */
- public void testDeleteFolderWindows() {
- if (!BootLoader.getOS().equals(BootLoader.OS_WIN32))
- return;
-
- IProject project = null;
- InputStream input = null;
- File projectRoot = null;
- try {
- IWorkspace workspace = getWorkspace();
- project = workspace.getRoot().getProject("MyProject");
- IFolder folder = project.getFolder("a_folder");
- IFile file1 = folder.getFile("file1.txt");
- IFile file3 = folder.getFile("file3.txt");
-
- ensureExistsInWorkspace(new IResource[] { file1, file3 }, true);
- projectRoot = project.getLocation().toFile();
-
- // opens a file so it cannot be removed on Windows
- try {
- input = file1.getContents();
- } catch (CoreException ce) {
- ce.printStackTrace();
- fail("1.0");
- }
-
- try {
- folder.delete(IResource.FORCE, getMonitor());
- fail("2.0 - should have failed");
- } catch (CoreException ce) {
- // success - a file couldn't be removed
- }
- assertTrue("2.2", file1.exists());
- assertTrue("2.4", !file3.exists());
- assertTrue("2.5", folder.exists());
- assertTrue("2.7", folder.isSynchronized(IResource.DEPTH_INFINITE));
-
- try {
- input.close();
- } catch (IOException ioe) {
- ioe.printStackTrace();
- fail("3.0", ioe);
- }
-
- assertTrue("3.5", project.isSynchronized(IResource.DEPTH_INFINITE));
- try {
- folder.delete(IResource.FORCE, getMonitor());
- } catch (CoreException ce) {
- ce.printStackTrace();
- fail("4.0", ce);
- }
- assertTrue("5.1", !file1.exists());
- assertTrue("5.2", !folder.exists());
- assertTrue("5.3", file1.isSynchronized(IResource.DEPTH_INFINITE));
- assertTrue("5.4", folder.isSynchronized(IResource.DEPTH_INFINITE));
- } finally {
- try {
- if (input != null)
- input.close();
- } catch (IOException e) {
- fail("7.0", e);
- } finally {
- if (projectRoot != null)
- ensureDoesNotExistInFileSystem(projectRoot);
- }
- }
- }
- /**
- * Tries to delete a folder containing an irremovable file.
- * Works only for Linux with natives.
- */
- public void testDeleteFolderLinux() {
- if (!(BootLoader.getOS().equals(BootLoader.OS_LINUX) && CoreFileSystemLibrary.usingNatives()))
- return;
-
- IProject project = null;
- File projectRoot = null;
- IFolder subFolder = null;
- try {
- IWorkspace workspace = getWorkspace();
- project = workspace.getRoot().getProject("MyProject");
- IFolder folder = project.getFolder("a_folder");
- subFolder = folder.getFolder("sub-folder");
- IFile file1 = subFolder.getFile("file1.txt");
- IFile file3 = folder.getFile("file3.txt");
-
- ensureExistsInWorkspace(new IResource[] { file1, file3 }, true);
- projectRoot = project.getLocation().toFile();
-
- // marks sub-folder as read-only so its files cannot be removed on Linux
- subFolder.setReadOnly(true);
-
- try {
- folder.delete(IResource.FORCE, getMonitor());
- fail("2.0 - should have failed");
- } catch (CoreException ce) {
- // success - a file couldn't be removed
- }
- assertTrue("2.2", file1.exists());
- assertTrue("2.3", subFolder.exists());
- assertTrue("2.4", !file3.exists());
- assertTrue("2.5", folder.exists());
- assertTrue("2.7", folder.isSynchronized(IResource.DEPTH_INFINITE));
-
- subFolder.setReadOnly(false);
-
- assertTrue("3.5", project.isSynchronized(IResource.DEPTH_INFINITE));
- try {
- folder.delete(IResource.FORCE, getMonitor());
- } catch (CoreException ce) {
- ce.printStackTrace();
- fail("4.0", ce);
- }
- assertTrue("5.1", !file1.exists());
- assertTrue("5.2", !subFolder.exists());
- assertTrue("5.3", !folder.exists());
- assertTrue("5.4", file1.isSynchronized(IResource.DEPTH_INFINITE));
- assertTrue("5.5", folder.isSynchronized(IResource.DEPTH_INFINITE));
- } finally {
- if (subFolder != null && subFolder.exists())
- subFolder.setReadOnly(false);
- if (projectRoot != null)
- ensureDoesNotExistInFileSystem(projectRoot);
- }
- }
-
- /**
- * @see org.eclipse.core.tests.harness.EclipseWorkspaceTest#tearDown()
- */
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_27271.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_27271.java
deleted file mode 100644
index fdab760..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_27271.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.regression;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.eclipse.core.resources.IPathVariableManager;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-/**
- * Tests how changes in the underlying preference store may affect the path
- * variable manager.
- */
-
-public class Bug_27271 extends EclipseWorkspaceTest {
-
- static final String VARIABLE_PREFIX = "pathvariable."; //$NON-NLS-1$
-
- private Preferences preferences;
-
- public Bug_27271(String name) {
- super(name);
- }
- protected void setUp() throws Exception {
- super.setUp();
- preferences = ResourcesPlugin.getPlugin().getPluginPreferences();
- clearPathVariablesProperties();
- }
- protected void tearDown() throws Exception {
- clearPathVariablesProperties();
- super.tearDown();
- }
- private void clearPathVariablesProperties() {
- // ensure we have no preferences related to path variables
- String[] propertyNames = preferences.propertyNames();
- for (int i = 0; i < propertyNames.length; i++)
- if (propertyNames[i].startsWith(VARIABLE_PREFIX))
- preferences.setToDefault(propertyNames[i]);
- }
- public static Test suite() {
- return new TestSuite(Bug_27271.class);
- }
- public void testBug() {
- IPathVariableManager pvm = getWorkspace().getPathVariableManager();
- Preferences preferences = ResourcesPlugin.getPlugin().getPluginPreferences();
-
- assertEquals("1.0", 0, pvm.getPathVariableNames().length);
- preferences.setValue(VARIABLE_PREFIX + "VALID_VAR", new Path("c:/temp").toString());
- assertEquals("1.1", 1, pvm.getPathVariableNames().length);
- assertEquals("1.2", "VALID_VAR", pvm.getPathVariableNames()[0]);
-
- //sets invalid value (relative path)
- IPath relativePath = new Path("temp");
- preferences.setValue(VARIABLE_PREFIX + "INVALID_VAR", relativePath.toString());
- assertEquals("2.0", 1, pvm.getPathVariableNames().length);
- assertEquals("2.1", "VALID_VAR", pvm.getPathVariableNames()[0]);
-
- //sets invalid value (invalid path)
- IPath invalidPath = new Path("c:\\a\\:\\b");
- preferences.setValue(VARIABLE_PREFIX + "ANOTHER_INVALID_VAR", invalidPath.toString());
- assertTrue("3.0", !Path.EMPTY.isValidPath(invalidPath.toString()));
- assertEquals("3.1", 1, pvm.getPathVariableNames().length);
- assertEquals("3.2", "VALID_VAR", pvm.getPathVariableNames()[0]);
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_28981.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_28981.java
deleted file mode 100644
index d702a50..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_28981.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.regression;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.QualifiedName;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-import org.eclipse.core.tests.resources.ResourceVisitorVerifier;
-
-/**
- * Resource#accept doesn't obey member flags for the traversal entry point.
- */
-
-public class Bug_28981 extends EclipseWorkspaceTest {
- public Bug_28981(String name) {
- super(name);
- }
- protected void setUp() throws Exception {
- super.setUp();
- }
- protected void tearDown() throws Exception {
- super.tearDown();
- }
- public void testBug() {
- final QualifiedName partner = new QualifiedName("org.eclipse.core.tests.resources", "myTarget");
- final IWorkspace workspace = getWorkspace();
- final ISynchronizer synchronizer = workspace.getSynchronizer();
- synchronizer.add(partner);
-
- IProject project = workspace.getRoot().getProject("MyProject");
- IFile teamPrivateFile = project.getFile("teamPrivate.txt");
- IFile phantomFile = project.getFile("phantom.txt");
- IFile regularFile = project.getFile("regular.txt");
- IFile projectDescriptionFile = project.getFile(".project");
-
- ensureExistsInWorkspace(new IResource[] { teamPrivateFile, regularFile }, true);
- try {
- synchronizer.setSyncInfo(partner, phantomFile, getRandomString().getBytes());
- } catch (CoreException e) {
- e.printStackTrace();
- fail("0.5");
- }
- try {
- teamPrivateFile.setTeamPrivateMember(true);
- } catch (CoreException e) {
- e.printStackTrace();
- fail("0.6");
- }
- assertTrue("0.7", !regularFile.isPhantom() && !regularFile.isTeamPrivateMember());
- assertTrue("0.8", teamPrivateFile.isTeamPrivateMember());
- assertTrue("0.8b", teamPrivateFile.exists());
- assertTrue("0.9", phantomFile.isPhantom());
- assertTrue("0.9b", !phantomFile.exists());
-
- ResourceVisitorVerifier verifier = new ResourceVisitorVerifier();
-
- verifier.addExpected(project);
- verifier.addExpected(projectDescriptionFile);
- verifier.addExpected(regularFile);
- try {
- project.accept(verifier);
- } catch (CoreException e) {
- fail("1.0", e);
- }
- assertTrue("1.1 - " + verifier.getMessage(), verifier.isValid());
-
- verifier.reset();
- try {
- phantomFile.accept(verifier);
- fail("2.0 - should fail");
- } catch (CoreException e) {
- //success
- }
-
- verifier.reset();
- verifier.addExpected(phantomFile);
- try {
- phantomFile.accept(verifier, IResource.DEPTH_INFINITE, IContainer.INCLUDE_PHANTOMS);
- } catch (CoreException e) {
- fail("3.0", e);
- }
- assertTrue("3.1 - " + verifier.getMessage(), verifier.isValid());
-
- verifier.reset();
- // no resources should be visited
- try {
- teamPrivateFile.accept(verifier);
- } catch (CoreException e) {
- fail("4.0", e);
- }
- assertTrue("4.1 - " + verifier.getMessage(), verifier.isValid());
-
- verifier.reset();
- verifier.addExpected(teamPrivateFile);
- try {
- teamPrivateFile.accept(verifier, IResource.DEPTH_INFINITE, IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
- } catch (CoreException e) {
- fail("5.0", e);
- }
- assertTrue("5.1 - " + verifier.getMessage(), verifier.isValid());
- }
- public static Test suite() {
- return new TestSuite(Bug_28981.class);
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_29116.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_29116.java
deleted file mode 100644
index f4ab5d6..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_29116.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.regression;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectDescription;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-/**
- * Test regression of bug 29116. In this bug, triggering a builder during
- * installation of a nature caused an assertion failure.
- */
-public class Bug_29116 extends EclipseWorkspaceTest {
- public Bug_29116() {
- super();
- }
- public Bug_29116(String name) {
- super(name);
- }
- public static Test suite() {
- return new TestSuite(Bug_29116.class);
- }
- public void testBug() {
- // Create some resource handles
- IProject project = getWorkspace().getRoot().getProject("PROJECT");
-
- try {
- // Create and open a project
- project.create(getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- // Create and set a build spec for the project
- try {
- IProjectDescription desc = project.getDescription();
- desc.setNatureIds(new String[] {NATURE_29116});
- project.setDescription(desc, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
- }
-
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_29671.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_29671.java
deleted file mode 100644
index 3e52fa6..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_29671.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.regression;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.QualifiedName;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-/**
- * When a container was moved, its children were not added to phantom space.
- *
- */
-public class Bug_29671 extends EclipseWorkspaceTest {
-
- public Bug_29671(String name) {
- super(name);
- }
- public static Test suite() {
- return new TestSuite(Bug_29671.class);
- }
- public void testBug() {
- final QualifiedName partner = new QualifiedName("org.eclipse.core.tests.resources", "myTarget");
- IWorkspace workspace = getWorkspace();
- final ISynchronizer synchronizer = workspace.getSynchronizer();
- synchronizer.add(partner);
-
- IProject project = workspace.getRoot().getProject("MyProject");
- IFolder folder = project.getFolder("source");
- IFile file = folder.getFile("file.txt");
-
- ensureExistsInWorkspace(file, true);
-
- try {
- // sets sync info for the folder and its children
- try {
- synchronizer.setSyncInfo(partner, folder, getRandomString().getBytes());
- synchronizer.setSyncInfo(partner, file, getRandomString().getBytes());
- } catch (CoreException ce) {
- fail("1.0", ce);
- }
-
- IFolder targetFolder = project.getFolder("target");
- IFile targetFile = targetFolder.getFile(file.getName());
-
- try {
- folder.move(targetFolder.getFullPath(), false, false, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
- assertTrue("3.0", folder.isPhantom());
- assertTrue("4.0", file.isPhantom());
-
- assertExistsInWorkspace("5.0", targetFolder);
- assertTrue("5.1", !targetFolder.isPhantom());
-
- assertExistsInWorkspace("6.0", targetFile);
- assertTrue("6.1", !targetFile.isPhantom());
- } finally {
- synchronizer.remove(partner);
- }
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_32076.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_32076.java
deleted file mode 100644
index 2bff923..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_32076.java
+++ /dev/null
@@ -1,567 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.regression;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.eclipse.core.boot.BootLoader;
-import org.eclipse.core.internal.localstore.CoreFileSystemLibrary;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-/**
- * When moving a resource "x" from parent "a" to parent "b", if "x" or any of
- * its children can't be deleted, both "a" and "b" become out-of-sync and resource info is lost.
- */
-public class Bug_32076 extends EclipseWorkspaceTest {
-
- public Bug_32076() {
- super("");
- }
- public Bug_32076(String name) {
- super(name);
- }
- public static Test suite() {
- return new TestSuite(Bug_32076.class);
- }
- public void testFileBugOnWindows() {
- if (!BootLoader.getOS().equals(BootLoader.OS_WIN32))
- return;
-
- InputStream input = null;
- IProject project = null;
- try {
- IWorkspace workspace = getWorkspace();
- project = project = workspace.getRoot().getProject("MyProject");
- IFolder sourceParent = project.getFolder("source_parent");
- IFolder destinationParent = project.getFolder("destination_parent");
- // this file will be made irremovable
- IFile sourceFile = sourceParent.getFile("file1.txt");
- IFile destinationFile = destinationParent.getFile(sourceFile.getName());
-
- ensureExistsInWorkspace(new IResource[] { sourceFile, destinationParent }, true);
-
- // add a marker to a file to ensure the move operation is not losing anything
- String attributeKey = getRandomString();
- String attributeValue = getRandomString();
- long markerId = -1;
- try {
- IMarker bookmark = null;
- bookmark = sourceFile.createMarker(IMarker.BOOKMARK);
- bookmark.setAttribute(attributeKey, attributeValue);
- markerId = bookmark.getId();
- } catch (CoreException e) {
- fail("0.1", e);
- }
-
- // opens the file so it cannot be removed on Windows
- try {
- input = sourceFile.getContents();
- } catch (CoreException ce) {
- fail("1.0");
- }
-
- try {
- sourceFile.move(destinationFile.getFullPath(), IResource.FORCE, getMonitor());
- fail("2.0");
- } catch (CoreException ce) {
- // success
- }
-
- // the source parent is out-of-sync
- assertTrue("3.0", !sourceParent.isSynchronized(IResource.DEPTH_INFINITE));
- // the target parent is in-sync
- assertTrue("3.1", destinationParent.isSynchronized(IResource.DEPTH_INFINITE));
-
- // file has been copied to destination
- assertTrue("3.4", destinationFile.exists());
-
- // ensure marker info has not been lost
- try {
- IMarker marker = destinationFile.findMarker(markerId);
- assertNotNull("3.6", marker);
- assertEquals("3.7", attributeValue, marker.getAttribute(attributeKey));
- } catch (CoreException e) {
- fail("3.8", e);
- }
-
- // non-removable file has been moved (but not in file system - they are out-of-sync)
- assertTrue("4.1", !sourceFile.exists());
-
- // refresh the source parent
- try {
- sourceParent.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- } catch (CoreException e) {
- fail("4.4");
- }
-
- // non-removable file now reappear in the resource tree
- assertTrue("4.7", sourceFile.exists());
-
- } finally {
- try {
- if (input != null)
- input.close();
- } catch (IOException e) {
- fail("5.0", e);
- } finally {
- if (project != null)
- ensureDoesNotExistInFileSystem(project);
- }
- }
- }
-
- public void testFolderBugOnWindows() {
- if (!BootLoader.getOS().equals(BootLoader.OS_WIN32))
- return;
-
- InputStream input = null;
- IProject project = null;
- try {
- IWorkspace workspace = getWorkspace();
- project = project = workspace.getRoot().getProject("MyProject");
- IFolder sourceParent = project.getFolder("source_parent");
- IFolder destinationParent = project.getFolder("destination_parent");
- IFolder folder = sourceParent.getFolder("folder");
- IFolder destinationFolder = destinationParent.getFolder(folder.getName());
- // this file will be made irremovable
- IFile file1 = folder.getFile("file1.txt");
- // but not this one
- IFile file2 = folder.getFile("file2.txt");
-
- ensureExistsInWorkspace(new IResource[] { file1, file2, destinationParent }, true);
-
- // add a marker to a file to ensure the move operation is not losing anything
- String attributeKey = getRandomString();
- String attributeValue = getRandomString();
- long markerId = -1;
- try {
- IMarker bookmark = null;
- bookmark = file1.createMarker(IMarker.BOOKMARK);
- bookmark.setAttribute(attributeKey, attributeValue);
- markerId = bookmark.getId();
- } catch (CoreException e) {
- fail("0.1", e);
- }
-
- // opens a file so it (and its parent) cannot be removed on Windows
- try {
- input = file1.getContents();
- } catch (CoreException ce) {
- fail("1.0", ce);
- }
-
- try {
- folder.move(destinationFolder.getFullPath(), IResource.FORCE, getMonitor());
- fail("2.0");
- } catch (CoreException ce) {
- // success
- }
-
- // the source parent is out-of-sync
- assertTrue("3.0", !sourceParent.isSynchronized(IResource.DEPTH_INFINITE));
- // the target parent is in-sync
- assertTrue("3.1", destinationParent.isSynchronized(IResource.DEPTH_INFINITE));
-
- // resources have been copied to destination
- assertTrue("3.3", destinationFolder.exists());
- assertTrue("3.4", destinationFolder.getFile(file1.getName()).exists());
- assertTrue("3.5", destinationFolder.getFile(file2.getName()).exists());
-
- // ensure marker info has not been lost
- try {
- IMarker marker = destinationFolder.getFile(file1.getName()).findMarker(markerId);
- assertNotNull("3.6", marker);
- assertEquals("3.7", attributeValue, marker.getAttribute(attributeKey));
- } catch (CoreException e) {
- fail("3.8", e);
- }
-
- // non-removable resources have been moved (but not in file system - they are out-of-sync)
- assertTrue("4.1", !folder.exists());
- assertTrue("4.2", !file1.exists());
- assertTrue("4.3", !file2.exists());
-
- // refresh the source parent
- try {
- sourceParent.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- } catch (CoreException e) {
- fail("4.4");
- }
-
- // non-removable resources now reappear in the resource tree
- assertTrue("4.6", folder.exists());
- assertTrue("4.7", file1.exists());
- assertTrue("4.8", !file2.exists());
-
- } finally {
- try {
- if (input != null)
- input.close();
- } catch (IOException e) {
- fail("5.0", e);
- } finally {
- if (project != null)
- ensureDoesNotExistInFileSystem(project);
- }
- }
- }
- public void testProjectBugOnWindows() {
- if (!BootLoader.getOS().equals(BootLoader.OS_WIN32))
- return;
-
- IProject sourceProject = null;
- IProject destinationProject = null;
- InputStream input = null;
- try {
- IWorkspace workspace = getWorkspace();
- sourceProject = workspace.getRoot().getProject("SourceProject");
- destinationProject = workspace.getRoot().getProject("DestinationProject");
- // this file will be made irremovable
- IFile file1 = sourceProject.getFile("file1.txt");
- // but not this one
- IFile file2 = sourceProject.getFile("file2.txt");
-
- ensureExistsInWorkspace(new IResource[] { file1, file2 }, true);
-
- // add a marker to a file to ensure the move operation is not losing anything
- String attributeKey = getRandomString();
- String attributeValue = getRandomString();
- long markerId = -1;
- try {
- IMarker bookmark = null;
- bookmark = file1.createMarker(IMarker.BOOKMARK);
- bookmark.setAttribute(attributeKey, attributeValue);
- markerId = bookmark.getId();
- } catch (CoreException e) {
- fail("0.1", e);
- }
-
- // opens a file so it (and its parent) cannot be removed on Windows
- try {
- input = file1.getContents();
- } catch (CoreException ce) {
- fail("1.0", ce);
- }
-
- try {
- sourceProject.move(destinationProject.getFullPath(), IResource.FORCE, getMonitor());
- fail("2.0");
- } catch (CoreException ce) {
- // success
- }
-
- // the source does not exist
- assertTrue("3.0", !sourceProject.exists());
- // the target exists and is in sync
- assertTrue("3.1", destinationProject.exists());
- assertTrue("3.2", destinationProject.isSynchronized(IResource.DEPTH_INFINITE));
-
- // resources have been copied to destination
- assertTrue("3.4", destinationProject.getFile(file1.getProjectRelativePath()).exists());
- assertTrue("3.5", destinationProject.getFile(file2.getProjectRelativePath()).exists());
-
- // ensure marker info has not been lost
- try {
- IMarker marker = destinationProject.getFile(file1.getProjectRelativePath()).findMarker(markerId);
- assertNotNull("3.6", marker);
- assertEquals("3.7", attributeValue, marker.getAttribute(attributeKey));
- } catch (CoreException e) {
- fail("3.8", e);
- }
-
- assertTrue("4.0", !sourceProject.exists());
-
- assertTrue("5.0", workspace.getRoot().isSynchronized(IResource.DEPTH_INFINITE));
-
- } finally {
- try {
- if (input != null)
- input.close();
- } catch (IOException e) {
- fail("6.0", e);
- } finally {
- if (sourceProject != null)
- ensureDoesNotExistInFileSystem(sourceProject);
- if (destinationProject != null)
- ensureDoesNotExistInFileSystem(destinationProject);
- }
- }
- }
-
- public void testFileBugOnLinux() {
- if (!(BootLoader.getOS().equals(BootLoader.OS_LINUX) && CoreFileSystemLibrary.usingNatives()))
- return;
-
- IPath roFolderLocation = null;
- IProject project = null;
- try {
- IWorkspace workspace = getWorkspace();
- project = project = workspace.getRoot().getProject("MyProject");
- IFolder sourceParent = project.getFolder("source_parent");
- IFolder roFolder = sourceParent.getFolder("sub-folder");
- IFolder destinationParent = project.getFolder("destination_parent");
- // this file will be made irremovable
- IFile sourceFile = roFolder.getFile("file.txt");
- IFile destinationFile = destinationParent.getFile("file.txt");
-
- ensureExistsInWorkspace(new IResource[] { sourceFile, destinationParent }, true);
-
- roFolderLocation = roFolder.getLocation();
-
- // add a marker to a file to ensure the move operation is not losing anything
- String attributeKey = getRandomString();
- String attributeValue = getRandomString();
- long markerId = -1;
- try {
- IMarker bookmark = null;
- bookmark = sourceFile.createMarker(IMarker.BOOKMARK);
- bookmark.setAttribute(attributeKey, attributeValue);
- markerId = bookmark.getId();
- } catch (CoreException e) {
- fail("0.1", e);
- }
-
- // mark sub-folder as read-only so its immediate children cannot be removed on Linux
- roFolder.setReadOnly(true);
- try {
- sourceFile.move(destinationFile.getFullPath(), IResource.FORCE, getMonitor());
- fail("2.0");
- } catch (CoreException ce) {
- // success
- }
-
- // the source parent is out-of-sync
- assertTrue("3.0", !sourceParent.isSynchronized(IResource.DEPTH_INFINITE));
- // the target parent is in-sync
- assertTrue("3.1", destinationParent.isSynchronized(IResource.DEPTH_INFINITE));
-
- // file has been copied to destination
- assertTrue("3.4", destinationFile.exists());
-
- // ensure marker info has not been lost
- try {
- IMarker marker = destinationFile.findMarker(markerId);
- assertNotNull("3.6", marker);
- assertEquals("3.7", attributeValue, marker.getAttribute(attributeKey));
- } catch (CoreException e) {
- fail("3.8", e);
- }
-
- // non-removable file has been moved (but not in file system - they are out-of-sync)
- assertTrue("4.1", !sourceFile.exists());
-
- // refresh the source parent
- try {
- sourceParent.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- } catch (CoreException e) {
- fail("4.4");
- }
-
- // non-removable file now reappear in the resource tree
- assertTrue("4.7", sourceFile.exists());
-
- } finally {
- if (roFolderLocation != null)
- CoreFileSystemLibrary.setReadOnly(roFolderLocation.toOSString(), false);
- if (project != null)
- ensureDoesNotExistInFileSystem(project);
- }
- }
-
- public void testFolderBugOnLinux() {
- if (!(BootLoader.getOS().equals(BootLoader.OS_LINUX) && CoreFileSystemLibrary.usingNatives()))
- return;
-
- IPath roFolderLocation = null;
- IPath destinationROFolderLocation = null;
- IProject project = null;
- try {
- IWorkspace workspace = getWorkspace();
- project = workspace.getRoot().getProject("MyProject");
- IFolder sourceParent = project.getFolder("source_parent");
- IFolder roFolder = sourceParent.getFolder("sub-folder");
- IFolder folder = roFolder.getFolder("folder");
- IFile file1 = roFolder.getFile("file1.txt");
- IFile file2 = folder.getFile("file2.txt");
- IFolder destinationParent = project.getFolder("destination_parent");
- IFolder destinationROFolder = destinationParent.getFolder(roFolder.getName());
-
- ensureExistsInWorkspace(new IResource[] { file1, file2, destinationParent }, true);
-
- roFolderLocation = roFolder.getLocation();
- destinationROFolderLocation = destinationROFolder.getLocation();
-
- // add a marker to a file to ensure the move operation is not losing anything
- String attributeKey = getRandomString();
- String attributeValue = getRandomString();
- long markerId = -1;
- try {
- IMarker bookmark = null;
- bookmark = file1.createMarker(IMarker.BOOKMARK);
- bookmark.setAttribute(attributeKey, attributeValue);
- markerId = bookmark.getId();
- } catch (CoreException e) {
- fail("0.1", e);
- }
-
- // mark sub-folder as read-only so its immediate children cannot be removed on Linux
- roFolder.setReadOnly(true);
-
- try {
- roFolder.move(destinationParent.getFullPath().append(roFolder.getName()), IResource.FORCE, getMonitor());
- fail("2.0");
- } catch (CoreException ce) {
- // success
- }
-
- // the source parent is out-of-sync
- assertTrue("3.0", !sourceParent.isSynchronized(IResource.DEPTH_INFINITE));
- // the target parent is in-sync
- assertTrue("3.1", destinationParent.isSynchronized(IResource.DEPTH_INFINITE));
-
- // resources have been copied to destination
- IFolder destinationFolder = destinationROFolder.getFolder(folder.getName());
- IFile destinationFile1 = destinationROFolder.getFile(file1.getName());
- IFile destinationFile2 = destinationFolder.getFile(file2.getName());
- assertTrue("3.2", destinationROFolder.exists());
- assertTrue("3.4", destinationFolder.exists());
- assertTrue("3.5", destinationFile1.exists());
- assertTrue("3.6", destinationFile2.exists());
-
- // ensure marker info has not been lost
- try {
- IMarker marker = destinationROFolder.getFile(file1.getName()).findMarker(markerId);
- assertNotNull("3.7", marker);
- assertEquals("3.8", attributeValue, marker.getAttribute(attributeKey));
- } catch (CoreException e) {
- fail("3.9", e);
- }
-
- // non-removable resources have been moved (but not in file system - they are out-of-sync)
- assertTrue("4.0", !roFolder.exists());
- assertTrue("4.1", !folder.exists());
- assertTrue("4.2", !file1.exists());
- assertTrue("4.3", !file2.exists());
-
- // refresh the source parent
- try {
- sourceParent.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- } catch (CoreException e) {
- fail("4.4");
- }
-
- // non-removed resources now reappear in the resource tree
- assertTrue("4.5", roFolder.exists());
- assertTrue("4.6", folder.exists());
- assertTrue("4.7", file1.exists());
- assertTrue("4.8", !file2.exists());
-
- } finally {
- if (roFolderLocation != null)
- CoreFileSystemLibrary.setReadOnly(roFolderLocation.toOSString(), false);
- if (destinationROFolderLocation != null)
- CoreFileSystemLibrary.setReadOnly(destinationROFolderLocation.toOSString(), false);
- if (project != null)
- ensureDoesNotExistInFileSystem(project);
- }
- }
- public void testProjectBugOnLinux() {
- if (!(BootLoader.getOS().equals(BootLoader.OS_LINUX) && CoreFileSystemLibrary.usingNatives()))
- return;
-
- IProject sourceProject = null;
- IProject destinationProject = null;
- IPath projectLocationParent = getRandomLocation();
- try {
- IWorkspace workspace = getWorkspace();
- sourceProject = workspace.getRoot().getProject("SourceProject");
- IProjectDescription sourceDescription = workspace.newProjectDescription(sourceProject.getName());
- sourceDescription.setLocation(projectLocationParent.append(sourceProject.getName()));
-
- destinationProject = workspace.getRoot().getProject("DestinationProject");
- IProjectDescription destinationDescription = workspace.newProjectDescription(destinationProject.getName());
-
- // create and open the source project at a non-default location
- try {
- sourceProject.create(sourceDescription, getMonitor());
- } catch (CoreException e) {
- fail("0.1", e);
- }
- try {
- sourceProject.open(getMonitor());
- } catch (CoreException e) {
- fail("0.2", e);
- }
-
- IFile file1 = sourceProject.getFile("file1.txt");
-
- ensureExistsInWorkspace(new IResource[] { file1 }, true);
-
- // add a marker to a file to ensure the move operation is not losing anything
- String attributeKey = getRandomString();
- String attributeValue = getRandomString();
- long markerId = -1;
- try {
- IMarker bookmark = null;
- bookmark = file1.createMarker(IMarker.BOOKMARK);
- bookmark.setAttribute(attributeKey, attributeValue);
- markerId = bookmark.getId();
- } catch (CoreException e) {
- fail("0.5", e);
- }
-
- // mark sub-folder as read-only so its immediate children cannot be removed on Linux
- assertTrue("0.7", CoreFileSystemLibrary.setReadOnly(projectLocationParent.toOSString(), true));
-
- try {
- sourceProject.move(destinationDescription, IResource.FORCE, getMonitor());
- fail("2.0");
- } catch (CoreException ce) {
- // success
- }
-
- // the source does not exist
- assertTrue("3.0", !sourceProject.exists());
- // the target exists and is in sync
- assertTrue("3.1", destinationProject.exists());
- assertTrue("3.2", destinationProject.isSynchronized(IResource.DEPTH_INFINITE));
-
- // resources have been copied to destination
- assertTrue("3.4", destinationProject.getFile(file1.getProjectRelativePath()).exists());
-
- // ensure marker info has not been lost
- try {
- IMarker marker = destinationProject.getFile(file1.getProjectRelativePath()).findMarker(markerId);
- assertNotNull("3.6", marker);
- assertEquals("3.7", attributeValue, marker.getAttribute(attributeKey));
- } catch (CoreException e) {
- fail("3.8", e);
- }
- // project's content area still exists in file system
- assertTrue("4.0", projectLocationParent.append(sourceProject.getName()).toFile().exists());
-
- assertTrue("5.0", workspace.getRoot().isSynchronized(IResource.DEPTH_INFINITE));
-
- } finally {
- CoreFileSystemLibrary.setReadOnly(projectLocationParent.toOSString(), false);
- ensureDoesNotExistInFileSystem(projectLocationParent.toFile());
- if (destinationProject != null)
- ensureDoesNotExistInFileSystem(destinationProject);
- }
- }
-
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_6708.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_6708.java
deleted file mode 100644
index 9e95398..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_6708.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.regression;
-
-import java.io.ByteArrayInputStream;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-public class Bug_6708 extends EclipseWorkspaceTest {
-/**
- * Constructor for Bug_6708.
- */
-public Bug_6708() {
- super();
-}
-/**
- * Constructor for Bug_6708.
- * @param name
- */
-public Bug_6708(String name) {
- super(name);
-}
-public static Test suite() {
- return new TestSuite(Bug_6708.class);
-}
-public void testBug() {
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
-
- try {
- IProject sourceProj = workspace.getRoot().getProject("P1");
- sourceProj.create(null);
- sourceProj.open(null);
- IFile source = sourceProj.getFile("Source.txt");
- source.create(new ByteArrayInputStream("abcdef".getBytes()), false, null);
-
- IProject destProj = workspace.getRoot().getProject("P2");
- destProj.create(null);
- destProj.open(null);
- IFile dest = destProj.getFile("Dest.txt");
-
- source.copy(dest.getFullPath(), false, null);
- dest.setContents(new ByteArrayInputStream("ghijkl".getBytes()), false, true, null);
- } catch (CoreException e) {
- fail("1.0", e);
- }
-}
-}
-
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IFileTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IFileTest.java
deleted file mode 100644
index 108c4df..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IFileTest.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.regression;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.boot.BootLoader;
-import org.eclipse.core.internal.localstore.CoreFileSystemLibrary;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-public class IFileTest extends EclipseWorkspaceTest {
-/**
- * Constructor for IFileTest.
- */
-public IFileTest() {
- super();
-}
-/**
- * Constructor for IFileTest.
- * @param name
- */
-public IFileTest(String name) {
- super(name);
-}
-public static Test suite() {
- return new TestSuite(IFileTest.class);
-}
-/**
- * Bug states that the error code in the CoreException which is thrown when
- * you try to create a file in a read-only folder on Linux should be
- * FAILED_WRITE_LOCAL.
- */
-public void testBug25658() {
-
- // This test is no longer valid since the error code is dependant on whether
- // or not the parent folder is marked as read-only. We need to write a different
- // test to make the file.create fail.
- if (true)
- return;
-
- // We need to know whether or not we can unset the read-only flag
- // in order to perform this test.
- if (!CoreFileSystemLibrary.usingNatives())
- return;
-
- // Don't test this on Windows
- if (BootLoader.getOS().equals(BootLoader.OS_WIN32))
- return;
-
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- IFolder folder = project.getFolder("folder");
- ensureExistsInWorkspace(new IResource[] {project, folder}, true);
- IFile file = folder.getFile("file.txt");
-
- try {
- folder.setReadOnly(true);
- assertTrue("0.0", folder.isReadOnly());
- try {
- file.create(getRandomContents(), true, getMonitor());
- fail("0.1");
- } catch (CoreException e) {
- assertEquals("0.2", IResourceStatus.FAILED_WRITE_LOCAL, e.getStatus().getCode());
- }
- } finally {
- folder.setReadOnly(false);
- }
-}
-/**
- * Bug requests that if a failed file write occurs on Linux that we check the immediate
- * parent to see if it is read-only so we can return a better error code and message
- * to the user.
- */
-public void testBug25662() {
-
- // We need to know whether or not we can unset the read-only flag
- // in order to perform this test.
- if (!CoreFileSystemLibrary.usingNatives())
- return;
-
- // Only run this test on Linux for now since Windows lets you create
- // a file within a read-only folder.
- if (!BootLoader.getOS().equals(BootLoader.OS_LINUX))
- return;
-
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- IFolder folder = project.getFolder("folder");
- ensureExistsInWorkspace(new IResource[] {project, folder}, true);
- IFile file = folder.getFile("file.txt");
-
- try {
- folder.setReadOnly(true);
- assertTrue("0.0", folder.isReadOnly());
- try {
- file.create(getRandomContents(), true, getMonitor());
- fail("0.1");
- } catch (CoreException e) {
- assertEquals("0.2", IResourceStatus.PARENT_READ_ONLY, e.getStatus().getCode());
- }
- } finally {
- folder.setReadOnly(false);
- }
-}
-/**
- * Tests setting local timestamp of project description file
- */
-public void testBug43936() {
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- IFile descFile = project.getFile(IProjectDescription.DESCRIPTION_FILE_NAME);
- ensureExistsInWorkspace(project, true);
- assertTrue("1.0", descFile.exists());
-
- IProjectDescription desc = null;
- try {
- desc = project.getDescription();
- } catch (CoreException e) {
- fail("1.99", e);
- }
- //change the local file timestamp
- long newTime = System.currentTimeMillis()+10000;
- long actualTime = 0;
- try {
- descFile.setLocalTimeStamp(newTime);
- } catch (CoreException e1) {
- fail("2.99", e1);
- }
-
- assertTrue("2.0", descFile.isSynchronized(IResource.DEPTH_ZERO));
-
- try {
- //try setting the description -- shouldn't fail
- project.setDescription(desc, getMonitor());
- } catch (CoreException e2) {
- fail("3.99", e2);
- }
-}
-}
-
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IFolderTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IFolderTest.java
deleted file mode 100644
index 057fad1..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IFolderTest.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.regression;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.boot.BootLoader;
-import org.eclipse.core.internal.localstore.CoreFileSystemLibrary;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-public class IFolderTest extends EclipseWorkspaceTest {
- /**
- * Constructor for IFolderTest.
- */
- public IFolderTest() {
- super();
- }
- /**
- * Constructor for IFolderTest.
- * @param name
- */
- public IFolderTest(String name) {
- super(name);
- }
- public static Test suite() {
- return new TestSuite(IFolderTest.class);
- }
-
- /**
- * Bug requests that if a failed folder creation occurs on Linux that we check
- * the immediate parent to see if it is read-only so we can return a better
- * error code and message to the user.
- */
- public void testBug25662() {
-
- // We need to know whether or not we can unset the read-only flag
- // in order to perform this test.
- if (!CoreFileSystemLibrary.usingNatives())
- return;
-
- // Only run this test on Linux for now since Windows lets you create
- // a file within a read-only folder.
- if (!BootLoader.getOS().equals(BootLoader.OS_LINUX))
- return;
-
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- IFolder parentFolder = project.getFolder("parentFolder");
- ensureExistsInWorkspace(new IResource[] { project, parentFolder }, true);
- IFolder folder = parentFolder.getFolder("folder");
-
- try {
- parentFolder.setReadOnly(true);
- assertTrue("0.0", parentFolder.isReadOnly());
- try {
- folder.create(true, true, getMonitor());
- fail("0.1");
- } catch (CoreException e) {
- assertEquals("0.2", IResourceStatus.PARENT_READ_ONLY, e.getStatus().getCode());
- }
- } finally {
- parentFolder.setReadOnly(false);
- }
- }
- /**
- * Bug 11510 [resources] Non-local folders do not become local when directory is created.
- */
- public void testBug11510() {
- IWorkspaceRoot root = getWorkspace().getRoot();
- IProject project = root.getProject("TestProject");
- IFolder folder = project.getFolder("fold1");
- IFile subFile = folder.getFile("f1");
- IFile file = project.getFile("f2");
- ensureExistsInWorkspace(project, true);
- ensureExistsInWorkspace(new IResource[] { folder, file, subFile }, false);
-
- assertTrue("1.0", !folder.isLocal(IResource.DEPTH_ZERO));
- assertTrue("1.1", !file.isLocal(IResource.DEPTH_ZERO));
- assertTrue("1.1", !subFile.isLocal(IResource.DEPTH_ZERO));
-
- // now create the resources in the local file system and refresh
- ensureExistsInFileSystem(file);
- try {
- project.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
- assertTrue("2.1", file.isLocal(IResource.DEPTH_ZERO));
- assertTrue("2.2", !folder.isLocal(IResource.DEPTH_ZERO));
- assertTrue("2.3", !subFile.isLocal(IResource.DEPTH_ZERO));
-
- folder.getLocation().toFile().mkdir();
- try {
- project.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
- assertTrue("3.1", folder.isLocal(IResource.DEPTH_ZERO));
- assertTrue("3.2", file.isLocal(IResource.DEPTH_ZERO));
- assertTrue("3.3", !subFile.isLocal(IResource.DEPTH_ZERO));
-
- ensureExistsInFileSystem(subFile);
- try {
- project.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- } catch (CoreException e) {
- fail("4.0", e);
- }
- assertTrue("4.1", subFile.isLocal(IResource.DEPTH_ZERO));
- assertTrue("4.2", folder.isLocal(IResource.DEPTH_ZERO));
- assertTrue("4.3", file.isLocal(IResource.DEPTH_ZERO));
-
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IProjectTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IProjectTest.java
deleted file mode 100644
index b87c338..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IProjectTest.java
+++ /dev/null
@@ -1,233 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.regression;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.tests.internal.builders.AbstractBuilderTest;
-import org.eclipse.core.tests.resources.usecase.SignaledBuilder;
-
-public class IProjectTest extends AbstractBuilderTest {
- public static Test suite() {
- return new TestSuite(IProjectTest.class);
- }
- public IProjectTest() {
- super("");
- }
- public IProjectTest(String name) {
- super(name);
- }
- public void test_1G0XIMA() throws CoreException {
- /* common objects */
- IProject project = project = getWorkspace().getRoot().getProject("MyProject");
- project.create(null);
- project.open(null);
-
- /* define a visitor that renames all resources it visits */
- IResourceVisitor renameVisitor = new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- if (!resource.exists())
- return false;
- IPath path = resource.getFullPath();
- path = path.removeLastSegments(1);
- long timestamp = System.currentTimeMillis();
- path = path.append(resource.getName() + " renamed at " + timestamp);
- resource.move(path, false, null);
- return true;
- }
-
- };
- /* test */
- try {
- project.accept(renameVisitor);
- } catch (CoreException e) {
- fail("1.0", e);
- }
- // cleanup
- project.delete(true, getMonitor());
- }
- public void test_1G5I6PV() throws CoreException {
- /* common objects */
- IProject project = project = getWorkspace().getRoot().getProject("MyProject");
- project.create(getMonitor());
- project.open(getMonitor());
-
- /* test */
- try {
- project.setLocal(true, IResource.DEPTH_ZERO, getMonitor());
- } catch (Exception e) {
- fail("1.0", e);
- }
-
- // cleanup
- project.delete(true, getMonitor());
- }
- /**
- * 1GC2FKV: ITPCORE:BuildManager triggers incremental build when doing full builds
- */
- public void testAutoBuild_1GC2FKV() {
- // set auto build OFF
- try {
- IWorkspaceDescription description = getWorkspace().getDescription();
- description.setAutoBuilding(false);
- getWorkspace().setDescription(description);
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- // create project with a builder
- IProject projectONE = getWorkspace().getRoot().getProject("Project_ONE");
- try {
- IProjectDescription prjDescription = getWorkspace().newProjectDescription("ProjectONE");
- ICommand command = prjDescription.newCommand();
- command.setBuilderName(SignaledBuilder.BUILDER_ID);
- prjDescription.setBuildSpec(new ICommand[] { command });
- projectONE.create(prjDescription, getMonitor());
- projectONE.open(getMonitor());
- } catch (CoreException e) {
- fail("0.1", e);
- }
-
- // create project with a builder
- IProject projectTWO = getWorkspace().getRoot().getProject("Project_TWO");
- try {
- IProjectDescription prjDescription = getWorkspace().newProjectDescription("Project_TWO");
- ICommand command = prjDescription.newCommand();
- command.setBuilderName(SignaledBuilder.BUILDER_ID);
- prjDescription.setBuildSpec(new ICommand[] { command });
- projectTWO.create(prjDescription, getMonitor());
- projectTWO.open(getMonitor());
- } catch (CoreException e) {
- fail("0.2", e);
- }
- // set auto build ON
- try {
- IWorkspaceDescription description = getWorkspace().getDescription();
- description.setAutoBuilding(true);
- getWorkspace().setDescription(description);
- getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- SignaledBuilder projectONEbuilder = SignaledBuilder.getInstance(projectONE);
- SignaledBuilder projectTWObuilder = SignaledBuilder.getInstance(projectTWO);
- projectONEbuilder.reset();
- projectTWObuilder.reset();
- try {
- projectONE.build(IncrementalProjectBuilder.FULL_BUILD, null);
- } catch (CoreException e) {
- fail("1.0", e);
- }
- assertTrue("1.1", projectONEbuilder.wasExecuted());
- assertTrue("1.2", !projectTWObuilder.wasExecuted());
-
- projectONEbuilder.reset();
- projectTWObuilder.reset();
- try {
- projectTWO.build(IncrementalProjectBuilder.FULL_BUILD, SignaledBuilder.BUILDER_ID, null, null);
- } catch (CoreException e) {
- fail("2.0", e);
- }
- assertTrue("2.1", !projectONEbuilder.wasExecuted());
- assertTrue("2.2", projectTWObuilder.wasExecuted());
-
- projectONEbuilder.reset();
- projectTWObuilder.reset();
- try {
- projectTWO.touch(null);
- waitForBuild();
- } catch (CoreException e) {
- fail("3.0", e);
- }
- //project one won't be executed because project didn't change.
- assertTrue("3.1", !projectONEbuilder.wasExecuted());
- assertTrue("3.2", projectTWObuilder.wasExecuted());
- }
- /**
- * 1G5FYZM: ITPCORE:WIN - Project.deleteWithoutForce does not look for out of sync children
- */
- public void testDelete_1G5FYZM() {
- //FIXME: invalid test now? if delete_contents is true then force flag is ignored.
- if (true)
- return;
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- try {
- project.close(getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- IFile file = project.getFile("MyFile");
- ensureExistsInFileSystem(file);
-
- try {
- project.delete(true, false, getMonitor());
- fail("3.0");
- } catch (CoreException e) {
- assertEquals("3.1", 1, e.getStatus().getChildren().length);
- }
-
- assertExistsInFileSystem("4.0", file);
-
- // clean up
- try {
- project.delete(true, true, getMonitor());
- } catch (CoreException e) {
- fail("5.0", e);
- }
- }
- /**
- * 1GDW1RX: ITPCORE:ALL - IResource.delete() without force not working correctly
- */
- public void testDelete_1GDW1RX() {
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- String[] paths = new String[] { "/1/", "/1/1", "/1/2", "/1/3", "/2/", "/2/1" };
- IResource[] resources = buildResources(project, paths);
- ensureExistsInWorkspace(resources, true);
-
- IFolder folder = project.getFolder("folder");
- ensureExistsInFileSystem(folder);
-
- IFile file = folder.getFile("MyFile");
- ensureExistsInFileSystem(file);
-
- try {
- project.delete(false, getMonitor());
- fail("3.0");
- } catch (CoreException e) {
- }
-
- // clean up
- try {
- project.delete(true, true, getMonitor());
- } catch (CoreException e) {
- fail("20.0", e);
- }
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IResourceTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IResourceTest.java
deleted file mode 100644
index badda55..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IResourceTest.java
+++ /dev/null
@@ -1,524 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.regression;
-
-import java.io.IOException;
-import java.io.InputStream;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.boot.BootLoader;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-public class IResourceTest extends EclipseWorkspaceTest {
-public IResourceTest() {
-}
-public IResourceTest(String name) {
- super(name);
-}
-public static Test suite() {
- return new TestSuite(IResourceTest.class);
-}
-protected void tearDown() throws Exception {
- super.tearDown();
- getWorkspace().getRoot().delete(true, null);
-}
-/**
- * 1G9RBH5: ITPCORE:WIN98 - IFile.appendContents might lose data
- */
-public void testAppendContents_1G9RBH5() {
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- try {
- project.create(null);
- project.open(null);
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- IFile target = project.getFile("file1");
- try {
- target.create(getContents("abc"), false, null);
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- try {
- target.appendContents(getContents("def"), false, true, null);
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- InputStream content = null;
- try {
- content = target.getContents(false);
- assertTrue("3.0", compareContent(content, getContents("abcdef")));
- } catch (CoreException e) {
- fail("3.1", e);
- }
-
- // clean up
- try {
- project.delete(true, true, null);
- } catch (CoreException e) {
- fail("3.0", e);
- }
-}
-/**
- * 1GA6QJP: ITPCORE:ALL - Copying a resource does not copy its lastmodified time
- */
-public void testCopy_1GA6QJP() {
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- IFile source = project.getFile("file1");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- source.create(getContents("abc"), true, getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- try {
- Thread.sleep(5000);
- } catch (InterruptedException e) {
- }
-
- IPath destinationPath = new Path("copy of file");
- try {
- source.copy(destinationPath, true, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- IFile destination = project.getFile(destinationPath);
- assertEquals("2.0", source.getLocation().toFile().lastModified(), destination.getLocation().toFile().lastModified());
-
- // clean up
- try {
- project.delete(true, true, null);
- } catch (CoreException e) {
- fail("3.0", e);
- }
-}
-/**
- * 1FW87XF: ITPUI:WIN2000 - Can create 2 files with same name
- */
-public void testCreate_1FW87XF() {
- // FIXME: remove when fix this PR
- String os = BootLoader.getOS();
- if (!os.equals(BootLoader.OS_LINUX)) {
- log("Skipping testCreate_1FW87XF because it is still not supported by the platform.");
- return;
- }
-
- // test if the file system is case sensitive
- boolean caseSensitive = new java.io.File("abc").compareTo(new java.io.File("ABC")) != 0;
-
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- IFile file = project.getFile("file");
- try {
- project.create(null);
- project.open(null);
- file.create(getRandomContents(), true, null);
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- // force = true
- assertTrue("2.0", file.exists());
- IFile anotherFile = project.getFile("File");
- try {
- anotherFile.create(getRandomContents(), true, null);
- if (!caseSensitive)
- fail("2.1");
- } catch (CoreException e) {
- if (caseSensitive)
- fail("2.2", e);
- }
-
- // clean-up
- try {
- anotherFile.delete(true, false, null);
- } catch (CoreException e) {
- fail("3.0", e);
- }
-
- // force = false
- try {
- anotherFile.create(getRandomContents(), false, null);
- if (!caseSensitive)
- fail("4.0");
- } catch (CoreException e) {
- if (caseSensitive)
- fail("4.1", e);
- }
-
- // test refreshLocal
- try {
- anotherFile.refreshLocal(IResource.DEPTH_ZERO, getMonitor());
- if (!caseSensitive)
- fail("5.0");
- } catch (CoreException e) {
- if (caseSensitive)
- fail("5.1", e);
- }
-
- // clean up
- try {
- project.delete(true, true, getMonitor());
- } catch (CoreException e) {
- fail("6.0", e);
- }
-}
-/**
- * 1FWYTKT: ITPCORE:WINNT - Error creating folder with long name
- */
-public void testCreate_1FWYTKT() {
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- try {
- project.create(null);
- project.open(null);
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < 260; i++)
- sb.append('a');
- sb.append('b');
- IFolder folder = project.getFolder(sb.toString());
- try {
- folder.create(true, true, null);
- fail("2.1");
- } catch (CoreException e) {
- }
- assertTrue("2.2", !folder.exists());
-
- IFile file = project.getFile(sb.toString());
- try {
- file.create(getRandomContents(), true, null);
- fail("3.0");
- } catch (CoreException e) {
- }
- assertTrue("3.1", !file.exists());
-
- // clean up
- try {
- project.delete(true, true, null);
- } catch (CoreException e) {
- fail("3.0", e);
- }
-
- project = getWorkspace().getRoot().getProject(sb.toString());
- try {
- project.create(null);
- fail("4.0");
- } catch (CoreException e) {
- }
- assertTrue("4.1", !project.exists());
-}
-/**
- * 1GD7CSU: ITPCORE:ALL - IFile.create bug?
- *
- * Ensure that creating a file with force==true doesn't throw
- * a CoreException if the resource already exists on disk.
- */
-public void testCreate_1GD7CSU() {
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- try {
- project.create(null);
- project.open(null);
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- IFile file = project.getFile("MyFile");
- ensureExistsInFileSystem(file);
-
- try {
- file.create(getRandomContents(), true, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
-}
-/*
- * Test PR: 1GD3ZUZ. Ensure that a CoreException is being thrown
- * when we try to delete a read-only resource. It will depend on the
- * OS and file system.
- */
-public void testDelete_1GD3ZUZ() {
- // This test cannot be done automatically because we don't know in that
- // file system we are running. Will leave test here in case it needs
- // to be run it in a special environment.
- if (true)
- return;
-
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- IFile file = project.getFile("MyFile");
-
- // setup
- ensureExistsInWorkspace(new IResource[] {project, file}, true);
- file.setReadOnly(true);
- assertTrue("2.0", file.isReadOnly());
-
- // doit
- try {
- file.delete(false, getMonitor());
- fail("3.0");
- } catch (CoreException e) {
- }
-
- // cleanup
- file.setReadOnly(false);
- assertTrue("4.0", !file.isReadOnly());
- ensureDoesNotExistInWorkspace(new IResource[] {project, file});
-}
-public void testDelete_Bug8754() {
- //In this test, we delete with force false on a file that does not exist in the file system,
- //and ensure that the returned exception is of type OUT_OF_SYNC_LOCAL
-
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- IFile file = project.getFile("MyFile");
-
- // setup
- ensureExistsInWorkspace(new IResource[] {project, file}, true);
- ensureOutOfSync(file);
-
- // doit
- try {
- file.delete(false, getMonitor());
- fail("1.0");
- } catch (CoreException e) {
- IStatus status = e.getStatus();
- if (status.isMultiStatus()) {
- IStatus[] children = status.getChildren();
- assertEquals("1.1", 1, children.length);
- status = children[0];
- }
- assertEquals("1.2", IResourceStatus.OUT_OF_SYNC_LOCAL, status.getCode());
- }
- //cleanup
- ensureDoesNotExistInWorkspace(new IResource[] {project, file});
-}
-public void testEquals_1FUOU25() {
- IResource fileResource = getWorkspace().getRoot().getFile(new Path("a/b/c/d"));
- IResource folderResource = getWorkspace().getRoot().getFolder(new Path("a/b/c/d"));
- assertTrue("1FUOU25: ITPCORE:ALL - Bug in Resource.equals()", !fileResource.equals(folderResource));
-}
-public void testExists_1FUP8U6() {
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- IFolder folder = project.getFolder("folder");
- try {
- project.create(null);
- project.open(null);
- folder.create(true, true, null);
- } catch (CoreException e) {
- fail("1.0", e);
- }
- IFile file = project.getFile("folder");
- assertTrue("2.0", !file.exists());
-
- // clean up
- try {
- project.delete(true, true, null);
- } catch (CoreException e) {
- fail("3.0", e);
- }
-}
-/**
- * 1GA6QYV: ITPCORE:ALL - IContainer.findMember( Path, boolean ) breaking API
- */
-public void testFindMember_1GA6QYV() {
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- IFolder folder1 = project.getFolder("Folder1");
- IFolder folder2 = folder1.getFolder("Folder2");
- IFolder folder3 = folder2.getFolder("Folder3");
- try {
- folder1.create(true, true, getMonitor());
- folder2.create(true, true, getMonitor());
- folder3.create(true, true, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- IPath targetPath = new Path("Folder2/Folder3");
- IFolder target = (IFolder) folder1.findMember(targetPath);
- assertTrue("3.0", folder3.equals(target));
-
- targetPath = new Path("/Folder2/Folder3");
- target = (IFolder) folder1.findMember(targetPath);
- assertTrue("4.0", folder3.equals(target));
-
- // clean up
- try {
- project.delete(true, true, null);
- } catch (CoreException e) {
- fail("3.0", e);
- }
-}
-/**
- * 1GBZD4S: ITPCORE:API - IFile.getContents(true) fails if performed during delta notification
- */
-public void testGetContents_1GBZD4S() {
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- try {
- project.create(null);
- project.open(null);
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- final IFile target = project.getFile("file1");
- String contents = "some random contents";
- try {
- target.create(getContents(contents), false, null);
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- try {
- InputStream is = target.getContents(false);
- assertTrue("2.0", compareContent(getContents(contents), is));
- } catch (CoreException e) {
- fail("2.1", e);
- }
-
- final String newContents = "some other contents";
- try {
- try {
- Thread.sleep(5000);
- } catch (InterruptedException e) {
- }
- createFileInFileSystem(target.getLocation(), getContents(newContents));
- } catch (IOException e) {
- fail("3.0", e);
- }
-
- final boolean[] failed = new boolean[1];
- IResourceChangeListener listener = new IResourceChangeListener() {
- public void resourceChanged(IResourceChangeEvent event) {
- try {
- failed[0] = true;
- InputStream is = target.getContents(true);
- assertTrue("4.0", compareContent(getContents(newContents), is));
- failed[0] = false;
- } catch (CoreException e) {
- fail("4.1", e);
- }
- }
- };
- getWorkspace().addResourceChangeListener(listener);
- // trigger delta notification
- try {
- project.touch(null);
- } catch (CoreException e) {
- fail("4.5", e);
- }
- getWorkspace().removeResourceChangeListener(listener);
- assertTrue("4.6", !failed[0]);
-
- try {
- target.getContents(false);
- fail("5.0");
- } catch (CoreException e) {
- }
-
- try {
- InputStream is = target.getContents(true);
- assertTrue("6.0", compareContent(getContents(newContents), is));
- } catch (CoreException e) {
- fail("6.1", e);
- }
-
- // clean up
- try {
- project.delete(true, true, null);
- } catch (CoreException e) {
- fail("3.0", e);
- }
-}
-/**
- * 1G60AFG: ITPCORE:WIN - problem calling RefreshLocal with DEPTH_ZERO on folder
- */
-public void testRefreshLocal_1G60AFG() {
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- IFolder folder = project.getFolder("folder");
- IFile file = folder.getFile("file");
- try {
- project.create(null);
- project.open(null);
- folder.create(true, true, null);
- file.create(getRandomContents(), true, null);
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- assertTrue("2.0", file.exists());
- try {
- folder.refreshLocal(IResource.DEPTH_ZERO, null);
- } catch (CoreException e) {
- fail("2.1", e);
- }
- assertTrue("2.2", file.exists());
-
- // clean up
- try {
- project.delete(true, true, null);
- } catch (CoreException e) {
- fail("3.0", e);
- }
-}
-/**
- * Bug states that JDT cannot copy the .project file from the project root to
- * the build output folder.
- */
-public void testBug25686() {
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- IFolder outputFolder = project.getFolder("bin");
- IFile description = project.getFile(".project");
- IFile destination = outputFolder.getFile(".project");
- ensureExistsInWorkspace(new IResource[] {project, outputFolder}, true);
-
- assertTrue("0.0", description.exists());
- try {
- description.copy(destination.getFullPath(), IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("0.99", e);
- }
- assertTrue("0.1", destination.exists());
-}
-/**
- * Bug 31750 states that an OperationCancelledException is
- * not handled correctly if it occurs within a proxy visitor.
- */
-public void testBug31750() {
- IResourceProxyVisitor visitor = new IResourceProxyVisitor() {
- public boolean visit(IResourceProxy proxy) {
- throw new OperationCanceledException();
- }
- };
- try {
- getWorkspace().getRoot().accept(visitor, IResource.NONE);
- fail("1.0");
- } catch (OperationCanceledException e) {
- // expected results
- } catch (CoreException e) {
- fail("2.0", e);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IWorkspaceTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IWorkspaceTest.java
deleted file mode 100644
index 06db768..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IWorkspaceTest.java
+++ /dev/null
@@ -1,243 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.regression;
-
-import org.eclipse.core.internal.resources.Workspace;
-import org.eclipse.core.internal.localstore.CoreFileSystemLibrary;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-import junit.framework.*;
-
-public class IWorkspaceTest extends EclipseWorkspaceTest {
-public IWorkspaceTest() {
-}
-public IWorkspaceTest(String name) {
- super(name);
-}
-public static Test suite() {
- return new TestSuite(IWorkspaceTest.class);
-}
-protected void tearDown() throws Exception {
- super.tearDown();
- getWorkspace().getRoot().delete(true, null);
-}
-/**
- * 1GDKIHD: ITPCORE:WINNT - API - IWorkspace.move needs to keep history
- */
-public void testMultiMove_1GDKIHD() {
- // create common objects
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- // test file (force = true)
- IFile file1 = project.getFile("file.txt");
- IFolder folder = project.getFolder("folder");
- IResource[] allResources = new IResource[] {file1, folder};
- try {
- folder.create(true, true, getMonitor());
- file1.create(getRandomContents(), true, getMonitor());
- file1.setContents(getRandomContents(), true, true, getMonitor());
- file1.setContents(getRandomContents(), true, true, getMonitor());
- getWorkspace().move(new IFile[] {file1}, folder.getFullPath(), true, getMonitor());
- file1.create(getRandomContents(), true, getMonitor());
- IFileState[] states = file1.getHistory(getMonitor());
- assertEquals("1.0", 3, states.length);
- getWorkspace().delete(allResources, true, getMonitor());
- project.clearHistory(getMonitor());
- } catch (CoreException e) {
- fail("1.20", e);
- }
-
- // test file (force = false)
- try {
- folder.create(true, true, getMonitor());
- file1.create(getRandomContents(), true, getMonitor());
- file1.setContents(getRandomContents(), true, true, getMonitor());
- file1.setContents(getRandomContents(), true, true, getMonitor());
- getWorkspace().move(new IFile[] {file1}, folder.getFullPath(), false, getMonitor());
- file1.create(getRandomContents(), true, getMonitor());
- IFileState[] states = file1.getHistory(getMonitor());
- assertEquals("2.0", 3, states.length);
- getWorkspace().delete(allResources, true, getMonitor());
- project.clearHistory(getMonitor());
- } catch (CoreException e) {
- fail("2.20", e);
- }
-
- // test folder (force = true)
- IFolder folder2 = project.getFolder("second folder");
- IFile file2 = folder.getFile("file2.txt");
- allResources = new IResource[] {file1, folder, folder2, file2};
- try {
- folder.create(true, true, getMonitor());
- folder2.create(true, true, getMonitor());
- file2.create(getRandomContents(), true, getMonitor());
- file2.setContents(getRandomContents(), true, true, getMonitor());
- file2.setContents(getRandomContents(), true, true, getMonitor());
- getWorkspace().move(new IResource[] {folder}, folder2.getFullPath(), true, getMonitor());
- folder.create(true, true, getMonitor());
- file2.create(getRandomContents(), true, getMonitor());
- IFileState[] states = file2.getHistory(getMonitor());
- assertEquals("3.0", 3, states.length);
- getWorkspace().delete(allResources, true, getMonitor());
- project.clearHistory(getMonitor());
- } catch (CoreException e) {
- fail("3.20", e);
- }
-
- // test folder (force = false)
- try {
- folder.create(true, true, getMonitor());
- folder2.create(true, true, getMonitor());
- file2.create(getRandomContents(), true, getMonitor());
- file2.setContents(getRandomContents(), true, true, getMonitor());
- file2.setContents(getRandomContents(), true, true, getMonitor());
- getWorkspace().move(new IResource[] {folder}, folder2.getFullPath(), false, getMonitor());
- folder.create(true, true, getMonitor());
- file2.create(getRandomContents(), true, getMonitor());
- IFileState[] states = file2.getHistory(getMonitor());
- assertEquals("4.0", 3, states.length);
- getWorkspace().delete(allResources, true, getMonitor());
- project.clearHistory(getMonitor());
- } catch (CoreException e) {
- fail("4.20", e);
- }
-
- try {
- project.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("20.0", e);
- }
-}
-/**
- * 1GDGRIZ: ITPCORE:WINNT - API - IWorkspace.delete needs to keep history
- */
-public void testMultiDelete_1GDGRIZ() {
- // create common objects
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- // test file (force = true)
- IFile file1 = project.getFile("file.txt");
- try {
- file1.create(getRandomContents(), true, getMonitor());
- file1.setContents(getRandomContents(), true, true, getMonitor());
- file1.setContents(getRandomContents(), true, true, getMonitor());
- getWorkspace().delete(new IFile[] {file1}, true, getMonitor());
- file1.create(getRandomContents(), true, getMonitor());
- IFileState[] states = file1.getHistory(getMonitor());
- assertEquals("1.0", 3, states.length);
- getWorkspace().delete(new IResource[] {file1}, true, getMonitor());
- project.clearHistory(getMonitor());
- } catch (CoreException e) {
- fail("1.20", e);
- }
-
- // test file (force = false)
- try {
- file1.create(getRandomContents(), true, getMonitor());
- file1.setContents(getRandomContents(), true, true, getMonitor());
- file1.setContents(getRandomContents(), true, true, getMonitor());
- getWorkspace().delete(new IFile[] {file1}, false, getMonitor());
- file1.create(getRandomContents(), true, getMonitor());
- IFileState[] states = file1.getHistory(getMonitor());
- assertEquals("2.0", 3, states.length);
- getWorkspace().delete(new IResource[] {file1}, true, getMonitor());
- project.clearHistory(getMonitor());
- } catch (CoreException e) {
- fail("2.20", e);
- }
-
- // test folder (force = true)
- IFolder folder = project.getFolder("folder");
- IFile file2 = folder.getFile("file2.txt");
- try {
- folder.create(true, true, getMonitor());
- file2.create(getRandomContents(), true, getMonitor());
- file2.setContents(getRandomContents(), true, true, getMonitor());
- file2.setContents(getRandomContents(), true, true, getMonitor());
- getWorkspace().delete(new IResource[] {folder}, true, getMonitor());
- folder.create(true, true, getMonitor());
- file2.create(getRandomContents(), true, getMonitor());
- IFileState[] states = file2.getHistory(getMonitor());
- assertEquals("3.0", 3, states.length);
- getWorkspace().delete(new IResource[] {folder, file1, file2}, true, getMonitor());
- project.clearHistory(getMonitor());
- } catch (CoreException e) {
- fail("3.20", e);
- }
-
- // test folder (force = false)
- try {
- folder.create(true, true, getMonitor());
- file2.create(getRandomContents(), true, getMonitor());
- file2.setContents(getRandomContents(), true, true, getMonitor());
- file2.setContents(getRandomContents(), true, true, getMonitor());
- getWorkspace().delete(new IResource[] {folder}, false, getMonitor());
- folder.create(true, true, getMonitor());
- file2.create(getRandomContents(), true, getMonitor());
- IFileState[] states = file2.getHistory(getMonitor());
- assertEquals("4.0", 3, states.length);
- getWorkspace().delete(new IResource[] {folder, file1, file2}, true, getMonitor());
- project.clearHistory(getMonitor());
- } catch (CoreException e) {
- fail("4.20", e);
- }
-
- try {
- project.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("20.0", e);
- }
-}
-public void test_8974() {
- IProject one = getWorkspace().getRoot().getProject("One");
- IPath oneLocation = getRandomLocation().append(one.getName());
- oneLocation.toFile().mkdirs();
- IProjectDescription oneDescription = getWorkspace().newProjectDescription(one.getName());
- oneDescription.setLocation(oneLocation);
-
- try {
- one.create(oneDescription, getMonitor());
- } catch (CoreException e) {
- Workspace.clear(oneLocation.removeLastSegments(1).toFile());
- fail("0.0", e);
- }
-
- try {
- IProject two = getWorkspace().getRoot().getProject("Two");
- IPath twoLocation = oneLocation.removeLastSegments(1).append(oneLocation.lastSegment().toLowerCase());
-
- IStatus result = getWorkspace().validateProjectLocation(two, twoLocation);
- if (CoreFileSystemLibrary.isCaseSensitive()) {
- assertTrue("1.0", result.isOK());
- } else {
- assertTrue("1.1", !result.isOK());
- }
- // cleanup
- ensureDoesNotExistInWorkspace(one);
- } finally {
- // ensure that the project directory is cleaned up.
- Workspace.clear(oneLocation.removeLastSegments(1).toFile());
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/LocalStoreRegressionTests.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/LocalStoreRegressionTests.java
deleted file mode 100644
index 514bc7a..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/LocalStoreRegressionTests.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.regression;
-
-/**
- */
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.internal.localstore.*;
-import org.eclipse.core.internal.resources.Workspace;
-import org.eclipse.core.tests.internal.localstore.LocalStoreTest;
-import java.io.*;
-import java.util.*;
-import junit.framework.*;
-//
-
-public class LocalStoreRegressionTests extends LocalStoreTest {
-/**
- * LocalStoreRegressionTests constructor comment.
- */
-public LocalStoreRegressionTests(String name) {
- super(name);
-}
-public static Test suite() {
- return new TestSuite(LocalStoreRegressionTests.class);
-}
-/**
- * 1FU4PJA: ITPCORE:ALL - refreshLocal for new file with depth zero doesn't work
- */
-public void test_1FU4PJA() throws Throwable {
- /* initialize common objects */
- IProject project = projects[0];
-
- /* */
- IFile file = project.getFile("file");
- ensureExistsInFileSystem(file);
- assertTrue("1.0", !file.exists());
- file.refreshLocal(IResource.DEPTH_ZERO, null);
- assertTrue("1.1", file.exists());
-}
-/**
- * From: 1FU4TW7: ITPCORE:ALL - Behaviour not specified for refreshLocal when parent doesn't exist
- */
-public void test_1FU4TW7() throws Throwable {
- IFolder folder = projects[0].getFolder("folder");
- IFile file = folder.getFile("file");
- ensureExistsInFileSystem(folder);
- ensureExistsInFileSystem(file);
- file.refreshLocal(IResource.DEPTH_INFINITE, null);
- assertTrue("1.1", folder.exists());
- assertTrue("1.2", file.exists());
- ensureDoesNotExistInWorkspace(folder);
- ensureDoesNotExistInFileSystem(folder);
-}
-/**
- * The PR reported a problem with longs, but we are testing more types here.
- */
-public void test_1G65KR1() {
- /* evaluate test environment */
- IPath root = getWorkspace().getRoot().getLocation().append("" + new Date().getTime());
- File temp = root.toFile();
- temp.mkdirs();
-
- File target = new File(temp, "target");
- Workspace.clear(target); // make sure there was nothing here before
- assertTrue("1.0", !target.exists());
-
- // write chunks
- SafeChunkyOutputStream output = null;
- try {
- output = new SafeChunkyOutputStream(target);
- DataOutputStream dos = new DataOutputStream(output);
- try {
- dos.writeLong(1234567890l);
- output.succeed();
- } finally {
- dos.close();
- }
- } catch (IOException e) {
- fail("2.0", e);
- }
-
- // read chunks
- SafeChunkyInputStream input = null;
- try {
- input = new SafeChunkyInputStream(target);
- DataInputStream dis = new DataInputStream(input);
- try {
- assertEquals("3.0", dis.readLong(), 1234567890l);
- } finally {
- dis.close();
- }
- } catch (IOException e) {
- fail("3.10", e);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/NLTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/NLTest.java
deleted file mode 100644
index 5302205..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/NLTest.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.regression;
-
-import java.util.*;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-public class NLTest extends EclipseWorkspaceTest {
-
-public NLTest() {
- super();
-}
-
-public NLTest(String name) {
- super(name);
-}
-
-public static Test suite() {
- return new TestSuite(NLTest.class);
-}
-
-public void getFileNames(List list, char begin, char end) {
- char current = begin;
- int index = 0;
- StringBuffer name = new StringBuffer();
- name.append(((int)current) + "_");
- while (current <= end) {
- if (!Character.isLetterOrDigit(current)) {
- current++;
- continue;
- }
- name.append(current);
- index++;
- current++;
- if (index == 10) {
- list.add(name.toString());
- index = 0;
- name.setLength(0);
- name.append(((int)current) + "_");
- }
- }
- if (name.length() > 0)
- list.add(name.toString());
-}
-
-public String[] getFileNames(String language) {
- List names = new ArrayList(20);
- if (language.equalsIgnoreCase("en")) { // English
- getFileNames(names, '\u0041', '\u005A'); // A - Z
- getFileNames(names, '\u0061', '\u007A'); // a - z
- } else
- if (language.equalsIgnoreCase("ja")) { // Japanese
- getFileNames(names, '\u3040', '\u3093'); // Hiragana
- // we are skipping \u3094
- getFileNames(names, '\u3095', '\u309F'); // Hiragana
- getFileNames(names, '\u30A0', '\u30F6'); // Katakana
- // we are skipping \u30F7 to \u30FA
- getFileNames(names, '\u30FB', '\u30FF'); // Katakana
- } else
- if (language.equalsIgnoreCase("de") || // German
- language.equalsIgnoreCase("pt")) { // Portuguese
- getFileNames(names, '\u00C0', '\u00FF'); // Latin-1 supplement
- } else
- if (language.equalsIgnoreCase("he") || // Hebrew
- language.equalsIgnoreCase("iw")) { // Hebrew
- getFileNames(names, '\u0590', '\u05FF');
- }
- return (String[]) names.toArray(new String[names.size()]);
-}
-
-public void testFileNames() {
- IProject project = getWorkspace().getRoot().getProject("project");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- String[] files = getFileNames(Locale.ENGLISH.getLanguage());
- IResource[] resources = buildResources(project, files);
- ensureExistsInWorkspace(resources, true);
- try {
- project.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
- assertExistsInFileSystem("2.1", resources);
- assertExistsInWorkspace("2.2", resources);
- ensureDoesNotExistInWorkspace(resources);
-
- files = getFileNames(Locale.getDefault().getLanguage());
- resources = buildResources(project, files);
- ensureExistsInWorkspace(resources, true);
- try {
- project.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
- assertExistsInFileSystem("3.1", resources);
- assertExistsInWorkspace("3.2", resources);
-
- // remove garbage
- try {
- project.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("20.0", e);
- }
-}
-
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GEAB3C_Test.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GEAB3C_Test.java
deleted file mode 100644
index d186778..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GEAB3C_Test.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.regression;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-import org.eclipse.core.tests.resources.ResourceDeltaVerifier;
-
-public class PR_1GEAB3C_Test extends EclipseWorkspaceTest {
- ResourceDeltaVerifier verifier;
-
- protected static final String VERIFIER_NAME = "TestListener";
-
-public PR_1GEAB3C_Test() {
-}
-public PR_1GEAB3C_Test(String name) {
- super(name);
-}
-public void assertDelta() {
- assertTrue(verifier.getMessage(), verifier.isDeltaValid());
-}
-/**
- * Runs code to handle a core exception
- */
-protected void handleCoreException(CoreException e) {
- assertTrue("CoreException: " + e.getMessage(), false);
-}
-/**
- * Sets up the fixture, for example, open a network connection.
- * This method is called before a test is executed.
- */
-protected void setUp() throws Exception {
- super.setUp();
- verifier = new ResourceDeltaVerifier();
- getWorkspace().addResourceChangeListener(verifier);
-}
-public static Test suite() {
- return new TestSuite(PR_1GEAB3C_Test.class);
-}
-/**
- * Tears down the fixture, for example, close a network connection.
- * This method is called after a test is executed.
- */
-protected void tearDown() throws Exception {
- super.tearDown();
- ensureDoesNotExistInWorkspace(getWorkspace().getRoot());
- getWorkspace().removeResourceChangeListener(verifier);
-}
-/*
- * Ensure that we get ADDED and OPEN in the delta when we create and open
- * a project in a workspace runnable.
- */
-public void test_1GEAB3C() {
- verifier.reset();
- final IProject project = getWorkspace().getRoot().getProject("MyAddedAndOpenedProject");
- verifier.addExpectedChange(project, IResourceDelta.ADDED, IResourceDelta.OPEN);
- verifier.addExpectedChange(project.getFile(IProjectDescription.DESCRIPTION_FILE_NAME), IResourceDelta.ADDED, 0);
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run (IProgressMonitor monitor) throws CoreException {
- monitor.beginTask("Creating and deleting", 100);
- try {
- project.create(new SubProgressMonitor(monitor, 50));
- project.open(new SubProgressMonitor(monitor, 50));
- } finally {
- monitor.done();
- }
- }
- };
- try {
- getWorkspace().run(body, getMonitor());
- } catch (CoreException e) {
- fail("1.1", e);
- }
- assertDelta();
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GH2B0N_Test.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GH2B0N_Test.java
deleted file mode 100644
index 8c1b12e..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GH2B0N_Test.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.regression;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectDescription;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-public class PR_1GH2B0N_Test extends EclipseWorkspaceTest {
-/**
- * Constructor for PR_1GH2B0N_Test
- */
-public PR_1GH2B0N_Test() {
- super();
-}
-/**
- * Constructor for PR_1GH2B0N_Test
- */
-public PR_1GH2B0N_Test(String name) {
- super(name);
-}
-public static Test suite() {
- return new TestSuite(PR_1GH2B0N_Test.class);
-}
-protected void tearDown() throws Exception {
- super.tearDown();
- ensureDoesNotExistInWorkspace(getWorkspace().getRoot());
-}
-public void test_1GH2B0N() {
- IPath path = new Path("c:/temp");
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- IProjectDescription description = getWorkspace().newProjectDescription("MyProject");
- IPath projectLocation = path.append(project.getName());
- description.setLocation(projectLocation);
- try {
- try {
- project.create(description, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
- try {
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("1.1", e);
- }
-
- IProject project2 = getWorkspace().getRoot().getProject("MyProject2");
- IStatus status = getWorkspace().validateProjectLocation(project2, project.getLocation().append(project2.getName()));
- assertTrue("2.0", !status.isOK());
- } finally {
- ensureDoesNotExistInWorkspace(project);
- ensureDoesNotExistInFileSystem(projectLocation.toFile());
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GHOM0N_Test.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GHOM0N_Test.java
deleted file mode 100644
index 33d39b9..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/PR_1GHOM0N_Test.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.regression;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-public class PR_1GHOM0N_Test extends EclipseWorkspaceTest {
-public PR_1GHOM0N_Test() {
-}
-public PR_1GHOM0N_Test(String name) {
- super(name);
-}
-/**
- * Sets up the fixture, for example, open a network connection.
- * This method is called before a test is executed.
- */
-protected void setUp() throws Exception {
- super.setUp();
-}
-public static Test suite() {
- return new TestSuite(PR_1GHOM0N_Test.class);
-}
-/**
- * Tears down the fixture, for example, close a network connection.
- * This method is called after a test is executed.
- */
-protected void tearDown() throws Exception {
- super.tearDown();
- ensureDoesNotExistInWorkspace(getWorkspace().getRoot());
-}
-/*
- * Ensure that we get ADDED and OPEN in the delta when we create and open
- * a project in a workspace runnable.
- */
-public void test_1GEAB3C() {
- // turn off auto-build
-// try {
-// IWorkspaceDescription wd = getWorkspace().getDescription();
-// wd.setAutoBuilding(false);
-// getWorkspace().setDescription(wd);
-// } catch (CoreException e) {
-// fail("1.0", e);
-// }
-
- // setup the project
- final IProject project = getWorkspace().getRoot().getProject("MyProject");
- try {
- IProjectDescription description = getWorkspace().newProjectDescription(project.getName());
- ICommand command = description.newCommand();
- command.setBuilderName(SimpleBuilder.BUILDER_ID);
- description.setBuildSpec(new ICommand[] { command });
- project.create(description, getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- // try and reproduce the error (there are problems when calling an incremental
- // build from within an operation...it leaves the tree immutable)
- IWorkspaceRunnable body = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, getMonitor());
- IFile file = project.getFile("test.txt");
- file.create(getRandomContents(), true, getMonitor());
- }
- };
- try {
- getWorkspace().run(body, getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/SimpleBuilder.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/SimpleBuilder.java
deleted file mode 100644
index a67f09a..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/SimpleBuilder.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.regression;
-
-import java.util.Map;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IncrementalProjectBuilder;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-/**
- * A builder that does not do anything.
- */
-public class SimpleBuilder extends IncrementalProjectBuilder {
-
- protected int triggerForLastBuild;
- protected static SimpleBuilder instance;
-
- /** contants */
- public static final String BUILDER_ID = "org.eclipse.core.tests.resources.simplebuilder";
-public SimpleBuilder() {
- super();
- instance = this;
-}
-protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
- triggerForLastBuild = kind;
- return null;
-}
-public static SimpleBuilder getInstance() {
- return instance;
-}
-/**
- *
- */
-protected void startupOnInitialize() {}
-public boolean wasAutoBuild() {
- return triggerForLastBuild == IncrementalProjectBuilder.AUTO_BUILD;
-}
-public boolean wasFullBuild() {
- return triggerForLastBuild == IncrementalProjectBuilder.FULL_BUILD;
-}
-public boolean wasIncrementalBuild() {
- return triggerForLastBuild == IncrementalProjectBuilder.INCREMENTAL_BUILD;
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/FindDeletedMembersTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/FindDeletedMembersTest.java
deleted file mode 100644
index 219f714..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/FindDeletedMembersTest.java
+++ /dev/null
@@ -1,371 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.session;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.tests.harness.WorkspaceSessionTest;
-
-/**
- * Copies the tests from HistoryStoreTest#testFindDeleted, phrased
- * as a session test.
- */
-public class FindDeletedMembersTest extends WorkspaceSessionTest {
- //common objects
- protected IWorkspaceRoot root;
- protected IProject project;
- protected IFile pfile;
- protected IFile folderAsFile;
- protected IFolder folder;
- protected IFile file;
- protected IFile file1;
- protected IFile file2;
- protected IFolder folder2;
- protected IFile file3;
-
-
-/**
- * Constructor for FindDeletedMembersTest.
- */
-public FindDeletedMembersTest() {
- super();
-}
-/**
- * Constructor for FindDeletedMembersTest.
- * @param name
- */
-public FindDeletedMembersTest(String name) {
- super(name);
-}
-protected void setUp() throws Exception {
- root = getWorkspace().getRoot();
- project = root.getProject("MyProject");
- pfile = project.getFile("file.txt");
- folder = project.getFolder("folder");
- file = folder.getFile("file.txt");
- folderAsFile = project.getFile(folder.getProjectRelativePath());
- file1 = folder.getFile("file1.txt");
- file2 = folder.getFile("file2.txt");
- folder2 = folder.getFolder("folder2");
- file3 = folder2.getFile("file3.txt");
-
-}
-protected void tearDown() throws Exception {
- getWorkspace().save(true, getMonitor());
-}
-public void test1() {
- try {
- project.create(getMonitor());
- project.open(getMonitor());
-
- IFile[] df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("0.1", 0, df.length);
- } catch (CoreException e) {
- fail("0.0", e);
- }
-
- // test that a deleted file can be found
- try {
- // create and delete a file
- pfile.create(getRandomContents(), true, getMonitor());
- pfile.delete(true, true, getMonitor());
- } catch (CoreException e) {
- fail("0.99", e);
- }
-}
-public void test2() {
- try {
- // the deleted file should show up as a deleted member of project
- IFile[] df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("0.1", 1, df.length);
- assertEquals("0.2", pfile, df[0]);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("0.3", 1, df.length);
- assertEquals("0.4", pfile, df[0]);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("0.5", 0, df.length);
-
- // the deleted file should show up as a deleted member of workspace root
- df = root.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("0.5.1", 0, df.length);
-
- df = root.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("0.5.2", 1, df.length);
- assertEquals("0.5.3", pfile, df[0]);
-
- df = root.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("0.5.4", 0, df.length);
-
- // recreate the file
- pfile.create(getRandomContents(), true, getMonitor());
- } catch (CoreException e) {
- fail("0.99", e);
- }
-}
-public void test3() {
- try {
- // the deleted file should no longer show up as a deleted member of project
- IFile[] df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("0.6", 0, df.length);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("0.7", 0, df.length);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("0.8", 0, df.length);
-
- // the deleted file should no longer show up as a deleted member of ws root
- df = root.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("0.8.1", 0, df.length);
-
- df = root.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("0.8.2", 0, df.length);
-
- df = root.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("0.8.3", 0, df.length);
-
- } catch (CoreException e) {
- fail("0.99", e);
- }
-
- // scrub the project
- try {
- project.delete(true, getMonitor());
- project.create(getMonitor());
- project.open(getMonitor());
-
- IFile[] df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("0.9", 0, df.length);
- } catch (CoreException e) {
- fail("0.10", e);
- }
-
- // test folder
- try {
- // create and delete a file in a folder
- folder.create(true, true, getMonitor());
- file.create(getRandomContents(), true, getMonitor());
- file.delete(true, true, getMonitor());
- } catch (CoreException e) {
- fail("1.99", e);
- }
-}
-public void test4() {
- try {
- // the deleted file should show up as a deleted member
- IFile[] df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("1.1", 0, df.length);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("1.2", 1, df.length);
- assertEquals("1.3", file, df[0]);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("1.4", 0, df.length);
-
- // recreate the file
- file.create(getRandomContents(), true, getMonitor());
-
- // the recreated file should no longer show up as a deleted member
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("1.5", 0, df.length);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("1.6", 0, df.length);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("1.7", 0, df.length);
-
- // deleting the folder should bring it back into history
- folder.delete(true, true, getMonitor());
- } catch (CoreException e) {
- fail("1.99", e);
- }
-}
-public void test5() {
- try {
- // the deleted file should show up as a deleted member of project
- IFile[] df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("1.8", 0, df.length);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("1.9", 1, df.length);
- assertEquals("1.10", file, df[0]);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("1.11", 0, df.length);
-
- // create and delete a file where the folder was
- folderAsFile.create(getRandomContents(), true, getMonitor());
- folderAsFile.delete(true, true, getMonitor());
- folder.create(true, true, getMonitor());
-
- // the deleted file should show up as a deleted member of folder
- df = folder.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("1.12", 1, df.length);
- assertEquals("1.13", folderAsFile, df[0]);
-
- df = folder.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("1.14", 2, df.length);
- List dfList = Arrays.asList(df);
- assertTrue("1.15", dfList.contains(file));
- assertTrue("1.16", dfList.contains(folderAsFile));
-
- df = folder.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("1.17", 2, df.length);
- dfList = Arrays.asList(df);
- assertTrue("1.18", dfList.contains(file));
- assertTrue("1.19", dfList.contains(folderAsFile));
-
-
- } catch (CoreException e) {
- fail("1.00", e);
- }
-
- // scrub the project
- try {
- project.delete(true, getMonitor());
- project.create(getMonitor());
- project.open(getMonitor());
-
- IFile[] df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("1.50", 0, df.length);
- } catch (CoreException e) {
- fail("1.51", e);
- }
-
- // test a bunch of deletes
- try {
- // create and delete a file in a folder
- folder.create(true, true, getMonitor());
- folder2.create(true, true, getMonitor());
- file1.create(getRandomContents(), true, getMonitor());
- file2.create(getRandomContents(), true, getMonitor());
- file3.create(getRandomContents(), true, getMonitor());
- folder.delete(true, true, getMonitor());
- } catch (CoreException e) {
- fail("3.99", e);
- }
-}
-public void test6() {
- try {
- // under root
- IFile[] df = root.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("3.1", 0, df.length);
-
- df = root.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("3.2", 0, df.length);
-
- df = root.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("3.3", 3, df.length);
- List dfList = Arrays.asList(df);
- assertTrue("3.3.1", dfList.contains(file1));
- assertTrue("3.3.2", dfList.contains(file2));
- assertTrue("3.3.3", dfList.contains(file3));
-
- // under project
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("3.4", 0, df.length);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("3.5", 0, df.length);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("3.6", 3, df.length);
- dfList = Arrays.asList(df);
- assertTrue("3.6.1", dfList.contains(file1));
- assertTrue("3.6.2", dfList.contains(file2));
- assertTrue("3.6.3", dfList.contains(file3));
-
- // under folder
- df = folder.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("3.7", 0, df.length);
-
- df = folder.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("3.8", 2, df.length);
-
- df = folder.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("3.9", 3, df.length);
-
- // under folder2
- df = folder2.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("3.10", 0, df.length);
-
- df = folder2.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("3.11", 1, df.length);
-
- df = folder2.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("3.12", 1, df.length);
-
- } catch (CoreException e) {
- fail("3.00", e);
- }
-
- try {
- project.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("3.5", e);
- }
-}
-public void test7() {
- // once the project is gone, so is all the history for that project
- try {
- // under root
- IFile[] df = root.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("4.1", 0, df.length);
-
- df = root.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("4.2", 0, df.length);
-
- df = root.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("4.3", 0, df.length);
-
-
- // under project
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("4.4", 0, df.length);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("4.5", 0, df.length);
-
- df = project.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("4.6", 0, df.length);
-
- // under folder
- df = folder.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("4.7", 0, df.length);
-
- df = folder.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("4.8", 0, df.length);
-
- df = folder.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("4.9", 0, df.length);
-
- // under folder2
- df = folder2.findDeletedMembersWithHistory(IResource.DEPTH_ZERO, getMonitor());
- assertEquals("4.10", 0, df.length);
-
- df = folder2.findDeletedMembersWithHistory(IResource.DEPTH_ONE, getMonitor());
- assertEquals("4.11", 0, df.length);
-
- df = folder2.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, getMonitor());
- assertEquals("4.12", 0, df.length);
-
- } catch (CoreException e) {
- fail("4.00", e);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/SampleSessionTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/SampleSessionTest.java
deleted file mode 100644
index 90c2da5..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/SampleSessionTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.session;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.tests.harness.WorkspaceSessionTest;
-
-/**
- * This class is a simple example of how session tests operate. Each method
- * starting with "test" will be invoked, in the order they are declared, in a separate
- * runtime instance of the workspace. Contents on disk are automatically
- * cleaned up after the last test method is run.
- */
-public class SampleSessionTest extends WorkspaceSessionTest {
-public SampleSessionTest() {
-}
-public SampleSessionTest(String name) {
- super(name);
-}
-public void test1() throws Exception {
- //create a project, save workspace
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
- IProject p1 = workspace.getRoot().getProject("P1");
- p1.create(null);
- p1.open(null);
- IFile file = p1.getFile("foo.txt");
- file.create(getRandomContents(), true, null);
- workspace.save(true, null);
-}
-public void test2() {
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
- IProject p1 = workspace.getRoot().getProject("P1");
- IFile file = p1.getFile("foo.txt");
- assertTrue("1.0", p1.exists());
- assertTrue("1.1", file.exists());
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/Test1G1N9GZ.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/Test1G1N9GZ.java
deleted file mode 100644
index b25f4ac..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/Test1G1N9GZ.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.session;
-
-import java.io.ByteArrayInputStream;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.tests.internal.builders.SortBuilder;
-
-/**
- * Regression test for 1G1N9GZ: ITPCORE:WIN2000 - ElementTree corruption when linking trees
- */
-public class Test1G1N9GZ extends WorkspaceSerializationTest {
-/**
- * Constructor for Test1G1N9GZ.
- */
-public Test1G1N9GZ() {
- super();
-}
-/**
- * Constructor for Test1G1N9GZ.
- * @param name
- */
-public Test1G1N9GZ(String name) {
- super(name);
-}
-/**
- * Initial setup and save
- */
-public void test1() throws CoreException {
- /* create P1 and set a builder */
- IProject p1 = workspace.getRoot().getProject("p1");
- p1.create(null);
- p1.open(null);
- IProjectDescription desc = p1.getDescription();
- ICommand command = desc.newCommand();
- command.setBuilderName(SortBuilder.BUILDER_NAME);
- command.getArguments().put(SortBuilder.BUILD_ID, "P1Build1");
- desc.setBuildSpec(new ICommand[] {command});
- p1.setDescription(desc, getMonitor());
-
- /* create P2 and set a builder */
- IProject p2 = workspace.getRoot().getProject("p2");
- p2.create(null);
- p2.open(null);
- desc = p1.getDescription();
- command = desc.newCommand();
- command.setBuilderName(SortBuilder.BUILDER_NAME);
- command.getArguments().put(SortBuilder.BUILD_ID, "P2Build1");
- desc.setBuildSpec(new ICommand[] {command});
- p1.setDescription(desc, getMonitor());
-
- /* PR test case */
- workspace.save(true, getMonitor());
-}
-public void test2() throws CoreException {
- workspace.save(true, getMonitor());
-}
-public void test3() throws CoreException {
- /* get new handles */
- IProject p1 = workspace.getRoot().getProject("p1");
- IProject p2 = workspace.getRoot().getProject("p2");
-
- /* try to create other files */
- try {
- ByteArrayInputStream source = new ByteArrayInputStream("file's content".getBytes());
- p1.getFile("file2").create(source, true, null);
- } catch (Exception e) {
- fail("1.0", e);
- }
- try {
- ByteArrayInputStream source = new ByteArrayInputStream("file's content".getBytes());
- p2.getFile("file2").create(source, true, null);
- } catch (Exception e) {
- fail("1.1", e);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/Test1GALH44.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/Test1GALH44.java
deleted file mode 100644
index 46543ec..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/Test1GALH44.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.session;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.tests.harness.WorkspaceSessionTest;
-import org.eclipse.core.tests.internal.builders.DeltaVerifierBuilder;
-
-public class Test1GALH44 extends WorkspaceSessionTest {
-/**
- * Prepares the environment. Create some resources and save the workspace.
- */
-public void test1() {
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- IProjectDescription description = getWorkspace().newProjectDescription("MyProject");
- ICommand command = description.newCommand();
- command.setBuilderName(DeltaVerifierBuilder.BUILDER_NAME);
- description.setBuildSpec(new ICommand[] { command });
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- project.setDescription(description, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- IFile file = project.getFile("foo.txt");
- try {
- file.create(getRandomContents(), true, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- try {
- getWorkspace().save(true, getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
-}
-/**
- * Step 2, edit a file then immediately crash.
- */
-public void test2() {
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- IFile file = project.getFile("foo.txt");
- try {
- file.setContents(getRandomContents(), true, true, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
- // crash
- System.exit(-1);
-}
-/**
- * Now immediately try to save after recovering from crash.
- */
-public void test3() {
- try {
- getWorkspace().save(true, getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
-
- //cleanup
- ensureDoesNotExistInWorkspace(getWorkspace().getRoot());
- try {
- getWorkspace().save(true, null);
- } catch(CoreException e) {
- fail("99.99", e);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBug12575.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBug12575.java
deleted file mode 100644
index 7d8a968..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBug12575.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.session;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectDescription;
-import org.eclipse.core.runtime.CoreException;
-
-/**
- *
- */
-public class TestBug12575 extends WorkspaceSerializationTest {
- public TestBug12575() {
- super();
- }
- public TestBug12575(String name) {
- super(name);
- }
- private static final String projectName = "Project";
- /**
- * Setup. Create a simple project, delete the .project file, shutdown
- * cleanly.
- */
- public void test1() {
- IProject project = workspace.getRoot().getProject(projectName);
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
- IFile dotProject = project.getFile(IProjectDescription.DESCRIPTION_FILE_NAME);
- try {
- dotProject.delete(IResource.NONE, getMonitor());
- } catch (CoreException e) {
- fail("1.1", e);
- }
- try {
- workspace.save(true, getMonitor());
- } catch (CoreException e) {
- fail("1.2", e);
- }
- }
- /**
- * Infection. Modify the .project, cause a snapshot, crash
- */
- public void test2() {
- IProject project = workspace.getRoot().getProject(projectName);
- IProject other = workspace.getRoot().getProject("Other");
- try {
- IProjectDescription desc = project.getDescription();
- desc.setReferencedProjects(new IProject[] {other});
- project.setDescription(desc, IResource.FORCE, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
- //creating a project will cause a snapshot
- ensureExistsInWorkspace(other, true);
-
- //crash
- }
- /**
- * Impact. Fails to start.
- */
- public void test3() {
- //just starting this test is a sign of success
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBug20127.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBug20127.java
deleted file mode 100644
index 90ee46d..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBug20127.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.session;
-
-import java.util.Map;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.tests.internal.builders.DeltaVerifierBuilder;
-import org.eclipse.core.tests.internal.builders.TestBuilder;
-
-/**
- * Tests regression of bug 20127 - error restoring builder state after
- * project move.
- */
-public class TestBug20127 extends WorkspaceSerializationTest {
-/**
- * Setup. Creates a project with a builder, with a built state,
- * autobuild off.
- */
-public void test1() {
- IProject project = workspace.getRoot().getProject("Project1");
- ensureExistsInWorkspace(project, true);
- try {
- //turn off autobuild
- IWorkspaceDescription desc = workspace.getDescription();
- desc.setAutoBuilding(false);
- workspace.setDescription(desc);
-
- //create a project and configure builder
- IProjectDescription description = project.getDescription();
- ICommand command = description.newCommand();
- Map args = command.getArguments();
- args.put(TestBuilder.BUILD_ID, "Project1Build1");
- command.setBuilderName(DeltaVerifierBuilder.BUILDER_NAME);
- command.setArguments(args);
- description.setBuildSpec(new ICommand[] {command});
- project.setDescription(description, getMonitor());
-
- //initial build
- workspace.build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
-
- getWorkspace().save(true, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-}
-/**
- * Rename the project without invoking any builds.
- */
-public void test2() {
- try {
- IProject project = workspace.getRoot().getProject("Project1");
- IProjectDescription desc = project.getDescription();
- desc.setName("MovedProject");
- project.move(desc, IResource.NONE, getMonitor());
- workspace.save(true, getMonitor());
- } catch (CoreException e) {
- fail ("1.0", e);
- }
-}
-/**
- * If this session starts correctly then the bug is fixed
- */
-public void test3() {
- IProject oldLocation = workspace.getRoot().getProject("Project1");
- IProject newLocation = workspace.getRoot().getProject("MovedProject");
-
- assertTrue("1.0", !oldLocation.exists());
- assertTrue("1.0", newLocation.exists());
- assertTrue("1.1", newLocation.isOpen());
- try {
- workspace.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, getMonitor());
- } catch (CoreException e) {
- fail("1.99", e);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBug30015.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBug30015.java
deleted file mode 100644
index 2efbb09..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBug30015.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.session;
-
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectDescription;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.WorkspaceSessionTest;
-
-/**
- * Tests regression of bug 30015. Due to this bug, it was impossible to restore
- * a project whose location was relative to a workspace path variable.
- */
-public class TestBug30015 extends WorkspaceSessionTest {
- protected static final String PROJECT_NAME = "Project";
- protected static final String VAR_NAME = "ProjectLocatio";
- protected IPath varValue;
- protected IPath rawLocation;
-
- public TestBug30015() {
- super();
- }
- public TestBug30015(String name) {
- super(name);
- }
- /**
- * Create and open the project
- */
- public void test1() {
- varValue = Platform.getLocation().removeLastSegments(1);
- rawLocation = new Path(VAR_NAME).append("ProjectLocation");
- //define the variable
- try {
- getWorkspace().getPathVariableManager().setValue(VAR_NAME, varValue);
- } catch (CoreException e) {
- fail("1.0", e);
- }
- IProject project = getWorkspace().getRoot().getProject(PROJECT_NAME);
- IProjectDescription description = getWorkspace().newProjectDescription(PROJECT_NAME);
- description.setLocation(rawLocation);
- //create the project
- try {
- project.create(description, getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("9.99", e);
- }
- //save and shutdown
- try {
- getWorkspace().save(true, getMonitor());
- } catch (CoreException e) {
- fail("9.99", e);
- }
- }
- /**
- * See if the project was successfully restored.
- */
- public void test2() {
- varValue = Platform.getLocation().removeLastSegments(1);
- rawLocation = new Path(VAR_NAME).append("ProjectLocation");
- IProject project = getWorkspace().getRoot().getProject(PROJECT_NAME);
-
- assertEquals("1.0", varValue, getWorkspace().getPathVariableManager().getValue(VAR_NAME));
- assertTrue("1.1", project.exists());
- assertTrue("1.2", project.isOpen());
- assertEquals("1.3", rawLocation, project.getRawLocation());
- assertEquals("1.4", varValue.append(rawLocation.lastSegment()), project.getLocation());
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBug6995.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBug6995.java
deleted file mode 100644
index 57ff268..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBug6995.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.session;
-
-import java.util.Map;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.tests.harness.WorkspaceSessionTest;
-import org.eclipse.core.tests.internal.builders.SortBuilder;
-import org.eclipse.core.tests.internal.builders.TestBuilder;
-
-/**
- * Tests the fix for bug 6995. In this bug, a snapshot immediately after startup and
- * before doing any builds was losing the old built tree. A subsequent build would
- * revert to a full build.
- */
-public class TestBug6995 extends WorkspaceSessionTest {
-/**
- * Constructor for TestBug6995.
- */
-public TestBug6995() {
- super();
-}
-/**
- * Constructor for TestBug6995.
- * @param name
- */
-public TestBug6995(String name) {
- super(name);
-}
-/**
- * Create a project and configure a builder for it.
- */
-public void test1() {
- //turn off autobuild
- IWorkspace workspace = getWorkspace();
- try {
- IWorkspaceDescription desc = workspace.getDescription();
- desc.setAutoBuilding(false);
- workspace.setDescription(desc);
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- //create a project and configure builder
- IProject project = workspace.getRoot().getProject("Project");
- try {
- project.create(getMonitor());
- project.open(getMonitor());
-
- IProjectDescription description = project.getDescription();
- ICommand command = description.newCommand();
- Map args = command.getArguments();
- args.put(TestBuilder.BUILD_ID, "Project1Build1");
- command.setBuilderName(SortBuilder.BUILDER_NAME);
- command.setArguments(args);
- description.setBuildSpec(new ICommand[] {command});
- project.setDescription(description, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- //do an initial build
- try {
- project.build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- }
-
- //save the workspace
- try {
- workspace.save(true, getMonitor());
- } catch (CoreException e) {
- fail("4.0", e);
- }
-}
-/**
- * After restarted the workspace, do a snapshot, then try to build.
- */
-public void test2() {
- IWorkspace workspace = getWorkspace();
- IProject project = workspace.getRoot().getProject("Project");
- //snapshot
- try {
- workspace.save(false, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- //build
- try {
- //make a change so build doesn't get short-circuited
- IFile file = project.getFile("File");
- file.create(getRandomContents(), true, getMonitor());
- project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- //make sure an incremental build occurred
- SortBuilder builder = SortBuilder.getInstance();
- assertTrue("3.0", !builder.wasDeltaNull());
- assertTrue("3.1", builder.wasIncrementalBuild());
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBuilderDeltaSerialization.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBuilderDeltaSerialization.java
deleted file mode 100644
index 4f979a8..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestBuilderDeltaSerialization.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.session;
-
-import java.io.ByteArrayInputStream;
-import java.util.Map;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.tests.internal.builders.SortBuilder;
-
-/**
- * Tests that builder deltas are correctly serialized.
- */
-public class TestBuilderDeltaSerialization extends WorkspaceSerializationTest {
- //various resource handles
- private IProject project1, project2;
- private IFolder sorted1, sorted2, unsorted1, unsorted2;
- private IFile sortedFile1, sortedFile2, unsortedFile1, unsortedFile2;
-
-/**
- * Constructor for TestBuilderDeltaSerialization.
- */
-public TestBuilderDeltaSerialization() {
- super();
-}
-/**
- * Constructor for TestBuilderDeltaSerialization.
- * @param name
- */
-public TestBuilderDeltaSerialization(String name) {
- super(name);
-}
-protected void setUp() throws Exception {
- super.setUp();
- IWorkspaceRoot root = getWorkspace().getRoot();
- project1 = root.getProject("Project1");
- unsorted1 = project1.getFolder(SortBuilder.UNSORTED_FOLDER);
- sorted1 = project1.getFolder(SortBuilder.SORTED_FOLDER);
- unsortedFile1 = unsorted1.getFile("File1");
- sortedFile1 = sorted1.getFile("File1");
-
- project2 = root.getProject("Project2");
- unsorted2 = project2.getFolder(SortBuilder.UNSORTED_FOLDER);
- sorted2 = project2.getFolder(SortBuilder.SORTED_FOLDER);
- unsortedFile2 = unsorted2.getFile("File2");
- sortedFile2 = sorted2.getFile("File2");
-}
-/**
- * Create projects, setup a builder, and do an initial build.
- */
-public void test1() {
- IResource[] resources = {project1, project2, unsorted1, unsorted2, sorted1, sorted2, unsortedFile1, unsortedFile2};
- ensureExistsInWorkspace(resources, true);
-
- try {
- //give unsorted files some initial content
- unsortedFile1.setContents(new ByteArrayInputStream(new byte[] {1, 4, 3}), true, true, null);
- unsortedFile2.setContents(new ByteArrayInputStream(new byte[] {1, 4, 3}), true, true, null);
-
- //turn off autobuild
- IWorkspace workspace = getWorkspace();
- IWorkspaceDescription desc = workspace.getDescription();
- desc.setAutoBuilding(false);
- desc.setBuildOrder(new String[] {project1.getName(), project2.getName()});
- workspace.setDescription(desc);
-
- //configure builder for project1
- IProjectDescription description = project1.getDescription();
- ICommand command = description.newCommand();
- Map args = command.getArguments();
- args.put(SortBuilder.BUILD_ID, "Project1Build1");
- args.put(SortBuilder.INTERESTING_PROJECT, project2.getName());
- command.setBuilderName(SortBuilder.BUILDER_NAME);
- command.setArguments(args);
- description.setBuildSpec(new ICommand[] {command});
- project1.setDescription(description, getMonitor());
-
- //configure builder for project2
- description = project1.getDescription();
- command = description.newCommand();
- args = command.getArguments();
- args.put(SortBuilder.BUILD_ID, "Project2Build1");
- args.put(SortBuilder.INTERESTING_PROJECT, project1.getName());
- command.setBuilderName(SortBuilder.BUILDER_NAME);
- command.setArguments(args);
- description.setBuildSpec(new ICommand[] {command});
- project2.setDescription(description, getMonitor());
-
- //initial build -- created sortedFile1 and sortedFile2
- workspace.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, getMonitor());
-
- getWorkspace().save(true, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
-}
-/**
- * Do another build immediately after restart. Builder1 should be invoked because it cares
- * about changes made by Builder2 during the last build phase.
- */
-public void test2() {
- try {
- getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, getMonitor());
- } catch (CoreException e) {
- fail("1.99", e);
- }
- //Only builder1 should have been built
- SortBuilder[] builders = SortBuilder.allInstances();
- assertEquals("1.0", 2, builders.length);
- assertTrue("1.1", builders[0].wasBuilt());
- assertTrue("1.2", builders[0].wasIncrementalBuild());
- assertTrue("1.3", !builders[1].wasBuilt());
-}
-
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestCloseNoSave.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestCloseNoSave.java
deleted file mode 100644
index b0c69e1..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestCloseNoSave.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.session;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-
-/**
- * Tests closing a workspace without save.
- */
-public class TestCloseNoSave extends WorkspaceSerializationTest {
-/**
- * Constructor for TestCloseNoSave.
- */
-public TestCloseNoSave() {
- super();
-}
-/**
- * Constructor for TestCloseNoSave.
- * @param name
- */
-public TestCloseNoSave(String name) {
- super(name);
-}
-public void test1() throws CoreException {
- /* create some resource handles */
- IProject project = workspace.getRoot().getProject(PROJECT);
- project.create(getMonitor());
- project.open(getMonitor());
- IFolder folder = project.getFolder(FOLDER);
- folder.create(true, true, getMonitor());
- IFile file = folder.getFile(FILE);
- file.create(getRandomContents(), true, getMonitor());
-}
-public void test2() throws CoreException {
- /* projects should exist, but files shouldn't. Refresh local should bring in files */
- IResource[] members = workspace.getRoot().members();
- assertEquals("1.0", 1, members.length);
- assertTrue("1.1", members[0].getType() == IResource.PROJECT);
- IProject project = (IProject)members[0];
- assertTrue("1.2", project.exists());
- members = project.members();
- assertEquals("1.3", 1, members.length);
- assertEquals("1.3a", IProjectDescription.DESCRIPTION_FILE_NAME, members[0].getName());
- IFolder folder = project.getFolder(FOLDER);
- IFile file = folder.getFile(FILE);
- assertTrue("1.4", !folder.exists());
- assertTrue("1.5", !file.exists());
-
- //opening the project does an automatic local refresh
- project.open(null);
-
- assertEquals("2.0", 2, project.members().length);
- assertTrue("2.1", folder.exists());
- assertTrue("2.2", file.exists());
-}
-}
-
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestClosedProjectLocation.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestClosedProjectLocation.java
deleted file mode 100644
index 7d2d0c6..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestClosedProjectLocation.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.session;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-
-/**
- * This is a test for bug 12507. Immediately after workspace startup, closed projects
- * would always specify the default location, even if they were not at the default
- * location. After opening the project, the location would be corrected.
- */
-public class TestClosedProjectLocation extends WorkspaceSerializationTest {
- IPath location = Platform.getLocation().removeLastSegments(1).append("OtherLocation");
-
-/**
- * Constructor for TestClosedProjectLocation.
- */
-public TestClosedProjectLocation() {
- super();
-}
-/**
- * Constructor for TestClosedProjectLocation.
- * @param name
- */
-public TestClosedProjectLocation(String name) {
- super(name);
-}
-/**
- * Create a project at a non-default location, and close it.
- */
-public void test1() {
- IProject project = workspace.getRoot().getProject(PROJECT);
- IFile file = project.getFile(FILE);
- try {
- IProjectDescription desc = workspace.newProjectDescription(PROJECT);
- desc.setLocation(location);
- project.create(desc, getMonitor());
- project.open(getMonitor());
- ensureExistsInWorkspace(file, true);
- project.close(getMonitor());
- } catch(CoreException e) {
- fail("1.0", e);
- }
- assertEquals("1.1", location, project.getLocation());
-
- try {
- workspace.save(true, getMonitor());
- } catch(CoreException e) {
- fail("1.2", e);
- }
-}
-/**
- * Now check the location of the closed project.
- */
-public void test2() {
- try {
- IProject project = workspace.getRoot().getProject(PROJECT);
- IFile file = project.getFile(FILE);
- assertTrue("1.0", project.exists());
- assertTrue("1.1", !project.isOpen());
- assertTrue("1.2", !file.exists());
- assertEquals("1.3", location, project.getLocation());
- } finally {
- ensureDoesNotExistInFileSystem(location.toFile());
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestInterestingProjectPersistence.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestInterestingProjectPersistence.java
deleted file mode 100644
index cadcc99..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestInterestingProjectPersistence.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.session;
-
-import java.util.ArrayList;
-import java.util.Map;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.tests.harness.WorkspaceSessionTest;
-import org.eclipse.core.tests.internal.builders.DeltaVerifierBuilder;
-import org.eclipse.core.tests.internal.builders.TestBuilder;
-
-/**
- * When a builder is run, it reports what projects it is interested in obtaining
- * deltas for the next time it is run. This class tests that this list of "interesting"
- * projects is correctly saved between sessions.
- */
-public class TestInterestingProjectPersistence extends WorkspaceSessionTest {
- //various resource handles
- private IProject project1;
- private IProject project2;
- private IProject project3;
- private IProject project4;
- private IFile file1;
- private IFile file2;
- private IFile file3;
- private IFile file4;
-
-/**
- * Constructor for TestInterestingProjectPersistence.
- */
-public TestInterestingProjectPersistence() {
- super();
-}
-/**
- * Constructor for TestInterestingProjectPersistence.
- * @param name
- */
-public TestInterestingProjectPersistence(String name) {
- super(name);
-}
-/**
- * Sets the workspace autobuilding to the desired value.
- */
-protected void setAutoBuilding(boolean value) throws CoreException {
- IWorkspace workspace = getWorkspace();
- if (workspace.isAutoBuilding() == value)
- return;
- IWorkspaceDescription desc = workspace.getDescription();
- desc.setAutoBuilding(value);
- workspace.setDescription(desc);
-}
-/*
- * @see TestCase#setUp()
- */
-protected void setUp() throws Exception {
- super.setUp();
- IWorkspaceRoot root = getWorkspace().getRoot();
- project1 = root.getProject("Project1");
- project2 = root.getProject("Project2");
- project3 = root.getProject("Project3");
- project4 = root.getProject("Project4");
- file1 = project1.getFile("File1");
- file2 = project2.getFile("File2");
- file3 = project3.getFile("File3");
- file4 = project4.getFile("File4");
-}
-/**
- * Create projects, setup a builder, and do an initial build.
- */
-public void test1() {
- IResource[] resources = {project1, project2, project3, project4, file1, file2, file3, file4};
- ensureExistsInWorkspace(resources, true);
- try {
- //turn off autobuild
- IWorkspace workspace = getWorkspace();
- IWorkspaceDescription desc = workspace.getDescription();
- desc.setAutoBuilding(false);
- workspace.setDescription(desc);
-
- //create a project and configure builder
- IProjectDescription description = project1.getDescription();
- ICommand command = description.newCommand();
- Map args = command.getArguments();
- args.put(TestBuilder.BUILD_ID, "Project1Build1");
- command.setBuilderName(DeltaVerifierBuilder.BUILDER_NAME);
- command.setArguments(args);
- description.setBuildSpec(new ICommand[] {command});
- project1.setDescription(description, getMonitor());
-
- //initial build requesting no projects
- project1.build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
-
- getWorkspace().save(true, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- }
-}
-/**
- * Check that "no interesting builders" case suceeded, then ask for more projects.
- */
-public void test2() {
- DeltaVerifierBuilder builder = DeltaVerifierBuilder.getInstance();
- builder.checkDeltas(new IProject[] {project1, project2, project3, project4});
- builder.requestDeltas(new IProject[] {project1, project2, project4});
- try {
- file1.setContents(getRandomContents(), true, true, getMonitor());
- project1.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, getMonitor());
- ArrayList received = builder.getReceivedDeltas();
-
- //should have received only a delta for project1
- assertEquals("1.0", 1, received.size());
- assertTrue("1.1", received.contains(project1));
-
- //should be no empty deltas
- ArrayList empty = builder.getEmptyDeltas();
- assertEquals("1.2", 0, empty.size());
-
- //save
- getWorkspace().save(true, getMonitor());
- } catch (CoreException e) {
- fail("1.99", e);
- }
-}
-/**
- * Check that interesting projects (1, 2, and 4) were stored and retrieved
- */
-public void test3() {
- DeltaVerifierBuilder builder = DeltaVerifierBuilder.getInstance();
- builder.checkDeltas(new IProject[] {project1, project2, project3, project4});
- try {
- //dirty projects 1, 2, 3
- file1.setContents(getRandomContents(), true, true, getMonitor());
- file2.setContents(getRandomContents(), true, true, getMonitor());
- file3.setContents(getRandomContents(), true, true, getMonitor());
-
- //build
- project1.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, getMonitor());
- ArrayList received = builder.getReceivedDeltas();
-
- //should have received deltas for 1, 2, and 4
- assertEquals("1.0", 3, received.size());
- assertTrue("1.1", received.contains(project1));
- assertTrue("1.2", received.contains(project2));
- assertTrue("1.3", !received.contains(project3));
- assertTrue("1.4", received.contains(project4));
-
- //delta for project4 should be empty
- ArrayList empty = builder.getEmptyDeltas();
- assertEquals("1.2", 1, empty.size());
- assertTrue("1.3", empty.contains(project4));
-
- //save
- getWorkspace().save(true, getMonitor());
- } catch (CoreException e) {
- fail("1.99", e);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestMasterTableCleanup.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestMasterTableCleanup.java
deleted file mode 100644
index 4c2a0c2..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestMasterTableCleanup.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/**********************************************************************
- * Copyright (c) 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 - Initial API and implementation
- **********************************************************************/
-package org.eclipse.core.tests.resources.session;
-
-import java.util.Properties;
-
-import org.eclipse.core.internal.resources.TestingSupport;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-
-/**
- * This is an internal test that makes sure the workspace master table does
- * not contain any stable entries after restart
- */
-public class TestMasterTableCleanup extends WorkspaceSerializationTest {
- private static final String CLOSE_OPEN = "CloseOpen";
- private static final String CLOSE_DELETE = "CloseDelete";
-
- public TestMasterTableCleanup() {
- super();
- }
- public TestMasterTableCleanup(String name) {
- super(name);
- }
- /**
- * Setup. Two scenarios with stale entries were:
- * 1) Project that was closed and then opened
- * 2) Project that was closed and then deleted
- */
- public void test1() {
- IProject closeOpen = getWorkspace().getRoot().getProject(CLOSE_OPEN);
- try {
- closeOpen.create(null);
- closeOpen.open(null);
- closeOpen.close(null);
- closeOpen.open(null);
-
- IProject closeDelete = getWorkspace().getRoot().getProject(CLOSE_DELETE);
- closeDelete.create(null);
- closeDelete.open(null);
- closeDelete.close(null);
- closeDelete.delete(IResource.NONE, null);
-
- getWorkspace().save(true, null);
- } catch (CoreException e) {
- fail("1.99", e);
- }
- }
- /**
- * Verify. Ensure safe table does not contain stale entries.
- */
- public void test2() {
- Properties masterTable = TestingSupport.getMasterTable();
- //ensure master table does not contain entries for stale projects
- IProject closeOpen = getWorkspace().getRoot().getProject(CLOSE_OPEN);
- IProject closeDelete = getWorkspace().getRoot().getProject(CLOSE_DELETE);
- assertTrue("2.0", !masterTable.containsKey(closeOpen.getFullPath().append(".tree").toString()));
- assertTrue("2.1", !masterTable.containsKey(closeDelete.getFullPath().append(".tree").toString()));
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestMissingBuilder.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestMissingBuilder.java
deleted file mode 100644
index bf9dfa7..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestMissingBuilder.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.session;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.tests.harness.WorkspaceSessionTest;
-import org.eclipse.core.tests.internal.builders.SnowBuilder;
-import org.eclipse.core.tests.internal.builders.TestBuilder;
-
-/**
- * Tests persistence cases for builders that are missing or disabled.
- */
-public class TestMissingBuilder extends WorkspaceSessionTest {
-/**
- * Constructor for TestMissingBuilderAcrossSessions.
- */
-public TestMissingBuilder() {
- super();
-}
-/**
- * Constructor for TestMissingBuilderAcrossSessions.
- * @param name
- */
-public TestMissingBuilder(String name) {
- super(name);
-}
-/**
- * Returns true if this project's build spec has the given builder,
- * and false otherwise.
- */
-protected boolean hasBuilder(IProject project, String builderId) {
- try {
- ICommand[] commands = project.getDescription().getBuildSpec();
- for (int i = 0; i < commands.length; i++) {
- if (commands[i].getBuilderName().equals(builderId))
- return true;
- }
- } catch(CoreException e) {
- fail("Failed in hasBuilder(" + project.getName() + ", " + builderId + ")", e);
- }
- return false;
-}
-protected InputStream projectFileWithoutWater() {
- String contents =
-"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
-"<projectDescription>\n" +
-" <name>P1</name>\n" +
-" <comment></comment>\n" +
-" <projects>\n" +
-" </projects>\n" +
-" <buildSpec>\n" +
-" <buildCommand>\n" +
-" <name>org.eclipse.core.tests.resources.snowbuilder</name>\n" +
-" <arguments>\n" +
-" <dictionary>\n" +
-" <key>BuildID</key>\n" +
-" <value>SnowBuild</value>\n" +
-" </dictionary>\n" +
-" </arguments>\n" +
-" </buildCommand>\n" +
-" </buildSpec>\n" +
-" <natures>\n" +
-" <nature>org.eclipse.core.tests.resources.snowNature</nature>\n" +
-" </natures>\n" +
-"</projectDescription>";
- return new ByteArrayInputStream(contents.getBytes());
-}
-/**
- * Sets the workspace autobuilding to the desired value.
- */
-protected void setAutoBuilding(boolean value) throws CoreException {
- IWorkspace workspace = getWorkspace();
- if (workspace.isAutoBuilding() == value)
- return;
- IWorkspaceDescription desc = workspace.getDescription();
- desc.setAutoBuilding(value);
- workspace.setDescription(desc);
-}
-/**
- * Setup. Create a project that has a disabled builder due to
- * missing nature prerequisite.
- */
-public void test1() {
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("P1");
- ensureExistsInWorkspace(project, true);
- try {
- setAutoBuilding(true);
- IProjectDescription desc = project.getDescription();
- desc.setNatureIds(new String[] {NATURE_WATER, NATURE_SNOW});
- project.setDescription(desc, IResource.FORCE, getMonitor());
- } catch (CoreException e) {
- fail("0.99", e);
- }
- //remove the water nature, thus invalidating snow nature
- SnowBuilder builder= SnowBuilder.getInstance();
- builder.reset();
- IFile descFile = project.getFile(IProjectDescription.DESCRIPTION_FILE_NAME);
- try {
- //setting description file will also trigger build
- descFile.setContents(projectFileWithoutWater(), IResource.FORCE, getMonitor());
- } catch(CoreException e) {
- fail("1.99", e);
- }
- //assert that builder was skipped
- builder.assertLifecycleEvents("1.0");
-
- //assert that the builder is still in the build spec
- assertTrue("1.1", hasBuilder(project, SnowBuilder.BUILDER_NAME));
-
- try {
- getWorkspace().save(true, getMonitor());
- } catch(CoreException e) {
- fail("99.99", e);
- }
-}
-/**
- * Now assert that the disabled builder was carried forward and that
- * it still doesn't build.
- */
-public void test2() {
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("P1");
-
- //assert that the builder is still in the build spec
- assertTrue("1.0", hasBuilder(project, SnowBuilder.BUILDER_NAME));
-
- //perform a build and ensure snow builder isn't called
- try {
- getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- } catch(CoreException e) {
- fail("1.99", e);
- }
- SnowBuilder builder = SnowBuilder.getInstance();
- builder.addExpectedLifecycleEvent(TestBuilder.SET_INITIALIZATION_DATA);
- builder.addExpectedLifecycleEvent(TestBuilder.STARTUP_ON_INITIALIZE);
- builder.assertLifecycleEvents("1.1");
-
- try {
- getWorkspace().save(true, getMonitor());
- } catch(CoreException e) {
- fail("99.99", e);
- }
-}
-/**
- * Test again in another workspace. This ensures that disabled builders
- * that were never instantiated get carried forward correctly.
- */
-public void test3(){
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("P1");
-
- //assert that the builder is still in the build spec
- assertTrue("1.0", hasBuilder(project, SnowBuilder.BUILDER_NAME));
-
- //perform a build and ensure snow builder isn't called
- try {
- getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
- } catch(CoreException e) {
- fail("1.99", e);
- }
- SnowBuilder builder = SnowBuilder.getInstance();
- builder.addExpectedLifecycleEvent(TestBuilder.SET_INITIALIZATION_DATA);
- builder.addExpectedLifecycleEvent(TestBuilder.STARTUP_ON_INITIALIZE);
- builder.assertLifecycleEvents("1.1");
-
- //now re-enable the nature and ensure that the delta was null
- builder.reset();
- builder.addExpectedLifecycleEvent(SnowBuilder.SNOW_BUILD_EVENT);
- try {
- IProjectDescription desc = project.getDescription();
- desc.setNatureIds(new String[] {NATURE_WATER, NATURE_SNOW});
- project.setDescription(desc, IResource.FORCE, getMonitor());
- } catch (CoreException e) {
- fail("2.99", e);
- }
- builder.assertLifecycleEvents("2.0");
- assertTrue("2.1", builder.wasDeltaNull());
-
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestMultiSnap.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestMultiSnap.java
deleted file mode 100644
index 76baeaa..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestMultiSnap.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.session;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-
-/**
- * Tests performing multiple snapshots on a workspace that has
- * never been saved, then crashing and recovering.
- */
-public class TestMultiSnap extends WorkspaceSerializationTest {
- /**
- * Constructor for TestMultiSnap.
- */
- public TestMultiSnap() {
- super();
- }
- /**
- * Constructor for TestMultiSnap.
- * @param name
- */
- public TestMultiSnap(String name) {
- super(name);
- }
-public void test1() throws Exception {
- /* create some resource handles */
- IProject project = getWorkspace().getRoot().getProject(PROJECT);
- project.create(getMonitor());
- project.open(getMonitor());
-
- /* snapshot */
- workspace.save(false, getMonitor());
-
- /* do more stuff */
- IFolder folder = project.getFolder(FOLDER);
- folder.create(true, true, getMonitor());
-
- workspace.save(false, getMonitor());
-
- /* do even more stuff */
- IFile file = folder.getFile(FILE);
- byte[] bytes = "Test bytes".getBytes();
- java.io.ByteArrayInputStream in = new java.io.ByteArrayInputStream(bytes);
- file.create(in, true, getMonitor());
-
- workspace.save(false, getMonitor());
-
- //exit without saving
-}
-public void test2() throws CoreException {
- IProject project = getWorkspace().getRoot().getProject(PROJECT);
- IFolder folder = project.getFolder(FOLDER);
- IFile file = folder.getFile(FILE);
-
- /* see if the workspace contains the resources created earlier*/
- IResource[] children = getWorkspace().getRoot().members();
- assertEquals("1.0", 1, children.length);
- assertEquals("1.1", children[0], project);
- assertTrue("1.2", project.exists());
- assertTrue("1.3", project.isOpen());
-
- assertExistsInWorkspace("1.4", new IResource[] {project, folder, file});
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSave.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSave.java
deleted file mode 100644
index d3e73bb..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSave.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.session;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-
-/**
- * Tests performing a save on a workspace, then crashing and recovering.
- */
-public class TestSave extends WorkspaceSerializationTest {
-/**
- * Constructor for TestSave.
- */
-public TestSave() {
- super();
-}
-/**
- * Constructor for TestSave.
- * @param name
- */
-public TestSave(String name) {
- super(name);
-}
-public void test1() {
- /* create some resource handles */
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT);
- try {
- project.create(getMonitor());
- project.open(getMonitor());
-
- workspace.save(true, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-}
-public void test2() {
- IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- assertTrue("1.0", root.exists());
- try {
- IResource[] children = root.members();
- assertEquals("1.2", 1, children.length);
- IProject project = (IProject)children[0];
- assertTrue("1.3", project.exists());
- assertTrue("1.4", project.isOpen());
- assertEquals("1.5", PROJECT, project.getName());
- } catch (CoreException e) {
- fail("1.99", e);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSaveCreateProject.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSaveCreateProject.java
deleted file mode 100644
index 4883c3d..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSaveCreateProject.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.session;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-
-/**
- * Tests recovery after adding a project and not saving
- */
-public class TestSaveCreateProject extends WorkspaceSerializationTest {
-/**
- * Constructor for TestSaveCreateProject.
- */
-public TestSaveCreateProject() {
- super();
-}
-/**
- * Constructor for TestSaveCreateProject.
- * @param name
- */
-public TestSaveCreateProject(String name) {
- super(name);
-}
-public void test1() {
- /* create some resource handles */
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT);
- try {
- workspace.save(true, getMonitor());
-
- project.create(getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
-}
-public void test2() {
- IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- assertTrue("1.0", root.exists());
- try {
- IResource[] children = root.members();
- assertEquals("1.2", 1, children.length);
- IProject project = (IProject)children[0];
- assertTrue("1.3", project.exists());
- assertTrue("1.4", !project.isOpen());
- assertEquals("1.5", PROJECT, project.getName());
- } catch (CoreException e) {
- fail("1.99", e);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSaveSnap.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSaveSnap.java
deleted file mode 100644
index 4fca34d..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSaveSnap.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.session;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-
-/**
- * Tests saving the workspace, then performing snapshots, then crashing and recovering
- */
-public class TestSaveSnap extends WorkspaceSerializationTest {
-/**
- * Constructor for TestSaveSnap.
- */
-public TestSaveSnap() {
- super();
-}
-/**
- * Constructor for TestSaveSnap.
- * @param name
- */
-public TestSaveSnap(String name) {
- super(name);
-}
-public void test1() throws Exception {
- /* create some resource handles */
- IProject project = getWorkspace().getRoot().getProject(PROJECT);
- project.create(getMonitor());
- project.open(getMonitor());
-
- /* full save */
- workspace.save(true, getMonitor());
-
- /* do more stuff */
- IFolder folder = project.getFolder(FOLDER);
- folder.create(true, true, getMonitor());
-
- //snapshot
- workspace.save(false, getMonitor());
-
- /* do even more stuff */
- IFile file = folder.getFile(FILE);
- byte[] bytes = "Test bytes".getBytes();
- java.io.ByteArrayInputStream in = new java.io.ByteArrayInputStream(bytes);
- file.create(in, true, getMonitor());
-
- //snapshot
- workspace.save(false, getMonitor());
-
- //exit without saving
-}
-public void test2() throws CoreException {
- IProject project = getWorkspace().getRoot().getProject(PROJECT);
- IFolder folder = project.getFolder(FOLDER);
- IFile file = folder.getFile(FILE);
-
- /* see if the workspace contains the resources created earlier*/
- IResource[] children = getWorkspace().getRoot().members();
- assertEquals("1.0", 1, children.length);
- assertEquals("1.1", children[0], project);
- assertTrue("1.2", project.exists());
- assertTrue("1.3", project.isOpen());
-
- assertExistsInWorkspace("1.4", new IResource[] {project, folder, file});
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSaveWithClosedProject.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSaveWithClosedProject.java
deleted file mode 100644
index 9574500..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSaveWithClosedProject.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.session;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-
-/**
- * Create a project, close it, save, crash, recover. Recovered project should still be closed.
- */
-public class TestSaveWithClosedProject extends WorkspaceSerializationTest {
-/**
- * Constructor for TestSaveWithClosedProject.
- */
-public TestSaveWithClosedProject() {
- super();
-}
-/**
- * Constructor for TestSaveWithClosedProject.
- * @param name
- */
-public TestSaveWithClosedProject(String name) {
- super(name);
-}
-public void test1() {
- /* create some resource handles */
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT);
- IFile file = project.getFile(FILE);
- try {
- project.create(getMonitor());
- project.open(getMonitor());
- file.create(getRandomContents(), true, null);
- project.close(getMonitor());
-
- workspace.save(true, getMonitor());
- } catch (CoreException e) {
- fail("1.99", e);
- }
-}
-public void test2() {
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT);
- IFile file = project.getFile(FILE);
-
- assertTrue("1.0", project.exists());
- assertTrue("1.1", !project.isOpen());
- assertTrue("1.2", !file.exists());
-
- try {
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("1.99", e);
- }
-
- assertTrue("2.0", project.isOpen());
- assertTrue("2.1", file.exists());
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSnapSaveSnap.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSnapSaveSnap.java
deleted file mode 100644
index acefc65..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestSnapSaveSnap.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.session;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-
-/**
- * Tests snapshoting, saving, snapshoting, then crash and recover.
- */
-public class TestSnapSaveSnap extends WorkspaceSerializationTest {
-/**
- * Constructor for TestSnapSaveSnap.
- */
-public TestSnapSaveSnap() {
- super();
-}
-/**
- * Constructor for TestSnapSaveSnap.
- * @param name
- */
-public TestSnapSaveSnap(String name) {
- super(name);
-}
-public void test1() {
- /* create some resource handles */
- IProject project = getWorkspace().getRoot().getProject(PROJECT);
- IFolder folder = project.getFolder(FOLDER);
- IFile file = folder.getFile(FILE);
- try {
- project.create(getMonitor());
- project.open(getMonitor());
-
- //snapshot
- workspace.save(false, getMonitor());
-
- /* do more stuff */
- folder.create(true, true, getMonitor());
-
- //full save
- workspace.save(true, getMonitor());
-
- /* do even more stuff */
- byte[] bytes = "Test bytes".getBytes();
- java.io.ByteArrayInputStream in = new java.io.ByteArrayInputStream(bytes);
- file.create(in, true, getMonitor());
-
- //snapshot
- workspace.save(false, getMonitor());
- } catch (CoreException e) {
- fail("1.99", e);
- }
- //exit without saving
-}
-public void test2() throws CoreException {
- IProject project = getWorkspace().getRoot().getProject(PROJECT);
- IFolder folder = project.getFolder(FOLDER);
- IFile file = folder.getFile(FILE);
-
- /* see if the workspace contains the resources created earlier*/
- IResource[] children = getWorkspace().getRoot().members();
- assertEquals("1.0", 1, children.length);
- assertEquals("1.1", children[0], project);
- assertTrue("1.2", project.exists());
- assertTrue("1.3", project.isOpen());
-
- assertExistsInWorkspace("1.4", new IResource[] {project, folder, file});
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/WorkspaceDescriptionTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/WorkspaceDescriptionTest.java
deleted file mode 100644
index 8eea366..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/WorkspaceDescriptionTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.session;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.tests.harness.WorkspaceSessionTest;
-
-/**
- * Ensures that the workspace description is correctly persisted across
- * sessions.
- */
-public class WorkspaceDescriptionTest extends WorkspaceSessionTest {
- private static final String[] BUILD_ORDER = new String[] {"Foo"};
- private static final int STATE_LONGEVITY = 123456;
- private static final int MAX_STATES = 244;
- private static final long MAX_FILE_SIZE = 1024 * 53;
- private static final long SNAPSHOT_INTERVAL = 4321;
- public WorkspaceDescriptionTest() {
- super();
- }
- public WorkspaceDescriptionTest(String name) {
- super(name);
- }
- public void test1() {
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
- IWorkspaceDescription desc = workspace.getDescription();
- desc.setAutoBuilding(false);
- desc.setBuildOrder(BUILD_ORDER);
- desc.setFileStateLongevity(STATE_LONGEVITY);
- desc.setMaxFileStates(MAX_STATES);
- desc.setMaxFileStateSize(MAX_FILE_SIZE);
- desc.setSnapshotInterval(SNAPSHOT_INTERVAL);
- try {
- workspace.setDescription(desc);
- workspace.save(true, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
- }
- public void test2() {
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
- IWorkspaceDescription desc = workspace.getDescription();
- assertTrue("2.0", !desc.isAutoBuilding());
- assertEquals("2.1", BUILD_ORDER, desc.getBuildOrder());
- assertEquals("2.2", STATE_LONGEVITY, desc.getFileStateLongevity());
- assertEquals("2.3", MAX_STATES, desc.getMaxFileStates());
- assertEquals("2.4", MAX_FILE_SIZE, desc.getMaxFileStateSize());
- assertEquals("2.5", SNAPSHOT_INTERVAL, desc.getSnapshotInterval());
- }
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/WorkspaceSerializationTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/WorkspaceSerializationTest.java
deleted file mode 100644
index 044bcf0..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/WorkspaceSerializationTest.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.session;
-
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.tests.harness.WorkspaceSessionTest;
-
-public class WorkspaceSerializationTest extends WorkspaceSessionTest {
- protected static final String PROJECT = "CrashProject";
- protected static final String FOLDER = "CrashFolder";
- protected static final String FILE = "CrashFile";
- protected IWorkspace workspace;
-
-/**
- * Creates a new WorkspaceSerializationTest.
- */
-public WorkspaceSerializationTest() {
- super("");
-}
-/**
- * Creates a new WorkspaceSerializationTest.
- * @param name the name of the test method to run
- */
-public WorkspaceSerializationTest(String name) {
- super(name);
-}
-protected void setUp() throws Exception {
- workspace = getWorkspace();
-}
-}
-
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/AllTests.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/AllTests.java
deleted file mode 100644
index fe73f91..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/AllTests.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.usecase;
-
-import junit.framework.*;
-
-public class AllTests extends TestCase {
-/**
- * AllTests constructor comment.
- * @param name java.lang.String
- */
-public AllTests() {
- super(null);
-}
-/**
- * AllTests constructor comment.
- * @param name java.lang.String
- */
-public AllTests(String name) {
- super(name);
-}
-public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(BuilderUseCaseTest.suite());
- suite.addTest(ConcurrencyTest.suite());
- suite.addTest(IFileTest.suite());
- suite.addTest(IFolderTest.suite());
- suite.addTest(IProjectTest.suite());
- suite.addTest(IWorkspaceRunnableUseCaseTest.suite());
- return suite;
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/BuilderUseCaseTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/BuilderUseCaseTest.java
deleted file mode 100644
index 3a04b49..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/BuilderUseCaseTest.java
+++ /dev/null
@@ -1,175 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.usecase;
-
-import java.io.ByteArrayInputStream;
-import java.util.Map;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-import org.eclipse.core.tests.internal.builders.SortBuilder;
-import org.eclipse.core.tests.resources.Comparator;
-import org.eclipse.core.tests.resources.ResourceDeltaVerifier;
-
-public class BuilderUseCaseTest extends EclipseWorkspaceTest {
-public BuilderUseCaseTest() {
- super();
-}
-public BuilderUseCaseTest(String name) {
- super(name);
-}
-/**
- * Sets the workspace autobuilding to the desired value.
- */
-protected void setAutoBuilding(boolean value) throws CoreException {
- IWorkspace workspace = getWorkspace();
- if (workspace.isAutoBuilding() == value)
- return;
- IWorkspaceDescription desc = workspace.getDescription();
- desc.setAutoBuilding(value);
- workspace.setDescription(desc);
-}
-public void testSortBuilder() {
- IProgressMonitor monitor = null;
-
- // Create some resource handles
- IProject proj = getWorkspace().getRoot().getProject("Project");
- IFolder unsortedFolder = proj.getFolder(SortBuilder.DEFAULT_UNSORTED_FOLDER);
- IFolder sortedFolder = proj.getFolder(SortBuilder.DEFAULT_SORTED_FOLDER);
- IFile file1a = unsortedFolder.getFile("File" + 1);
- IFile file2a = unsortedFolder.getFile("File" + 2);
- IFile file1b = sortedFolder.getFile("File" + 1);
- IFile file2b = sortedFolder.getFile("File" + 2);
-
- // Create unsorted content for each file
- byte[] bytes1a = new byte[] {0, 4, 1, 3, 2};
- byte[] bytes2a = new byte[] {9, 5, 8, 6, 7};
-
- // Create sorted content for each file (ascending order)
- byte[] bytes1b = new byte[] {0, 1, 2, 3, 4};
- byte[] bytes2b = new byte[] {5, 6, 7, 8, 9};
-
- // Create sorted content for each file (descending order)
- byte[] bytes1c = new byte[] {4, 3, 2, 1, 0};
- byte[] bytes2c = new byte[] {9, 8, 7, 6, 5};
- ByteArrayInputStream bais1a = null;
- ByteArrayInputStream bais2a = null;
-
- try {
- // Turn auto-building off
- setAutoBuilding(false);
-
- // Create some resources
- bais1a = new ByteArrayInputStream(bytes1a);
- bais2a = new ByteArrayInputStream(bytes2a);
- proj.create(monitor);
- proj.open(monitor);
- unsortedFolder.create(false, true, monitor);
- file1a.create(bais1a, false, monitor);
- file2a.create(bais2a, false, monitor);
- } catch (CoreException e) {
- fail("1.0", e);
- }
-
- // Set up a resource delta verifier
- ResourceDeltaVerifier verifier = new ResourceDeltaVerifier();
- getWorkspace().addResourceChangeListener(verifier);
-
- // Create and set a build spec for the project
- try {
- IProjectDescription desc = proj.getDescription();
- ICommand command = desc.newCommand();
- command.setBuilderName(SortBuilder.BUILDER_NAME);
- Map arguments = command.getArguments();
- arguments.put(SortBuilder.SORT_ORDER, SortBuilder.ASCENDING);
- desc.setBuildSpec(new ICommand[] {command});
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- // Build the solution
- try {
- verifier.addExpectedChange(sortedFolder, IResourceDelta.ADDED, 0);
- verifier.addExpectedChange(file1b, IResourceDelta.ADDED, 0);
- verifier.addExpectedChange(file2b, IResourceDelta.ADDED, 0);
- proj.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
- assertTrue("3.0 " + verifier.getMessage(), verifier.isDeltaValid());
- assertTrue("3.1", Comparator.equals(bytes1b, readBytesInWorkspace(file1b)));
- assertTrue("3.2", Comparator.equals(bytes2b, readBytesInWorkspace(file2b)));
- } catch (CoreException e) {
- fail("3.3", e);
- }
-
- // Change an unsorted file and build the solution
- try {
- verifier.addExpectedChange(file2a, IResourceDelta.CHANGED, IResourceDelta.CONTENT);
- bais2a = new ByteArrayInputStream(bytes1a);
- file2a.setContents(bais2a, true, false, monitor);
- assertTrue("4.0 " + verifier.getMessage(), verifier.isDeltaValid());
-
- verifier.addExpectedChange(file2b, IResourceDelta.CHANGED, IResourceDelta.CONTENT);
- proj.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
- assertTrue("4.0 " + verifier.getMessage(), verifier.isDeltaValid());
- assertTrue("4.1", Comparator.equals(bytes1b, readBytesInWorkspace(file2b)));
- } catch (CoreException e) {
- fail("4.2", e);
- }
-
- // Remove an unsorted file and build the solution
- try {
- verifier.addExpectedChange(file2a, IResourceDelta.REMOVED, 0);
- file2a.delete(false, monitor);
- assertTrue("5.0 " + verifier.getMessage(), verifier.isDeltaValid());
-
- verifier.addExpectedChange(file2b, IResourceDelta.REMOVED, 0);
- proj.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
- assertTrue("5.1 " + verifier.getMessage(), verifier.isDeltaValid());
- } catch (CoreException e) {
- fail("5.9", e);
- }
-
- // Add an unsorted file and build the solution
- try {
- verifier.reset();
- verifier.addExpectedChange(file2a, IResourceDelta.ADDED, 0);
- bais2a = new ByteArrayInputStream(bytes2a);
- file2a.create(bais2a, false, monitor);
- assertTrue("6.0 " + verifier.getMessage(), verifier.isDeltaValid());
-
- verifier.addExpectedChange(file2b, IResourceDelta.ADDED, 0);
- proj.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
- assertTrue("6.1 " + verifier.getMessage(), verifier.isDeltaValid());
- assertTrue("6.2", Comparator.equals(bytes2b, readBytesInWorkspace(file2b)));
- } catch (CoreException e) {
- fail("6.9", e);
- }
-
- // Change the builder's sort order and build the solution
- try {
- IProjectDescription desc = proj.getDescription();
- ICommand command = desc.getBuildSpec()[0];
- Map arguments = command.getArguments();
- arguments.put(SortBuilder.SORT_ORDER, SortBuilder.DESCENDING);
-
- verifier.addExpectedChange(file1b, IResourceDelta.CHANGED, IResourceDelta.CONTENT | IResourceDelta.REPLACED);
- verifier.addExpectedChange(file2b, IResourceDelta.CHANGED, IResourceDelta.CONTENT | IResourceDelta.REPLACED);
-
- proj.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
- assertTrue("7.0 " + verifier.getMessage(), verifier.isDeltaValid());
- assertTrue("7.1", Comparator.equals(bytes1c, readBytesInWorkspace(file1b)));
- assertTrue("7.2", Comparator.equals(bytes2c, readBytesInWorkspace(file2b)));
- } catch (CoreException e) {
- fail("7.3", e);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/ConcurrencyPerformanceTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/ConcurrencyPerformanceTest.java
deleted file mode 100644
index 64ceb08..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/ConcurrencyPerformanceTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.usecase;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.CorePerformanceTest;
-import junit.framework.*;
-
-public class ConcurrencyPerformanceTest extends CorePerformanceTest {
-public ConcurrencyPerformanceTest() {
- super("");
-}
-public ConcurrencyPerformanceTest(String name) {
- super(name);
-}
-public static Test suite() {
- return new TestSuite(ConcurrencyPerformanceTest.class);
-}
-public void testSimpleCalls() throws CoreException {
-
- IWorkspaceRunnable job = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- }
- };
- startBench();
- int repeat = 50;
- for (int i = 0; i < repeat; i++) {
- getWorkspace().run(job, null);
- }
- stopBench("testSimpleCalls", repeat);
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/ConcurrencyTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/ConcurrencyTest.java
deleted file mode 100644
index d6c09fd..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/ConcurrencyTest.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.usecase;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-import junit.framework.*;
-
-public class ConcurrencyTest extends EclipseWorkspaceTest {
-public ConcurrencyTest() {
-}
-public ConcurrencyTest(String name) {
- super(name);
-}
-protected void assertIsNotRunning(ConcurrentOperation01 op, String label) {
- /* try more than once, "just in case" */
- for (int i = 0; i < 3; i++) {
- try {
- Thread.sleep(100 * i); // fancy sleep
- } catch (InterruptedException e) {}
- assertTrue(label, !op.isRunning());
- }
-}
-public static Test suite() {
- return new TestSuite(ConcurrencyTest.class);
-}
-/**
- * This test is used to find out if two operations can start concurrently. It assumes
- * that they cannot.
- */
-public void testConcurrentOperations() throws CoreException {
-
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- project.create(null);
- project.open(null);
-
- buildResources(project, defineHierarchy());
-
- ConcurrentOperation01 op1 = new ConcurrentOperation01(getWorkspace());
- ConcurrentOperation01 op2 = new ConcurrentOperation01(getWorkspace());
-
- /* start first operation */
- new Thread(op1, "op1").start();
- assertTrue("0.0", op1.hasStarted());
- op1.returnWhenInSyncPoint();
- assertTrue("0.1", op1.isRunning());
-
- /* start second operation but it should not run until the first finishes */
- new Thread(op2, "op2").start();
- assertTrue("1.0", op2.hasStarted());
- assertIsNotRunning(op2, "1.1");
-
- /* free operations */
- op1.proceed();
- op2.returnWhenInSyncPoint();
- assertTrue("2.0", op2.isRunning());
- op2.proceed();
- assertTrue("2.1", op1.getStatus().isOK());
- assertTrue("2.2", op2.getStatus().isOK());
-
- /* remove trash */
- try {
- ensureDoesNotExistInWorkspace(getWorkspace().getRoot());
- } catch(Exception e){
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/ConcurrentOperation.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/ConcurrentOperation.java
deleted file mode 100644
index f9df2e4..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/ConcurrentOperation.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.usecase;
-
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.internal.resources.ResourceStatus;
-/**
- * A class to help testing use cases that access the workspace concurrently but in
- * a deterministic way.
- * Operations can be defined with some sync points. It means that the operation will
- * run to that point and wait for some other thread signal (call #proceed) before continuing.
- *
- * Some of the constructs can lead to deadlocks if not used correctly.
- *
- * One tip to avoid deadlocks is aways honour the sync points defined by the operation.
- * For example, exceptions should be logged using #logException instead of thrown.
- *
- * Although operations of this type can run using IWorkspace.run(), it was designed
- * to run in a separate thread.
- * Example: new Thread(concurrentOperation).start();
- */
-public abstract class ConcurrentOperation implements Runnable, IWorkspaceRunnable {
- /** workspace */
- protected IWorkspace workspace;
-
- /** synchronization flags */
- protected boolean go;
- protected boolean isWaiting;
- protected int hasStarted;
-
- /** log any exception we get */
- protected MultiStatus status;
-
- /** locks */
- protected Object startedLock = new Object();
-
- /** constants */
- protected static final int STARTED_NONE = 0;
- protected static final int STARTED_YES = 1;
- protected static final int STARTED_NO = 2;
-public ConcurrentOperation(IWorkspace workspace) {
- this.workspace = workspace;
- reset();
-}
-/**
- * This method should verify all pre-requisites necessaries in order
- * to the operation run properly.
- */
-abstract protected void assertRequisites() throws Exception;
-public IStatus getStatus() {
- return status;
-}
-/**
- * Returns only when we get out of the STARTED_NONE state.
- */
-public boolean hasStarted() {
-
- synchronized (startedLock) {
- while (hasStarted == STARTED_NONE) {
- try {
- startedLock.wait();
- } catch (InterruptedException e) {}
- }
- }
- return hasStarted == STARTED_YES;
-}
-protected boolean isReadyToStart() {
- boolean ok = true;
- try {
- assertRequisites();
- } catch (Exception e) {
- logException(e);
- ok = false;
- }
- return ok;
-}
-protected void logException(Exception e) {
- if (e instanceof CoreException)
- status.add(((CoreException) e).getStatus());
- else
- status.add(new ResourceStatus(0, null, null, e));
-}
-/**
- * @see #waitNotification
- */
-public synchronized void proceed() {
- go = true;
- notify();
-}
-public void reset() {
- go = false;
- isWaiting = false;
- hasStarted = STARTED_NONE;
- status = new MultiStatus("a plugin", IStatus.INFO, "", null);
-}
-/**
- * Only returns from this method if the operation is in
- * a sync point.
- *
- * This method can cause deadlock.
- */
-public synchronized void returnWhenInSyncPoint() {
- while (!isWaiting && hasStarted()) {
- try {
- wait();
- } catch (InterruptedException e) {
- }
- }
-}
-public void run() {
-
- if (isReadyToStart()) {
- setHasStarted(true);
- try {
- workspace.run(this, null);
- } catch (Exception e) {
- logException(e);
- }
- } else
- setHasStarted(false);
-
-}
-protected void setHasStarted(boolean value) {
-
- synchronized (startedLock) {
- hasStarted = value ? STARTED_YES : STARTED_NO;
- startedLock.notify();
- }
-}
-/**
- * Waits until #proceed is called.
- *
- * This method can cause deadlock.
- */
-protected synchronized void syncPoint() {
- /* we set "go" to false because we want to continue only when proceed is called */
- go = false;
- isWaiting = true;
- notify(); // notify we are in a sync point
- while (!go) {
- try {
- wait();
- } catch (InterruptedException e) {
- }
- }
- isWaiting = false;
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/ConcurrentOperation01.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/ConcurrentOperation01.java
deleted file mode 100644
index 0a3f7a3..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/ConcurrentOperation01.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.usecase;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.resources.IWorkspace;
-/**
- * This operation does not change any resource. It only has one
- * syncPoint in order to inform that it's runnning.
- */
-public class ConcurrentOperation01 extends ConcurrentOperation {
-
- /** indicates if this operation has entered the run() method */
- protected boolean isRunning;
-public ConcurrentOperation01(IWorkspace workspace) {
- super(workspace);
- reset();
-}
-protected void assertRequisites() throws Exception {}
-public boolean isRunning() {
- return isRunning;
-}
-public void reset() {
- super.reset();
- isRunning = false;
-}
-public void run(IProgressMonitor monitor) throws CoreException {
- isRunning = true;
- syncPoint();
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/HistoryStorePerformanceTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/HistoryStorePerformanceTest.java
deleted file mode 100644
index c45b798..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/HistoryStorePerformanceTest.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.usecase;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-import junit.framework.*;
-
-public class HistoryStorePerformanceTest extends EclipseWorkspaceTest {
-public HistoryStorePerformanceTest() {
- super();
-}
-public HistoryStorePerformanceTest(String name) {
- super(name);
-}
-public void setUp() throws Exception {
- IProject project = getWorkspace().getRoot().getProject("Project");
- project.create(getMonitor());
- project.open(getMonitor());
- IWorkspaceDescription description = getWorkspace().getDescription();
- description.setFileStateLongevity(1000 * 3600 * 24); // 1 day
- description.setMaxFileStates(10000);
- description.setMaxFileStateSize(1024 * 1024); // 1 Mb
- getWorkspace().setDescription(description);
-}
-public static Test suite() {
- return new TestSuite(HistoryStorePerformanceTest.class);
-}
-protected void tearDown() throws Exception {
- IProject project = getWorkspace().getRoot().getProject("Project");
- project.clearHistory(getMonitor());
- project.delete(true, true, getMonitor());
-}
-public void testPerformance() {
-
- /* Create common objects. */
- IProject project = getWorkspace().getRoot().getProject("Project");
- IFile file = project.getFile("file.txt");
- try {
- file.create(null, true, null);
- } catch (CoreException e) {
- fail("0.0", e);
- }
- String contents = "fixed contents for performance test";
-
- int nTimes = 1000;
- long startTime = System.currentTimeMillis();
- for (int i = 0; i < nTimes; i++) {
- try {
- file.setContents(getContents(contents), true, true, null);
- } catch (CoreException e) {
- fail("1.0", e);
- }
- }
- long endTime = System.currentTimeMillis();
- System.out.println("Adding " + nTimes + " states: " + (endTime - startTime) + " milliseconds.");
-
- startTime = System.currentTimeMillis();
- try {
- file.getHistory(null);
- } catch (CoreException e) {
- fail("2.0", e);
- }
- endTime = System.currentTimeMillis();
- System.out.println("Retrieving " + nTimes + " states: " + (endTime - startTime) + " milliseconds.");
-
- startTime = System.currentTimeMillis();
- try {
- file.clearHistory(null);
- } catch (CoreException e) {
- fail("3.0", e);
- }
- endTime = System.currentTimeMillis();
- System.out.println("Removing " + nTimes + " states: " + (endTime - startTime) + " milliseconds.");
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/IFileTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/IFileTest.java
deleted file mode 100644
index 459bcc0..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/IFileTest.java
+++ /dev/null
@@ -1,211 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.usecase;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-
-/**
- *
- */
-public class IFileTest extends IResourceTest {
-public IFileTest() {
- super(null);
-}
-public IFileTest(String name) {
- super(name);
-}
-/**
- * Tests failure on get/set methods invoked on a nonexistent file.
- * Get methods either throw an exception or return null (abnormally).
- * Set methods throw an exception.
- */
-protected void nonexistentFileFailureTests(IFile file, IFolder parent, IWorkspace wb) {
- String method = "nonexistentFileFailureTests(IFolder,IWorkspace)";
-
- /* Tests for failure in get/set methods in IResource. */
-
- try {
- if (file.isLocal(IResource.DEPTH_ZERO)) {
- fail(method + "1.1");
- }
- } catch (RuntimeException e) {
- }
- try {
- if (file.isLocal(IResource.DEPTH_ONE)) {
- fail(method + "1.2");
- }
- } catch (RuntimeException e) {
- }
- try {
- if (file.isLocal(IResource.DEPTH_INFINITE)) {
- fail(method + "1.3");
- }
- } catch (RuntimeException e) {
- }
- commonFailureTestsForResource(file, false);
-
-}
-public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(new IFileTest("testFile"));
- return suite;
-}
-/**
- * Create a folder in an open project.
- * Contruct a file handle "in" the folder & check its initial state.
- * Create the file & check its state further.
- * Delete the file.
- *
- * TBD:
- *
- * Test file created over already existing file (failure).
- * Test file created "below" another file (ie. fail since its parent should be a directory).
- * Test deleting file that doesn't exist (failure?).
- * Finish testing IResource API
- */
-public void testFile() {
- IProgressMonitor monitor = null;
- IWorkspace workspace = getWorkspace();
-
- // Create & open a project
- IProject proj = workspace.getRoot().getProject(PROJECT);
- try {
- proj.create(monitor);
- } catch (CoreException e) {
- fail("2.1", e);
- }
- try {
- proj.open(monitor);
- } catch (CoreException e) {
- fail("2.2", e);
- }
-
- // Construct a folder handle without creating the folder.
- IFolder folder = proj.getFolder(new Path(FOLDER));
-
- // Construct a file handle
- IFile file = folder.getFile(new Path(FILE));
-
- // Inspection methods with meaninful results invoked on a handle for a nonexistent folder.
- assertTrue("3.1", !file.exists());
- assertTrue("3.2", file.getWorkspace().equals(workspace));
- assertTrue("3.4", file.getProject().equals(proj));
- assertTrue("3.5", file.getParent().equals(folder));
- assertTrue("3.5", file.getType() == IResource.FILE);
- assertTrue("3.6", file.getFullPath().equals(new Path("/" + PROJECT + "/" + FOLDER + "/" + FILE)));
- assertTrue("3.7", file.getName().equals(FILE));
- assertTrue("3.8", proj.getFolder(new Path(FOLDER)).equals(folder));
- assertTrue("3.9", workspace.getRoot().getFile(file.getFullPath()).equals(file));
- IPath projRelativePath = new Path(FOLDER + "/" + FILE);
- assertTrue("3.11", proj.getFile(projRelativePath).equals(file));
- assertTrue("3.12", folder.getFile(new Path(FILE)).equals(file));
- assertTrue("3.13", !workspace.getRoot().exists(file.getFullPath()));
- Path absolutePath = new Path(proj.getLocation().toOSString() + "/" + FOLDER + "/" + FILE);
- assertTrue("3.14", file.getLocation().equals(absolutePath));
- assertTrue("3.15", file.getProjectRelativePath().equals(new Path(FOLDER + "/" + FILE)));
-
- // Create a folder.
- try {
- folder.create(false, true, monitor);
- } catch (CoreException e) {
- fail("4", e);
- }
-
- // Parent folder must exist for this.
- assertTrue("5", workspace.getRoot().findMember(file.getFullPath()) == null);
-
- // These tests produce failure because the file does not exist yet.
- nonexistentFileFailureTests(file, folder, workspace);
-
- // Create the file
- try {
- file.create(getContents("0123456789"), false, monitor);
- } catch (CoreException e) {
- fail("6", e);
- }
-
- // Now tests pass that require that the file exists.
- assertTrue("7.0", file.exists());
- assertTrue("7.1", folder.findMember(file.getName()).exists());
- assertTrue("7.3", workspace.getRoot().findMember(file.getFullPath()).equals(file));
- assertTrue("7.4", workspace.getRoot().exists(file.getFullPath()));
- assertTrue("7.5", file.getLocation().equals(absolutePath));
-
- /* Session Property */
-
- try {
- assertTrue("8.0", file.getSessionProperty(Q_NAME_SESSION) == null);
- } catch (CoreException e) {
- assertTrue("8.1", false);
- }
- try {
- file.setSessionProperty(Q_NAME_SESSION, STRING_VALUE);
- } catch (CoreException e) {
- assertTrue("8.2", false);
- }
- try {
- assertTrue("8.2", file.getSessionProperty(Q_NAME_SESSION).equals(STRING_VALUE));
- } catch (CoreException e) {
- assertTrue("8.3", false);
- }
-
- try {
- file.setSessionProperty(Q_NAME_SESSION, null);
- } catch (CoreException e) {
- assertTrue("8.4", false);
- }
- try {
- assertTrue("8.5", file.getSessionProperty(Q_NAME_SESSION) == null);
- } catch (CoreException e) {
- assertTrue("8.6", false);
- }
-
- // IResource.isLocal(int)
- // There is no server (yet) so everything should be local.
- assertTrue("9.0", file.isLocal(IResource.DEPTH_ZERO));
- // No kids, but it should still answer yes.
- assertTrue("9.1", file.isLocal(IResource.DEPTH_ONE));
- assertTrue("9.2", file.isLocal(IResource.DEPTH_INFINITE));
- // These guys have kids.
- assertTrue("9.3", proj.isLocal(IResource.DEPTH_INFINITE));
- assertTrue("9.5", folder.isLocal(IResource.DEPTH_ONE));
- assertTrue("9.6", folder.isLocal(IResource.DEPTH_INFINITE));
-
- // Delete the file
- try {
- file.delete(false, monitor);
- } catch (CoreException e) {
- fail("10.0", e);
- }
- assertTrue("11.1", !file.exists());
- try {
- assertTrue("11.2", folder.members().length == 0);
- } catch (CoreException e) {
- assertTrue("11.3", false);
- }
- assertTrue("11.4", workspace.getRoot().findMember(file.getFullPath()) == null);
- assertTrue("11.5", !workspace.getRoot().exists(file.getFullPath()));
- assertTrue("11.6", file.getLocation().equals(absolutePath));
-
- // These tests produce failure because the file no longer exists.
- nonexistentFileFailureTests(file, folder, workspace);
-
- /* remove garbage */
- try {
- proj.delete(true, getMonitor());
- } catch (CoreException e) {
- fail("12.0", e);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/IFolderTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/IFolderTest.java
deleted file mode 100644
index ca93743..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/IFolderTest.java
+++ /dev/null
@@ -1,271 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.usecase;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-
-/**
- *
- */
-public class IFolderTest extends IResourceTest {
-public IFolderTest() {
- super(null);
-}
-public IFolderTest(String name) {
- super(name);
-}
-/**
- * Tests failure on get/set methods invoked on a nonexistent folder.
- * Get methods either throw an exception or return null (abnormally).
- * Set methods throw an exception.
- */
-protected void nonexistentFolderFailureTests(IFolder folder, IContainer parent, IWorkspace wb) {
- String method = "nonexistentFolderFailureTests(IFolder,IWorkspace)";
-
- /* Tests for failure in get/set methods in IResource. */
- commonFailureTestsForResource(folder, false);
- assertTrue(method + "4.0", parent.findMember(folder.getName()) == null);
-
- try {
- IResource[] members = parent.members();
- for (int i = 0; i < members.length; i++) {
- assertTrue("4.1: i=" + i, !members[i].getName().equals(folder.getName()));
- }
- } catch (CoreException e) {
- assertTrue(method + "4.2", false);
- }
- assertTrue(method + "5", !wb.getRoot().exists(folder.getFullPath()));
-}
-public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(new IFolderTest("testFolder"));
- return suite;
-}
-/**
- * Create a project in an open solution. Don't open the project.
- * Contruct a folder handle & check its initial state.
- * Try creating the folder in the unopened project.
- * Open the project.
- * Create the folder & check its state further.
- * Construct a nested folder handle & check its initial state.
- * Create the nested folder & check its further.
- * Delete the nested folder.
- * Delete the parent folder.
- * Close the workspace.
- *
- * TBD:
- *
- * Test deleting a folder that doesn't exist.
- * Test that deleting a folder recursively deletes all children.
- * Test deleting a folder the is in a closed project.
- * Test IResource API
- * Test IFolder API
- */
-public void testFolder() {
- IProgressMonitor monitor = null;
- IWorkspace workspace = getWorkspace();
-
- // Construct a project handle.
- IProject proj = workspace.getRoot().getProject(PROJECT);
- // Construct a folder handle
- IPath path = new Path(FOLDER);
-
- // Inspection methods with meaninful results invoked on a handle for a nonexistent folder
- // in a nonexistent project.
- IFolder folder = proj.getFolder(path);
- assertTrue("2.1", !folder.exists());
- assertTrue("2.2", folder.getWorkspace().equals(workspace));
- assertTrue("2.4", folder.getProject().equals(proj));
- assertTrue("2.5", folder.getType() == IResource.FOLDER);
- assertTrue("2.6", folder.getFullPath().equals(new Path("/" + PROJECT + "/" + FOLDER)));
- assertTrue("2.7", folder.getName().equals(FOLDER));
- assertTrue("2.8", workspace.getRoot().getFolder(folder.getFullPath()).equals(folder));
- assertTrue("2.10", proj.getFolder(path).equals(folder));
- assertTrue("2.11", folder.getParent().equals(proj));
- assertTrue("2.13", folder.getProjectRelativePath().equals(new Path(FOLDER)));
-
- // Create a project without opening it.
- try {
- proj.create(monitor);
- } catch (CoreException e) {
- fail("3", e);
- }
-
- // These tests produce failure because the project is not open yet.
- unopenedProjectFailureTests(folder, proj, workspace);
-
- // Open project.
- try {
- proj.open(monitor);
- } catch (CoreException e) {
- fail("4", e);
- }
-
- // These tests produce failure because the folder does not exist yet.
- nonexistentFolderFailureTests(folder, proj, workspace);
- Path absolutePath = new Path(proj.getLocation().toOSString() + "/" + FOLDER);
- assertTrue("5", folder.getLocation().equals(absolutePath));
-
- // Now create folder.
- try {
- folder.create(false, true, monitor);
- } catch (CoreException e) {
- fail("6", e);
- }
-
- // The tests that failed above (becaues the folder must exist) now pass.
- assertTrue("7.0", folder.exists());
- assertTrue("7.1", workspace.getRoot().findMember(folder.getFullPath()).exists());
- assertTrue("7.3", workspace.getRoot().findMember(folder.getFullPath()).equals(folder));
- assertTrue("7.4", workspace.getRoot().exists(folder.getFullPath()));
- assertTrue("7.5", folder.getLocation().equals(absolutePath));
-
- // Session Property
- try {
- assertTrue("8.0", folder.getSessionProperty(Q_NAME_SESSION) == null);
- } catch (CoreException e) {
- fail("8.1");
- }
- try {
- folder.setSessionProperty(Q_NAME_SESSION, STRING_VALUE);
- } catch (CoreException e) {
- fail("8.2");
- }
- try {
- assertTrue("8.3", folder.getSessionProperty(Q_NAME_SESSION).equals(STRING_VALUE));
- } catch (CoreException e) {
- fail("8.4");
- }
- try {
- folder.setSessionProperty(Q_NAME_SESSION, null);
- } catch (CoreException e) {
- fail("8.5");
- }
- try {
- assertTrue("8.6", folder.getSessionProperty(Q_NAME_SESSION) == null);
- } catch (CoreException e) {
- fail("8.7");
- }
-
- // IResource.isLocal(int)
- // There is no server (yet) so everything should be local.
- assertTrue("9.1", folder.isLocal(IResource.DEPTH_ZERO));
- // No kids, but it should still answer yes.
- assertTrue("9.2", folder.isLocal(IResource.DEPTH_ONE));
- assertTrue("9.3", folder.isLocal(IResource.DEPTH_INFINITE));
- // These guys have kids.
- assertTrue("9.4", proj.isLocal(IResource.DEPTH_ONE));
- assertTrue("9.5", proj.isLocal(IResource.DEPTH_INFINITE));
-
- // Construct a nested folder handle.
- IFolder nestedFolder = getWorkspace().getRoot().getFolder(folder.getFullPath().append(FOLDER));
-
- // Inspection methods with meaninful results invoked on a handle for a nonexistent folder.
- assertTrue("10.0", !nestedFolder.exists());
- assertTrue("10.1", nestedFolder.getWorkspace().equals(workspace));
- assertTrue("10.3", nestedFolder.getProject().equals(proj));
- assertTrue("10.4", nestedFolder.getType() == IResource.FOLDER);
- assertTrue("10.5", nestedFolder.getFullPath().equals(new Path("/" + PROJECT + "/" + FOLDER + "/" + FOLDER)));
- assertTrue("10.6", nestedFolder.getName().equals(FOLDER));
- assertTrue("10.7", workspace.getRoot().getFolder(nestedFolder.getFullPath()).equals(nestedFolder));
- IPath projRelativePath = new Path(FOLDER + "/" + FOLDER);
- assertTrue("10.9", proj.getFolder(projRelativePath).equals(nestedFolder));
- assertTrue("10.10", nestedFolder.getParent().equals(folder));
- assertTrue("10.11", nestedFolder.getProjectRelativePath().equals(new Path(FOLDER + "/" + FOLDER)));
- // Now the parent folder has a kid.
- assertTrue("10.12", folder.isLocal(IResource.DEPTH_ONE));
- assertTrue("10.13", folder.isLocal(IResource.DEPTH_INFINITE));
-
- // These tests produce failure because the nested folder does not exist yet.
- nonexistentFolderFailureTests(nestedFolder, folder, workspace);
-
- // Create the nested folder.
- try {
- nestedFolder.create(false, true, monitor);
- } catch (CoreException e) {
- fail("11", e);
- }
-
- // The tests that failed above (becaues the folder must exist) now pass.
- assertTrue("12.0", workspace.getRoot().exists(nestedFolder.getFullPath()));
- assertTrue("12.1", nestedFolder.exists());
- assertTrue("12.2", folder.findMember(nestedFolder.getName()).exists());
- assertTrue("12.4", workspace.getRoot().findMember(nestedFolder.getFullPath()).equals(nestedFolder));
- assertTrue("12.5", workspace.getRoot().exists(nestedFolder.getFullPath()));
- assertTrue("12.6", nestedFolder.getLocation().equals(absolutePath.append(FOLDER)));
-
- // Delete the nested folder
- try {
- nestedFolder.delete(false, monitor);
- } catch (CoreException e) {
- fail("13.0", e);
- }
- assertTrue("13.1", !nestedFolder.exists());
- try {
- assertTrue("13.2", folder.members().length == 0);
- } catch (CoreException e) {
- fail("13.3");
- }
- assertTrue("13.4", workspace.getRoot().findMember(nestedFolder.getFullPath()) == null);
- assertTrue("13.5", !workspace.getRoot().exists(nestedFolder.getFullPath()));
- assertTrue("13.6", nestedFolder.getLocation().equals(absolutePath.append(FOLDER)));
-
- // These tests produce failure because the nested folder no longer exists.
- nonexistentFolderFailureTests(nestedFolder, folder, workspace);
-
- // Parent is still there.
- assertTrue("14.0", folder.exists());
- assertTrue("14.1", workspace.getRoot().findMember(folder.getFullPath()).exists());
- assertTrue("14.3", workspace.getRoot().findMember(folder.getFullPath()).equals(folder));
- assertTrue("14.4", workspace.getRoot().exists(folder.getFullPath()));
- assertTrue("14.5", folder.getLocation().equals(absolutePath));
-
- // Delete the parent folder
- try {
- folder.delete(false, monitor);
- } catch (CoreException e) {
- fail("15.0", e);
- }
- assertTrue("15.1", !folder.exists());
- assertTrue("15.4", workspace.getRoot().findMember(folder.getFullPath()) == null);
- assertTrue("15.5", !workspace.getRoot().exists(folder.getFullPath()));
- assertTrue("15.6", folder.getLocation().equals(absolutePath));
-
- // These tests produce failure because the parent folder no longer exists.
- nonexistentFolderFailureTests(folder, proj, workspace);
-
- try {
- proj.delete(true, true, getMonitor());
- } catch (CoreException e) {
- fail("20.0", e);
- }
-}
-/**
- * Tests failure on get/set methods invoked on a nonexistent folder.
- * Get methods either throw an exception or return null (abnormally).
- * Set methods throw an exception.
- */
-protected void unopenedProjectFailureTests(IFolder folder, IContainer parent, IWorkspace wb) {
- String method = "unopenedProjectFailureTests(IFolder,IWorkspace)";
- IProgressMonitor monitor = null;
-
- /* Try creating a folder in a project which is not yet open. */
- try {
- folder.create(false, true, monitor);
- fail(method + "1");
- } catch (CoreException e) {
- }
- assertTrue(method + "2", !wb.getRoot().exists(folder.getFullPath()));
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/IProjectTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/IProjectTest.java
deleted file mode 100644
index a5191a4..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/IProjectTest.java
+++ /dev/null
@@ -1,271 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.usecase;
-
-
-import java.util.Hashtable;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.resources.Comparator;
-
-public class IProjectTest extends IResourceTest {
- public static String LOCAL_LOCATION_PATH_STRING_0;
-public IProjectTest() {
-}
-public IProjectTest(String name) {
- super(name);
-}
-protected void setUp() throws Exception {
- LOCAL_LOCATION_PATH_STRING_0 = getWorkspace().getRoot().getLocation().append("temp/location0").toOSString();
-}
-/**
- * Tests failure on get/set methods invoked on a nonexistent or unopened project.
- * Get methods either throw an exception or return null (abnormally).
- * Set methods throw an exception.
- */
-protected void commonFailureTests(IProject proj, boolean created) {
- // Prefix to assertion messages.
- String method = "commonFailureTests(IProject," + (created ? "CREATED" : "NONEXISTENT") + "): ";
-
- // Tests for failure in get/set methods in IResource.
- commonFailureTestsForResource(proj, created);
-
- // Description
- try {
- proj.getDescription();
- fail(method + "4.1");
- } catch (CoreException e) {
- }
-}
-/**
- * Tests failure on get/set methods invoked on a nonexistent project.
- * Get methods either throw an exception or return null (abnormally).
- * Set methods throw an exception.
- */
-protected void nonexistentProjectFailureTests(IProject proj) {
- String method = "nonexistentProjectFailureTests(IProject,ISolution,IWorkspace): ";
- commonFailureTests(proj, false);
- IProgressMonitor monitor = null;
-
- IWorkspace wb = getWorkspace();
-
- // Try to open a non-created project.
- try {
- proj.open(monitor);
- fail(method + "0.0");
- } catch (CoreException e) {
- }
- assertTrue(method + "0.1", !proj.isOpen());
-
- // addMapping
- try {
- // Project must exist.
- proj.getDescription().setLocation(new Path(LOCAL_LOCATION_PATH_STRING_0));
- fail(method + "1");
- } catch (Exception e) {
- }
-
- assertTrue(method + "2.1", wb.getRoot().getProjects().length == 0);
-}
-public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(new IProjectTest("testProject"));
- return suite;
-}
-/**
- * Create a solution in an open workspace. Don't open the solution.
- * Contruct a project handle & check its initial state.
- * Try creating the project in the unopened solution.
- * Set/get comment & owner after creating the project but before opening. Is this proper?
- * Open the solution.
- * Create the project & check its state further.
- * Delete the project.
- * Close the workspace.
- *
- * TBD:
- *
- * Test that deletion of open project works.
- * Test that session properties are lost when wb is closed or containing soln is closed or deleted or the
- * receiving project is closed/deleted.
- * Test deleting a project that doesn't exist.
- * Test deleting a project the is in a closed solution.
- * Test that deleting a project recursively deletes all children.
- * Test closing a project that doesn't exist.
- * Test closing a project the is in a closed solution.
- * Test getDataLocation(Plugin)
- * Test ensureLocal(...)
- * Test IResource API
- * Test IFolder API
- */
-public void testProject() {
- IWorkspace wb = getWorkspace();
- IProgressMonitor monitor = null;
-
- // Create a project handle.
- IProject proj = wb.getRoot().getProject(PROJECT);
-
- // Inspection methods with meaninful results invoked on a handle for a nonexistent project
- assertTrue("1.1", !proj.exists());
- assertTrue("1.2", proj.getWorkspace().equals(wb));
- assertTrue("1.4", proj.getType() == IResource.PROJECT);
- assertTrue("1.5", proj.getFullPath().equals(new Path("/" + PROJECT)));
- assertTrue("1.6", proj.getName().equals(PROJECT));
- assertTrue("1.9", !wb.getRoot().exists(proj.getFullPath()));
- assertTrue("1.11", wb.getRoot().findMember(proj.getFullPath()) == null);
- assertTrue("1.12", proj.getParent().equals(wb.getRoot()));
- // Legal question inherited from IResource: returns the receiver.
- assertTrue("1.13", proj.getProject().equals(proj));
- assertTrue("1.14", proj.getProjectRelativePath().equals(new Path("")));
-
- // Check that there are no projects.
- assertTrue("6.1", wb.getRoot().getProjects().length == 0);
-
- // These tests produce failure because the project does not exist yet.
- nonexistentProjectFailureTests(proj);
-
- // Create the project.
- try {
- proj.create(monitor);
- } catch (CoreException e) {
- fail("8");
- }
-
- // Check that the project is get-able from the containers.
- assertTrue("9.0", proj.exists());
- assertTrue("9.1", wb.getRoot().findMember(proj.getName()).exists());
- assertTrue("9.3", wb.getRoot().exists(proj.getFullPath()));
- // But it is still not open.
- assertTrue("9.4", !proj.isOpen());
- assertTrue("9.5", wb.getRoot().findMember(proj.getFullPath()).equals(proj));
-
- // These tests produce failure because the project has not been opened yet.
- unopenedProjectFailureTests(proj);
-
- // Open project
- try {
- proj.open(monitor);
- } catch (CoreException e) {
- fail("11.0", e);
- }
- assertTrue("11.1", proj.isOpen());
- assertTrue("11.2", proj.getLocation() != null);
-
- /* Properties */
-
- // Session Property
- try {
- assertTrue("12.0", proj.getSessionProperty(Q_NAME_SESSION) == null);
- } catch (CoreException e) {
- fail("12.1");
- }
- try {
- proj.setSessionProperty(Q_NAME_SESSION, STRING_VALUE);
- } catch (CoreException e) {
- fail("12.2");
- }
- try {
- assertTrue("12.3", proj.getSessionProperty(Q_NAME_SESSION).equals(STRING_VALUE));
- } catch (CoreException e) {
- fail("12.4");
- }
- try {
- proj.setSessionProperty(Q_NAME_SESSION, null);
- } catch (CoreException e) {
- fail("12.5");
- }
- try {
- assertTrue("12.6", proj.getSessionProperty(Q_NAME_SESSION) == null);
- } catch (CoreException e) {
- fail("12.7");
- }
-
- // Project buildspec
- IProjectDescription desc = null;
- try {
- desc = proj.getDescription();
- } catch(CoreException e){
- fail("14.0");
- }
-
- assertTrue("15.1", desc.getBuildSpec().length == 0);
- ICommand command = desc.newCommand();
- command.setBuilderName("org.eclipse.core.tests.buildername");
- ICommand[] commands = new ICommand[] {command};
- Hashtable arguments = new Hashtable(2);
- arguments.put("param0", "arg0");
- command.setArguments(arguments);
- // Add buildspec to project
- desc.setBuildSpec(commands);
-
- // Compare project buildspecs
- assertTrue("15.5", Comparator.equals(desc.getBuildSpec(), commands));
-
- // IResource.isLocal(int)
- assertTrue("18.0", proj.isLocal(IResource.DEPTH_ZERO));
- assertTrue("18.1", proj.isLocal(IResource.DEPTH_ONE));
- assertTrue("18.2", proj.isLocal(IResource.DEPTH_INFINITE));
-
- // Close project
- try {
- proj.close(monitor);
- } catch (CoreException e) {
- fail("19.0", e);
- }
- // The project is no longer open
- assertTrue("19.1", !proj.isOpen());
- // But it still exists.
- assertTrue("19.2", proj.exists());
- assertTrue("19.5", wb.getRoot().findMember(proj.getFullPath()).equals(proj));
- assertTrue("19.6", wb.getRoot().exists(proj.getFullPath()));
-
- // These tests produce failure because the project is now closed.
- unopenedProjectFailureTests(proj);
-
- // Delete the project
- try {
- proj.delete(false, monitor);
- } catch (CoreException e) {
- fail("20.0", e);
- }
-
- // The project no longer exists.
- assertTrue("20.1", !proj.exists());
- assertTrue("20.2", wb.getRoot().getProjects().length == 0);
- assertTrue("20.4", wb.getRoot().findMember(proj.getFullPath()) == null);
- // These tests produce failure because the project no longer exists.
- nonexistentProjectFailureTests(proj);
- assertTrue("20.5", !wb.getRoot().exists(proj.getFullPath()));
-}
-/**
- * Tests failure on get/set methods invoked on a unopened project.
- * Get methods either throw an exception or return null (abnormally).
- * Set methods throw an exception.
- */
-protected void unopenedProjectFailureTests(IProject proj) {
- commonFailureTests(proj, true);
-}
-protected void unopenedSolutionFailureTests(IProject proj, IWorkspace wb) {
- String method = "unopenedSolutionFailureTests(IProject,IWorkspace): ";
- IProgressMonitor monitor = null;
-
- // Try to create the project without the solution being open.
- try {
- proj.create(monitor);
- fail(method + "1");
- } catch (CoreException e) {
- }
- assertTrue(method + "2", !proj.exists());
- assertTrue(method + "3", !wb.getRoot().exists(proj.getFullPath()));
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/IResourceTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/IResourceTest.java
deleted file mode 100644
index 39b2e55..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/IResourceTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.usecase;
-
-
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.QualifiedName;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-public abstract class IResourceTest extends EclipseWorkspaceTest {
- public static QualifiedName Q_NAME_SESSION = new QualifiedName("prop", "session");
- public static String STRING_VALUE = "value";
- public static String PROJECT = "Project";
- public static String FOLDER = "Folder";
- public static String FILE = "File";
-public IResourceTest() {
-}
-public IResourceTest(String name) {
- super(name);
-}
-/**
- * Tests failure on get/set methods invoked on a nonexistent or unopened solution.
- * Get methods either throw an exception or return null (abnormally).
- * Set methods throw an exception.
- */
-protected void commonFailureTestsForResource(IResource resource, boolean created) {
- /* Prefix to assertion messages. */
- String method = "commonFailureTestsForResource(IResource," + (created ? "CREATED" : "NONEXISTENT") + "): ";
- if (!created) {
- assertTrue(method + "1", getWorkspace().getRoot().findMember(resource.getFullPath()) == null);
- }
-
- /* Session properties */
- try {
- resource.getSessionProperty(Q_NAME_SESSION);
- fail(method + "2.1");
- } catch (CoreException e) {
- }
- try {
- resource.setSessionProperty(Q_NAME_SESSION, STRING_VALUE);
- fail(method + "2.2");
- } catch (CoreException e) {
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/IWorkspaceRunnableUseCaseTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/IWorkspaceRunnableUseCaseTest.java
deleted file mode 100644
index d665484..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/IWorkspaceRunnableUseCaseTest.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.usecase;
-
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
-
-public class IWorkspaceRunnableUseCaseTest extends EclipseWorkspaceTest {
-public IWorkspaceRunnableUseCaseTest() {
-}
-public IWorkspaceRunnableUseCaseTest(String name) {
- super(name);
-}
-protected IWorkspaceRunnable createRunnable(final IProject project, final IWorkspaceRunnable nestedOperation, final boolean triggerBuild, final boolean shouldCancel) {
- return new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- if (shouldCancel)
- throw new OperationCanceledException();
- if (triggerBuild)
- project.touch(getMonitor());
- if (nestedOperation != null)
- getWorkspace().run(nestedOperation, getMonitor());
- }
- };
-}
-public static Test suite() {
- return new TestSuite(IWorkspaceRunnableUseCaseTest.class);
-}
-public void testNestedOperationsAndBuilds() {
- IWorkspaceDescription original = getWorkspace().getDescription();
- IProject project = getWorkspace().getRoot().getProject("MyProject");
- try {
- IWorkspaceDescription description = getWorkspace().getDescription();
- description.setAutoBuilding(true);
- getWorkspace().setDescription(description);
- IProjectDescription prjDescription = getWorkspace().newProjectDescription("MyProject");
- ICommand command = prjDescription.newCommand();
- command.setBuilderName(SignaledBuilder.BUILDER_ID);
- prjDescription.setBuildSpec(new ICommand[] { command });
- project.create(prjDescription, getMonitor());
- project.open(getMonitor());
- } catch (CoreException e) {
- fail("0.0", e);
- }
- SignaledBuilder builder = SignaledBuilder.getInstance(project);
-
- /* should trigger a build */
- IWorkspaceRunnable op1 = createRunnable(project, null, true, false);
- IWorkspaceRunnable op2 = createRunnable(project, op1, false, false);
- IWorkspaceRunnable op3 = createRunnable(project, op2, false, false);
- builder.reset();
- try {
- getWorkspace().run(op3, getMonitor());
- } catch (CoreException e) {
- fail("1.0", e);
- }
- assertTrue("1.1", builder.wasExecuted());
-
- /* should not trigger a build */
- op1 = createRunnable(project, null, true, true);
- op2 = createRunnable(project, op1, true, false);
- op3 = createRunnable(project, op2, true, false);
- builder.reset();
- try {
- getWorkspace().run(op3, getMonitor());
- } catch (CoreException e) {
- fail("2.0", e);
- } catch (OperationCanceledException e) {
- }
- assertTrue("2.1", !builder.wasExecuted());
-
- /* should not trigger a build */
- op1 = createRunnable(project, null, false, false);
- op2 = createRunnable(project, op1, false, false);
- op3 = createRunnable(project, op2, false, false);
- builder.reset();
- try {
- getWorkspace().run(op3, getMonitor());
- } catch (CoreException e) {
- fail("3.0", e);
- } catch (OperationCanceledException e) {
- }
- assertTrue("3.1", !builder.wasExecuted());
-
- /* remove trash */
- try {
- project.delete(true, getMonitor());
- getWorkspace().setDescription(original);
- } catch (CoreException e) {
- fail("20.0", e);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/SignaledBuilder.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/SignaledBuilder.java
deleted file mode 100644
index 537fbce..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/SignaledBuilder.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.usecase;
-
-import java.util.*;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IncrementalProjectBuilder;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-
-public class SignaledBuilder extends IncrementalProjectBuilder {
-
- /** contants */
- public static final String BUILDER_ID = "org.eclipse.core.tests.resources.sigbuilder";
-
- /**
- * associate IProject->SignaledBuilder
- */
- private static HashMap instances = new HashMap(10);
- protected boolean wasExecuted;
- public static SignaledBuilder getInstance(IProject project) {
- return (SignaledBuilder)instances.get(project);
- }
- public SignaledBuilder() {
- reset();
- }
- protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
- instances.put(getProject(), this);
- try {
- monitor.beginTask("Building.", 1);
- wasExecuted = true;
- getProject().touch(null);
- return null;
- } finally {
- monitor.done();
- }
- }
- public void reset() {
- wasExecuted = false;
- }
- public boolean wasExecuted() {
- return wasExecuted;
- }
-}
\ No newline at end of file
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot1Test.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot1Test.java
deleted file mode 100644
index 8173b72..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot1Test.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.usecase;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-
-/**
- * Basically, it is a representation of a user session. The other class,
- * in this case Snapshot2Test, is going to verify if this session ended
- * as expected (failing or not) and may add more "user actions" to be
- * verified in the next session and so on.
- */
-public class Snapshot1Test extends SnapshotTest {
-public Snapshot1Test() {
-}
-public Snapshot1Test(String name) {
- super(name);
-}
-protected static String[] defineHierarchy1() {
- return new String[] {
- "/folder110/",
- "/folder110/folder120/",
- "/folder110/folder120/folder130/",
- "/folder110/folder120/folder130/folder140/",
- "/folder110/folder120/folder130/folder140/folder150/",
- "/folder110/folder120/folder130/folder140/folder150/file160",
- "/folder110/folder120/folder130/folder140/file150",
- "/folder110/folder121/",
- "/folder110/folder121/folder131/",
- "/folder110/folder120/folder130/folder141/"
- };
-}
-protected static String[] defineHierarchy2() {
- return new String[] {
- "/file110",
- "/folder110/",
- "/folder110/file120",
- "/folder111/",
- "/folder111/folder120/",
- "/folder111/file121"
- };
-}
-// copy and paste in the scrapbook to run
-public void testCreateMyProject() {
- IProject project = getWorkspace().getRoot().getProject(PROJECT_1);
- try {
- project.create(null);
- project.open(null);
- } catch (CoreException e) {
- fail("0.0", e);
- }
- assertTrue("0.1", project.exists());
- assertTrue("0.2", project.isOpen());
-
- // create some children
- IResource[] resources = buildResources(project, defineHierarchy1());
- ensureExistsInWorkspace(resources, true);
- assertExistsInFileSystem("1.1", resources);
- assertExistsInWorkspace("1.2", resources);
-
- try {
- project.close(null);
- } catch (CoreException e) {
- fail("2.0", e);
- }
- assertTrue("2.1", project.exists());
- assertTrue("2.2", !project.isOpen());
-}
-/**
- * Create another project and leave it closed for next session.
- */
-public void testCreateProject2() {
- IProject project = getWorkspace().getRoot().getProject(PROJECT_2);
- try {
- project.create(null);
- project.open(null);
- } catch (CoreException e) {
- fail("0.0", e);
- }
- assertTrue("0.1", project.exists());
- assertTrue("0.2", project.isOpen());
-
- // create some children
- IResource[] resources = buildResources(project, defineHierarchy2());
- ensureExistsInWorkspace(resources, true);
- assertExistsInFileSystem("3.1", resources);
- assertExistsInWorkspace("3.2", resources);
-}
-public void testSnapshotWorkspace() {
- try {
- getWorkspace().save(false, null);
- } catch (CoreException e) {
- fail("1.0", e);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot2Test.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot2Test.java
deleted file mode 100644
index 36aa46c..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot2Test.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.usecase;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.Path;
-/**
- * This session add some resources to MyProject. All resources
- * from Project2 are removed and some resources are added to it
- * but not written to disk (only in the tree).
- * Only snapshots are taken. No full saves.
- */
-public class Snapshot2Test extends SnapshotTest {
-public Snapshot2Test() {
-}
-public Snapshot2Test(String name) {
- super(name);
-}
-protected static String[] defineHierarchy1() {
- List result = new ArrayList();
- String[] old = Snapshot1Test.defineHierarchy1();
- for (int i = 0; i < old.length; i++)
- result.add(old[i]);
- result.add(new Path(PROJECT_1).append("added file").toString());
- result.add(new Path(PROJECT_1).append("yet another file").toString());
- result.add(new Path(PROJECT_1).append("a folder").addTrailingSeparator().toString());
- return (String[]) result.toArray(new String[result.size()]);
-}
-protected static String[] defineHierarchy2() {
- return new String[] {
- "/added file",
- "/yet another file",
- "/a folder/"
- };
-}
-public void testChangeMyProject() {
- // MyProject
- IProject project = getWorkspace().getRoot().getProject(PROJECT_1);
- assertTrue("0.1", project.exists());
- assertTrue("0.2", project.isOpen());
-
- // create some children
- IResource[] resources = buildResources(project, defineHierarchy1());
- ensureExistsInWorkspace(resources, true);
- assertExistsInFileSystem("1.1", resources);
- assertExistsInWorkspace("1.2", resources);
-}
-public void testChangeProject2() {
- IProject project = getWorkspace().getRoot().getProject("Project2");
- assertTrue("0.1", project.exists());
- assertTrue("0.2", project.isOpen());
-
- // remove all resources
- try {
- IResource[] children = project.members();
- getWorkspace().delete(children, true, null);
- } catch (CoreException e) {
- fail("0.5", e);
- }
-
- // create some children
- IResource[] resources = buildResources(project, defineHierarchy2());
- ensureExistsInWorkspace(resources, true);
- assertExistsInFileSystem("1.1", resources);
- assertExistsInWorkspace("1.2", resources);
-}
-public void testSnapshotWorkspace() {
- try {
- getWorkspace().save(false, null);
- } catch (CoreException e) {
- fail("1.0", e);
- }
-}
-public void testVerifyPreviousSession() {
- // MyProject
- IProject project = getWorkspace().getRoot().getProject(PROJECT_1);
- assertTrue("0.0", project.exists());
- assertTrue("0.1", !project.isOpen());
-
- try {
- project.open(null);
- } catch (CoreException e) {
- fail("1.0", e);
- }
- assertTrue("1.2", project.isOpen());
-
- // verify existence of children
- IResource[] resources = buildResources(project, Snapshot1Test.defineHierarchy1());
- assertExistsInFileSystem("2.1", resources);
- assertExistsInWorkspace("2.2", resources);
-
- // Project2
- project = getWorkspace().getRoot().getProject(PROJECT_2);
- assertTrue("3.0", project.exists());
- assertTrue("3.1", project.isOpen());
-
- // verify existence of children
- resources = buildResources(project, Snapshot1Test.defineHierarchy2());
- assertExistsInFileSystem("5.1", resources);
- assertExistsInWorkspace("5.2", resources);
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot3Test.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot3Test.java
deleted file mode 100644
index 86ec323..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot3Test.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.usecase;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-/**
- * This session only performs a full save. The workspace should stay
- * the same.
- */
-public class Snapshot3Test extends SnapshotTest {
-public Snapshot3Test() {
-}
-public Snapshot3Test(String name) {
- super(name);
-}
-protected static String[] defineHierarchy1() {
- return Snapshot2Test.defineHierarchy1();
-}
-protected static String[] defineHierarchy2() {
- return Snapshot2Test.defineHierarchy2();
-}
-public void testSaveWorkspace() {
- try {
- getWorkspace().save(true, null);
- } catch (CoreException e) {
- fail("2.0", e);
- }
-}
-public void testVerifyPreviousSession() {
- // MyProject
- IProject project = getWorkspace().getRoot().getProject(PROJECT_1);
- assertTrue("0.0", project.exists());
- assertTrue("0.1", project.isOpen());
-
- // verify existence of children
- IResource[] resources = buildResources(project, Snapshot2Test.defineHierarchy1());
- assertExistsInFileSystem("2.1", resources);
- assertExistsInWorkspace("2.2", resources);
-
- // Project2
- project = getWorkspace().getRoot().getProject(PROJECT_2);
- assertTrue("3.0", project.exists());
- assertTrue("3.1", project.isOpen());
-
- try {
- assertEquals("4.0", 4, project.members().length);
- assertNotNull("4.1", project.findMember(IProjectDescription.DESCRIPTION_FILE_NAME));
- } catch (CoreException e) {
- fail("4.2", e);
- }
-
- // verify existence of children
- resources = buildResources(project, Snapshot2Test.defineHierarchy2());
- assertExistsInFileSystem("5.1", resources);
- assertExistsInWorkspace("5.2", resources);
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot4Test.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot4Test.java
deleted file mode 100644
index cfec7a9..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot4Test.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.usecase;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.Path;
-/**
- * Change some resources mixing full saves and snapshots.
- */
-public class Snapshot4Test extends SnapshotTest {
-public Snapshot4Test() {
-}
-public Snapshot4Test(String name) {
- super(name);
-}
-protected static String[] defineHierarchy1() {
- List result = new ArrayList();
- String[] old = Snapshot3Test.defineHierarchy1();
- for (int i = 0; i < old.length; i++)
- result.add(old[i]);
- result.remove(new Path(PROJECT_1).append("added file").toString());
- result.remove(new Path(PROJECT_1).append("yet another file").toString());
- result.remove(new Path(PROJECT_1).append("a folder").addTrailingSeparator().toString());
- return (String[]) result.toArray(new String[result.size()]);
-}
-protected static String[] defineHierarchy2() {
- return new String[0];
-}
-public void testChangeMyProject() {
- // MyProject
- IProject project = getWorkspace().getRoot().getProject(PROJECT_1);
- assertTrue("0.1", project.exists());
- assertTrue("0.2", project.isOpen());
-
- // remove resources
- IFile file = project.getFile("added file");
- try {
- file.delete(true, true, null);
- } catch (CoreException e) {
- fail("1.0", e);
- }
- assertDoesNotExistInFileSystem("1.1", file);
- assertDoesNotExistInWorkspace("1.2", file);
-
- // full save
- try {
- getWorkspace().save(true, null);
- } catch (CoreException e) {
- fail("2.0", e);
- }
-
- // remove resources
- file = project.getFile("yet another file");
- try {
- file.delete(true, true, null);
- } catch (CoreException e) {
- fail("3.0", e);
- }
- assertDoesNotExistInFileSystem("3.1", file);
- assertDoesNotExistInWorkspace("3.2", file);
-
- // snapshot
- try {
- getWorkspace().save(false, null);
- } catch (CoreException e) {
- fail("4.0", e);
- }
-
- // remove resources
- IFolder folder = project.getFolder("a folder");
- try {
- folder.delete(true, true, null);
- } catch (CoreException e) {
- fail("5.0", e);
- }
- assertDoesNotExistInFileSystem("5.1", folder);
- assertDoesNotExistInWorkspace("5.2", folder);
-
- // snapshot
- try {
- getWorkspace().save(false, null);
- } catch (CoreException e) {
- fail("6.0", e);
- }
-}
-public void testChangeProject2() {
- IProject project = getWorkspace().getRoot().getProject(PROJECT_2);
- assertTrue("0.1", project.exists());
- assertTrue("0.2", project.isOpen());
-
- // remove project
- try {
- project.delete(true, true, null);
- } catch (CoreException e) {
- fail("1.0", e);
- }
- assertTrue("1.1", !project.exists());
-
- // snapshot
- try {
- getWorkspace().save(false, null);
- } catch (CoreException e) {
- fail("4.0", e);
- }
-}
-public void testVerifyPreviousSession() {
- // MyProject
- IProject project = getWorkspace().getRoot().getProject(PROJECT_1);
- assertTrue("0.0", project.exists());
- assertTrue("0.1", project.isOpen());
-
- // verify existence of children
- IResource[] resources = buildResources(project, Snapshot3Test.defineHierarchy1());
- assertExistsInFileSystem("2.1", resources);
- assertExistsInWorkspace("2.2", resources);
-
- // Project2
- project = getWorkspace().getRoot().getProject(PROJECT_2);
- assertTrue("3.0", project.exists());
- assertTrue("3.1", project.isOpen());
-
- try {
- assertEquals("4.0", 4, project.members().length);
- assertNotNull("4.1", project.findMember(IProjectDescription.DESCRIPTION_FILE_NAME));
- } catch (CoreException e) {
- fail("4.2", e);
- }
-
- // verify existence of children
- resources = buildResources(project, Snapshot3Test.defineHierarchy2());
- assertExistsInFileSystem("5.1", resources);
- assertExistsInWorkspace("5.2", resources);
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot5Test.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot5Test.java
deleted file mode 100644
index 52f6e16..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/Snapshot5Test.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.usecase;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-/**
- * Only verifies previous session.
- */
-public class Snapshot5Test extends SnapshotTest {
-public Snapshot5Test() {
-}
-public Snapshot5Test(String name) {
- super(name);
-}
-public void testVerifyPreviousSession() {
- // MyProject
- IProject project = getWorkspace().getRoot().getProject(PROJECT_1);
- assertTrue("0.0", project.exists());
- assertTrue("0.1", project.isOpen());
-
- // verify existence of children
- IResource[] resources = buildResources(project, Snapshot4Test.defineHierarchy1());
- assertExistsInFileSystem("2.1", resources);
- assertExistsInWorkspace("2.2", resources);
- IFile file = project.getFile("added file");
- assertDoesNotExistInFileSystem("2.3", file);
- assertDoesNotExistInWorkspace("2.4", file);
- file = project.getFile("yet another file");
- assertDoesNotExistInFileSystem("2.5", file);
- assertDoesNotExistInWorkspace("2.6", file);
- IFolder folder = project.getFolder("a folder");
- assertDoesNotExistInFileSystem("2.7", folder);
- assertDoesNotExistInWorkspace("2.8", folder);
-
- // Project2
- project = getWorkspace().getRoot().getProject(PROJECT_2);
- assertTrue("3.0", !project.exists());
-}
-public void cleanUp() {
- try {
- ensureDoesNotExistInWorkspace(getWorkspace().getRoot());
- getWorkspace().save(true, null);
- } catch(CoreException e) {
- fail("1.0", e);
- }
-}
-}
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/SnapshotTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/SnapshotTest.java
deleted file mode 100644
index c6567b0..0000000
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/usecase/SnapshotTest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*******************************************************************************
- * 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.tests.resources.usecase;
-
-
-import org.eclipse.core.tests.harness.WorkspaceSessionTest;
-
-/**
- * Runs all the snapshot usecase tests as a single session test.
- * Each test method will run a different snapshot test.
- */
-public class SnapshotTest extends WorkspaceSessionTest {
-
- /** project names */
- static final String PROJECT_1 = "MyProject";
- static final String PROJECT_2 = "Project2";
-
- /** activities */
- static final String COMMENT_1 = "COMMENT ONE";
- static final String COMMENT_2 = "COMMENT TWO";
-public SnapshotTest() {
-}
-public SnapshotTest(String name) {
- super(name);
-}
-public void test1() {
- Snapshot1Test test = new Snapshot1Test();
- test.testCreateMyProject();
- test.testCreateProject2();
- test.testSnapshotWorkspace();
-}
-public void test2() {
- Snapshot2Test test = new Snapshot2Test();
- test.testVerifyPreviousSession();
- test.testChangeMyProject();
- test.testChangeProject2();
- test.testSnapshotWorkspace();
-}
-public void test3() {
- Snapshot3Test test = new Snapshot3Test();
- test.testVerifyPreviousSession();
- test.testSaveWorkspace();
-}
-public void test4() {
- Snapshot4Test test = new Snapshot4Test();
- test.testVerifyPreviousSession();
- test.testChangeMyProject();
- test.testChangeProject2();
-}
-public void test5() {
- Snapshot5Test test = new Snapshot5Test();
- test.testVerifyPreviousSession();
- test.cleanUp();
-}
-}