@Override protected void setUp() throws Exception { projectContainer = TestProjects.newPubProject3(); project = new DeltaProcessorMockProject(projectContainer); projDir = FileUtilities2.createTempDir(projectContainer.getName()); pkg1Dir = FileUtilities2.createTempDir("pkg1").getCanonicalFile(); projectContainer.setLocation(new Path(projDir.getAbsolutePath())); }
/** * Create a symlink from the pubDir/packages/pkg1 directory to the pkg1 directory. * * @param pubDir the pub directory (not {@code null}) * @return {@code true} if symlinks can be created on this platform, else {@code false} */ private boolean symlinkPackage(File pubDir) throws IOException { if (!FileUtilities2.isSymLinkSupported()) { System.out.println("Skipping test in " + getClass().getSimpleName()); return false; } packagesDir = new File(pubDir, "packages"); assertTrue(packagesDir.mkdirs()); FileUtilities2.createSymLink(pkg1Dir, new File(packagesDir, "pkg1")); return true; }
/** Test adding and removing a symlinked package in the "packages" directory */ public void test_traverse_package_added_removed() throws Exception { if (!symlinkPackage(projDir)) { return; } // add package MockDelta delta = new MockDelta(projectContainer); delta.add(PACKAGES_DIRECTORY_NAME).add("pkg1", ADDED); DeltaProcessor processor = new DeltaProcessor(project); ProjectUpdater updater = new ProjectUpdater(); processor.addDeltaListener(updater); processor.traverse(delta); updater.applyChanges(); // Canonical locations File pkg1SomeDir = new File(pkg1Dir, "some_folder"); File[] added = new File[] { new File(pkg1Dir, "build.dart"), new File(pkg1Dir, "bar.dart"), new File(pkg1SomeDir, "build.dart"), new File(pkg1SomeDir, "bar.dart") }; project.assertChanged(projectContainer, added, null, null, null); project.assertNoCalls(); // remove package FileUtilities2.deleteSymLink(new File(packagesDir, "pkg1")); delta = new MockDelta(projectContainer); delta.add(PACKAGES_DIRECTORY_NAME).add("pkg1", REMOVED); processor = new DeltaProcessor(project); updater = new ProjectUpdater(); processor.addDeltaListener(updater); processor.traverse(delta); updater.applyChanges(); project.assertPackagesRemoved(projectContainer); project.assertNoCalls(); }
public void test_toLTK_Change_SourceChange_externalFile() throws Exception { FileBasedSource source = new FileBasedSource(FileUtilities2.createFile("/some/path")); // fill SourceChange SourceChange sourceChange = new SourceChange("My change", source); sourceChange.addEdit(new Edit(10, 1, "a")); sourceChange.addEdit(new Edit(20, 2, "b")); // no IFile for this Source, so no LTK change { org.eclipse.ltk.core.refactoring.Change ltkChange = ServiceUtils.toLTK(sourceChange); assertNull(ltkChange); } // try as part of CompositeChange { CompositeChange compositeChange = new CompositeChange("My composite change", sourceChange); org.eclipse.ltk.core.refactoring.CompositeChange ltkChange = ServiceUtils.toLTK(compositeChange); assertNotNull(ltkChange); // wrong SourceChange was ignored assertThat(ltkChange.getChildren()).isEmpty(); } }
public void test_getInvertedSourceContainer() throws Exception { if (!setupSymlinks()) { return; } File file1 = new File(pkg1CanonicalDir, "file1.dart"); File file2 = new File(pkg2CanonicalDir, "file2.dart"); FileBasedSource source1 = new FileBasedSource(file1); FileBasedSource source2 = new FileBasedSource(file2); PubFolderImpl pubFolder = newTarget(); InvertedSourceContainer container1 = pubFolder.getInvertedSourceContainer(); assertFalse(container1.contains(source1)); assertFalse(container1.contains(source2)); FileUtilities2.deleteSymLink(new File(packagesDir, "pkg2")); InvertedSourceContainer container2 = pubFolder.getInvertedSourceContainer(); assertFalse(container2.contains(source1)); assertTrue(container2.contains(source2)); }
@Override protected void tearDown() throws Exception { FileUtilities2.deleteTempDir(); }