Example #1
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));
    }
  }
Example #2
0
  @Override
  public void rename(String newModelName, boolean changeFile) {
    assertCanChange();

    SModelReference oldName = getReference();
    fireBeforeModelRenamed(new SModelRenamedEvent(this, oldName.getModelName(), newModelName));

    // TODO update SModelId (if it contains modelName)
    // if(getReference().getModelId().getModelName() != null) { }
    SModelReference newModelReference =
        PersistenceFacade.getInstance()
            .createModelReference(
                getReference().getModuleReference(), getReference().getModelId(), newModelName);

    fireBeforeModelRenamed(newModelReference);
    changeModelReference(newModelReference);

    if (!changeFile) {
      save();
    } else {
      if (changeFile && !(getSource() instanceof FileDataSource)) {
        throw new UnsupportedOperationException("cannot change model file on non-file data source");
      }

      IFile oldFile = ((FileDataSource) getSource()).getFile();
      ModelRoot root = ModelRootUtil.getModelRoot(this);
      if (root instanceof DefaultModelRoot) {
        DefaultModelRoot defaultModelRoot = (DefaultModelRoot) root;
        String sourceRoot = null;
        for (String sr : defaultModelRoot.getFiles(FileBasedModelRoot.SOURCE_ROOTS)) {
          if (oldFile.getPath().startsWith(sr)) {
            // using the same sourceRoot
            sourceRoot = sr;
            break;
          }
        }
        try {
          IFile newFile =
              defaultModelRoot
                  .createSource(
                      newModelName,
                      FileUtil.getExtension(oldFile.getName()),
                      sourceRoot,
                      new HashMap<String, String>())
                  .getFile();
          newFile.getParent().mkdirs();
          newFile.createNewFile();
          changeModelFile(newFile);
          save();
          oldFile.delete();
        } catch (IOException e) {
          LOG.error("cannot rename " + getModelName() + ": " + e.getMessage());
          save();
        }
      }
    }

    fireModelRenamed(new SModelRenamedEvent(this, oldName.getModelName(), newModelName));
    fireModelRenamed(oldName);
  }
  /*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;
  }
Example #4
0
 @Nullable
 public static IFile getRealDescriptorFile(
     String filePath, DeploymentDescriptor deploymentDescriptor) {
   if (deploymentDescriptor.getSourcesJar() != null) {
     IFile moduleJar =
         FileSystem.getInstance()
             .getFileByPath(
                 filePath.substring(0, filePath.length() - SLASH_META_INF_MODULE_XML.length()));
     IFile sourcesJar = moduleJar.getParent().getDescendant(deploymentDescriptor.getSourcesJar());
     if (sourcesJar.exists() && deploymentDescriptor.getDescriptorFile() != null) {
       return FileSystem.getInstance()
           .getFileByPath(
               sourcesJar.getPath() + "!/module/" + deploymentDescriptor.getDescriptorFile());
     }
   }
   return null;
 }
Example #5
0
 public static ModuleDescriptor loadModuleDescriptor(
     IFile moduleDescriptorFile,
     TemplateQueryContext genContext,
     SNode originalModule,
     ModuleChecker.Reporter reporter) {
   MacroHelper helper =
       new ModuleLoaderUtils.ModuleMacroHelper(
           moduleDescriptorFile.getParent(), genContext, originalModule, reporter);
   String path = moduleDescriptorFile.getPath();
   if (path.endsWith(MPSExtentions.DOT_LANGUAGE)) {
     return LanguageDescriptorPersistence.loadLanguageDescriptor(moduleDescriptorFile, helper);
   } else if (path.endsWith(MPSExtentions.DOT_SOLUTION)) {
     return SolutionDescriptorPersistence.loadSolutionDescriptor(moduleDescriptorFile, helper);
   } else if (path.endsWith(MPSExtentions.DOT_DEVKIT)) {
     return DevkitDescriptorPersistence.loadDevKitDescriptor(moduleDescriptorFile);
   }
   throw new RuntimeException("unknown file type: " + moduleDescriptorFile.getName());
 }
Example #6
0
  public ProcessHandler createProcess(SNode file) throws ExecutionException {
    if ((myGccLocation_String == null || myGccLocation_String.length() == 0)
        || !(new File(myGccLocation_String).exists())) {
      throw new ExecutionException("Could not find gcc by path " + myGccLocation_String);
    }

    IFile sourceFile = Gcc_Command.getSourceFile(file);
    if (!((sourceFile.exists()))) {
      throw new ExecutionException(
          "Source file " + sourceFile + " does not exist. Can't compile it.");
    }
    final IFile executableFile = Gcc_Command.getExecutableFile(file);
    ThreadUtils.runInUIThreadAndWait(
        new Runnable() {
          public void run() {
            ModelAccess.instance()
                .requireWrite(
                    new Runnable() {
                      public void run() {
                        executableFile.getParent().mkdirs();
                      }
                    });
          }
        });

    // -xc -- specifies source language (c)
    // -g -- save debug information
    return new Exec_Command()
        .setWorkingDirectory_File(new File(sourceFile.getParent().getAbsolutePath()))
        .setProgramParameters_String(
            "-xc"
                + " "
                + "-g"
                + " "
                + Gcc_Command.protect(sourceFile.getAbsolutePath())
                + " "
                + "-o "
                + Gcc_Command.protect(executableFile.getAbsolutePath()))
        .createProcess(new File(myGccLocation_String));
  }
Example #7
0
 /**
  * Module sources folder In case of working on sources == dir with module descriptor In case of
  * working on distribution = {module-name}-src.jar/module/ In case of Generator =
  * sourceLanguage.getModuleSourceDir() ${module} expands to this method
  */
 public IFile getModuleSourceDir() {
   return myDescriptorFile != null ? myDescriptorFile.getParent() : null;
 }
