コード例 #1
0
 @Override
 protected ModuleEx createAndLoadModule(String filePath) throws IOException {
   final ModuleEx module = createModule(filePath);
   VirtualFile vFile = StandardFileSystems.local().findFileByPath(filePath);
   try {
     assert vFile != null;
     StorageData storageData = CoreProjectLoader.loadStorageFile(module, vFile);
     ModuleRootManagerImpl.ModuleRootManagerState state =
         new ModuleRootManagerImpl.ModuleRootManagerState();
     state.readExternal(storageData.getState("NewModuleRootManager"));
     ((ModuleRootManagerImpl) ModuleRootManager.getInstance(module)).loadState(state);
   } catch (JDOMException e) {
     throw new StateStorageException(e);
   } catch (InvalidDataException e) {
     throw new StateStorageException(e);
   }
   return module;
 }
コード例 #2
0
  @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();
  }