Create a job on the server (in the given folder)

@param folder {@link FolderJob}
@param jobName name of the job.
@param crumbFlag <code>true</code> to add <b>crumbIssuer</b>
<code>false</code> otherwise.
@throws IOException in case of an error.
517215
public JenkinsServer createFolder(FolderJob folder, String jobName, Boolean crumbFlag) throws IOException {
        // https://gist.github.com/stuart-warren/7786892 was slightly helpful
        // here
        //TODO: JDK9+: Map.of(...)
        Map<String, String> params = new HashMap<>();
        params.put("mode", "com.cloudbees.hudson.plugins.folder.Folder");
        params.put("name", jobName);
        params.put("from", "");
        params.put("Submit", "OK");
        client.post_form(UrlUtils.toBaseUrl(folder) + "createItem?", params, crumbFlag);
        return this;
    }
1125289
public BoxFolder.Info createFolder(String name) {
        JsonObject parent = new JsonObject();
        parent.add("id", this.getID());

        JsonObject newFolder = new JsonObject();
        newFolder.add("name", name);
        newFolder.add("parent", parent);

        BoxJSONRequest request = new BoxJSONRequest(this.getAPI(), CREATE_FOLDER_URL.build(this.getAPI().getBaseURL()),
                "POST");
        request.setBody(newFolder.toString());
        BoxJSONResponse response = (BoxJSONResponse) request.send();
        JsonObject responseJSON = JsonObject.readFrom(response.getJSON());

        BoxFolder createdFolder = new BoxFolder(this.getAPI(), responseJSON.get("id").asString());
        return createdFolder.new Info(responseJSON);
    }
126018
private void registerFolder(final Path folder) throws IOException {
        // register directory and sub-directories
        Files.walkFileTree(folder, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
                    throws IOException
            {
                WatchKey key = dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
                logger.debug("registering folder {}", dir);
                folders.put(key, dir);
                return FileVisitResult.CONTINUE;
            }
        });
    }
759981
public JenkinsServer enableJob(String jobName, boolean crumbFlag) throws IOException {
        client.post("/job/" + EncodingUtils.encode(jobName) + "/enable", crumbFlag);
        return this;
    }
790755
@Override
  public final void setupJob(org.apache.hadoop.mapreduce.JobContext jobContext
                             ) throws IOException {
    setupJob((JobContext) jobContext);
  }
788115
@POST
  @Produces(APPLICATION_JSON)
  @Timed
  @ExceptionMetered
  public CreateJobResponse post(@Valid final Job job,
                                @RequestUser final String username) {
    final Job.Builder clone = job.toBuilder()
        .setCreatingUser(username)
        .setCreated(clock.now().getMillis())
        // If the job had a hash coming in, preserve it
        .setHash(job.getId().getHash());
    final Job actualJob = clone.build();
    final Collection<String> errors = jobValidator.validate(actualJob);
    final String jobIdString = actualJob.getId().toString();
    if (!errors.isEmpty()) {
      throw badRequest(new CreateJobResponse(INVALID_JOB_DEFINITION, ImmutableList.copyOf(errors),
          jobIdString));
    }
    try {
      model.addJob(actualJob);
    } catch (JobExistsException e) {
      throw badRequest(new CreateJobResponse(JOB_ALREADY_EXISTS, ImmutableList.<String>of(),
          jobIdString));
    }
    log.info("created job: {}", actualJob);
    return new CreateJobResponse(CreateJobResponse.Status.OK, ImmutableList.<String>of(),
        jobIdString);
  }
995232
public URI uploadFile(final String jobFolder, final File file) throws IOException {

    LOG.log(Level.INFO, "Uploading [{0}] to [{1}]", new Object[]{file, jobFolder});

    try {
      final CloudBlobClient cloudBlobClient = this.cloudBlobClientProvider.getCloudBlobClient();
      final CloudBlobContainer container = cloudBlobClient.getContainerReference(this.azureStorageContainerName);

      final String destination = String.format("%s/%s", jobFolder, file.getName());
      final CloudBlockBlob blob = container.getBlockBlobReference(destination);

      try (FileInputStream fis = new FileInputStream(file)) {
        blob.upload(fis, file.length());
      }

      LOG.log(Level.FINE, "Uploaded to: {0}", blob.getStorageUri().getPrimaryUri());
      return this.cloudBlobClientProvider.generateSharedAccessSignature(blob, getSharedAccessBlobPolicy());

    } catch (final URISyntaxException | StorageException e) {
      throw new IOException(e);
    }
  }
