示例#1
0
  /**
   * FIXME module editing is generally done through descriptor and reload. Although I do not mind
   * exposing add/remove methods here, it should be consistent!
   */
  @Nullable
  public Dependency addDependency(@NotNull SModuleReference moduleRef, boolean reexport) {
    assertCanChange();
    ModuleDescriptor descriptor = getModuleDescriptor();
    if (descriptor == null) {
      return null;
    }
    for (Dependency dep : descriptor.getDependencies()) {
      if (!EqualUtil.equals(dep.getModuleRef(), moduleRef)) {
        continue;
      }

      if (reexport && !dep.isReexport()) {
        dep.setReexport(true);
        dependenciesChanged();
        fireChanged();
        setChanged();
      }
      return dep;
    }

    Dependency dep = new Dependency();
    dep.setModuleRef(moduleRef);
    dep.setReexport(reexport);
    descriptor.getDependencies().add(dep);

    dependenciesChanged();
    fireChanged();
    setChanged();
    return dep;
  }
示例#2
0
  protected Iterable<ModelRoot> loadRoots() {
    ModuleDescriptor descriptor = getModuleDescriptor();
    if (descriptor == null) {
      return Collections.emptyList();
    }

    List<ModelRoot> result = new ArrayList<ModelRoot>();
    for (ModelRootDescriptor modelRoot : descriptor.getModelRootDescriptors()) {
      try {
        ModelRootFactory modelRootFactory =
            PersistenceFacade.getInstance().getModelRootFactory(modelRoot.getType());
        if (modelRootFactory == null) {
          LOG.error(
              "Unknown model root type: `" + modelRoot.getType() + "'. Requested by: " + this);
          continue;
        }

        ModelRoot root = modelRootFactory.create();
        Memento mementoWithFS = new MementoWithFS(modelRoot.getMemento(), myFileSystem);
        root.load(mementoWithFS);
        result.add(root);
      } catch (Exception e) {
        LOG.error(
            "Error loading models from root with type: `"
                + modelRoot.getType()
                + "'. Requested by: "
                + this,
            e);
      }
    }
    return result;
  }
示例#3
0
 public ModuleDescriptor loadModuleDescriptor(IFile file) {
   try {
     String filePath = file.getPath();
     if (filePath.endsWith(SLASH_META_INF_MODULE_XML)) {
       DeploymentDescriptor deploymentDescriptor =
           DeploymentDescriptorPersistence.loadDeploymentDescriptor(file);
       ModuleDescriptor result = null;
       IFile realDescriptorFile = getRealDescriptorFile(filePath, deploymentDescriptor);
       if (realDescriptorFile != null) {
         result = loadModuleDescriptor(realDescriptorFile);
       }
       // TODO create module without sources
       if (result != null) {
         result.setDeploymentDescriptor(deploymentDescriptor);
         // TODO fix stubs
       }
       return result;
     } else {
       return DescriptorIOFacade.getInstance().fromFileType(file).readFromFile(file);
     }
   } catch (Exception t) {
     LOG.error("Fail to load module from descriptor " + file.getPath(), t);
     return null;
   }
 }
示例#4
0
  @Override
  public Iterable<SDependency> getDeclaredDependencies() {
    assertCanRead();
    ModuleDescriptor descriptor = getModuleDescriptor();
    if (descriptor == null) {
      return Collections.emptyList();
    }
    HashSet<SDependency> result = new HashSet<SDependency>();
    final SRepository repo = getRepository();
    if (repo == null) {
      throw new IllegalStateException(
          "It is not possible to resolve all declared dependencies with a null repository : module "
              + this);
    }

    // add declared dependencies
    for (Dependency d : descriptor.getDependencies()) {
      result.add(new SDependencyImpl(d.getModuleRef(), repo, d.getScope(), d.isReexport()));
    }

    // add dependencies provided by devkits as nonreexport dependencies
    for (SModuleReference usedDevkit : descriptor.getUsedDevkits()) {
      final SModule devkit = usedDevkit.resolve(repo);
      if (DevKit.class.isInstance(devkit)) {
        for (Solution solution : ((DevKit) devkit).getAllExportedSolutions()) {
          result.add(
              new SDependencyImpl(
                  solution.getModuleReference(), repo, SDependencyScope.DEFAULT, false));
        }
      }
    }
    return result;
  }
