예제 #1
0
  private Set getDependencies(ProjectModel model) {
    Set dependencies = new HashSet();
    getDependencies(dependencies, model.getProject().getDependencySet());

    return dependencies;
  }
예제 #2
0
  private List generateSequence(List projects) {
    DefaultModelFactory factory = new DefaultModelFactory();
    Repository repository = (Repository) getProject().getReference("q.project.repository");
    factory.setRepository(repository);

    // 1st pass: map artifacts generated from each project to a target representing their project
    // files
    Project tempProject = new Project();

    Map targetsByArtifact = new HashMap();
    Map targetsByProject = new HashMap();
    List models = new ArrayList();

    for (Iterator i = projects.iterator(); i.hasNext(); ) {
      File projectFile = (File) i.next();

      // For now, we assume the default profile will contain all dependencies
      ProjectModel model =
          factory.getProjectModel(
              projectFile, Collections.EMPTY_LIST, true, null, new TaskLogger(this), getProject());
      models.add(model);

      // Create a target for each project file
      Target target = new Target();
      target.setName(projectFile.getAbsolutePath());
      tempProject.addTarget(target);
      targetsByProject.put(model.getProject().getProjectFile(), target);

      // Map the artifacts to the target
      for (Iterator j = model.getProject().getArtifacts().iterator(); j.hasNext(); ) {
        Artifact artifact = (Artifact) j.next();
        targetsByArtifact.put(artifact.getId(), target);
      }
    }

    // 2nd pass: Process project dependencies. Where a dependency uses an artifactId found in the
    // 1st pass,
    // set up a dependency between the projects.
    for (Iterator i = models.iterator(); i.hasNext(); ) {
      ProjectModel model = (ProjectModel) i.next();
      Target projectTarget = (Target) targetsByProject.get(model.getProject().getProjectFile());

      Set dependencies = getDependencies(model);

      // Where there is a dependency between projects, mirror it in the targets
      for (Iterator j = dependencies.iterator(); j.hasNext(); ) {
        RepoArtifactId id = (RepoArtifactId) j.next();
        Target dependencyTarget = (Target) targetsByArtifact.get(id);

        if (dependencyTarget != null) {
          projectTarget.addDependency(dependencyTarget.getName());
        }
      }
    }

    // Use ANT's target dependency mechanism to produce a build sequence
    String anyTarget = ((Target) targetsByArtifact.values().iterator().next()).getName();
    Collection sequencedTargets = tempProject.topoSort(anyTarget, tempProject.getTargets());

    // Transform targets into a list of files
    List sequence = new ArrayList();

    for (Iterator i = sequencedTargets.iterator(); i.hasNext(); ) {
      Target seqTarget = (Target) i.next();
      sequence.add(new File(seqTarget.getName()));
    }

    return sequence;
  }