654688
public JenkinsServer restart(Boolean crumbFlag) throws IOException {
		try {
			client.post("/restart", crumbFlag);
		} catch (org.apache.http.client.ClientProtocolException e) {
			LOGGER.error("restart()", e);
		}
        return this;
	}
1252996
@SuppressWarnings("deprecation")
    public CmsResource createFolder(String targetFolder, String folderName) throws Exception {

        if (m_cms.existsResource(targetFolder + folderName)) {
            m_shell.getOut().println(
                getMessages().key(Messages.GUI_SHELL_FOLDER_ALREADY_EXISTS_1, targetFolder + folderName));
            return null;
        }
        return m_cms.createResource(targetFolder + folderName, CmsResourceTypeFolder.getStaticTypeId());
    }
225028
public static String toJobBaseUrl(final FolderJob folder, final String jobName) {
        final StringBuilder sb = new StringBuilder(DEFAULT_BUFFER_SIZE);
        sb.append(UrlUtils.toBaseUrl(folder));
        if (sb.charAt(sb.length() - 1) != '/') sb.append('/');
        sb.append("job/");
        final String[] jobNameParts = jobName.split("/");
        
        for (int i = 0; i < jobNameParts.length; i++) {
            sb.append(EncodingUtils.encode(jobNameParts[i]));
            if (i != jobNameParts.length - 1) sb.append('/');
        }
        return sb.toString();
    }
1119073
public void addJobType(final String jobName, final Class<?> jobType) {
        checkJobType(jobName, jobType);
        this.jobTypes.put(jobName, jobType);
    }
20055
public static void addFolderToZip(String path, String srcFolder, ZipOutputStream zip) throws IOException {
        File folder = new File(srcFolder);
        if (folder.list().length == 0) {
            addFileToZip(path, srcFolder, zip, true);
        } else {
            for (String fileName : folder.list()) {
                if (path.equals("")) {
                    addFileToZip(folder.getName(), srcFolder + "/" + fileName, zip, false);
                } else {
                    addFileToZip(path + "/" + folder.getName(), srcFolder + "/" + fileName, zip, false);
                }
            }
        }
    }
175040
public static boolean zipFolder(File folder, String fileName){
		boolean success = false;
		if(!folder.isDirectory()){
			return false;
		}
		
		if(fileName == null){
			fileName = folder.getAbsolutePath()+ZIP_EXT;
		}
		
		ZipArchiveOutputStream zipOutput = null;
		try {
			zipOutput = new ZipArchiveOutputStream(new File(fileName));
			
			success = addFolderContentToZip(folder,zipOutput,"");

			zipOutput.close();
		
		} catch (IOException e) {
			e.printStackTrace();
			return false;
		}
		finally{
			try {
				if(zipOutput != null){
					zipOutput.close();
				}
			} catch (IOException e) {}
		}
		return success;
	}
845468
public Job createJob(String query) {
    // [START ]
    Job job = null;
    JobConfiguration jobConfiguration = QueryJobConfiguration.of(query);
    JobInfo jobInfo = JobInfo.of(jobConfiguration);
    try {
      job = bigquery.create(jobInfo);
    } catch (BigQueryException e) {
      // the job was not created
    }
    // [END ]
    return job;
  }
624645
private static void setJobName(Map<String,String> map, String jobName) {
		map.put(JOB_NAME_KEY, jobName);
	}
642069
public QueueReference build(Map<String, String> params, boolean crumbFlag) throws IOException {
        return build(params,null,crumbFlag);
    }
329101
public void mkdir(String folderName) {
    try {
      getDFS().mkdirs(new Path(this.path, folderName));
    } catch (IOException ioe) {
      ioe.printStackTrace();
    }
    doRefresh();
  }