示例#5
0
 /**
  * @deprecated shall be removed once tests in MPS plugin got fixed
  *     (FacetTests.testAddRemoveUsedLanguage(), testFacetInitialized()
  */
 @Deprecated
 @ToRemove(version = 3.4)
 public final Collection<SModuleReference> getUsedLanguagesReferences() {
   assertCanRead();
   ModuleDescriptor descriptor = getModuleDescriptor();
   if (descriptor == null) {
     return Collections.emptySet();
   }
   return Collections.unmodifiableCollection(descriptor.getUsedLanguages());
 }
示例#6
0
  private void processExcludes(
      @NotNull IFile descriptorFile, ModuleDescriptor descriptor, Set<IFile> excludes) {
    if (descriptor == null || descriptorFile.isReadOnly()) {
      return;
    }

    for (String p : descriptor.getSourcePaths()) {
      excludes.add(FileSystem.getInstance().getFileByPath(p));
    }

    IFile genPath = ProjectPathUtil.getGeneratorOutputPath(descriptorFile.getParent(), descriptor);
    if (genPath != null) {
      excludes.add(genPath);
      if (!descriptorFile.isReadOnly()) {
        FileSystem.getInstance().getFileByPath(FileGenerationUtil.getCachesPath(genPath.getPath()));
      }
    }

    IFile testsGenPath = ProjectPathUtil.getGeneratorTestsOutputPath(descriptorFile, descriptor);
    if (testsGenPath != null) {
      excludes.add(testsGenPath);
      if (!descriptorFile.isReadOnly()) {
        FileSystem.getInstance()
            .getFileByPath(FileGenerationUtil.getCachesPath(testsGenPath.getPath()));
      }
    }

    for (ModelRootDescriptor rootDescriptor : descriptor.getModelRootDescriptors()) {
      ModelRoot root = rootDescriptor.getRoot();
      if (root == null
          || root.getManager() != null && root.getManager() != LanguageID.JAVA_MANAGER) {
        continue;
      }

      excludes.add(FileSystem.getInstance().getFileByPath(root.getPath()));
    }

    IFile classesGen = ProjectPathUtil.getClassesGenFolder(descriptorFile.getParent(), false);
    if (classesGen != null) {
      excludes.add(classesGen);
    }

    // todo: specify what kind of descriptor can be input for this method
    if (descriptor instanceof LanguageDescriptor) {
      IFile generatorClassesGen =
          ProjectPathUtil.getClassesGenFolder(descriptorFile.getParent(), true);
      if (generatorClassesGen != null) {
        excludes.add(generatorClassesGen);
      }
    }

    for (String entry : descriptor.getAdditionalJavaStubPaths()) {
      excludes.add(FileSystem.getInstance().getFileByPath(entry));
    }
  }
