Search in sources :

Example 6 with Storage2UriMapperJavaImpl

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

the class Storage2UriMapperJdtImplTest method testBug463258_05.

@Test
public void testBug463258_05() throws Exception {
    IJavaProject project = createJavaProject("foo");
    final Storage2UriMapperJavaImpl impl = getStorage2UriMapper();
    IPackageFragmentRoot root = project.getPackageFragmentRoot("does/not/exist.jar");
    IPackageFragment foo = root.getPackageFragment("foo");
    final JarEntryFile fileInJar = new JarEntryFile("bar.notindexed");
    fileInJar.setParent(foo);
    LoggingTester.captureLogging(Level.ERROR, Storage2UriMapperJavaImpl.class, new Runnable() {

        @Override
        public void run() {
            URI uri = impl.getUri(fileInJar);
            assertNull(uri);
        }
    }).assertNoLogEntries();
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IJavaProject(org.eclipse.jdt.core.IJavaProject) Storage2UriMapperJavaImpl(org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl) 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 7 with Storage2UriMapperJavaImpl

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

the class Storage2UriMapperJdtImplTest method testResourceInExternalFolder.

@Test
public void testResourceInExternalFolder() throws Exception {
    IFolder externalFolder = createExternalFolder("externalFolder");
    IJavaProject project = createJavaProject("foo");
    IFile file = externalFolder.getFile("a.indexed");
    file.create(new StringInputStream("content"), true, monitor());
    IFile file2 = externalFolder.getFile("b.nonindexed");
    file2.create(new StringInputStream("content"), true, monitor());
    IClasspathEntry classpathEntry = addExternalFolderToClasspath(project, externalFolder);
    IPackageFragmentRoot packageFragmentRoot = project.findPackageFragmentRoots(classpathEntry)[0];
    Assert.assertTrue(packageFragmentRoot.getPath().toFile().setLastModified(456L));
    Storage2UriMapperJavaImpl impl = getStorage2UriMapper();
    IPackageFragmentRoot root = project.getPackageFragmentRoot(externalFolder);
    Map<URI, IStorage> rootData = impl.getAllEntries(root);
    assertEquals(rootData.toString(), 1, rootData.size());
    assertEquals("platform:/resource/.org.eclipse.jdt.core.external.folders/externalFolder/a.indexed", rootData.keySet().iterator().next().toString());
    IFile file3 = externalFolder.getFile("c.indexed");
    file3.create(new StringInputStream("content"), true, monitor());
    rootData = impl.getAllEntries(root);
    assertEquals(rootData.toString(), 2, rootData.size());
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) IJavaProject(org.eclipse.jdt.core.IJavaProject) IFile(org.eclipse.core.resources.IFile) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) Storage2UriMapperJavaImpl(org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) IFolder(org.eclipse.core.resources.IFolder) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test)

Example 8 with Storage2UriMapperJavaImpl

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

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

Example 10 with Storage2UriMapperJavaImpl

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

the class Storage2UriMapperJdtImplTest method getStorage2UriMapper.

protected Storage2UriMapperJavaImpl getStorage2UriMapper() {
    Storage2UriMapperJavaImpl impl = new Storage2UriMapperJavaImpl();
    impl.setUriValidator(new UriValidator() {

        @Override
        public boolean isPossiblyManaged(IStorage storage) {
            return "indexed".equals(storage.getFullPath().getFileExtension());
        }

        @Override
        public boolean isValid(URI uri, IStorage storage) {
            return "indexed".equals(storage.getFullPath().getFileExtension());
        }
    });
    impl.setLocator(new JarEntryLocator());
    return impl;
}
Also used : Storage2UriMapperJavaImpl(org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl) JarEntryLocator(org.eclipse.xtext.ui.resource.JarEntryLocator) UriValidator(org.eclipse.xtext.ui.resource.UriValidator) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI)

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