CodeOrchestraStreamHandler(
      SModelDescriptor modelDescriptor,
      IFile outputDir,
      CodeOrchestraGenerationFileProcessor processor) {
    myOriginalOutputDir = outputDir;

    CodeOrchestraGenerateManager codeOrchestraGenerateManager =
        processor.getProject().getComponent(CodeOrchestraGenerateManager.class);
    CodeOrchestraGenerationContext currentContext =
        codeOrchestraGenerateManager.getCurrentContext();
    if (currentContext == null) {
      myOutputDir = outputDir;
      myCachesOutputDir = FileGenerationUtil.getCachesDir(outputDir);
    } else {
      ModuleReference rootModuleReference = currentContext.getRootModule();

      // We override the output path for the AS & JS modules
      if (currentContext.isSingleOutputContext()) {
        IModule rootModule = MPSModuleRepository.getInstance().getModule(rootModuleReference);
        myOutputDir =
            FileSystem.getInstance().getFileByPath(rootModule.getOutputFor(modelDescriptor));
        myCachesOutputDir = FileGenerationUtil.getCachesDir(myOutputDir);
      } else {
        myOutputDir = outputDir;
        myCachesOutputDir = FileGenerationUtil.getCachesDir(outputDir);
      }
    }

    myModelDescriptor = modelDescriptor;
    myProcessor = processor;
  }
示例#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));
    }
  }
  private IFile fileForContent(String name, boolean isCache) {
    // RE-3090
    // RE-3635
    if (name.endsWith(TraceInfoCache.TRACE_FILE_NAME)) {
      // RE-3103
      if (myOriginalOutputDir instanceof IdeaFile) {
        IdeaFile originalOutputDirIdeaFile = (IdeaFile) myOriginalOutputDir;
        if (!originalOutputDirIdeaFile.isPackaged()) {
          return FileGenerationUtil.getDefaultOutputDir(myModelDescriptor, myOriginalOutputDir)
              .getDescendant(name);
        }
      }
    }

    IFile outputRootDir = isCache ? myCachesOutputDir : myOutputDir;

    CodeOrchestraGenerateManager codeOrchestraGenerateManager =
        myProcessor.getProject().getComponent(CodeOrchestraGenerateManager.class);
    CodeOrchestraGenerationContext currentContext =
        codeOrchestraGenerateManager.getCurrentContext();
    if (currentContext != null) {
      String fqName =
          NameUtil.longNameFromNamespaceAndShortName(
              myModelDescriptor.getLongName(), getRootNameFromFileName(name));
      if (fqName != null) {
        FileOverrideWrapper customMapping = currentContext.getCustomFileFqNameMapping(fqName);
        if (customMapping != null) {
          return FileGenerationUtil.getDefaultOutputDir(
                  NameUtil.namespaceFromLongName(customMapping.getTargetFqName()), outputRootDir)
              .getDescendant(
                  NameUtil.shortNameFromLongName(customMapping.getTargetFqName())
                      + customMapping.getExtension());
        }
      }
    }

    return FileGenerationUtil.getDefaultOutputDir(myModelDescriptor, outputRootDir)
        .getDescendant(name);
  }