Exemplo n.º 1
0
  private void resolveProperties(AnnotatedProperties properties, DependencySet dependencySet) {
    for (Iterator i = dependencySet.getSubsets().iterator(); i.hasNext(); ) {
      resolveProperties(properties, (DependencySet) i.next());
    }

    if (dependencySet.getProperties() != null) {
      properties.putAll(
          applyProfiles(dependencySet.getProperties(), project.getActiveProfiles().getElements()));
    }
  }
Exemplo n.º 2
0
  public Set getLicenses() {
    Set licenses = new HashSet();

    for (Iterator i = depthFirst(project.getDependencySet()).iterator(); i.hasNext(); ) {
      DependencySet set = (DependencySet) i.next();
      licenses.addAll(set.getLicenses());
    }

    return licenses;
  }
Exemplo n.º 3
0
  public ResolvedPath getReslovedProjectPath(
      String id,
      boolean mergeWithCore,
      boolean overrideCore,
      boolean flatten,
      List appliedOverrides) {
    log.debug(
        "Getting project path: id="
            + id
            + ", mergeWithCore="
            + mergeWithCore
            + ", overrideCore="
            + overrideCore
            + ", flatten="
            + flatten);

    RepoArtifact artifact = new RepoArtifact();

    for (Iterator i = depthFirst(project.getDependencySet()).iterator(); i.hasNext(); ) {
      DependencySet set = (DependencySet) i.next();

      // Add dependencies
      for (Iterator j = set.getDependencies().iterator(); j.hasNext(); ) {
        RepoDependency dependency = (RepoDependency) j.next();
        artifact.addDependency(dependency);
      }

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

      // Add overrides
      for (Iterator j = set.getOverrides().iterator(); j.hasNext(); ) {
        RepoOverride override = (RepoOverride) j.next();
        artifact.addOverride(override);
      }
    }

    // Copy the project paths to the artifact
    for (Iterator i = resolvedPaths.values().iterator(); i.hasNext(); ) {
      RepoPath path = (RepoPath) i.next();
      artifact.addPath(path);
    }

    ResolvedPath path = pathResolver.resolvePath(id, artifact, appliedOverrides, false, true);
    path.setId("Project path '" + id + "'");

    path = handleMergeAndFlatten(mergeWithCore, flatten, path);

    return path;
  }
Exemplo n.º 4
0
  private void resolvePath(
      List ids,
      List paths,
      boolean mergeWithCore,
      boolean overrideCore,
      Target target,
      boolean flatten) {
    String projectPrefix = "project.";
    String pluginPrefix = "plugin.";
    String propertyPrefix = "property.";

    for (Iterator i = ids.iterator(); i.hasNext(); ) {
      String id = (String) i.next();

      if (id.startsWith(projectPrefix)) {
        String projectPathId = id.substring(projectPrefix.length());
        Assert.isTrue(
            resolvedPaths.get(projectPathId) != null,
            "Project path '" + projectPathId + "' is not defined");
        paths.add(getReslovedProjectPath(projectPathId, mergeWithCore, overrideCore, flatten));
      } else if (id.startsWith(pluginPrefix)) {
        String pluginPathId = id.substring(pluginPrefix.length());
        paths.add(
            getResolvedPluginPath(
                target.getPlugin(), pluginPathId, mergeWithCore, overrideCore, flatten));
      } else if (id.startsWith(propertyPrefix)) {
        String property = id.substring(propertyPrefix.length());
        property = Strings.replace(property, "prefix", target.getPrefix());

        String value = project.getProperties().getProperty(property);

        if (value != null) {
          resolvePath(
              Strings.commaSepList(value), paths, mergeWithCore, overrideCore, target, flatten);
        }
      } else if (id.equals("plugin")) {
        ResolvedPath path = new ResolvedPath();
        path.setId("Plugin:");
        path.add(target.getPlugin().getArtifact());
        paths.add(path);
      } else {
        throw new BuildException(
            "A path group must contain a comma separated list of: plugin | plugin.<pluginpath> | project.<projectpath> | property.<reference to a property containing additional paths>: id="
                + id);
      }
    }
  }
