Package org.gradle.tooling

Examples of org.gradle.tooling.ProjectConnection


        return gradlewFile;
    }

    public static void callGradleTask(File buildFile, String taskName, String[] params) throws Exception {

        ProjectConnection connection = GradleConnector.newConnector().forProjectDirectory(buildFile.getParentFile())
                .connect();

        try {
            BuildLauncher build = connection.newBuild();

            // select tasks to run:
            build.forTasks(taskName);

            List<String> buildArgs = new ArrayList<String>();
View Full Code Here


    static class ExecGradle {

        public static void exec(File buildFile, String taskName, String[] params) throws Exception {

            ProjectConnection connection = GradleConnector.newConnector()
                    .forProjectDirectory(buildFile.getParentFile()).connect();

            try {
                BuildLauncher build = connection.newBuild();

                // select tasks to run:
                build.forTasks(taskName);

                List<String> buildArgs = new ArrayList<String>();
                // buildArgs.add("-b");
                // buildArgs.add(buildFilePath);
                buildArgs.add("-stacktrace");
                buildArgs.add("-info");
                if (params.length > 0) {
                    for (int i = 0; i < params.length; i++) {
                        buildArgs.add("-P" + params[i]);
                    }
                }

                logger.info(Arrays.toString(buildArgs.toArray()));

                build.withArguments(buildArgs.toArray(new String[] {}));

                // if you want to listen to the progress events:
                ProgressListener listener = null; // use your implementation
                // build.addProgressListener(listener);

                // kick the build off:
                build.run();
            } finally {
                connection.close();
            }
        }
View Full Code Here

      if (!Strings.isNullOrEmpty(gradleHome))
      {
         connector = connector.useGradleUserHomeDir(new File(gradleHome));
      }
     
      ProjectConnection connection = connector.connect();

      BuildLauncher launcher = connection.newBuild().forTasks(task);

      List<String> argList = Lists.newArrayList(arguments);

      if (!Strings.isNullOrEmpty(profile))
      {
View Full Code Here

public class ToolingApiGradleHandleFactory implements GradleHandleFactory {

    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);
    }
View Full Code Here

        OperationInitializer setup = GradleModelLoader.modelBuilderSetup(project, progress);

        // FIXME: Currently we just fetch IdeaProject and rely on that to fetch
        //   the sources. Then the source locator query will find the sources
        //   in the Gradle cache.
        ProjectConnection connection = connector.connect();
        try {
            ModelBuilder<IdeaProject> builder = connection.model(IdeaProject.class);
            GradleModelLoader.setupLongRunningOP(setup, builder);

            builder.get();
        } finally {
            connection.close();
        }
    }
View Full Code Here

        Throwable commandError = null;

        GradleConnector gradleConnector = GradleModelLoader.createGradleConnector(cancelToken, project);
        gradleConnector.forProjectDirectory(projectDir);
        ProjectConnection projectConnection = null;
        try {
            projectConnection = gradleConnector.connect();

            BuildLauncher buildLauncher = projectConnection.newBuild();
            List<TemporaryFileRef> initScripts = getAllInitScriptFiles(project);
            try {
                configureBuildLauncher(targetSetup, buildLauncher, taskDef, initScripts);

                TaskOutputDef outputDef = taskDef.getOutputDef();

                TaskOutputKey outputDefKey = outputDef.getKey();
                String outputDefCaption = outputDef.getCaption();
                try (IOTabRef<TaskIOTab> ioRef = IOTabs.taskTabs().getTab(outputDefKey, outputDefCaption)) {
                    TaskIOTab tab = ioRef.getTab();
                    tab.setLastTask(buildItem.getSourceTaskDef(), adjust(taskDef));
                    tab.taskStarted();
                    BuildExecutionSupport.registerRunningItem(buildItem);

                    try {
                        OutputWriter buildOutput = tab.getIo().getOutRef();
                        if (GlobalGradleSettings.getAlwaysClearOutput().getValue()
                                || taskDef.isCleanOutput()) {
                            buildOutput.reset();
                            // There is no need to reset buildErrOutput,
                            // at least this is what NetBeans tells you in its
                            // logs if you do.
                        }
                        printCommand(buildOutput, command, taskDef);

                        try (OutputRef outputRef = configureOutput(project, taskDef, buildLauncher, tab)) {
                            assert outputRef != null; // Avoid warning

                            InputOutputWrapper io = tab.getIo();
                            io.getIo().select();

                            if (checkTaskExecutable(projectConnection, taskDef, targetSetup, io)) {
                                runBuild(cancelToken, buildLauncher);

                                taskDef.getSuccessfulCommandFinalizer().finalizeSuccessfulCommand(
                                        buildOutput,
                                        io.getErrRef());
                            }
                        }
                    } catch (Throwable ex) {
                        Level logLevel;

                        if (taskDef.getCommandExceptionHider().hideException(ex)) {
                            logLevel = Level.INFO;
                        }
                        else {
                            commandError = ex;
                            logLevel = ex instanceof Exception ? Level.INFO : Level.SEVERE;
                        }

                        LOGGER.log(logLevel, "Gradle build failure: " + command, ex);

                        String buildFailureMessage = NbStrings.getBuildFailure(command);

                        OutputWriter buildErrOutput = tab.getIo().getErrRef();
                        buildErrOutput.println();
                        buildErrOutput.println(buildFailureMessage);
                        if (commandError != null) {
                            project.displayError(buildFailureMessage, commandError);
                        }
                    }

                    tab.taskCompleted();
                }
                buildItem.markFinished();
                BuildExecutionSupport.registerFinishedItem(buildItem);
            } finally {
                closeAll(initScripts);
            }
        } finally {
            try {
                if (projectConnection != null) {
                    projectConnection.close();
                }
            } finally {
                ExecutedCommandContext commandContext = buildItem.getCommandContext();
                taskDef.getCommandFinalizer().onComplete(commandContext, commandError);
            }
View Full Code Here

        LOGGER.log(Level.INFO, "Loading Gradle project from directory: {0}", projectDir);

        GradleConnector gradleConnector = createGradleConnector(cancelToken, project);
        gradleConnector.forProjectDirectory(projectDir);
        ProjectConnection projectConnection = null;

        NbModelLoader.Result loadedModels;
        try {
            projectConnection = gradleConnector.connect();

            ModelBuilderSetup setup = modelBuilderSetup(project, progress);

            ModelBuilder<BuildEnvironment> modelBuilder = projectConnection.model(BuildEnvironment.class);
            setupLongRunningOP(setup, modelBuilder);

            BuildEnvironment env = modelBuilder.get();
            reportKnownIssues(env);

            GradleTarget gradleTarget = new GradleTarget(
                    setup.getJDKVersion(),
                    GradleVersion.version(env.getGradle().getGradleVersion()));
            NbModelLoader modelLoader = chooseModel(gradleTarget, cachedEntry, setup);

            loadedModels = modelLoader.loadModels(project, projectConnection, progress);
        } finally {
            if (projectConnection != null) {
                projectConnection.close();
            }
        }

        ModelLoadIssueReporter.reportAllIssues(loadedModels.getIssues());
View Full Code Here

        if (connector instanceof DefaultGradleConnector) {
            ((DefaultGradleConnector)connector).daemonMaxIdleTime(60, TimeUnit.SECONDS);
        }

        ProjectConnection connection = connector.connect();
        try {
            task.doTask(connection);
        } finally {
            connection.close();
        }
    }
View Full Code Here

      .find("springloaded").getVersion();

  @Test
  public void defaultJvmArgsArePreservedWhenLoadedAgentIsConfigured()
      throws IOException {
    ProjectConnection project = new ProjectCreator()
        .createProject("spring-loaded-jvm-args");
    project.newBuild()
        .forTasks("bootRun")
        .withArguments("-PbootVersion=" + BOOT_VERSION,
            "-PspringLoadedVersion=" + SPRING_LOADED_VERSION, "--stacktrace")
        .run();
View Full Code Here

        "-javaagent:.*springloaded-" + SPRING_LOADED_VERSION + ".jar", output);
  }

  @Test
  public void springLoadedCanBeUsedWithGradle16() throws IOException {
    ProjectConnection project = new ProjectCreator("1.6")
        .createProject("spring-loaded-old-gradle");
    project.newBuild()
        .forTasks("bootRun")
        .withArguments("-PbootVersion=" + BOOT_VERSION,
            "-PspringLoadedVersion=" + SPRING_LOADED_VERSION, "--stacktrace")
        .run();

View Full Code Here

TOP

Related Classes of org.gradle.tooling.ProjectConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.