Search in sources :

Example 91 with IStorage

use of org.eclipse.core.resources.IStorage 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 92 with IStorage

use of org.eclipse.core.resources.IStorage 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 93 with IStorage

use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.

the class ResourceAccess method readOnly.

@Override
public <R> R readOnly(URI targetURI, IUnitOfWork<R, ResourceSet> work) {
    URI resourceURI = targetURI.trimFragment();
    Iterable<Pair<IStorage, IProject>> storages = storage2UriMapper.getStorages(resourceURI);
    Iterator<Pair<IStorage, IProject>> iterator = storages.iterator();
    ResourceSet resourceSet = fallBackResourceSet;
    while (iterator.hasNext()) {
        Pair<IStorage, IProject> pair = iterator.next();
        IProject project = pair.getSecond();
        if (project != null) {
            resourceSet = getResourceSet(project);
            break;
        }
    }
    if (resourceSet != null) {
        resourceSet.getResource(resourceURI, true);
        try {
            return work.exec(resourceSet);
        } catch (Exception e) {
            throw new WrappedException(e);
        }
    }
    return null;
}
Also used : WrappedException(org.eclipse.emf.common.util.WrappedException) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) IProject(org.eclipse.core.resources.IProject) WrappedException(org.eclipse.emf.common.util.WrappedException) Pair(org.eclipse.xtext.util.Pair)

Example 94 with IStorage

use of org.eclipse.core.resources.IStorage in project xtext-eclipse by eclipse.

the class DerivedResourceMarkerBasedOpenerContributor method collectGeneratedFileOpeners.

@Override
public boolean collectGeneratedFileOpeners(IEditorPart editor, IAcceptor<FileOpener> acceptor) {
    IStorage storage = getStorage(editor);
    if (storage != null) {
        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        URI uri = URI.createPlatformResourceURI(storage.getFullPath().toString(), true);
        try {
            List<IFile> resources = derivedResourceMarkers.findDerivedResources(root, uri.toString());
            for (IFile file : resources) acceptor.accept(createOpener(file));
            return true;
        } catch (CoreException e) {
            LOG.error(e.getMessage(), e);
        }
    }
    return false;
}
Also used : IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI)

Example 95 with IStorage

use of org.eclipse.core.resources.IStorage in project jbosstools-hibernate by jbosstools.

the class HQLEditorInputFactory method saveState.

public static void saveState(IMemento memento, HQLEditorInput input) {
    // Save the editor input type.
    memento.putString(KEY_EDITOR_INPUT_TYPE, ID_STORAGE_EDITOR_INPUT);
    String storageName = null;
    // $NON-NLS-1$
    String storageContent = "";
    // $NON-NLS-1$
    String configurationName = "";
    IStorage storage = input.getStorage();
    if (storage != null) {
        storageName = storage.getName();
        if (storage instanceof HQLEditorStorage) {
            HQLEditorStorage sqlEditorStorage = (HQLEditorStorage) storage;
            storageContent = sqlEditorStorage.getContentsString();
            configurationName = sqlEditorStorage.getConfigurationName();
        }
    }
    // Save the storage content name in the memento.
    memento.putString(KEY_STORAGE_NAME, storageName);
    // Save the storage content string in the memento.
    memento.putString(KEY_STORAGE_CONTENT, storageContent);
    memento.putString(KEY_CONFIGURATION_NAME, configurationName);
}
Also used : IStorage(org.eclipse.core.resources.IStorage)

Aggregations

IStorage (org.eclipse.core.resources.IStorage)96 URI (org.eclipse.emf.common.util.URI)32 IFile (org.eclipse.core.resources.IFile)31 IProject (org.eclipse.core.resources.IProject)27 CoreException (org.eclipse.core.runtime.CoreException)25 IResource (org.eclipse.core.resources.IResource)20 Pair (org.eclipse.xtext.util.Pair)16 Test (org.junit.Test)15 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)13 IStorageEditorInput (org.eclipse.ui.IStorageEditorInput)12 IPath (org.eclipse.core.runtime.IPath)11 IJavaProject (org.eclipse.jdt.core.IJavaProject)10 IOException (java.io.IOException)7 WrappedException (org.eclipse.emf.common.util.WrappedException)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 GitSynchronizeData (org.eclipse.egit.core.synchronize.dto.GitSynchronizeData)6 GitSynchronizeDataSet (org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet)6 Storage2UriMapperJavaImpl (org.eclipse.xtext.ui.resource.Storage2UriMapperJavaImpl)6