Пример #1
0
 public void collectRequired(Iterable<SModule> pool) {
   Set<SModuleReference> allRequired =
       SetSequence.fromSetWithValues(
           new HashSet<SModuleReference>(),
           Sequence.fromIterable(MapSequence.fromMap(allDeps).values())
               .translate(
                   new ITranslator2<ModulesCluster.ModuleDeps, SModuleReference>() {
                     public Iterable<SModuleReference> translate(ModulesCluster.ModuleDeps dep) {
                       return dep.required;
                     }
                   }));
   List<SModule> available = Sequence.fromIterable(pool).toListSequence();
   int atSize;
   do {
     atSize = MapSequence.fromMap(allDeps).count();
     for (Iterator<SModule> it = ListSequence.fromList(available).iterator(); it.hasNext(); ) {
       SModule mod = it.next();
       SModuleReference mr = mod.getModuleReference();
       if (SetSequence.fromSet(allRequired).contains(mr)) {
         primAdd(mod);
         SetSequence.fromSet(allRequired)
             .addSequence(ListSequence.fromList(MapSequence.fromMap(allDeps).get(mr).required));
         it.remove();
       }
     }
   } while (atSize < MapSequence.fromMap(allDeps).count());
 }
Пример #2
0
  private static SModule getModuleForModel(MPSProject project, SModel model) {
    // language's and solution's own models (+generator models in language)
    SModule owner = model.getModule();
    SModule mainModule =
        owner instanceof Generator ? ((Generator) owner).getSourceLanguage() : owner;
    if (project.isProjectModule(mainModule)) return owner;

    // accessories models in languages
    /*
      //with this enabled, alt-f1 does not work in case node is in non-owned accessory model to a project language
      for (Language l : project.getProjectLanguages()) {
        if (l.isAccessoryModel(model.getSModelReference())) return l;
      }
    */

    // runtime models in languages
    for (Language l : project.getProjectModules(Language.class)) {
      for (SModuleReference depModule : l.getRuntimeModulesReferences()) {
        if (depModule.equals(mainModule.getModuleReference())) return owner;
      }
    }

    // accessories models in devkits

    // runtime models in devkits

    return owner;
  }
Пример #3
0
 protected void readModules(FileMPSProject.ProjectDescriptor projDesc) {
   myErrors = null;
   //  load solutions
   Set<SModuleReference> existingModules = getModuleReferences();
   for (Path modulePath : projDesc.getModules()) {
     String path = modulePath.getPath();
     IFile descriptorFile = FileSystem.getInstance().getFileByPath(path);
     if (descriptorFile.exists()) {
       ModuleDescriptor descriptor =
           ModulesMiner.getInstance().loadModuleDescriptor(descriptorFile);
       if (descriptor != null) {
         ModulesMiner.ModuleHandle moduleHandle =
             new ModulesMiner.ModuleHandle(descriptorFile, descriptor);
         SModule m = ModuleRepositoryFacade.createModule(moduleHandle, this);
         SModuleReference moduleReference = m.getModuleReference();
         if (!(existingModules.remove(moduleReference))) {
           super.addModule(moduleReference);
         }
       } else {
         error("Can't load module from " + descriptorFile.getPath() + " Unknown file type.");
       }
     } else {
       error("Can't load module from " + descriptorFile.getPath() + " File doesn't exist.");
     }
   }
   for (SModuleReference ref : existingModules) {
     super.removeModule(ref);
   }
 }
Пример #4
0
 private void primAdd(SModule mod) {
   SModuleReference mr = mod.getModuleReference();
   if (!(MapSequence.fromMap(modulesView).containsKey(mr))) {
     MapSequence.fromMap(modulesView).put(mr, mod);
     updateDeps(mod);
   }
 }
