Ejemplo n.º 1
0
  public TargetDetail targetFrom(BuildType buildType) {
    final BuildTypeDetail buildTypeDetail = communicator.detailsFor(buildType);

    if (buildTypeDetail.paused) {
      return new TargetDetail(
          communicator.endpoint() + buildType.href,
          buildType.webUrl(),
          buildType.name,
          Status.DISABLED,
          0L);
    }

    final Set<Sponsor> sponsors = new HashSet<Sponsor>();
    final List<RunningBuild> runningBuilds = new ArrayList<RunningBuild>();
    long startTime = 0L;

    for (Build build : communicator.runningBuildsFor(buildType)) {
      final BuildDetail buildDetail = communicator.detailsOf(build);
      startTime = Math.max(buildDetail.startDateTime(), startTime);
      sponsors.addAll(sponsorsOf(buildDetail));
      runningBuilds.add(
          new RunningBuild(percentageOf(build.percentageComplete), buildDetail.status()));
    }

    Status currentStatus = Status.GREEN;
    final Build lastCompletedBuild = communicator.lastCompletedBuildFor(buildTypeDetail);
    if (null != lastCompletedBuild) {
      currentStatus = lastCompletedBuild.status();
      if (runningBuilds.isEmpty() || Status.BROKEN.equals(currentStatus)) {
        final BuildDetail buildDetail = communicator.detailsOf(lastCompletedBuild);
        startTime = Math.max(buildDetail.startDateTime(), startTime);
        sponsors.addAll(sponsorsOf(buildDetail));
        currentStatus = buildDetail.status();
      }
    }

    return new TargetDetail(
        communicator.endpoint() + buildType.href,
        buildType.webUrl(),
        buildType.name,
        currentStatus,
        startTime,
        runningBuilds,
        sponsors);
  }