Java Code Examples for org.eclipse.core.resources.IFile#setLocalTimeStamp()

The following examples show how to use org.eclipse.core.resources.IFile#setLocalTimeStamp() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Storage2UriMapperJdtImplTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testResourceInJar() throws Exception {
	IJavaProject project = createJavaProject("foo");
	IFile file = project.getProject().getFile("foo.jar");
	file.create(jarInputStream(new TextFile("foo/bar.indexed", "//empty"), new TextFile("foo/bar.notIndexed", "//empty")), true, monitor());
	// we do cache per timestamp - test is to fast and tries to update the file content in the very same millisecond
	// that's why we fake the timestamp here
	file.setLocalTimeStamp(123L);
	addJarToClasspath(project, file);
	
	Storage2UriMapperJavaImpl impl = getStorage2UriMapper();
	
	IPackageFragmentRoot root = project.getPackageFragmentRoot(file);
	Map<URI, IStorage> rootData = impl.getAllEntries(root);
	assertEquals(1, rootData.size());
	assertEquals("archive:platform:/resource/foo/foo.jar!/foo/bar.indexed", rootData.keySet().iterator().next().toString());
	file.setContents(jarInputStream(new TextFile("foo/bar.notindexed", "//empty"), new TextFile("foo/bar.notIndexed", "//empty")), IResource.FORCE, monitor());
	rootData = impl.getAllEntries(root);
	assertTrue(rootData.isEmpty());
}
 
Example 2
Source File: Bug486584Test.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testFullBuildWhenClasspathChanged_4() throws CoreException, IOException, InterruptedException {
	IJavaProject project = setupProject();
	IFile libraryFile = copyAndGetXtendExampleJar(project);
	IPath rawLocation = libraryFile.getRawLocation();
	libraryFile.setLocalTimeStamp(10L);
	IClasspathEntry libraryEntry = JavaCore.newLibraryEntry(rawLocation, null, null);
	addToClasspath(project, libraryEntry);
	build();
	assertFalse(getEvents().isEmpty());
	getEvents().clear();
	libraryFile.setLocalTimeStamp(System.currentTimeMillis());
	project.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
	// refresh -> full build
	build();
	assertEquals(1, getEvents().size());
}
 
Example 3
Source File: Bug486584Test.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testNoFullBuildWhenClasspathNotReallyChanged_2() throws CoreException, IOException, InterruptedException {
	IJavaProject project = setupProject();
	IFile libraryFile = copyAndGetXtendExampleJar(project);
	IPath rawLocation = libraryFile.getRawLocation();
	libraryFile.setLocalTimeStamp(10L);
	IClasspathEntry libraryEntry = JavaCore.newLibraryEntry(rawLocation, null, null);
	addToClasspath(project, libraryEntry);
	build();
	assertFalse(getEvents().isEmpty());
	getEvents().clear();
	libraryFile.setLocalTimeStamp(System.currentTimeMillis());
	// no refresh -> no full build
	build();
	assertEquals(0, getEvents().size());
}
 
Example 4
Source File: BuilderParticipantPluginTest.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 *
 * 01. Class0 uses Class1 in require statement and in isa function
 * 02. Class2 calls Class0.field0 in variable statement, field0 is defined in Class1
 * 03. Class1.field0 is renamed in Class1.field23
 * 04. Class2 should get error marker at field usage
 * 05. Class1.field23 is renamed in Class1.field0
 * 06. Class2 should have no error markers
 */
//@formatter:on
@Test
public void testMethodRenamedInSuperClassOfClassThatIsUsedToCallTheMethod() throws Exception {
	final IProject project = createJSProject("testMethodInSuperClassRenamed");
	IFolder folder = configureProjectWithXtext(project);
	IFolder module1Folder = createFolder(folder, InheritanceTestFiles.module1());
	IFolder module2Folder = createFolder(folder, InheritanceTestFiles.module2());

	IFile fileA = createTestFile(module1Folder, "A", InheritanceTestFiles.A());
	fileA.setLocalTimeStamp(0L);
	IFile fileB = createTestFile(module2Folder, "B", InheritanceTestFiles.B());
	IFile fileC = createTestFile(module2Folder, "C", InheritanceTestFiles.C());
	IFile fileD = createTestFile(module1Folder, "D", InheritanceTestFiles.D());

	assertMarkers("File A should only have no errors and no warnings", fileA, 0);

	assertMarkers("File B should only have no errors no warnings", fileB, 0);
	assertMarkers("File C should have no markers", fileC, 0);
	assertMarkers("File D should no errors and only no warnings", fileD, 0);

	replaceFileContentAndWaitForRefresh(folder, fileA, InheritanceTestFiles.AOtherMethodName().toString(), 1L);

	assertMarkers("File A with other method name should have no errors and no warnings", fileA, 0);

	// First marker for using old method name
	assertMarkers("File D should have errors as using old method name.", fileD, 1);

	replaceFileContentAndWaitForRefresh(folder, fileA, InheritanceTestFiles.A().toString(), 2L);

	assertMarkers("File A with old method name should have no errors and no warnings", fileA, 0);
	assertMarkers("File D should have no errors and no warnings after changing back to old A", fileD, 0);
}
 
Example 5
Source File: BuilderParticipantPluginTest.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 *
 * 01. B requires A, B calls method of A
 * 02. method of A is renamed but outside the workspace
 * 03. Perform workspace refresh
 * 04. B should get error marker at variable statement
 * 05. method of A is renamed back but outside the workspace
 * 06. Perform workspace refresh
 * 07. B should have no error markers
 *
 */
