/**
   * Browse through all three resource sets and resolve the physical {@link IResource}s than
   * constitute this logical model.
   *
   * @return The list of all physical resources that constitute this logical model.
   */
  public Set<IResource> resolvePhysicalResources() {
    if (localResourceSet == null) {
      // FIXME throw exception of some kind
    }
    if (iResourcesInScope != null) {
      return iResourcesInScope;
    }

    iResourcesInScope = new LinkedHashSet<IResource>();

    for (Resource eResource : localResourceSet.getResources()) {
      if (eResource == emfResource) {
        iResourcesInScope.add(file);
      } else {
        IResource iResource = EclipseModelUtils.findIResource(eResource);
        if (iResource != null) {
          iResourcesInScope.add(iResource);
        }
      }
    }

    if (remoteResourceSet != null) {
      for (Resource eResource : remoteResourceSet.getResources()) {
        IResource iResource = EclipseModelUtils.findIResource(eResource);
        if (iResource != null) {
          iResourcesInScope.add(iResource);
        }
      }
    }

    if (ancestorResourceSet != null) {
      for (Resource eResource : ancestorResourceSet.getResources()) {
        IResource iResource = EclipseModelUtils.findIResource(eResource);
        if (iResource != null) {
          iResourcesInScope.add(iResource);
        }
      }
    }

    return iResourcesInScope;
  }
Example #2
0
 /**
  * Return the {@link ResourceMapping}s that cover the given {@link IFile}.
  *
  * @param file The file for which to determine mappings.
  * @param monitor A progress monitor, or <code>null</code> if progress reporting is not desired.
  * @return The {@link ResourceMapping}s that cover the given {@link IFile}.
  */
 private ResourceMapping[] getMappings(IFile file, IProgressMonitor monitor) {
   List<ResourceMapping> mappings = new ArrayList<ResourceMapping>();
   // FIXME find a way to dispose of this resource set
   try {
     Resource resource = EclipseModelUtils.getResource(file, createLogicalModelResourceSet());
     if (resource != null) {
       mappings.add(new EMFResourceMapping(file, resource, PROVIDER_ID));
     }
   } catch (IOException e) {
     // return an empty array
   } catch (WrappedException e) {
     // return an empty array
   }
   return mappings.toArray(new ResourceMapping[mappings.size()]);
 }
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.eclipse.core.resources.mapping.ResourceMapping#getTraversals(org.eclipse.core.resources.mapping.ResourceMappingContext,
   *     org.eclipse.core.runtime.IProgressMonitor)
   */
  @Override
  public ResourceTraversal[] getTraversals(ResourceMappingContext context, IProgressMonitor monitor)
      throws CoreException {
    if (!isResolved) {
      resolveLocalResourceSet();

      if (context instanceof RemoteResourceMappingContext) {
        RemoteResourceMappingContext remoteContext = (RemoteResourceMappingContext) context;

        for (Resource eResource : localResourceSet.getResources()) {
          final IFile localFile;
          if (eResource == emfResource) {
            localFile = file;
          } else {
            localFile = (IFile) EclipseModelUtils.findIResource(eResource);
          }

          IStorage remoteContents = remoteContext.fetchRemoteContents(localFile, monitor);
          IStorage ancestorContents = remoteContext.fetchBaseContents(localFile, monitor);

          if (remoteContents != null) {
            if (remoteResourceSet == null) {
              remoteResourceSet = createRemoteResourceSet(localFile, remoteContents);
            } else {
              RevisionedURIConverter converter =
                  (RevisionedURIConverter) remoteResourceSet.getURIConverter();
              converter.setStorage(remoteContents);
            }
            loadRemoteResource(eResource.getURI(), remoteContents, remoteResourceSet);
          }
          if (ancestorContents != null) {
            if (ancestorResourceSet == null) {
              ancestorResourceSet = createRemoteResourceSet(localFile, ancestorContents);
            } else {
              RevisionedURIConverter converter =
                  (RevisionedURIConverter) ancestorResourceSet.getURIConverter();
              converter.setStorage(ancestorContents);
            }
            loadRemoteResource(eResource.getURI(), ancestorContents, ancestorResourceSet);
          }
        }

        // There is a chance that the resource did not exist on the repository
        if (remoteResourceSet != null) {
          EcoreUtil.resolveAll(remoteResourceSet);
        }
        if (ancestorResourceSet != null) {
          EcoreUtil.resolveAll(ancestorResourceSet);
        }
      }

      resolvePhysicalResources();

      isResolved = true;
    }

    /*
     * All of our resource sets are now fully resolved. Browse them to find all IResources than constitute
     * this logical model, whether they exist locally or not.
     */

    ResourceTraversal traversal =
        new ResourceTraversal(
            iResourcesInScope.toArray(new IResource[iResourcesInScope.size()]),
            IResource.DEPTH_ONE,
            IResource.NONE);

    return new ResourceTraversal[] {
      traversal,
    };
  }