org.gradle.tooling.GradleConnectionException Java Examples
The following examples show how to use
org.gradle.tooling.GradleConnectionException.
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 |
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 |
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: GradleConnector.java From MSPaintIDE with MIT License | 6 votes |
public void runTask(OutputStream out, OutputStream err, String... tasks) { LOGGER.info("Running task(s) {}", String.join(" ", tasks)); try (ProjectConnection connection = connector.connect()) { connection.newBuild().setStandardOutput(out).setStandardError(err).forTasks(tasks).run(new ResultHandler<>() { @Override public void onComplete(Void result) { LOGGER.info("Finished {}", String.join(" ", tasks)); } @Override public void onFailure(GradleConnectionException failure) { LOGGER.error("Failed to execute " + String.join(" ", tasks), failure.fillInStackTrace()); } }); } }
Example #4
Source File: GradleDaemon.java From netbeans with Apache License 2.0 | 6 votes |
private static void doLoadDaemon() { GradleConnector gconn = GradleConnector.newConnector(); ProjectConnection pconn = gconn.forProjectDirectory(LOADER_PROJECT_DIR).connect(); BuildActionExecuter<String> action = pconn.action(DUMMY_ACTION); GradleCommandLine cmd = new GradleCommandLine(); cmd.addSystemProperty(PROP_TOOLING_JAR, TOOLING_JAR); cmd.setFlag(GradleCommandLine.Flag.OFFLINE, true); cmd.addParameter(GradleCommandLine.Parameter.INIT_SCRIPT, INIT_SCRIPT); cmd.configure(action); try { action.run(); } catch (GradleConnectionException | IllegalStateException ex) { // Well for some reason we were not able to load Gradle. // Ignoring that for now } finally { pconn.close(); } }
Example #5
Source File: BuildLauncherBackedGradleHandle.java From paraphrase with Apache License 2.0 | 5 votes |
public BuildLauncherBackedGradleHandle(BuildLauncher launcher) { launcher.setStandardOutput(standardOutput); launcher.setStandardError(standardError); launcher.run(new ResultHandler<Void>() { public void onComplete(Void result) { finish(); } public void onFailure(GradleConnectionException failure) { exception = failure; finish(); } }); }
Example #6
Source File: DefaultGradleConnector.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public ProjectConnection connect() throws GradleConnectionException { LOGGER.debug("Connecting from tooling API consumer version {}", GradleVersion.current().getVersion()); ConnectionParameters connectionParameters = connectionParamsBuilder.build(); if (connectionParameters.getProjectDir() == null) { throw new IllegalStateException("A project directory must be specified before creating a connection."); } if (distribution == null) { distribution = distributionFactory.getDefaultDistribution(connectionParameters.getProjectDir(), connectionParameters.isSearchUpwards() != null ? connectionParameters.isSearchUpwards() : true); } return connectionFactory.create(distribution, connectionParameters); }
Example #7
Source File: DefaultToolingImplementationLoader.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public ConsumerConnection create(Distribution distribution, ProgressLoggerFactory progressLoggerFactory, ConnectionParameters connectionParameters) { LOGGER.debug("Using tooling provider from {}", distribution.getDisplayName()); ClassLoader classLoader = createImplementationClassLoader(distribution, progressLoggerFactory, connectionParameters.getGradleUserHomeDir()); ServiceLocator serviceLocator = new ServiceLocator(classLoader); try { Factory<ConnectionVersion4> factory = serviceLocator.findFactory(ConnectionVersion4.class); if (factory == null) { return new NoToolingApiConnection(distribution); } // ConnectionVersion4 is a part of the protocol and cannot be easily changed. ConnectionVersion4 connection = factory.create(); ProtocolToModelAdapter adapter = new ProtocolToModelAdapter(new ConsumerTargetTypeProvider()); ModelMapping modelMapping = new ModelMapping(); // Adopting the connection to a refactoring friendly type that the consumer owns AbstractConsumerConnection adaptedConnection; if (connection instanceof ModelBuilder && connection instanceof InternalBuildActionExecutor) { adaptedConnection = new ActionAwareConsumerConnection(connection, modelMapping, adapter); } else if (connection instanceof ModelBuilder) { adaptedConnection = new ModelBuilderBackedConsumerConnection(connection, modelMapping, adapter); } else if (connection instanceof BuildActionRunner) { adaptedConnection = new BuildActionRunnerBackedConsumerConnection(connection, modelMapping, adapter); } else if (connection instanceof InternalConnection) { adaptedConnection = new InternalConnectionBackedConsumerConnection(connection, modelMapping, adapter); } else { adaptedConnection = new ConnectionVersion4BackedConsumerConnection(connection, modelMapping, adapter); } adaptedConnection.configure(connectionParameters); return adaptedConnection; } catch (UnsupportedVersionException e) { throw e; } catch (Throwable t) { throw new GradleConnectionException(String.format("Could not create an instance of Tooling API implementation using the specified %s.", distribution.getDisplayName()), t); } }
Example #8
Source File: ResultHandlerAdapter.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
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 BuildExceptionVersion1) { handler.onFailure(new BuildException(connectionFailureMessage(failure), failure.getCause())); } else { handler.onFailure(new GradleConnectionException(connectionFailureMessage(failure), failure)); } }
Example #9
Source File: DefaultGradleConnector.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public ProjectConnection connect() throws GradleConnectionException { LOGGER.debug("Connecting from tooling API consumer version {}", GradleVersion.current().getVersion()); ConnectionParameters connectionParameters = connectionParamsBuilder.build(); if (connectionParameters.getProjectDir() == null) { throw new IllegalStateException("A project directory must be specified before creating a connection."); } if (distribution == null) { distribution = distributionFactory.getDefaultDistribution(connectionParameters.getProjectDir(), connectionParameters.isSearchUpwards() != null ? connectionParameters.isSearchUpwards() : true); } return connectionFactory.create(distribution, connectionParameters); }
Example #10
Source File: GradleDependencyAdapter.java From thorntail with Apache License 2.0 | 5 votes |
/** * Attempt to load the {@link ThorntailConfiguration} and retrieve the dependencies. * * @param connection the Gradle project connection. * @return the declared dependencies for the current project. */ private DeclaredDependencies getDependenciesViaThorntailModel(ProjectConnection connection) { DeclaredDependencies declaredDependencies = null; try { ThorntailConfiguration config = connection.getModel(ThorntailConfiguration.class); if (config != null) { declaredDependencies = GradleToolingHelper.toDeclaredDependencies(config.getTestDependencies()); } } catch (GradleConnectionException | IllegalStateException e) { e.printStackTrace(); } return declaredDependencies; }
Example #11
Source File: GradleProject.java From meghanada-server with GNU General Public License v3.0 | 5 votes |
@Override public void onFailure(final GradleConnectionException failure) { try { log.catching(failure.getCause()); outputStream.close(); inputStream.close(); } catch (IOException e) { log.error(e.getMessage(), e); } finally { projectConnection.close(); } }
Example #12
Source File: TemplateOperation.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Set<FileObject> execute() { GradleConnector gconn = GradleConnector.newConnector(); ProjectConnection pconn = gconn.forProjectDirectory(projectDir).connect(); try { pconn.newBuild().withArguments("--offline").forTasks("wrapper").run(); //NOI18N } catch (GradleConnectionException | IllegalStateException ex) { // Well for some reason we were not able to load Gradle. // Ignoring that for now } finally { pconn.close(); } return null; }
Example #13
Source File: DefaultGradleConnector.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public ProjectConnection connect() throws GradleConnectionException { LOGGER.debug("Connecting from tooling API consumer version {}", GradleVersion.current().getVersion()); ConnectionParameters connectionParameters = connectionParamsBuilder.build(); if (connectionParameters.getProjectDir() == null) { throw new IllegalStateException("A project directory must be specified before creating a connection."); } if (distribution == null) { distribution = distributionFactory.getDefaultDistribution(connectionParameters.getProjectDir(), connectionParameters.isSearchUpwards() != null ? connectionParameters.isSearchUpwards() : true); } return connectionFactory.create(distribution, connectionParameters); }
Example #14
Source File: DefaultToolingImplementationLoader.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public ConsumerConnection create(Distribution distribution, ProgressLoggerFactory progressLoggerFactory, ConnectionParameters connectionParameters) { LOGGER.debug("Using tooling provider from {}", distribution.getDisplayName()); ClassLoader classLoader = createImplementationClassLoader(distribution, progressLoggerFactory, connectionParameters.getGradleUserHomeDir()); ServiceLocator serviceLocator = new ServiceLocator(classLoader); try { Factory<ConnectionVersion4> factory = serviceLocator.findFactory(ConnectionVersion4.class); if (factory == null) { return new NoToolingApiConnection(distribution); } // ConnectionVersion4 is a part of the protocol and cannot be easily changed. ConnectionVersion4 connection = factory.create(); ProtocolToModelAdapter adapter = new ProtocolToModelAdapter(new ConsumerTargetTypeProvider()); ModelMapping modelMapping = new ModelMapping(); // Adopting the connection to a refactoring friendly type that the consumer owns AbstractConsumerConnection adaptedConnection; if (connection instanceof ModelBuilder && connection instanceof InternalBuildActionExecutor) { adaptedConnection = new ActionAwareConsumerConnection(connection, modelMapping, adapter); } else if (connection instanceof ModelBuilder) { adaptedConnection = new ModelBuilderBackedConsumerConnection(connection, modelMapping, adapter); } else if (connection instanceof BuildActionRunner) { adaptedConnection = new BuildActionRunnerBackedConsumerConnection(connection, modelMapping, adapter); } else if (connection instanceof InternalConnection) { adaptedConnection = new InternalConnectionBackedConsumerConnection(connection, modelMapping, adapter); } else { adaptedConnection = new ConnectionVersion4BackedConsumerConnection(connection, modelMapping, adapter); } adaptedConnection.configure(connectionParameters); return adaptedConnection; } catch (UnsupportedVersionException e) { throw e; } catch (Throwable t) { throw new GradleConnectionException(String.format("Could not create an instance of Tooling API implementation using the specified %s.", distribution.getDisplayName()), t); } }
Example #15
Source File: ResultHandlerAdapter.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
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 BuildExceptionVersion1) { handler.onFailure(new BuildException(connectionFailureMessage(failure), failure.getCause())); } else { handler.onFailure(new GradleConnectionException(connectionFailureMessage(failure), failure)); } }
Example #16
Source File: DefaultGradleConnector.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public ProjectConnection connect() throws GradleConnectionException { LOGGER.debug("Connecting from tooling API consumer version {}", GradleVersion.current().getVersion()); ConnectionParameters connectionParameters = connectionParamsBuilder.build(); if (connectionParameters.getProjectDir() == null) { throw new IllegalStateException("A project directory must be specified before creating a connection."); } if (distribution == null) { distribution = distributionFactory.getDefaultDistribution(connectionParameters.getProjectDir(), connectionParameters.isSearchUpwards() != null ? connectionParameters.isSearchUpwards() : true); } return connectionFactory.create(distribution, connectionParameters); }
Example #17
Source File: DefaultModelBuilder.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
public T get() throws GradleConnectionException { BlockingResultHandler<T> handler = new BlockingResultHandler<T>(modelType); get(handler); return handler.getResult(); }
Example #18
Source File: BlockingResultHandler.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
public void onFailure(GradleConnectionException failure) { queue.add(failure); }
Example #19
Source File: DefaultModelBuilder.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
public T get() throws GradleConnectionException { BlockingResultHandler<T> handler = new BlockingResultHandler<T>(modelType); get(handler); return handler.getResult(); }
Example #20
Source File: DefaultToolingImplementationLoader.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
public ConsumerConnection create(Distribution distribution, ProgressLoggerFactory progressLoggerFactory, ConnectionParameters connectionParameters, BuildCancellationToken cancellationToken) { LOGGER.debug("Using tooling provider from {}", distribution.getDisplayName()); ClassLoader classLoader = createImplementationClassLoader(distribution, progressLoggerFactory, connectionParameters.getGradleUserHomeDir(), cancellationToken); ServiceLocator serviceLocator = new ServiceLocator(classLoader); try { Factory<ConnectionVersion4> factory = serviceLocator.findFactory(ConnectionVersion4.class); if (factory == null) { return new NoToolingApiConnection(distribution); } // ConnectionVersion4 is a part of the protocol and cannot be easily changed. ConnectionVersion4 connection = factory.create(); ProtocolToModelAdapter adapter = new ProtocolToModelAdapter(new ConsumerTargetTypeProvider()); ModelMapping modelMapping = new ModelMapping(); // Adopting the connection to a refactoring friendly type that the consumer owns AbstractConsumerConnection adaptedConnection; if (connection instanceof StoppableConnection) { adaptedConnection = new ShutdownAwareConsumerConnection(connection, modelMapping, adapter); } else if (connection instanceof InternalCancellableConnection) { adaptedConnection = new CancellableConsumerConnection(connection, modelMapping, adapter); } else if (connection instanceof ModelBuilder && connection instanceof InternalBuildActionExecutor) { adaptedConnection = new ActionAwareConsumerConnection(connection, modelMapping, adapter); } else if (connection instanceof ModelBuilder) { adaptedConnection = new ModelBuilderBackedConsumerConnection(connection, modelMapping, adapter); } else if (connection instanceof BuildActionRunner) { adaptedConnection = new BuildActionRunnerBackedConsumerConnection(connection, modelMapping, adapter); } else if (connection instanceof InternalConnection) { adaptedConnection = new InternalConnectionBackedConsumerConnection(connection, modelMapping, adapter); } else { return new ConnectionVersion4BackedConsumerConnection(distribution, connection, adapter); } adaptedConnection.configure(connectionParameters); if (!adaptedConnection.getVersionDetails().supportsCancellation()) { return new NonCancellableConsumerConnectionAdapter(adaptedConnection); } return adaptedConnection; } catch (UnsupportedVersionException e) { throw e; } catch (Throwable t) { throw new GradleConnectionException(String.format("Could not create an instance of Tooling API implementation using the specified %s.", distribution.getDisplayName()), t); } }
Example #21
Source File: BlockingResultHandler.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
public void onFailure(GradleConnectionException failure) { queue.add(failure); }
Example #22
Source File: DefaultBuildActionExecuter.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
public T run() throws GradleConnectionException { BlockingResultHandler<Object> handler = new BlockingResultHandler<Object>(Object.class); run(handler); return (T) handler.getResult(); }
Example #23
Source File: DefaultModelBuilder.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
public T get() throws GradleConnectionException { BlockingResultHandler<T> handler = new BlockingResultHandler<T>(modelType); get(handler); return handler.getResult(); }
Example #24
Source File: DefaultBuildActionExecuter.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
public T run() throws GradleConnectionException { BlockingResultHandler<Object> handler = new BlockingResultHandler<Object>(Object.class); run(handler); return (T) handler.getResult(); }
Example #25
Source File: DefaultModelBuilder.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
public T get() throws GradleConnectionException { BlockingResultHandler<T> handler = new BlockingResultHandler<T>(modelType); get(handler); return handler.getResult(); }
Example #26
Source File: DefaultToolingImplementationLoader.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
public ConsumerConnection create(Distribution distribution, ProgressLoggerFactory progressLoggerFactory, ConnectionParameters connectionParameters, BuildCancellationToken cancellationToken) { LOGGER.debug("Using tooling provider from {}", distribution.getDisplayName()); ClassLoader classLoader = createImplementationClassLoader(distribution, progressLoggerFactory, connectionParameters.getGradleUserHomeDir(), cancellationToken); ServiceLocator serviceLocator = new ServiceLocator(classLoader); try { Factory<ConnectionVersion4> factory = serviceLocator.findFactory(ConnectionVersion4.class); if (factory == null) { return new NoToolingApiConnection(distribution); } // ConnectionVersion4 is a part of the protocol and cannot be easily changed. ConnectionVersion4 connection = factory.create(); ProtocolToModelAdapter adapter = new ProtocolToModelAdapter(new ConsumerTargetTypeProvider()); ModelMapping modelMapping = new ModelMapping(); // Adopting the connection to a refactoring friendly type that the consumer owns AbstractConsumerConnection adaptedConnection; if (connection instanceof StoppableConnection) { adaptedConnection = new ShutdownAwareConsumerConnection(connection, modelMapping, adapter); } else if (connection instanceof InternalCancellableConnection) { adaptedConnection = new CancellableConsumerConnection(connection, modelMapping, adapter); } else if (connection instanceof ModelBuilder && connection instanceof InternalBuildActionExecutor) { adaptedConnection = new ActionAwareConsumerConnection(connection, modelMapping, adapter); } else if (connection instanceof ModelBuilder) { adaptedConnection = new ModelBuilderBackedConsumerConnection(connection, modelMapping, adapter); } else if (connection instanceof BuildActionRunner) { adaptedConnection = new BuildActionRunnerBackedConsumerConnection(connection, modelMapping, adapter); } else if (connection instanceof InternalConnection) { adaptedConnection = new InternalConnectionBackedConsumerConnection(connection, modelMapping, adapter); } else { return new ConnectionVersion4BackedConsumerConnection(distribution, connection, adapter); } adaptedConnection.configure(connectionParameters); if (!adaptedConnection.getVersionDetails().supportsCancellation()) { return new NonCancellableConsumerConnectionAdapter(adaptedConnection); } return adaptedConnection; } catch (UnsupportedVersionException e) { throw e; } catch (Throwable t) { throw new GradleConnectionException(String.format("Could not create an instance of Tooling API implementation using the specified %s.", distribution.getDisplayName()), t); } }
Example #27
Source File: BlockingResultHandler.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
public void onFailure(GradleConnectionException failure) { queue.add(failure); }
Example #28
Source File: BlockingResultHandler.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
public void onFailure(GradleConnectionException failure) { queue.add(failure); }
Example #29
Source File: GradleHandlerImpl.java From NBANDROID-V2 with Apache License 2.0 | 4 votes |
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(); } } }
Example #30
Source File: ExecuteGoal.java From NBANDROID-V2 with Apache License 2.0 | 4 votes |
@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); } }