Skip to content

Commit 6c31065

Browse files
author
Tomasz Pasternak
committed
wip (testcompat layer)
1 parent dfe5e15 commit 6c31065

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

testing/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,12 @@ java_library(
148148
"intellij-2024.1": glob([
149149
"testcompat/v241/com/google/idea/sdkcompat/**/*.java",
150150
"testcompat/v241/com/google/idea/testing/**/*.java",
151+
"testcompat/v241/com/google/idea/java/**/*.java",
151152
]),
152153
"intellij-ue-2024.1": glob([
153154
"testcompat/v241/com/google/idea/sdkcompat/**/*.java",
154155
"testcompat/v241/com/google/idea/testing/**/*.java",
156+
"testcompat/v241/com/google/idea/java/**/*.java",
155157
]),
156158
"default": [],
157159
}),
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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

Comments
 (0)