org.gradle.api.Project.javaexec()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(266)

本文整理了Java中org.gradle.api.Project.javaexec()方法的一些代码示例,展示了Project.javaexec()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Project.javaexec()方法的具体详情如下:
包路径:org.gradle.api.Project
类名称:Project
方法名:javaexec

Project.javaexec介绍

暂无

代码示例

代码示例来源:origin: gradle.plugin.ca.coglinc2/javacc-gradle-plugin

@Override
public void invokeCompiler(ProgramArguments arguments) throws Exception {
  ExecResult execResult = project.javaexec(executor(arguments));
  if (execResult.getExitValue() != 0) {
    throw new IllegalStateException("JJTree failed with error code: [" + execResult.getExitValue() + "]");
  }
}

代码示例来源:origin: com.github.rodm/gradle-teamcity-dsl-plugin

@TaskAction
void generate() {
  ExecResult result = getProject().javaexec(new Action<JavaExecSpec>() {
    @Override
    public void execute(JavaExecSpec spec) {
      getLogger().lifecycle(CONFIG_MESSAGE, getFormat(), formatPath(getBaseDir()), formatPath(getDestDir()));
      getLogger().info("Using main class {}", getMainClass());
      Configuration configuration = getProject().getConfigurations().getAt(CONFIGURATION_NAME);
      String toolPath = configuration.getAsPath();
      spec.setIgnoreExitValue(true);
      spec.setClasspath(createToolClasspath(configuration));
      spec.setMain(getMainClass());
      spec.args(getFormat(), getBaseDir().getAbsolutePath(), getDestDir().getAbsolutePath(), toolPath);
    }
    private FileCollection createToolClasspath(Configuration teamcityClasspath) {
      File toolJar = new File(getClass().getProtectionDomain().getCodeSource().getLocation().getPath());
      List<Object> classPath = new ArrayList<>();
      classPath.add(toolJar);
      classPath.add(teamcityClasspath);
      return getProject().files(classPath);
    }
  });
  if (result.getExitValue() != 0) {
    String message = "Process generating TeamCity configurations failed. See the report at: ";
    String dslReportUrl = asClickableFileUrl(new File(getDestDir(), DSL_EXCEPTION_FILENAME));
    throw new GradleException(message + dslReportUrl);
  }
}

代码示例来源:origin: javafxports/javafxmobile-plugin

public void exec() {
  project.javaexec(exec -> {
    exec.setClasspath(project.getBuildscript().getConfigurations().getByName("classpath"));
    String path = retrobufferClasspath.getAsPath();
    exec.setMain("org.javafxports.retrobuffer.Main");
    exec.setJvmArgs(Arrays.asList(
        "-Dretrobuffer.inputDir=" + inputDir,
        "-Dretrobuffer.outputDir=" + outputDir,
        "-Dretrobuffer.classpath=" + path
    ));
    if (classpathLengthGreaterThanLimit(path)) {
      try {
        File classpathFile = File.createTempFile("inc-", ".path");
        try (BufferedWriter writer = Files.newBufferedWriter(classpathFile.toPath(), StandardCharsets.UTF_8)) {
          for (File item : this.retrobufferClasspath) {
            writer.write(item.toString() + "\n");
          }
        }
        classpathFile.deleteOnExit();
        exec.getJvmArgs().add("-Dretrobuffer.classpathFile=" + classpathFile.getAbsolutePath());
      } catch (IOException e) {
      }
    } else {
      exec.getJvmArgs().add("-Dretrobuffer.classpath=" + path);
    }
    for (String arg : jvmArgs) {
      exec.getJvmArgs().add(arg);
    }
  });
}

代码示例来源:origin: MinecraftForge/ForgeGradle

private void runForkedFernFlower(final File data)
{
  ExecResult result = getProject().javaexec(new Action<JavaExecSpec>() {
    @Override
    public void execute(JavaExecSpec exec)
    {
      exec.classpath(forkedClasspath);
      exec.setMain(FernFlowerInvoker.class.getName());
      exec.setJvmArgs(ImmutableList.of("-Xmx3G"));
      // pass the temporary file
      exec.args(data);
      // Forward std streams
      exec.setStandardOutput(System.out);
      exec.setErrorOutput(System.err);
    }
  });
  result.rethrowFailure();
  result.assertNormalExitValue();
}

代码示例来源:origin: steffenschaefer/gwt-gradle-plugin

