org.gradle.tooling.BuildCancelledException Java Examples

The following examples show how to use org.gradle.tooling.BuildCancelledException. 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: ResultHandlerAdapter.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void onFailure(Throwable failure) {
    if (failure instanceof InternalUnsupportedBuildArgumentException) {
        handler.onFailure(new UnsupportedBuildArgumentException(connectionFailureMessage(failure)
                + "\n" + failure.getMessage(), failure));
    } else if (failure instanceof UnsupportedOperationConfigurationException) {
        handler.onFailure(new UnsupportedOperationConfigurationException(connectionFailureMessage(failure)
                + "\n" + failure.getMessage(), failure.getCause()));
    } else if (failure instanceof GradleConnectionException) {
        handler.onFailure((GradleConnectionException) failure);
    } else if (failure instanceof InternalBuildCancelledException) {
        handler.onFailure(new BuildCancelledException(connectionFailureMessage(failure), failure.getCause()));
    } else if (failure instanceof BuildExceptionVersion1) {
        handler.onFailure(new BuildException(connectionFailureMessage(failure), failure.getCause()));
    } else {
        handler.onFailure(new GradleConnectionException(connectionFailureMessage(failure), failure));
    }
}
 
Example #2
Source File: ResultHandlerAdapter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void onFailure(Throwable failure) {
    if (failure instanceof InternalUnsupportedBuildArgumentException) {
        handler.onFailure(new UnsupportedBuildArgumentException(connectionFailureMessage(failure)
                + "\n" + failure.getMessage(), failure));
    } else if (failure instanceof UnsupportedOperationConfigurationException) {
        handler.onFailure(new UnsupportedOperationConfigurationException(connectionFailureMessage(failure)
                + "\n" + failure.getMessage(), failure.getCause()));
    } else if (failure instanceof GradleConnectionException) {
        handler.onFailure((GradleConnectionException) failure);
    } else if (failure instanceof InternalBuildCancelledException) {
        handler.onFailure(new BuildCancelledException(connectionFailureMessage(failure), failure.getCause()));
    } else if (failure instanceof BuildExceptionVersion1) {
        handler.onFailure(new BuildException(connectionFailureMessage(failure), failure.getCause()));
    } else {
        handler.onFailure(new GradleConnectionException(connectionFailureMessage(failure), failure));
    }
}
 
Example #3
Source File: LazyConsumerActionExecutor.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <T> T run(ConsumerAction<T> action) throws UnsupportedOperationException, IllegalStateException {
    try {
        BuildCancellationToken cancellationToken = action.getParameters().getCancellationToken();
        if (cancellationToken.isCancellationRequested()) {
            throw new BuildCancelledException("Build cancelled");
        }
        ConsumerConnection connection = onStartAction(cancellationToken);
        return action.run(connection);
    } finally {
        onEndAction();
    }
}
 
Example #4
Source File: LazyConsumerActionExecutor.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <T> T run(ConsumerAction<T> action) throws UnsupportedOperationException, IllegalStateException {
    try {
        BuildCancellationToken cancellationToken = action.getParameters().getCancellationToken();
        if (cancellationToken.isCancellationRequested()) {
            throw new BuildCancelledException("Build cancelled");
        }
        ConsumerConnection connection = onStartAction(cancellationToken);
        return action.run(connection);
    } finally {
        onEndAction();
    }
}
 
Example #5
Source File: ExecuteGoal.java    From NBANDROID-V2 with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
    cancellation.set(false);
    cancellationReference.set(new DefaultBuildCancellationToken());
    GradleConnector connector = GradleConnector.newConnector();
    connector.useInstallation(gradleHome);
    connector.forProjectDirectory(FileUtil.toFile(project.getProjectDirectory()));
    try (ProjectConnection connection = connector.connect()) {
        BuildLauncher buildLauncher = connection.newBuild();
        buildLauncher.forTasks(taskInfo.getName());
        buildLauncher.withCancellationToken(this);
        ProjectConfigurationProvider pcp = project.getLookup().lookup(ProjectConfigurationProvider.class);
        if (pcp != null && pcp.getActiveConfiguration() != null) {
            buildLauncher.addArguments("-Pandroid.profile=" + pcp.getActiveConfiguration());
        }
        if (argsConfiguration != null) {
            buildLauncher.addArguments(argsConfiguration.getJvmArguments());
        }
        if (jvmConfiguration == null) {
            buildLauncher.addJvmArguments("-Xms800m", "-Xmx2000m");
        } else {
            buildLauncher.addJvmArguments(jvmConfiguration.getJvmArguments());
        }
        InputOutput io = project.getLookup().lookup(InputOutput.class);
        if (io != null) {
            io.show(ImmutableSet.of(ShowOperation.OPEN, ShowOperation.MAKE_VISIBLE));
            io.getOut().print("\n\r");
            io.getOut().print("\n\r");
            io.getOut().print("\n\r");
            io.getOut().print("\n\r");
            io.getOut().println(BLUE + "Executing task: " + taskInfo.getName() + BLACK);
            io.getOut().print("\n\r");
            io.getOut().print("\n\r");
            CustomWriterOutputStream cwos = new CustomWriterOutputStream(io.getOut(), "UTF-8");
            buildLauncher.setStandardOutput(cwos);
            buildLauncher.setStandardError(cwos);
            buildLauncher.setColorOutput(true);
        }
        final ProgressHandle progressHandle = ProgressHandleFactory.createSystemHandle(project.getProjectDirectory().getName() + " : " + taskInfo.getDescription(), this);
        progressHandle.start();
        buildLauncher.addProgressListener(new ProgressListener() {
            @Override
            public void statusChanged(ProgressEvent event) {
                progressHandle.progress(event.getDisplayName());
            }
        });
        try {
            buildLauncher.run();
        } catch (GradleConnectionException | IllegalStateException gradleConnectionException) {
            if (!(gradleConnectionException instanceof BuildCancelledException)) {
                Exceptions.printStackTrace(gradleConnectionException);
            }
        }
        progressHandle.finish();
        ModelRefresh modelRefresh = project.getLookup().lookup(ModelRefresh.class);
        if (modelRefresh != null) {
            modelRefresh.refreshModels();
        }
    } catch (Exception e) {
        Exceptions.printStackTrace(e);
    }
}
 
