/**
   * @see
   *     org.jenkins.plugins.audit2db.reports.JobsByParamReport#getProjectExecutions(java.lang.String,
   *     java.lang.String, java.lang.String, java.lang.String)
   */
  @Override
  public Map<String, List<BuildDetails>> getProjectExecutions(
      final String paramName,
      final String paramValue,
      final String startDateString,
      final String endDateString) {
    final Jenkins jenkins = Jenkins.getInstance();
    if (jenkins != null) {
      // unit tests won't have a Jenkins instance
      jenkins.checkPermission(DbAuditPlugin.RUN);
    }
    final Map<String, List<BuildDetails>> retval = new HashMap<String, List<BuildDetails>>();
    final Date startDate = DbAuditReportUtils.stringToDate(startDateString);
    final Date endDate = DbAuditReportUtils.stringToDate(endDateString);
    final String jenkinsHost = getJenkinsHostname();
    final List<BuildDetails> buildDetails =
        getRepository()
            .getBuildDetailsByParams(jenkinsHost, paramName, paramValue, startDate, endDate);

    for (final BuildDetails details : buildDetails) {
      final String projectName = details.getName();
      if (!retval.containsKey(projectName)) {
        retval.put(projectName, new ArrayList<BuildDetails>());
      }
      retval.get(projectName).add(details);
    }

    return retval;
  }
Esempio n. 2
0
  /** Bare-minimum configuration mechanism to change the update center. */
  public HttpResponse doSiteConfigure(@QueryParameter String site) throws IOException {
    Jenkins hudson = Jenkins.getInstance();
    hudson.checkPermission(CONFIGURE_UPDATECENTER);
    UpdateCenter uc = hudson.getUpdateCenter();
    PersistedList<UpdateSite> sites = uc.getSites();
    for (UpdateSite s : sites) {
      if (s.getId().equals(UpdateCenter.ID_DEFAULT)) sites.remove(s);
    }
    sites.add(new UpdateSite(UpdateCenter.ID_DEFAULT, site));

    return HttpResponses.redirectToContextRoot();
  }
Esempio n. 3
0
  public HttpResponse doProxyConfigure(StaplerRequest req) throws IOException, ServletException {
    Jenkins jenkins = Jenkins.getInstance();
    jenkins.checkPermission(CONFIGURE_UPDATECENTER);

    ProxyConfiguration pc = req.bindJSON(ProxyConfiguration.class, req.getSubmittedForm());
    if (pc.name == null) {
      jenkins.proxy = null;
      ProxyConfiguration.getXmlFile().delete();
    } else {
      jenkins.proxy = pc;
      jenkins.proxy.save();
    }
    return new HttpRedirect("advanced");
  }
Esempio n. 4
0
  /** Accepts the update to the node configuration. */
  @RequirePOST
  public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp)
      throws IOException, ServletException, FormException {
    final Jenkins app = Jenkins.getInstance();

    app.checkPermission(Jenkins.ADMINISTER);

    properties.rebuild(req, req.getSubmittedForm(), getApplicablePropertyDescriptors());

    this.description = req.getSubmittedForm().getString("description");

    updateTransientActions();
    save();

    FormApply.success(".").generateResponse(req, rsp, null);
  }
  @Override
  public Map<String, List<BuildDetails>> getProjectExecutions(
      final String jobName, final String startDateString, final String endDateString) {
    final Jenkins jenkins = Jenkins.getInstance();
    if (jenkins != null) {
      // unit tests won't have a Jenkins instance
      jenkins.checkPermission(DbAuditPlugin.RUN);
    }
    final Map<String, List<BuildDetails>> retval = new HashMap<String, List<BuildDetails>>();
    final Date startDate = DbAuditReportUtils.stringToDate(startDateString);
    final Date endDate = DbAuditReportUtils.stringToDate(endDateString);
    final String jenkinsHost = getJenkinsHostname();
    final List<String> projectNames =
        getRepository().getProjectNames(jenkinsHost, jobName, startDate, endDate);
    for (final String projectName : projectNames) {
      final List<BuildDetails> buildDetails =
          getRepository().getBuildDetails(jenkinsHost, projectName, startDate, endDate);
      if (!buildDetails.isEmpty()) {
        retval.put(projectName, buildDetails);
      }
    }

    return retval;
  }
  protected int run() throws Exception {
    Jenkins h = Jenkins.getInstance();
    h.checkPermission(Jenkins.READ);

    // where is this build running?
    BuildIDs id = checkChannel().call(new BuildIDs());

    if (!id.isComplete())
      throw new AbortException(
          "This command can be only invoked from a build executing inside Hudson");

    AbstractProject p = Jenkins.getInstance().getItemByFullName(id.job, AbstractProject.class);
    if (p == null) throw new AbortException("No such job found: " + id.job);
    p.checkPermission(Item.CONFIGURE);

    List<String> toolTypes = new ArrayList<String>();
    for (ToolDescriptor<?> d : ToolInstallation.all()) {
      toolTypes.add(d.getDisplayName());
      if (d.getDisplayName().equals(toolType)) {
        List<String> toolNames = new ArrayList<String>();
        for (ToolInstallation t : d.getInstallations()) {
          toolNames.add(t.getName());
          if (t.getName().equals(toolName)) return install(t, id, p);
        }

        // didn't find the right tool name
        error(toolNames, toolName, "name");
      }
    }

    // didn't find the tool type
    error(toolTypes, toolType, "type");

    // will never be here
    throw new AssertionError();
  }