示例#7
0
  /**
   * AP the contract is not clear: when should this method be called? it seems to be our internal
   * mechanism which is exposed to the client it must be done on the fs update (actually it is
   * #update method here) Nobody must recount the module dependency versions from the outside
   *
   * <p>Currently happens only during migration;
   *
   * @deprecated please do not use
   */
  @Deprecated
  @ToRemove(version = 3.4)
  public void validateLanguageVersions() {
    assertCanChange();
    ModuleDescriptor md = getModuleDescriptor();
    if (md == null) {
      return;
    }
    Map<SLanguage, Integer> oldLanguageVersions = md.getLanguageVersions();
    Map<SLanguage, Integer> newLanguageVersions = new HashMap<SLanguage, Integer>();

    LangAndDevkits langAndDevkits = collectLanguagesAndDevkits();
    Set<SLanguage> usedLanguages = langAndDevkits.languages;
    Set<SModuleReference> devkits = langAndDevkits.devkits;
    SLanguageHierarchy languageHierarchy = new SLanguageHierarchy(usedLanguages);
    Reference<Boolean> hasErrors = new Reference<>(false);
    Set<SLanguage> extendingLangsClosure =
        languageHierarchy.getExtendedLangs(language -> hasErrors.set(true));
    if (hasErrors.get()) {
      return;
    }
    if (!md.hasLanguageVersions()) {
      for (SLanguage lang : extendingLangsClosure) {
        newLanguageVersions.put(lang, 0);
      }
      md.getUsedDevkits().addAll(devkits);
      md.setHasLanguageVersions(true);
    } else {
      for (SLanguage lang : extendingLangsClosure) {
        if (oldLanguageVersions.containsKey(lang)) {
          newLanguageVersions.put(lang, oldLanguageVersions.get(lang));
        } else {
          checkModelVersionsAreValid(lang);
          newLanguageVersions.put(lang, lang.getLanguageVersion());
          // this check is needed to avoid numerous changes in msd/mpl files when opening project
          // without dependency versions
          // here we assume that validateLanguageVersions() is called before
          // validateDependencyVersions()
          // todo: remove this hack after 3.4
          if (md.hasDependencyVersions()) {
            setChanged();
          }
        }
      }
      if (!md.getUsedDevkits().containsAll(devkits)) {
        // intentionally no clean(), augmentation only, just in case there's anything vital already.
        md.getUsedDevkits().addAll(devkits);
        setChanged();
      }
      if (!oldLanguageVersions.equals(newLanguageVersions)) {
        // todo: remove this hack after 3.4
        if (md.hasDependencyVersions()) {
          setChanged();
        }
      }
    }
    oldLanguageVersions.clear();
    oldLanguageVersions.putAll(newLanguageVersions);
  }
示例#8
0
 // unlike similar method in SModel, doesn't take SRepository now
 // according to present use cases, we iterate modules of a repository and update them,
 // hence it's superficial  to pass repository in here (although might add one for consistency)
 public void updateExternalReferences() {
   ModuleDescriptor moduleDescriptor = getModuleDescriptor();
   final SRepository repository = getRepository();
   if (moduleDescriptor == null || repository == null) {
     return;
   }
   if (moduleDescriptor.updateModelRefs(repository)) {
     setChanged();
   }
   if (moduleDescriptor.updateModuleRefs(repository)) {
     setChanged();
   }
 }
示例#9
0
  public void removeDependency(@NotNull Dependency dependency) {
    assertCanChange();
    ModuleDescriptor descriptor = getModuleDescriptor();
    if (descriptor == null) {
      return;
    }
    if (!descriptor.getDependencies().contains(dependency)) {
      return;
    }

    descriptor.getDependencies().remove(dependency);

    dependenciesChanged();
    fireChanged();
    setChanged();
  }
