protected void processDeferredUnloadedResources() { Resource resource = null; for (int i = 0; i < deferredUnloadResources.size(); i++) { resource = (Resource) deferredUnloadResources.get(i); resource.unload(); } }
/** * We need to remove the Resource that corresponds to the <code>file</code> to force a * refresh. */ protected void refreshResource(IFile file) { Resource res = WorkbenchResourceHelperBase.getResource(file); if (res != null) res.unload(); }
protected void processDeferredRemovedResources() { Resource resource = null; for (int i = 0; i < deferredRemoveResources.size(); i++) { resource = (Resource) deferredRemoveResources.get(i); resourceSet.getResources().remove(resource); resource.unload(); } }
@Override public Resource createResource(String uri) { Resource resource = super.createResource(uri); resource.getContents().clear(); resource.unload(); return resource; } }.createResource(uri);
protected void revertAllResources() { List someResources = getSortedResources(); for (int i = 0; i < someResources.size(); i++) ((Resource) someResources.get(i)).unload(); getResources().removeAll(someResources); for (int i = 0; i < someResources.size(); i++) ((Resource) someResources.get(i)).eAdapters().remove(resourceAdapter); }
/** * Remove all of the resources from the resource set and then unload them. Unload forces all of the objects to become proxies so next resolve will * reload the resource. * * @param resources * @param aSet * * @since 1.0.0 */ public static void removeAndUnloadAll(List resources, ResourceSet aSet) { if (aSet == null || resources == null || resources.isEmpty()) return; aSet.getResources().removeAll(resources); Resource res; for (int i = 0; i < resources.size(); i++) { res = (Resource) resources.get(i); res.unload(); } }
protected void unloadNonTargetResources(ResourceSet resourceSet, Set<Resource> targetResources) { for (Resource resource : newArrayList(resourceSet.getResources())) { if (!targetResources.contains(resource)) { resource.unload(); resourceSet.getResources().remove(resource); } } }
protected void removeAndUnloadAllResources() { boolean caughtException = false; if (getResources().isEmpty()) return; List list = new ArrayList(getResources()); getResources().clear(); Resource res; int size = list.size(); for (int i = 0; i < size; i++) { res = (Resource) list.get(i); try { res.unload(); } catch (RuntimeException ex) { Logger.getLogger().logError(ex); caughtException = true; } } if (caughtException) throw new RuntimeException("Exception(s) unloading resources - check log files"); //$NON-NLS-1$ } protected void setIsReleasing(boolean aBoolean) {
protected Resource createResourceForEPackages(final Grammar grammar, final List<EPackage> packs, final ResourceSet rs) { final URI ecoreFileUri = this.getEcoreFileUri(grammar); final Resource existing = rs.getResource(ecoreFileUri, false); if ((existing != null)) { existing.unload(); rs.getResources().remove(existing); } final Resource ecoreFile = rs.createResource(ecoreFileUri, ContentHandler.UNSPECIFIED_CONTENT_TYPE); ecoreFile.getContents().addAll(packs); return ecoreFile; }
/** * Remove aResource from my ResourceSet. Return true if aResource was removed. */ protected boolean removeResourceSetResource(Resource aResource) { aResource.eSetDeliver(false); aResource.unload(); aResource.eSetDeliver(true); return getResourceSet().getResources().remove(aResource); }
@Override protected IStatus run(IProgressMonitor monitor) { final Resource res = handler.createResourceWithApp(appCopy); cleanUpCopy(appCopy, e4Context); try { if (!detectWorkbenchCorruption((MApplication) res.getContents().get(0))) { res.save(null); } } catch (IOException e) { // Just auto-save, we don't really care } finally { res.unload(); res.getResourceSet().getResources().remove(res); } return Status.OK_STATUS; }
/** * Disposes me by unloading my resource, if and only if I created it in * the first place. If I was loaded from an existing resource, then it is * the client's responsibility to manage it. * * @since 1.2 */ public void dispose() { if (shouldDisposeResource && (resource != null)) { if (resource.isLoaded()) { resource.unload(); } if (resource.getResourceSet() != null) { resource.getResourceSet().getResources().remove(resource); } resource = null; } } }
/** * Disposes me by unloading my resource, if and only if I created it in * the first place. If I was loaded from an existing resource, then it is * the client's responsibility to manage it. * * @since 1.2 */ public void dispose() { if (shouldDisposeResource && (resource != null)) { if (resource.isLoaded()) { resource.unload(); } if (resource.getResourceSet() != null) { resource.getResourceSet().getResources().remove(resource); } resource = null; } } }
public static void createDeploymentDescriptor(IProject project, int version) { EnterpriseArtifactEdit earEdit = new EARArtifactEdit(project, false, true); try { earEdit.createModelRoot(version); earEdit.save(null); } finally { // Make sure new resource is removed - the uri used for creation shouldn't be cached Resource newRes = earEdit.getDeploymentDescriptorResource(); WorkbenchResourceHelperBase.getResourceSet(project).getResources().remove(newRes); newRes.unload(); earEdit.dispose(); } }
public static void createDeploymentDescriptor(IProject project, int version) { AppClientArtifactEdit appClientEdit = new AppClientArtifactEdit(project,false,true); try { appClientEdit.createModelRoot(version); appClientEdit.save(null); } finally { // Make sure new resource is removed - the uri used for creation shouldn't be cached Resource newRes = appClientEdit.getDeploymentDescriptorResource(); WorkbenchResourceHelperBase.getResourceSet(project).getResources().remove(newRes); newRes.unload(); appClientEdit.dispose(); } } public IModelProvider create(IProject project) {
public static void createDeploymentDescriptor(IProject project, int version) { EnterpriseArtifactEdit ejbEdit = new EJBArtifactEdit(project, false, true); try { ejbEdit.createModelRoot(version); ejbEdit.save(null); } finally { // Make sure new resource is removed - the uri used for creation shouldn't be cached Resource newRes = ejbEdit.getDeploymentDescriptorResource(); WorkbenchResourceHelperBase.getResourceSet(project).getResources().remove(newRes); newRes.unload(); ejbEdit.dispose(); } } public IModelProvider create(IProject project) {
/** * Checks the copy from a XMI file to another. * * @param uri the URI of the file to copy * @param useCompression {@code true} if the target file must be compressed */ @ParameterizedTest(name = "[{index}] source = {0} ; useCompression = {1}") @ArgumentsSource(UriProvider.AllWithBooleans.class) void testCopy(URI uri, Boolean useCompression) throws IOException { final File targetFile = new File(currentTempFile() + "." + (useCompression ? "z" : Strings.EMPTY) + "xmi"); Log.info("Exporting to {0}", targetFile); try (InputStream in = new URL(uri.toString()).openStream()) { Migrator.fromXmi(in) .toXmi(targetFile, useCompression) .migrate(); } EObject actual = ResourceManager.load(URI.createFileURI(targetFile.toString())); EObject expected = ResourceManager.load(uri); ModelComparisonUtils.assertEObjectAreEqual(actual, expected); actual.eResource().unload(); expected.eResource().unload(); } }
/** * Checks the export from a {@link Backend} to a file. */ @Tag("slow") @ParameterizedTest(name = "[{index}] source = {0}: useCompression = {1}") @ArgumentsSource(UriProvider.UncompressedWithBooleans.class) void testDirectExport(URI uri, Boolean useCompression) throws IOException { final File targetFile = new File(currentTempFile() + "." + (useCompression ? "z" : Strings.EMPTY) + "xmi"); Log.info("Exporting to file... [{0}]", targetFile); try (DataMapper mapper = new DefaultInMemoryBackend(); InputStream in = new URL(uri.toString()).openStream()) { Migrator.fromXmi(in).toMapper(mapper).migrate(); Migrator.fromMapper(mapper) .toXmi(targetFile, useCompression) .migrate(); } // Comparing with EMF EObject actual = ResourceManager.load(URI.createFileURI(targetFile.toString())); EObject expected = ResourceManager.load(uri); ModelComparisonUtils.assertEObjectAreEqual(actual, expected); actual.eResource().unload(); expected.eResource().unload(); } }
/** * Checks the import from a file to a {@link Backend}. */ @Tag("slow") @ParameterizedTest(name = "[{index}] source = {0}") @ArgumentsSource(UriProvider.All.class) void testDirectImport(URI uri) throws IOException { final File sourceFile = currentTempFile(); Log.info("Importing from file... [{0}]", sourceFile); try (Backend backend = new DefaultInMemoryBackend(); InputStream in = new URL(uri.toString()).openStream()) { Migrator.fromXmi(in).toMapper(backend).migrate(); EObject actual = createMockResource(uri, backend).getContents().get(0); EObject expected = ResourceManager.load(uri); // Comparing with EMF ModelComparisonUtils.assertEObjectAreEqual(actual, expected); expected.eResource().unload(); } } }
/** * Checks the export from a {@link Backend} to a file. */ @Tag("slowest") @ParameterizedTest(name = "[{index}] {0}: useCompression = {1}") @ArgumentsSource(ContextProvider.AllWithBooleans.class) void testDirectExport(Context context, Boolean useCompression) throws IOException { final File targetFile = new File(currentTempFile() + "." + (useCompression ? "z" : Strings.EMPTY) + "xmi"); Log.info("Exporting to file... [{0}]", targetFile); URI expectedUri = ResourceManager.xmiWithId(); try (DataMapper mapper = context.createMapper(currentTempFile()); InputStream in = new URL(expectedUri.toString()).openStream()) { Migrator.fromXmi(in).toMapper(mapper).migrate(); Migrator.fromMapper(mapper) .toXmi(targetFile, useCompression) .migrate(); } // Comparing with EMF EObject actual = ResourceManager.load(URI.createFileURI(targetFile.toString())); EObject expected = ResourceManager.load(expectedUri); ModelComparisonUtils.assertEObjectAreEqual(actual, expected); actual.eResource().unload(); expected.eResource().unload(); }