Sdk (String mySdkName, String mySdkType, String mySdkHome) { Sdk oldSdk = ProjectJdkTable.getInstance().findJdk(mySdkName); if (oldSdk != null) { if (Objects.equals(oldSdk.getSdkType().getName(), mySdkName) && FileUtil.pathsEqual(oldSdk.getHomePath(), mySdkHome)) { LOG.info("Existing SDK is already configured the expected way"); return oldSdk; } LOG.info("Existing different SDK will be removed: " + oldSdk); ProjectJdkTable.getInstance().removeJdk(oldSdk); } SdkType sdkType = SdkType.findByName(mySdkType); if (sdkType == null) { throw new IllegalArgumentException("Failed to find SdkType: " + mySdkType); } boolean isValidSdkHome; try { isValidSdkHome = sdkType.isValidSdkHome(mySdkHome); } catch (Throwable t) { throw new IllegalArgumentException("Sdk home " + mySdkHome + " for " + sdkType + " is not valid. " + t.getMessage(), t); } if (!isValidSdkHome) { throw new IllegalArgumentException("Sdk home " + mySdkHome + " for " + sdkType + " is not valid"); } Sdk newSdk = ProjectJdkTable.getInstance().createSdk(mySdkName, sdkType); SdkModificator mod = newSdk.getSdkModificator(); try { mod.setVersionString(sdkType.getVersionString(mySdkHome)); mod.setHomePath(mySdkHome); } catch (Throwable t) { throw new IllegalArgumentException( "Failed to configure Sdk instance home for " + mySdkHome + " for " + sdkType + " is not valid. " + t.getMessage(), t); } finally { mod.commitChanges(); } try { sdkType.setupSdkPaths(newSdk); } catch (Throwable t) { throw new IllegalArgumentException( "Failed to setup Sdk home for " + mySdkHome + " for " + sdkType + " is not valid. " + t.getMessage(), t); } ProjectJdkTable.getInstance().addJdk(newSdk); LOG.info("Registered new SDK to ProjectJdkTable: " + newSdk); return newSdk; }