Exemplo n.º 5
0
  /**
   * Returns a set of properties for the project. The precedence is: quokka.properties
   * quokka.properties of inherited projects plugin.properties No expansion or ordering of
   * properties is done
   */
  public AnnotatedProperties getProperties() {
    AnnotatedProperties resolvedProperties = new AnnotatedProperties();

    // Add the global defaults
    resolvedProperties.put("quokka.project.targetDir", "${basedir}/target");
    resolvedProperties.put("quokka.project.sourceDir", "${basedir}/src");
    resolvedProperties.put("quokka.project.resourcesDir", "${basedir}/resources");

    // Add artifact related properties
    if (project.getArtifacts().size() > 0) {
      // Add properties common to all (group & version)
      RepoArtifactId artifactId =
          ((Artifact) getProject().getArtifacts().iterator().next()).getId();
      resolvedProperties.put("quokka.project.artifact.group", artifactId.getGroup());
      resolvedProperties.put("quokka.project.artifact.version", artifactId.getVersion().toString());

      // Build up a list of names by type
      Map namesByType = new HashMap();

      for (Iterator i = project.getArtifacts().iterator(); i.hasNext(); ) {
        Artifact artifact = (Artifact) i.next();
        artifactId = artifact.getId();

        List names = (List) namesByType.get(artifactId.getType());

        if (names == null) {
          names = new ArrayList();
          namesByType.put(artifactId.getType(), names);
        }

        names.add(artifactId.getName());
      }

      // Output the names
      for (Iterator i = namesByType.entrySet().iterator(); i.hasNext(); ) {
        Map.Entry entry = (Map.Entry) i.next();
        List names = (List) entry.getValue();
        resolvedProperties.put(
            "quokka.project.artifact.name[" + entry.getKey() + "]",
            Strings.join(names.iterator(), ","));
      }
    }

    // Put the plugin properties in first. Order is not important as plugin properties should be
    // unique to their plugin
    for (Iterator i = resolvedTargets.values().iterator(); i.hasNext(); ) {
      Target target = (Target) i.next();
      AnnotatedProperties targetProperties = target.getDefaultProperties();
      resolvedProperties.putAll(
          applyProfiles(targetProperties, project.getActiveProfiles().getElements()));
    }

    // Put in any properties defined in dependency sets (processed in reverse to ensure high levels
    // override low levels)
    resolveProperties(resolvedProperties, project.getDependencySet());

    resolvedProperties.putAll(
        applyProfiles(project.getProperties(), project.getActiveProfiles().getElements()));

    // Put the project paths as properties
    for (Iterator i = resolvedPaths.entrySet().iterator(); i.hasNext(); ) {
      Map.Entry entry = (Map.Entry) i.next();
      resolvedProperties.put(
          "quokka.project.path." + entry.getKey(),
          toAntPath(getProjectPath((String) entry.getKey(), false, true)).toString());
    }

    return resolvedProperties;
  }
Exemplo n.º 6
0
  public void initialise() {
    pathResolver = new Resolver(repository, log);

    // Add ant-types path
    project
        .getDependencySet()
        .addPath(
            new Path(
                "ant-types",
                "Dependencies added to this path are available to ant optional tasks."));

    // Get dependency sets, applying profiles and overrides
    List sets = depthFirst(project.getDependencySet());

    // O pass: aggregate overrides
    for (Iterator i = sets.iterator(); i.hasNext(); ) {
      DependencySet set = (DependencySet) i.next();
      overrides.addAll(set.getOverrides());
    }

    // 1st pass: Define targets, paths, imported URLs
    Map targets = new HashMap();

    for (Iterator i = sets.iterator(); i.hasNext(); ) {
      DependencySet set = (DependencySet) i.next();

      // Get targets
      for (Iterator j = set.getDependencies().iterator(); j.hasNext(); ) {
        Dependency dependency = (Dependency) j.next();

        if (dependency instanceof PluginDependency) {
          resolveTargets(targets, (PluginDependency) dependency);
        }
      }

      // Get paths
      for (Iterator j = set.getPaths().values().iterator(); j.hasNext(); ) {
        addPath((Path) j.next());
      }

      if (set.getImportURL() != null) {
        resolvedImports.add(set.getImportURL());
      }

      // Find the unique names for all declared artifacts
      Set uniqueNames = new HashSet();

      for (Iterator j = project.getArtifacts().iterator(); j.hasNext(); ) {
        Artifact artifact = (Artifact) j.next();
        uniqueNames.add(artifact.getId().getName());
      }

      // Create artifacts for any licenses referenced by files
      for (Iterator j = set.getLicenses().iterator(); j.hasNext(); ) {
        License license = (License) j.next();

        if (license.getFile() != null) {
          Assert.isTrue(
              project.getArtifacts().size() != 0,
              license.getLocator(),
              "There are no artifacts defined for a license to be applied to.");

          Artifact artifact = (Artifact) project.getArtifacts().iterator().next();
          RepoArtifactId id = artifact.getId();

          // If no name is specified, default it to name of the artifact if it is unique,
          // otherwise use the default from the group
          String name = license.getId().getName();
          String defaultName = RepoArtifactId.defaultName(id.getGroup());

          if (name == null) {
            if (uniqueNames.size() == 1) {
              name = (String) uniqueNames.iterator().next();
            } else {
              name = defaultName;
            }
          }

          Artifact licenseArtifact = new Artifact(id.getGroup(), name, "license", id.getVersion());
          licenseArtifact.setDescription(
              "License for " + id.getGroup() + (name.equals(defaultName) ? "" : (":" + name)));
          project.addArtifact(licenseArtifact);
          license.setId(licenseArtifact.getId());
        }
      }
    }

    // 2nd pass: Define default paths specs, add imported targets
    for (Iterator i = sets.iterator(); i.hasNext(); ) {
      DependencySet set = (DependencySet) i.next();

      // Fill in path spec defaults now that the project paths have been defined
      addPathSpecDefaults(set);
    }

    // 3rd pass: Reverse order for build resources
    List reverse = new ArrayList(sets);
    Collections.reverse(reverse);

    for (Iterator i = reverse.iterator(); i.hasNext(); ) {
      DependencySet set = (DependencySet) i.next();
      buildResources.putAll(set.getBuildResources()); // Parent overrides children
    }

    resolvedTargets = targets;
    corePath = resolveCorePath();

    if ("true".equals(antProject.getProperty("quokka.project.overrideCore"))) {
      coreOverrides = getCoreOverrides();
    }
  }