예제 #1
0
  /**
   * Returns true if any of the builds recorded in this fingerprint is still retained.
   *
   * <p>This is used to find out old fingerprint records that can be removed without losing too much
   * information.
   */
  public synchronized boolean isAlive() {
    if (original != null && original.isAlive()) return true;

    for (Entry<String, RangeSet> e : usages.entrySet()) {
      Job j = Jenkins.getInstance().getItemByFullName(e.getKey(), Job.class);
      if (j == null) continue;

      Run firstBuild = j.getFirstBuild();
      if (firstBuild == null) continue;

      int oldest = firstBuild.getNumber();
      if (!e.getValue().isSmallerThan(oldest)) return true;
    }
    return false;
  }
  /** Graph of duration of tests over time. */
  public Graph getSummaryGraph() {
    // The standard equals doesn't work because two LocalDate objects can
    // be differente even if the date is the same (different internal
    // timestamp)
    Comparator<LocalDate> localDateComparator =
        new Comparator<LocalDate>() {

          @Override
          public int compare(LocalDate d1, LocalDate d2) {
            if (d1.isEqual(d2)) {
              return 0;
            }
            if (d1.isAfter(d2)) {
              return 1;
            }
            return -1;
          }
        };

    // We need a custom comparator for LocalDate objects
    final Map<LocalDate, TestResultSummary> summaries = // new
        // HashMap<LocalDate,
        // TestResultSummary>();
        new TreeMap<LocalDate, TestResultSummary>(localDateComparator);
    LocalDate today =
        new LocalDate(
            System.currentTimeMillis() - dateShift * 6000, GregorianChronology.getInstanceUTC());

    // for each job, for each day, add last build of the day to summary
    for (Job job : getDashboard().getJobs()) {
      Run run = job.getFirstBuild();

      if (run != null) { // execute only if job has builds
        LocalDate runDay =
            new LocalDate(
                run.getTimeInMillis() - dateShift * 60000, GregorianChronology.getInstanceUTC());
        LocalDate firstDay =
            (dateRange != 0)
                ? new LocalDate(
                        System.currentTimeMillis() - dateShift * 6000,
                        GregorianChronology.getInstanceUTC())
                    .minusDays(dateRange)
                : runDay;

        while (run != null) {
          runDay =
              new LocalDate(
                  run.getTimeInMillis() - dateShift * 60000, GregorianChronology.getInstanceUTC());
          Run nextRun = run.getNextBuild();

          if (nextRun != null) {
            LocalDate nextRunDay =
                new LocalDate(
                    nextRun.getTimeInMillis() - dateShift * 60000,
                    GregorianChronology.getInstanceUTC());
            // skip run before firstDay, but keep if next build is
            // after start date
            if (!runDay.isBefore(firstDay)
                || runDay.isBefore(firstDay) && !nextRunDay.isBefore(firstDay)) {
              // if next run is not the same day, use this test to
              // summarize
              if (nextRunDay.isAfter(runDay)) {
                summarize(
                    summaries,
                    run,
                    (runDay.isBefore(firstDay) ? firstDay : runDay),
                    nextRunDay.minusDays(1));
              }
            }
          } else {
            // use this run's test result from last run to today
            summarize(summaries, run, (runDay.isBefore(firstDay) ? firstDay : runDay), today);
          }

          run = nextRun;
        }
      }
    }

    return new Graph(-1, getGraphWidth(), getGraphHeight()) {

      @Override
      protected JFreeChart createGraph() {
        final JFreeChart chart =
            ChartFactory.createStackedAreaChart(
                null, // chart title
                Messages.Dashboard_Date(), // unused
                Messages.Dashboard_Count(), // range axis label
                buildDataSet(summaries), // data
                PlotOrientation.VERTICAL, // orientation
                false, // include legend
                false, // tooltips
                false // urls
                );

        chart.setBackgroundPaint(Color.white);

        final CategoryPlot plot = chart.getCategoryPlot();

        plot.setBackgroundPaint(Color.WHITE);
        plot.setOutlinePaint(null);
        plot.setForegroundAlpha(0.8f);
        plot.setRangeGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.black);

        CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
        plot.setDomainAxis(domainAxis);
        domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
        domainAxis.setLowerMargin(0.0);
        domainAxis.setUpperMargin(0.0);
        domainAxis.setCategoryMargin(0.0);

        final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

        StackedAreaRenderer ar = new StackedAreaRenderer2();
        plot.setRenderer(ar);

        switch (getDisplayStatusEnum()) {
          case SUCCESS:
            ar.setSeriesPaint(0, ColorPalette.BLUE);
            break;
          case SKIPPED:
            ar.setSeriesPaint(0, ColorPalette.YELLOW);
            break;
          case FAILED:
            ar.setSeriesPaint(0, ColorPalette.RED);
            break;
          default:
            ar.setSeriesPaint(0, ColorPalette.RED); // Failures.
            ar.setSeriesPaint(1, ColorPalette.YELLOW); // Skips.
            ar.setSeriesPaint(2, ColorPalette.BLUE); // Total.
        }

        // crop extra space around the graph
        plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));

        return chart;
      }
    };
  }