@TaskAction
public void exec() {
   final ExecResult execResult = getProject().javaexec(new Action<JavaExecSpec>() {
    @Override
    public void execute(JavaExecSpec javaExecSpec) {

代码示例来源:origin: gradle.plugin.pl.itgolo.gradle/allegro-wsdl

String.format("--output=%1$s", extension.getOutputDir())
    );
getProject().javaexec(new Closure(this) {
  public void doCall(JavaExecSpec javaExecSpec) {
    javaExecSpec.setMain("org.apache.axis.wsdl.WSDL2Java")

代码示例来源:origin: io.github.gradle-clojure/gradle-clojure-plugin

public void exec(ClojureExecSpec cljSpec) {
 FileCollection fullClasspath = cljSpec.getClasspath();
 project.javaexec(spec -> {
  spec.setMain("clojure.main");
  spec.args("-m", cljSpec.getMain());
  String ednArgs = Edn.print(Arrays.asList(cljSpec.getArgs()));
  ByteArrayInputStream input = new ByteArrayInputStream(ednArgs.getBytes(StandardCharsets.UTF_8));
  spec.setStandardInput(input);
  spec.setClasspath(fullClasspath);
  cljSpec.getConfigureFork().forEach(forkAction -> forkAction.execute(spec));
  spec.systemProperty("gradle-clojure.tools.logger.level", getLogLevel());
 });
}

代码示例来源:origin: gradle-clojure/gradle-clojure

public void exec(ClojureExecSpec cljSpec) {
 FileCollection fullClasspath = cljSpec.getClasspath();
 project.javaexec(spec -> {
  spec.setMain("clojure.main");
  spec.args("-m", cljSpec.getMain());
  String ednArgs = Edn.print(Arrays.asList(cljSpec.getArgs()));
  ByteArrayInputStream input = new ByteArrayInputStream(ednArgs.getBytes(StandardCharsets.UTF_8));
  spec.setStandardInput(input);
  spec.setClasspath(fullClasspath);
  cljSpec.getConfigureFork().forEach(forkAction -> forkAction.execute(spec));
  spec.systemProperty("gradle-clojure.tools.logger.level", getLogLevel());
 });
}

代码示例来源:origin: javafxports/javafxmobile-plugin

public void exec() {
  project.javaexec(exec -> {
    Configuration retrolambdaConfig = project.getConfigurations().getByName("retrolambdaConfig");

代码示例来源:origin: org.gosu-lang.gosu/gradle-gosu-plugin

ExecResult result = _project.javaexec(javaExecSpec -> {

代码示例来源:origin: typelead/gradle-eta

private void execute(Action<JavaExecSpec> execSpecAction,
             TestResultProcessor resultProcessor) {
    Object rootTestId = "eta-test-root";
    Object testId = "eta-test";
    resultProcessor.started
      (new DefaultTestSuiteDescriptor(rootTestId, "Eta Root"),
       new TestStartEvent(System.currentTimeMillis()));
    resultProcessor.started
      (new DefaultTestDescriptor(testId, "eta.main", "Default Eta Test"),
       new TestStartEvent(System.currentTimeMillis()));
    ExecResult execResult = project.javaexec(execSpec -> {
        execSpecAction.execute(execSpec);
        execSpec.setMain("eta.main");
      });
    ResultType resultType =
      (execResult.getExitValue() == 0)? ResultType.SUCCESS : ResultType.FAILURE;
    resultProcessor.completed
      (testId, new TestCompleteEvent(System.currentTimeMillis(), resultType));
    resultProcessor.completed
      (rootTestId, new TestCompleteEvent(System.currentTimeMillis(), resultType));
  }
}

代码示例来源:origin: diffplug/goomph

/** Calls javaExec() in a way which is friendly with windows classpath limitations. */
public static ExecResult javaExec(Project project, Action<JavaExecSpec> spec) throws IOException {
  if (OS.getNative().isWindows()) {
    Box.Nullable<File> classpathJarBox = Box.Nullable.ofNull();
    ExecResult execResult = project.javaexec(execSpec -> {
      // handle the user
      spec.execute(execSpec);
      // create a jar which embeds the classpath
      File classpathJar = toJarWithClasspath(execSpec.getClasspath());
      classpathJar.deleteOnExit();
      // set the classpath to be just that one jar
      execSpec.setClasspath(project.files(classpathJar));
      // save the jar so it can be deleted later
      classpathJarBox.set(classpathJar);
    });
    // delete the jar after the task has finished
    Errors.suppress().run(() -> FileMisc.forceDelete(classpathJarBox.get()));
    return execResult;
  } else {
    return project.javaexec(spec);
  }
}

代码示例来源:origin: org.gosu-lang.gosu/gradle-gosu-plugin

ByteArrayOutputStream stderr = new ByteArrayOutputStream();
ExecResult result = _project.javaexec(javaExecSpec -> {

代码示例来源:origin: io.freefair.gradle/lombok-plugin

getProject().javaexec(delombok -> {
  delombok.setClasspath(getLombokClasspath());
  delombok.setMain("lombok.launch.Main");

代码示例来源:origin: com.android.tools.build/gradle-core

@NonNull
@Override
public ProcessResult execute(
    @NonNull JavaProcessInfo javaProcessInfo,
    @NonNull ProcessOutputHandler processOutputHandler) {
  project.getLogger().info("Executing java process: ", javaProcessInfo.toString());
  ProcessOutput output = processOutputHandler.createOutput();
  ExecResult result;
  try {
    result = project.javaexec(new ExecAction(javaProcessInfo, output));
  } finally {
    try {
      output.close();
    } catch (IOException e) {
      project.getLogger().warn("Exception while closing sub process streams", e);
    }
  }
  try {
    processOutputHandler.handleOutput(output);
  } catch (ProcessException e) {
    return new OutputHandlerFailedGradleProcessResult(e);
  }
  return new GradleProcessResult(result, javaProcessInfo);
}

代码示例来源:origin: gradle.plugin.de.set.gradle/gradle-eclipse-compiler-plugin

@Override
public WorkResult execute(JavaCompileSpec javaCompileSpec) {
 LOGGER.info("Compiling sources using eclipse compiler for java ["+this.ecjArtifact+"]");
 final List<String> remainingArguments =
   new JavaCompilerArgumentsBuilder(javaCompileSpec).includeSourceFiles(true).build();
 ExecResult result = project.javaexec(exec -> {
  exec.setWorkingDir(javaCompileSpec.getWorkingDir());
  exec.setClasspath(compilerConfiguration);
  exec.setMain("org.eclipse.jdt.internal.compiler.batch.Main");
  exec.args(shortenArgs(javaCompileSpec.getTempDir(), remainingArguments));
 });
 if (result.getExitValue() != 0) {
  throw new CompilationFailedException(result.getExitValue());
 }
 return () -> true;
}

相关文章