-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prepare for 2024.1: Move Jdk Mock creation to testsdkcompat (#5968)
2. The IdeaTestUtil.getMockJdk no longer returns an instance of MockJdk. It returns a regular JavaSdk instead. Even more, the MockSdk is officially deprecated. Hence, in 2024.1 and newer we need to Use the regular SDKs in tests and modify them with SdkModificator JetBrains/intellij-community@7f05dd0#diff-5fb6bb2bf3104221b2ee04a10cdcf4424ea108b3f541e6b7eb828c721ea8817fL183
- Loading branch information
1 parent
0bda2bd
commit c4440bd
Showing
6 changed files
with
214 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
testing/testcompat/v223/com/google/idea/java/JavaSdkCompat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2021 The Bazel Authors. All rights reserved. | ||
* | ||
* 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. | ||
*/ | ||
package com.google.idea.java; | ||
|
||
import com.intellij.openapi.projectRoots.Sdk; | ||
import com.intellij.openapi.projectRoots.impl.MockSdk; | ||
import com.intellij.openapi.projectRoots.impl.UnknownSdkType; | ||
import com.intellij.pom.java.LanguageLevel; | ||
import com.intellij.testFramework.IdeaTestUtil; | ||
import com.intellij.util.containers.MultiMap; | ||
|
||
/** | ||
* Provides SDK compatibility shims for base plugin API classes, available to all IDEs during | ||
* test-time. | ||
*/ | ||
public final class JavaSdkCompat { | ||
private JavaSdkCompat() {} | ||
/** #api233 to inline */ | ||
public static Sdk getUniqueMockJdk(LanguageLevel languageLevel) { | ||
MockSdk jdk = (MockSdk) IdeaTestUtil.getMockJdk(languageLevel.toJavaVersion()); | ||
jdk.setName(jdk.getName() + "." + jdk.hashCode()); | ||
jdk.setHomePath(jdk.getHomePath() + "." + jdk.hashCode()); | ||
return jdk; | ||
} | ||
|
||
/** #api233 to remove */ | ||
public static Sdk getNonJavaMockSdk() { | ||
return new MockSdk( | ||
/* name= */ "", | ||
/* homePath= */ "", | ||
/* versionString= */ "", | ||
/* roots= */ MultiMap.empty(), | ||
UnknownSdkType.getInstance("")); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
testing/testcompat/v231/com/google/idea/java/JavaSdkCompat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2021 The Bazel Authors. All rights reserved. | ||
* | ||
* 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. | ||
*/ | ||
package com.google.idea.java; | ||
|
||
import com.intellij.openapi.projectRoots.Sdk; | ||
import com.intellij.openapi.projectRoots.impl.MockSdk; | ||
import com.intellij.openapi.projectRoots.impl.UnknownSdkType; | ||
import com.intellij.pom.java.LanguageLevel; | ||
import com.intellij.testFramework.IdeaTestUtil; | ||
import com.intellij.util.containers.MultiMap; | ||
|
||
/** | ||
* Provides SDK compatibility shims for base plugin API classes, available to all IDEs during | ||
* test-time. | ||
*/ | ||
public final class JavaSdkCompat { | ||
private JavaSdkCompat() {} | ||
/** #api233 to inline */ | ||
public static Sdk getUniqueMockJdk(LanguageLevel languageLevel) { | ||
MockSdk jdk = (MockSdk) IdeaTestUtil.getMockJdk(languageLevel.toJavaVersion()); | ||
jdk.setName(jdk.getName() + "." + jdk.hashCode()); | ||
jdk.setHomePath(jdk.getHomePath() + "." + jdk.hashCode()); | ||
return jdk; | ||
} | ||
|
||
/** #api233 to remove */ | ||
public static Sdk getNonJavaMockSdk() { | ||
return new MockSdk( | ||
/* name= */ "", | ||
/* homePath= */ "", | ||
/* versionString= */ "", | ||
/* roots= */ MultiMap.empty(), | ||
UnknownSdkType.getInstance("")); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
testing/testcompat/v232/com/google/idea/java/JavaSdkCompat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2021 The Bazel Authors. All rights reserved. | ||
* | ||
* 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. | ||
*/ | ||
package com.google.idea.java; | ||
|
||
import com.intellij.openapi.projectRoots.Sdk; | ||
import com.intellij.openapi.projectRoots.impl.MockSdk; | ||
import com.intellij.openapi.projectRoots.impl.UnknownSdkType; | ||
import com.intellij.pom.java.LanguageLevel; | ||
import com.intellij.testFramework.IdeaTestUtil; | ||
import com.intellij.util.containers.MultiMap; | ||
|
||
/** | ||
* Provides SDK compatibility shims for base plugin API classes, available to all IDEs during | ||
* test-time. | ||
*/ | ||
public final class JavaSdkCompat { | ||
private JavaSdkCompat() {} | ||
/** #api233 to inline */ | ||
public static Sdk getUniqueMockJdk(LanguageLevel languageLevel) { | ||
MockSdk jdk = (MockSdk) IdeaTestUtil.getMockJdk(languageLevel.toJavaVersion()); | ||
jdk.setName(jdk.getName() + "." + jdk.hashCode()); | ||
jdk.setHomePath(jdk.getHomePath() + "." + jdk.hashCode()); | ||
return jdk; | ||
} | ||
|
||
/** #api233 to remove */ | ||
public static Sdk getNonJavaMockSdk() { | ||
return new MockSdk( | ||
/* name= */ "", | ||
/* homePath= */ "", | ||
/* versionString= */ "", | ||
/* roots= */ MultiMap.empty(), | ||
UnknownSdkType.getInstance("")); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
testing/testcompat/v233/com/google/idea/java/JavaSdkCompat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2021 The Bazel Authors. All rights reserved. | ||
* | ||
* 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. | ||
*/ | ||
package com.google.idea.java; | ||
|
||
import com.intellij.openapi.projectRoots.Sdk; | ||
import com.intellij.openapi.projectRoots.impl.MockSdk; | ||
import com.intellij.openapi.projectRoots.impl.UnknownSdkType; | ||
import com.intellij.pom.java.LanguageLevel; | ||
import com.intellij.testFramework.IdeaTestUtil; | ||
import com.intellij.util.containers.MultiMap; | ||
|
||
/** | ||
* Provides SDK compatibility shims for base plugin API classes, available to all IDEs during | ||
* test-time. | ||
*/ | ||
public final class JavaSdkCompat { | ||
private JavaSdkCompat() {} | ||
/** #api233 to inline */ | ||
public static Sdk getUniqueMockJdk(LanguageLevel languageLevel) { | ||
MockSdk jdk = (MockSdk) IdeaTestUtil.getMockJdk(languageLevel.toJavaVersion()); | ||
jdk.setName(jdk.getName() + "." + jdk.hashCode()); | ||
jdk.setHomePath(jdk.getHomePath() + "." + jdk.hashCode()); | ||
return jdk; | ||
} | ||
|
||
/** #api233 to remove */ | ||
public static Sdk getNonJavaMockSdk() { | ||
return new MockSdk( | ||
/* name= */ "", | ||
/* homePath= */ "", | ||
/* versionString= */ "", | ||
/* roots= */ MultiMap.empty(), | ||
UnknownSdkType.getInstance("")); | ||
} | ||
} |