示例#10
0
  @Override
  public List<String> getErrors() {
    List<String> errors = new ArrayList<String>();
    Throwable loadException = myModule.getModuleDescriptor().getLoadException();
    if (loadException != null) {
      errors.add("Couldn't load module: " + loadException.getMessage());
      return errors;
    }

    ModuleDescriptor descriptor = myModule.getModuleDescriptor();
    // null?

    for (Dependency dep : descriptor.getDependencies()) {
      SModuleReference moduleRef = dep.getModuleRef();
      if (MPSModuleRepository.getInstance().getModule(moduleRef) == null) {
        errors.add("Can't find dependency: " + moduleRef.getModuleName());
      }
    }
    for (SModuleReference reference : descriptor.getUsedLanguages()) {
      if (ModuleRepositoryFacade.getInstance().getModule(reference, Language.class) == null) {
        errors.add("Can't find used language: " + reference.getModuleName());
      }
    }
    for (SModuleReference reference : descriptor.getUsedDevkits()) {
      if (MPSModuleRepository.getInstance().getModule(reference) == null) {
        errors.add("Can't find used devkit: " + reference.getModuleName());
      }
    }

    if (descriptor.getSourcePaths() != null && !myModule.isPackaged()) {
      for (String sourcePath : descriptor.getSourcePaths()) {
        IFile file = FileSystem.getInstance().getFileByPath(sourcePath);
        if (file == null || !file.exists()) {
          errors.add("Can't find source path: " + sourcePath);
        }
      }
    }
    if (descriptor.getAdditionalJavaStubPaths() != null) {
      for (String path : descriptor.getAdditionalJavaStubPaths()) {
        IFile file = FileSystem.getInstance().getFileByPath(path);
        if (file == null || !file.exists()) {
          if (new File(path).exists()) {
            errors.add("Idea VFS is not up-to-date. Can't find library: " + path);
          } else {
            errors.add("Can't find library: " + path);
          }
        }
      }
    }

    // todo: =(
    if (!(myModule instanceof Generator)) {
      errors.addAll(validateDependenciesOnGenerators());
    }

    return errors;
  }
示例#11
0
 public ModuleHandle loadHandle(ModelInputStream stream) throws IOException {
   if (stream.readShort() != 0x1be0) throw new IOException("bad stream: no start marker");
   String file = stream.readString();
   ModuleDescriptor descriptor;
   int type = stream.readByte();
   if (type == 1) {
     descriptor = new LanguageDescriptor();
   } else if (type == 2) {
     descriptor = new SolutionDescriptor();
   } else if (type == 3) {
     descriptor = new DevkitDescriptor();
   } else {
     throw new IOException("broken stream: invalid descriptor type");
   }
   descriptor.load(stream);
   return new ModuleHandle(FileSystem.getInstance().getFileByPath(file), descriptor);
 }
示例#12
0
文件: TempModule.java 项目: sprig/MPS
 public TempModule(Set<ModelRootDescriptor> modelRoots) {
   SModuleId id = ModuleId.regular();
   SModuleReference reference = new ModuleReference("TempModule" + id, id);
   setModuleReference(reference);
   myDescriptor = new ModuleDescriptor();
   myDescriptor.getModelRootDescriptors().addAll(modelRoots);
   setModuleDescriptor(myDescriptor, false);
 }
示例#13
0
 public String addClassPathItem(String path) {
   if (SetSequence.fromSet(myClassPaths).contains(path)) {
     path = null;
   } else {
     SetSequence.fromSet(myClassPaths).addElement(path);
     myDescriptor.getAdditionalJavaStubPaths().add(path);
   }
   fireChanged();
   return path;
 }
示例#14
0
  protected void updateFacets() {
    assertCanChange();

    ModuleDescriptor descriptor = getModuleDescriptor();
    if (descriptor == null) {
      return;
    }

    for (ModuleFacetBase facet : myFacets) {
      facet.dispose();
    }
    myFacets.clear();

    Map<String, Memento> config = new HashMap<String, Memento>();
    for (ModuleFacetDescriptor facetDescriptors : descriptor.getModuleFacetDescriptors()) {
      config.put(facetDescriptors.getType(), facetDescriptors.getMemento());
    }

    Set<String> types = new HashSet<String>();
    collectMandatoryFacetTypes(types);
    types.addAll(config.keySet());

    for (String facetType : types) {
      FacetFactory factory = FacetsFacade.getInstance().getFacetFactory(facetType);
      if (factory == null) {
        LOG.error("no registered factory for a facet with type=`" + facetType + "'");
        continue;
      }
      SModuleFacet newFacet = factory.create();
      if (!(newFacet instanceof ModuleFacetBase)) {
        LOG.error("broken facet factory: " + factory.getClass().getName());
        continue;
      }

      ModuleFacetBase facet = (ModuleFacetBase) newFacet;
      Memento m = config.get(facetType);
      facet = setupFacet(facet, m);
      if (facet != null) {
        myFacets.add(facet);
      }
    }
  }
