/******************************************************************************* Copyright (c) 2011, Perforce Software, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ /******************************************************************************* * Name : Repository.Job.cs * * Author : dbb * * Description : Job operations for the Repository. * ******************************************************************************/ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace Perforce.P4 { public partial class Repository { /// /// Create a new job in the repository. /// /// Job specification for the new job /// The '-i' flags is needed when creating a new job /// The Job object if new job was created, null if creation failed /// The '-i' flags is added if not specified by the caller ///
///
p4 help job ///
///
job -- Create or edit a job (defect) specification ///
///
p4 job [-f] [jobName] ///
p4 job -d jobName ///
p4 job -o [jobName] ///
p4 job -i [-f] ///
///
The 'p4 job' command creates and edits job specifications using an ///
ASCII form. A job is a defect, enhancement, or other unit of ///
intended work.The 'p4 fix' command associates changelists with jobs. ///
///
With no arguments, 'p4 job' creates an empty job specification ///
and invokes the user's editor. When the specification is saved, ///
a job name of the form jobNNNNNN is assigned. If the jobName ///
parameter is specified on the command line, the job is created or ///
opened for editing. ///
///
As jobs are entered or updated, all fields are indexed for searching ///
Text fields are broken into individual alphanumeric words (punctuation ///
and whitespace are ignored) and each word is case-folded and entered ///
into the word index. Date fields are converted to an internal ///
representation (seconds since 1970/01/01 00:00:00) and entered ///
into the date index. ///
///
The fields that compose a job are defined by the 'p4 jobspec' command. ///
Perforce provides a default job specification that you can edit. ///
///
The -d flag deletes the specified job. You cannot delete a job if ///
it has pending or submitted fixes associated with it. ///
///
The -o flag writes the job specification to the standard output. ///
The user's editor is not invoked. ///
///
The -i flag reads a job specification from the standard input. The ///
user's editor is not invoked. ///
///
The -f flag enables you set fields that are read-only by default. ///
The -f flag requires 'admin' access, which is granted using the ///
'p4 protect' command. ///
///
///
/// /// To create a new job with a name 'Myjob': /// /// /// Job job = new Job(); /// job.Id = "Myjob"; /// job.Add("Status", "open"); /// job.Add("User", "admin"); /// job.Add("Description", "this is a test job"); /// Job job = _repository.CreateJob( job, null); /// /// /// To create a job with name of the form jobNNNNNN: /// /// /// Job job = new Job(); /// job.Id = "new"; /// job.Add("Status", "open"); /// job.Add("User", "admin"); /// job.Add("Description", "this is a test job"); /// Job job = _repository.CreateJob( job, JobCmdFlags.Input); /// /// /// /// public Job CreateJob(Job job, Options options) { if (job == null) { throw new ArgumentNullException("job"); } P4Command cmd = new P4Command(this, "job", true); cmd.DataSet = job.ToString(); if (options == null) { options = new Options(); } options["-i"] = null; P4CommandResult results = cmd.Run(options); if (results.Success) { // If this a new job that was saved, we need to parse out the new job Id if (job.Id == "new") { string[] words = results.InfoOutput[0].Info.Split(' '); string newId = words[1]; Job newJob = GetJob(newId); return newJob; } else { Job newJob = GetJob(job.Id); return newJob; } } else { P4Exception.Throw(results.ErrorList); } return null; } /// /// Create a new job in the repository. /// /// Job specification for the new job /// The Job object if new job was created, null if creation failed /// /// To create a new job name of the form jobNNNNNN: /// /// /// Job job = new Job(); /// job.Id = new; /// job.Add("Status", "open"); /// job.Add("User", "admin"); /// job.Add("Description", "this is a test job"); /// Job job = _repository.CreateJob( job ); /// /// /// public Job CreateJob(Job job) { return CreateJob(job, null); } /// /// Update the record for a job in the repository /// /// Job specification for the job being updated /// The Job object if new job was saved, null if creation failed /// /// To update the description of job 'job000001': /// /// /// Job job = _repository.GetJob("job000001"); /// job["Description"] += "\n\Updated description"; /// _repository.UpdateJob("job000001"); /// /// /// public Job UpdateJob(Job job) { return CreateJob(job, null); } /// /// Get the record for an existing job from the repository. /// /// Job name /// There are no valid flags to use when fetching an existing job /// The Job object if new job was found, null if the requested job does not exist /// /// Get the record for job 'job000001': /// /// /// Job job = _repository.GetJob("job000001", null); /// /// /// public Job GetJob(string job, Options options) { if (job == null) { throw new ArgumentNullException("job"); } P4Command cmd = new P4Command(this, "job", true, job); if (options == null) { options = new Options(); } options["-o"] = null; P4CommandResult results = cmd.Run(options); if (results.Success) { if ((results.TaggedOutput == null) || (results.TaggedOutput.Count <= 0)) { return null; } Job value = new Job(); value.FromJobCmdTaggedOutput((results.TaggedOutput[0])); return value; } else { P4Exception.Throw(results.ErrorList); } return null; } /// /// Get the record for an existing job from the repository. /// /// Job name /// The Job object if new job was found, null if the requested job does not exist /// /// Get the record for job 'job000001': /// /// /// Job job = _repository.GetJob("job000001"); /// /// /// public Job GetJob(string job) { return GetJob(job, null); } /// /// Get a list of jobs from the repository /// /// options for the jobs command /// A list containing the matching jobs /// ///
p4 help jobs ///
///
jobs -- Display list of jobs ///
///
p4 jobs [-e jobview -i -l -m max -r] [file[revRange] ...] ///
p4 jobs -R ///
///
Lists jobs in the server. If a file specification is included, fixes ///
for submitted changelists affecting the specified files are listed. ///
The file specification can include wildcards and a revision range. ///
See 'p4 help revisions' for details about specifying revisions. ///
///
The -e flag lists jobs matching the expression specified in the ///
jobview parameter. For a description of jobview syntax, see 'p4 help ///
jobview'. ///
///
The -i flag includes any fixes made by changelists integrated into ///
the specified files. ///
///
The -l flag produces long output with the full text of the job ///
descriptions. ///
///
The -m max flag limits the output to the first 'max' jobs, ordered ///
by their job name. ///
///
The -r flag sorts the jobs in reverse order (by job name). ///
///
The -R flag rebuilds the jobs table and reindexes each job, which ///
is necessary after upgrading to 98.2. 'p4 jobs -R' requires that ///
that the user be an operator or have 'super' access granted by ///
'p4 protect'. ///
///
///
/// /// /// To get a list of 100 jobs that include files under a given filepath: /// /// /// FileSpec path = new FileSpec(new DepotPath(@"//depot/..."), null); /// IList<Job> jobs = rep.GetJobs((new Options(JobsCmdFlags.LongDescriptions, null, 100)), path); /// /// /// /// To get a list of 100 jobs with the status "open": /// /// /// string jobView = "status=open"; /// IList<Job> jobs = rep.GetJobs((new Options(JobsCmdFlags.LongDescriptions, jobView, 100)), path); /// /// /// To get a list of 10 jobs in reverse order: /// /// /// IList<Job> jobs = rep.GetJobs((new Options(JobsCmdFlags.ReverseSort, null, 10)); /// /// /// /// To get a list of 10 jobs that include any fixes made by changelists integrated into /// the specified files: /// /// /// FileSpec path = new FileSpec(new DepotPath(@"//depot/..."), null); /// IList<Job> jobs = rep.GetJobs((new Options(JobsCmdFlags.IncludeIntegratedFixes, null, 10)), path); /// /// /// /// /// public IList GetJobs(Options options, params FileSpec[] files) { P4Command cmd = null; if ((files != null) && (files.Length > 0)) { cmd = new P4Command(this, "jobs", true, FileSpec.ToStrings(files)); } else { cmd = new P4Command(this, "jobs", true); } P4CommandResult results = cmd.Run(options); if (results.Success) { if ((results.TaggedOutput == null) || (results.TaggedOutput.Count <= 0)) { return null; } List value = new List(); Dictionary map = new Dictionary(); foreach (TaggedObject obj in results.TaggedOutput) { Job job = new Job(); job.FromJobCmdTaggedOutput(obj); value.Add(job); } return value; } else { P4Exception.Throw(results.ErrorList); } return null; } /// /// Delete a job from the repository /// /// The job to be deleted /// Only the '-f' flag is valid when deleting an existing job /// /// To delete job000002 from the repository : /// /// /// Job u = _repository.GetJob("job000002"); /// _repository.DeleteJob(u, null); /// /// /// public void DeleteJob(Job job, Options options) { if (job == null) { throw new ArgumentNullException("job"); } P4Command cmd = new P4Command(this, "job", true, job.Id); if (options == null) { options = new Options(); } options["-d"] = null; P4CommandResult results = cmd.Run(options); if (results.Success == false) { P4Exception.Throw(results.ErrorList); } } } }