use of org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile in project xtext-eclipse by eclipse.
the class SimpleProjectsIntegrationTest method testJarOnTwoProjectsRemovedFromOne.
@Test
public void testJarOnTwoProjectsRemovedFromOne() throws Exception {
IJavaProject foo = createJavaProject("foo");
IJavaProject bar = createJavaProject("bar");
IJavaProject baz = createJavaProject("baz");
addNature(foo.getProject(), XtextProjectHelper.NATURE_ID);
addNature(bar.getProject(), XtextProjectHelper.NATURE_ID);
addNature(baz.getProject(), XtextProjectHelper.NATURE_ID);
IFile file = foo.getProject().getFile("foo.jar");
file.create(JavaProjectSetupUtil.jarInputStream(new TextFile("foo/Foo" + F_EXT, "object Foo")), true, monitor());
IClasspathEntry newLibraryEntry = JavaCore.newLibraryEntry(file.getFullPath(), null, null, true);
addToClasspath(foo, newLibraryEntry);
addToClasspath(bar, JavaCore.newProjectEntry(foo.getPath(), true));
addToClasspath(bar, JavaCore.newLibraryEntry(file.getFullPath(), null, null, true));
addToClasspath(baz, JavaCore.newProjectEntry(bar.getPath(), false));
addSourceFolder(baz, "src");
IFile bazFile = createFile("baz/src/Baz" + F_EXT, "object Baz references Foo");
build();
assertEquals(0, countMarkers(bazFile));
assertEquals(2, countResourcesInIndex());
deleteClasspathEntry(foo, newLibraryEntry.getPath());
build();
assertEquals(0, countMarkers(bazFile));
assertEquals(2, countResourcesInIndex());
}
use of org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile in project xtext-eclipse by eclipse.
the class Storage2UriMapperJdtImplTest method testResourceInJar.
@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());
}
use of org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile in project xtext-eclipse by eclipse.
the class Storage2UriMapperJdtImplTest method testBug463258_03b.
@Test
public void testBug463258_03b() throws Exception {
IJavaProject project = createJavaProject("foo");
IFile file = project.getProject().getFile("foo.jar");
file.create(jarInputStream(new TextFile("foo/bar.notindexed", "//empty")), true, monitor());
Storage2UriMapperJavaImpl impl = getStorage2UriMapper();
IPackageFragmentRoot root = JarPackageFragmentRootTestUtil.getJarPackageFragmentRoot(file, (JavaProject) project);
IPackageFragment foo = root.getPackageFragment("foo");
JarEntryFile fileInJar = new JarEntryFile("bar.notindexed");
fileInJar.setParent(foo);
File jarFile = file.getLocation().toFile();
assertTrue("exists", jarFile.exists());
assertTrue("delete", jarFile.delete());
URI uri = impl.getUri(fileInJar);
assertNull(uri);
}
use of org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile in project xtext-eclipse by eclipse.
the class Storage2UriMapperJdtImplTest method testBug463258_01.
@Test
public void testBug463258_01() throws Exception {
IJavaProject project = createJavaProject("foo");
IFile file = project.getProject().getFile("foo.jar");
file.create(jarInputStream(new TextFile("foo/bar.notindexed", "//empty")), true, monitor());
addJarToClasspath(project, file);
Storage2UriMapperJavaImpl impl = getStorage2UriMapper();
IPackageFragmentRoot root = project.getPackageFragmentRoot(file);
IPackageFragment foo = root.getPackageFragment("foo");
JarEntryFile fileInJar = new JarEntryFile("bar.notindexed");
fileInJar.setParent(foo);
URI uri = impl.getUri(fileInJar);
assertEquals("archive:platform:/resource/foo/foo.jar!/foo/bar.notindexed", uri.toString());
try (InputStream stream = new ResourceSetImpl().getURIConverter().createInputStream(uri)) {
byte[] bytes = ByteStreams.toByteArray(stream);
assertEquals("//empty", new String(bytes));
}
}
use of org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile in project xtext-eclipse by eclipse.
the class Storage2UriMapperJdtImplTest method testJaredBundle.
@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());
}
Aggregations