Search in sources :

Example 16 with TextFile

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());
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IFile(org.eclipse.core.resources.IFile) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) TextFile(org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile) Test(org.junit.Test)

Example 17 with TextFile

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());
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IFile(org.eclipse.core.resources.IFile) Storage2UriMapperJavaImpl(org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl) TextFile(org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test)

Example 18 with TextFile

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);
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IJavaProject(org.eclipse.jdt.core.IJavaProject) IFile(org.eclipse.core.resources.IFile) Storage2UriMapperJavaImpl(org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl) TextFile(org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile) JarEntryFile(org.eclipse.jdt.internal.core.JarEntryFile) JarEntryFile(org.eclipse.jdt.internal.core.JarEntryFile) IFile(org.eclipse.core.resources.IFile) TextFile(org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile) File(java.io.File) URI(org.eclipse.emf.common.util.URI) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test)

Example 19 with TextFile

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));
    }
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IJavaProject(org.eclipse.jdt.core.IJavaProject) IFile(org.eclipse.core.resources.IFile) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) Storage2UriMapperJavaImpl(org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl) StringInputStream(org.eclipse.xtext.util.StringInputStream) InputStream(java.io.InputStream) TextFile(org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile) JarEntryFile(org.eclipse.jdt.internal.core.JarEntryFile) URI(org.eclipse.emf.common.util.URI) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test)

Example 20 with TextFile

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());
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IFile(org.eclipse.core.resources.IFile) Storage2UriMapperJavaImpl(org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl) TextFile(org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test)

Aggregations

IFile (org.eclipse.core.resources.IFile)23 IJavaProject (org.eclipse.jdt.core.IJavaProject)23 TextFile (org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile)23 Test (org.junit.Test)23 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)12 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)10 JarEntryFile (org.eclipse.jdt.internal.core.JarEntryFile)10 URI (org.eclipse.emf.common.util.URI)7 Storage2UriMapperJavaImpl (org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl)7 File (java.io.File)6 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)5 XtextReadonlyEditorInput (org.eclipse.xtext.ui.editor.XtextReadonlyEditorInput)5 AbstractWorkbenchTest (org.eclipse.xtext.ui.testing.AbstractWorkbenchTest)5 IProject (org.eclipse.core.resources.IProject)3 IResource (org.eclipse.core.resources.IResource)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 NonJavaResource (org.eclipse.jdt.internal.core.NonJavaResource)3 IReferenceDescription (org.eclipse.xtext.resource.IReferenceDescription)3 IOException (java.io.IOException)2 IStorage (org.eclipse.core.resources.IStorage)2