Search in sources :

Example 6 with TextFile

use of org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile in project xtext-eclipse by eclipse.

the class JavaClassPathResourceForIEditorInputFactoryTest method testBug463258_02.

@Test
public void testBug463258_02() throws Exception {
    IJavaProject project = createJavaProject("foo");
    IFile file = project.getProject().getFile("foo.jar");
    file.create(jarInputStream(new TextFile("do/not", "care")), true, monitor());
    addJarToClasspath(project, file);
    IPackageFragmentRoot root = project.getPackageFragmentRoot(file);
    IPackageFragment foo = root.getPackageFragment("unknown");
    JarEntryFile fileInJar = new JarEntryFile("doesNotExist.testlanguage");
    fileInJar.setParent(foo);
    XtextReadonlyEditorInput editorInput = new XtextReadonlyEditorInput(fileInJar);
    Resource resource = factory.createResource(editorInput);
    assertNotNull(resource);
    try {
        resource.load(null);
    } catch (IOException e) {
    // expected
    }
}
Also used : XtextReadonlyEditorInput(org.eclipse.xtext.ui.editor.XtextReadonlyEditorInput) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IJavaProject(org.eclipse.jdt.core.IJavaProject) IFile(org.eclipse.core.resources.IFile) TextFile(org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile) NonJavaResource(org.eclipse.jdt.internal.core.NonJavaResource) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) IOException(java.io.IOException) JarEntryFile(org.eclipse.jdt.internal.core.JarEntryFile) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test) AbstractWorkbenchTest(org.eclipse.xtext.ui.testing.AbstractWorkbenchTest)

Example 7 with TextFile

use of org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile in project xtext-eclipse by eclipse.

the class JavaClassPathResourceForIEditorInputFactoryTest method testBug463258_03a.

@Test
public void testBug463258_03a() throws Exception {
    IJavaProject project = createJavaProject("foo");
    IFile file = project.getProject().getFile("foo.jar");
    file.create(jarInputStream(new TextFile("foo/bar.testlanguage", "//empty")), true, monitor());
    addJarToClasspath(project, file);
    IPackageFragmentRoot root = project.getPackageFragmentRoot(file);
    IPackageFragment foo = root.getPackageFragment("foo");
    JarEntryFile fileInJar = new JarEntryFile("bar.testlanguage");
    fileInJar.setParent(foo);
    File jarFile = file.getRawLocation().toFile();
    assertTrue("exists", jarFile.exists());
    assertTrue("delete", jarFile.delete());
    XtextReadonlyEditorInput editorInput = new XtextReadonlyEditorInput(fileInJar);
    Resource resource = factory.createResource(editorInput);
    assertNotNull(resource);
    try {
        resource.load(null);
    } catch (IOException e) {
    // expected
    }
}
Also used : XtextReadonlyEditorInput(org.eclipse.xtext.ui.editor.XtextReadonlyEditorInput) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IJavaProject(org.eclipse.jdt.core.IJavaProject) IFile(org.eclipse.core.resources.IFile) TextFile(org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile) NonJavaResource(org.eclipse.jdt.internal.core.NonJavaResource) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) IOException(java.io.IOException) JarEntryFile(org.eclipse.jdt.internal.core.JarEntryFile) TextFile(org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile) File(java.io.File) JarEntryFile(org.eclipse.jdt.internal.core.JarEntryFile) IFile(org.eclipse.core.resources.IFile) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test) AbstractWorkbenchTest(org.eclipse.xtext.ui.testing.AbstractWorkbenchTest)

Example 8 with TextFile

use of org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile in project xtext-eclipse by eclipse.

the class JavaClassPathResourceForIEditorInputFactoryTest method testBug463258_03c.

@Test(expected = CoreException.class)
public void testBug463258_03c() throws Throwable {
    IJavaProject project = createJavaProject("foo");
    IFile file = project.getProject().getFile("foo.jar");
    file.create(jarInputStream(new TextFile("foo/bar.testlanguage", "//empty")), true, monitor());
    addJarToClasspath(project, file);
    IPackageFragmentRoot root = JarPackageFragmentRootTestUtil.getJarPackageFragmentRoot(file, (JavaProject) project);
    IPackageFragment foo = root.getPackageFragment("foo");
    JarEntryFile fileInJar = new JarEntryFile("bar.testlanguage");
    fileInJar.setParent(foo);
    File jarFile = file.getLocation().toFile();
    assertTrue("exists", jarFile.exists());
    assertTrue("delete", jarFile.delete());
    // simulate an automated refresh
    file.refreshLocal(IResource.DEPTH_ONE, null);
    XtextReadonlyEditorInput editorInput = new XtextReadonlyEditorInput(fileInJar);
    try {
        factory.createResource(editorInput);
    } catch (WrappedException e) {
        throw e.getCause();
    }
}
Also used : XtextReadonlyEditorInput(org.eclipse.xtext.ui.editor.XtextReadonlyEditorInput) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) WrappedException(org.eclipse.emf.common.util.WrappedException) IJavaProject(org.eclipse.jdt.core.IJavaProject) IFile(org.eclipse.core.resources.IFile) TextFile(org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile) JarEntryFile(org.eclipse.jdt.internal.core.JarEntryFile) TextFile(org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile) File(java.io.File) JarEntryFile(org.eclipse.jdt.internal.core.JarEntryFile) IFile(org.eclipse.core.resources.IFile) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test) AbstractWorkbenchTest(org.eclipse.xtext.ui.testing.AbstractWorkbenchTest)

Example 9 with TextFile

use of org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile in project xtext-eclipse by eclipse.

the class IntegrationTest method testReexportedSource.

@Test
public void testReexportedSource() 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(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(baz, JavaCore.newProjectEntry(bar.getPath(), false));
    IFile bazFile = createFile("baz/src/Baz" + F_EXT, "object Baz references Foo");
    build();
    assertEquals(0, countMarkers(bazFile));
    assertEquals(2, countResourcesInIndex());
    Iterator<IReferenceDescription> references = getContainedReferences(URI.createPlatformResourceURI(bazFile.getFullPath().toString(), true)).iterator();
    IReferenceDescription next = references.next();
    assertFalse(references.hasNext());
    assertEquals("platform:/resource/baz/src/Baz.buildertestlanguage#/", next.getSourceEObjectUri().toString());
    assertEquals("archive:platform:/resource/foo/foo.jar!/foo/Foo.buildertestlanguage#/", next.getTargetEObjectUri().toString());
    assertEquals(-1, next.getIndexInList());
    assertEquals(BuilderTestLanguagePackage.Literals.ELEMENT__REFERENCES, next.getEReference());
}
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) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) Test(org.junit.Test)

Example 10 with TextFile

use of org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile in project xtext-eclipse by eclipse.

the class IntegrationTest method testTwoJars.

@Test
public void testTwoJars() throws Exception {
    IJavaProject project = createJavaProject("foo");
    addNature(project.getProject(), XtextProjectHelper.NATURE_ID);
    IFile file = project.getProject().getFile("foo.jar");
    file.create(jarInputStream(new TextFile("foo/Bar" + F_EXT, "object Foo")), true, monitor());
    IFile file2 = project.getProject().getFile("bar.jar");
    file2.create(jarInputStream(new TextFile("foo/Bar" + F_EXT, "object Foo"), new TextFile("foo/Bar2" + F_EXT, "object Bar references Foo")), true, monitor());
    addJarToClasspath(project, file);
    addJarToClasspath(project, file2);
    assertEquals(3, countResourcesInIndex());
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IFile(org.eclipse.core.resources.IFile) TextFile(org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile) 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