Search in sources :

Example 1 with JavaSdkVersion

use of com.intellij.openapi.projectRoots.JavaSdkVersion in project intellij-community by JetBrains.

the class SceneBuilderImpl method isCompatibleLanguageLevel.

private static boolean isCompatibleLanguageLevel(@NotNull PsiClass aClass, @Nullable LanguageLevel targetLevel) {
    if (targetLevel == null)
        return true;
    final Project project = aClass.getProject();
    final VirtualFile vFile = PsiUtilCore.getVirtualFile(aClass);
    if (vFile == null)
        return true;
    Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(vFile);
    if (module == null) {
        final OrderEntry entry = LibraryUtil.findLibraryEntry(vFile, project);
        if (entry != null) {
            module = entry.getOwnerModule();
        }
    }
    Sdk jdk = module != null ? ModuleRootManager.getInstance(module).getSdk() : null;
    if (jdk == null) {
        jdk = ProjectRootManager.getInstance(project).getProjectSdk();
    }
    if (jdk == null)
        return true;
    final String versionString = jdk.getVersionString();
    if (versionString != null) {
        final JavaSdkVersion jdkVersion = JdkVersionUtil.getVersion(versionString);
        if (jdkVersion != null) {
            return targetLevel.isAtLeast(jdkVersion.getMaxLanguageLevel());
        }
    }
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) JavaSdkVersion(com.intellij.openapi.projectRoots.JavaSdkVersion) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module)

Example 2 with JavaSdkVersion

use of com.intellij.openapi.projectRoots.JavaSdkVersion in project intellij-community by JetBrains.

the class ProjectConfigurable method createUIComponents.

private void createUIComponents() {
    myLanguageLevelCombo = new LanguageLevelCombo(JavaCoreBundle.message("default.language.level.description")) {

        @Override
        protected LanguageLevel getDefaultLevel() {
            Sdk sdk = myProjectJdkConfigurable.getSelectedProjectJdk();
            if (sdk == null)
                return null;
            JavaSdkVersion version = JavaSdk.getInstance().getVersion(sdk);
            return version == null ? null : version.getMaxLanguageLevel();
        }
    };
    final JTextField textField = new JTextField();
    final FileChooserDescriptor outputPathsChooserDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    InsertPathAction.addTo(textField, outputPathsChooserDescriptor);
    outputPathsChooserDescriptor.setHideIgnored(false);
    BrowseFilesListener listener = new BrowseFilesListener(textField, "", ProjectBundle.message("project.compiler.output"), outputPathsChooserDescriptor);
    myProjectCompilerOutput = new FieldPanel(textField, null, null, listener, EmptyRunnable.getInstance());
    FileChooserFactory.getInstance().installFileCompletion(myProjectCompilerOutput.getTextField(), outputPathsChooserDescriptor, true, null);
}
Also used : JavaSdkVersion(com.intellij.openapi.projectRoots.JavaSdkVersion) BrowseFilesListener(com.intellij.ide.util.BrowseFilesListener) LanguageLevel(com.intellij.pom.java.LanguageLevel) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) FieldPanel(com.intellij.ui.FieldPanel)

Example 3 with JavaSdkVersion

use of com.intellij.openapi.projectRoots.JavaSdkVersion in project android by JetBrains.

the class FormFactorApiComboBox method deriveValues.

/**
   * Fill in the values that can be derived from the selected min SDK level:
   *
   * minApiLevel will be set to the selected api level (string or number)
   * minApi will be set to the numerical equivalent
   * buildApi will be set to the highest installed platform, or to the preview platform if a preview is selected
   * buildApiString will be set to the corresponding string
   * targetApi will be set to the highest installed platform or to the preview platform if a preview is selected
   * targetApiString will be set to the corresponding string
   *
   * @param stateStore
   * @param modified
   */
