private Map<String, String> getPluginNameByIdMap() {
   if (myPluginNameById == null) {
     myPluginNameById = new HashMap<String, String>();
     for (IdeaPluginDescriptor descriptor : PluginManagerCore.getPlugins()) {
       myPluginNameById.put(descriptor.getPluginId().getIdString(), descriptor.getName());
     }
   }
   return myPluginNameById;
 }
 private static boolean loadOldPlugins(File plugins, File dest) throws IOException {
   if (plugins.exists()) {
     List<IdeaPluginDescriptorImpl> descriptors = new SmartList<IdeaPluginDescriptorImpl>();
     PluginManagerCore.loadDescriptors(plugins, descriptors, null, 0);
     List<String> oldPlugins = new SmartList<String>();
     for (IdeaPluginDescriptorImpl descriptor : descriptors) {
       // check isBundled also - probably plugin is bundled in new IDE version
       if (descriptor.isEnabled() && !descriptor.isBundled()) {
         oldPlugins.add(descriptor.getPluginId().getIdString());
       }
     }
     if (!oldPlugins.isEmpty()) {
       PluginManagerCore.savePluginsList(
           oldPlugins, false, new File(dest, PluginManager.INSTALLED_TXT));
     }
     return true;
   }
   return false;
 }
Esempio n. 3
0
  private static Exception wrapException(InvalidMirrorException e, VirtualFile file) {
    ClassFileDecompilers.Decompiler decompiler = ClassFileDecompilers.find(file);
    if (decompiler instanceof ClassFileDecompilers.Light) {
      PluginId pluginId = PluginManagerCore.getPluginByClassName(decompiler.getClass().getName());
      if (pluginId != null) {
        return new PluginException(e, pluginId);
      }
    }

    return e;
  }
  /**
   * Should be called whenever a list of plugins is loaded from a repository to check if there is an
   * updated version.
   */
  public void onDescriptorDownload(@NotNull IdeaPluginDescriptor descriptor) {
    PluginId id = descriptor.getPluginId();
    IdeaPluginDescriptor existing = PluginManager.getPlugin(id);
    if (existing == null
        || (existing.isBundled() && !existing.allowBundledUpdate())
        || wasUpdated(id)) {
      return;
    }

    boolean supersedes =
        !PluginManagerCore.isIncompatible(descriptor)
            && (PluginDownloader.compareVersionsSkipBroken(existing, descriptor.getVersion()) > 0
                || PluginManagerCore.isIncompatible(existing));

    String idString = id.getIdString();

    synchronized (myLock) {
      if (supersedes) {
        myOutdatedPlugins.add(idString);
      } else {
        myOutdatedPlugins.remove(idString);
      }
    }
  }
  // used in upsource
  protected void readExternal(@NotNull Element element) {
    final PluginBean pluginBean = XmlSerializer.deserialize(element, PluginBean.class);

    url = pluginBean.url;
    myName = pluginBean.name;
    String idString = pluginBean.id;
    if (idString == null || idString.isEmpty()) {
      idString = myName;
    }
    myId = idString == null ? null : PluginId.getId(idString);

    String internalVersionString = pluginBean.formatVersion;
    if (internalVersionString != null) {
      try {
        //noinspection ResultOfMethodCallIgnored
        Integer.parseInt(internalVersionString);
      } catch (NumberFormatException e) {
        LOG.error(
            new PluginException(
                "Invalid value in plugin.xml format version: '" + internalVersionString + "'",
                e,
                myId));
      }
    }
    myUseIdeaClassLoader = pluginBean.useIdeaClassLoader;
    myAllowBundledUpdate = pluginBean.allowBundledUpdate;
    if (pluginBean.ideaVersion != null) {
      mySinceBuild = pluginBean.ideaVersion.sinceBuild;
      myUntilBuild = convertExplicitBigNumberInUntilBuildToStar(pluginBean.ideaVersion.untilBuild);
    }

    myResourceBundleBaseName = pluginBean.resourceBundle;

    myDescriptionChildText = pluginBean.description;
    myChangeNotes = pluginBean.changeNotes;
    myVersion = pluginBean.pluginVersion;
    if (myVersion == null) {
      myVersion = PluginManagerCore.getBuildNumber().asStringWithoutProductCode();
    }

    myCategory = pluginBean.category;

    if (pluginBean.vendor != null) {
      myVendor = pluginBean.vendor.name;
      myVendorEmail = pluginBean.vendor.email;
      myVendorUrl = pluginBean.vendor.url;
      myVendorLogoPath = pluginBean.vendor.logo;
    }

    // preserve items order as specified in xml (filterBadPlugins will not fail if module comes
    // first)
    Set<PluginId> dependentPlugins = new LinkedHashSet<PluginId>();
    Set<PluginId> optionalDependentPlugins = new LinkedHashSet<PluginId>();
    if (pluginBean.dependencies != null) {
      myOptionalConfigs = new THashMap<PluginId, String>();
      for (PluginDependency dependency : pluginBean.dependencies) {
        String text = dependency.pluginId;
        if (!StringUtil.isEmpty(text)) {
          PluginId id = PluginId.getId(text);
          dependentPlugins.add(id);
          if (dependency.optional) {
            optionalDependentPlugins.add(id);
            if (!StringUtil.isEmpty(dependency.configFile)) {
              myOptionalConfigs.put(id, dependency.configFile);
            }
          }
        }
      }
    }

    myDependencies =
        dependentPlugins.isEmpty()
            ? PluginId.EMPTY_ARRAY
            : dependentPlugins.toArray(new PluginId[dependentPlugins.size()]);
    myOptionalDependencies =
        optionalDependentPlugins.isEmpty()
            ? PluginId.EMPTY_ARRAY
            : optionalDependentPlugins.toArray(new PluginId[optionalDependentPlugins.size()]);

    if (pluginBean.helpSets == null || pluginBean.helpSets.length == 0) {
      myHelpSets = HelpSetPath.EMPTY;
    } else {
      myHelpSets = new HelpSetPath[pluginBean.helpSets.length];
      PluginHelpSet[] sets = pluginBean.helpSets;
      for (int i = 0, n = sets.length; i < n; i++) {
        PluginHelpSet pluginHelpSet = sets[i];
        myHelpSets[i] = new HelpSetPath(pluginHelpSet.file, pluginHelpSet.path);
      }
    }

    myAppComponents = pluginBean.applicationComponents;
    myProjectComponents = pluginBean.projectComponents;
    myModuleComponents = pluginBean.moduleComponents;

    if (myAppComponents == null) myAppComponents = ComponentConfig.EMPTY_ARRAY;
    if (myProjectComponents == null) myProjectComponents = ComponentConfig.EMPTY_ARRAY;
    if (myModuleComponents == null) myModuleComponents = ComponentConfig.EMPTY_ARRAY;

    StringInterner interner = new StringInterner();
    List<Element> extensions = copyElements(pluginBean.extensions, interner);
    if (extensions != null) {
      myExtensions = MultiMap.createSmart();
      for (Element extension : extensions) {
        myExtensions.putValue(ExtensionsAreaImpl.extractEPName(extension), extension);
      }
    }

    List<Element> extensionPoints = copyElements(pluginBean.extensionPoints, interner);
    if (extensionPoints != null) {
      myExtensionsPoints = MultiMap.createSmart();
      for (Element extensionPoint : extensionPoints) {
        myExtensionsPoints.putValue(
            StringUtil.notNullize(
                extensionPoint.getAttributeValue(ExtensionsAreaImpl.ATTRIBUTE_AREA)),
            extensionPoint);
      }
    }

    myActionsElements = copyElements(pluginBean.actions, interner);

    if (pluginBean.modules != null && !pluginBean.modules.isEmpty()) {
      myModules = pluginBean.modules;
    }
  }