当前位置: 首页>>代码示例>>Java>>正文


Java BuildLauncher.forTasks方法代码示例

本文整理汇总了Java中org.gradle.tooling.BuildLauncher.forTasks方法的典型用法代码示例。如果您正苦于以下问题:Java BuildLauncher.forTasks方法的具体用法?Java BuildLauncher.forTasks怎么用?Java BuildLauncher.forTasks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.gradle.tooling.BuildLauncher的用法示例。


在下文中一共展示了BuildLauncher.forTasks方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runTasks

import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
protected byte[] runTasks(String pathToRootOfProject, String... tasks) {
    ProjectConnection connection = GradleConnector.newConnector().forProjectDirectory(new File(pathToRootOfProject)).connect();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    try {
        BuildLauncher build = connection.newBuild();
        build.forTasks(tasks);
        build.setStandardOutput(outputStream);
        build.setStandardError(outputStream);
        build.run();
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        connection.close();
    }
    return outputStream.toByteArray();
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:18,代码来源:GradleAutomaticBuilder.java

示例2: compile

import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
public void compile() throws Exception {

        ProjectConnection connection = getConnector().connect();
        try {
            // Configure the build
            BuildLauncher launcher = connection.newBuild();
            if (flavor != null) {
                launcher.forTasks(task + StringUtils.capitalize(flavor));
            } else {
                launcher.forTasks(task);
            }
            if (buildFile != null) {
                launcher.withArguments("-b", buildFile.getAbsolutePath());
            }
            launcher.setStandardOutput(System.out);
            launcher.setStandardError(System.err);

            // Run the build
            launcher.run();
        } finally {
            // Clean up
            connection.close();
        }
    }
 
开发者ID:walkmod,项目名称:walkmod-gradle-plugin,代码行数:25,代码来源:ClassLoaderConfigurationProvider.java

示例3: main

import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
public static void main(String[] args) {
    // Configure the connector and create the connection
    GradleConnector connector = GradleConnector.newConnector();

    if (args.length > 0) {
        connector.useInstallation(new File(args[0]));
        if (args.length > 1) {
            connector.useGradleUserHomeDir(new File(args[1]));
        }
    }

    connector.forProjectDirectory(new File("."));

    ProjectConnection connection = connector.connect();
    try {
        // Configure the build
        BuildLauncher launcher = connection.newBuild();
        launcher.forTasks("help");
        launcher.setStandardOutput(System.out);
        launcher.setStandardError(System.err);

        // Run the build
        launcher.run();
    } finally {
        // Clean up
        connection.close();
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:29,代码来源:Main.java

示例4: runTask

import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
@Override
public InputStream runTask(final List<String> args) throws IOException {
  try {
    final List<String> tasks = new ArrayList<>(4);
    final List<String> taskArgs = new ArrayList<>(4);
    for (final String temp : args) {
      for (final String arg : temp.split(" ")) {
        if (arg.startsWith("-")) {
          taskArgs.add(arg.trim());
        } else {
          tasks.add(arg.trim());
        }
      }
    }

    log.debug("task:{}:{} args:{}:{}", tasks, tasks.size(), taskArgs, taskArgs.size());

    final ProjectConnection projectConnection = getProjectConnection();
    final BuildLauncher build = projectConnection.newBuild();
    this.setBuildJVMArgs(build);
    build.forTasks(tasks.toArray(new String[tasks.size()]));
    if (taskArgs.size() > 0) {
      build.withArguments(taskArgs.toArray(new String[taskArgs.size()]));
    }

    final PipedOutputStream outputStream = new PipedOutputStream();
    PipedInputStream inputStream = new PipedInputStream(outputStream);
    build.setStandardError(outputStream);
    build.setStandardOutput(outputStream);
    final VoidResultHandler handler =
        new VoidResultHandler(outputStream, inputStream, projectConnection);
    build.run(handler);
    return inputStream;
  } finally {
    Config.setProjectRoot(this.projectRoot.getCanonicalPath());
  }
}
 
开发者ID:mopemope,项目名称:meghanada-server,代码行数:38,代码来源:GradleProject.java

示例5: run

import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
/**
 * Starts the progress handler and executes the gradle task.
 */
@Override
public void run() {
    if (gradleTask != null && gradleTask.isValid()) {
        progressHandler = ProgressHandle.createHandle(gradleTask.getDescription(), this);
        progressHandler.start();            
        ProjectConnection connection = null;            
        try {
            connection = getGradleConnection();
            BuildLauncher buildLauncher = connection.newBuild();
            buildLauncher.forTasks(gradleTask.getName());
            String[] executionParameters = gradleTask.getExecutionParameters();
            buildLauncher.withArguments(executionParameters);
            LOG.info(EXECUTE_A_GRADLE_TASK);
            LOG.log(Level.INFO, "{0} {1} on folder: {2}", new Object[]{gradleTask.getName(), 
                                                                       Arrays.toString(executionParameters),
                                                                       gradleTask.getFolder()});
            GradleResultHandler resultHandler = gradleTask.getResultHandler();
            if (resultHandler != null) {
                buildLauncher.setStandardError(resultHandler.getErrorOutputStream());
                buildLauncher.setStandardOutput(resultHandler.getOutputStream());
                buildLauncher.run(resultHandler);
            } else {
                buildLauncher.run();
            }
        } catch(GradleConnectionException | IllegalStateException ex) {
            Exceptions.printStackTrace(ex);
        } finally {
            if (connection != null) {
                connection.close();
            }
        }
    }
}
 
开发者ID:fundacionjala,项目名称:oblivion-netbeans-plugin,代码行数:37,代码来源:GradleTaskExecutor.java

示例6: main

import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
public static void main(String[] args) {
    // Configure the connector and create the connection
    GradleConnector connector = GradleConnector.newConnector();

    if (args.length > 0) {
        connector.useInstallation(new File(args[0]));
        if (args.length > 1) {
            connector.useGradleUserHomeDir(new File(args[1]));
        }
    }

    connector.forProjectDirectory(new File("."));

    ProjectConnection connection = connector.connect();
    try {
        // Configure the build
        BuildLauncher launcher = connection.newBuild();
        launcher.forTasks("help");
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        launcher.setStandardOutput(outputStream);
        launcher.setStandardError(outputStream);

        // Run the build
        launcher.run();
    } finally {
        // Clean up
        connection.close();
    }
}
 
开发者ID:Pushjet,项目名称:Pushjet-Android,代码行数:30,代码来源:Main.java

示例7: buildProject

import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
private void buildProject(SubMonitor monitor, ProjectConnection connection) throws CoreException {
    monitor.beginTask(Messages.GradleBuildTask_monitorBuild, 100);
    try {
        GradleUtil.checkCancel(monitor);
        BuildEnvironment environment = GradleUtil.getEnvironment(connection);
        BuildLauncher builder = connection.newBuild();
        builder.forTasks(tasks.toArray(new String[tasks.size()]));
        OperationHandler<Void> handler = GradleUtil.configureOperation(environment, builder, configuration);
        try {
            builder.run(handler);
            while (handler.await() == false) {
                GradleUtil.checkCancel(monitor, handler);
                ProgressEvent event = handler.takeProgressEvent();
                if (event != null) {
                    monitor.setTaskName(String.format("[Gradle] %s", event.getDescriptor())); //$NON-NLS-1$
                }
                monitor.worked(1);
                monitor.setWorkRemaining(100);
            }
            if (handler.hasException()) {
                GradleUtil.reportException(configuration, handler.getException());
                throw new GradleException(new Status(
                        IStatus.WARNING,
                        Activator.PLUGIN_ID,
                        MessageFormat.format(
                                Messages.GradleBuildTask_errorFailedToBuildProject,
                                configuration.projectDirectory.getName()),
                        handler.getException()), handler.getException());
            }
        } finally {
            handler.close();
        }
    } catch (InterruptedException e) {
        throw new CoreException(Status.CANCEL_STATUS);
    }
}
 
开发者ID:asakusafw,项目名称:asakusafw-shafu,代码行数:37,代码来源:GradleBuildTask.java

示例8: executeTasks

import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
@Override
public void executeTasks(@NotNull final ExternalSystemTaskId id,
                         @NotNull final List<String> taskNames,
                         @NotNull String projectPath,
                         @Nullable final GradleExecutionSettings settings,
                         @NotNull final List<String> vmOptions,
                         @NotNull final List<String> scriptParameters,
                         @Nullable final String debuggerSetup,
                         @NotNull final ExternalSystemTaskNotificationListener listener) throws ExternalSystemException {

  // TODO add support for external process mode
  if (ExternalSystemApiUtil.isInProcessMode(GradleConstants.SYSTEM_ID)) {
    for (GradleTaskManagerExtension gradleTaskManagerExtension : GradleTaskManagerExtension.EP_NAME.getExtensions()) {
      if (gradleTaskManagerExtension.executeTasks(
        id, taskNames, projectPath, settings, vmOptions, scriptParameters, debuggerSetup, listener)) {
        return;
      }
    }
  }
  if(!scriptParameters.contains("--tests") && taskNames.contains("test")) {
    ContainerUtil.addAll(scriptParameters, "--tests", "*");
  }

  Function<ProjectConnection, Void> f = new Function<ProjectConnection, Void>() {
    @Override
    public Void fun(ProjectConnection connection) {

      final List<String> initScripts = ContainerUtil.newArrayList();
      final GradleProjectResolverExtension projectResolverChain = GradleProjectResolver.createProjectResolverChain(settings);
      for (GradleProjectResolverExtension resolverExtension = projectResolverChain;
           resolverExtension != null;
           resolverExtension = resolverExtension.getNext()) {
        final String resolverClassName = resolverExtension.getClass().getName();
        resolverExtension.enhanceTaskProcessing(taskNames, debuggerSetup, new Consumer<String>() {
          @Override
          public void consume(String script) {
            if (StringUtil.isNotEmpty(script)) {
              ContainerUtil.addAllNotNull(
                initScripts,
                "//-- Generated by " + resolverClassName,
                script,
                "//");
            }
          }
        });
      }

      if (!initScripts.isEmpty()) {
        try {
          final File tempFile = FileUtil.createTempFile("init", ".gradle");
          tempFile.deleteOnExit();
          FileUtil.writeToFile(tempFile, StringUtil.join(initScripts, SystemProperties.getLineSeparator()));
          ContainerUtil.addAll(scriptParameters, GradleConstants.INIT_SCRIPT_CMD_OPTION, tempFile.getAbsolutePath());
        }
        catch (IOException e) {
          throw new ExternalSystemException(e);
        }
      }

      GradleVersion gradleVersion = GradleExecutionHelper.getGradleVersion(connection);
      BuildLauncher launcher = myHelper.getBuildLauncher(id, connection, settings, listener, vmOptions, scriptParameters);
      launcher.forTasks(ArrayUtil.toStringArray(taskNames));

      if (gradleVersion != null && gradleVersion.compareTo(GradleVersion.version("2.1")) < 0) {
        myCancellationMap.put(id, new UnsupportedCancellationToken());
      } else {
        final CancellationTokenSource cancellationTokenSource = GradleConnector.newCancellationTokenSource();
        launcher.withCancellationToken(cancellationTokenSource.token());
        myCancellationMap.put(id, cancellationTokenSource);
      }
      try {
        launcher.run();
      }
      finally {
        myCancellationMap.remove(id);
      }
      return null;
    }
  };
  myHelper.execute(projectPath, settings, f);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:82,代码来源:GradleTaskManager.java

示例9: getDepsCoordinates

import org.gradle.tooling.BuildLauncher; //导入方法依赖的package包/类
public List<String> getDepsCoordinates(ProjectConnection connection, File buildFile) {
    BuildLauncher launcher = connection.newBuild();
    if (buildFile != null) {
        launcher.withArguments("-b", buildFile.getAbsolutePath());
    }
    launcher.forTasks("dependencies");
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    launcher.setStandardOutput(bos);
    launcher.setStandardError(System.err);
    launcher.run();
    String content = bos.toString();
    String[] lines = content.split("\\n");
    List<String> coordinates = new LinkedList<String>();
    for (int i = 0; i < lines.length; i++) {
        if (lines[i].startsWith("compile") || lines[i].startsWith("provided")) {
            if (i + 1 < lines.length && !lines[i + 1].startsWith("No dependencies")) {
                int j = i + 1;
                String prefix = null;
                String nextGoal = "debugApk";
                if (lines[i].startsWith("provided")) {
                    nextGoal = "releaseApk";
                }
                while (j < lines.length && !lines[j].startsWith(nextGoal)) {
                    int index = lines[j].lastIndexOf("--");
                    if (index != -1) {
                        prefix = lines[j].substring(0, index + 2);

                        if (lines[j].length() > prefix.length()) {

                            String artifact = lines[j].substring(prefix.length()).trim();
                            if (!artifact.endsWith("(*)")) {
                                int dynamicVersionIndex = artifact.indexOf("->");
                                if (dynamicVersionIndex != -1) {
                                    String artifactName = artifact.substring(0, artifact.lastIndexOf(":")).trim();
                                    String version = artifact.substring(dynamicVersionIndex + 2).trim();
                                    artifact = artifactName + ":" + version;
                                }
                                coordinates.add(artifact);
                            }

                        }
                    }
                    j++;
                }

            }
        }
    }
    return coordinates;
}
 
开发者ID:walkmod,项目名称:walkmod-gradle-plugin,代码行数:51,代码来源:GradleUtils.java


注:本文中的org.gradle.tooling.BuildLauncher.forTasks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。