Java Code Examples for org.gradle.tooling.ProjectConnection#newBuild()

The following examples show how to use org.gradle.tooling.ProjectConnection#newBuild() . 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: ComparableGradleBuildExecuter.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ProjectOutcomes executeWith(ProjectConnection connection) {
    List<String> tasksList = getSpec().getTasks();
    String[] tasks = tasksList.toArray(new String[tasksList.size()]);
    List<String> argumentsList = getImpliedArguments();
    String[] arguments = argumentsList.toArray(new String[argumentsList.size()]);

    if (isCanObtainProjectOutcomesModel()) {
        // Run the build and get the build outcomes model
        ModelBuilder<ProjectOutcomes> modelBuilder = connection.model(ProjectOutcomes.class);
        return modelBuilder.
                withArguments(arguments).
                forTasks(tasks).
                get();
    } else {
        BuildLauncher buildLauncher = connection.newBuild();
        buildLauncher.
                withArguments(arguments).
                forTasks(tasks).
                run();

        return null;
    }
}
 
Example 2
Source File: ComparableGradleBuildExecuter.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ProjectOutcomes executeWith(ProjectConnection connection) {
    List<String> tasksList = getSpec().getTasks();
    String[] tasks = tasksList.toArray(new String[tasksList.size()]);
    List<String> argumentsList = getImpliedArguments();
    String[] arguments = argumentsList.toArray(new String[argumentsList.size()]);

    if (isCanObtainProjectOutcomesModel()) {
        // Run the build and get the build outcomes model
        ModelBuilder<ProjectOutcomes> modelBuilder = connection.model(ProjectOutcomes.class);
        return modelBuilder.
                withArguments(arguments).
                forTasks(tasks).
                get();
    } else {
        BuildLauncher buildLauncher = connection.newBuild();
        buildLauncher.
                withArguments(arguments).
                forTasks(tasks).
                run();

        return null;
    }
}
 
Example 3
Source File: ComparableGradleBuildExecuter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ProjectOutcomes executeWith(ProjectConnection connection) {
    List<String> tasksList = getSpec().getTasks();
    String[] tasks = tasksList.toArray(new String[tasksList.size()]);
    List<String> argumentsList = getImpliedArguments();
    String[] arguments = argumentsList.toArray(new String[argumentsList.size()]);

    if (isCanObtainProjectOutcomesModel()) {
        // Run the build and get the build outcomes model
        ModelBuilder<ProjectOutcomes> modelBuilder = connection.model(ProjectOutcomes.class);
        return modelBuilder.
                withArguments(arguments).
                forTasks(tasks).
                get();
    } else {
        BuildLauncher buildLauncher = connection.newBuild();
        buildLauncher.
                withArguments(arguments).
                forTasks(tasks).
                run();

        return null;
    }
}
 
Example 4
Source File: ComparableGradleBuildExecuter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ProjectOutcomes executeWith(ProjectConnection connection) {
    List<String> tasksList = getSpec().getTasks();
    String[] tasks = tasksList.toArray(new String[tasksList.size()]);
    List<String> argumentsList = getImpliedArguments();
    String[] arguments = argumentsList.toArray(new String[argumentsList.size()]);

    if (isCanObtainProjectOutcomesModel()) {
        // Run the build and get the build outcomes model
        ModelBuilder<ProjectOutcomes> modelBuilder = connection.model(ProjectOutcomes.class);
        return modelBuilder.
                withArguments(arguments).
                forTasks(tasks).
                get();
    } else {
        BuildLauncher buildLauncher = connection.newBuild();
        buildLauncher.
                withArguments(arguments).
                forTasks(tasks).
                run();

        return null;
    }
}
 
Example 5
Source File: Main.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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();
    }
}
 
Example 6
Source File: Main.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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();
    }
}
 
Example 7
Source File: GradleProject.java    From meghanada-server with GNU General Public License v3.0 5 votes vote down vote up
@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 : Splitter.on(" ").split(temp)) {
        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();
    GradleProject.setBuildJVMArgs(build);
    build.forTasks(tasks.toArray(STRINGS));
    if (taskArgs.size() > 0) {
      build.withArguments(taskArgs.toArray(STRINGS));
    }

    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());
  }
}
 
Example 8
Source File: Main.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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();
    }
}
 
Example 9
Source File: Main.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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();
    }
}
 
Example 10
Source File: ToolingApiGradleHandleFactory.java    From paraphrase with Apache License 2.0 5 votes vote down vote up
public GradleHandle start(File directory, List<String> arguments) {
    GradleConnector connector = GradleConnector.newConnector();
    connector.forProjectDirectory(directory);
    ProjectConnection connection = connector.connect();
    BuildLauncher launcher = connection.newBuild();
    String[] argumentArray = new String[arguments.size()];
    arguments.toArray(argumentArray);
    launcher.withArguments(argumentArray);
    return new BuildLauncherBackedGradleHandle(launcher);
}