Search in sources :

Example 6 with DefaultGradleConnector

use of org.gradle.tooling.internal.consumer.DefaultGradleConnector in project spring-boot by spring-projects.

the class GradleIT method test.

private void test(String name, String expected) throws Exception {
    File projectDirectory = new File("target/gradleit/" + name);
    File javaDirectory = new File("target/gradleit/" + name + "/src/main/java/org/test/");
    projectDirectory.mkdirs();
    javaDirectory.mkdirs();
    File script = new File(projectDirectory, "build.gradle");
    FileCopyUtils.copy(new File("src/it/" + name + "/build.gradle"), script);
    FileCopyUtils.copy(new File("src/it/" + name + "/src/main/java/org/test/SampleApplication.java"), new File(javaDirectory, "SampleApplication.java"));
    GradleConnector gradleConnector = GradleConnector.newConnector();
    gradleConnector.useGradleVersion("2.9");
    ((DefaultGradleConnector) gradleConnector).embedded(true);
    ProjectConnection project = gradleConnector.forProjectDirectory(projectDirectory).connect();
    project.newBuild().forTasks("clean", "build").setStandardOutput(System.out).setStandardError(System.err).withArguments("-PbootVersion=" + getBootVersion()).run();
    Verify.verify(new File("target/gradleit/" + name + "/build/libs/" + name + ".jar"), expected);
}
Also used : DefaultGradleConnector(org.gradle.tooling.internal.consumer.DefaultGradleConnector) ProjectConnection(org.gradle.tooling.ProjectConnection) File(java.io.File) DefaultGradleConnector(org.gradle.tooling.internal.consumer.DefaultGradleConnector) GradleConnector(org.gradle.tooling.GradleConnector)

Example 7 with DefaultGradleConnector

use of org.gradle.tooling.internal.consumer.DefaultGradleConnector in project intellij-community by JetBrains.

the class AbstractModelBuilderTest method setUp.

@Before
public void setUp() throws Exception {
    assumeThat(gradleVersion, versionMatcherRule.getMatcher());
    ensureTempDirCreated();
    String methodName = name.getMethodName();
    Matcher m = TEST_METHOD_NAME_PATTERN.matcher(methodName);
    if (m.matches()) {
        methodName = m.group(1);
    }
    testDir = new File(ourTempDir, methodName);
    FileUtil.ensureExists(testDir);
    final InputStream buildScriptStream = getClass().getResourceAsStream("/" + methodName + "/" + GradleConstants.DEFAULT_SCRIPT_NAME);
    try {
        FileUtil.writeToFile(new File(testDir, GradleConstants.DEFAULT_SCRIPT_NAME), FileUtil.loadTextAndClose(buildScriptStream));
    } finally {
        StreamUtil.closeStream(buildScriptStream);
    }
    final InputStream settingsStream = getClass().getResourceAsStream("/" + methodName + "/" + GradleConstants.SETTINGS_FILE_NAME);
    try {
        if (settingsStream != null) {
            FileUtil.writeToFile(new File(testDir, GradleConstants.SETTINGS_FILE_NAME), FileUtil.loadTextAndClose(settingsStream));
        }
    } finally {
        StreamUtil.closeStream(settingsStream);
    }
    GradleConnector connector = GradleConnector.newConnector();
    GradleVersion _gradleVersion = GradleVersion.version(gradleVersion);
    final URI distributionUri = new DistributionLocator().getDistributionFor(_gradleVersion);
    connector.useDistribution(distributionUri);
    connector.forProjectDirectory(testDir);
    int daemonMaxIdleTime = 10;
    try {
        daemonMaxIdleTime = Integer.parseInt(System.getProperty("gradleDaemonMaxIdleTime", "10"));
    } catch (NumberFormatException ignore) {
    }
    ((DefaultGradleConnector) connector).daemonMaxIdleTime(daemonMaxIdleTime, TimeUnit.SECONDS);
    ProjectConnection connection = connector.connect();
    try {
        boolean isGradleProjectDirSupported = _gradleVersion.compareTo(GradleVersion.version("2.4")) >= 0;
        boolean isCompositeBuildsSupported = isGradleProjectDirSupported && _gradleVersion.compareTo(GradleVersion.version("3.1")) >= 0;
        final ProjectImportAction projectImportAction = new ProjectImportAction(false, isGradleProjectDirSupported, isCompositeBuildsSupported);
        projectImportAction.addExtraProjectModelClasses(getModels());
        BuildActionExecuter<ProjectImportAction.AllModels> buildActionExecutor = connection.action(projectImportAction);
        File initScript = GradleExecutionHelper.generateInitScript(false, getToolingExtensionClasses());
        assertNotNull(initScript);
        String jdkHome = IdeaTestUtil.requireRealJdkHome();
        buildActionExecutor.setJavaHome(new File(jdkHome));
        buildActionExecutor.setJvmArguments("-Xmx128m", "-XX:MaxPermSize=64m");
        buildActionExecutor.withArguments("--info", "--recompile-scripts", GradleConstants.INIT_SCRIPT_CMD_OPTION, initScript.getAbsolutePath());
        allModels = buildActionExecutor.run();
        assertNotNull(allModels);
    } finally {
        connection.close();
    }
}
Also used : Matcher(java.util.regex.Matcher) DefaultGradleConnector(org.gradle.tooling.internal.consumer.DefaultGradleConnector) InputStream(java.io.InputStream) ProjectConnection(org.gradle.tooling.ProjectConnection) URI(java.net.URI) ProjectImportAction(org.jetbrains.plugins.gradle.model.ProjectImportAction) GradleConnector(org.gradle.tooling.GradleConnector) DefaultGradleConnector(org.gradle.tooling.internal.consumer.DefaultGradleConnector) GradleVersion(org.gradle.util.GradleVersion) File(java.io.File) Before(org.junit.Before)

Example 8 with DefaultGradleConnector

use of org.gradle.tooling.internal.consumer.DefaultGradleConnector 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)

Aggregations

DefaultGradleConnector (org.gradle.tooling.internal.consumer.DefaultGradleConnector)8 File (java.io.File)7 GradleConnector (org.gradle.tooling.GradleConnector)6 ProjectConnection (org.gradle.tooling.ProjectConnection)4 InputStream (java.io.InputStream)2 URI (java.net.URI)2 Matcher (java.util.regex.Matcher)2 NotNull (org.jetbrains.annotations.NotNull)2 ProjectImportAction (org.jetbrains.plugins.gradle.model.ProjectImportAction)2 Before (org.junit.Before)2 Application (com.intellij.openapi.application.Application)1 ExternalSystemException (com.intellij.openapi.externalSystem.model.ExternalSystemException)1 IOException (java.io.IOException)1 DefaultExecutorServiceFactory (org.gradle.tooling.internal.consumer.DefaultExecutorServiceFactory)1 Distribution (org.gradle.tooling.internal.consumer.Distribution)1 GradleVersion (org.gradle.util.GradleVersion)1 DistributionFactoryExt (org.jetbrains.plugins.gradle.service.project.DistributionFactoryExt)1