diff --git a/jenkins-client/pom.xml b/jenkins-client/pom.xml index 75eb3fc9..6d5d5f73 100644 --- a/jenkins-client/pom.xml +++ b/jenkins-client/pom.xml @@ -18,6 +18,11 @@ Jenkins API client for Java :: The Client. + + org.projectlombok + lombok + provided + com.fasterxml.jackson.core diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/JenkinsServer.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/JenkinsServer.java index a7e0c416..a8a2ffd0 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/JenkinsServer.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/JenkinsServer.java @@ -6,20 +6,6 @@ package com.offbytwo.jenkins; -import java.io.IOException; -import java.net.URI; -import java.util.List; -import java.util.Map; - -import javax.xml.bind.JAXBException; - -import org.apache.http.HttpStatus; -import org.apache.http.client.HttpResponseException; -import org.apache.http.entity.ContentType; -import org.dom4j.DocumentException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.common.base.Function; import com.google.common.base.Optional; import com.google.common.collect.ImmutableMap; @@ -29,22 +15,20 @@ import com.offbytwo.jenkins.client.util.EncodingUtils; import com.offbytwo.jenkins.client.util.UrlUtils; import com.offbytwo.jenkins.helper.JenkinsVersion; -import com.offbytwo.jenkins.model.Build; -import com.offbytwo.jenkins.model.Computer; -import com.offbytwo.jenkins.model.ComputerSet; -import com.offbytwo.jenkins.model.FolderJob; -import com.offbytwo.jenkins.model.Job; -import com.offbytwo.jenkins.model.JobConfiguration; -import com.offbytwo.jenkins.model.JobWithDetails; -import com.offbytwo.jenkins.model.LabelWithDetails; -import com.offbytwo.jenkins.model.MainView; -import com.offbytwo.jenkins.model.MavenJobWithDetails; -import com.offbytwo.jenkins.model.PluginManager; -import com.offbytwo.jenkins.model.Queue; -import com.offbytwo.jenkins.model.QueueItem; -import com.offbytwo.jenkins.model.QueueReference; -import com.offbytwo.jenkins.model.View; +import com.offbytwo.jenkins.model.*; +import org.apache.http.HttpStatus; +import org.apache.http.client.HttpResponseException; +import org.apache.http.entity.ContentType; +import org.dom4j.DocumentException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.xml.bind.JAXBException; import java.io.Closeable; +import java.io.IOException; +import java.net.URI; +import java.util.List; +import java.util.Map; /** * The main starting point for interacting with a Jenkins server. @@ -61,7 +45,7 @@ public class JenkinsServer implements Closeable { * Create a new Jenkins server reference given only the server address * * @param serverUri address of jenkins server (ex. - * http://localhost:8080/jenkins) + * http://localhost:8080/jenkins) */ public JenkinsServer(URI serverUri) { this(new JenkinsHttpClient(serverUri)); @@ -70,9 +54,9 @@ public JenkinsServer(URI serverUri) { /** * Create a new Jenkins server reference given the address and credentials * - * @param serverUri address of jenkins server (ex. - * http://localhost:8080/jenkins) - * @param username username to use when connecting + * @param serverUri address of jenkins server (ex. + * http://localhost:8080/jenkins) + * @param username username to use when connecting * @param passwordOrToken password (not recommended) or token (recommended) */ public JenkinsServer(URI serverUri, String username, String passwordOrToken) { @@ -127,6 +111,23 @@ public Map getJobs() throws IOException { return getJobs(null, null); } + /** + * 获取包含详细信息的job列表 + * + * @return + * @throws Exception + */ + public Map getDetailJobs() throws Exception { + String path = UrlUtils.toBaseUrl(null); + path += "?depth=1"; + List jobs = client.get(path, DetailJobView.class).getJobs(); + return Maps.uniqueIndex(jobs, job -> { + job.setClient(client); + return job.getName(); + }); + } + + /** * Get a list of all the defined jobs on the server (in the given folder) * @@ -153,9 +154,9 @@ public Map getJobs(String view) throws IOException { /** * Get a list of all the defined jobs on the server (at the specified view * level and in the specified folder) - * + * * @param folder {@link FolderJob} - * @param view The view to use. + * @param view The view to use. * @return list of defined jobs (view level, for details @see Job#details * @throws IOException in case of an error. */ @@ -189,7 +190,7 @@ public Map getViews() throws IOException { /** * Get a list of all the defined views on the server (at the summary level * and in the given folder) - * + * * @param folder {@link FolderJob} * @return list of defined views * @throws IOException in case of an error. @@ -229,9 +230,9 @@ public View getView(String name) throws IOException { /** * Get a single view object from the given folder - * + * * @param folder The name of the folder. - * @param name name of the view in Jenkins + * @param name name of the view in Jenkins * @return the view object * @throws IOException in case of an error. */ @@ -261,7 +262,7 @@ public View getView(FolderJob folder, String name) throws IOException { /** * Get a single Job from the server. - * + * * @param jobName name of the job to get details of. * @return A single Job, null if not present * @throws IOException in case of an error. @@ -272,8 +273,8 @@ public JobWithDetails getJob(String jobName) throws IOException { /** * Get a single Job from the given folder. - * - * @param folder {@link FolderJob} + * + * @param folder {@link FolderJob} * @param jobName name of the job to get details of. * @return A single Job, null if not present * @throws IOException in case of an error. @@ -335,10 +336,10 @@ public Optional getFolderJob(Job job) throws IOException { /** * Create a job on the server using the provided xml - * + * * @param jobName name of the job to be created. - * @param jobXml the config.xml which should be used to create - * the job. + * @param jobXml the config.xml which should be used to create + * the job. * @throws IOException in case of an error. */ public void createJob(String jobName, String jobXml) throws IOException { @@ -347,12 +348,12 @@ public void createJob(String jobName, String jobXml) throws IOException { /** * Create a job on the server using the provided xml - * - * @param jobName name of the job to be created. - * @param jobXml the config.xml which should be used to create - * the job. + * + * @param jobName name of the job to be created. + * @param jobXml the config.xml which should be used to create + * the job. * @param crumbFlag true to add crumbIssuer - * false otherwise. + * false otherwise. * @throws IOException in case of an error. */ public void createJob(String jobName, String jobXml, Boolean crumbFlag) throws IOException { @@ -363,10 +364,10 @@ public void createJob(String jobName, String jobXml, Boolean crumbFlag) throws I * Create a job on the server using the provided xml and in the provided * folder * - * @param folder {@link FolderJob} + * @param folder {@link FolderJob} * @param jobName name of the job to be created. - * @param jobXml the config.xml which should be used to create - * the job. + * @param jobXml the config.xml which should be used to create + * the job. * @throws IOException in case of an error. */ public void createJob(FolderJob folder, String jobName, String jobXml) throws IOException { @@ -377,12 +378,12 @@ public void createJob(FolderJob folder, String jobName, String jobXml) throws IO * Create a job on the server using the provided xml and in the provided * folder * - * @param folder {@link FolderJob} - * @param jobName name of the job to be created. - * @param jobXml the config.xml which should be used to create - * the job. + * @param folder {@link FolderJob} + * @param jobName name of the job to be created. + * @param jobXml the config.xml which should be used to create + * the job. * @param crumbFlag true to add crumbIssuer - * false otherwise. + * false otherwise. * @throws IOException in case of an error. */ public void createJob(FolderJob folder, String jobName, String jobXml, Boolean crumbFlag) throws IOException { @@ -391,9 +392,9 @@ public void createJob(FolderJob folder, String jobName, String jobXml, Boolean c /** * Create a view on the server using the provided xml - * + * * @param viewName name of the view to be created. - * @param viewXml The configuration for the view. + * @param viewXml The configuration for the view. * @throws IOException in case of an error. */ public void createView(String viewName, String viewXml) throws IOException { @@ -403,10 +404,10 @@ public void createView(String viewName, String viewXml) throws IOException { /** * Create a view on the server using the provided xml. * - * @param viewName name of the view to be created. - * @param viewXml The configuration for the view. + * @param viewName name of the view to be created. + * @param viewXml The configuration for the view. * @param crumbFlag true to add crumbIssuer - * false otherwise. + * false otherwise. * @throws IOException in case of an error. */ public void createView(String viewName, String viewXml, Boolean crumbFlag) throws IOException { @@ -416,10 +417,10 @@ public void createView(String viewName, String viewXml, Boolean crumbFlag) throw /** * Create a view on the server using the provided xml and in the provided * folder. - * - * @param folder {@link FolderJob} + * + * @param folder {@link FolderJob} * @param viewName name of the view to be created. - * @param viewXml The configuration for the view. + * @param viewXml The configuration for the view. * @throws IOException in case of an error. */ public void createView(FolderJob folder, String viewName, String viewXml) throws IOException { @@ -429,12 +430,12 @@ public void createView(FolderJob folder, String viewName, String viewXml) throws /** * Create a view on the server using the provided xml and in the provided * folder. - * - * @param folder the folder. - * @param viewName the view name. - * @param viewXml the view xml. + * + * @param folder the folder. + * @param viewName the view name. + * @param viewXml the view xml. * @param crumbFlag true to add crumbIssuer - * false otherwise. + * false otherwise. * @throws IOException in case of an error. */ public void createView(FolderJob folder, String viewName, String viewXml, Boolean crumbFlag) throws IOException { @@ -444,7 +445,7 @@ public void createView(FolderJob folder, String viewName, String viewXml, Boolea /** * Create a folder on the server (in the root) - * + * * @param folderName name of the folder. * @throws IOException in case of an error. */ @@ -454,10 +455,10 @@ public void createFolder(String folderName) throws IOException { /** * Create a folder on the server (in the root) - * + * * @param folderName name of the folder. - * @param crumbFlag true to add crumbIssuer - * false otherwise. + * @param crumbFlag true to add crumbIssuer + * false otherwise. * @throws IOException in case of an error. */ public void createFolder(String folderName, Boolean crumbFlag) throws IOException { @@ -467,7 +468,7 @@ public void createFolder(String folderName, Boolean crumbFlag) throws IOExceptio /** * Create a job on the server (in the given folder) * - * @param folder {@link FolderJob} + * @param folder {@link FolderJob} * @param jobName name of the job. * @throws IOException in case of an error. */ @@ -478,10 +479,10 @@ public void createFolder(FolderJob folder, String jobName) throws IOException { /** * Create a job on the server (in the given folder) * - * @param folder {@link FolderJob} - * @param jobName name of the job. + * @param folder {@link FolderJob} + * @param jobName name of the job. * @param crumbFlag true to add crumbIssuer - * false otherwise. + * false otherwise. * @throws IOException in case of an error. */ public void createFolder(FolderJob folder, String jobName, Boolean crumbFlag) throws IOException { @@ -505,9 +506,9 @@ public String getJobXml(String jobName) throws IOException { /** * Get the xml description of an existing job. - * + * * @param jobName name of the job. - * @param folder {@link FolderJob} + * @param folder {@link FolderJob} * @return the new job object * @throws IOException in case of an error. */ @@ -517,7 +518,7 @@ public String getJobXml(FolderJob folder, String jobName) throws IOException { /** * Get the description of an existing Label - * + * * @param labelName name of the label. * @return {@link LabelWithDetails} * @throws IOException in case of an error. @@ -530,7 +531,7 @@ public LabelWithDetails getLabel(String labelName) throws IOException { * Get a list of all the computers on the server (at the summary level) * * @return map of defined computers (summary level, for details @see - * Computer#details + * Computer#details * @throws IOException in case of an error. */ public Map getComputers() throws IOException { @@ -548,7 +549,7 @@ public String apply(Computer computer) { * The ComputerSet class will give informations like * {@link ComputerSet#getBusyExecutors()} or the * {@link ComputerSet#getTotalExecutors()}. - * + * * @return {@link ComputerSet} * @throws IOException in case of an error. */ @@ -558,7 +559,7 @@ public ComputerSet getComputerSet() throws IOException { /** * This will give you back the {@link PluginManager}. - * + * * @return {@link PluginManager} * @throws IOException in case of a failure. */ @@ -570,7 +571,7 @@ public PluginManager getPluginManager() throws IOException { * Update the xml description of an existing view * * @param viewName name of the view. - * @param viewXml the view configuration. + * @param viewXml the view configuration. * @throws IOException in case of an error. */ public void updateView(String viewName, String viewXml) throws IOException { @@ -580,7 +581,7 @@ public void updateView(String viewName, String viewXml) throws IOException { public void updateView(String viewName, String viewXml, boolean crumbFlag) throws IOException { client.post_xml("/view/" + EncodingUtils.encode(viewName) + "/config.xml", viewXml, crumbFlag); } - + public void updateView(FolderJob folder, String viewName, String viewXml) throws IOException { client.post_xml(UrlUtils.toBaseUrl(folder) + "view/" + EncodingUtils.encode(viewName) + "/config.xml", viewXml, true); } @@ -593,7 +594,7 @@ public void updateView(FolderJob folder, String viewName, String viewXml, boolea * Update the xml description of an existing job * * @param jobName name of the job to be updated. - * @param jobXml the configuration to be used for updating. + * @param jobXml the configuration to be used for updating. * @throws IOException in case of an error. */ public void updateJob(String jobName, String jobXml) throws IOException { @@ -603,8 +604,8 @@ public void updateJob(String jobName, String jobXml) throws IOException { /** * Update the xml description of an existing job * - * @param jobName name of the job to be updated. - * @param jobXml the configuration to be used for updating. + * @param jobName name of the job to be updated. + * @param jobXml the configuration to be used for updating. * @param crumbFlag true/false. * @throws IOException in case of an error. */ @@ -615,9 +616,9 @@ public void updateJob(String jobName, String jobXml, boolean crumbFlag) throws I /** * Update the xml description of an existing job * - * @param folder the folder. - * @param jobName the name of the job. - * @param jobXml the job xml configuration. + * @param folder the folder. + * @param jobName the name of the job. + * @param jobXml the job xml configuration. * @param crumbFlag true/false. * @throws IOException in case of an error. */ @@ -626,12 +627,12 @@ public void updateJob(FolderJob folder, String jobName, String jobXml, boolean c } /** - * @param jobName name of the job. - * @param name name of the parameter. - * @param description of the parameters. + * @param jobName name of the job. + * @param name name of the parameter. + * @param description of the parameters. * @param defaultValue the defaultValue for the parameters. - * @throws IOException in case of an error. - * @throws JAXBException in case of an error. + * @throws IOException in case of an error. + * @throws JAXBException in case of an error. * @throws DocumentException in case of an error. */ public void addStringParam(String jobName, String name, String description, String defaultValue) @@ -644,7 +645,7 @@ public void addStringParam(String jobName, String name, String description, Stri /** * Sends the Quiet Down (Prepare for shutdown) message - * + * * @throws IOException in case of an error. */ public void quietDown() throws IOException { @@ -658,7 +659,7 @@ public void quietDown() throws IOException { /** * Cancels the Quiet Down (Prepare for shutdown) message - * + * * @throws IOException in case of an error. */ public void cancelQuietDown() throws IOException { @@ -672,9 +673,8 @@ public void cancelQuietDown() throws IOException { /** * Delete a job from Jenkins within a folder. * - * @param folder The folder where the given job is located. + * @param folder The folder where the given job is located. * @param jobName The job which should be deleted. - * * @throws IOException in case of an error. */ public void deleteJob(FolderJob folder, String jobName) throws IOException { @@ -683,9 +683,9 @@ public void deleteJob(FolderJob folder, String jobName) throws IOException { /** * Delete a job from Jenkins within a folder. - * - * @param folder The folder where the given job is located. - * @param jobName The job which should be deleted. + * + * @param folder The folder where the given job is located. + * @param jobName The job which should be deleted. * @param crumbFlag The crumbFlag * @throws IOException in case of problems. */ @@ -695,7 +695,7 @@ public void deleteJob(FolderJob folder, String jobName, boolean crumbFlag) throw /** * Delete a job from jenkins - * + * * @param jobName The name of the job which should be deleted. * @throws IOException in case of an error. */ @@ -705,10 +705,10 @@ public void deleteJob(String jobName) throws IOException { /** * Delete a job from Jenkins. - * - * @param jobName The name of the job to be deleted. + * + * @param jobName The name of the job to be deleted. * @param crumbFlag true to add crumbIssuer - * false otherwise. + * false otherwise. * @throws IOException In case of an failure. */ public void deleteJob(String jobName, boolean crumbFlag) throws IOException { @@ -717,7 +717,7 @@ public void deleteJob(String jobName, boolean crumbFlag) throws IOException { /** * Disable a job from jenkins - * + * * @param jobName The name of the job which should be disabled. * @throws IOException in case of an error. */ @@ -728,9 +728,9 @@ public void disableJob(String jobName) throws IOException { /** * Disable a job from Jenkins. * - * @param jobName The name of the job to be deleted. + * @param jobName The name of the job to be deleted. * @param crumbFlag true to add crumbIssuer - * false otherwise. + * false otherwise. * @throws IOException In case of an failure. */ public void disableJob(String jobName, boolean crumbFlag) throws IOException { @@ -739,20 +739,20 @@ public void disableJob(String jobName, boolean crumbFlag) throws IOException { /** * Enable a job from jenkins - * + * * @param jobName name of the job which should be enabled. * @throws IOException In case of an failure. */ public void enableJob(String jobName) throws IOException { - enableJob( jobName, false ); + enableJob(jobName, false); } /** * Enable a job from Jenkins. * - * @param jobName The name of the job to be deleted. + * @param jobName The name of the job to be deleted. * @param crumbFlag true to add crumbIssuer - * false otherwise. + * false otherwise. * @throws IOException In case of an failure. */ public void enableJob(String jobName, boolean crumbFlag) throws IOException { @@ -761,9 +761,9 @@ public void enableJob(String jobName, boolean crumbFlag) throws IOException { /** * Runs the provided groovy script on the server and returns the result. - * + *

* This is similar to running groovy scripts using the script console. - * + *

* In the instance where your script causes an exception, the server still * returns a 200 status, so detecting errors is very challenging. It is * recommended to use heuristics to check your return string for stack @@ -779,17 +779,17 @@ public String runScript(String script) throws IOException { /** * Runs the provided groovy script on the server and returns the result. - * + *

* This is similar to running groovy scripts using the script console. - * + *

* In the instance where your script causes an exception, the server still * returns a 200 status, so detecting errors is very challenging. It is * recommended to use heuristics to check your return string for stack * traces by detecting strings like "groovy.lang.(something)Exception". * - * @param script The script to run. + * @param script The script to run. * @param crumbFlag true to add crumbIssuer - * false otherwise. + * false otherwise. * @return results The results of the run of the script. * @throws IOException in case of an error. */ @@ -851,8 +851,8 @@ public void renameJob(String oldJobName, String newJobName) throws IOException { * * @param oldJobName existing job name. * @param newJobName The new job name. - * @param crumbFlag true to add crumbIssuer - * false otherwise. + * @param crumbFlag true to add crumbIssuer + * false otherwise. * @throws IOException In case of a failure. */ public void renameJob(String oldJobName, String newJobName, Boolean crumbFlag) throws IOException { @@ -862,7 +862,7 @@ public void renameJob(String oldJobName, String newJobName, Boolean crumbFlag) t /** * Rename a job * - * @param folder {@link FolderJob} + * @param folder {@link FolderJob} * @param oldJobName existing job name. * @param newJobName The new job name. * @throws IOException In case of a failure. @@ -874,22 +874,21 @@ public void renameJob(FolderJob folder, String oldJobName, String newJobName) th /** * Rename a job * - * @param folder {@link FolderJob} + * @param folder {@link FolderJob} * @param oldJobName existing job name. * @param newJobName The new job name. - * @param crumbFlag true to add crumbIssuer - * false otherwise. + * @param crumbFlag true to add crumbIssuer + * false otherwise. * @throws IOException In case of a failure. */ public void renameJob(FolderJob folder, String oldJobName, String newJobName, Boolean crumbFlag) throws IOException { - client.post(UrlUtils.toJobBaseUrl(folder, oldJobName) - + "/doRename?newName=" + EncodingUtils.encodeParam(newJobName), - crumbFlag); + client.post(UrlUtils.toJobBaseUrl(folder, oldJobName) + + "/doRename?newName=" + EncodingUtils.encodeParam(newJobName), + crumbFlag); } - - - + + /** * Closes underlying resources. * Closed instances should no longer be used @@ -901,74 +900,66 @@ public void close() { } - /** - * Restart Jenkins without waiting for any existing build to complete - * - * @param crumbFlag - * true to add crumbIssuer false - * otherwise. - * @throws IOException - * in case of an error. - */ - public void restart(Boolean crumbFlag) throws IOException { - try { - client.post("/restart", crumbFlag); - } catch (org.apache.http.client.ClientProtocolException e) { - LOGGER.error("restart()", e); - } - } - - /** - * safeRestart: Puts Jenkins into the quiet mode, wait for existing builds - * to be completed, and then restart Jenkins - * - * @param crumbFlag - * true to add crumbIssuer false - * otherwise. - * @throws IOException - * in case of an error. - */ - public void safeRestart(Boolean crumbFlag) throws IOException { - try { - client.post("/safeRestart", crumbFlag); - } catch (org.apache.http.client.ClientProtocolException e) { - LOGGER.error("safeRestart()", e); - } - } - - /** - * Shutdown Jenkins without waiting for any existing build to complete - * - * @param crumbFlag - * true to add crumbIssuer false - * otherwise. - * @throws IOException - * in case of an error. - */ - // - public void exit(Boolean crumbFlag) throws IOException { - try { - client.post("/exit", crumbFlag); - } catch (org.apache.http.client.ClientProtocolException e) { - LOGGER.error("exit()", e); - } - } - - /** - * safeExit: Puts Jenkins into the quiet mode, wait for existing builds to - * be completed, and then shut down Jenkins - * - * @param crumbFlag - * true to add crumbIssuer false - * otherwise. - * @throws IOException - * in case of an error. - */ - public void safeExit(Boolean crumbFlag) throws IOException { - try { - client.post("/safeExit", crumbFlag); - } catch (org.apache.http.client.ClientProtocolException e) { - LOGGER.error("safeExit()", e); - } - } + /** + * Restart Jenkins without waiting for any existing build to complete + * + * @param crumbFlag true to add crumbIssuer false + * otherwise. + * @throws IOException in case of an error. + */ + public void restart(Boolean crumbFlag) throws IOException { + try { + client.post("/restart", crumbFlag); + } catch (org.apache.http.client.ClientProtocolException e) { + LOGGER.error("restart()", e); + } + } + + /** + * safeRestart: Puts Jenkins into the quiet mode, wait for existing builds + * to be completed, and then restart Jenkins + * + * @param crumbFlag true to add crumbIssuer false + * otherwise. + * @throws IOException in case of an error. + */ + public void safeRestart(Boolean crumbFlag) throws IOException { + try { + client.post("/safeRestart", crumbFlag); + } catch (org.apache.http.client.ClientProtocolException e) { + LOGGER.error("safeRestart()", e); + } + } + + /** + * Shutdown Jenkins without waiting for any existing build to complete + * + * @param crumbFlag true to add crumbIssuer false + * otherwise. + * @throws IOException in case of an error. + */ + // + public void exit(Boolean crumbFlag) throws IOException { + try { + client.post("/exit", crumbFlag); + } catch (org.apache.http.client.ClientProtocolException e) { + LOGGER.error("exit()", e); + } + } + + /** + * safeExit: Puts Jenkins into the quiet mode, wait for existing builds to + * be completed, and then shut down Jenkins + * + * @param crumbFlag true to add crumbIssuer false + * otherwise. + * @throws IOException in case of an error. + */ + public void safeExit(Boolean crumbFlag) throws IOException { + try { + client.post("/safeExit", crumbFlag); + } catch (org.apache.http.client.ClientProtocolException e) { + LOGGER.error("safeExit()", e); + } + } } diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/DetailJobView.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/DetailJobView.java new file mode 100644 index 00000000..9b2a7394 --- /dev/null +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/DetailJobView.java @@ -0,0 +1,17 @@ +package com.offbytwo.jenkins.model; + +import java.util.List; + +public class DetailJobView extends BaseModel { + + private List jobs; + + public List getJobs() { + return jobs; + } + + public void setJobs(List jobs) { + this.jobs = jobs; + } + +} diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/HealthReport.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/HealthReport.java new file mode 100644 index 00000000..240dde4b --- /dev/null +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/HealthReport.java @@ -0,0 +1,12 @@ +package com.offbytwo.jenkins.model; + +import lombok.Data; + +@Data +public class HealthReport { + private String description; + private String iconClassName; + private String iconUrl; + private Integer score; + +} diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/JobWithDetails.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/JobWithDetails.java index d203aad5..be95438f 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/JobWithDetails.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/JobWithDetails.java @@ -6,16 +6,6 @@ package com.offbytwo.jenkins.model; -import static com.google.common.collect.Lists.transform; - -import java.io.IOException; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -import org.apache.http.HttpStatus; -import org.apache.http.client.HttpResponseException; - import com.google.common.base.Function; import com.google.common.base.Optional; import com.google.common.base.Predicate; @@ -23,9 +13,28 @@ import com.google.common.collect.Iterables; import com.offbytwo.jenkins.client.util.EncodingUtils; import com.offbytwo.jenkins.helper.Range; +import lombok.Getter; +import lombok.Setter; +import org.apache.http.HttpStatus; +import org.apache.http.client.HttpResponseException; + +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +import static com.google.common.collect.Lists.transform; public class JobWithDetails extends Job { + @Getter + @Setter + private String fullName; + + @Getter + @Setter + private List healthReport; + private String description; private String displayName; @@ -59,7 +68,7 @@ public class JobWithDetails extends Job { private List downstreamProjects; private List upstreamProjects; - + public String getDescription() { return description; } @@ -82,14 +91,14 @@ public boolean isInQueue() { /** * This method will give you back the builds of a particular job. - * + * * Note: Jenkins limits the number of results to a maximum of 100 builds * which you will get back.. In case you have more than 100 build you * won't get back all builds via this method. In such cases you need to use * {@link #getAllBuilds()}. - * + * * @return the list of {@link Build}. In case of no builds have been - * executed yet return {@link Collections#emptyList()}. + * executed yet return {@link Collections#emptyList()}. */ public List getBuilds() { if (builds == null) { @@ -112,12 +121,12 @@ public Build apply(Build from) { * which can be later used to get supplemental information about a * particular build {@link Build#details()} to reduce the amount of data * which needed to be transfered. - * + * * @return the list of {@link Build}. In case of no builds have been - * executed yet return {@link Collections#emptyList()}. + * executed yet return {@link Collections#emptyList()}. * @throws IOException In case of failure. * @see Jenkins - * Issue + * Issue */ public List getAllBuilds() throws IOException { String path = "/"; @@ -149,7 +158,6 @@ public Build apply(Build from) { } /** - * *

    *
  • {M,N}: From the M-th element (inclusive) to the N-th element * (exclusive).
  • @@ -158,14 +166,14 @@ public Build apply(Build from) { * (exclusive). The same as {0,N}. *
  • {N}: Just retrieve the N-th element. The same as {N,N+1}.
  • *
- * + * * Note: At the moment there seemed to be no option to get the number of * existing builds for a job. The only option is to get all builds via * {@link #getAllBuilds()}. - * + * * @param range {@link Range} * @return the list of {@link Build}. In case of no builds have been - * executed yet return {@link Collections#emptyList()}. + * executed yet return {@link Collections#emptyList()}. * @throws IOException in case of an error. */ public List getAllBuilds(Range range) throws IOException { @@ -207,8 +215,8 @@ private Build buildWithClient(Build from) { /** * @return the first build which has been executed or - * {@link Build#BUILD_HAS_NEVER_RUN} if the build has never been - * run. + * {@link Build#BUILD_HAS_NEVER_RUN} if the build has never been + * run. */ public Build getFirstBuild() { if (firstBuild == null) { @@ -220,9 +228,9 @@ public Build getFirstBuild() { /** * Check if the {@link #firstBuild} has been run or not. - * + * * @return true if a build has been run false - * otherwise. + * otherwise. */ public boolean hasFirstBuildRun() { if (firstBuild == null) { @@ -234,7 +242,7 @@ public boolean hasFirstBuildRun() { /** * @return The lastBuild. If {@link #lastBuild} has never been run - * {@link Build#BUILD_HAS_NEVER_RUN} will be returned. + * {@link Build#BUILD_HAS_NEVER_RUN} will be returned. */ public Build getLastBuild() { if (lastBuild == null) { @@ -246,9 +254,9 @@ public Build getLastBuild() { /** * Check if the {@link #lastBuild} has been run or not. - * + * * @return true if the last build has been run - * false otherwise. + * false otherwise. */ public boolean hasLastBuildRun() { if (lastBuild == null) { @@ -260,7 +268,7 @@ public boolean hasLastBuildRun() { /** * @return The lastCompletedBuild. If {@link #lastCompletedBuild} has never - * been run {@link Build#BUILD_HAS_NEVER_RUN} will be returned. + * been run {@link Build#BUILD_HAS_NEVER_RUN} will be returned. */ public Build getLastCompletedBuild() { if (lastCompletedBuild == null) { @@ -272,9 +280,9 @@ public Build getLastCompletedBuild() { /** * Check if the {@link #lastCompletedBuild} has been run or not. - * + * * @return true if the last completed build has been run - * false otherwise. + * false otherwise. */ public boolean hasLastCompletedBuildRun() { if (lastCompletedBuild == null) { @@ -286,7 +294,7 @@ public boolean hasLastCompletedBuildRun() { /** * @return The lastFailedBuild. If {@link #lastFailedBuild} has never been - * run {@link Build#BUILD_HAS_NEVER_RUN} will be returned. + * run {@link Build#BUILD_HAS_NEVER_RUN} will be returned. */ public Build getLastFailedBuild() { if (lastFailedBuild == null) { @@ -298,9 +306,9 @@ public Build getLastFailedBuild() { /** * Check if the {@link #lastFailedBuild} has been run or not. - * + * * @return true if the last failed build has been run - * false otherwise. + * false otherwise. */ public boolean hasLastFailedBuildRun() { if (lastFailedBuild == null) { @@ -312,7 +320,7 @@ public boolean hasLastFailedBuildRun() { /** * @return The lastStableBuild. If {@link #lastStableBuild} has never been - * run {@link Build#BUILD_HAS_NEVER_RUN} will be returned. + * run {@link Build#BUILD_HAS_NEVER_RUN} will be returned. */ public Build getLastStableBuild() { if (lastStableBuild == null) { @@ -324,9 +332,9 @@ public Build getLastStableBuild() { /** * Check if the {@link #lastStableBuild} has been run or not. - * + * * @return true if the last stable build has been run - * false otherwise. + * false otherwise. */ public boolean hasLastStableBuildRun() { if (lastStableBuild == null) { @@ -338,8 +346,8 @@ public boolean hasLastStableBuildRun() { /** * @return The lastSuccessfulBuild. If {@link #lastSuccessfulBuild} has - * never been run {@link Build#BUILD_HAS_NEVER_RUN} will be - * returned. + * never been run {@link Build#BUILD_HAS_NEVER_RUN} will be + * returned. */ public Build getLastSuccessfulBuild() { if (lastSuccessfulBuild == null) { @@ -351,9 +359,9 @@ public Build getLastSuccessfulBuild() { /** * Check if the {@link #lastSuccessfulBuild} has been run or not. - * + * * @return true if the last successful build has been run - * false otherwise. + * false otherwise. */ public boolean hasLastSuccessfulBuildRun() { if (lastSuccessfulBuild == null) { @@ -365,7 +373,7 @@ public boolean hasLastSuccessfulBuildRun() { /** * @return The lastUnstableBuild. If {@link #lastUnstableBuild} has never - * been run {@link Build#BUILD_HAS_NEVER_RUN} will be returned. + * been run {@link Build#BUILD_HAS_NEVER_RUN} will be returned. */ public Build getLastUnstableBuild() { if (lastUnstableBuild == null) { @@ -377,9 +385,9 @@ public Build getLastUnstableBuild() { /** * Check if the {@link #lastUnstableBuild} has been run or not. - * + * * @return true if the last unstable build has been run - * false otherwise. + * false otherwise. */ public boolean hasLastUnstableBuildRun() { if (lastUnstableBuild == null) { @@ -391,8 +399,8 @@ public boolean hasLastUnstableBuildRun() { /** * @return The lastUnsuccessfulBuild. If {@link #lastUnsuccessfulBuild} has - * never been run {@link Build#BUILD_HAS_NEVER_RUN} will be - * returned. + * never been run {@link Build#BUILD_HAS_NEVER_RUN} will be + * returned. */ public Build getLastUnsuccessfulBuild() { if (lastUnsuccessfulBuild == null) { @@ -404,9 +412,9 @@ public Build getLastUnsuccessfulBuild() { /** * Check if the {@link #lastUnsuccessfulBuild} has been run or not. - * + * * @return true if the last unsuccessful build has been run - * false otherwise. + * false otherwise. */ public boolean hasLastUnsuccessfulBuildRun() { if (lastUnsuccessfulBuild == null) { @@ -422,7 +430,7 @@ public int getNextBuildNumber() { /** * @return the list of downstream projects. If no downstream projects exist - * just return an empty list {@link Collections#emptyList()}. + * just return an empty list {@link Collections#emptyList()}. */ public List getDownstreamProjects() { if (downstreamProjects == null) { @@ -434,7 +442,7 @@ public List getDownstreamProjects() { /** * @return the list of upstream projects. If no upstream projects exist just - * return an empty list {@link Collections#emptyList()}. + * return an empty list {@link Collections#emptyList()}. */ public List getUpstreamProjects() { if (upstreamProjects == null) { @@ -450,10 +458,9 @@ public QueueItem getQueueItem() { /** * Get a build by the given buildNumber. - * + * * @param buildNumber The number to select the build by. * @return The {@link Build} selected by the given buildnumber - * */ public Build getBuildByNumber(final int buildNumber) { @@ -486,10 +493,10 @@ public Job apply(Job job) { /** * Update the description of a Job. - * + * * @param description The description which should be set. If you like to - * set an empty description you should use - * {@link #EMPTY_DESCRIPTION}. + * set an empty description you should use + * {@link #EMPTY_DESCRIPTION}. * @throws IOException in case of errors. */ public void updateDescription(String description) throws IOException { @@ -498,11 +505,11 @@ public void updateDescription(String description) throws IOException { /** * Update the description of a Job. - * + * * @param description The description which should be set. If you like to - * set an empty description you should use - * {@link #EMPTY_DESCRIPTION}. - * @param crumbFlag true or false. + * set an empty description you should use + * {@link #EMPTY_DESCRIPTION}. + * @param crumbFlag true or false. * @throws IOException in case of errors. */ public void updateDescription(String description, boolean crumbFlag) throws IOException { @@ -513,7 +520,7 @@ public void updateDescription(String description, boolean crumbFlag) throws IOEx /** * clear the description of a job. - * + * * @throws IOException in case of errors. */ public void clearDescription() throws IOException { @@ -522,7 +529,7 @@ public void clearDescription() throws IOException { /** * clear the description of a job. - * + * * @param crumbFlag true or false. * @throws IOException in case of errors. */ diff --git a/pom.xml b/pom.xml index cea2c716..39d072b3 100644 --- a/pom.xml +++ b/pom.xml @@ -87,6 +87,11 @@ + + org.projectlombok + lombok + 1.18.6 + com.fasterxml.jackson.core