Search in sources :

Example 1 with ProjectImportAction

use of org.jetbrains.plugins.gradle.model.ProjectImportAction in project kotlin 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);
    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);
    }
    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();
    URI distributionUri = new DistributionLocator().getDistributionFor(GradleVersion.version(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 {
        ProjectImportAction projectImportAction = new ProjectImportAction(false);
        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) File(java.io.File) Before(org.junit.Before)

Example 2 with ProjectImportAction

use of org.jetbrains.plugins.gradle.model.ProjectImportAction 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)

Aggregations

File (java.io.File)2 InputStream (java.io.InputStream)2 URI (java.net.URI)2 Matcher (java.util.regex.Matcher)2 GradleConnector (org.gradle.tooling.GradleConnector)2 ProjectConnection (org.gradle.tooling.ProjectConnection)2 DefaultGradleConnector (org.gradle.tooling.internal.consumer.DefaultGradleConnector)2 ProjectImportAction (org.jetbrains.plugins.gradle.model.ProjectImportAction)2 Before (org.junit.Before)2 GradleVersion (org.gradle.util.GradleVersion)1