示例#15
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);
 }
示例#16
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;
 }
示例#17
0
  public void rename(@NotNull String newName) {
    SModuleReference oldRef = getModuleReference();
    renameModels(getModuleName(), newName, true);

    save(); // see MPS-18743, need to save before setting descriptor

    ModuleDescriptor descriptor = getModuleDescriptor();
    if (myDescriptorFile != null) {
      // fixme AP: this looks awful -- I agree; the right way is to have IFile something immutable
      // fixme or just work in <code>WatchedRoots</code> by IFile (not by String) and listen for
      // rename
      myFileSystem.removeListener(this);
      myDescriptorFile.rename(newName + "." + FileUtil.getExtension(myDescriptorFile.getName()));
      myFileSystem.addListener(this);
    }

    if (descriptor != null) {
      descriptor.setNamespace(newName);
      setModuleDescriptor(descriptor);
    }

    fireModuleRenamed(oldRef);
  }
示例#18
0
 /**
  * has a fallback if the usedLanguage is absent in the module descriptor. if it happens then
  * returns simply the current usedLanguage version
  *
  * @param check is whether to show error for not found version
  * @deprecated hack for migration, will be gone after 3.4
  */
 @ToRemove(version = 3.4)
 @Hack
 @Deprecated
 public int getUsedLanguageVersion(@NotNull SLanguage usedLanguage, boolean check) {
   ModuleDescriptor moduleDescriptor = getModuleDescriptor();
   if (!checkDescriptorNotNull(moduleDescriptor)) {
     return -1;
   }
   Integer res = moduleDescriptor.getLanguageVersions().get(usedLanguage);
   if (res == null) {
     if (check) {
       LOG.warn(
           String.format(
               "#getUsedLanguageVersion can't find a version for language %s in module %s, so it is falling back to the current version of the language. "
                   + "Probably the language is not imported into this module or #validateLanguageVersions() was not called on this module in appropriate moment."
                   + "NB: there might be migrations which must be applied, however they are not going to.",
               usedLanguage.getQualifiedName(), getModuleName()),
           new Throwable());
     }
     return usedLanguage.getLanguageVersion();
   }
   return res;
 }
示例#19
0
 private static Iterable<SModuleReference> getNonreexportDeps(ModuleDescriptor descr) {
   return SetSequence.fromSet(
           ((Set<jetbrains.mps.project.structure.modules.Dependency>) descr.getDependencies()))
       .where(
           new IWhereFilter<jetbrains.mps.project.structure.modules.Dependency>() {
             public boolean accept(jetbrains.mps.project.structure.modules.Dependency dep) {
               return !(dep.isReexport());
             }
           })
       .select(
           new ISelector<jetbrains.mps.project.structure.modules.Dependency, SModuleReference>() {
             public SModuleReference select(
                 jetbrains.mps.project.structure.modules.Dependency dep) {
               return dep.getModuleRef();
             }
           });
 }
