I got it working by using an embedded daemon. Doing all the wiring required
used of reflection though. The key was to override some functionality in the
creation of the GradleConnector.

Here is the code:

  private static GradleConnector getGradleConnector() {
    ToolingImplementationLoader delegate = new
DefaultToolingImplementationLoader();
    final SynchronizedToolingImplementationLoader loader = new
SynchronizedToolingImplementationLoader(delegate);
    final ProtocolToModelAdapter adapter = new ProtocolToModelAdapter();
    final DefaultExecutorFactory executorFactory = new
DefaultExecutorFactory();
    ConnectionFactory connectionFactory = new ConnectionFactory(loader) {
      @Override
      public ProjectConnection create(Distribution distribution,
ConnectionParameters parameters) {
        try {
          Field field =
DefaultConnectionParameters.class.getDeclaredField("embedded");
          field.setAccessible(true);
          field.set(parameters, Boolean.TRUE);
        } catch (Throwable e) {
          throw new RuntimeException(e);
        }
        SynchronizedLogging synchronizedLogging = new SynchronizedLogging();
        ConsumerConnection lazyConnection = new LazyConnection(distribution,
loader, synchronizedLogging, parameters.getVerboseLogging());
        ConsumerConnection progressLoggingConnection = new
ProgressLoggingConnection(lazyConnection, synchronizedLogging);
        final ConsumerConnection initializingConnection = new
LoggingInitializerConnection(progressLoggingConnection,
synchronizedLogging);
        AsyncConnection asyncConnection = new
DefaultAsyncConnection(initializingConnection, executorFactory) {
          @Override
          public <T> void run(Class<T> type, ConsumerOperationParameters
operationParameters, ResultHandlerVersion1<? super T> handler) throws
UnsupportedOperationException, IllegalStateException {
            System.out.println(operationParameters.isEmbedded());
            super.run(type, operationParameters, handler);
            // initializingConnection.run(type, operationParameters);
          }
        };
        try {
          Class<?> type =
Class.forName("org.gradle.tooling.internal.consumer.DefaultProjectConnection");
          Constructor<?> constructor =
              type.getConstructor(AsyncConnection.class,
ProtocolToModelAdapter.class, ConnectionParameters.class);
          constructor.setAccessible(true);
          return (ProjectConnection)
constructor.newInstance(asyncConnection, adapter, parameters);
        } catch (Throwable e) {
          throw new RuntimeException(e);
        }
      }
    };
    DistributionFactory distributionFactory = new DistributionFactory(new
File("/Users/alruiz"));
    return new DefaultGradleConnector(connectionFactory,
distributionFactory);
  }

Is there a better/easier way to do this?

Thanks,
-Alex



--
View this message in context: 
http://gradle.1045684.n5.nabble.com/Debugging-Gradle-daemon-while-using-Tools-API-tp5710965p5710967.html
Sent from the gradle-user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to