Ejemplo n.º 1
0
  public synchronized TopLevelItem createProject(
      TopLevelItemDescriptor type, String name, boolean notify) throws IOException {
    acl.checkPermission(Job.CREATE);

    Jenkins.getInstance().getProjectNamingStrategy().checkName(name);
    if (parent.getItem(name) != null)
      throw new IllegalArgumentException("Project of the name " + name + " already exists");

    TopLevelItem item;
    try {
      item = type.newInstance(parent, name);
    } catch (Exception e) {
      throw new IllegalArgumentException(e);
    }
    try {
      callOnCreatedFromScratch(item);
    } catch (AbstractMethodError e) {
      // ignore this error. Must be older plugin that doesn't have this method
    }
    item.save();
    add(item);
    Jenkins.getInstance().rebuildDependencyGraph();

    if (notify) ItemListener.fireOnCreated(item);

    return item;
  }
Ejemplo n.º 2
0
  public synchronized TopLevelItem createProjectFromXML(String name, InputStream xml)
      throws IOException {
    acl.checkPermission(Job.CREATE);

    Jenkins.getInstance().getProjectNamingStrategy().checkName(name);
    // place it as config.xml
    File configXml = Items.getConfigFile(getRootDirFor(name)).getFile();
    configXml.getParentFile().mkdirs();
    try {
      IOUtils.copy(xml, configXml);

      // load it
      TopLevelItem result;
      Items.updatingByXml.set(true);
      try {
        result = (TopLevelItem) Items.load(parent, configXml.getParentFile());
      } finally {
        Items.updatingByXml.set(false);
      }
      add(result);

      ItemListener.fireOnCreated(result);
      Jenkins.getInstance().rebuildDependencyGraph();

      return result;
    } catch (IOException e) {
      // if anything fails, delete the config file to avoid further confusion
      Util.deleteRecursive(configXml.getParentFile());
      throw e;
    }
  }