Пример #5
0
 /**
  * FIXME Obviously it must be internal module method: it must be done on the fs update (actually
  * it is #update method here) Nobody must recount the module dependency versions from the outside
  * AP
  *
  * <p>Currently happens only during migration;
  *
  * @deprecated please do not use
  */
 @Deprecated
 @ToRemove(version = 3.4)
 public void validateDependencyVersions() {
   assertCanChange();
   ModuleDescriptor md = getModuleDescriptor();
   if (md == null) {
     return;
   }
   Map<SModuleReference, Integer> oldDepVersions = md.getDependencyVersions();
   Map<SModuleReference, Integer> newDepVersions = new HashMap<SModuleReference, Integer>();
   Set<SModule> visible = new LinkedHashSet<SModule>();
   visible.add(this);
   PostingWarningsErrorHandler handler = new PostingWarningsErrorHandler();
   Collection<SModule> dependentModules =
       new GlobalModuleDependenciesManager(this, handler).getModules(Deptype.VISIBLE);
   if (handler.hasErrors()) {
     return;
   }
   visible.addAll(dependentModules);
   if (!md.hasDependencyVersions()) {
     for (SModule dep : visible) {
       newDepVersions.put(dep.getModuleReference(), 0);
     }
     md.setHasDependencyVersions(true);
   } else {
     for (SModule dep : visible) {
       if (oldDepVersions.containsKey(dep.getModuleReference())) {
         newDepVersions.put(
             dep.getModuleReference(), oldDepVersions.get(dep.getModuleReference()));
       } else {
         newDepVersions.put(dep.getModuleReference(), ((AbstractModule) dep).getModuleVersion());
         setChanged();
       }
     }
     if (oldDepVersions.size() != newDepVersions.size()) {
       setChanged();
     }
   }
   oldDepVersions.clear();
   oldDepVersions.putAll(newDepVersions);
 }
Пример #6
0
 @Override
 public Iterable<SModel> loadModels() {
   List<SModel> result = new ArrayList<SModel>();
   Map<String, String> options = new HashMap<String, String>();
   String contentHome = getContentRoot();
   SModule module = getModule();
   if (module != null) {
     options.put(ModelFactory.OPTION_MODULEREF, module.getModuleReference().toString());
   }
   for (String path : getFiles(SOURCE_ROOTS)) {
     String relativePath = contentHome != null ? makeRelative(contentHome, path) : null;
     collectModels(
         FileSystem.getInstance().getFileByPath(path), "", relativePath, options, result);
   }
   return result;
 }
 public void handleAction_impl(
     SModule parameterObject,
     SNode node,
     SModel model,
     IOperationContext operationContext,
     EditorContext editorContext) {
   SPropertyOperations.set(
       node,
       MetaAdapterFactory.getProperty(
           0x7866978ea0f04cc7L,
           0x81bc4d213d9375e1L,
           0x38130dc4e3db5af1L,
           0x38130dc4e3db5af3L,
           "moduleId"),
       parameterObject.getModuleReference().getModuleId().toString());
 }
Пример #8
0
  public synchronized Set<SModelReference> resolveModel(
      SModule module, String name, @Nullable SNodeId nodeId) {
    Pair<SModuleReference, String> key =
        new Pair<SModuleReference, String>(module.getModuleReference(), name);
    ensureInitialized(key);

    Set<SModelReference> models = myStubModulesCache.get(key);
    if (nodeId == null) return new HashSet<SModelReference>(models);

    Set<SModelReference> result = new HashSet<SModelReference>();
    for (SModelReference ref : models) {
      SModel m = SModelRepository.getInstance().getModelDescriptor(ref);
      if (m.getNode(nodeId) != null) {
        result.add(ref);
      }
    }

    return result;
  }
Пример #9
0
 public void updateDeps(SModule mod) {
   SModuleReference mr = mod.getModuleReference();
   ModulesCluster.ModuleDeps deps = MapSequence.fromMap(allDeps).get(mr);
   if (deps == null) {
     deps = new ModulesCluster.ModuleDeps(mr);
     MapSequence.fromMap(allDeps).put(mr, deps);
   }
   ListSequence.fromList(deps.required).addSequence(Sequence.fromIterable(required(mod)));
   for (SModuleReference req : deps.required) {
     if (MapSequence.fromMap(allDeps).containsKey(req)) {
       ListSequence.fromList(MapSequence.fromMap(allDeps).get(req).dependent).addElement(mr);
     }
   }
   for (IMapping<SModuleReference, ModulesCluster.ModuleDeps> m :
       MapSequence.fromMap(allDeps).mappingsSet()) {
     if (ListSequence.fromList(m.value().required).contains(mr)
         && !(ListSequence.fromList(deps.dependent).contains(m.key()))) {
       ListSequence.fromList(deps.dependent).addElement(m.key());
     }
   }
 }