//@formatter:on
@Test
public void testChangeOutsideWorkspaceAndRefreshInWorkspace() throws Exception {
	final IProject project = createJSProject("testMethodInSuperClassRenamed");
	IFolder folder = configureProjectWithXtext(project);
	IFolder module1Folder = createFolder(folder, InheritanceTestFiles.module1());
	IFolder module2Folder = createFolder(folder, InheritanceTestFiles.module2());

	IFile fileA = createTestFile(module1Folder, "A", InheritanceTestFiles.A());
	fileA.setLocalTimeStamp(0L);
	IFile fileB = createTestFile(module2Folder, "B", InheritanceTestFiles.B());

	assertMarkers("File A should only have no warnings", fileA, 0);
	assertMarkers("File B should only have no warnings", fileB, 0);

	replaceFileContentAndWaitForRefresh(folder, fileA, InheritanceTestFiles.AOtherMethodName().toString(), 1L);
	assertMarkers("File A with other method name should no markers", fileA, 0);

	// Uses the old method name
	assertMarkers("File B should have errors as using old method name", fileB, 1);

	replaceFileContentAndWaitForRefresh(folder, fileA, InheritanceTestFiles.A().toString(), 2L);

	assertMarkers("File A with old method name should only have no warnings", fileA, 0);
	assertMarkers("File B should have no errors after changing back to old A", fileB, 0);
}
 
Example 6
Source File: Storage2UriMapperJdtImplTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testJaredBundle() throws Exception {
	IJavaProject project = createJavaProject("foo");
	IFile file = project.getProject().getFile("foo.jar");
	file.create(jarInputStream(
			new TextFile("foo/bar.indexed", "//empty"), 
			new TextFile("foo/bar.notIndexed", "//empty"),
			new TextFile("META-INF/MANIFEST.MF", "Manifest-Version: 1.0\nBundle-SymbolicName: hubba.bubba\n")
			), true, monitor());
	file.setLocalTimeStamp(678L);
	addJarToClasspath(project, file);
	
	Storage2UriMapperJavaImpl impl = getStorage2UriMapper();
	
	IPackageFragmentRoot root = project.getPackageFragmentRoot(file);
	Map<URI, IStorage> rootData = impl.getAllEntries(root);
	assertEquals(1, rootData.size());
	assertEquals("platform:/resource/hubba.bubba/foo/bar.indexed", rootData.keySet().iterator().next().toString());
	
	// let's change the bundle name
	file.setContents(jarInputStream(
			new TextFile("foo/bar.indexed", "//empty"), 
			new TextFile("foo/bar.notIndexed", "//empty"),
			new TextFile("META-INF/MANIFEST.MF", "Manifest-Version: 1.0\nBundle-SymbolicName: other.bundle.name;singleton:=true\n")
			), IResource.FORCE, monitor());
	rootData = impl.getAllEntries(root);
	assertEquals(1, rootData.size());
	assertEquals("platform:/resource/other.bundle.name/foo/bar.indexed", rootData.keySet().iterator().next().toString());
}
 
Example 7
Source File: SimpleProjectsIntegrationTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testEvents() throws Exception {
	IJavaProject xtextProject = createJavaProject("xtextProject");
	addNature(xtextProject.getProject(), XtextProjectHelper.NATURE_ID);
	IProject projectWithJarFile = createProject("projectWithJar");
	IFile jarFile = projectWithJarFile.getFile("jarFile.jar");
	jarFile.create(JavaProjectSetupUtil.jarInputStream(new TextFile("inJar/Bar"+F_EXT, "object InJar")), true, monitor());
	jarFile.setLocalTimeStamp(100L);
	addJarToClasspath(xtextProject, jarFile);
	projectWithJarFile.delete(true, monitor());
	build();
	assertEmptyIndex();
}
 
Example 8
Source File: IntegrationTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testEvents() throws Exception {
	IJavaProject project = createJavaProject("foo");
	addNature(project.getProject(), XtextProjectHelper.NATURE_ID);
	IProject someProject = createProject("bar");
	IFile file = someProject.getFile("foo.jar");
	file.create(jarInputStream(new TextFile("foo/Bar" + F_EXT, "object Foo")), true, monitor());
	file.setLocalTimeStamp(100L);
	addJarToClasspath(project, file);
	someProject.delete(true, monitor());
	build();
	assertEmptyIndex();
}
 
Example 9
Source File: AbstractFSSynchronizationTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void testDeleteUpdatedDerivedResource(IContainer output) {
	try {
		File outputDirectory = output.getLocation().toFile();
		final int expectedSize;
		if (outputDirectory.exists()) {
			expectedSize = outputDirectory.list().length;
		} else {
			expectedSize = 0;
		}
		IFile sourceFile = createFile(project.getFile(("src/Foo" + F_EXT)).getFullPath(), "object Foo");
		build();
		Assert.assertNotEquals(expectedSize, outputDirectory.list().length);
		IFile file = output.getFile(new Path("Foo.txt"));
		file.setLocalTimeStamp(1L);
		new WorkspaceJob("file.setContent") {
			@Override
			public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
				setContent(file.getLocation().toFile(), "Lalala");
				Assert.assertFalse(isSynchronized(file));
				return Status.OK_STATUS;
			}
		}.run(monitor());
		sourceFile.delete(false, monitor());
		build();
		Assert.assertEquals(expectedSize, outputDirectory.list().length);
	} catch (CoreException e) {
		throw Exceptions.sneakyThrow(e);
	}
}