@NotNull @Override public Sdk createJdk(@NotNull String jdkName, @NotNull String home, boolean isJre) { ProjectJdkImpl jdk = new ProjectJdkImpl(jdkName, this); SdkModificator sdkModificator = jdk.getSdkModificator(); String path = home.replace(File.separatorChar, '/'); sdkModificator.setHomePath(path); sdkModificator.setVersionString( jdkName); // must be set after home path, otherwise setting home path clears the version // string File jdkHomeFile = new File(home); addClasses(jdkHomeFile, sdkModificator, isJre); addSources(jdkHomeFile, sdkModificator); addDocs(jdkHomeFile, sdkModificator); sdkModificator.commitChanges(); return jdk; }
@Override public void setupSdkPaths(@NotNull Sdk sdk) { VirtualFile homeDirectory = sdk.getHomeDirectory(); if (sdk.getSdkType() != this || homeDirectory == null) { return; } String path = homeDirectory.getPath(); GoSdkData sdkData = GoSdkUtil.testGoogleGoSdk(path); if (sdkData == null) return; final VirtualFile sdkSourcesRoot = homeDirectory.findFileByRelativePath("src/pkg/"); if (sdkSourcesRoot != null) { sdkSourcesRoot.refresh(false, false); } String goPathFirst = System.getenv("GOPATH"); VirtualFile goPathDirectory; VirtualFile pathSourcesRoot = null; if (goPathFirst != null && !goPathFirst.equals("") && goPathFirst.contains(File.pathSeparator)) { // If there are multiple directories under GOPATH then we extract only the first one if (goPathFirst.contains(File.pathSeparator)) { goPathFirst = goPathFirst.split(File.pathSeparator)[0]; } if ((new File(goPathFirst).exists())) { goPathDirectory = StandardFileSystems.local().findFileByPath(goPathFirst); if (goPathDirectory != null) { pathSourcesRoot = goPathDirectory.findFileByRelativePath("src/"); } } } final SdkModificator sdkModificator = sdk.getSdkModificator(); final VirtualFile finalPathSourcesRoot = pathSourcesRoot; ApplicationManager.getApplication() .runWriteAction( new Runnable() { public void run() { sdkModificator.addRoot(sdkSourcesRoot, OrderRootType.CLASSES); sdkModificator.addRoot(sdkSourcesRoot, OrderRootType.SOURCES); // If we could detect the GOPATH properly, automatically add the first directory to // the autocompletion path if (finalPathSourcesRoot != null) { sdkModificator.addRoot(finalPathSourcesRoot, OrderRootType.CLASSES); sdkModificator.addRoot(finalPathSourcesRoot, OrderRootType.SOURCES); } } }); sdkModificator.setVersionString(sdkData.VERSION_MAJOR); sdkModificator.setSdkAdditionalData(sdkData); sdkModificator.commitChanges(); }