Пример #10
0
 /**
  * has a fallback if the dependency is absent in the module descriptor. if it happens then returns
  * simply the current dep. module version
  *
  * @param check is whether to show error for not found version
  */
 public int getDependencyVersion(@NotNull SModule dependency, boolean check) {
   ModuleDescriptor moduleDescriptor = getModuleDescriptor();
   if (!checkDescriptorNotNull(moduleDescriptor)) {
     return -1;
   }
   Integer res = moduleDescriptor.getDependencyVersions().get(dependency.getModuleReference());
   if (res == null) {
     if (check) {
       LOG.error(
           "#getDependencyVersion can't find a version for module "
               + dependency.getModuleName()
               + " in module "
               + getModuleName()
               + "."
               + " This can either mean that the module is not visible from this module or that "
               + "#validateDependencyVersions() was not called on this module in appropriate moment.",
           new Throwable());
     }
     return ((AbstractModule) dependency).getModuleVersion();
   }
   return res;
 }
Пример #11
0
 /** Build set of dependencies for the given module, grouped under a fake root container */
 public DepLink build(SModule module) {
   DepLink rv = new DepLink(module.getModuleReference(), DependencyUtil.Role.None, null);
   List<DepLink> queue = ListSequence.fromList(new LinkedList<DepLink>());
   ListSequence.fromList(queue).addElement(rv);
   Map<Dependency, DepLink> visited = MapSequence.fromMap(new HashMap<Dependency, DepLink>());
   while (ListSequence.fromList(queue).isNotEmpty()) {
     DepLink e = ListSequence.fromList(queue).removeElementAt(0);
     List<DepLink> dependencies = dependencies(e.role, e.module);
     for (DepLink d : ListSequence.fromList(dependencies)) {
       d.myParent = e;
       ListSequence.fromList(e.children()).addElement(d);
       Dependency key = d.getRoleModuleKey();
       if (MapSequence.fromMap(visited).containsKey(key)) {
         d.setReused(MapSequence.fromMap(visited).get(key));
       } else {
         MapSequence.fromMap(visited).put(key, d);
         ListSequence.fromList(queue).addElement(d);
       }
     }
   }
   return rv;
 }
Пример #12
0
 public static SModuleReference createReference(String moduleName) {
   // TODO use SRepository?
   SModuleReference ref = new ModuleReference(moduleName);
   SModule module = getInstance().getModule(ref);
   return module != null ? module.getModuleReference() : ref;
 }
