/**
   * Find all the transitive dependency plugins of the given plugins, in the order of installation.
   *
   * <p>Resolved plugins set should satisfy required versions including Jenkins version.
   *
   * <p>Transitive dependencies will not be included if there is an already valid version of the
   * plugin installed.
   *
   * @throws UnableToResolveDependencies When there requested plugin version can not be installed.
   */
  public List<PluginMetadata> transitiveDependenciesOf(
      Jenkins jenkins, Collection<PluginSpec> plugins) throws UnableToResolveDependencies {
    List<PluginMetadata> set = new ArrayList<>();
    for (PluginSpec n : plugins) {
      PluginMetadata p = this.plugins.get(n.getName());
      if (p == null) throw new IllegalArgumentException("No such plugin " + n.getName());
      if (p.requiredCore().isNewerThan(jenkins.getVersion())) {
        throw new UnableToResolveDependencies(
            String.format(
                "Unable to install %s plugin because of core dependency. Requeried: %s Used: %s",
                p, p.requiredCore(), jenkins));
      }

      transitiveDependenciesOf(jenkins, p, n.getVersion(), set);
    }
    return set;
  }
  private void transitiveDependenciesOf(
      Jenkins jenkins, PluginMetadata p, String v, List<PluginMetadata> result) {
    for (Dependency d : p.getDependencies()) {
      if (d.optional || !shouldBeIncluded(jenkins, d)) continue;
      PluginMetadata depMetaData = plugins.get(d.name);
      if (depMetaData == null) {
        throw new UnableToResolveDependencies(
            String.format("Unable to install dependency '%s' for '%s': plugin not found", d, p));
      }
      transitiveDependenciesOf(jenkins, depMetaData, d.version, result);
    }

    if (!result.contains(p)) {
      if (p.requiredCore().isNewerThan(jenkins.getVersion())) {
        // If latest version is too new for current Jenkins, use the declared one
        result.add(p.withVersion(v));
      } else {
        result.add(p);
      }
    }
  }
 private void init() {
   for (PluginMetadata pm : plugins.values()) {
     pm.init(this);
   }
 }
示例#4
0
 public Property[] getPluginProperties(PluginMetadata metadata) {
   Plugins plugins = getContainer().getComponent(Plugins.class);
   return plugins.getProperties(plugins.getPlugin(metadata.getKey()));
 }