private static void addOrUpdateArtifact(URI uri, boolean update) {
   if (!IndexUtil.INSTANCE.isArtifact(uri)) {
     IndexUtil.INSTANCE.addArtifact(uri);
   } else if (update) {
     IndexUtil.INSTANCE.updateArtifact(uri);
   }
 }
  private void reloadReuseExtensionActivator(Resource resource, ResourceSet resourceSet) {
    if (resource.getContents().isEmpty()) {
      return;
    }
    if (!(resource.getContents().get(0) instanceof ReuseExtension)) {
      return;
    }
    URI rexURI = resource.getURI();
    List<Constraint> constraints =
        FacetUtil.buildConstraints(
            IndexConstants.COLUMN_CM_ACTIVATED_REUSE_EXTENSION,
            ResourceUtil.idString(ResourceUtil.idFrom(rexURI)));
    FacetedRequest request = FacetUtil.buildFacetedRequest(constraints);
    List<IndexRow> response = IndexUtil.INSTANCE.getIndex(request);
    for (IndexRow row : response) {
      URI rexActivatorURI = ResourceUtil.uriFrom(row.getPhyURI());
      if (rexActivatorURI != null) {
        reload(rexActivatorURI, resourceSet);
      }
    }

    constraints =
        FacetUtil.buildConstraints(
            IndexConstants.COLUMN_CL_ACTIVATED_REUSE_EXTENSION,
            ResourceUtil.idString(ResourceUtil.idFrom(rexURI)));
    request = FacetUtil.buildFacetedRequest(constraints);
    response = IndexUtil.INSTANCE.getIndex(request);
    for (IndexRow row : response) {
      URI rexActivatorURI = ResourceUtil.uriFrom(row.getPhyURI());
      if (rexActivatorURI != null) {
        reload(rexActivatorURI, resourceSet);
      }
    }
  }
  private void reloadReuseExtension(Resource resource, ResourceSet resourceSet) {
    if (resource.getContents().isEmpty()) {
      return;
    }
    if (!(resource.getContents().get(0) instanceof FragmentCollaboration)) {
      return;
    }
    URI fracolURI = resource.getURI();
    List<Constraint> constraints =
        FacetUtil.buildConstraints(
            IndexConstants.COLUMN_CM_IMPLEMENTED_FRAGMENT_COLLABORATION,
            ResourceUtil.idString(ResourceUtil.idFrom(fracolURI)));
    FacetedRequest request = FacetUtil.buildFacetedRequest(constraints);
    List<IndexRow> response = IndexUtil.INSTANCE.getIndex(request);
    for (IndexRow row : response) {
      URI rexURI = ResourceUtil.uriFrom(row.getPhyURI());
      if (rexURI != null) {
        reload(rexURI, resourceSet);
      }
    }

    constraints =
        FacetUtil.buildConstraints(
            IndexConstants.COLUMN_CL_IMPLEMENTED_FRAGMENT_COLLABORATION,
            ResourceUtil.idString(ResourceUtil.idFrom(fracolURI)));
    request = FacetUtil.buildFacetedRequest(constraints);
    response = IndexUtil.INSTANCE.getIndex(request);
    for (IndexRow row : response) {
      URI rexURI = ResourceUtil.uriFrom(row.getPhyURI());
      if (rexURI != null) {
        reload(rexURI, resourceSet);
      }
    }
  }
 private static void removeOldArtifacts(List<URI> existingURIs) {
   for (IndexRow row : IndexUtil.INSTANCE.getIndex()) {
     URI rowURI = URI.createURI(row.getPhyURI());
     if (rowURI != null && rowURI.isPlatformPlugin()) {
       if (!existingURIs.contains(rowURI)) {
         IndexUtil.INSTANCE.removeArtifact(rowURI);
       }
     }
   }
 }
示例#5
0
 /**
  * Runs the action.
  *
  * @param action the action proxy that handles the presentation portion of the action
  */
 public void run(IAction action) {
   for (IndexRow row : IndexUtil.INSTANCE.getIndex()) {
     URI uri = ResourceUtil.uriFrom(row.getPhyURI());
     IFile file = ResourceUtil.fileFor(uri);
     if (file == null || !file.exists()) {
       IndexUtil.INSTANCE.removeArtifact(row);
     }
   }
   IndexUtil.INSTANCE.commitIndex();
 }
  private void computeAndCacheCompositionInterface(
      List<String> ufi,
      Resource fragmentResource,
      List<ReuseExtensionActivator> rexActivatorList,
      ResourceSet resourceSet,
      IndexMetaData metaData) {
    Fragment fragment = null;

    // physical or composed?
    List<Constraint> constraints =
        FacetUtil.buildConstraints(
            IndexConstants.COLUMN_COMPOSED_FRAGMENT, ResourceUtil.idString(ufi));
    FacetedRequest request = FacetUtil.buildFacetedRequest(constraints);
    List<IndexRow> response = IndexUtil.INSTANCE.getIndex(request);

    if (response.isEmpty()) {
      fragment = FragmentFactory.eINSTANCE.createPhysicalFragment();
    } else {
      fragment = FragmentFactory.eINSTANCE.createComposedFragment();
    }

    // load
    fragment.getUFI().addAll(ufi);
    fragment.getContents().addAll(fragmentResource.getContents());

    // find reuse extension activators
    for (ReuseExtensionActivator rexActivator : rexActivatorList) {
      if (rexActivator.getReuseExtension() instanceof ComponentModelSpecification) {
        if (influencesFragment(rexActivator, fragment)) {
          fragment.getComponentModelActivators().add(rexActivator);
        }
      }
    }

    // compute composition interface (post processors might need diagrams)
    if (!fragment.getContents().isEmpty()) {
      for (URI fragmentDiagramURI : ReuseResources.INSTANCE.getDiagramURIs(ufi)) {
        Resource fragmentDiagramResource = null;
        try {
          fragmentDiagramResource = resourceSet.getResource(fragmentDiagramURI, true);
        } catch (Exception e) {
          // ok
        }
        if (fragmentDiagramResource != null) {
          fragment.getDiagrams().addAll(fragmentDiagramResource.getContents());
        }
      }
    }
    CompositionInterfaceComputerUtil.compute(fragment);

    // index (cache)
    Resource tempXMIResource = resourceSet.createResource(URI.createURI("temp:/temp.xmi"));
    tempXMIResource.getContents().add(fragment);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try {
      tempXMIResource.save(outputStream, resourceSet.getLoadOptions());
      metaData.putSingle(IndexConstants.COLUMN_FRAGMENT, outputStream.toString("UTF-8"));
    } catch (IOException e) {
      e.printStackTrace();
    }
    resourceSet.getResources().remove(tempXMIResource);

    // are there external computers registered?
    // TODO #1656: test this
    DerivedCompositionProgram derivedCp = CompositionProgramExtractorUtil.extract(fragment);
    if (derivedCp != null && derivedCp.getUCPI() != null && !derivedCp.getUCPI().isEmpty()) {
      URI derivedCpURI =
          SokanReuseResourceUtil.getDerivedCompositionProgramURI(
              derivedCp.getUCPI(), fragment.getUFI(), null);
      Resource resource =
          createResourceForDerivedCompositionProgram(derivedCp, derivedCpURI, resourceSet);
      ReuseResourcesUtil.completeCompositionProgram(resource);
    }
  }