Beispiel #1
0
  @Override
  public void onLoad(ItemGroup<? extends Item> parent, String name) throws IOException {
    super.onLoad(parent, name);

    TextFile f = getNextBuildNumberFile();
    if (f.exists()) {
      // starting 1.28, we store nextBuildNumber in a separate file.
      // but old Hudson didn't do it, so if the file doesn't exist,
      // assume that nextBuildNumber was read from config.xml
      try {
        synchronized (this) {
          this.nextBuildNumber = Integer.parseInt(f.readTrim());
        }
      } catch (NumberFormatException e) {
        // try to infer the value of the next build number from the existing build records. See
        // JENKINS-11563
        File[] folders =
            this.getBuildDir()
                .listFiles(
                    new FileFilter() {
                      public boolean accept(File file) {
                        return file.isDirectory() && file.getName().matches("[0-9]+");
                      }
                    });

        if (folders == null || folders.length == 0) {
          this.nextBuildNumber = 1;
        } else {
          Collection<Integer> foldersInt =
              Collections2.transform(
                  Arrays.asList(folders),
                  new Function<File, Integer>() {
                    public Integer apply(File file) {
                      return Integer.parseInt(file.getName());
                    }
                  });
          this.nextBuildNumber = Collections.max(foldersInt) + 1;
        }
        saveNextBuildNumber();
      }
    } else {
      // From the old Hudson, or doCreateItem. Create this file now.
      saveNextBuildNumber();
      save(); // and delete it from the config.xml
    }

    if (properties == null) // didn't exist < 1.72
    properties = new CopyOnWriteList<JobProperty<? super JobT>>();

    for (JobProperty p : properties) p.setOwner(this);
  }
Beispiel #2
0
  @Exported(name = "healthReport")
  public List<HealthReport> getBuildHealthReports() {
    List<HealthReport> reports = new ArrayList<HealthReport>();
    RunT lastBuild = getLastBuild();

    if (lastBuild != null && lastBuild.isBuilding()) {
      // show the previous build's report until the current one is
      // finished building.
      lastBuild = lastBuild.getPreviousBuild();
    }

    // check the cache
    if (cachedBuildHealthReportsBuildNumber != null
        && cachedBuildHealthReports != null
        && lastBuild != null
        && cachedBuildHealthReportsBuildNumber.intValue() == lastBuild.getNumber()) {
      reports.addAll(cachedBuildHealthReports);
    } else if (lastBuild != null) {
      for (HealthReportingAction healthReportingAction :
          lastBuild.getActions(HealthReportingAction.class)) {
        final HealthReport report = healthReportingAction.getBuildHealth();
        if (report != null) {
          if (report.isAggregateReport()) {
            reports.addAll(report.getAggregatedReports());
          } else {
            reports.add(report);
          }
        }
      }
      final HealthReport report = getBuildStabilityHealthReport();
      if (report != null) {
        if (report.isAggregateReport()) {
          reports.addAll(report.getAggregatedReports());
        } else {
          reports.add(report);
        }
      }

      Collections.sort(reports);

      // store the cache
      cachedBuildHealthReportsBuildNumber = lastBuild.getNumber();
      cachedBuildHealthReports = new ArrayList<HealthReport>(reports);
    }

    return reports;
  }
Beispiel #3
0
 /** Gets all the builds in a map. */
 public SortedMap<Integer, RunT> getBuildsAsMap() {
   return Collections.unmodifiableSortedMap(_getRuns());
 }
Beispiel #4
0
 public Collection<? extends Job> getAllJobs() {
   return Collections.<Job>singleton(this);
 }