示例#20
0
  private void fill(SNode module, ModuleDescriptor source) {
    SPropertyOperations.set(module, "uuid", source.getUUID());
    SPropertyOperations.set(module, "namespace", source.getNamespace());
    SPropertyOperations.set(module, "compileInMPS", "" + source.getCompileInMPS());

    for (ModelRoot root : source.getModelRoots()) {
      SLinkOperations.getTargets(module, "modelRoots", true).add(convert(root));
    }
    for (Dependency mdep : source.getDependencies()) {
      SLinkOperations.getTargets(module, "dependencies", true).add(convert(mdep));
    }
    for (ModuleReference ref : source.getUsedDevkits()) {
      SLinkOperations.getTargets(module, "usedDevkits", true).add(convert(ref));
    }
    for (ModuleReference ref : source.getUsedLanguages()) {
      SLinkOperations.getTargets(module, "usedLanguages", true).add(convert(ref));
    }
    for (ModelRoot entry : source.getStubModelEntries()) {
      SLinkOperations.getTargets(module, "stubModels", true).add(convert(entry));
    }
    for (String s : source.getSourcePaths()) {
      SLinkOperations.getTargets(module, "sourcePaths", true).add(convertSourcePath(s));
    }
  }
示例#21
0
  /**
   * Convert path from sources module descriptor for using on distribution /classes && /classes_gen
   * converts to bundle home path
   *
   * @param originalPath Original path from sources module descriptor
   * @return Converted path, null if path meaningless on packaged module
   */
  @Nullable
  private String convertPath(
      String originalPath,
      IFile bundleHome,
      IFile sourcesDescriptorFile,
      ModuleDescriptor descriptor) {
    MacroHelper macroHelper = MacrosFactory.forModuleFile(sourcesDescriptorFile);

    String canonicalPath = FileUtil.getCanonicalPath(originalPath).toLowerCase();

    // /classes && /classes_gen hack
    String suffix = descriptor.getCompileInMPS() ? CLASSES_GEN : CLASSES;
    if (canonicalPath.endsWith(suffix)) {
      // MacrosFactory based on original descriptor file because we use original descriptor file for
      // ModuleDescriptor reading, so all paths expanded to original descriptor file
      String classes = macroHelper.expandPath("${module}/" + suffix);
      if (FileUtil.getCanonicalPath(classes).equalsIgnoreCase(canonicalPath)) {
        return bundleHome.getPath();
      }
    } else if (FileUtil.getCanonicalPath(bundleHome.getPath()).equalsIgnoreCase(canonicalPath)) {
      return bundleHome.getPath();
    }

    // ${mps_home}/lib
    String mpsHomeLibPath =
        FileUtil.getCanonicalPath(PathManager.getHomePath() + File.separator + "lib").toLowerCase();
    if (canonicalPath.startsWith(mpsHomeLibPath)) {
      return canonicalPath;
    }

    // we used to keep originalPath if it has a macro not known to MPS here.
    // However, the check has been deprecated in 2012 and thus removed. I'm not 100% sure what
    // 'meaningless' in the contract of the method means. Of course, unknown macros make no sense
    // for us
    // and thus null is legitimate answer, OTOH, custom macros might have a lot of meaning to
    // someone else.
    //
    // ignore paths starts from ${module}/${project} etc
    return null;
  }
示例#22
0
 public int getModuleVersion() {
   ModuleDescriptor descriptor = getModuleDescriptor();
   return descriptor == null ? 0 : descriptor.getModuleVersion();
 }