Example #8
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));
      }
    }
  }
  public static LanguageDescriptor loadLanguageDescriptor(
      final IFile file, final MacroHelper macroHelper) {
    LanguageDescriptor descriptor;

    try {
      Document document = JDOMUtil.loadDocument(file);
      final Element languageElement = document.getRootElement();
      final String contentRoot = file.getParent().getPath();

      descriptor =
          new _FunctionTypes._return_P0_E0<LanguageDescriptor>() {
            public LanguageDescriptor invoke() {
              final LanguageDescriptor result_v3r4p8_a0a0e0c0b = new LanguageDescriptor();
              final String result_v3r4p8_a0a0a0e0c0b =
                  languageElement.getAttributeValue("namespace");
              result_v3r4p8_a0a0e0c0b.setNamespace(result_v3r4p8_a0a0a0e0c0b);
              String uuidValue = languageElement.getAttributeValue("uuid");
              if (uuidValue != null) {
                final String result_v3r4p8_a0a2a0a0e0c0b = uuidValue;
                result_v3r4p8_a0a0e0c0b.setUUID(result_v3r4p8_a0a2a0a0e0c0b);
              }

              String genOutput = languageElement.getAttributeValue("generatorOutputPath");
              if (genOutput != null) {
                final String result_v3r4p8_a0a5a0a0e0c0b = macroHelper.expandPath(genOutput);
                result_v3r4p8_a0a0e0c0b.setGenPath(result_v3r4p8_a0a5a0a0e0c0b);
              }

              Element modelsTag = XmlUtil.first(languageElement, "models");
              if (modelsTag != null) {
                result_v3r4p8_a0a0e0c0b
                    .getModelRootDescriptors()
                    .addAll(
                        ModuleDescriptorPersistence.loadModelRoots(
                            XmlUtil.children(modelsTag, "modelRoot"), contentRoot, macroHelper));
              } else {
                // old - for backwards compatibility
                result_v3r4p8_a0a0e0c0b
                    .getModelRootDescriptors()
                    .addAll(
                        ModuleDescriptorPersistence.loadModelRoots(
                            XmlUtil.children(languageElement, "modelRoot"),
                            contentRoot,
                            macroHelper));
              }

              Element facets = XmlUtil.first(languageElement, "facets");
              if (facets != null) {
                result_v3r4p8_a0a0e0c0b
                    .getModuleFacetDescriptors()
                    .addAll(
                        ModuleDescriptorPersistence.loadFacets(
                            XmlUtil.children(facets, "facet"), macroHelper));
              }

              ModuleDescriptorPersistence.loadDependencies(
                  result_v3r4p8_a0a0e0c0b, languageElement);
              for (Element extendedLanguage :
                  Sequence.fromIterable(
                      XmlUtil.children(
                          XmlUtil.first(languageElement, "extendedLanguages"),
                          "extendedLanguage"))) {
                result_v3r4p8_a0a0e0c0b
                    .getExtendedLanguages()
                    .add(
                        PersistenceFacade.getInstance()
                            .createModuleReference(extendedLanguage.getText()));
              }

              Element autoImports = XmlUtil.first(languageElement, "accessoryModels");
              if (autoImports == null) {
                // deprecated name
                autoImports = XmlUtil.first(languageElement, "library");
              }
              for (Element modelElement :
                  Sequence.fromIterable(XmlUtil.children(autoImports, "model"))) {
                result_v3r4p8_a0a0e0c0b
                    .getAccessoryModels()
                    .add(
                        PersistenceFacade.getInstance()
                            .createModelReference(modelElement.getAttributeValue("modelUID")));
              }

              for (Element generatorElement :
                  Sequence.fromIterable(
                      XmlUtil.children(
                          XmlUtil.first(languageElement, "generators"), "generator"))) {
                result_v3r4p8_a0a0e0c0b
                    .getGenerators()
                    .add(
                        GeneratorDescriptorPersistence.loadGeneratorDescriptor(
                            generatorElement, file, contentRoot, macroHelper));
              }

              for (Element entryElement :
                  Sequence.fromIterable(
                          XmlUtil.children(XmlUtil.first(languageElement, "classPath"), "entry"))
                      .concat(
                          Sequence.fromIterable(
                              XmlUtil.children(
                                  XmlUtil.first(languageElement, "runtimeClassPath"), "entry")))) {
                // runtimeClassPath was left for compatibility
                result_v3r4p8_a0a0e0c0b
                    .getAdditionalJavaStubPaths()
                    .add(macroHelper.expandPath(entryElement.getAttributeValue("path")));
              }

              Element stubModelEntries = XmlUtil.first(languageElement, "stubModelEntries");
              if (stubModelEntries != null) {
                List<String> roots =
                    ModuleDescriptorPersistence.loadStubModelEntries(stubModelEntries, macroHelper);
                result_v3r4p8_a0a0e0c0b.getAdditionalJavaStubPaths().addAll(roots);
              }

              for (Element entryElement :
                  Sequence.fromIterable(
                      XmlUtil.children(XmlUtil.first(languageElement, "sourcePath"), "source"))) {
                result_v3r4p8_a0a0e0c0b
                    .getSourcePaths()
                    .add(macroHelper.expandPath(entryElement.getAttributeValue("path")));
              }
              return result_v3r4p8_a0a0e0c0b;
            }
          }.invoke();
    } catch (Exception e) {
      throw new ModuleReadException(e);
    }

    ModuleDescriptorPersistence.setTimestamp(descriptor, file);
    return descriptor;
  }
  @Override
  public void dispose() {
    CodeOrchestraGenerateManager codeOrchestraGenerateManager =
        myProcessor.getProject().getComponent(CodeOrchestraGenerateManager.class);
    CodeOrchestraGenerationContext currentContext =
        codeOrchestraGenerateManager.getCurrentContext();

    List<String> relativeAssetsPaths;
    if (currentContext == null) {
      relativeAssetsPaths = Collections.emptyList();
    } else {
      relativeAssetsPaths = currentContext.getRelativeAssetsPaths();
    }

    Set<IFile> directories = new HashSet<IFile>();

    // RF-826
    // directories.add(myOutputDir);

    directories.add(myCachesOutputDir);
    for (IFile f : mySavedFiles) {
      // RE-3231
      if (f instanceof IdeaFile) {
        IdeaFile ideaFile = (IdeaFile) f;
        // RE-3635
        if (ideaFile.getName().endsWith(TraceInfoCache.TRACE_FILE_NAME)) {
          continue;
        }
      }
      directories.add(f.getParent());
    }

    // clear garbage
    final List<IFile> filesToDelete = new ArrayList<IFile>();
    for (IFile dir : directories) {
      for (IFile outputDirectoryFile : dir.getChildren()) {
        if (outputDirectoryFile.isDirectory()) continue;
        if (mySavedFiles.contains(outputDirectoryFile)) continue;

        if (outputDirectoryFile instanceof IdeaFile) {
          IdeaFile ideaFile = (IdeaFile) outputDirectoryFile;

          // Ignore assets
          for (String relativeAssetsPath : relativeAssetsPaths) {
            if (ideaFile.getPath().endsWith(relativeAssetsPath)) {
              continue;
            }
          }

          // Ignore debug file
          if (ASDebugGenFile.FILE_NAME.equals(ideaFile.getName())) {
            continue;
          }

          // Ignore generated model digest file
          if (ideaFile.getName().endsWith(".generated")) {
            continue;
          }
        }

        filesToDelete.add(outputDirectoryFile);
      }
    }

    myProcessor.filesToDelete(filesToDelete);
    myProcessor.invalidateModel(myModelDescriptor);
  }