org.jetbrains.jps.model.module.JpsModule Java Examples

The following examples show how to use org.jetbrains.jps.model.module.JpsModule. 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: CabalBuilder.java    From intellij-haskforce with Apache License 2.0 6 votes vote down vote up
/**
 * Runs cabal configure.
 */
private static boolean runConfigure(CompileContext context, JpsModule module, CabalJspInterface cabal)
        throws IOException, InterruptedException, ExecutionException {
    context.processMessage(new CompilerMessage("cabal", BuildMessage.Kind.INFO, "Start configure"));

    Process configureProcess = cabal.configure();

    processOut(context, configureProcess, module);

    if (configureProcess.waitFor() != 0) {
        context.processMessage(new CompilerMessage(
                "cabal",
                BuildMessage.Kind.ERROR,
                "configure failed."));
        return true;
    }
    return false;
}
 
Example #2
Source File: CabalBuilder.java    From intellij-haskforce with Apache License 2.0 6 votes vote down vote up
/**
 * Runs cabal install --only-dependencies
 */
private static boolean runInstallDependencies(CompileContext context, JpsModule module, CabalJspInterface cabal)
        throws IOException, InterruptedException, ExecutionException {

    if (!installDependenciesRequired(cabal)) {
        return false;
    }

    context.processMessage(new CompilerMessage("cabal", BuildMessage.Kind.INFO, "Install dependencies"));

    Process installDependenciesProcess = cabal.installDependencies();

    processOut(context, installDependenciesProcess, module, true);

    if (installDependenciesProcess.waitFor() != 0) {
        context.processMessage(new CompilerMessage(
                "cabal",
                BuildMessage.Kind.ERROR,
                "install dependencies failed."));
        return true;
    }
    return false;
}
 
Example #3
Source File: CabalBuilder.java    From intellij-haskforce with Apache License 2.0 6 votes vote down vote up
/**
 * Runs cabal sandbox init
 */
private static boolean runSandboxInit(CompileContext context, JpsModule module, CabalJspInterface cabal, File cabalFile)
        throws IOException, InterruptedException, ExecutionException {

    // If sandbox already exists, no need to run init - just bail out.
    if (new File(cabalFile.getParent(), "cabal.sandbox.config").isFile()) {
        return false;
    }

    context.processMessage(new CompilerMessage("cabal", BuildMessage.Kind.INFO, "Create sandbox"));

    Process sandboxProcess = cabal.sandboxInit();

    if (sandboxProcess.waitFor() != 0) {
        context.processMessage(new CompilerMessage(
                "cabal",
                BuildMessage.Kind.ERROR,
                "sandbox init failed."));
        return true;
    }
    return false;
}
 
Example #4
Source File: ThriftFacetConfigurationSerializer.java    From intellij-thrift with Apache License 2.0 6 votes vote down vote up
@Override
protected ThriftCompilerOptions loadExtension(@NotNull Element facetConfigurationElement,
                                              String name,
                                              JpsElement parent,
                                              JpsModule module) {
  ThriftCompilerOptions configuration = XmlSerializer.deserialize(
    facetConfigurationElement,
    ThriftCompilerOptions.class
  );

  if (configuration == null) {
    configuration = new ThriftCompilerOptions();
  }

  return configuration;
}
 
Example #5
Source File: HaskellTarget.java    From intellij-haskforce with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<BuildTarget<?>> computeDependencies(BuildTargetRegistry buildTargetRegistry, TargetOutputIndex targetOutputIndex) {
    List<BuildTarget<?>> dependencies = new ArrayList<BuildTarget<?>>();
    Set<JpsModule> modules = JpsJavaExtensionService.dependencies(myModule).includedIn(JpsJavaClasspathKind.compile(isTests())).getModules();
    for (JpsModule module : modules) {
        if (module.getModuleType().equals(JpsHaskellModuleType.INSTANCE)) {
            dependencies.add(new HaskellTarget(module, getHaskellTargetType()));
        }
    }
    if (isTests()) {
        dependencies.add(new HaskellTarget(myModule, HaskellTargetType.PRODUCTION));
    }
    return dependencies;    }
 
Example #6
Source File: CabalBuilder.java    From intellij-haskforce with Apache License 2.0 5 votes vote down vote up
/**
 * Runs cabal build.
 */
private static boolean runBuild(CompileContext context, JpsModule module, CabalJspInterface cabal)
        throws IOException, InterruptedException, ExecutionException {
    context.processMessage(new ProgressMessage("cabal build"));
    context.processMessage(new CompilerMessage("cabal", BuildMessage.Kind.INFO, "Start build"));
    Process buildProcess = cabal.build();
    processOut(context, buildProcess, module);

    if (buildProcess.waitFor() != 0) {
        context.processMessage(new CompilerMessage("cabal", BuildMessage.Kind.ERROR, "build errors."));
        return true;
    }
    return false;
}
 
