コード例 #1
0
  public ResolvedPath _getResolvedPluginPath(
      Plugin plugin, String pathId, boolean mergeWithCore, boolean overrideCore, boolean flatten) {
    // Create a mock artifact for the resolver as a way to add user specified path specs and
    // overrides
    RepoArtifact artifact = new RepoArtifact();
    RepoDependency dependency = new RepoDependency();
    RepoArtifactId pluginId = plugin.getArtifact().getId();
    dependency.setId(pluginId);
    artifact.addDependency(dependency);

    String id = "plugin";
    artifact.addPath(new RepoPath(id, "Plugin path", true, true));

    // Add dependencies
    if (plugin.getDependency() != null) {
      for (Iterator j = plugin.getDependency().getPathSpecs().iterator(); j.hasNext(); ) {
        RepoPathSpec pluginPathSpec = (RepoPathSpec) j.next();

        if (pluginPathSpec.getFrom().equals(pathId)) {
          // Add user specifications. Ignore the mandatory flag and to paths as they
          // are not relevant. However, allow descend to be false in case the writer of the
          // plugin added bogus dependencies.
          dependency.addPathSpec(
              new RepoPathSpec(
                  pathId,
                  id,
                  pluginPathSpec.getOptions(),
                  (pluginPathSpec.isDescend() == null) ? Boolean.TRUE : pluginPathSpec.isDescend(),
                  Boolean.TRUE));
        }
      }
    }

    if (dependency.getPathSpecs().size() == 0) {
      // Add default ... user hasn't specified anything
      dependency.addPathSpec(new RepoPathSpec(pathId, id, null, Boolean.TRUE, Boolean.TRUE));
    }

    // Add core overrides if applicable
    if (overrideCore) {
      for (Iterator j = coreOverrides.iterator(); j.hasNext(); ) {
        RepoOverride override = (RepoOverride) j.next();
        artifact.addOverride(override);
      }
    }

    // Add overrides
    for (Iterator i = overrides.iterator(); i.hasNext(); ) {
      ws.quokka.core.model.Override override = (ws.quokka.core.model.Override) i.next();
      Set paths = override.matchingPluginPaths(plugin.getArtifact().getId());

      if (paths.contains(pathId) || ((paths.size() == 1) && paths.contains("*"))) {
        // Create a copy of the override, moving matching plugin paths to be standard paths
        RepoOverride copy =
            new RepoOverride(
                Collections.singleton("*"),
                override.getGroup(),
                override.getName(),
                override.getType(),
                override.getVersion(),
                override.getWithVersion(),
                override.getWithPathSpecs());
        artifact.addOverride(copy);
      }
    }

    // Remove the plugin itself from the path
    // TODO: Look into a better way of doing this, perhaps modifying Resolver so it has the option
    // of not adding the root in first place.
    ResolvedPath path = pathResolver.resolvePath(id, artifact);
    path.setId("Plugin path '" + pathId + "' from " + pluginId.toShortString());

    List artifacts = new ArrayList();

    for (Iterator i = path.getArtifacts().iterator(); i.hasNext(); ) {
      artifact = (RepoArtifact) i.next();

      if (!artifact.getId().equals(pluginId)) {
        artifacts.add(artifact);
      }

      if (pluginId.equals(artifact.getId().getAnnotations().get("declaredBy"))) {
        artifact.getId().getAnnotations().remove("declaredBy");
      }
    }

    path = new ResolvedPath(path.getId(), artifacts);
    path = handleMergeAndFlatten(mergeWithCore, flatten, path);

    return path;
  }
コード例 #2
0
  private void addTarget(Map resolved, Target target) {
    //        System.out.println("Adding " + target.getName() + " from " + parents);
    if (target.getPrefix() != null) {
      target.setDefaultProperties(expandPrefix(target.getPrefix(), target.getDefaultProperties()));
    }

    Target existing = (Target) resolved.get(target.getName());

    if (existing != null) {
      RepoArtifactId targetId = target.getPlugin().getArtifact().getId();
      RepoArtifactId existingId = existing.getPlugin().getArtifact().getId();
      Assert.isTrue(
          targetId.equals(existingId),
          target.getLocator(),
          "Multiple targets are defined with the name '"
              + target.getName()
              + "'. Declared in "
              + targetId
              + " and "
              + existingId);

      return;
    }

    resolved.put(target.getName(), target);
    registerTypes(target);
    registerProjectPaths(target);
    buildResources.putAll(target.getPlugin().getBuildResources());

    // PluginDependency declares the target
    addDependentTargets(resolved, target);

    if (target.getImplementsPlugin() != null) {
      // PluginDependency implements the target declared in another plugin
      String[] implementsPlugin = parseImplements(target);
      RepoArtifactId declaringPluginId =
          fastFindMatchingDependency(
              target,
              new RepoArtifactId(
                  implementsPlugin[0], implementsPlugin[1], "plugin", (Version) null));

      Plugin declaringPlugin = getPluginInstance(declaringPluginId);
      String declaringTargetName = declaringPlugin.getNameSpace() + ":" + implementsPlugin[2];

      // Get the declaring plugin and find the matching target
      Target declaringTarget = (Target) resolved.get(declaringTargetName);

      if (declaringTarget == null) {
        declaringTarget = declaringPlugin.getTarget(declaringTargetName);
        Assert.isTrue(
            declaringTarget != null,
            target.getLocator(),
            "'"
                + declaringTargetName
                + "' is not defined in '"
                + declaringPluginId.toShortString()
                + "'");
        addTarget(resolved, declaringTarget);
      }

      Assert.isTrue(
          declaringTarget.isAbstract(),
          target.getLocator(),
          "Target is attempting to implement a non-abstract target: target="
              + target.getName()
              + ", implements="
              + declaringTarget.getName());
      target.getPlugin().setDeclaringPlugin(declaringTarget.getPlugin());

      if (!declaringTarget.isImplemented()) {
        declaringTarget.setImplemented(true);
        declaringTarget.clearDependencies();
      }

      declaringTarget.addDependency(target.getName());

      // Add the declaring targets dependencies to ensure the implementation is executed before them
      for (Iterator i = declaringTarget.getOriginalDependencies().iterator(); i.hasNext(); ) {
        String dependency = (String) i.next();
        target.addDependency(dependency);
      }
    }
  }