mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-30 18:27:49 +08:00
Update sdk.md
This commit is contained in:
parent
848aad82c2
commit
ebda7646e1
@ -42,65 +42,18 @@ See the following [code sample](https://github.com/JetBrains/intellij-sdk-docs/b
|
||||
|
||||
## Working with your own SDK
|
||||
|
||||
To create your own SDK, You need to create a class extends `SdkType`, and set your recommended SDK name, SDK home path, a presentable name. <br/>
|
||||
Finally you need to implement `isValidSdkHome` to do the SDK validation, and this example just check if the given path is a directory.
|
||||
To create your own SDK, You need to create a class extends [SdkType](https://upsource.jetbrains.com/idea-ce/file/idea-ce-974a6ed084613aa5b0e345fbeb50de59720ab283/platform/lang-api/src/com/intellij/openapi/projectRoots/SdkType.java), leave `saveAdditionalData` blank, and register it in the `com.intellij.sdkType` extension point.
|
||||
|
||||
To make your SDK settings persistant, you should override `setupSdkPaths` and save your settings by `modificator.commitChanges()`:
|
||||
|
||||
```java
|
||||
import com.intellij.openapi.projectRoots.*;
|
||||
|
||||
public class MySdkType extends SdkType {
|
||||
public MySdkType() {
|
||||
super("MY_SDK_NAME");
|
||||
}
|
||||
|
||||
@Override public @Nullable String suggestHomePath() {
|
||||
return "/usr/share/covscript";
|
||||
}
|
||||
|
||||
@Override public boolean isValidSdkHome(@NotNull String path) {
|
||||
return Files.isDirectory(Paths.get(path));
|
||||
}
|
||||
|
||||
@Override public @Nullable String suggestSdkName(@NotNull String s, @NotNull String s1) {
|
||||
return "Replace with your SDK name";
|
||||
}
|
||||
|
||||
@Override public @Nullable AdditionalDataConfigurable createAdditionalDataConfigurable(
|
||||
@NotNull SdkModel sdkModel, @NotNull SdkModificator sdkModificator) {
|
||||
return null; // not needed
|
||||
}
|
||||
|
||||
@Override public @NotNull String getPresentableName() {
|
||||
return "My Awesome Sdk";
|
||||
}
|
||||
|
||||
@Override public void saveAdditionalData(
|
||||
@NotNull SdkAdditionalData sdkAdditionalData, @NotNull Element element) {
|
||||
// leave blank
|
||||
}
|
||||
|
||||
@Override public boolean setupSdkPaths(@NotNull Sdk sdk, @NotNull SdkModel sdkModel) {
|
||||
SdkModificator modificator = sdk.getSdkModificator();
|
||||
modificator.setVersionString(getVersionString(sdk));
|
||||
modificator.commitChanges();
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean setupSdkPaths(@NotNull Sdk sdk, @NotNull SdkModel sdkModel) {
|
||||
SdkModificator modificator = sdk.getSdkModificator();
|
||||
modificator.setVersionString(getVersionString(sdk));
|
||||
modificator.commitChanges();
|
||||
return true;
|
||||
}
|
||||
```
|
||||
|
||||
Optionally, you can override `getIcon` to set an icon to your SDK type.
|
||||
|
||||
The last method is not abstract, so it's possible to remove it. But to save your SDK settings
|
||||
(say, the next time you open your IDE, the SDK will still be there), you should override it.
|
||||
|
||||
To let users create or select an existing SDK, you may do this in some configuration panels (like, module wizard, facet, or run configuration):
|
||||
|
||||
```java
|
||||
ProjectJdksEditor editor = new ProjectJdksEditor(sdkCurrentlyUsed, project, parentGuiComponent);
|
||||
editor.setTitle("Select a SDK");
|
||||
editor.show();
|
||||
if (editor.isOK()) {
|
||||
Sdk newSdkSelected = editor.getSelectedJdk();
|
||||
// do your update job here
|
||||
}
|
||||
```
|
||||
To let user select an SDK, see [ProjectJdksEditor](https://upsource.jetbrains.com/idea-ce/file/idea-ce-8c9022ae739b82b2ee8f3355da98b9bbce2cb915/java/idea-ui/src/com/intellij/openapi/projectRoots/ui/ProjectJdksEditor.java).
|
||||
|
Loading…
x
Reference in New Issue
Block a user