|
| 1 | +/* |
| 2 | + * Copyright 2021 The Bazel Authors. All rights reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.google.idea.java; |
| 17 | + |
| 18 | +import com.intellij.openapi.application.ApplicationManager; |
| 19 | +import com.intellij.openapi.projectRoots.Sdk; |
| 20 | +import com.intellij.pom.java.LanguageLevel; |
| 21 | +import com.intellij.testFramework.IdeaTestUtil; |
| 22 | + |
| 23 | +/** |
| 24 | + * Provides SDK compatibility shims for base plugin API classes, available to all IDEs during |
| 25 | + * test-time. |
| 26 | + */ |
| 27 | +public final class JavaSdkCompat { |
| 28 | + private JavaSdkCompat() {} |
| 29 | + |
| 30 | + /** #api233 to inline */ |
| 31 | + public static Sdk getUniqueMockJdk(LanguageLevel languageLevel) { |
| 32 | + var jdk = IdeaTestUtil.getMockJdk(languageLevel.toJavaVersion()); |
| 33 | + var modificator = jdk.getSdkModificator(); |
| 34 | + modificator.setHomePath(jdk.getHomePath() + "." + jdk.hashCode()); |
| 35 | + modificator.setName(jdk.getName() + "." + jdk.hashCode()); |
| 36 | + ApplicationManager.getApplication().runWriteAction(modificator::commitChanges); |
| 37 | + return jdk; |
| 38 | + } |
| 39 | + |
| 40 | + /** #api233 to remove */ |
| 41 | + public static Sdk getNonJavaMockSdk() { |
| 42 | + throw new RuntimeException("Not supported in 2024.1 or newer"); |
| 43 | + } |
| 44 | +} |
0 commit comments