Search in sources :

Example 1 with JavaSdk

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

the class JavaFxArtifactProperties method onBuildFinished.

@Override
public void onBuildFinished(@NotNull final Artifact artifact, @NotNull final CompileContext compileContext) {
    if (!(artifact.getArtifactType() instanceof JavaFxApplicationArtifactType)) {
        return;
    }
    final Project project = compileContext.getProject();
    final Set<Module> modules = ReadAction.compute(() -> ArtifactUtil.getModulesIncludedInArtifacts(Collections.singletonList(artifact), project));
    if (modules.isEmpty()) {
        return;
    }
    Sdk fxCompatibleSdk = null;
    for (Module module : modules) {
        final Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
        if (sdk != null && sdk.getSdkType() instanceof JavaSdk) {
            if (((JavaSdk) sdk.getSdkType()).isOfVersionOrHigher(sdk, JavaSdkVersion.JDK_1_7)) {
                fxCompatibleSdk = sdk;
                break;
            }
        }
    }
    if (fxCompatibleSdk == null) {
        compileContext.addMessage(CompilerMessageCategory.ERROR, "Java version 7 or higher is required to build JavaFX package", null, -1, -1);
        return;
    }
    final JavaFxArtifactProperties properties = (JavaFxArtifactProperties) artifact.getProperties(JavaFxArtifactPropertiesProvider.getInstance());
    final JavaFxPackager javaFxPackager = new JavaFxPackager(artifact, properties, project) {

        @Override
        protected void registerJavaFxPackagerError(String message) {
            compileContext.addMessage(CompilerMessageCategory.ERROR, message, null, -1, -1);
        }
    };
    javaFxPackager.buildJavaFxArtifact(fxCompatibleSdk.getHomePath());
}
Also used : Project(com.intellij.openapi.project.Project) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module)

Example 2 with JavaSdk

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

the class JavaParametersUtil method createAlternativeJdk.

private static Sdk createAlternativeJdk(@NotNull String jreHome) throws CantRunException {
    final Sdk configuredJdk = ProjectJdkTable.getInstance().findJdk(jreHome);
    if (configuredJdk != null) {
        return configuredJdk;
    }
    if (!JdkUtil.checkForJre(jreHome) && !JdkUtil.checkForJdk(jreHome)) {
        throw new CantRunException(ExecutionBundle.message("jre.path.is.not.valid.jre.home.error.message", jreHome));
    }
    final JavaSdk javaSdk = JavaSdk.getInstance();
    final String versionString = javaSdk.getVersionString(jreHome);
    final Sdk jdk = javaSdk.createJdk(versionString != null ? versionString : "", jreHome);
    if (jdk == null)
        throw CantRunException.noJdkConfigured();
    return jdk;
}
Also used : CantRunException(com.intellij.execution.CantRunException) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 3 with JavaSdk

use of com.intellij.openapi.projectRoots.JavaSdk 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 JavaSdk

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

the class JavaProjectDataService method findJdk.

@Nullable
private static Sdk findJdk(@NotNull JavaSdkVersion version) {
    JavaSdk javaSdk = JavaSdk.getInstance();
    List<Sdk> javaSdks = ProjectJdkTable.getInstance().getSdksOfType(javaSdk);
    Sdk candidate = null;
    for (Sdk sdk : javaSdks) {
        JavaSdkVersion v = javaSdk.getVersion(sdk);
        if (v == version) {
            return sdk;
        }
        if (candidate == null && v != null && version.getMaxLanguageLevel().isAtLeast(version.getMaxLanguageLevel())) {
            candidate = sdk;
        }
    }
    return candidate;
}
Also used : JavaSdkVersion(com.intellij.openapi.projectRoots.JavaSdkVersion) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with JavaSdk

use of com.intellij.openapi.projectRoots.JavaSdk in project liferay-ide by liferay.

the class LiferayGradleProjectImportBuilder method _findJdk.

@Nullable
private static Sdk _findJdk(@NotNull JavaSdkVersion version) {
    JavaSdk javaSdk = JavaSdk.getInstance();
    ProjectJdkTable projectJdkTable = ProjectJdkTable.getInstance();
    List<Sdk> javaSdks = projectJdkTable.getSdksOfType(javaSdk);
    Stream<Sdk> stream = javaSdks.stream();
    Sdk candidate = stream.filter(sdk -> {
        JavaSdkVersion sdkVersion = javaSdk.getVersion(sdk);
        if (version.equals(sdkVersion) || ((sdkVersion != null) && version.getMaxLanguageLevel().isAtLeast(version.getMaxLanguageLevel()))) {
            return true;
        }
        return false;
    }).findFirst().orElse(null);
    return candidate;
}
Also used : JavaSdkVersion(com.intellij.openapi.projectRoots.JavaSdkVersion) ProjectJdkTable(com.intellij.openapi.projectRoots.ProjectJdkTable) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)12 Sdk (com.intellij.openapi.projectRoots.Sdk)10 JavaSdkVersion (com.intellij.openapi.projectRoots.JavaSdkVersion)6 Module (com.intellij.openapi.module.Module)2 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 File (java.io.File)2 Nullable (org.jetbrains.annotations.Nullable)2 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)1 AndroidTargetManager (com.android.sdklib.repository.targets.AndroidTargetManager)1 AndroidSdks (com.android.tools.idea.sdk.AndroidSdks)1 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)1 CantRunException (com.intellij.execution.CantRunException)1 NamedLibraryElement (com.intellij.ide.projectView.impl.nodes.NamedLibraryElement)1 NamedLibraryElementNode (com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode)1 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)1 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)1 JavaSdkType (com.intellij.openapi.projectRoots.JavaSdkType)1 ProjectJdkTable (com.intellij.openapi.projectRoots.ProjectJdkTable)1