@Nullable
  @Override
  public ValidationInfo validate() {
    if (getSdkData() == null) {
      return new ValidationInfo(GoBundle.message("error.invalid.sdk.path", mySdkPath.getText()));
    }

    String goSdkPath = mySdkPath.getText();

    GoSdkType goSdk = new GoSdkType();
    if (!goSdk.isValidSdkHome(goSdkPath)) {
      return new ValidationInfo(GoBundle.message("error.invalid.sdk.path", mySdkPath.getText()));
    }

    GoSdkData goSdkData = GoSdkUtil.testGoogleGoSdk(goSdkPath);

    if (goSdkData == null) {
      return new ValidationInfo(GoBundle.message("error.invalid.sdk.path", mySdkPath.getText()));
    }

    goSdkData.GO_GOPATH_PATH = gopathPath.getText();

    labelSdkVersion.setText(goSdkData.VERSION_MAJOR);
    if (goSdkData.TARGET_OS != null && goSdkData.TARGET_ARCH != null) {
      labelSdkTarget.setText(
          String.format(
              "%s-%s (%s, %s)",
              goSdkData.TARGET_OS.getName(),
              goSdkData.TARGET_ARCH.getName(),
              GoSdkUtil.getCompilerName(goSdkData.TARGET_ARCH),
              GoSdkUtil.getLinkerName(goSdkData.TARGET_ARCH)));
    } else {
      labelSdkTarget.setText("Unknown target");
    }

    labelBinariesPath.setText(goSdkData.GO_BIN_PATH);
    return null;
  }
  @Override
  public void initComponent() {
    ProjectJdkTable jdkTable = ProjectJdkTable.getInstance();
    List<Sdk> sdkList = new ArrayList<Sdk>();

    sdkList.addAll(GoSdkUtil.getSdkOfType(GoSdkType.getInstance(), jdkTable));

    for (Sdk sdk : sdkList) {
      GoSdkData sdkData = (GoSdkData) sdk.getSdkAdditionalData();

      boolean needsUpgrade = sdkData == null;
      try {
        if (!needsUpgrade) {
          sdkData.checkValid();
        }
      } catch (ConfigurationException ex) {
        needsUpgrade = true;
      }

      if (!needsUpgrade) continue;

      needsUpgrade = false;
      GoSdkData data = GoSdkUtil.testGoogleGoSdk(sdk.getHomePath());

      if (data == null) needsUpgrade = true;

      try {
        if (data != null) {
          data.checkValid();
        }
      } catch (ConfigurationException ex) {
        needsUpgrade = true;
      }

      if (needsUpgrade) {
        Notifications.Bus.notify(
            new Notification(
                "Go SDK validator",
                "Corrupt Go SDK",
                getContent("Go", sdk.getName()),
                NotificationType.WARNING),
            myProject);
      }

      SdkModificator sdkModificator = sdk.getSdkModificator();
      sdkModificator.setSdkAdditionalData(data);
      sdkModificator.commitChanges();
    }

    sdkList.clear();
    sdkList.addAll(GoSdkUtil.getSdkOfType(GoAppEngineSdkType.getInstance(), jdkTable));

    Boolean hasGAESdk = sdkList.size() > 0;

    for (Sdk sdk : sdkList) {
      GoAppEngineSdkData sdkData = (GoAppEngineSdkData) sdk.getSdkAdditionalData();

      if (sdkData == null || sdkData.TARGET_ARCH == null || sdkData.TARGET_OS == null) {
        Notifications.Bus.notify(
            new Notification(
                "Go AppEngine SDK validator",
                "Corrupt Go App Engine SDK",
                getContent("Go App Engine", sdk.getName()),
                NotificationType.WARNING),
            myProject);

        continue;
      }

      boolean needsUpgrade = false;
      try {
        sdkData.checkValid();
      } catch (ConfigurationException ex) {
        needsUpgrade = true;
      }

      if (!needsUpgrade) continue;

      needsUpgrade = false;
      GoAppEngineSdkData data = GoSdkUtil.testGoAppEngineSdk(sdk.getHomePath());

      if (data == null) needsUpgrade = true;

      try {
        if (data != null) {
          data.checkValid();
        }
      } catch (ConfigurationException ex) {
        needsUpgrade = true;
      }

      // GAE SDK auto-update needs a bit more love
      if (data != null && !(new File(data.GOAPP_BIN_PATH)).exists()) {
        needsUpgrade = true;
      }

      if (needsUpgrade) {
        Notifications.Bus.notify(
            new Notification(
                "Go AppEngine SDK validator",
                "Corrupt Go App Engine SDK",
                getContent("Go AppEngine", sdk.getName()),
                NotificationType.WARNING),
            myProject);
      }

      SdkModificator sdkModificator = sdk.getSdkModificator();
      sdkModificator.setSdkAdditionalData(data);
      sdkModificator.commitChanges();
    }

    if (hasGAESdk) {
      String sysAppEngineDevServerPath = GoSdkUtil.getAppEngineDevServer();
      if (sysAppEngineDevServerPath.isEmpty())
        Notifications.Bus.notify(
            new Notification(
                "Go AppEngine SDK validator",
                "Problem with env variables",
                getInvalidAPPENGINE_DEV_APPSERVEREnvMessage(),
                NotificationType.WARNING,
                NotificationListener.URL_OPENING_LISTENER),
            myProject);
    }

    PluginDescriptor pluginDescriptor =
        PluginManager.getPlugin(PluginId.getId("ro.redeul.google.go"));
    if (pluginDescriptor != null) {
      String version = ((IdeaPluginDescriptorImpl) pluginDescriptor).getVersion();

      if (version.endsWith("-dev")
          && !System.getProperty("go.skip.dev.warn", "false").equals("true")) {
        Notifications.Bus.notify(
            new Notification(
                "Go plugin notice",
                "Development version detected",
                getDevVersionMessage(),
                NotificationType.WARNING,
                null),
            myProject);
      }
    }

    super.initComponent();
  }
 @Override
 public boolean isValidSdkHome(String path) {
   sdkData = GoSdkUtil.testGoogleGoSdk(path);
   return sdkData != null;
 }
  @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();
  }
 @Nullable
 private GoSdkData getSdkData() {
   return GoSdkUtil.testGoogleGoSdk(FileUtil.toSystemIndependentName(mySdkPath.getText()));
 }