示例#23
0
  // FIXME: MPS-19756
  // TODO: get rid of this code - generate the deployment descriptor during build process
  protected void updatePackagedDescriptor() {
    // things to do:
    // 1) load/prepare stub libraries (getAdditionalJavaStubPaths) from sources descriptor
    // 2) load/prepare stub model roots from sources descriptor
    // 3) load libraries from deployment descriptor (/classes_gen ?)

    // possible cases:
    // 1) without deployment descriptor (nothing to do; todo: ?)
    // 2) with deployment descriptor, without sources (to do: 3)
    // 3) with deployment descriptor, with sources (to do: 1,2,3)

    if (!isPackaged()) {
      return;
    }

    ModuleDescriptor descriptor = getModuleDescriptor();
    if (descriptor == null) {
      return;
    }
    DeploymentDescriptor deplDescriptor = descriptor.getDeploymentDescriptor();
    if (deplDescriptor == null) {
      return;
    }

    final IFile bundleHomeFile = getDescriptorFile().getBundleHome();
    if (bundleHomeFile == null) {
      return;
    }

    IFile bundleParent = bundleHomeFile.getParent();
    if (bundleParent == null || !bundleParent.exists()) {
      return;
    }

    IFile sourcesDescriptorFile =
        ModulesMiner.getSourceDescriptorFile(getDescriptorFile(), deplDescriptor);
    if (sourcesDescriptorFile == null) {
      // todo: for now it's impossible
      assert descriptor instanceof DeploymentDescriptor;
    } else {
      assert !(descriptor instanceof DeploymentDescriptor);
    }

    // 1 && 2
    if (sourcesDescriptorFile != null) {
      // stub libraries
      // todo: looks like module.xml contains info about model libs
      // ignore stub libraries from source module descriptor, use libs from DeploymentDescriptor
      descriptor.getAdditionalJavaStubPaths().clear();

      // stub model roots
      List<ModelRootDescriptor> toRemove = new ArrayList<ModelRootDescriptor>();
      List<ModelRootDescriptor> toAdd = new ArrayList<ModelRootDescriptor>();
      for (ModelRootDescriptor rootDescriptor : descriptor.getModelRootDescriptors()) {
        String rootDescriptorType = rootDescriptor.getType();
        if (rootDescriptorType.equals(PersistenceRegistry.JAVA_CLASSES_ROOT)) {
          // trying to load old format from deployment descriptor
          String pathElement = rootDescriptor.getMemento().get("path");
          boolean update = false;
          Memento newMemento = new MementoImpl();
          if (pathElement != null) {
            // See JavaSourceStubModelRoot & JavaClassStubsModelRoot load methods need to replace
            // with super
            String convertedPath =
                convertPath(pathElement, bundleHomeFile, sourcesDescriptorFile, descriptor);

            if (convertedPath != null) {
              newMemento.put("path", convertedPath);
              update = true;
            }
          } else {
            // trying to load new format : replacing paths like **.jar!/module ->
            String contentPath = rootDescriptor.getMemento().get(FileBasedModelRoot.CONTENT_PATH);
            List<String> paths = new LinkedList<String>();
            for (Memento sourceRoot :
                rootDescriptor.getMemento().getChildren(FileBasedModelRoot.SOURCE_ROOTS)) {
              paths.add(contentPath + File.separator + sourceRoot.get("location"));
            }
            newMemento.put(FileBasedModelRoot.CONTENT_PATH, bundleParent.getPath());
            Memento newMementoChild = newMemento.createChild(FileBasedModelRoot.SOURCE_ROOTS);
            for (String path : paths) {
              String convertedPath =
                  convertPath(path, bundleHomeFile, sourcesDescriptorFile, descriptor);
              if (convertedPath != null) {
                newMementoChild.put(
                    "location",
                    convertedPath.replace(newMemento.get(FileBasedModelRoot.CONTENT_PATH), ""));
                update = true;
              }
            }
          }
          if (update) {
            toAdd.add(new ModelRootDescriptor(rootDescriptorType, newMemento));
          }
          toRemove.add(rootDescriptor);
        }
      }
      descriptor.getModelRootDescriptors().removeAll(toRemove);
      descriptor.getModelRootDescriptors().addAll(toAdd);
    }

    // 3
    for (String jarFile : deplDescriptor.getLibraries()) {
      IFile jar =
          jarFile.startsWith("/")
              ? myFileSystem.getFile(PathManager.getHomePath() + jarFile)
              : bundleParent.getDescendant(jarFile);
      if (jar.exists()) {
        String path = jar.getPath();
        descriptor.getAdditionalJavaStubPaths().add(path);
        descriptor.getModelRootDescriptors().add(ModelRootDescriptor.getJavaStubsModelRoot(jar));
      }
    }
  }
示例#24
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;
  }