Search in sources :

Example 1 with DisposeAwareProjectChange

use of com.intellij.openapi.externalSystem.util.DisposeAwareProjectChange in project intellij-community by JetBrains.

the class JavaProjectDataService method updateSdk.

private static void updateSdk(@NotNull final Project project, @NotNull final JavaSdkVersion version) {
    final Sdk sdk = findJdk(version);
    if (sdk == null)
        return;
    ExternalSystemApiUtil.executeProjectChangeAction(new DisposeAwareProjectChange(project) {

        @Override
        public void execute() {
            ProjectRootManager.getInstance(project).setProjectSdk(sdk);
            LanguageLevel level = version.getMaxLanguageLevel();
            LanguageLevelProjectExtension languageLevelExtension = LanguageLevelProjectExtension.getInstance(project);
            if (level.compareTo(languageLevelExtension.getLanguageLevel()) < 0) {
                languageLevelExtension.setLanguageLevel(level);
            }
        }
    });
}
Also used : DisposeAwareProjectChange(com.intellij.openapi.externalSystem.util.DisposeAwareProjectChange) LanguageLevel(com.intellij.pom.java.LanguageLevel) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) LanguageLevelProjectExtension(com.intellij.openapi.roots.LanguageLevelProjectExtension)

Example 2 with DisposeAwareProjectChange

use of com.intellij.openapi.externalSystem.util.DisposeAwareProjectChange in project intellij-community by JetBrains.

the class JavaProjectDataService method setLanguageLevel.

@SuppressWarnings("MethodMayBeStatic")
public void setLanguageLevel(@NotNull final LanguageLevel languageLevel, @NotNull Project project) {
    final LanguageLevelProjectExtension languageLevelExtension = LanguageLevelProjectExtension.getInstance(project);
    if (languageLevelExtension.getLanguageLevel().isAtLeast(languageLevel)) {
        return;
    }
    ExternalSystemApiUtil.executeProjectChangeAction(new DisposeAwareProjectChange(project) {

        @Override
        public void execute() {
            languageLevelExtension.setLanguageLevel(languageLevel);
        }
    });
}
Also used : DisposeAwareProjectChange(com.intellij.openapi.externalSystem.util.DisposeAwareProjectChange) LanguageLevelProjectExtension(com.intellij.openapi.roots.LanguageLevelProjectExtension)

Example 3 with DisposeAwareProjectChange

use of com.intellij.openapi.externalSystem.util.DisposeAwareProjectChange in project android by JetBrains.

the class PostProjectBuildTasksExecutor method syncJavaLangLevel.

private void syncJavaLangLevel() {
    Boolean updateJavaLangLevel = myProject.getUserData(UPDATE_JAVA_LANG_LEVEL_AFTER_BUILD);
    if (updateJavaLangLevel == null || !updateJavaLangLevel.booleanValue()) {
        return;
    }
    myProject.putUserData(UPDATE_JAVA_LANG_LEVEL_AFTER_BUILD, null);
    executeProjectChangeAction(true, new DisposeAwareProjectChange(myProject) {

        @Override
        public void execute() {
            if (myProject.isOpen()) {
                //noinspection TestOnlyProblems
                LanguageLevel langLevel = getMaxJavaLangLevel();
                if (langLevel != null) {
                    LanguageLevelProjectExtension ext = LanguageLevelProjectExtension.getInstance(myProject);
                    if (langLevel != ext.getLanguageLevel()) {
                        ext.setLanguageLevel(langLevel);
                    }
                }
            }
        }
    });
}
Also used : DisposeAwareProjectChange(com.intellij.openapi.externalSystem.util.DisposeAwareProjectChange) LanguageLevel(com.intellij.pom.java.LanguageLevel) LanguageLevelProjectExtension(com.intellij.openapi.roots.LanguageLevelProjectExtension)

Example 4 with DisposeAwareProjectChange

use of com.intellij.openapi.externalSystem.util.DisposeAwareProjectChange in project android by JetBrains.

the class AndroidGradleBuildProcessParametersProviderTest method testPopulateJvmArgsWithGradleExecutionSettings.

public void testPopulateJvmArgsWithGradleExecutionSettings() {
    executeProjectChangeAction(true, new DisposeAwareProjectChange(myProject) {

        @Override
        public void execute() {
            removeAllKnownJdks();
            String jdkHome = myJdk.getHomePath();
            assertNotNull(jdkHome);
            File jdkHomePath = new File(toSystemDependentName(jdkHome));
            IdeSdks.getInstance().setJdkPath(jdkHomePath);
        }
    });
    GradleExecutionSettings settings = createMock(GradleExecutionSettings.class);
    expect(settings.getGradleHome()).andReturn("~/gradle-1.6");
    expect(settings.isVerboseProcessing()).andReturn(true);
    expect(settings.getServiceDirectory()).andReturn("~./gradle");
    if (!IdeInfo.getInstance().isAndroidStudio()) {
        expect(settings.getVmOptions()).andReturn(Sets.newLinkedHashSet("-Xmx2048m", "-XX:MaxPermSize=512m"));
    }
    replay(settings);
    List<String> jvmArgList = Lists.newArrayList();
    myParametersProvider.populateJvmArgs(settings, jvmArgList);
    Map<String, String> jvmArgs = convertJvmArgsToMap(jvmArgList);
    verify(settings);
    String projectDirPath = Projects.getBaseDirPath(myProject).getPath();
    assertEquals(projectDirPath, jvmArgs.get("-Dcom.android.studio.gradle.project.path"));
    assertEquals("~" + File.separatorChar + "gradle-1.6", jvmArgs.get("-Dcom.android.studio.gradle.home.path"));
    assertEquals("true", jvmArgs.get("-Dcom.android.studio.gradle.use.verbose.logging"));
    assertEquals("~." + File.separatorChar + "gradle", jvmArgs.get("-Dcom.android.studio.gradle.service.dir.path"));
    if (IdeInfo.getInstance().isAndroidStudio()) {
        String javaPath = FileUtilRt.toSystemDependentName(EmbeddedDistributionPaths.getInstance().getEmbeddedJdkPath().getAbsolutePath());
        assertEquals(javaPath, jvmArgs.get("-Dcom.android.studio.gradle.java.home.path"));
    } else {
        assertEquals("-Xmx2048m", jvmArgs.get("-Dcom.android.studio.gradle.daemon.jvm.option.0"));
        assertEquals("-XX:MaxPermSize=512m", jvmArgs.get("-Dcom.android.studio.gradle.daemon.jvm.option.1"));
        String javaHomeDirPath = myJdk.getHomePath();
        assertNotNull(javaHomeDirPath);
        javaHomeDirPath = toSystemDependentName(javaHomeDirPath);
        assertEquals(javaHomeDirPath, jvmArgs.get("-Dcom.android.studio.gradle.java.home.path"));
    }
}
Also used : GradleExecutionSettings(org.jetbrains.plugins.gradle.settings.GradleExecutionSettings) DisposeAwareProjectChange(com.intellij.openapi.externalSystem.util.DisposeAwareProjectChange) File(java.io.File)

Aggregations

DisposeAwareProjectChange (com.intellij.openapi.externalSystem.util.DisposeAwareProjectChange)4 LanguageLevelProjectExtension (com.intellij.openapi.roots.LanguageLevelProjectExtension)3 LanguageLevel (com.intellij.pom.java.LanguageLevel)2 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 File (java.io.File)1 GradleExecutionSettings (org.jetbrains.plugins.gradle.settings.GradleExecutionSettings)1