Пример #1
0
 private SNode convert(ModelRoot source) {
   SNode result =
       SModelOperations.createNewNode(
           myModel, "jetbrains.mps.lang.project.structure.ModelRoot", null);
   SPropertyOperations.set(result, "path", source.getPath());
   SPropertyOperations.set(result, "prefix", source.getPrefix());
   SLinkOperations.setTarget(result, "manager", convert(source.getManager()), true);
   return result;
 }
Пример #2
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));
    }
  }
 public static void addModelRoots(
     SolutionDescriptor solutionDescriptor, VirtualFile[] roots, ModelRootManager rootMgr) {
   Set<String> seenPaths = new HashSet<String>();
   for (ModelRootDescriptor d : solutionDescriptor.getModelRootDescriptors()) {
     ModelRoot root = d.getRoot();
     if (root != null && EqualUtil.equals(root.getManager(), rootMgr)) {
       seenPaths.add(root.getPath());
     }
   }
   for (VirtualFile f : roots) {
     SModelRoot modelRoot = new SModelRoot(rootMgr);
     modelRoot.setPath(getLocalPath(f));
     if (!seenPaths.add(modelRoot.getPath())) continue;
     solutionDescriptor.getModelRootDescriptors().add(modelRoot.toDescriptor());
   }
 }
Пример #4
0
 public void readFromXml(Element config) throws FacetConfigurationFormatException {
   List<ModelRootDescriptor> descriptors = new ArrayList<ModelRootDescriptor>();
   for (Element ch : XmlUtil.children(config, "option")) {
     String optionName = ch.getAttributeValue("name");
     if ("UUID".equals(optionName)) {
       this.UUID = ch.getAttributeValue(OPT_VALUE);
     } else if ("generatorOutputPath".equals(optionName)) {
       this.generatorOutputPath = ch.getAttributeValue(OPT_VALUE);
     } else if ("modelRoots".equals(optionName)) {
       ModelRootDescriptor[] cache = new ModelRootDescriptor[2];
       for (ModelRoot root : SetSequence.fromSet(readModelRoots(XmlUtil.first(ch, "set")))) {
         Memento m = new MementoImpl();
         root.save(m);
         ModelRootDescriptor descr =
             ModuleDescriptorPersistence.createDescriptor(null, m, null, cache);
         if (descr != null) {
           descriptors.add(descr);
         }
       }
     } else if ("usedLanguages".equals(optionName)) {
       this.usedLanguages = readArray(XmlUtil.first(ch, "array"));
     } else if ("useModuleSourceFolder".equals(optionName)) {
       this.useModuleSourceFolder = "true".equals(ch.getAttributeValue(OPT_VALUE));
     } else if ("useTransientOutputFolder".equals(optionName)) {
       this.useTransientOutputFolder = "true".equals(ch.getAttributeValue(OPT_VALUE));
     }
   }
   for (Element modelRoot : XmlUtil.children(XmlUtil.first(config, "modelRoots"), "modelRoot")) {
     Element settings = XmlUtil.first(modelRoot, "settings");
     Memento m = new MementoImpl();
     if (settings != null) {
       MementoUtil.readMemento(m, settings);
     }
     descriptors.add(new ModelRootDescriptor(modelRoot.getAttributeValue("type"), m));
   }
   rootDescriptors = descriptors.toArray(new ModelRootDescriptor[descriptors.size()]);
 }
  /*package*/ Solution createNewSolution(final IFile solutionDescriptorFile) {
    MPSProject mpsProject = myThis.getProject();

    // Prepare files
    File dir = new File(solutionDescriptorFile.getAbsolutePath()).getParentFile();
    if (!(dir.exists())) {
      dir.mkdirs();
    }
    String solutionFileName = solutionDescriptorFile.getName();
    String solutionName = solutionFileName.substring(0, solutionFileName.length() - 4);

    // Create
    // RE-2448
    ModelRoot modelRoot = new ModelRoot();
    modelRoot.setPrefix("");
    modelRoot.setPath(solutionDescriptorFile.getParent().getAbsolutePath());
    final Solution solution =
        Solution.createStubSolution(solutionName, solutionDescriptorFile, mpsProject, modelRoot);

    SolutionDescriptor solutionDescriptor = solution.getModuleDescriptor();
    solutionDescriptor.setCompileInMPS(myThis.getCompileInMPS());

    // Add SWC file to the classpath
    ModelRoot stubModelEntry = new ModelRoot();
    stubModelEntry.setPath(myThis.getSourcesPath());
    stubModelEntry.setManager(LanguageID.AS_MANAGER);
    solutionDescriptor.getStubModelEntries().add(stubModelEntry);

    // Add languages refs
    solutionDescriptor
        .getUsedLanguages()
        .add(ModuleReference.fromString(Languages.ACTION_SCRIPT_INTERNAL));
    solutionDescriptor
        .getUsedLanguages()
        .add(ModuleReference.fromString(Languages.ACTION_SCRIPT_LOGGING));
    solutionDescriptor
        .getUsedLanguages()
        .add(ModuleReference.fromString(Languages.ACTION_SCRIPT_ASSETS));

    // Add playerglobal reference
    Dependency playerGlobalDependency = new Dependency();
    playerGlobalDependency.setModuleRef(ModuleReference.fromString(PLAYERGLOBAL_SWC));
    solutionDescriptor.getDependencies().add(playerGlobalDependency);

    // Save the solution descriptor
    ModelAccess.instance()
        .writeFilesInEDT(
            new Runnable() {
              public void run() {
                solution.save();
              }
            });
    mpsProject.addProjectModule(solution);

    return solution;
  }