Search in sources :

Example 1 with Storage2UriMapperJavaImpl

use of org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl in project xtext-eclipse by eclipse.

the class Storage2UriMapperJdtImplTest 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.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);
    File jarFile = file.getRawLocation().toFile();
    assertTrue("exists", jarFile.exists());
    assertTrue("delete", jarFile.delete());
    URI uri = impl.getUri(fileInJar);
    assertEquals("archive:platform:/resource/foo/foo.jar!/foo/bar.notindexed", uri.toString());
}
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 2 with Storage2UriMapperJavaImpl

use of org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl in project xtext-eclipse by eclipse.

the class Storage2UriMapperJdtImplTest method testBug463258_04.

@Test
public void testBug463258_04() throws Exception {
    IFolder externalFolder = createExternalFolder("externalFolder");
    IJavaProject project = createJavaProject("foo");
    addExternalFolderToClasspath(project, externalFolder);
    Storage2UriMapperJavaImpl impl = getStorage2UriMapper();
    IPackageFragmentRoot root = project.getPackageFragmentRoot(externalFolder);
    IPackageFragment foo = root.getPackageFragment("foo");
    NonJavaResource fileInFolder = new NonJavaResource(foo, externalFolder.getFile("foo/does.notexist"));
    externalFolder.delete(true, null);
    URI uri = impl.getUri(fileInFolder);
    assertNull(uri);
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IJavaProject(org.eclipse.jdt.core.IJavaProject) Storage2UriMapperJavaImpl(org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl) NonJavaResource(org.eclipse.jdt.internal.core.NonJavaResource) URI(org.eclipse.emf.common.util.URI) IFolder(org.eclipse.core.resources.IFolder) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test)

Example 3 with Storage2UriMapperJavaImpl

use of org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl in project xtext-eclipse by eclipse.

the class Storage2UriMapperJdtImplTest 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);
    Storage2UriMapperJavaImpl impl = getStorage2UriMapper();
    IPackageFragmentRoot root = project.getPackageFragmentRoot(file);
    IPackageFragment foo = root.getPackageFragment("unknown");
    JarEntryFile fileInJar = new JarEntryFile("doesNotExist.notindexed");
    fileInJar.setParent(foo);
    URI uri = impl.getUri(fileInJar);
    assertEquals("archive:platform:/resource/foo/foo.jar!/unknown/doesNotExist.notindexed", uri.toString());
}
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) URI(org.eclipse.emf.common.util.URI) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test)

Example 4 with Storage2UriMapperJavaImpl

use of org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl 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 5 with Storage2UriMapperJavaImpl

use of org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl 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)

Aggregations

URI (org.eclipse.emf.common.util.URI)13 Storage2UriMapperJavaImpl (org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl)13 IJavaProject (org.eclipse.jdt.core.IJavaProject)10 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)10 Test (org.junit.Test)10 IFile (org.eclipse.core.resources.IFile)8 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)7 TextFile (org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile)7 IStorage (org.eclipse.core.resources.IStorage)6 JarEntryFile (org.eclipse.jdt.internal.core.JarEntryFile)6 File (java.io.File)3 JarEntryLocator (org.eclipse.xtext.ui.resource.JarEntryLocator)3 UriValidator (org.eclipse.xtext.ui.resource.UriValidator)3 IFolder (org.eclipse.core.resources.IFolder)2 WorkspaceLockAccess (org.eclipse.xtext.ui.workspace.WorkspaceLockAccess)2 StringInputStream (org.eclipse.xtext.util.StringInputStream)2 InputStream (java.io.InputStream)1 IResource (org.eclipse.core.resources.IResource)1 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)1 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)1