Search in sources :

Example 21 with ProjectJdkTable

use of com.intellij.openapi.projectRoots.ProjectJdkTable in project moe-ide-integration by multi-os-engine.

the class MOESdkType method getMOESdk.

public static Sdk getMOESdk(Module module) {
    if (module == null) {
        return null;
    }
    String modulePath = ModuleUtils.getModulePath(module);
    if (modulePath == null) {
        return null;
    }
    final Properties properties = ProjectUtil.retrievePropertiesFromGradle(new File(modulePath), ProjectUtil.SDK_PROPERTIES_TASK);
    String moeRootPath = properties.getProperty(ProjectUtil.SDK_PATH_KEY);
    if (moeRootPath == null) {
        return null;
    }
    String name = new File(moeRootPath).getName();
    ProjectJdkTable jdkTable = ProjectJdkTable.getInstance();
    for (Sdk sdk : jdkTable.getAllJdks()) {
        if (sdk != null && sdk.getHomePath() != null && sdk.getHomePath().equals(moeRootPath)) {
            return sdk;
        }
    }
    Sdk jdk = getJDK();
    if (jdk == null) {
        jdk = findValidJdk();
    }
    if (jdk == null) {
        Messages.showMessageDialog(MOEText.get("JDK.Not.Found"), "Error", MOEIcons.MOELogo);
        return null;
    }
    MOESdkType sdkType = new MOESdkType(name, moeRootPath);
    final Sdk sdk = ProjectJdkTable.getInstance().createSdk(sdkType.suggestSdkName(null, null), sdkType);
    sdkType.setupSdkRoots(sdk, jdk);
    ApplicationManager.getApplication().runWriteAction(new Runnable() {

        @Override
        public void run() {
            ProjectJdkTable.getInstance().addJdk(sdk);
        }
    });
    return sdk;
}
Also used : ProjectJdkTable(com.intellij.openapi.projectRoots.ProjectJdkTable) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) Properties(java.util.Properties) SystemProperties(com.intellij.util.SystemProperties) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

ProjectJdkTable (com.intellij.openapi.projectRoots.ProjectJdkTable)21 Sdk (com.intellij.openapi.projectRoots.Sdk)21 Nullable (org.jetbrains.annotations.Nullable)7 ProjectJdkImpl (com.intellij.openapi.projectRoots.impl.ProjectJdkImpl)5 SdkModificator (com.intellij.openapi.projectRoots.SdkModificator)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 FlexSdkType2 (com.intellij.lang.javascript.flex.sdk.FlexSdkType2)3 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)3 BuildConfigurationNature (com.intellij.flex.model.bc.BuildConfigurationNature)2 Disposable (com.intellij.openapi.Disposable)2 File (java.io.File)2 Container (aQute.bnd.build.Container)1 Project (aQute.bnd.build.Project)1 Workspace (aQute.bnd.build.Workspace)1 Attrs (aQute.bnd.header.Attrs)1 Refreshable (aQute.bnd.service.Refreshable)1 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)1 GoSdkType (com.goide.sdk.GoSdkType)1 CompilerConfiguration (com.intellij.compiler.CompilerConfiguration)1 JavacConfiguration (com.intellij.compiler.impl.javaCompiler.javac.JavacConfiguration)1