org.jetbrains.jps.builders.java.JavaSourceRootDescriptor Java Examples

The following examples show how to use org.jetbrains.jps.builders.java.JavaSourceRootDescriptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HaxeModuleLevelBuilder.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
@Override
  public ExitCode build(CompileContext context,
                        ModuleChunk chunk,
                        DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder,
                        OutputConsumer outputConsumer)
    throws ProjectBuildException, IOException {
    boolean doneSomething = false;

    // Don't do this.  HaxeCompiler already does it, and doing it here just
    // does it again.
//    for (final JpsModule module : chunk.getModules()) {
//      if (module.getModuleType() == JpsHaxeModuleType.INSTANCE) {
//        doneSomething |= processModule(context, dirtyFilesHolder, module);
//      }
//    }

    return doneSomething ? ExitCode.OK : ExitCode.NOTHING_DONE;
  }
 
Example #2
Source File: ThriftBuilder.java    From intellij-thrift with Apache License 2.0 5 votes vote down vote up
private Map<ModuleBuildTarget, List<File>> collectChangedFiles(
  DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder
) throws IOException {
  final Map<ModuleBuildTarget, List<File>> toCompile = new HashMap<ModuleBuildTarget, List<File>>();
  dirtyFilesHolder.processDirtyFiles(
    new ThriftFilter(toCompile)
  );
  return toCompile;
}
 
Example #3
Source File: ThriftBuilder.java    From intellij-thrift with Apache License 2.0 5 votes vote down vote up
public boolean apply(
  ModuleBuildTarget target,
  File file,
  JavaSourceRootDescriptor sourceRoot
) throws IOException {
  if (file.getName().endsWith(".thrift")) {
    List<File> files = myToCompile.get(target);
    if (files == null) {
      files = new ArrayList<File>();
      myToCompile.put(target, files);
    }
    files.add(file);
  }
  return true;
}
 
Example #4
Source File: ThriftBuilder.java    From intellij-thrift with Apache License 2.0 4 votes vote down vote up
@Override
public ExitCode build(CompileContext context,
                      ModuleChunk chunk,
                      DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder,
                      ModuleLevelBuilder.OutputConsumer outputConsumer) throws ProjectBuildException, IOException {
  ThriftConfig thriftConfig = ThriftConfig.getSettings(context.getProjectDescriptor().getProject());

  final String compiler = thriftConfig.getCompilerPath();

  final Map<ModuleBuildTarget, List<File>> toCompile = collectChangedFiles(dirtyFilesHolder);

  List<String> cmdLine = new ArrayList<String>();
  cmdLine.add(compiler);

  if (thriftConfig.isNoWarn()) {
    cmdLine.add("-nowarn");
  }
  if (thriftConfig.isStrict()) {
    cmdLine.add("-strict");
  }
  if (thriftConfig.isVerbose()) {
    cmdLine.add("-verbose");
  }
  if (thriftConfig.isRecurse()) {
    cmdLine.add("-recurse");
  }
  if (thriftConfig.isDebug()) {
    cmdLine.add("-debug");
  }
  if (thriftConfig.isAllowNegKeys()) {
    cmdLine.add("--allow-neg-keys");
  }
  if (thriftConfig.isAllow64bitConsts()) {
    cmdLine.add("--allow-64bit-consts");
  }

  for (Map.Entry<ModuleBuildTarget, List<File>> e : toCompile.entrySet()) {
    final ModuleBuildTarget target = e.getKey();
    final JpsModule module = target.getModule();
    ThriftCompilerOptions options = ThriftCompilerOptions.getSettings(module);
    final List<File> sourceFiles = e.getValue();

    final List<Generator> generators = options.getGenerators();
    if (generators.isEmpty()) {
      context.processMessage(
        new CompilerMessage(
          getPresentableName(),
          BuildMessage.Kind.WARNING,
          "No valid translators found for module " + module.getName() + ". Check facet configuration."
        )
      );

      continue;
    }

    List<String> moduleCmdLine = new ArrayList<String>(cmdLine);
    for (String include : options.getIncludes()) {
      moduleCmdLine.add("-I");
      moduleCmdLine.add(include);
    }

    for (IGenerator g : generators) {
      List<String> genCmdLine = new ArrayList<String>(moduleCmdLine);
      genCmdLine.add("--gen");
      genCmdLine.add(g.getOptionsString());
      genCmdLine.add("-out");

      final String path = new URL(g.getOutputDir()).getPath();
      genCmdLine.add(path);
      final File targetDir = new File(path);

      if (options.isCleanOutput()) {
        try {
          FileUtils.cleanDirectory(targetDir);
        }
        catch (IOException ex) {
          context.processMessage(
            new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR,
                                "Failed to empty target directory: " + path + " . Error: " + ex.getMessage())
          );
          return ExitCode.ABORT;
        }
      }

      for (File source : sourceFiles) {
        compileFile(context, target, genCmdLine, source, targetDir);
      }
    }
  }

  return ExitCode.OK;
}