Search in sources :

Example 11 with GradleConnector

use of org.gradle.tooling.GradleConnector in project android by JetBrains.

the class AndroidGradleTargetBuilder method getGradleConnector.

@NotNull
private static GradleConnector getGradleConnector(@NotNull BuilderExecutionSettings executionSettings) {
    GradleConnector connector = GradleConnector.newConnector();
    if (connector instanceof DefaultGradleConnector) {
        DefaultGradleConnector defaultConnector = (DefaultGradleConnector) connector;
        if (executionSettings.isEmbeddedModeEnabled()) {
            LOG.info("Using Gradle embedded mode.");
            defaultConnector.embedded(true);
        }
        defaultConnector.setVerboseLogging(executionSettings.isVerboseLoggingEnabled());
    }
    connector.forProjectDirectory(executionSettings.getProjectDir());
    File gradleHomeDir = executionSettings.getGradleHomeDir();
    if (gradleHomeDir != null) {
        connector.useInstallation(gradleHomeDir);
    }
    File gradleServiceDir = executionSettings.getGradleServiceDir();
    if (gradleServiceDir != null) {
        connector.useGradleUserHomeDir(gradleServiceDir);
    }
    return connector;
}
Also used : DefaultGradleConnector(org.gradle.tooling.internal.consumer.DefaultGradleConnector) File(java.io.File) GradleConnector(org.gradle.tooling.GradleConnector) DefaultGradleConnector(org.gradle.tooling.internal.consumer.DefaultGradleConnector) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with GradleConnector

use of org.gradle.tooling.GradleConnector in project android by JetBrains.

the class ExportSignedPackageTest method getAndroidProject.

/**
   * Returns the {@link com.android.builder.model.AndroidProject} given the gradle project root.
   * Note that this works only single module projects (only one build.gradle)
   */
@Nullable
private static AndroidProject getAndroidProject(String projectPath) {
    File androidPlugin = new File(AndroidTestBase.getAndroidPluginHome());
    File projectDir = new File(androidPlugin, BASE_PATH + projectPath);
    GradleConnector connector = GradleConnector.newConnector();
    connector.forProjectDirectory(projectDir);
    connector.useDistribution(new DistributionLocator().getDistributionFor(GradleVersion.version("2.2.1")));
    AndroidProject model = null;
    ProjectConnection connection = connector.connect();
    try {
        model = connection.getModel(AndroidProject.class);
    } finally {
        connection.close();
    }
    return model;
}
Also used : DistributionLocator(org.gradle.util.DistributionLocator) ProjectConnection(org.gradle.tooling.ProjectConnection) AndroidProject(com.android.builder.model.AndroidProject) File(java.io.File) GradleConnector(org.gradle.tooling.GradleConnector) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GradleConnector (org.gradle.tooling.GradleConnector)12 File (java.io.File)9 ProjectConnection (org.gradle.tooling.ProjectConnection)9 DefaultGradleConnector (org.gradle.tooling.internal.consumer.DefaultGradleConnector)8 BuildLauncher (org.gradle.tooling.BuildLauncher)3 GradleVersion (org.gradle.util.GradleVersion)3 InputStream (java.io.InputStream)2 URI (java.net.URI)2 Matcher (java.util.regex.Matcher)2 BuildException (org.gradle.tooling.BuildException)2 ProjectImportAction (org.jetbrains.plugins.gradle.model.ProjectImportAction)2 Before (org.junit.Before)2 AndroidProject (com.android.builder.model.AndroidProject)1 BuildMode (com.android.tools.idea.gradle.util.BuildMode)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 TeeOutputStream (org.apache.commons.io.output.TeeOutputStream)1 StreamByteBuffer (org.gradle.internal.io.StreamByteBuffer)1