Пример #13
0
  private List<DepLink> dependencies(DependencyUtil.Role role, SModuleReference moduleRef) {
    List<DepLink> result = ListSequence.fromList(new ArrayList<DepLink>());
    SModule module = moduleRef.resolve(myRepo);
    ModuleDescriptor descr = ((AbstractModule) module).getModuleDescriptor();
    if (descr == null) {
      return result;
    }
    switch (role) {
      case OwnedGenerator:
      case None:
        // first step
        addDeps(
            result,
            descr.getUsedDevkits(),
            DependencyUtil.Role.UsedDevkit,
            DependencyUtil.LinkType.UsesDevkit);
        for (SLanguage lang : module.getUsedLanguages()) {
          SModule langModule = lang.getSourceModule();
          if (langModule != null) {
            ListSequence.fromList(result)
                .addElement(
                    new DepLink(
                        langModule.getModuleReference(),
                        DependencyUtil.Role.UsedLanguage,
                        DependencyUtil.LinkType.UsesLanguage));
          }
        }
        for (SDependency dep : module.getDeclaredDependencies()) {
          switch (dep.getScope()) {
            case EXTENDS:
              SModule t = dep.getTarget();
              if (t instanceof Language) {
                ListSequence.fromList(result)
                    .addElement(
                        new DepLink(
                            dep.getTargetModule(),
                            DependencyUtil.Role.RegularDependency,
                            DependencyUtil.LinkType.ExtendsLanguage));
              } else if (t instanceof Generator) {
                ListSequence.fromList(result)
                    .addElement(
                        new DepLink(
                            dep.getTargetModule(),
                            DependencyUtil.Role.RegularDependency,
                            DependencyUtil.LinkType.ExtendsGenerator));
              } else {
                // just in case module could not be resolved
                ListSequence.fromList(result)
                    .addElement(
                        new DepLink(
                            dep.getTargetModule(),
                            DependencyUtil.Role.RegularDependency,
                            DependencyUtil.LinkType.Depends));
              }
              break;
            case DESIGN:
              ListSequence.fromList(result)
                  .addElement(
                      new DepLink(
                          dep.getTargetModule(),
                          DependencyUtil.Role.RegularDependency,
                          DependencyUtil.LinkType.Depends));
              break;
            case RUNTIME:
              ListSequence.fromList(result)
                  .addElement(
                      new DepLink(
                          dep.getTargetModule(),
                          DependencyUtil.Role.RuntimeDependency,
                          DependencyUtil.LinkType.Depends));
              break;
            default:
              ListSequence.fromList(result)
                  .addElement(
                      new DepLink(
                          dep.getTargetModule(),
                          DependencyUtil.Role.RegularDependency,
                          (dep.isReexport()
                              ? DependencyUtil.LinkType.ReexportsDep
                              : DependencyUtil.LinkType.Depends)));
          }
        }
        if (module instanceof Language) {
          // generators and generators dependencies are now also added to language dependencies
          // (MPS-15883)
          for (Generator g : ((Language) module).getGenerators()) {
            ListSequence.fromList(result)
                .addElement(
                    new DepLink(
                        g.getModuleReference(),
                        DependencyUtil.Role.OwnedGenerator,
                        DependencyUtil.LinkType.Generator));
          }
        }
        if (module instanceof Generator) {
          Language srcLang = ((Generator) module).getSourceLanguage();
          ListSequence.fromList(result)
              .addElement(
                  new DepLink(
                      srcLang.getModuleReference(),
                      DependencyUtil.Role.SourceLanguage,
                      DependencyUtil.LinkType.GeneratorLanguage));
        }
        break;

      case UsedDevkit:
        // explicit use of devkit
      case DependencyDevkit:
        DevkitDescriptor devkit = as_he47wm_a0a0a3e0g(descr, DevkitDescriptor.class);
        if (devkit == null) {
          break;
        }
        boolean direct = role == DependencyUtil.Role.UsedDevkit;
        addDeps(
            result,
            devkit.getExtendedDevkits(),
            (direct ? DependencyUtil.Role.UsedDevkit : DependencyUtil.Role.DependencyDevkit),
            DependencyUtil.LinkType.ExtendsDevkit);
        addDeps(
            result,
            devkit.getExportedLanguages(),
            (direct ? DependencyUtil.Role.UsedLanguage : DependencyUtil.Role.DependencyLanguage),
            DependencyUtil.LinkType.ExportsLanguage);
        addDeps(
            result,
            devkit.getExportedSolutions(),
            (direct
                ? DependencyUtil.Role.RegularDependency
                : DependencyUtil.Role.RuntimeDependency),
            DependencyUtil.LinkType.ExportsSolution);
        break;

      case UsedLanguage:
        LanguageDescriptor lang = as_he47wm_a0a0a4e0g(descr, LanguageDescriptor.class);
        if (lang == null) {
          break;
        }
        addDeps(
            result,
            lang.getExtendedLanguages(),
            DependencyUtil.Role.UsedLanguage,
            DependencyUtil.LinkType.ExtendsLanguage);
        if (myNeedRuntime) {
          addDeps(
              result,
              lang.getRuntimeModules(),
              DependencyUtil.Role.RuntimeDependency,
              DependencyUtil.LinkType.ExportsRuntime);
        }
        break;

      case RegularDependency:
        addDeps(
            result,
            getReexportDeps(descr),
            DependencyUtil.Role.RegularDependency,
            DependencyUtil.LinkType.ReexportsDep);
        if (descr instanceof LanguageDescriptor) {
          addDeps(
              result,
              (as_he47wm_a0a1a0a1a5e0g(descr, LanguageDescriptor.class)).getExtendedLanguages(),
              DependencyUtil.Role.RegularDependency,
              DependencyUtil.LinkType.ExtendsLanguage);
        }
        if (myNeedRuntime) {
          addDeps(
              result,
              getNonreexportDeps(descr),
              DependencyUtil.Role.RuntimeDependency,
              DependencyUtil.LinkType.Depends);
          addDeps(
              result,
              descr.getUsedLanguages(),
              DependencyUtil.Role.DependencyLanguage,
              DependencyUtil.LinkType.UsesLanguage);
          addDeps(
              result,
              descr.getUsedDevkits(),
              DependencyUtil.Role.DependencyDevkit,
              DependencyUtil.LinkType.UsesDevkit);
        }
        break;

      case RuntimeDependency:
        if (myNeedRuntime) {
          addDeps(
              result,
              getReexportDeps(descr),
              DependencyUtil.Role.RuntimeDependency,
              DependencyUtil.LinkType.ReexportsDep);
          addDeps(
              result,
              getNonreexportDeps(descr),
              DependencyUtil.Role.RuntimeDependency,
              DependencyUtil.LinkType.Depends);
          addDeps(
              result,
              descr.getUsedLanguages(),
              DependencyUtil.Role.DependencyLanguage,
              DependencyUtil.LinkType.UsesLanguage);
          addDeps(
              result,
              descr.getUsedDevkits(),
              DependencyUtil.Role.DependencyDevkit,
              DependencyUtil.LinkType.UsesDevkit);
          if (descr instanceof LanguageDescriptor) {
            addDeps(
                result,
                (as_he47wm_a0a1a0a4a0a6e0g(descr, LanguageDescriptor.class)).getExtendedLanguages(),
                DependencyUtil.Role.RuntimeDependency,
                DependencyUtil.LinkType.ExtendsLanguage);
          }
          if (descr instanceof GeneratorDescriptor) {
            GeneratorDescriptor gen = (GeneratorDescriptor) descr;
            // generator languages are now also dependencies
            addDeps(
                result,
                gen.getDepGenerators(),
                DependencyUtil.Role.RuntimeDependency,
                DependencyUtil.LinkType.DependsOnGenerator);
            ListSequence.fromList(result)
                .addElement(
                    new DepLink(
                        (as_he47wm_a0a0a0a0a3a5a0a6e0g(module, Generator.class))
                            .getSourceLanguage()
                            .getModuleReference(),
                        DependencyUtil.Role.RuntimeDependency,
                        DependencyUtil.LinkType.GeneratorLanguage));
          }
        }
        break;

      case SourceLanguage:
        // dependency from generator to its source language
        addDeps(
            result,
            check_he47wm_b0b0h4a6(as_he47wm_a0b0b0h4a6(descr, LanguageDescriptor.class)),
            DependencyUtil.Role.SourceLanguage,
            DependencyUtil.LinkType.ExtendsLanguage);
        addDeps(
            result,
            check_he47wm_b0c0h4a6(as_he47wm_a0b0c0h4a6(descr, LanguageDescriptor.class)),
            DependencyUtil.Role.RuntimeDependency,
            DependencyUtil.LinkType.ExportsRuntime);
        break;

      case DependencyLanguage:
        addDeps(
            result,
            check_he47wm_b0a0i4a6(as_he47wm_a0b0a0i4a6(descr, LanguageDescriptor.class)),
            DependencyUtil.Role.DependencyLanguage,
            DependencyUtil.LinkType.ExtendsLanguage);
        addDeps(
            result,
            check_he47wm_b0b0i4a6(as_he47wm_a0b0b0i4a6(descr, LanguageDescriptor.class)),
            DependencyUtil.Role.RuntimeDependency,
            DependencyUtil.LinkType.ExportsRuntime);
        break;

      default:
    }
    return result;
  }