Overview | Package | Class | Deprecated | Index | Help
| Groovy Documentation
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | METHOD | DETAIL: FIELD | METHOD

## org.gradle.tooling
[Java] Interface ProjectConnection

    public interface ProjectConnection

Represents a long-lived connection to a Gradle project. You obtain an instance of a `ProjectConnection` by using GradleConnector.connect.

     ProjectConnection connection = GradleConnector.newConnector()
        .forProjectDirectory(new File("someFolder"))
        .connect();

     try {
        //obtain some information from the build
        BuildEnvironment environment = connection.model(BuildEnvironment.class)
          .get();

        //run some tasks
        connection.newBuild()
          .forTasks("tasks")
          .setStandardOutput(System.out)
          .run();

     } finally {
        connection.close();
     }

### Thread safety information

All implementations of `ProjectConnection` are thread-safe, and may be shared by any number of threads.

All notifications from a given `ProjectConnection` instance are delivered by a single thread at a time. Note, however, that the delivery thread may change over time.

Since:
  1.0-milestone-3

Method Summary
`BuildActionExecuter` | `action(BuildAction buildAction)` Creates an executer which can be used to run the given action.
`void` | `close()` Closes this connection.
`Object` | `getModel(Class modelType)` Fetches a snapshot of the model of the given type for this project.
`void` | `getModel(Class modelType, ResultHandler handler)` Starts fetching a snapshot of the given model, passing the result to the given handler when complete.
`ModelBuilder` | `model(Class modelType)` Creates a builder which can be used to build the model of the given type.
`BuildLauncher` | `newBuild()` Creates a launcher which can be used to execute a build.

Method Detail

### action

    @Incubating
    public BuildActionExecuter action(BuildAction buildAction)

  Creates an executer which can be used to run the given action. The action is serialized into the build process and executed, then its result is serialized back to the caller.
  Parameters:
    `buildAction` - The action to run.
    `` - The result type.
  Returns:
    The builder.
  Since:
    1.8

### close

    public void close()

  Closes this connection. Blocks until any pending operations are complete. Once this method has returned, no more notifications will be delivered by any threads.
  Since:
    1.0-milestone-3

### getModel

    public Object getModel(Class modelType)

  Fetches a snapshot of the model of the given type for this project. This method blocks until the model is available.

  This method is simply a convenience for calling `model(modelType).get()`

  throws:
    UnsupportedVersionException When the target Gradle version does not support the given model.
  throws:
    UnknownModelException When the target Gradle version or build does not support the requested model.
  throws:
    BuildException On some failure executing the Gradle build, in order to build the model.
  throws:
    GradleConnectionException On some other failure using the connection.
  throws:
    IllegalStateException When this connection has been closed or is closing.
  Parameters:
    `modelType` - The model type.
    `` - The model type.
  Returns:
    The model.
  Since:
    1.0-milestone-3

### getModel

    public void getModel(Class modelType, ResultHandler handler)

  Starts fetching a snapshot of the given model, passing the result to the given handler when complete. This method returns immediately, and the result is later passed to the given handler's ResultHandler#onComplete(Object)#onComplete(Object) method.

  If the operation fails, the handler's ResultHandler#onFailure(GradleConnectionException)#onFailure(GradleConnectionException) method is called with the appropriate exception. See getModel(Class) for a description of the various exceptions that the operation may fail with.

  This method is simply a convenience for calling `model(modelType).get(handler)`

  throws:
    IllegalStateException When this connection has been closed or is closing.
  Parameters:
    `modelType` - The model type.
    `handler` - The handler to pass the result to.
    `` - The model type.
  Since:
    1.0-milestone-3

### model

    public ModelBuilder model(Class modelType)

  Creates a builder which can be used to build the model of the given type.

  Any of following models types may be available, depending on the version of Gradle being used by the target build:

  - GradleBuild
  - BuildEnvironment
  - GradleProject
  - IdeaProject
  - BasicIdeaProject
  - EclipseProject
  - HierarchicalEclipseProject

  A build may also expose additional custom tooling models.

  Parameters:
    `modelType` - The model type
    `` - The model type.
  Returns:
    The builder.
  Since:
    1.0-milestone-3

### newBuild

    public BuildLauncher newBuild()

  Creates a launcher which can be used to execute a build.
  Returns:
    The launcher.
  Since:
    1.0-milestone-3

Gradle API 1.10