diff --git a/java/execution/impl/src/com/intellij/execution/util/JreVersionDetector.java b/java/execution/impl/src/com/intellij/execution/util/JreVersionDetector.java index ed0636697b26..f465f01080e3 100644 --- a/java/execution/impl/src/com/intellij/execution/util/JreVersionDetector.java +++ b/java/execution/impl/src/com/intellij/execution/util/JreVersionDetector.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.execution.util; @@ -26,17 +14,17 @@ import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.text.StringUtil; +import org.jetbrains.jps.model.java.JdkVersionDetector; public class JreVersionDetector { private String myLastAlternativeJrePath ; //awful hack private boolean myLastIsJre50; public boolean isModuleJre50Configured(final ModuleBasedConfiguration configuration) { - final Module module = configuration.getConfigurationModule().getModule(); - if (module != null && !module.isDisposed()) { - return isJre50(ModuleRootManager.getInstance(module).getSdk()); - } - return isJre50(ProjectRootManager.getInstance(configuration.getProject()).getProjectSdk()); + Module module = configuration.getConfigurationModule().getModule(); + Sdk sdk = module != null && !module.isDisposed() ? ModuleRootManager.getInstance(module).getSdk() + : ProjectRootManager.getInstance(configuration.getProject()).getProjectSdk(); + return JavaSdkUtil.isJdkAtLeast(sdk, JavaSdkVersion.JDK_1_5); } public boolean isJre50Configured(final CommonJavaRunConfigurationParameters configuration) { @@ -48,22 +36,12 @@ public class JreVersionDetector { } myLastAlternativeJrePath = alternativeJrePath; - String versionString = SdkVersionUtil.detectJdkVersion(myLastAlternativeJrePath); - myLastIsJre50 = versionString != null && isJre50(versionString); + JdkVersionDetector.JdkVersionInfo jdkInfo = SdkVersionUtil.getJdkVersionInfo(myLastAlternativeJrePath); + myLastIsJre50 = jdkInfo != null && jdkInfo.version.feature >= 5; return myLastIsJre50; } } return false; } - - private static boolean isJre50(Sdk jdk) { - return JavaSdkUtil.isJdkAtLeast(jdk, JavaSdkVersion.JDK_1_5); - } - - private static boolean isJre50(String versionString) { - if (versionString == null) return false; - JavaSdkVersion version = JavaSdkVersion.fromVersionString(versionString); - return version != null && version.isAtLeast(JavaSdkVersion.JDK_1_5); - } } \ No newline at end of file diff --git a/java/openapi/src/com/intellij/openapi/projectRoots/JavaSdk.java b/java/openapi/src/com/intellij/openapi/projectRoots/JavaSdk.java index 9a807c28c0ac..83d4f8e320dd 100644 --- a/java/openapi/src/com/intellij/openapi/projectRoots/JavaSdk.java +++ b/java/openapi/src/com/intellij/openapi/projectRoots/JavaSdk.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.openapi.projectRoots; @@ -57,7 +45,7 @@ public abstract class JavaSdk extends SdkType implements JavaSdkType { return JdkUtil.checkForJre(file); } - /** @deprecated use {@link SdkVersionUtil#detectJdkVersion} (to be removed in IDEA 2019) */ + /** @deprecated use {@link SdkVersionUtil#getJdkVersionInfo} (to be removed in IDEA 2019) */ public static String getJdkVersion(@NotNull String sdkHome) { return SdkVersionUtil.detectJdkVersion(sdkHome); } diff --git a/platform/lang-api/src/com/intellij/openapi/projectRoots/SimpleJavaSdkType.java b/platform/lang-api/src/com/intellij/openapi/projectRoots/SimpleJavaSdkType.java index a7a298e17b9f..2dc435c6be8d 100644 --- a/platform/lang-api/src/com/intellij/openapi/projectRoots/SimpleJavaSdkType.java +++ b/platform/lang-api/src/com/intellij/openapi/projectRoots/SimpleJavaSdkType.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.openapi.projectRoots; @@ -20,6 +8,7 @@ import com.intellij.openapi.projectRoots.impl.SdkVersionUtil; import com.intellij.openapi.util.io.FileUtil; import org.jdom.Element; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jps.model.java.JdkVersionDetector; import java.io.File; @@ -52,8 +41,7 @@ public class SimpleJavaSdkType extends SdkType implements JavaSdkType { } @Override - public void saveAdditionalData(@NotNull SdkAdditionalData additionalData, @NotNull Element additional) { - } + public void saveAdditionalData(@NotNull SdkAdditionalData additionalData, @NotNull Element additional) { } @Override public String getBinPath(@NotNull Sdk sdk) { @@ -87,6 +75,7 @@ public class SimpleJavaSdkType extends SdkType implements JavaSdkType { @Override public final String getVersionString(final String sdkHome) { - return SdkVersionUtil.detectJdkVersion(sdkHome); + JdkVersionDetector.JdkVersionInfo jdkInfo = SdkVersionUtil.getJdkVersionInfo(sdkHome); + return jdkInfo != null ? JdkVersionDetector.formatVersionString(jdkInfo.version) : null; } } \ No newline at end of file