Exemplo n.º 1
0
  public static void attachJdkAnnotations(@NotNull SdkModificator modificator) {
    LocalFileSystem lfs = LocalFileSystem.getInstance();
    List<String> pathsChecked = new ArrayList<>();
    // community idea under idea
    String path =
        FileUtil.toSystemIndependentName(PathManager.getHomePath()) + "/java/jdkAnnotations";
    VirtualFile root = lfs.findFileByPath(path);
    pathsChecked.add(path);

    if (root == null) { // idea under idea
      path =
          FileUtil.toSystemIndependentName(PathManager.getHomePath())
              + "/community/java/jdkAnnotations";
      root = lfs.findFileByPath(path);
      pathsChecked.add(path);
    }
    if (root == null) { // build
      String url =
          "jar://"
              + FileUtil.toSystemIndependentName(PathManager.getHomePath())
              + "/lib/jdkAnnotations.jar!/";
      root = VirtualFileManager.getInstance().findFileByUrl(url);
      pathsChecked.add(
          FileUtil.toSystemIndependentName(PathManager.getHomePath()) + "/lib/jdkAnnotations.jar");
    }
    if (root == null) {
      String msg = "Paths checked:\n";
      for (String p : pathsChecked) {
        File file = new File(p);
        msg +=
            "Path: '"
                + p
                + "' "
                + (file.exists() ? "Found" : "Not found")
                + "; directory children: "
                + Arrays.toString(file.getParentFile().listFiles())
                + "\n";
      }
      LOG.error("JDK annotations not found", msg);
      return;
    }

    OrderRootType annoType = AnnotationOrderRootType.getInstance();
    modificator.removeRoot(root, annoType);
    modificator.addRoot(root, annoType);
  }
Exemplo n.º 2
0
  @Override
  @SuppressWarnings("HardCodedStringLiteral")
  public void setupSdkPaths(@NotNull Sdk sdk) {
    String homePath = sdk.getHomePath();
    assert homePath != null : sdk;

    File jdkHome = new File(homePath);
    List<VirtualFile> classes = findClasses(jdkHome, false);
    VirtualFile sources = findSources(jdkHome);
    VirtualFile docs = findDocs(jdkHome, "docs/api");
    SdkModificator sdkModificator = sdk.getSdkModificator();

    Set<VirtualFile> previousRoots =
        new LinkedHashSet<>(Arrays.asList(sdkModificator.getRoots(OrderRootType.CLASSES)));
    sdkModificator.removeRoots(OrderRootType.CLASSES);
    previousRoots.removeAll(new HashSet<>(classes));
    for (VirtualFile aClass : classes) {
      sdkModificator.addRoot(aClass, OrderRootType.CLASSES);
    }
    for (VirtualFile root : previousRoots) {
      sdkModificator.addRoot(root, OrderRootType.CLASSES);
    }

    if (sources != null) {
      sdkModificator.addRoot(sources, OrderRootType.SOURCES);
    }
    VirtualFile javaFxSources = findSources(jdkHome, "javafx-src");
    if (javaFxSources != null) {
      sdkModificator.addRoot(javaFxSources, OrderRootType.SOURCES);
    }

    if (docs != null) {
      sdkModificator.addRoot(docs, JavadocOrderRootType.getInstance());
    } else if (SystemInfo.isMac) {
      VirtualFile commonDocs = findDocs(jdkHome, "docs");
      if (commonDocs == null) {
        commonDocs = findInJar(new File(jdkHome, "docs.jar"), "doc/api");
        if (commonDocs == null) {
          commonDocs = findInJar(new File(jdkHome, "docs.jar"), "docs/api");
        }
      }
      if (commonDocs != null) {
        sdkModificator.addRoot(commonDocs, JavadocOrderRootType.getInstance());
      }

      VirtualFile appleDocs = findDocs(jdkHome, "appledocs");
      if (appleDocs == null) {
        appleDocs = findInJar(new File(jdkHome, "appledocs.jar"), "appledoc/api");
      }
      if (appleDocs != null) {
        sdkModificator.addRoot(appleDocs, JavadocOrderRootType.getInstance());
      }

      if (commonDocs == null && appleDocs == null && sources == null) {
        String url = getDefaultDocumentationUrl(sdk);
        if (url != null) {
          sdkModificator.addRoot(
              VirtualFileManager.getInstance().findFileByUrl(url),
              JavadocOrderRootType.getInstance());
        }
      }
    } else if (getVersion(sdk) == JavaSdkVersion.JDK_1_7) {
      VirtualFile url =
          VirtualFileManager.getInstance().findFileByUrl("http://docs.oracle.com/javafx/2/api/");
      sdkModificator.addRoot(url, JavadocOrderRootType.getInstance());
    }

    attachJdkAnnotations(sdkModificator);

    sdkModificator.commitChanges();
  }