public void deriveValues(@NotNull ScopedStateStore stateStore, @NotNull Set<Key> modified) {
    if (modified.contains(myTargetComboBoxKey) || modified.contains(myInclusionKey)) {
        // First remove the last request, no need to install more than one platform
        if (!myInstallRequests.isEmpty()) {
            for (String request : myInstallRequests) {
                stateStore.listRemove(INSTALL_REQUESTS_KEY, request);
            }
            myInstallRequests.clear();
        }
        // If this form factor is not included then there is nothing to do:
        AndroidTargetComboBoxItem targetItem = stateStore.get(myTargetComboBoxKey);
        if (targetItem == null || !stateStore.getNotNull(myInclusionKey, false)) {
            return;
        }
        stateStore.put(FormFactorUtils.getMinApiKey(myFormFactor), targetItem.getData());
        stateStore.put(FormFactorUtils.getMinApiLevelKey(myFormFactor), targetItem.myApiLevel);
        IAndroidTarget target = targetItem.target;
        if (target != null && (target.getVersion().isPreview() || !target.isPlatform())) {
            // Make sure we set target and build to the preview version as well
            populateApiLevels(targetItem.myApiLevel, target, stateStore);
        } else {
            int targetApiLevel;
            if (ourHighestInstalledApiTarget != null) {
                targetApiLevel = ourHighestInstalledApiTarget.getVersion().getFeatureLevel();
            } else {
                targetApiLevel = 0;
            }
            populateApiLevels(targetApiLevel, ourHighestInstalledApiTarget, stateStore);
        }
        AndroidVersion androidVersion = targetItem.myAndroidVersion;
        String platformPath = DetailsTypes.getPlatformPath(androidVersion);
        // Update build tools: use preview versions with preview platforms, etc
        BuildToolInfo buildTool = (target == null) ? null : target.getBuildToolInfo();
        if (buildTool == null) {
            final AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
            buildTool = sdkHandler.getLatestBuildTool(new StudioLoggerProgressIndicator(ConfigureAndroidProjectPath.class), false);
        }
        if (buildTool != null) {
            stateStore.put(WizardConstants.BUILD_TOOLS_VERSION_KEY, buildTool.getRevision().toString());
        }
        // Check to see if this is installed. If not, request that we install it
        if (targetItem.myAddon != null) {
            // The user selected a non platform SDK (e.g. for Google Glass). Let us install it:
            String packagePath = targetItem.myAddon.getPath();
            stateStore.listPush(INSTALL_REQUESTS_KEY, packagePath);
            myInstallRequests.add(packagePath);
            // We also need the platform if not already installed:
            AndroidTargetManager targetManager = AndroidSdks.getInstance().tryToChooseSdkHandler().getAndroidTargetManager(REPO_LOG);
            if (targetManager.getTargetFromHashString(AndroidTargetHash.getPlatformHashString(androidVersion), REPO_LOG) == null) {
                stateStore.listPush(INSTALL_REQUESTS_KEY, platformPath);
                myInstallRequests.add(platformPath);
            }
            // The selected minVersion should also be the buildApi:
            populateApiLevels(targetItem.myApiLevel, null, stateStore);
        } else if (target == null) {
            // unlikely, so this logic can wait for a followup CL.
            if (ourHighestInstalledApiTarget == null || (androidVersion.getApiLevel() > ourHighestInstalledApiTarget.getVersion().getApiLevel() && !ourInstalledVersions.contains(androidVersion))) {
                // Let us install the HIGHEST_KNOWN_STABLE_API.
                platformPath = DetailsTypes.getPlatformPath(new AndroidVersion(SdkVersionInfo.HIGHEST_KNOWN_STABLE_API, null));
                stateStore.listPush(INSTALL_REQUESTS_KEY, platformPath);
                myInstallRequests.add(platformPath);
                // HIGHEST_KNOWN_STABLE_API would also be the highest sdkVersion after this install, so specify buildApi again here:
                populateApiLevels(SdkVersionInfo.HIGHEST_KNOWN_STABLE_API, null, stateStore);
            }
        }
        PropertiesComponent.getInstance().setValue(getPropertiesComponentMinSdkKey(myFormFactor), targetItem.getData());
        // Check Java language level; should be 7 for L; eventually this will be automatically defaulted by the Android Gradle plugin
        // instead: https://code.google.com/p/android/issues/detail?id=76252
        String javaVersion = null;
        if (ourHighestInstalledApiTarget != null && ourHighestInstalledApiTarget.getVersion().getFeatureLevel() >= 21) {
            AndroidSdkData sdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
            if (sdkData != null) {
                JavaSdk jdk = JavaSdk.getInstance();
                Sdk sdk = ProjectJdkTable.getInstance().findMostRecentSdkOfType(jdk);
                if (sdk != null) {
                    JavaSdkVersion version = jdk.getVersion(sdk);
                    if (version != null && version.isAtLeast(JavaSdkVersion.JDK_1_7)) {
                        javaVersion = JavaSdkVersion.JDK_1_7.getDescription();
                    }
                }
            }
        }
        stateStore.put(FormFactorUtils.getLanguageLevelKey(myFormFactor), javaVersion);
    }
}
Also used : JavaSdkVersion(com.intellij.openapi.projectRoots.JavaSdkVersion) AndroidTargetManager(com.android.sdklib.repository.targets.AndroidTargetManager) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 4 with JavaSdkVersion

