mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-30 02:07:50 +08:00
Update sdk.md
This commit is contained in:
parent
6a7a4fbc32
commit
848aad82c2
@ -39,3 +39,68 @@ Sdk projectSdk = ProjectRootManager.getInstance(project).getProjectSdk();
|
||||
```
|
||||
|
||||
See the following [code sample](https://github.com/JetBrains/intellij-sdk-docs/blob/master/code_samples/project_model/src/com/intellij/tutorials/project/model/ProjectSdkAction.java) to get more familiar with SDK manipulation tool set.
|
||||
|
||||
## 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.
|
||||
|
||||
```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;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
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
|
||||
}
|
||||
```
|
||||
|
Loading…
x
Reference in New Issue
Block a user