コード例 #1
0
  static void loadDescriptorsFromClassPath(
      @NotNull List<IdeaPluginDescriptorImpl> result, @Nullable StartupProgress progress) {
    Collection<URL> urls = getClassLoaderUrls();
    String platformPrefix = System.getProperty(PlatformUtilsCore.PLATFORM_PREFIX_KEY);
    int i = 0;
    for (URL url : urls) {
      i++;
      if ("file".equals(url.getProtocol())) {
        File file = new File(decodeUrl(url.getFile()));

        IdeaPluginDescriptorImpl platformPluginDescriptor = null;
        if (platformPrefix != null) {
          platformPluginDescriptor = loadDescriptor(file, platformPrefix + "Plugin.xml");
          if (platformPluginDescriptor != null && !result.contains(platformPluginDescriptor)) {
            platformPluginDescriptor.setUseCoreClassLoader(true);
            result.add(platformPluginDescriptor);
          }
        }

        IdeaPluginDescriptorImpl pluginDescriptor = loadDescriptor(file, PLUGIN_XML);
        if (platformPrefix != null
            && pluginDescriptor != null
            && pluginDescriptor.getName().equals(SPECIAL_IDEA_PLUGIN)) {
          continue;
        }
        if (pluginDescriptor != null && !result.contains(pluginDescriptor)) {
          if (platformPluginDescriptor != null) {
            // if we found a regular plugin.xml in the same .jar/root as a platform-prefixed
            // descriptor, use the core loader for it too
            pluginDescriptor.setUseCoreClassLoader(true);
          }
          result.add(pluginDescriptor);
          if (progress != null) {
            progress.showProgress(
                "Plugin loaded: " + pluginDescriptor.getName(),
                PLUGINS_PROGRESS_MAX_VALUE * ((float) i / urls.size()));
          }
        }
      }
    }
  }
コード例 #2
0
  @SuppressWarnings({"HardCodedStringLiteral"})
  @Nullable
  public static IdeaPluginDescriptorImpl loadDescriptor(
      final File file, @NonNls final String fileName) {
    IdeaPluginDescriptorImpl descriptor = null;

    if (file.isDirectory()) {
      descriptor = loadDescriptorFromDir(file, fileName);

      if (descriptor == null) {
        File libDir = new File(file, "lib");
        if (!libDir.isDirectory()) {
          return null;
        }
        final File[] files = libDir.listFiles();
        if (files == null || files.length == 0) {
          return null;
        }
        Arrays.sort(
            files,
            new Comparator<File>() {
              @Override
              public int compare(File o1, File o2) {
                if (o2.getName().startsWith(file.getName())) return Integer.MAX_VALUE;
                if (o1.getName().startsWith(file.getName())) return -Integer.MAX_VALUE;
                if (o2.getName().startsWith("resources")) return -Integer.MAX_VALUE;
                if (o1.getName().startsWith("resources")) return Integer.MAX_VALUE;
                return 0;
              }
            });
        for (final File f : files) {
          if (FileUtil.isJarOrZip(f)) {
            descriptor = loadDescriptorFromJar(f, fileName);
            if (descriptor != null) {
              descriptor.setPath(file);
              break;
            }
            //           getLogger().warn("Cannot load descriptor from " + f.getName() + "");
          } else if (f.isDirectory()) {
            IdeaPluginDescriptorImpl descriptor1 = loadDescriptorFromDir(f, fileName);
            if (descriptor1 != null) {
              if (descriptor != null) {
                getLogger()
                    .info("Cannot load " + file + " because two or more plugin.xml's detected");
                return null;
              }
              descriptor = descriptor1;
              descriptor.setPath(file);
            }
          }
        }
      }
    } else if (StringUtil.endsWithIgnoreCase(file.getName(), ".jar") && file.exists()) {
      descriptor = loadDescriptorFromJar(file, fileName);
    }

    if (descriptor != null && !descriptor.getOptionalConfigs().isEmpty()) {
      final Map<PluginId, IdeaPluginDescriptorImpl> descriptors =
          new HashMap<PluginId, IdeaPluginDescriptorImpl>(descriptor.getOptionalConfigs().size());
      for (Map.Entry<PluginId, String> entry : descriptor.getOptionalConfigs().entrySet()) {
        String optionalDescriptorName = entry.getValue();
        assert !Comparing.equal(fileName, optionalDescriptorName)
            : "recursive dependency: " + fileName;

        IdeaPluginDescriptorImpl optionalDescriptor = loadDescriptor(file, optionalDescriptorName);
        if (optionalDescriptor == null && !FileUtil.isJarOrZip(file)) {
          for (URL url : getClassLoaderUrls()) {
            if ("file".equals(url.getProtocol())) {
              optionalDescriptor =
                  loadDescriptor(new File(decodeUrl(url.getFile())), optionalDescriptorName);
              if (optionalDescriptor != null) {
                break;
              }
            }
          }
        }
        if (optionalDescriptor != null) {
          descriptors.put(entry.getKey(), optionalDescriptor);
        } else {
          getLogger().info("Cannot find optional descriptor " + optionalDescriptorName);
        }
      }
      descriptor.setOptionalDescriptors(descriptors);
    }
    return descriptor;
  }