use of com.intellij.openapi.projectRoots.JavaSdkVersion in project android by JetBrains.

the class IdeSdksConfigurable method validateState.

@NotNull
public List<ProjectConfigurationError> validateState() {
    List<ProjectConfigurationError> errors = Lists.newArrayList();
    String msg = validateAndroidSdkPath();
    if (msg != null) {
        ProjectConfigurationError error = new ProjectConfigurationError(msg, mySdkLocationTextField.getTextField());
        errors.add(error);
    }
    File jdkLocation;
    jdkLocation = validateJdkPath(getJdkLocation());
    if (jdkLocation == null) {
        ProjectConfigurationError error = new ProjectConfigurationError(CHOOSE_VALID_JDK_DIRECTORY_ERR, myJdkLocationTextField.getTextField());
        errors.add(error);
    } else {
        JavaSdkVersion version = Jdks.getInstance().findVersion(jdkLocation);
        if (version == null || !version.isAtLeast(JDK_1_8)) {
            ProjectConfigurationError error = new ProjectConfigurationError("Please choose JDK 8 or newer", myJdkLocationTextField.getTextField());
            errors.add(error);
        }
    }
    msg = validateAndroidNdkPath();
    if (msg != null) {
        ProjectConfigurationError error = new ProjectConfigurationError(msg, myNdkLocationTextField.getTextField());
        errors.add(error);
    }
    return errors;
}
Also used : JavaSdkVersion(com.intellij.openapi.projectRoots.JavaSdkVersion) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtil.findFileByIoFile(com.intellij.openapi.vfs.VfsUtil.findFileByIoFile) FileChooser.chooseFile(com.intellij.openapi.fileChooser.FileChooser.chooseFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with JavaSdkVersion

use of com.intellij.openapi.projectRoots.JavaSdkVersion in project intellij-community by JetBrains.

the class PsiAdapter method getJavaVersion.

public static int getJavaVersion(@NotNull PsiElement element) {
    JavaSdkVersion sdkVersion = JavaVersionService.getInstance().getJavaSdkVersion(element);
    if (sdkVersion == null) {
        sdkVersion = JavaSdkVersion.fromLanguageLevel(PsiUtil.getLanguageLevel(element));
    }
    int version = 0;
    switch(sdkVersion) {
        case JDK_1_0:
        case JDK_1_1:
            version = 1;
            break;
        case JDK_1_2:
            version = 2;
            break;
        case JDK_1_3:
            version = 3;
            break;
        case JDK_1_4:
            version = 4;
            break;
        case JDK_1_5:
            version = 5;
            break;
        case JDK_1_6:
            version = 6;
            break;
        case JDK_1_7:
            version = 7;
            break;
        case JDK_1_8:
            version = 8;
            break;
        case JDK_1_9:
            version = 9;
            break;
    }
    return version;
}
Also used : JavaSdkVersion(com.intellij.openapi.projectRoots.JavaSdkVersion)

Aggregations

JavaSdkVersion (com.intellij.openapi.projectRoots.JavaSdkVersion)22 Sdk (com.intellij.openapi.projectRoots.Sdk)16 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)13 Module (com.intellij.openapi.module.Module)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 File (java.io.File)5 JavaSdkType (com.intellij.openapi.projectRoots.JavaSdkType)3 LanguageLevel (com.intellij.pom.java.LanguageLevel)3 IOException (java.io.IOException)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 ExecutionException (com.intellij.execution.ExecutionException)2 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)2 Project (com.intellij.openapi.project.Project)2 JpsJavaSdkType (org.jetbrains.jps.model.java.JpsJavaSdkType)2 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)1 AndroidTargetManager (com.android.sdklib.repository.targets.AndroidTargetManager)1 NotificationHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)1 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)1 CompilerConfiguration (com.intellij.compiler.CompilerConfiguration)1