Example #6
Source File: GradleHandlerImpl.java    From NBANDROID-V2 with Apache License 2.0 4 votes vote down vote up
private void deserializeModels() {
    cancellation.set(false);
    cancellationReference.set(new DefaultBuildCancellationToken());
    GradleHome gradleHome = lookupResult.allInstances().iterator().next();
    if (gradleHome.getStatus() == GradleDownloader.Status.OK) {
        synchronized (gradleLocations) {
            gradleLocations.put(project, gradleHome);
        }
        //      modelContent.set(Collections.emptyList(), null);
        GradleConnector connector = GradleConnector.newConnector();
        connector.useInstallation(gradleHome.getGradleHome());
        connector.forProjectDirectory(FileUtil.toFile(project.getProjectDirectory()));
        try (ProjectConnection connection = connector.connect()) {
            List<Object> modelList = new ArrayList<>();
            for (Class model : models) {
                ModelBuilder modelBuilder = connection.model(model);
                modelBuilder.withCancellationToken(this);
                //Emulate Android studio
                modelBuilder.addArguments("-Pandroid.injected.build.model.only.versioned=3");
                //Prepare load of plugin to retreive tasks from Gradle
                modelBuilder.addJvmArguments("-DANDROID_TOOLING_JAR=" + TOOLING_JAR);
                modelBuilder.addArguments("-I");
                modelBuilder.addArguments(INIT_SCRIPT);
                if (argsConfiguration != null) {
                    modelBuilder.addArguments(argsConfiguration.getJvmArguments());
                }
                if (jvmConfiguration == null) {
                    modelBuilder.addJvmArguments("-Xms800m", "-Xmx2000m");
                } else {
                    modelBuilder.addJvmArguments(jvmConfiguration.getJvmArguments());
                }
                InputOutput io = project.getLookup().lookup(InputOutput.class);
                if (io != null) {
                    io.show(ImmutableSet.of(ShowOperation.OPEN, ShowOperation.MAKE_VISIBLE));
                    io.getOut().print("\n\r");
                    io.getOut().print("\n\r");
                    io.getOut().print("\n\r");
                    io.getOut().print("\n\r");
                    io.getOut().println(BLUE + "Deserializing model: " + model.getSimpleName() + BLACK);
                    io.getOut().print("\n\r");
                    io.getOut().print("\n\r");
                    CustomWriterOutputStream cwos = new CustomWriterOutputStream(io.getOut(), "UTF-8");
                    modelBuilder.setStandardOutput(cwos);
                    modelBuilder.setStandardError(cwos);
                    modelBuilder.setColorOutput(true);
                }
                final ProgressHandle progressHandle = ProgressHandleFactory.createSystemHandle(project.getProjectDirectory().getName() + ": Loading Gradle model..", this);
                progressHandle.start();
                modelBuilder.addProgressListener(new ProgressListener() {
                    @Override
                    public void statusChanged(ProgressEvent event) {
                        progressHandle.progress(event.getDisplayName());
                    }
                });
                try {
                    modelList.add(modelBuilder.get());
                } catch (GradleConnectionException | IllegalStateException gradleConnectionException) {
                    if (!(gradleConnectionException instanceof BuildCancelledException)) {
                        Exceptions.printStackTrace(gradleConnectionException);
                    }
                }
                progressHandle.finish();
            }
            modelContent.set(modelList, null);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}