private static final Logger LOG = Logger.getInstance("#ro.redeul.google.go.components.GoBundledSdkDetector");
@Override
public void initComponent() {
final ProjectJdkTable jdkTable = ProjectJdkTable.getInstance();
List<Sdk> goSdks = GoSdkUtil.getSdkOfType(GoSdkType.getInstance());
String homePath = PathManager.getHomePath() + "/bundled/go-sdk";
File bundledGoSdkHomePath = new File(homePath);
if ( ! bundledGoSdkHomePath.exists() || ! bundledGoSdkHomePath.isDirectory() ) {
return;
}
LOG.debug("Bundled Go SDK path exists: " + homePath);
for (Sdk sdk : goSdks) {
if (sdk.getHomePath() == null) {
continue;
}
if ( homePath.startsWith(sdk.getHomePath()) ) {
LOG.debug("Bundled Go SDK at registered already with name: " + sdk.getName());
return;
}
}
// validate the sdk
GoSdkData sdkData = GoSdkUtil.testGoogleGoSdk(homePath);
if ( sdkData == null ) {
// skip since the folder isn't a proper go sdk
return;
}
LOG.info("We have a bundled go sdk (at " + homePath + ") that is not in the jdk table. Attempting to add");
try {
final ProjectJdkImpl bundledGoSdk;
final GoSdkType goSdkType = GoSdkType.getInstance();
goSdkType.setSdkData(sdkData);
String newSdkName = SdkConfigurationUtil.createUniqueSdkName(goSdkType, sdkData.GO_GOROOT_PATH, Arrays.asList(jdkTable.getAllJdks()));
bundledGoSdk = new ProjectJdkImpl(newSdkName, goSdkType);
bundledGoSdk.setHomePath(homePath);
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
goSdkType.setupSdkPaths(bundledGoSdk);
jdkTable.addJdk(bundledGoSdk);
}
});
} catch (Exception e) {
LOG.error("Exception while adding the bundled sdk", e);