Esempio n. 1
0
  /** Accepts submission from the configuration page. */
  @RequirePOST
  public synchronized void doConfigSubmit(StaplerRequest req, StaplerResponse rsp)
      throws IOException, ServletException, FormException {
    checkPermission(CONFIGURE);

    description = req.getParameter("description");

    keepDependencies = req.getParameter("keepDependencies") != null;

    try {
      JSONObject json = req.getSubmittedForm();

      setDisplayName(json.optString("displayNameOrNull"));

      if (req.getParameter("logrotate") != null)
        logRotator = LogRotator.DESCRIPTOR.newInstance(req, json.getJSONObject("logrotate"));
      else logRotator = null;

      DescribableList<JobProperty<?>, JobPropertyDescriptor> t =
          new DescribableList<JobProperty<?>, JobPropertyDescriptor>(NOOP, getAllProperties());
      t.rebuild(
          req,
          json.optJSONObject("properties"),
          JobPropertyDescriptor.getPropertyDescriptors(Job.this.getClass()));
      properties.clear();
      for (JobProperty p : t) {
        p.setOwner(this);
        properties.add(p);
      }

      submit(req, rsp);

      save();
      ItemListener.fireOnUpdated(this);

      String newName = req.getParameter("name");
      final ProjectNamingStrategy namingStrategy = Jenkins.getInstance().getProjectNamingStrategy();
      if (newName != null && !newName.equals(name)) {
        // check this error early to avoid HTTP response splitting.
        Jenkins.checkGoodName(newName);
        namingStrategy.checkName(newName);
        rsp.sendRedirect("rename?newName=" + URLEncoder.encode(newName, "UTF-8"));
      } else {
        if (namingStrategy.isForceExistingJobs()) {
          namingStrategy.checkName(name);
        }
        FormApply.success(".").generateResponse(req, rsp, null);
      }
    } catch (JSONException e) {
      StringWriter sw = new StringWriter();
      PrintWriter pw = new PrintWriter(sw);
      pw.println("Failed to parse form data. Please report this problem as a bug");
      pw.println("JSON=" + req.getSubmittedForm());
      pw.println();
      e.printStackTrace(pw);

      rsp.setStatus(SC_BAD_REQUEST);
      sendError(sw.toString(), req, rsp, true);
    }
  }
Esempio n. 2
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);
  }
Esempio n. 3
0
 /** Overrides from job properties. */
 public Collection<?> getOverrides() {
   List<Object> r = new ArrayList<Object>();
   for (JobProperty<? super JobT> p : properties) r.addAll(p.getJobOverrides());
   return r;
 }
Esempio n. 4
0
 /**
  * Bind {@link JobProperty}s to URL spaces.
  *
  * @since 1.403
  */
 public JobProperty getProperty(String className) {
   for (JobProperty p : properties) if (p.getClass().getName().equals(className)) return p;
   return null;
 }
Esempio n. 5
0
 /**
  * Adds {@link JobProperty}.
  *
  * @since 1.188
  */
 public void addProperty(JobProperty<? super JobT> jobProp) throws IOException {
   ((JobProperty) jobProp).setOwner(this);
   properties.add(jobProp);
   save();
 }