Example #7
Source File: CabalBuilder.java    From intellij-haskforce with Apache License 2.0 5 votes vote down vote up
/**
 * Searches for the cabal file in the module top directory.
 */
private static File getCabalFile(JpsModule module) {
    String pathname = getContentRootPath(module);
    //noinspection ConstantConditions
    for (File file : new File(pathname).listFiles()) {
        if (file.getName().endsWith(".cabal")) {
            return file;
        }
    }
    return null;
}
 
Example #8
Source File: ThriftBuilder.java    From intellij-thrift with Apache License 2.0 5 votes vote down vote up
private void compileFile(final CompileContext context, ModuleBuildTarget target, List<String> line, File source, File dir)
  throws StopBuildException {
  final JpsModule module = target.getModule();
  List<String> cmdLine = new ArrayList<String>(line);
  cmdLine.add(source.getAbsolutePath());

  StringBuilder cmdMessage = new StringBuilder();
  for (String cmdPart : cmdLine) {
    cmdMessage.append(cmdPart).append(' ');
  }

  context.processMessage(
    new CompilerMessage(getPresentableName(), BuildMessage.Kind.INFO, cmdMessage.toString())
  );

  try {
    Process process = new ProcessBuilder()
      .command(cmdLine)
      .start();


    BaseOSProcessHandler handler = new BaseOSProcessHandler(process, StringUtil.join(cmdLine, " "), CharsetToolkit.UTF8_CHARSET);

    final AtomicBoolean hasErrors = new AtomicBoolean();
    handler.addProcessListener(new ThriftOutputConsumer(source.getAbsolutePath(), context, hasErrors, module, dir));
    handler.startNotify();
    handler.waitFor();
    if (hasErrors.get()) {
      throw new StopBuildException();
    }
  }
  catch (IOException e) {
    context.processMessage(
      new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, "Failed to translate files . Error: " + e.getMessage())
    );
  }
}
 
Example #9
Source File: ThriftOutputConsumer.java    From intellij-thrift with Apache License 2.0 5 votes vote down vote up
public ThriftOutputConsumer(String fileName, CompileContext context, AtomicBoolean hasErrors, JpsModule module, File targetDir) {
  this.fileName = fileName;
  myContext = context;
  myHasErrors = hasErrors;
  myModule = module;
  stdOutput = new StringBuilder();
  errOutput = new StringBuilder();
  myTargetDir = targetDir;
}
 
Example #10
Source File: ThriftCompilerOptions.java    From intellij-thrift with Apache License 2.0 4 votes vote down vote up
public static ThriftCompilerOptions getSettings(JpsModule module) {
  final ThriftCompilerOptions config = module.getContainer().getChild(ROLE);

  return config == null ? new ThriftCompilerOptions() : config;
}
 
Example #11
Source File: HaskellTarget.java    From intellij-haskforce with Apache License 2.0 4 votes vote down vote up
public HaskellTarget(@NotNull JpsModule module, HaskellTargetType targetType) {
    super(targetType, module);
}
 
Example #12
Source File: ThriftFacetConfigurationSerializer.java    From intellij-thrift with Apache License 2.0 4 votes vote down vote up
@Override
protected void saveExtension(ThriftCompilerOptions extension, Element facetConfigurationTag, JpsModule module) {
}
 
Example #13
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;
}
 
Example #14
Source File: JpsHaxeUtil.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
@Nullable
public static JpsHaxeModuleSettings getModuleSettings(@NotNull JpsModule module) {
  final JpsElement result = module.getProperties();
  return result instanceof JpsHaxeModuleSettings ? (JpsHaxeModuleSettings)result : null;
}
 
Example #15
Source File: JpsHaskellModuleExtension.java    From intellij-haskforce with Apache License 2.0 4 votes vote down vote up
@Nullable
public static JpsHaskellModuleExtension getExtension(@Nullable JpsModule module) {
    return module != null ? module.getContainer().getChild(ROLE) : null;
}
 
Example #16
Source File: CabalBuilder.java    From intellij-haskforce with Apache License 2.0 4 votes vote down vote up
private static String getContentRootPath(JpsModule module) {
    String url = module.getContentRootsList().getUrls().get(0);
    return url.substring("file://".length());
}
 
Example #17
Source File: CabalBuilder.java    From intellij-haskforce with Apache License 2.0 4 votes vote down vote up
/**
 * Parses output from cabal and signals errors/warnings to the IDE.
 */
private static void processOut(CompileContext context, Process process, JpsModule module) {
    processOut(context, process, module, false);
}