diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..5b8d5402 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: [khmarbaise] \ No newline at end of file diff --git a/.sdkmanrc b/.sdkmanrc new file mode 100644 index 00000000..4fc377de --- /dev/null +++ b/.sdkmanrc @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# Enable auto-env through the sdkman_auto_env config +# Add key=value pairs of SDKs to use below +java=8.0.252.hs-adpt diff --git a/ReleaseNotes.md b/ReleaseNotes.md index 9ecf4fb9..71176ed3 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -1,8 +1,89 @@ # Release Notes -## Release 0.3.9 (NOT RELEASED YET) +## Release 0.4.0 (NOT RELEASED YET) + + * [Fixed Issue 465][issue-465] + + * Remove asciidoctor site parts + * AS preparation for user guide. + + * [Fixed Issue 464][issue-464] + + * Replaced xml-apis with xerces-xmlParserAPI. + + * [Fixed Issue 309][issue-309] + + * Added possibility to get mode detailed data from Maven Modules from Jobs/Builds + + Thanks for that to [Jakub Zacek](https://github.com/dawon). + + * [Fixed Issue 395][issue-395] + + * Remove google guava lib + * Removed also the creation of the shaded artifact `stash` + cause we do not rely on Guava anymore. So you + can use the original artifact directly. + * This results in a bumping of the version + number cause it is a change which is breaking + with previous version 0.3.8. + + * [Fixed Issue 405][issue-405] + + * CVE-2018-14718 + * CVE-2018-14719 + * CVE-2018-14720 + * CVE-2018-14721 + * CVE-2018-19360 + * CVE-2018-19361 + * CVE-2018-19362 + + * [Fixed Issue 402][issue-402] + + Upgrade httpclient/httpmine/httpcore. + + * [Fixed Issue 401][issue-401] + + Upgrade JUnit + + * [Fixed Issue 400][issue-400] + + Upgrade assertj-core. + + * [Fixed Issue 399][issue-399] + + Upgrade Maven Plugins + + * [Fixed Issue 397][issue-397] + + Refactored Code Replaced UrlEscapers calls with EncodingUtils. + + * [Fixed Issue 396][issue-396] + + Add Unit Test for EncodingUtils. + + * [Fixed Issue 394][issue-394] + + Replace `Strings.isNullOrEmpty()` with self implemented code. + + * [Pull Request #386][pull-386] + + Add the crumbFlag as the 2nd parameter of getConsoleOutputText method + + * [JENKINS-56186][jissue-56186] + + Added labels to computers + + ```java + ComputerWithDetails computer = ... + for (ComputerLabel assignedLabel : computer.getAssignedLabels()) { + assignedLabel.getName() + } + ``` + + * [JENKINS-56585][jissue-56585] + + Change request method of `QuietDown()` to POST - * ... ## Release 0.3.8 @@ -121,7 +202,7 @@ Added new methods to JenkinsServer for stopping and restarting Jenkins. The methods are restart(Boolean crumbFlag), safeRestart(Boolean crumbFlag), exit(Boolean crumbFlag) and safeExit(Boolean crumbFlag) Thanks for that to [Chids](https://github.com/Chids-gs). - + ## Release 0.3.7 * Changed Eclipse Formatting configuration. @@ -1070,8 +1151,21 @@ TestReport testReport = mavenJob.getLastSuccessfulBuild().getTestReport(); [issue-244]: https://github.com/jenkinsci/java-client-api/issues/244 [issue-268]: https://github.com/jenkinsci/java-client-api/issues/268 [issue-289]: https://github.com/jenkinsci/java-client-api/issues/289 +[issue-282]: https://github.com/jenkinsci/java-client-api/issues/282 +[issue-291]: https://github.com/jenkinsci/java-client-api/issues/291 [issue-298]: https://github.com/jenkinsci/java-client-api/issues/298 [issue-301]: https://github.com/jenkinsci/java-client-api/issues/301 +[issue-309]: https://github.com/jenkinsci/java-client-api/issues/309 +[issue-394]: https://github.com/jenkinsci/java-client-api/issues/394 +[issue-395]: https://github.com/jenkinsci/java-client-api/issues/395 +[issue-396]: https://github.com/jenkinsci/java-client-api/issues/396 +[issue-397]: https://github.com/jenkinsci/java-client-api/issues/397 +[issue-399]: https://github.com/jenkinsci/java-client-api/issues/399 +[issue-400]: https://github.com/jenkinsci/java-client-api/issues/400 +[issue-401]: https://github.com/jenkinsci/java-client-api/issues/401 +[issue-402]: https://github.com/jenkinsci/java-client-api/issues/402 +[issue-405]: https://github.com/jenkinsci/java-client-api/issues/405 +[issue-464]: https://github.com/jenkinsci/java-client-api/issues/464 [pull-123]: https://github.com/jenkinsci/java-client-api/pull/123 [pull-149]: https://github.com/jenkinsci/java-client-api/pull/149 [pull-158]: https://github.com/jenkinsci/java-client-api/pull/158 @@ -1083,10 +1177,13 @@ TestReport testReport = mavenJob.getLastSuccessfulBuild().getTestReport(); [pull-240]: https://github.com/jenkinsci/java-client-api/pull/240 [pull-247]: https://github.com/jenkinsci/java-client-api/pull/247 [pull-262]: https://github.com/jenkinsci/java-client-api/pull/262 +[pull-386]: https://github.com/jenkinsci/java-client-api/pull/386 [jissue-35002]: https://issues.jenkins-ci.org/browse/JENKINS-35002 [jissue-35108]: https://issues.jenkins-ci.org/browse/JENKINS-35108 [jissue-38787]: https://issues.jenkins-ci.org/browse/JENKINS-38787 [jissue-38816]: https://issues.jenkins-ci.org/browse/JENKINS-38816 [jissue-38823]: https://issues.jenkins-ci.org/browse/JENKINS-38823 -[jissue-46445]: https://issues.jenkins-ci.org/browse/JENKINS-46445) -[jissue-46472]: https://issues.jenkins-ci.org/browse/JENKINS-46472) +[jissue-46445]: https://issues.jenkins-ci.org/browse/JENKINS-46445 +[jissue-46472]: https://issues.jenkins-ci.org/browse/JENKINS-46472 +[jissue-56186]: https://issues.jenkins-ci.org/browse/JENKINS-56186 +[jissue-56585]: https://issues.jenkins-ci.org/browse/JENKINS-56585 diff --git a/jenkins-client-it-docker/pom.xml b/jenkins-client-it-docker/pom.xml index 8f4c7ac7..11e6b485 100644 --- a/jenkins-client-it-docker/pom.xml +++ b/jenkins-client-it-docker/pom.xml @@ -11,7 +11,7 @@ com.offbytwo.jenkins jenkins-client-parent - 0.3.9-SNAPSHOT + 0.4.0-SNAPSHOT jenkins-client-it-docker @@ -43,11 +43,6 @@ assertj-core test - - com.google.guava - guava - test - org.apache.httpcomponents httpclient diff --git a/jenkins-client-it-docker/src/test/java/com/offbytwo/jenkins/integration/NoExecutorStartedGetJobIT.java b/jenkins-client-it-docker/src/test/java/com/offbytwo/jenkins/integration/NoExecutorStartedGetJobIT.java index 279bb40a..35c2aeac 100644 --- a/jenkins-client-it-docker/src/test/java/com/offbytwo/jenkins/integration/NoExecutorStartedGetJobIT.java +++ b/jenkins-client-it-docker/src/test/java/com/offbytwo/jenkins/integration/NoExecutorStartedGetJobIT.java @@ -7,7 +7,6 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import com.google.common.base.Joiner; import com.offbytwo.jenkins.model.Build; import com.offbytwo.jenkins.model.BuildResult; import com.offbytwo.jenkins.model.BuildWithDetails; @@ -50,7 +49,7 @@ private void checkJob(BuildWithDetails details) throws IOException { "Building in workspace /var/jenkins_home/jobs/test/workspace", "[workspace] $ /bin/sh -xe /tmp/hudson2556403647634111927.sh", "+ echo test", "test", "Finished: SUCCESS", "" }; - String expectedOutput = Joiner.on("\r\n").join(expectedOutputLines); + String expectedOutput = String.join("\r\n", expectedOutputLines); // Hint: It looks like the consoleOutputText contains CR+LF String resultingOutput = details.getConsoleOutputText(); assertThat(resultingOutput).isEqualTo(expectedOutput); diff --git a/jenkins-client-it-docker/src/test/java/com/offbytwo/jenkins/integration/NoExecutorStartedGetJobXmlIT.java b/jenkins-client-it-docker/src/test/java/com/offbytwo/jenkins/integration/NoExecutorStartedGetJobXmlIT.java index 451e7585..38a3507a 100644 --- a/jenkins-client-it-docker/src/test/java/com/offbytwo/jenkins/integration/NoExecutorStartedGetJobXmlIT.java +++ b/jenkins-client-it-docker/src/test/java/com/offbytwo/jenkins/integration/NoExecutorStartedGetJobXmlIT.java @@ -7,8 +7,6 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import com.google.common.base.Joiner; - @Test(groups = { Groups.NO_EXECUTOR_GROUP }) public class NoExecutorStartedGetJobXmlIT extends AbstractJenkinsIntegrationCase { @@ -47,7 +45,7 @@ public void beforeMethod() throws IOException { @Test public void getJobXmlShouldReturnTheExpectedConfigXml() { - String expectedXml = Joiner.on("\n").join(CONFIG_XML); + String expectedXml = String.join("\n", CONFIG_XML); assertThat(jobXml).isEqualTo(expectedXml); } diff --git a/jenkins-client/pom.xml b/jenkins-client/pom.xml index 75eb3fc9..2cbc3df9 100644 --- a/jenkins-client/pom.xml +++ b/jenkins-client/pom.xml @@ -11,7 +11,7 @@ com.offbytwo.jenkins jenkins-client-parent - 0.3.9-SNAPSHOT + 0.4.0-SNAPSHOT jenkins-client @@ -34,7 +34,7 @@ - dom4j + org.dom4j dom4j @@ -51,11 +51,6 @@ - - com.google.guava - guava - - org.apache.commons commons-lang3 @@ -114,10 +109,9 @@ assertj-core test - - xml-apis - xml-apis + xerces + xmlParserAPIs @@ -127,28 +121,6 @@ org.apache.maven.plugins maven-shade-plugin - - stash - package - - shade - - - - - com.google.guava:guava - - - true - stash - - - com.google.common - com.google.common.jenkins_client_jarjar - - - - httpclient package @@ -164,12 +136,6 @@ true apachehttp - - - com.google.common - com.google.common.jenkins_client_jarjar - - 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..01755baa 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/JenkinsServer.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/JenkinsServer.java @@ -8,6 +8,7 @@ import java.io.IOException; import java.net.URI; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -20,10 +21,6 @@ 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; -import com.google.common.collect.Maps; import com.offbytwo.jenkins.client.JenkinsHttpClient; import com.offbytwo.jenkins.client.JenkinsHttpConnection; import com.offbytwo.jenkins.client.util.EncodingUtils; @@ -45,6 +42,12 @@ import com.offbytwo.jenkins.model.QueueReference; import com.offbytwo.jenkins.model.View; import java.io.Closeable; +import java.util.Optional; +import java.util.function.Function; +import java.util.stream.Collectors; + +import static com.offbytwo.jenkins.helper.FunctionalHelper.SET_CLIENT; +import static java.util.stream.Collectors.toMap; /** * The main starting point for interacting with a Jenkins server. @@ -167,13 +170,10 @@ public Map getJobs(FolderJob folder, String view) throws IOExceptio viewClass = View.class; } List jobs = client.get(path, viewClass).getJobs(); - return Maps.uniqueIndex(jobs, new Function() { - @Override - public String apply(Job job) { - job.setClient(client); - return job.getName(); - } - }); + + return jobs.stream() + .map(SET_CLIENT(this.client)) + .collect(toMap(s -> s.getName(), s -> s)); } /** @@ -198,22 +198,23 @@ public Map getViews(FolderJob folder) throws IOException { // This is much better than using &depth=2 // http://localhost:8080/api/json?pretty&tree=views[name,url,jobs[name,url]] List views = client.get(UrlUtils.toBaseUrl(folder) + "?tree=views[name,url,jobs[name,url]]", MainView.class).getViews(); - return Maps.uniqueIndex(views, new Function() { - @Override - public String apply(View view) { - view.setClient(client); - // TODO: Think about the following? Does there exists a - // simpler/more elegant method? + + //TODO: Think about this Lambda. It's too large? Make it smaller! + return views.stream().map(view -> { + SET_CLIENT(this.client); + + // TODO: Think about the following? Does there exists a simpler/more + // elegant method? for (Job job : view.getJobs()) { - job.setClient(client); + SET_CLIENT(this.client); } - for (View item : view.getViews()) { - item.setClient(client); + for (View viewView : view.getViews()) { + SET_CLIENT(this.client); } - return view.getName(); - } - }); + return view; + }) + .collect(Collectors.toMap(s -> s.getName(), v -> v)); } /** @@ -317,10 +318,9 @@ public Optional getFolderJob(Job job) throws IOException { try { FolderJob folder = client.get(job.getUrl(), FolderJob.class); if (!folder.isFolder()) { - return Optional.absent(); + return Optional.empty(); } folder.setClient(client); - return Optional.of(folder); } catch (HttpResponseException e) { LOGGER.debug("getForlderJob(job={}) status={}", job, e.getStatusCode()); @@ -341,8 +341,8 @@ public Optional getFolderJob(Job job) throws IOException { * the job. * @throws IOException in case of an error. */ - public void createJob(String jobName, String jobXml) throws IOException { - createJob(null, jobName, jobXml, false); + public JenkinsServer createJob(String jobName, String jobXml) throws IOException { + return createJob(null, jobName, jobXml, false); } /** @@ -355,8 +355,8 @@ public void createJob(String jobName, String jobXml) throws IOException { * false otherwise. * @throws IOException in case of an error. */ - public void createJob(String jobName, String jobXml, Boolean crumbFlag) throws IOException { - createJob(null, jobName, jobXml, crumbFlag); + public JenkinsServer createJob(String jobName, String jobXml, Boolean crumbFlag) throws IOException { + return createJob(null, jobName, jobXml, crumbFlag); } /** @@ -369,8 +369,8 @@ public void createJob(String jobName, String jobXml, Boolean crumbFlag) throws I * the job. * @throws IOException in case of an error. */ - public void createJob(FolderJob folder, String jobName, String jobXml) throws IOException { - createJob(folder, jobName, jobXml, false); + public JenkinsServer createJob(FolderJob folder, String jobName, String jobXml) throws IOException { + return createJob(folder, jobName, jobXml, false); } /** @@ -385,8 +385,10 @@ public void createJob(FolderJob folder, String jobName, String jobXml) throws IO * false otherwise. * @throws IOException in case of an error. */ - public void createJob(FolderJob folder, String jobName, String jobXml, Boolean crumbFlag) throws IOException { - client.post_xml(UrlUtils.toBaseUrl(folder) + "createItem?name=" + EncodingUtils.encodeParam(jobName), jobXml, crumbFlag); + public JenkinsServer createJob(FolderJob folder, String jobName, String jobXml, Boolean crumbFlag) + throws IOException { + client.post_xml(UrlUtils.toBaseUrl(folder) + "createItem?name=" + EncodingUtils.formParameter(jobName), jobXml, crumbFlag); + return this; } /** @@ -396,8 +398,8 @@ public void createJob(FolderJob folder, String jobName, String jobXml, Boolean c * @param viewXml The configuration for the view. * @throws IOException in case of an error. */ - public void createView(String viewName, String viewXml) throws IOException { - createView(null, viewName, viewXml, false); + public JenkinsServer createView(String viewName, String viewXml) throws IOException { + return createView(null, viewName, viewXml, false); } /** @@ -409,8 +411,8 @@ public void createView(String viewName, String viewXml) throws IOException { * false otherwise. * @throws IOException in case of an error. */ - public void createView(String viewName, String viewXml, Boolean crumbFlag) throws IOException { - createView(null, viewName, viewXml, crumbFlag); + public JenkinsServer createView(String viewName, String viewXml, Boolean crumbFlag) throws IOException { + return createView(null, viewName, viewXml, crumbFlag); } /** @@ -422,8 +424,8 @@ public void createView(String viewName, String viewXml, Boolean crumbFlag) throw * @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 { - createView(folder, viewName, viewXml, false); + public JenkinsServer createView(FolderJob folder, String viewName, String viewXml) throws IOException { + return createView(folder, viewName, viewXml, false); } /** @@ -437,9 +439,11 @@ public void createView(FolderJob folder, String viewName, String viewXml) throws * false otherwise. * @throws IOException in case of an error. */ - public void createView(FolderJob folder, String viewName, String viewXml, Boolean crumbFlag) throws IOException { - client.post_xml(UrlUtils.toBaseUrl(folder) + "createView?name=" + EncodingUtils.encodeParam(viewName), viewXml, + public JenkinsServer createView(FolderJob folder, String viewName, String viewXml, Boolean crumbFlag) + throws IOException { + client.post_xml(UrlUtils.toBaseUrl(folder) + "createView?name=" + EncodingUtils.formParameter(viewName), viewXml, crumbFlag); + return this; } /** @@ -448,8 +452,8 @@ public void createView(FolderJob folder, String viewName, String viewXml, Boolea * @param folderName name of the folder. * @throws IOException in case of an error. */ - public void createFolder(String folderName) throws IOException { - createFolder(null, folderName, false); + public JenkinsServer createFolder(String folderName) throws IOException { + return createFolder(null, folderName, false); } /** @@ -460,8 +464,8 @@ public void createFolder(String folderName) throws IOException { * false otherwise. * @throws IOException in case of an error. */ - public void createFolder(String folderName, Boolean crumbFlag) throws IOException { - createFolder(null, folderName, crumbFlag); + public JenkinsServer createFolder(String folderName, Boolean crumbFlag) throws IOException { + return createFolder(null, folderName, crumbFlag); } /** @@ -471,8 +475,8 @@ public void createFolder(String folderName, Boolean crumbFlag) throws IOExceptio * @param jobName name of the job. * @throws IOException in case of an error. */ - public void createFolder(FolderJob folder, String jobName) throws IOException { - createFolder(folder, jobName, false); + public JenkinsServer createFolder(FolderJob folder, String jobName) throws IOException { + return createFolder(folder, jobName, false); } /** @@ -484,12 +488,17 @@ public void createFolder(FolderJob folder, String jobName) throws IOException { * false otherwise. * @throws IOException in case of an error. */ - public void createFolder(FolderJob folder, String jobName, Boolean crumbFlag) throws IOException { + public JenkinsServer createFolder(FolderJob folder, String jobName, Boolean crumbFlag) throws IOException { // https://gist.github.com/stuart-warren/7786892 was slightly helpful // here - ImmutableMap params = ImmutableMap.of("mode", "com.cloudbees.hudson.plugins.folder.Folder", - "name", EncodingUtils.encodeParam(jobName), "from", "", "Submit", "OK"); + //TODO: JDK9+: Map.of(...) + Map 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; } /** @@ -535,13 +544,9 @@ public LabelWithDetails getLabel(String labelName) throws IOException { */ public Map getComputers() throws IOException { List computers = client.get("computer/", Computer.class).getComputers(); - return Maps.uniqueIndex(computers, new Function() { - @Override - public String apply(Computer computer) { - computer.setClient(client); - return computer.getDisplayName().toLowerCase(); - } - }); + return computers.stream() + .map(SET_CLIENT(this.client)) + .collect(Collectors.toMap(s -> s.getDisplayName().toLowerCase(), Function.identity())); } /** @@ -573,20 +578,24 @@ public PluginManager getPluginManager() throws IOException { * @param viewXml the view configuration. * @throws IOException in case of an error. */ - public void updateView(String viewName, String viewXml) throws IOException { - this.updateView(viewName, viewXml, true); + public JenkinsServer updateView(String viewName, String viewXml) throws IOException { + return this.updateView(viewName, viewXml, true); } - public void updateView(String viewName, String viewXml, boolean crumbFlag) throws IOException { + public JenkinsServer updateView(String viewName, String viewXml, boolean crumbFlag) throws IOException { client.post_xml("/view/" + EncodingUtils.encode(viewName) + "/config.xml", viewXml, crumbFlag); + return this; } - public void updateView(FolderJob folder, String viewName, String viewXml) throws IOException { + public JenkinsServer updateView(FolderJob folder, String viewName, String viewXml) throws IOException { client.post_xml(UrlUtils.toBaseUrl(folder) + "view/" + EncodingUtils.encode(viewName) + "/config.xml", viewXml, true); + return this; } - public void updateView(FolderJob folder, String viewName, String viewXml, boolean crumbFlag) throws IOException { + public JenkinsServer updateView(FolderJob folder, String viewName, String viewXml, boolean crumbFlag) + throws IOException { client.post_xml(UrlUtils.toBaseUrl(folder) + "view/" + EncodingUtils.encode(viewName) + "/config.xml", viewXml, crumbFlag); + return this; } /** @@ -596,8 +605,8 @@ public void updateView(FolderJob folder, String viewName, String viewXml, boolea * @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 { - this.updateJob(jobName, jobXml, true); + public JenkinsServer updateJob(String jobName, String jobXml) throws IOException { + return this.updateJob(jobName, jobXml, true); } /** @@ -608,8 +617,8 @@ public void updateJob(String jobName, String jobXml) throws IOException { * @param crumbFlag true/false. * @throws IOException in case of an error. */ - public void updateJob(String jobName, String jobXml, boolean crumbFlag) throws IOException { - updateJob(null, jobName, jobXml, crumbFlag); + public JenkinsServer updateJob(String jobName, String jobXml, boolean crumbFlag) throws IOException { + return updateJob(null, jobName, jobXml, crumbFlag); } /** @@ -621,25 +630,27 @@ public void updateJob(String jobName, String jobXml, boolean crumbFlag) throws I * @param crumbFlag true/false. * @throws IOException in case of an error. */ - public void updateJob(FolderJob folder, String jobName, String jobXml, boolean crumbFlag) throws IOException { + public JenkinsServer updateJob(FolderJob folder, String jobName, String jobXml, boolean crumbFlag) + throws IOException { client.post_xml(UrlUtils.toJobBaseUrl(folder, jobName) + "/config.xml", jobXml, crumbFlag); + return this; } /** * @param jobName name of the job. - * @param name name of the parameter. + * @param name name of the formParameter. * @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 DocumentException in case of an error. */ - public void addStringParam(String jobName, String name, String description, String defaultValue) + public JenkinsServer addStringParam(String jobName, String name, String description, String defaultValue) throws IOException, JAXBException, DocumentException { String jobXml = this.getJobXml(jobName); JobConfiguration jobConf = new JobConfiguration(jobXml); jobXml = jobConf.addStringParam(name, description, defaultValue).asXml(); - this.updateJob(jobName, jobXml); + return this.updateJob(jobName, jobXml); } /** @@ -647,13 +658,13 @@ public void addStringParam(String jobName, String name, String description, Stri * * @throws IOException in case of an error. */ - public void quietDown() throws IOException { + public JenkinsServer quietDown() throws IOException { try { - client.get("/quietDown/"); + client.post("/quietDown/"); } catch (org.apache.http.client.ClientProtocolException e) { LOGGER.error("quietDown()", e); } - + return this; } /** @@ -661,12 +672,13 @@ public void quietDown() throws IOException { * * @throws IOException in case of an error. */ - public void cancelQuietDown() throws IOException { + public JenkinsServer cancelQuietDown() throws IOException { try { client.post("/cancelQuietDown/"); } catch (org.apache.http.client.ClientProtocolException e) { LOGGER.error("cancelQuietDown()", e); } + return this; } /** @@ -677,8 +689,8 @@ public void cancelQuietDown() throws IOException { * * @throws IOException in case of an error. */ - public void deleteJob(FolderJob folder, String jobName) throws IOException { - deleteJob(folder, jobName, false); + public JenkinsServer deleteJob(FolderJob folder, String jobName) throws IOException { + return deleteJob(folder, jobName, false); } /** @@ -689,8 +701,9 @@ public void deleteJob(FolderJob folder, String jobName) throws IOException { * @param crumbFlag The crumbFlag * @throws IOException in case of problems. */ - public void deleteJob(FolderJob folder, String jobName, boolean crumbFlag) throws IOException { + public JenkinsServer deleteJob(FolderJob folder, String jobName, boolean crumbFlag) throws IOException { client.post(UrlUtils.toJobBaseUrl(folder, jobName) + "/doDelete", crumbFlag); + return this; } /** @@ -699,8 +712,8 @@ public void deleteJob(FolderJob folder, String jobName, boolean crumbFlag) throw * @param jobName The name of the job which should be deleted. * @throws IOException in case of an error. */ - public void deleteJob(String jobName) throws IOException { - deleteJob(jobName, false); + public JenkinsServer deleteJob(String jobName) throws IOException { + return deleteJob(jobName, false); } /** @@ -711,8 +724,9 @@ public void deleteJob(String jobName) throws IOException { * false otherwise. * @throws IOException In case of an failure. */ - public void deleteJob(String jobName, boolean crumbFlag) throws IOException { + public JenkinsServer deleteJob(String jobName, boolean crumbFlag) throws IOException { client.post("/job/" + EncodingUtils.encode(jobName) + "/doDelete", crumbFlag); + return this; } /** @@ -721,8 +735,8 @@ public void deleteJob(String jobName, boolean crumbFlag) throws IOException { * @param jobName The name of the job which should be disabled. * @throws IOException in case of an error. */ - public void disableJob(String jobName) throws IOException { - disableJob(jobName, false); + public JenkinsServer disableJob(String jobName) throws IOException { + return disableJob(jobName, false); } /** @@ -733,8 +747,9 @@ public void disableJob(String jobName) throws IOException { * false otherwise. * @throws IOException In case of an failure. */ - public void disableJob(String jobName, boolean crumbFlag) throws IOException { + public JenkinsServer disableJob(String jobName, boolean crumbFlag) throws IOException { client.post("/job/" + EncodingUtils.encode(jobName) + "/disable", crumbFlag); + return this; } /** @@ -743,8 +758,8 @@ public void disableJob(String jobName, boolean crumbFlag) throws IOException { * @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 ); + public JenkinsServer enableJob(String jobName) throws IOException { + return enableJob(jobName, false); } /** @@ -755,8 +770,9 @@ public void enableJob(String jobName) throws IOException { * false otherwise. * @throws IOException In case of an failure. */ - public void enableJob(String jobName, boolean crumbFlag) throws IOException { + public JenkinsServer enableJob(String jobName, boolean crumbFlag) throws IOException { client.post("/job/" + EncodingUtils.encode(jobName) + "/enable", crumbFlag); + return this; } /** @@ -842,8 +858,8 @@ public Build getBuild(QueueItem q) throws IOException { * @param newJobName The new job name. * @throws IOException In case of a failure. */ - public void renameJob(String oldJobName, String newJobName) throws IOException { - renameJob(null, oldJobName, newJobName, false); + public JenkinsServer renameJob(String oldJobName, String newJobName) throws IOException { + return renameJob(null, oldJobName, newJobName, false); } /** @@ -855,8 +871,9 @@ public void renameJob(String oldJobName, String newJobName) throws IOException { * false otherwise. * @throws IOException In case of a failure. */ - public void renameJob(String oldJobName, String newJobName, Boolean crumbFlag) throws IOException { + public JenkinsServer renameJob(String oldJobName, String newJobName, Boolean crumbFlag) throws IOException { renameJob(null, oldJobName, newJobName, crumbFlag); + return this; } /** @@ -867,8 +884,8 @@ public void renameJob(String oldJobName, String newJobName, Boolean crumbFlag) t * @param newJobName The new job name. * @throws IOException In case of a failure. */ - public void renameJob(FolderJob folder, String oldJobName, String newJobName) throws IOException { - renameJob(folder, oldJobName, newJobName, false); + public JenkinsServer renameJob(FolderJob folder, String oldJobName, String newJobName) throws IOException { + return renameJob(folder, oldJobName, newJobName, false); } /** @@ -881,11 +898,12 @@ public void renameJob(FolderJob folder, String oldJobName, String newJobName) th * false otherwise. * @throws IOException In case of a failure. */ - public void renameJob(FolderJob folder, String oldJobName, String newJobName, Boolean crumbFlag) + public JenkinsServer renameJob(FolderJob folder, String oldJobName, String newJobName, Boolean crumbFlag) throws IOException { client.post(UrlUtils.toJobBaseUrl(folder, oldJobName) - + "/doRename?newName=" + EncodingUtils.encodeParam(newJobName), + + "/doRename?newName=" + EncodingUtils.formParameter(newJobName), crumbFlag); + return this; } @@ -910,12 +928,13 @@ public void close() { * @throws IOException * in case of an error. */ - public void restart(Boolean crumbFlag) throws IOException { + 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; } /** @@ -928,12 +947,13 @@ public void restart(Boolean crumbFlag) throws IOException { * @throws IOException * in case of an error. */ - public void safeRestart(Boolean crumbFlag) throws IOException { + public JenkinsServer safeRestart(Boolean crumbFlag) throws IOException { try { client.post("/safeRestart", crumbFlag); } catch (org.apache.http.client.ClientProtocolException e) { LOGGER.error("safeRestart()", e); } + return this; } /** @@ -945,13 +965,13 @@ public void safeRestart(Boolean crumbFlag) throws IOException { * @throws IOException * in case of an error. */ - // - public void exit(Boolean crumbFlag) throws IOException { + public JenkinsServer exit(Boolean crumbFlag) throws IOException { try { client.post("/exit", crumbFlag); } catch (org.apache.http.client.ClientProtocolException e) { LOGGER.error("exit()", e); } + return this; } /** @@ -964,11 +984,12 @@ public void exit(Boolean crumbFlag) throws IOException { * @throws IOException * in case of an error. */ - public void safeExit(Boolean crumbFlag) throws IOException { + public JenkinsServer safeExit(Boolean crumbFlag) throws IOException { try { client.post("/safeExit", crumbFlag); } catch (org.apache.http.client.ClientProtocolException e) { LOGGER.error("safeExit()", e); } + return this; } } diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/client/JenkinsHttpClient.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/client/JenkinsHttpClient.java index 3954f952..4eadc5c9 100755 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/client/JenkinsHttpClient.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/client/JenkinsHttpClient.java @@ -6,8 +6,6 @@ package com.offbytwo.jenkins.client; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.collect.Lists; -import com.google.common.io.ByteStreams; import com.offbytwo.jenkins.client.util.EncodingUtils; import com.offbytwo.jenkins.client.util.RequestReleasingInputStream; import com.offbytwo.jenkins.client.validator.HttpResponseValidator; @@ -17,7 +15,6 @@ import net.sf.json.JSONObject; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; -import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; @@ -48,6 +45,8 @@ import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.nio.ByteBuffer; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -227,12 +226,7 @@ public R post(String path, D data, Class cls, boolea @Override public R post(String path, D data, Class cls, Map fileParams, boolean crumbFlag) throws IOException { HttpPost request = new HttpPost(UrlUtils.toJsonApiUri(uri, context, path)); - if (crumbFlag == true) { - Crumb crumb = getQuietly("/crumbIssuer", Crumb.class); - if (crumb != null) { - request.addHeader(new BasicHeader(crumb.getCrumbRequestField(), crumb.getCrumb())); - } - } + handleCrumbFlag(crumbFlag, request); if (data != null) { String value = mapper.writeValueAsString(data); @@ -279,6 +273,15 @@ public R post(String path, D data, Class cls, Map data, boolean crumbFlag) if (data != null) { // https://gist.github.com/stuart-warren/7786892 was slightly // helpful here - List queryParams = Lists.newArrayList(); + List queryParams = new ArrayList<>(); for (String param : data.keySet()) { - queryParams.add(param + "=" + EncodingUtils.encodeParam(data.get(param))); + queryParams.add(param + "=" + EncodingUtils.formParameter(data.get(param))); } - queryParams.add("json=" + EncodingUtils.encodeParam(JSONObject.fromObject(data).toString())); + queryParams.add("json=" + EncodingUtils.formParameter(JSONObject.fromObject(data).toString())); String value = mapper.writeValueAsString(data); StringEntity stringEntity = new StringEntity(value, ContentType.APPLICATION_FORM_URLENCODED); request = new HttpPost(UrlUtils.toNoApiUri(uri, context, path) + StringUtils.join(queryParams, "&")); @@ -302,12 +305,7 @@ public void post_form(String path, Map data, boolean crumbFlag) request = new HttpPost(UrlUtils.toNoApiUri(uri, context, path)); } - if (crumbFlag == true) { - Crumb crumb = get("/crumbIssuer", Crumb.class); - if (crumb != null) { - request.addHeader(new BasicHeader(crumb.getCrumbRequestField(), crumb.getCrumb())); - } - } + handleCrumbFlag(crumbFlag, request); HttpResponse response = client.execute(request, localContext); jenkinsVersion = ResponseUtils.getJenkinsVersion(response); @@ -334,12 +332,7 @@ public HttpResponse post_form_with_result(String path, List data, request = new HttpPost(UrlUtils.toNoApiUri(uri, context, path)); } - if (crumbFlag == true) { - Crumb crumb = get("/crumbIssuer", Crumb.class); - if (crumb != null) { - request.addHeader(new BasicHeader(crumb.getCrumbRequestField(), crumb.getCrumb())); - } - } + handleCrumbFlag(crumbFlag, request); HttpResponse response = client.execute(request, localContext); jenkinsVersion = ResponseUtils.getJenkinsVersion(response); return response; @@ -359,12 +352,7 @@ public String post_xml(String path, String xml_data) throws IOException { @Override public String post_xml(String path, String xml_data, boolean crumbFlag) throws IOException { HttpPost request = new HttpPost(UrlUtils.toJsonApiUri(uri, context, path)); - if (crumbFlag == true) { - Crumb crumb = getQuietly("/crumbIssuer", Crumb.class); - if (crumb != null) { - request.addHeader(new BasicHeader(crumb.getCrumbRequestField(), crumb.getCrumb())); - } - } + handleCrumbFlag(crumbFlag, request); if (xml_data != null) { request.setEntity(new StringEntity(xml_data, ContentType.create("text/xml", "utf-8"))); @@ -395,12 +383,7 @@ public String post_text(String path, String textData, boolean crumbFlag) throws public String post_text(String path, String textData, ContentType contentType, boolean crumbFlag) throws IOException { HttpPost request = new HttpPost(UrlUtils.toJsonApiUri(uri, context, path)); - if (crumbFlag == true) { - Crumb crumb = get("/crumbIssuer", Crumb.class); - if (crumb != null) { - request.addHeader(new BasicHeader(crumb.getCrumbRequestField(), crumb.getCrumb())); - } - } + handleCrumbFlag(crumbFlag, request); if (textData != null) { request.setEntity(new StringEntity(textData, contentType)); @@ -510,7 +493,7 @@ protected void setLocalContext(final HttpContext localContext) { private T objectFromResponse(Class cls, HttpResponse response) throws IOException { InputStream content = response.getEntity().getContent(); - byte[] bytes = ByteStreams.toByteArray(content); + byte[] bytes = IOUtils.toByteArray(content); T result = mapper.readValue(bytes, cls); // TODO: original: // T result = mapper.readValue(content, cls); diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/client/JenkinsHttpConnection.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/client/JenkinsHttpConnection.java index 26a6fb01..b90bfcaf 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/client/JenkinsHttpConnection.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/client/JenkinsHttpConnection.java @@ -150,7 +150,7 @@ public interface JenkinsHttpConnection extends Closeable { * useful for other API calls as well. Unlike post and post_xml, the path is * *not* modified by adding "/toJsonApiUri/json". Additionally, the params * in data are provided as both request parameters including a json - * parameter, *and* in the JSON-formatted StringEntity, because this is what + * formParameter, *and* in the JSON-formatted StringEntity, because this is what * the folder creation call required. It is unclear if any other jenkins * APIs operate in this fashion. * diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/client/util/EncodingUtils.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/client/util/EncodingUtils.java index 25661294..4638634b 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/client/util/EncodingUtils.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/client/util/EncodingUtils.java @@ -1,7 +1,21 @@ +/* + * Copyright (c) 2019 Karl Heinz Marbaise, and contributors. + * + * Distributed under the MIT license: http://opensource.org/licenses/MIT + */ package com.offbytwo.jenkins.client.util; -import com.google.common.net.UrlEscapers; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; + +/** + * This class is a help class to centralize the + * encoding parts which will call an appropriate library function. + * + * @author Karl Heinz Marbaise + */ public final class EncodingUtils { private EncodingUtils() { @@ -9,13 +23,24 @@ private EncodingUtils() { public static String encode(String pathPart) { // jenkins doesn't like the + for space, use %20 instead - String escape = UrlEscapers.urlPathSegmentEscaper().escape(pathPart); - return escape; + try { + return URLEncoder.encode(pathPart, StandardCharsets.UTF_8.displayName()); + } catch (UnsupportedEncodingException e) { + // Should never happen, because that would imply that + // the parameter StandardCharsets.UTF_8 is wrong. + throw new IllegalArgumentException(e); + } } - public static String encodeParam(String pathPart) { + public static String formParameter(String pathPart) { // jenkins doesn't like the + for space, use %20 instead - return UrlEscapers.urlFormParameterEscaper().escape(pathPart); + try { + return URLEncoder.encode(pathPart, StandardCharsets.UTF_8.displayName()); + } catch (UnsupportedEncodingException e) { + // Should never happen, because that would imply that + // the parameter StandardCharsets.UTF_8 is wrong. + throw new IllegalArgumentException(e); + } } } diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/helper/FunctionalHelper.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/helper/FunctionalHelper.java new file mode 100644 index 00000000..d7f507b7 --- /dev/null +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/helper/FunctionalHelper.java @@ -0,0 +1,22 @@ +package com.offbytwo.jenkins.helper; + +import com.offbytwo.jenkins.client.JenkinsHttpConnection; +import com.offbytwo.jenkins.model.BaseModel; + +import java.util.function.Function; + +public final class FunctionalHelper { + + private FunctionalHelper() { + // intentionally empty. + } + + public static final Function SET_CLIENT(JenkinsHttpConnection client) { + return s -> { + s.setClient(client); + return s; + }; + } + + +} diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/helper/Range.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/helper/Range.java index 8b70eb09..cdbdc60a 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/helper/Range.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/helper/Range.java @@ -16,122 +16,127 @@ * The same as {0,N}. *
  • {N}: Just retrieve the N-th element. The same as {N,N+1}.
  • * - * + *

    * You can use the {@link Range} class like this: - * + * *

      * Range fromAndTo = Range.build().from(1).to(5);
      * Range fromOnly = Range.build().from(3).build();
      * Range toOnly = Range.build().to(5).build();
      * Range only = Range.build().only(3);
      * 
    - * - * @author Karl Heinz Marbaise * + * @author Karl Heinz Marbaise */ public final class Range { - public static final String CURLY_BRACKET_OPEN = "%7B"; // { - public static final String CURLY_BRACKET_CLOSE = "%7D"; // } + /** + * This represents {@code {} (left curly bracket). + */ + public static final String CURLY_BRACKET_OPEN = "%7B"; + /** + * This represents {@code }} (right curly bracket). + */ + public static final String CURLY_BRACKET_CLOSE = "%7D"; private Integer from; private Integer to; private Range() { - this.from = null; - this.to = null; + this.from = null; + this.to = null; } private Range setFrom(int from) { - if (from < 0) { - throw new IllegalArgumentException("from value must be greater or equal null."); - } - this.from = new Integer(from); - return this; + if (from < 0) { + throw new IllegalArgumentException("from value must be greater or equal null."); + } + this.from = new Integer(from); + return this; } private Range setTo(int to) { - if (to < 0) { - throw new IllegalArgumentException("to must be greater or equal null."); - } - this.to = new Integer(to); - return this; + if (to < 0) { + throw new IllegalArgumentException("to must be greater or equal null."); + } + this.to = new Integer(to); + return this; } public String getRangeString() { - StringBuilder sb = new StringBuilder(); - sb.append(CURLY_BRACKET_OPEN); - if (this.from != null) { - sb.append(String.format("%d", this.from)); - } + StringBuilder sb = new StringBuilder(); + sb.append(CURLY_BRACKET_OPEN); + if (this.from != null) { + sb.append(String.format("%d", this.from)); + } - sb.append(','); + sb.append(','); - if (this.to != null) { - sb.append(String.format("%d", this.to)); - } + if (this.to != null) { + sb.append(String.format("%d", this.to)); + } - sb.append(CURLY_BRACKET_CLOSE); - return sb.toString(); + sb.append(CURLY_BRACKET_CLOSE); + return sb.toString(); } public static final class FromBuilder { - private Range range; - - public FromBuilder(Range range) { - this.range = range; - } - - public Range to(int t) { - this.range.setTo(t); - if (range.to <= range.from) { - throw new IllegalArgumentException("to must be greater than from"); - } - return this.range; - } - - public Range build() { - return this.range; - } + private Range range; + + public FromBuilder(Range range) { + this.range = range; + } + + public Range to(int t) { + this.range.setTo(t); + if (range.to <= range.from) { + throw new IllegalArgumentException("to must be greater than from"); + } + return this.range; + } + + public Range build() { + return this.range; + } } public static final class ToBuilder { - private Range range; + private Range range; - public ToBuilder(Range range) { - this.range = range; - } + public ToBuilder(Range range) { + this.range = range; + } - public Range build() { - return this.range; - } + public Range build() { + return this.range; + } } public static final class Builder { - private Range range; - - protected Builder() { - this.range = new Range(); - } - - public FromBuilder from(int f) { - this.range.setFrom(f); - return new FromBuilder(this.range); - } - - public ToBuilder to(int t) { - this.range.setTo(t); - return new ToBuilder(this.range); - } - - public Range only(int only) { - this.range.from = new Integer(only); - this.range.to = new Integer(only + 1); - return this.range; - } + private Range range; + + protected Builder() { + this.range = new Range(); + } + + public FromBuilder from(int f) { + this.range.setFrom(f); + return new FromBuilder(this.range); + } + + public ToBuilder to(int t) { + this.range.setTo(t); + return new ToBuilder(this.range); + } + + public Range only(int only) { + this.range.from = new Integer(only); + this.range.to = new Integer(only + 1); + return this.range; + } } public static Builder build() { - return new Builder(); + return new Builder(); } } \ No newline at end of file diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Artifact.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Artifact.java index 6d0b0e69..a6c7a2f0 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Artifact.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Artifact.java @@ -16,24 +16,27 @@ public String getDisplayPath() { return displayPath; } - public void setDisplayPath(String displayPath) { + public Artifact setDisplayPath(String displayPath) { this.displayPath = displayPath; + return this; } public String getFileName() { return fileName; } - public void setFileName(String fileName) { + public Artifact setFileName(String fileName) { this.fileName = fileName; + return this; } public String getRelativePath() { return relativePath; } - public void setRelativePath(String relativePath) { + public Artifact setRelativePath(String relativePath) { this.relativePath = relativePath; + return this; } @Override diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BaseModel.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BaseModel.java index 95f70bab..5275d36b 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BaseModel.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BaseModel.java @@ -7,6 +7,7 @@ package com.offbytwo.jenkins.model; import com.offbytwo.jenkins.client.JenkinsHttpConnection; +import java.util.function.Predicate; /** * The base model. @@ -17,8 +18,7 @@ public class BaseModel { * The class. */ private String _class; - - + /** * Get the class. * @return class @@ -43,7 +43,13 @@ public JenkinsHttpConnection getClient() { * Set the HTTP client. * @param client {@link JenkinsHttpConnection}. */ - public void setClient(final JenkinsHttpConnection client) { + public BaseModel setClient(final JenkinsHttpConnection client) { this.client = client; + return this; } + + protected static Predicate isBuildNumberEqualTo(int buildNumber) { + return build -> build.getNumber() == buildNumber; + } + } diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Build.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Build.java index f48e38e8..470707d9 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Build.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Build.java @@ -8,6 +8,7 @@ import java.io.IOException; +import org.apache.http.HttpStatus; import org.apache.http.client.HttpResponseException; public class Build extends BaseModel { @@ -82,16 +83,19 @@ public String getUrl() { return url; } - protected void setNumber(int number) { + protected Build setNumber(int number) { this.number = number; + return this; } - protected void setQueueId(int queueId) { + protected Build setQueueId(int queueId) { this.queueId = queueId; + return this; } - protected void setUrl(String url) { + protected Build setUrl(String url) { this.url = url; + return this; } /** @@ -122,6 +126,7 @@ public TestReport getTestReport() throws IOException { * @throws IOException in case of an error. */ public TestResult getTestResult() throws IOException { + return client.get(this.getUrl() + "/testReport/?depth=1", TestResult.class); } @@ -141,7 +146,7 @@ public String Stop() throws HttpResponseException, IOException { return client.get(url + "stop"); } catch (HttpResponseException ex) { - if (ex.getStatusCode() == 405) { + if (ex.getStatusCode() == HttpStatus.SC_METHOD_NOT_ALLOWED) { stopPost(); return ""; } @@ -164,7 +169,7 @@ public String Stop(boolean crumbFlag) throws HttpResponseException, IOException return client.get(url + "stop"); } catch (HttpResponseException ex) { - if (ex.getStatusCode() == 405) { + if (ex.getStatusCode() == HttpStatus.SC_METHOD_NOT_ALLOWED) { stopPost(crumbFlag); return ""; } diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildCause.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildCause.java index ab15f94f..821a027f 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildCause.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildCause.java @@ -29,48 +29,54 @@ public String getShortDescription() { return shortDescription; } - public void setShortDescription(String shortDescription) { + public BuildCause setShortDescription(String shortDescription) { this.shortDescription = shortDescription; + return this; } public int getUpstreamBuild() { return upstreamBuild; } - public void setUpstreamBuild(Integer upstreamBuild) { + public BuildCause setUpstreamBuild(Integer upstreamBuild) { this.upstreamBuild = upstreamBuild; + return this; } public String getUpstreamProject() { return upstreamProject; } - public void setUpstreamProject(String upstreamProject) { + public BuildCause setUpstreamProject(String upstreamProject) { this.upstreamProject = upstreamProject; + return this; } public String getUpstreamUrl() { return upstreamUrl; } - public void setUpstreamUrl(String upstreamUrl) { + public BuildCause setUpstreamUrl(String upstreamUrl) { this.upstreamUrl = upstreamUrl; + return this; } public String getUserId() { return userId; } - public void setUserId(String userId) { + public BuildCause setUserId(String userId) { this.userId = userId; + return this; } public String getUserName() { return userName; } - public void setUserName(String userName) { + public BuildCause setUserName(String userName) { this.userName = userName; + return this; } @Override diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildChangeSet.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildChangeSet.java index 1987cc49..2b7cf520 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildChangeSet.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildChangeSet.java @@ -24,8 +24,9 @@ public class BuildChangeSet { /** * @param items {@link BuildChangeSet} */ - public void setItems(List items) { + public BuildChangeSet setItems(List items) { this.items = items; + return this; } /** @@ -45,8 +46,9 @@ public String getKind() { /** * @param kind the kind of (usually svn, git). */ - public void setKind(String kind) { + public BuildChangeSet setKind(String kind) { this.kind = kind; + return this; } @Override diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildChangeSetAuthor.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildChangeSetAuthor.java index 9abdd1ba..af416581 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildChangeSetAuthor.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildChangeSetAuthor.java @@ -13,16 +13,18 @@ public String getAbsoluteUrl() { return absoluteUrl; } - public void setAbsoluteUrl(String absoluteUrl) { + public BuildChangeSetAuthor setAbsoluteUrl(String absoluteUrl) { this.absoluteUrl = absoluteUrl; + return this; } public String getFullName() { return fullName; } - public void setFullName(String fullName) { + public BuildChangeSetAuthor setFullName(String fullName) { this.fullName = fullName; + return this; } @Override diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildChangeSetItem.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildChangeSetItem.java index e817d12b..922a19b1 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildChangeSetItem.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildChangeSetItem.java @@ -27,72 +27,81 @@ public List getAffectedPaths() { return affectedPaths; } - public void setAffectedPaths(List affectedPaths) { + public BuildChangeSetItem setAffectedPaths(List affectedPaths) { this.affectedPaths = affectedPaths; + return this; } public String getCommitId() { return commitId; } - public void setCommitId(String commitId) { + public BuildChangeSetItem setCommitId(String commitId) { this.commitId = commitId; + return this; } public String getTimestamp() { return timestamp; } - public void setTimestamp(String timeStamp) { + public BuildChangeSetItem setTimestamp(String timeStamp) { this.timestamp = timeStamp; + return this; } public String getComment() { return comment; } - public void setComment(String comment) { + public BuildChangeSetItem setComment(String comment) { this.comment = comment; + return this; } public String getDate() { return date; } - public void setDate(String date) { + public BuildChangeSetItem setDate(String date) { this.date = date; + return this; } public String getId() { return id; } - public void setId(String id) { + public BuildChangeSetItem setId(String id) { this.id = id; + return this; } public String getMsg() { return msg; } - public void setMsg(String msg) { + public BuildChangeSetItem setMsg(String msg) { this.msg = msg; + return this; } public List getPaths() { return paths; } - public void setPaths(List paths) { + public BuildChangeSetItem setPaths(List paths) { this.paths = paths; + return this; } public BuildChangeSetAuthor getAuthor() { return author; } - public void setAuthor(BuildChangeSetAuthor author) { + public BuildChangeSetItem setAuthor(BuildChangeSetAuthor author) { this.author = author; + return this; } @Override diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildChangeSetPath.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildChangeSetPath.java index e5078f3a..5758ee78 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildChangeSetPath.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildChangeSetPath.java @@ -27,16 +27,18 @@ public String getEditType() { * @param editType the SCM operation, add or edit or delete * @see EditType */ - public void setEditType(String editType) { + public BuildChangeSetPath setEditType(String editType) { this.editType = editType; + return this; } public String getFile() { return file; } - public void setFile(String file) { + public BuildChangeSetPath setFile(String file) { this.file = file; + return this; } @Override diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildWithDetails.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildWithDetails.java index 8674e921..d3ce5842 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildWithDetails.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildWithDetails.java @@ -7,9 +7,6 @@ package com.offbytwo.jenkins.model; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.base.Predicate; -import com.google.common.base.Strings; -import com.google.common.collect.ImmutableMap; import com.offbytwo.jenkins.helper.BuildConsoleStreamListener; import org.apache.http.Header; import org.apache.http.HttpResponse; @@ -24,14 +21,15 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; -import static com.google.common.collect.Collections2.filter; +import static java.util.stream.Collectors.toList; +import static java.util.stream.Collectors.toMap; /** * This class represents build information with details about what has been done @@ -111,7 +109,7 @@ public BuildResult getResult() { }; - private List actions; // TODO: Should be improved. + private List>>> actions; // TODO: Should be improved. private boolean building; private String description; private String displayName; @@ -163,31 +161,12 @@ public boolean isBuilding() { } public List getCauses() { - // actions is a List List[BuildCause] - Collection causes = filter(actions, new Predicate>() { - @Override - public boolean apply(Map action) { - return action.containsKey("causes"); - } - }); - - List result = new ArrayList(); - - if (causes != null && !causes.isEmpty()) { - // The underlying key-value can be either a or a - // . - List> causes_blob = ((Map>>) causes.toArray()[0]) - .get("causes"); - for (Map cause : causes_blob) { - - BuildCause convertToBuildCause = convertToBuildCause(cause); - - result.add(convertToBuildCause); - } - } - - return result; + return actions.stream() + .filter(item -> item.containsKey("causes")) + .flatMap(item -> item.entrySet().stream()) + .flatMap(sub -> sub.getValue().stream()) + .map(item -> convertToBuildCause(item)) + .collect(toList()); } /** @@ -199,14 +178,19 @@ public boolean apply(Map action) { * @param crumbFlag true or false. * @throws IOException in case of errors. */ - public void updateDisplayNameAndDescription(String displayName, String description, boolean crumbFlag) + public BuildWithDetails updateDisplayNameAndDescription(String displayName, String description, boolean crumbFlag) throws IOException { Objects.requireNonNull(displayName, "displayName is not allowed to be null."); Objects.requireNonNull(description, "description is not allowed to be null."); + //TODO:JDK9+ Map.of()... + Map params = new HashMap<>(); + params.put("displayName", displayName); + params.put("description", description); // TODO: Check what the "core:apply" means? - ImmutableMap params = ImmutableMap.of("displayName", displayName, "description", description, - "core:apply", "", "Submit", "Save"); + params.put("core:apply", ""); + params.put("Submit", "Save"); client.post_form(this.getUrl() + "/configSubmit?", params, crumbFlag); + return this; } /** @@ -217,8 +201,8 @@ public void updateDisplayNameAndDescription(String displayName, String descripti * @param description The description which should be set. * @throws IOException in case of errors. */ - public void updateDisplayNameAndDescription(String displayName, String description) throws IOException { - updateDisplayNameAndDescription(displayName, description, false); + public BuildWithDetails updateDisplayNameAndDescription(String displayName, String description) throws IOException { + return updateDisplayNameAndDescription(displayName, description, false); } /** @@ -228,13 +212,17 @@ public void updateDisplayNameAndDescription(String displayName, String descripti * @param crumbFlag true or false. * @throws IOException in case of errors. */ - public void updateDisplayName(String displayName, boolean crumbFlag) throws IOException { + public BuildWithDetails updateDisplayName(String displayName, boolean crumbFlag) throws IOException { Objects.requireNonNull(displayName, "displayName is not allowed to be null."); String description = getDescription() == null ? "" : getDescription(); + Map params = new HashMap<>(); + params.put("displayName", displayName); + params.put("description", description); // TODO: Check what the "core:apply" means? - ImmutableMap params = ImmutableMap.of("displayName", displayName, "description", description, - "core:apply", "", "Submit", "Save"); + params.put("core:apply", ""); + params.put("Submit", "Save"); client.post_form(this.getUrl() + "/configSubmit?", params, crumbFlag); + return this; } /** @@ -243,8 +231,8 @@ public void updateDisplayName(String displayName, boolean crumbFlag) throws IOEx * @param displayName The new displayName which should be set. * @throws IOException in case of errors. */ - public void updateDisplayName(String displayName) throws IOException { - updateDisplayName(displayName, false); + public BuildWithDetails updateDisplayName(String displayName) throws IOException { + return updateDisplayName(displayName, false); } /** @@ -254,13 +242,18 @@ public void updateDisplayName(String displayName) throws IOException { * @param crumbFlag true or false. * @throws IOException in case of errors. */ - public void updateDescription(String description, boolean crumbFlag) throws IOException { + public BuildWithDetails updateDescription(String description, boolean crumbFlag) throws IOException { Objects.requireNonNull(description, "description is not allowed to be null."); String displayName = getDisplayName() == null ? "" : getDisplayName(); + //JDK9+: Map.of(..) + Map params = new HashMap<>(); + params.put("displayName", displayName); + params.put("description", description); // TODO: Check what the "core:apply" means? - ImmutableMap params = ImmutableMap.of("displayName", displayName, "description", description, - "core:apply", "", "Submit", "Save"); + params.put("core:apply", ""); + params.put("Submit", "Save"); client.post_form(this.getUrl() + "/configSubmit?", params, crumbFlag); + return this; } /** @@ -269,8 +262,12 @@ public void updateDescription(String description, boolean crumbFlag) throws IOEx * @param description The description which should be set. * @throws IOException in case of errors. */ - public void updateDescription(String description) throws IOException { - updateDescription(description, false); + public BuildWithDetails updateDescription(String description) throws IOException { + return updateDescription(description, false); + } + + private boolean isNullOrEmpty(String value) { + return value == null || value.isEmpty(); } private BuildCause convertToBuildCause(Map cause) { @@ -278,7 +275,7 @@ private BuildCause convertToBuildCause(Map cause) { // TODO: Think about it. Can this be done more simpler? String description = (String) cause.get("shortDescription"); - if (!Strings.isNullOrEmpty(description)) { + if (!isNullOrEmpty(description)) { cause_object.setShortDescription(description); } @@ -288,22 +285,22 @@ private BuildCause convertToBuildCause(Map cause) { } String upstreamProject = (String) cause.get("upstreamProject"); - if (!Strings.isNullOrEmpty(upstreamProject)) { + if (!isNullOrEmpty(upstreamProject)) { cause_object.setUpstreamProject(upstreamProject); } String upstreamUrl = (String) cause.get("upstreamUrl"); - if (!Strings.isNullOrEmpty(upstreamUrl)) { + if (!isNullOrEmpty(upstreamUrl)) { cause_object.setUpstreamUrl(upstreamUrl); } String userId = (String) cause.get("userId"); - if (!Strings.isNullOrEmpty(userId)) { + if (!isNullOrEmpty(userId)) { cause_object.setUserId(userId); } String userName = (String) cause.get("userName"); - if (!Strings.isNullOrEmpty(userName)) { + if (!isNullOrEmpty(userName)) { cause_object.setUserName(userName); } return cause_object; @@ -349,33 +346,21 @@ public List getActions() { return actions; } - public Map getParameters() { - Collection parameters = filter(actions, new Predicate>() { - @Override - public boolean apply(Map action) { - return action.containsKey("parameters"); - } - }); - - Map params = new HashMap(); - - if (parameters != null && !parameters.isEmpty()) { - for (Map param : ((Map>>) parameters.toArray()[0]) - .get("parameters")) { - String key = (String) param.get("name"); - Object value = param.get("value"); - params.put(key, String.valueOf(value)); - } - } + public Map getParameters() { + Map parameters = actions.stream() + .filter(item -> item.containsKey("parameters")) + .flatMap(item -> item.entrySet().stream()) + .flatMap(sub -> sub.getValue().stream()) + .collect(toMap(k -> (String) k.get("name"), v -> v.get("value"))); - return params; + return parameters; } /** * @return The full console output of the build. The line separation is done by * {@code CR+LF}. * - * @see streamConsoleOutput method for obtaining logs for running build + * @see #streamConsoleOutput(BuildConsoleStreamListener, int, int, boolean) method for obtaining logs for running build * * @throws IOException in case of a failure. */ @@ -386,7 +371,7 @@ public String getConsoleOutputText() throws IOException { /** * The full console output with HTML. * - * @see streamConsoleOutput method for obtaining logs for running build + * @see #streamConsoleOutput(BuildConsoleStreamListener, int, int, boolean) method for obtaining logs for running build * * @return The console output as HTML. * @throws IOException in case of an error. @@ -407,7 +392,7 @@ public String getConsoleOutputHtml() throws IOException { * @throws IOException in case of an error. * */ - public void streamConsoleOutput(final BuildConsoleStreamListener listener, final int poolingInterval, final int poolingTimeout) throws InterruptedException, IOException { + public void streamConsoleOutput(final BuildConsoleStreamListener listener, final int poolingInterval, final int poolingTimeout, boolean crumbFlag) throws InterruptedException, IOException { // Calculate start and timeout final long startTime = System.currentTimeMillis(); final long timeoutTime = startTime + (poolingTimeout * 1000); @@ -417,7 +402,7 @@ public void streamConsoleOutput(final BuildConsoleStreamListener listener, final Thread.sleep(poolingInterval * 1000); ConsoleLog consoleLog = null; - consoleLog = getConsoleOutputText(bufferOffset); + consoleLog = getConsoleOutputText(bufferOffset, crumbFlag); String logString = consoleLog.getConsoleLog(); if (logString != null && !logString.isEmpty()) { listener.onData(logString); @@ -443,15 +428,16 @@ public void streamConsoleOutput(final BuildConsoleStreamListener listener, final * Use this method to periodically obtain logs from jenkins and skip chunks that were already received * * @param bufferOffset offset in console lo + * @param crumbFlag true or false. * @return ConsoleLog object containing console output of the build. The line separation is done by * {@code CR+LF}. * @throws IOException in case of a failure. */ - public ConsoleLog getConsoleOutputText(int bufferOffset) throws IOException { + public ConsoleLog getConsoleOutputText(int bufferOffset, boolean crumbFlag) throws IOException { List formData = new ArrayList<>(); formData.add(new BasicNameValuePair("start", Integer.toString(bufferOffset))); String path = getUrl() + "logText/progressiveText"; - HttpResponse httpResponse = client.post_form_with_result(path, formData, false); + HttpResponse httpResponse = client.post_form_with_result(path, formData, crumbFlag); Header moreDataHeader = httpResponse.getFirstHeader(MORE_DATA_HEADER); Header textSizeHeader = httpResponse.getFirstHeader(TEXT_SIZE_HEADER); @@ -496,8 +482,9 @@ public BuildChangeSet getChangeSet() { return result; } - public void setChangeSet(BuildChangeSet changeSet) { + public BuildWithDetails setChangeSet(BuildChangeSet changeSet) { this.changeSet = changeSet; + return this; } /** @@ -518,20 +505,23 @@ public List getChangeSets() { return result; } - public void setChangeSets(List changeSets) { + public BuildWithDetails setChangeSets(List changeSets) { this.changeSets = changeSets; + return this; } public List getCulprits() { return culprits; } - public void setCulprits(List culprits) { + public BuildWithDetails setCulprits(List culprits) { this.culprits = culprits; + return this; } - public void setResult(BuildResult result) { + public BuildWithDetails setResult(BuildResult result) { this.result = result; + return this; } public InputStream downloadArtifact(Artifact a) throws IOException, URISyntaxException { @@ -543,6 +533,17 @@ public InputStream downloadArtifact(Artifact a) throws IOException, URISyntaxExc ""); return client.getFile(artifactUri); } + + /** + * Returns {@link MavenModuleWithDetails} based on its name + * + * @param name module name + * @return {@link MavenModuleWithDetails} + * @throws IOException in case of error. + */ + public MavenModuleWithDetails getModule(String name) throws IOException { + return client.get(getUrl() + name, MavenModuleWithDetails.class); + } @Override public boolean equals(Object obj) { diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/CauseAction.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/CauseAction.java index e481f03a..dd455b50 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/CauseAction.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/CauseAction.java @@ -9,24 +9,27 @@ public String getShortDescription() { return shortDescription; } - public void setShortDescription(String shortDescription) { + public CauseAction setShortDescription(String shortDescription) { this.shortDescription = shortDescription; + return this; } public String getUserId() { return userId; } - public void setUserId(String userId) { + public CauseAction setUserId(String userId) { this.userId = userId; + return this; } public String getUserName() { return userName; } - public void setUserName(String userName) { + public CauseAction setUserName(String userName) { this.userName = userName; + return this; } @Override diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Computer.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Computer.java index edc7350c..2414f061 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Computer.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Computer.java @@ -9,7 +9,8 @@ import java.io.IOException; import java.util.List; -import com.google.common.net.UrlEscapers; +import com.offbytwo.jenkins.client.util.EncodingUtils; +import com.fasterxml.jackson.annotation.JsonProperty; /** * @author Kelly Plummer @@ -19,17 +20,20 @@ public class Computer extends BaseModel { private String displayName; - public List getComputers() { - return computer; - } + private List computers; - public void setComputer(List computer) { - this.computer = computer; + public Computer() { } - List computer; + @JsonProperty("computer") + public List getComputers() { + return computers; + } - public Computer() { + @JsonProperty("computer") + public Computer setComputers(List computers) { + this.computers = computers; + return this; } public Computer(String displayName) { @@ -46,7 +50,7 @@ public ComputerWithDetails details() throws IOException { if ("master".equals(displayName)) { name = "(master)"; } else { - name = UrlEscapers.urlPathSegmentEscaper().escape(displayName); + name = EncodingUtils.encode(displayName); } // TODO: Check if depth=2 is a good idea or if it could be solved // better. @@ -65,10 +69,10 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) return false; Computer other = (Computer) obj; - if (computer == null) { - if (other.computer != null) + if (computers == null) { + if (other.computers != null) return false; - } else if (!computer.equals(other.computer)) + } else if (!computers.equals(other.computers)) return false; if (displayName == null) { if (other.displayName != null) @@ -82,7 +86,7 @@ public boolean equals(Object obj) { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((computer == null) ? 0 : computer.hashCode()); + result = prime * result + ((computers == null) ? 0 : computers.hashCode()); result = prime * result + ((displayName == null) ? 0 : displayName.hashCode()); return result; } diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ComputerLabel.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ComputerLabel.java new file mode 100644 index 00000000..e61ecd2d --- /dev/null +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ComputerLabel.java @@ -0,0 +1,34 @@ +package com.offbytwo.jenkins.model; + +public class ComputerLabel { + private String name; + + public String getName() { + return name; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ComputerLabel other = (ComputerLabel) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } +} diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ComputerSet.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ComputerSet.java index 7bebc43f..0c12ba5a 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ComputerSet.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ComputerSet.java @@ -7,9 +7,7 @@ package com.offbytwo.jenkins.model; import java.util.List; - -import com.google.common.base.Function; -import com.google.common.collect.Lists; +import java.util.stream.Collectors; public class ComputerSet extends BaseModel { private int busyExecutors; @@ -26,38 +24,39 @@ public int getBusyExecutors() { return busyExecutors; } - public void setBusyExecutors(int busyExecutors) { + public ComputerSet setBusyExecutors(int busyExecutors) { this.busyExecutors = busyExecutors; + return this; } public String getDisplayName() { return displayName; } - public void setDisplayName(String displayName) { + public ComputerSet setDisplayName(String displayName) { this.displayName = displayName; + return this; } public int getTotalExecutors() { return totalExecutors; } - public void setTotalExecutors(int totalExecutors) { + public ComputerSet setTotalExecutors(int totalExecutors) { this.totalExecutors = totalExecutors; + return this; } public List getComputers() { - return Lists.transform( computer, new Function() { - @Override - public ComputerWithDetails apply(ComputerWithDetails computerWithDetails) { - computerWithDetails.setClient(client); - return computerWithDetails; - } - }); + return computer.stream().map(s -> { + s.setClient(this.client); + return s; + }).collect(Collectors.toList()); } - public void setComputer(List computers) { + public ComputerSet setComputer(List computers) { this.computer = computers; + return this; } @Override diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ComputerWithDetails.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ComputerWithDetails.java index c565f8a2..c57b40a5 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ComputerWithDetails.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ComputerWithDetails.java @@ -10,15 +10,15 @@ import java.util.HashMap; import java.util.List; import java.util.Map; - -import com.google.common.base.Function; -import com.google.common.net.UrlEscapers; +import com.offbytwo.jenkins.client.util.EncodingUtils; +import java.util.function.Function; public class ComputerWithDetails extends Computer { private String displayName; private List actions; //TODO: What kind of List? private List executors; + private List assignedLabels; private Boolean idle; private Boolean jnlp; private Boolean launchSupported; @@ -34,6 +34,7 @@ public class ComputerWithDetails extends Computer { public ComputerWithDetails() { } + @Override public String getDisplayName() { return displayName; } @@ -46,6 +47,10 @@ public List getExecutors() { return executors; } + public List getAssignedLabels() { + return assignedLabels; + } + public Boolean getIdle() { return idle; } @@ -72,46 +77,45 @@ public LoadStatistics getLoadStatistics() throws IOException { if ("master".equals(displayName)) { name = "(master)"; } else { - name = UrlEscapers.urlPathSegmentEscaper().escape(displayName); + name = EncodingUtils.encode(displayName); } // TODO: ?depth=2 good idea or could this being done better? return client.get("/computer/" + name + "/" + "loadStatistics/?depth=2", LoadStatistics.class); } - public void toggleOffline(boolean crumbFlag) throws IOException { + public ComputerWithDetails toggleOffline(boolean crumbFlag) throws IOException { // curl --data "json=init" -X POST "http://192.168.99.100:8080/computer/(master)/toggleOffline" String name; if ("master".equals(displayName)) { name = "(master)"; } else { - name = UrlEscapers.urlPathSegmentEscaper().escape(displayName); + name = EncodingUtils.encode(displayName); } - Map data = new HashMap(); - data.put( "json", "init" ); client.post( "/computer/" + name + "/toggleOffline", crumbFlag); + return this; } - public void toggleOffline() throws IOException { - toggleOffline( false ); + public ComputerWithDetails toggleOffline() throws IOException { + return toggleOffline(false); } - public void changeOfflineCause(String cause, boolean crumbFlag) throws IOException { + public ComputerWithDetails changeOfflineCause(String cause, boolean crumbFlag) throws IOException { String name; if ("master".equals(displayName)) { name = "(master)"; } else { - name = UrlEscapers.urlPathSegmentEscaper().escape(displayName); + name = EncodingUtils.encode(displayName); } - - Map data = new HashMap(); - data.put( "offlineMessage", cause ); - client.post_form("/computer/" + name + "/changeOfflineCause?", data, crumbFlag); + Map data = new HashMap(); + data.put("offlineMessage", cause); + client.post_form("/computer/" + name + "/changeOfflineCause?", data, crumbFlag); + return this; } - public void changeOfflineCause(String cause) throws IOException { - changeOfflineCause(cause, false); + public ComputerWithDetails changeOfflineCause(String cause) throws IOException { + return changeOfflineCause(cause, false); } public Boolean getManualLaunchAllowed() { @@ -170,6 +174,11 @@ public boolean equals(Object obj) { return false; } else if (!executors.equals(other.executors)) return false; + if (assignedLabels == null) { + if (other.assignedLabels != null) + return false; + } else if (!assignedLabels.equals(other.assignedLabels)) + return false; if (idle == null) { if (other.idle != null) return false; @@ -249,11 +258,4 @@ public int hashCode() { return result; } - private class ComputerWithClient implements Function { - @Override - public Computer apply(Computer computer) { - computer.setClient(client); - return computer; - } - } } \ No newline at end of file diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ConsoleLog.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ConsoleLog.java index 59ef5c6d..503e1ce0 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ConsoleLog.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ConsoleLog.java @@ -19,23 +19,26 @@ public String getConsoleLog() { return consoleLog; } - public void setConsoleLog(String consoleLog) { + public ConsoleLog setConsoleLog(String consoleLog) { this.consoleLog = consoleLog; + return this; } public Boolean getHasMoreData() { return hasMoreData; } - public void setHasMoreData(Boolean hasMoreData) { + public ConsoleLog setHasMoreData(Boolean hasMoreData) { this.hasMoreData = hasMoreData; + return this; } public Integer getCurrentBufferSize() { return currentBufferSize; } - public void setCurrentBufferSize(Integer currentBufferSize) { + public ConsoleLog setCurrentBufferSize(Integer currentBufferSize) { this.currentBufferSize = currentBufferSize; + return this; } } diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Executable.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Executable.java index ff1b6e27..5f044e13 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Executable.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Executable.java @@ -9,16 +9,18 @@ public Long getNumber() { return number; } - public void setNumber(Long number) { + public Executable setNumber(Long number) { this.number = number; + return this; } public String getUrl() { return url; } - public void setUrl(String url) { + public Executable setUrl(String url) { this.url = url; + return this; } @Override diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Executor.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Executor.java index 15fcebde..c6914d97 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Executor.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Executor.java @@ -23,48 +23,54 @@ public Job getCurrentExecutable() { return currentExecutable; } - public void setCurrentExecutable(Job currentExecutable) { + public Executor setCurrentExecutable(Job currentExecutable) { this.currentExecutable = currentExecutable; + return this; } public Job getCurrentWorkUnit() { return currentWorkUnit; } - public void setCurrentWorkUnit(Job currentWorkUnit) { + public Executor setCurrentWorkUnit(Job currentWorkUnit) { this.currentWorkUnit = currentWorkUnit; + return this; } public Boolean getIdle() { return idle; } - public void setIdle(Boolean idle) { + public Executor setIdle(Boolean idle) { this.idle = idle; + return this; } public Boolean getLikelyStuck() { return likelyStuck; } - public void setLikelyStuck(Boolean likelyStuck) { + public Executor setLikelyStuck(Boolean likelyStuck) { this.likelyStuck = likelyStuck; + return this; } public int getNumber() { return number; } - public void setNumber(int number) { + public Executor setNumber(int number) { this.number = number; + return this; } public int getProgress() { return progress; } - public void setProgress(int progress) { + public Executor setProgress(int progress) { this.progress = progress; + return this; } @Override diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ExtractHeader.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ExtractHeader.java index cb3c683a..6dd43221 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ExtractHeader.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ExtractHeader.java @@ -4,8 +4,9 @@ public class ExtractHeader extends BaseModel { private String location; - public void setLocation(String value) { + public ExtractHeader setLocation(String value) { location = value; + return this; } public String getLocation() { diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/FolderJob.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/FolderJob.java index 844c801d..f2677081 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/FolderJob.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/FolderJob.java @@ -1,13 +1,15 @@ package com.offbytwo.jenkins.model; +import com.offbytwo.jenkins.helper.FunctionalHelper; + import java.io.IOException; +import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; -import com.google.common.base.Function; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; -import com.offbytwo.jenkins.client.util.EncodingUtils; +import static com.offbytwo.jenkins.helper.FunctionalHelper.SET_CLIENT; public class FolderJob extends Job { @@ -46,16 +48,13 @@ public boolean isFolder() { /** * Get a list of all the defined jobs in this folder * - * @return list of defined jobs (summary level, for details @see Job#details + * @return list of defined jobs (summary level, for details {@link Job#details()}. */ public Map getJobs() { - return Maps.uniqueIndex(jobs, new Function() { - @Override - public String apply(Job job) { - job.setClient(client); - return job.getName(); - } - }); + //FIXME: Check for null of jobs? Can that happen? + return jobs.stream() + .map(SET_CLIENT(this.client)) + .collect(Collectors.toMap(k -> k.getName(), Function.identity())); } /** @@ -63,15 +62,15 @@ public String apply(Job job) { * * @param name the name of the job. * @return the given job + * @throws IllegalArgumentException in case if the {@code name} does not exist. */ public Job getJob(String name) { - return Maps.uniqueIndex(jobs, new Function() { - @Override - public String apply(Job job) { - job.setClient(client); - return job.getName(); - } - }).get(name); + //FIXME: Check for null of jobs? Can that happen? + return jobs.stream() + .map(SET_CLIENT(this.client)) + .filter(item -> item.getName().equals(name)) + .findAny() + .orElseThrow(() -> new IllegalArgumentException("Job with name " + name + " does not exist.")); } /** @@ -80,8 +79,8 @@ public String apply(Job job) { * @param folderName name of the folder to be created. * @throws IOException in case of an error. */ - public void createFolder(String folderName) throws IOException { - createFolder(folderName, false); + public FolderJob createFolder(String folderName) throws IOException { + return createFolder(folderName, false); } /** @@ -89,14 +88,20 @@ public void createFolder(String folderName) throws IOException { * * @param folderName name of the folder to be created. * @param crumbFlag true/false. + * @return * @throws IOException in case of an error. */ - public void createFolder(String folderName, Boolean crumbFlag) throws IOException { + public FolderJob createFolder(String folderName, Boolean crumbFlag) throws IOException { // https://gist.github.com/stuart-warren/7786892 was slightly helpful // here - ImmutableMap params = ImmutableMap.of("mode", "com.cloudbees.hudson.plugins.folder.Folder", - "name", EncodingUtils.encodeParam(folderName), "from", "", "Submit", "OK"); + //TODO: JDK9+: Map.of(...) + Map params = new HashMap<>(); + params.put("mode", "com.cloudbees.hudson.plugins.folder.Folder"); + params.put("name", folderName); + params.put("from", ""); + params.put("Submit", "OK"); client.post_form(this.getUrl() + "/createItem?", params, crumbFlag); + return this; } /* diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/HourMinSec10.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/HourMinSec10.java index 0dba01dc..66823616 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/HourMinSec10.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/HourMinSec10.java @@ -15,24 +15,27 @@ public Statis getHour() { return hour; } - public void setHour(Statis hour) { + public HourMinSec10 setHour(Statis hour) { this.hour = hour; + return this; } public Statis getMin() { return min; } - public void setMin(Statis min) { + public HourMinSec10 setMin(Statis min) { this.min = min; + return this; } public Statis getSec10() { return sec10; } - public void setSec10(Statis sec10) { + public HourMinSec10 setSec10(Statis sec10) { this.sec10 = sec10; + return this; } @Override diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/JacocoCoverageReport.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/JacocoCoverageReport.java index ed623aa1..cc1345d5 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/JacocoCoverageReport.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/JacocoCoverageReport.java @@ -11,32 +11,46 @@ public class JacocoCoverageReport extends BaseModel { public JacocoCoverageResult getLineCoverage() { return lineCoverage; } - public void setLineCoverage(JacocoCoverageResult lineCoverage) { + + public JacocoCoverageReport setLineCoverage(JacocoCoverageResult lineCoverage) { this.lineCoverage = lineCoverage; + return this; } + public JacocoCoverageResult getClassCoverage() { return classCoverage; } - public void setClassCoverage(JacocoCoverageResult classCoverage) { + + public JacocoCoverageReport setClassCoverage(JacocoCoverageResult classCoverage) { this.classCoverage = classCoverage; + return this; } + public JacocoCoverageResult getComplexityScore() { return complexityScore; } - public void setComplexityScore(JacocoCoverageResult complexityScore) { + + public JacocoCoverageReport setComplexityScore(JacocoCoverageResult complexityScore) { this.complexityScore = complexityScore; + return this; } + public JacocoCoverageResult getInstructionCoverage() { return instructionCoverage; } - public void setInstructionCoverage(JacocoCoverageResult instructionCoverage) { + + public JacocoCoverageReport setInstructionCoverage(JacocoCoverageResult instructionCoverage) { this.instructionCoverage = instructionCoverage; + return this; } + public JacocoCoverageResult getBranchCoverage() { return branchCoverage; } - public void setBranchCoverage(JacocoCoverageResult branchCoverage) { + + public JacocoCoverageReport setBranchCoverage(JacocoCoverageResult branchCoverage) { this.branchCoverage = branchCoverage; + return this; } } \ No newline at end of file diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/JacocoCoverageResult.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/JacocoCoverageResult.java index 760bb610..41f3f43d 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/JacocoCoverageResult.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/JacocoCoverageResult.java @@ -11,34 +11,46 @@ public class JacocoCoverageResult { public int getCovered() { return covered; } - public void setCovered(int covered) { + + public JacocoCoverageResult setCovered(int covered) { this.covered = covered; + return this; } + public int getMissed() { return missed; } - public void setMissed(int missed) { + + public JacocoCoverageResult setMissed(int missed) { this.missed = missed; + return this; } + public int getPercentage() { return percentage; } - public void setPercentage(int percentage) { + + public JacocoCoverageResult setPercentage(int percentage) { this.percentage = percentage; + return this; } + public int getPercentageFloat() { return percentageFloat; } - public void setPercentageFloat(int percentageFloat) { + + public JacocoCoverageResult setPercentageFloat(int percentageFloat) { this.percentageFloat = percentageFloat; + return this; } + public int getTotal() { return total; } - public void setTotal(int total) { + + public JacocoCoverageResult setTotal(int total) { this.total = total; + return this; } - - } \ No newline at end of file diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Job.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Job.java index 309d728a..7d5313fd 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Job.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Job.java @@ -6,19 +6,15 @@ package com.offbytwo.jenkins.model; -import static org.apache.commons.lang.StringUtils.join; - +import com.offbytwo.jenkins.client.util.EncodingUtils; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.util.Map; - -import com.google.common.base.Function; -import com.google.common.collect.Collections2; -import com.google.common.escape.Escaper; -import com.google.common.net.UrlEscapers; +import java.util.function.Function; +import java.util.stream.Collectors; public class Job extends BaseModel { @@ -147,7 +143,10 @@ public QueueReference build(Map params, Map filePa * @throws IOException in case of an error. */ public QueueReference build(Map params, Map fileParams, boolean crumbFlag) throws IOException { - String qs = join(Collections2.transform(params.entrySet(), new MapEntryToQueryStringPair()), "&"); + String qs = params.entrySet().stream() + .map(s -> s.getKey() + "=" + s.getValue()) + .collect(Collectors.joining("&")); +// String qs = join(Collections2.transform(params.entrySet(), new MapEntryToQueryStringPair()), "&"); ExtractHeader location = client.post(url + "buildWithParameters?" + qs,null, ExtractHeader.class, fileParams, crumbFlag); return new QueueReference(location.getLocation()); } @@ -181,8 +180,9 @@ public int hashCode() { private static class MapEntryToQueryStringPair implements Function, String> { @Override public String apply(Map.Entry entry) { - Escaper escaper = UrlEscapers.urlFormParameterEscaper(); - return escaper.escape(entry.getKey()) + "=" + escaper.escape(entry.getValue()); + return EncodingUtils.formParameter(entry.getKey()) + "=" + EncodingUtils.formParameter(entry.getValue()); } } + + } diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/JobConfiguration.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/JobConfiguration.java index 571430ab..d6a95050 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/JobConfiguration.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/JobConfiguration.java @@ -77,7 +77,8 @@ public String getConfigXml() { return configXml; } - public void setConfigXml(String configXml) { + public JobConfiguration setConfigXml(String configXml) { this.configXml = configXml; + return this; } } 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..f13903cf 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,23 +6,21 @@ package com.offbytwo.jenkins.model; -import static com.google.common.collect.Lists.transform; +import com.offbytwo.jenkins.client.util.EncodingUtils; +import com.offbytwo.jenkins.helper.Range; +import org.apache.http.HttpStatus; +import org.apache.http.client.HttpResponseException; import java.io.IOException; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; +import java.util.Optional; -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; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Iterables; -import com.offbytwo.jenkins.client.util.EncodingUtils; -import com.offbytwo.jenkins.helper.Range; +import static com.offbytwo.jenkins.helper.FunctionalHelper.SET_CLIENT; +import static java.util.stream.Collectors.toList; public class JobWithDetails extends Job { @@ -32,7 +30,7 @@ public class JobWithDetails extends Job { private boolean buildable; - private List builds; + private List builds = Collections.emptyList(); private Build firstBuild; @@ -95,12 +93,9 @@ public List getBuilds() { if (builds == null) { return Collections.emptyList(); } else { - return transform(builds, new Function() { - @Override - public Build apply(Build from) { - return buildWithClient(from); - } - }); + return builds.stream() + .map(s -> buildWithClient(s)) + .collect(toList()); } } @@ -129,12 +124,9 @@ public List getAllBuilds() throws IOException { if (builds == null) { return Collections.emptyList(); } else { - return transform(builds, new Function() { - @Override - public Build apply(Build from) { - return buildWithClient(from); - } - }); + return builds.stream() + .map(s -> buildWithClient(s)) + .collect(toList()); } } catch (HttpResponseException e) { // TODO: Thinks about a better handling if the job does not exist? @@ -178,12 +170,9 @@ public List getAllBuilds(Range range) throws IOException { if (builds == null) { return Collections.emptyList(); } else { - return transform(builds, new Function() { - @Override - public Build apply(Build from) { - return buildWithClient(from); - } - }); + return builds.stream() + .map(s -> buildWithClient(s)) + .collect(toList()); } } catch (HttpResponseException e) { // TODO: Thinks about a better handline if the job does not exist? @@ -428,7 +417,9 @@ public List getDownstreamProjects() { if (downstreamProjects == null) { return Collections.emptyList(); } else { - return transform(downstreamProjects, new JobWithClient()); + return downstreamProjects.stream() + .map(SET_CLIENT(this.client)) + .collect(toList()); } } @@ -440,7 +431,9 @@ public List getUpstreamProjects() { if (upstreamProjects == null) { return Collections.emptyList(); } else { - return transform(upstreamProjects, new JobWithClient()); + return upstreamProjects.stream() + .map(SET_CLIENT(this.client)) + .collect(toList()); } } @@ -452,31 +445,24 @@ 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 - * + * @return The an Optional with the {@link Build} selected by the given buildnumber + * */ - public Build getBuildByNumber(final int buildNumber) { - - Predicate isMatchingBuildNumber = new Predicate() { - - @Override - public boolean apply(Build input) { - return input.getNumber() == buildNumber; - } - }; - - Optional optionalBuild = Iterables.tryFind(builds, isMatchingBuildNumber); - // TODO: Check if we could use Build#NO...instead of Null? - return optionalBuild.orNull() == null ? null : buildWithClient(optionalBuild.orNull()); - } - - private class JobWithClient implements Function { - @Override - public Job apply(Job job) { - job.setClient(client); - return job; - } + public Optional getBuildByNumber(final int buildNumber) { + return builds.stream().filter(isBuildNumberEqualTo(buildNumber)).findFirst(); } + + /** + * Get a module of a {@link Job} + * + * @param moduleName name of the {@link MavenModule} + * @return The {@link MavenModuleWithDetails} selected by the given module name + * @throws java.io.IOException in case of errors. + * + */ + public MavenModuleWithDetails getModule(String moduleName) throws IOException { + return client.get(getUrl() + moduleName, MavenModuleWithDetails.class); + } /** * Empty description to be used for {@link #updateDescription(String)} or @@ -492,8 +478,8 @@ public Job apply(Job job) { * {@link #EMPTY_DESCRIPTION}. * @throws IOException in case of errors. */ - public void updateDescription(String description) throws IOException { - updateDescription(description, false); + public JobWithDetails updateDescription(String description) throws IOException { + return updateDescription(description, false); } /** @@ -505,10 +491,14 @@ public void updateDescription(String description) throws IOException { * @param crumbFlag true or false. * @throws IOException in case of errors. */ - public void updateDescription(String description, boolean crumbFlag) throws IOException { + public JobWithDetails updateDescription(String description, boolean crumbFlag) throws IOException { Objects.requireNonNull(description, "description is not allowed to be null."); - ImmutableMap params = ImmutableMap.of("description", description); + //JDK9+ + // Map.of(...); + Map params = new HashMap<>(); + params.put("description", description); client.post_form(this.getUrl() + "/submitDescription?", params, crumbFlag); + return this; } /** @@ -516,8 +506,8 @@ public void updateDescription(String description, boolean crumbFlag) throws IOEx * * @throws IOException in case of errors. */ - public void clearDescription() throws IOException { - updateDescription(EMPTY_DESCRIPTION); + public JobWithDetails clearDescription() throws IOException { + return updateDescription(EMPTY_DESCRIPTION); } /** @@ -526,8 +516,8 @@ public void clearDescription() throws IOException { * @param crumbFlag true or false. * @throws IOException in case of errors. */ - public void clearDescription(boolean crumbFlag) throws IOException { - updateDescription(EMPTY_DESCRIPTION, crumbFlag); + public JobWithDetails clearDescription(boolean crumbFlag) throws IOException { + return updateDescription(EMPTY_DESCRIPTION, crumbFlag); } @Override diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/LoadStatistics.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/LoadStatistics.java index df2a5608..fc335e5e 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/LoadStatistics.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/LoadStatistics.java @@ -18,24 +18,27 @@ public HourMinSec10 getBusyExecutors() { return busyExecutors; } - public void setBusyExecutors(HourMinSec10 busyExecutors) { + public LoadStatistics setBusyExecutors(HourMinSec10 busyExecutors) { this.busyExecutors = busyExecutors; + return this; } public HourMinSec10 getQueueLength() { return queueLength; } - public void setQueueLength(HourMinSec10 queueLength) { + public LoadStatistics setQueueLength(HourMinSec10 queueLength) { this.queueLength = queueLength; + return this; } public HourMinSec10 getTotalExecutors() { return totalExecutors; } - public void setTotalExecutors(HourMinSec10 totalExecutors) { + public LoadStatistics setTotalExecutors(HourMinSec10 totalExecutors) { this.totalExecutors = totalExecutors; + return this; } @Override diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/MainView.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/MainView.java index b239558d..167f6f40 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/MainView.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/MainView.java @@ -6,11 +6,10 @@ package com.offbytwo.jenkins.model; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import com.google.common.collect.Lists; - public class MainView extends BaseModel { private List jobs; @@ -18,7 +17,7 @@ public class MainView extends BaseModel { /* default constructor needed for Jackson */ public MainView() { - this(Lists.newArrayList(), Lists.newArrayList()); + this(new ArrayList<>(), new ArrayList<>()); } public MainView(List jobs, List views) { @@ -27,22 +26,24 @@ public MainView(List jobs, List views) { } public MainView(Job... jobs) { - this(Arrays.asList(jobs), Lists.newArrayList()); + this(Arrays.asList(jobs), new ArrayList<>()); } public List getJobs() { return jobs; } - public void setJobs(List jobs) { + public MainView setJobs(List jobs) { this.jobs = jobs; + return this; } public List getViews() { return views; } - public void setViews(List views) { + public MainView setViews(List views) { this.views = views; + return this; } } diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/MavenArtifact.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/MavenArtifact.java index 184ccc37..c51ea4ea 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/MavenArtifact.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/MavenArtifact.java @@ -18,63 +18,71 @@ public String getArtifactId() { return artifactId; } - public void setArtifactId(String artifactId) { + public MavenArtifact setArtifactId(String artifactId) { this.artifactId = artifactId; + return this; } public String getCanonicalName() { return canonicalName; } - public void setCanonicalName(String canonicalName) { + public MavenArtifact setCanonicalName(String canonicalName) { this.canonicalName = canonicalName; + return this; } public String getClassifier() { return classifier; } - public void setClassifier(String classifier) { + public MavenArtifact setClassifier(String classifier) { this.classifier = classifier; + return this; } public String getFileName() { return fileName; } - public void setFileName(String fileName) { + public MavenArtifact setFileName(String fileName) { this.fileName = fileName; + return this; } public String getGroupId() { return groupId; } - public void setGroupId(String groupId) { + public MavenArtifact setGroupId(String groupId) { this.groupId = groupId; + return this; } public String getMd5sum() { return md5sum; } - public void setMd5sum(String md5sum) { + public MavenArtifact setMd5sum(String md5sum) { this.md5sum = md5sum; + return this; } public String getType() { return type; } - public void setType(String type) { + public MavenArtifact setType(String type) { this.type = type; + return this; } public String getVersion() { return version; } - public void setVersion(String version) { + public MavenArtifact setVersion(String version) { this.version = version; + return this; } } diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/MavenJobWithDetails.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/MavenJobWithDetails.java index ae2c7c06..3eaf7fc0 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/MavenJobWithDetails.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/MavenJobWithDetails.java @@ -1,21 +1,17 @@ package com.offbytwo.jenkins.model; -import static com.google.common.collect.Lists.transform; +import com.offbytwo.jenkins.client.util.EncodingUtils; +import com.offbytwo.jenkins.helper.Range; +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.Optional; -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; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import com.offbytwo.jenkins.client.util.EncodingUtils; -import com.offbytwo.jenkins.helper.Range; +import static com.offbytwo.jenkins.helper.FunctionalHelper.SET_CLIENT; +import static java.util.stream.Collectors.toList; public class MavenJobWithDetails extends MavenJob { @@ -60,12 +56,9 @@ public List getBuilds() { if (builds == null) { return Collections.emptyList(); } else { - return Lists.transform(builds, new Function() { - @Override - public MavenBuild apply(MavenBuild from) { - return buildWithClient(from); - } - }); + return builds.stream() + .map(SET_CLIENT(this.client)) + .collect(toList()); } } @@ -95,12 +88,9 @@ public List getAllBuilds() throws IOException { if (builds == null) { return Collections.emptyList(); } else { - return transform(builds, new Function() { - @Override - public MavenBuild apply(MavenBuild from) { - return buildWithClient(from); - } - }); + return builds.stream() + .map(SET_CLIENT(this.client)) + .collect(toList()); } } catch (HttpResponseException e) { // TODO: Thinks about a better handling if the job does not exist? @@ -146,12 +136,9 @@ public List getAllBuilds(Range range) throws IOException { if (builds == null) { return Collections.emptyList(); } else { - return transform(builds, new Function() { - @Override - public MavenBuild apply(MavenBuild from) { - return buildWithClient(from); - } - }); + return builds.stream() + .map(SET_CLIENT(this.client)) + .collect(toList()); } } catch (HttpResponseException e) { // TODO: Thinks about a better handline if the job does not exist? @@ -271,7 +258,9 @@ public List getDownstreamProjects() { if (downstreamProjects == null) { return Collections.emptyList(); } else { - return Lists.transform(downstreamProjects, new MavenJobWithClient()); + return downstreamProjects.stream() + .map(SET_CLIENT(this.client)) + .collect(toList()); } } @@ -279,23 +268,20 @@ public List getUpstreamProjects() { if (upstreamProjects == null) { return Collections.emptyList(); } else { - return Lists.transform(upstreamProjects, new MavenJobWithClient()); + return upstreamProjects.stream() + .map(SET_CLIENT(this.client)) + .collect(toList()); } } - public MavenBuild getBuildByNumber(final int buildNumber) { - - Predicate isMatchingBuildNumber = new Predicate() { - - @Override - public boolean apply(MavenBuild input) { - return input.getNumber() == buildNumber; - } - }; - - Optional optionalBuild = Iterables.tryFind(builds, isMatchingBuildNumber); - // TODO: Check if we could use Build#NO...instead of Null? - return optionalBuild.orNull() == null ? null : buildWithClient(optionalBuild.orNull()); + /** + * @param buildNumber The build you would like to select. + * @return Optional which contains the {@link MavenBuild}. + */ + public Optional getBuildByNumber(final int buildNumber) { + return builds.stream() + .filter(isBuildNumberEqualTo(buildNumber)) + .findFirst(); } private MavenBuild buildWithClient(MavenBuild from) { @@ -304,11 +290,4 @@ private MavenBuild buildWithClient(MavenBuild from) { return ret; } - private class MavenJobWithClient implements Function { - @Override - public Job apply(Job job) { - job.setClient(client); - return job; - } - } } diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/MavenModule.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/MavenModule.java index 07c61bb1..91c7ef1c 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/MavenModule.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/MavenModule.java @@ -1,10 +1,59 @@ +/* + * Copyright (c) 2018 Cosmin Stejerean, Karl Heinz Marbaise, and contributors. + * + * Distributed under the MIT license: http://opensource.org/licenses/MIT + */ package com.offbytwo.jenkins.model; +import java.io.IOException; import java.util.List; - +/** + * + * @author Karl Heinz Marbaise, Ricardo Zanini, René Scheibe, Jakub Zacek + */ public class MavenModule extends BaseModel { private List moduleRecords; + private String name; + private String url; + private String color; + private String displayName; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getColor() { + return color; + } + + public void setColor(String color) { + this.color = color; + } + + public String getDisplayName() { + return displayName; + } + + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + public MavenModuleWithDetails details() throws IOException { + return client.get(url, MavenModuleWithDetails.class); + } public List getModuleRecords() { return moduleRecords; diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/MavenModuleRecord.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/MavenModuleRecord.java index 3684c21d..34fbd424 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/MavenModuleRecord.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/MavenModuleRecord.java @@ -17,39 +17,44 @@ public List getAttachedArtifacts() { return attachedArtifacts; } - public void setAttachedArtifacts(List attachedArtifacts) { + public MavenModuleRecord setAttachedArtifacts(List attachedArtifacts) { this.attachedArtifacts = attachedArtifacts; + return this; } public Build getParent() { return parent; } - public void setParent(Build parent) { + public MavenModuleRecord setParent(Build parent) { this.parent = parent; + return this; } public MavenArtifact getMainArtifact() { return mainArtifact; } - public void setMainArtifact(MavenArtifact mainArtifact) { + public MavenModuleRecord setMainArtifact(MavenArtifact mainArtifact) { this.mainArtifact = mainArtifact; + return this; } public MavenArtifact getPomArtifact() { return pomArtifact; } - public void setPomArtifact(MavenArtifact pomArtifact) { + public MavenModuleRecord setPomArtifact(MavenArtifact pomArtifact) { this.pomArtifact = pomArtifact; + return this; } public String getUrl() { return url; } - public void setUrl(String url) { + public MavenModuleRecord setUrl(String url) { this.url = url; + return this; } } diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/MavenModuleWithDetails.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/MavenModuleWithDetails.java new file mode 100644 index 00000000..d168a45e --- /dev/null +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/MavenModuleWithDetails.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2018 Cosmin Stejerean, Karl Heinz Marbaise, and contributors. + * + * Distributed under the MIT license: http://opensource.org/licenses/MIT + */ +package com.offbytwo.jenkins.model; + +import static com.offbytwo.jenkins.helper.FunctionalHelper.SET_CLIENT; +import static java.util.stream.Collectors.toList; + +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +/** + * Model Class for Maven Modules + * + * @author Jakub Zacek + */ +public class MavenModuleWithDetails extends BaseModel { + + private List builds = Collections.emptyList(); + private List actions = Collections.emptyList(); + private String displayName; + private BuildResult result; + private String url; + private long duration; + private long timestamp; + + public List getActions() { + return actions; + } + + public void setActions(List actions) { + this.actions = actions; + } + + public void setBuilds(List builds) { + this.builds = builds; + } + + public List getBuilds() { + return builds.stream() + .map(SET_CLIENT(this.getClient())) + .collect(toList()); + } + + public Build getBuildByNumber(final int buildNumber) { + return builds.stream() + .filter(isBuildNumberEqualTo(buildNumber)) + .map(SET_CLIENT(this.getClient())) + .findFirst() + .orElse(Build.BUILD_HAS_NEVER_RUN); + } + + public String getDisplayName() { + return displayName; + } + + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + public BuildResult getResult() { + return result; + } + + public void setResult(BuildResult result) { + this.result = result; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public long getTimestamp() { + return timestamp; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + + public long getDuration() { + return duration; + } + + public void setDuration(long duration) { + this.duration = duration; + } + + public String getConsoleOutputText() throws IOException { + return client.get(getUrl() + "/logText/progressiveText"); + } + + public TestReport getTestReport() throws IOException { + return client.get(this.getUrl() + "/testReport/?depth=1", TestReport.class); + } + +} diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/OfflineCause.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/OfflineCause.java index 66c70cd1..30969dc9 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/OfflineCause.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/OfflineCause.java @@ -17,6 +17,16 @@ public String getDescription() { return description; } + public OfflineCause setTimestamp(Long timestamp) { + this.timestamp = timestamp; + return this; + } + + public OfflineCause setDescription(String description) { + this.description = description; + return this; + } + @Override public int hashCode() { final int prime = 31; @@ -48,12 +58,4 @@ public boolean equals(Object obj) { return true; } - public void setTimestamp(Long timestamp) { - this.timestamp = timestamp; - } - - public void setDescription(String description) { - this.description = description; - } - } diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ParameterDefinitions.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ParameterDefinitions.java index b46c69e4..47247c74 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ParameterDefinitions.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ParameterDefinitions.java @@ -30,11 +30,13 @@ public List getStringParams() { return stringParams; } - public void setStringParams(List stringParams) { + public ParameterDefinitions setStringParams(List stringParams) { this.stringParams = stringParams; + return this; } - public void addParam(StringParameterDefinition spd) { + public ParameterDefinitions addParam(StringParameterDefinition spd) { stringParams.add(spd); + return this; } } diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ParametersDefinitionProperty.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ParametersDefinitionProperty.java index efb033f5..bb88a128 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ParametersDefinitionProperty.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/ParametersDefinitionProperty.java @@ -26,7 +26,8 @@ public ParameterDefinitions getPd() { return pd; } - public void setPd(ParameterDefinitions pd) { + public ParametersDefinitionProperty setPd(ParameterDefinitions pd) { this.pd = pd; + return this; } } diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Plugin.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Plugin.java index fe380202..6c9e09a1 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Plugin.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Plugin.java @@ -27,9 +27,10 @@ public boolean isActive() return active; } - public void setActive( boolean active ) + public Plugin setActive(boolean active) { this.active = active; + return this; } public String getBackupVersion() @@ -37,9 +38,10 @@ public String getBackupVersion() return backupVersion; } - public void setBackupVersion( String backupVersion ) + public Plugin setBackupVersion(String backupVersion) { this.backupVersion = backupVersion; + return this; } public boolean isBundled() @@ -47,9 +49,10 @@ public boolean isBundled() return bundled; } - public void setBundled( boolean bundled ) + public Plugin setBundled(boolean bundled) { this.bundled = bundled; + return this; } public boolean isDowngradable() @@ -57,9 +60,10 @@ public boolean isDowngradable() return downgradable; } - public void setDowngradable( boolean downgradable ) + public Plugin setDowngradable(boolean downgradable) { this.downgradable = downgradable; + return this; } public boolean isEnabled() @@ -67,9 +71,10 @@ public boolean isEnabled() return enabled; } - public void setEnabled( boolean enabled ) + public Plugin setEnabled(boolean enabled) { this.enabled = enabled; + return this; } public boolean isHasUpdate() @@ -77,9 +82,10 @@ public boolean isHasUpdate() return hasUpdate; } - public void setHasUpdate( boolean hasUpdate ) + public Plugin setHasUpdate(boolean hasUpdate) { this.hasUpdate = hasUpdate; + return this; } public String getLongName() @@ -87,9 +93,10 @@ public String getLongName() return longName; } - public void setLongName( String longName ) + public Plugin setLongName(String longName) { this.longName = longName; + return this; } public boolean isPinned() @@ -97,9 +104,10 @@ public boolean isPinned() return pinned; } - public void setPinned( boolean pinned ) + public Plugin setPinned(boolean pinned) { this.pinned = pinned; + return this; } public String getShortName() @@ -107,9 +115,10 @@ public String getShortName() return shortName; } - public void setShortName( String shortName ) + public Plugin setShortName(String shortName) { this.shortName = shortName; + return this; } public String getSupportsDynamicLoad() @@ -117,9 +126,10 @@ public String getSupportsDynamicLoad() return supportsDynamicLoad; } - public void setSupportsDynamicLoad( String supportsDynamicLoad ) + public Plugin setSupportsDynamicLoad(String supportsDynamicLoad) { this.supportsDynamicLoad = supportsDynamicLoad; + return this; } public String getUrl() @@ -127,9 +137,10 @@ public String getUrl() return url; } - public void setUrl( String url ) + public Plugin setUrl(String url) { this.url = url; + return this; } public String getVersion() @@ -137,9 +148,10 @@ public String getVersion() return version; } - public void setVersion( String version ) + public Plugin setVersion(String version) { this.version = version; + return this; } public List getDependencies() @@ -147,9 +159,10 @@ public List getDependencies() return dependencies; } - public void setDependencies( List dependencies ) + public Plugin setDependencies(List dependencies) { this.dependencies = dependencies; + return this; } @Override @@ -247,6 +260,4 @@ else if ( !version.equals( other.version ) ) return true; } - - } diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/PluginDependency.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/PluginDependency.java index adb1331d..acac798d 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/PluginDependency.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/PluginDependency.java @@ -11,6 +11,33 @@ public class PluginDependency extends BaseModel private String version; + public boolean isOptional() { + return optional; + } + + public PluginDependency setOptional(boolean optional) { + this.optional = optional; + return this; + } + + public String getShortName() { + return shortName; + } + + public PluginDependency setShortName(String shortName) { + this.shortName = shortName; + return this; + } + + public String getVersion() { + return version; + } + + public PluginDependency setVersion(String version) { + this.version = version; + return this; + } + @Override public int hashCode() { @@ -51,34 +78,4 @@ else if ( !version.equals( other.version ) ) return true; } - public boolean isOptional() - { - return optional; - } - - public void setOptional( boolean optional ) - { - this.optional = optional; - } - - public String getShortName() - { - return shortName; - } - - public void setShortName( String shortName ) - { - this.shortName = shortName; - } - - public String getVersion() - { - return version; - } - - public void setVersion( String version ) - { - this.version = version; - } - } diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/PluginManager.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/PluginManager.java index f23ccaba..c08fc713 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/PluginManager.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/PluginManager.java @@ -14,8 +14,9 @@ public List getPlugins() return plugins; } - public void setPlugins(List plugins) { + public PluginManager setPlugins(List plugins) { this.plugins = plugins; + return this; } @Override diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Queue.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Queue.java index 3320ecb5..355dc910 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Queue.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Queue.java @@ -8,8 +8,7 @@ import java.util.List; -public class Queue - extends BaseModel +public class Queue extends BaseModel { private List discoverableItems; @@ -24,9 +23,10 @@ public List getDiscoverableItems() return discoverableItems; } - public void setDiscoverableItems( List discoverableItems ) + public Queue setDiscoverableItems(List discoverableItems) { this.discoverableItems = discoverableItems; + return this; } @Override @@ -44,9 +44,10 @@ public List getItems() return items; } - public void setItems( List items ) + public Queue setItems(List items) { this.items = items; + return this; } @Override diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/QueueItem.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/QueueItem.java index 662b3e2b..ae2d8d3d 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/QueueItem.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/QueueItem.java @@ -38,48 +38,54 @@ public List getActions() { return actions; } - public void setActions(List actions) { + public QueueItem setActions(List actions) { this.actions = actions; + return this; } public boolean isBlocked() { return blocked; } - public void setBlocked(boolean blocked) { + public QueueItem setBlocked(boolean blocked) { this.blocked = blocked; + return this; } public boolean isBuildable() { return buildable; } - public void setBuildable(boolean buildable) { + public QueueItem setBuildable(boolean buildable) { this.buildable = buildable; + return this; } public Long getId() { return id; } - public void setId(Long id) { + public QueueItem setId(Long id) { this.id = id; + return this; } public Long getInQueueSince() { return inQueueSince; } - public void setInQueueSince(Long inQueueSince) { + public QueueItem setInQueueSince(Long inQueueSince) { this.inQueueSince = inQueueSince; + return this; } public String getParams() { return params; } - public void setParams(String params) { + public QueueItem setParams(String params) { this.params = params; + return this; } public boolean isStuck() { @@ -90,44 +96,50 @@ public QueueTask getTask() { return task; } - public void setTask(QueueTask task) { + public QueueItem setTask(QueueTask task) { this.task = task; + return this; } - public void setStuck(boolean stuck) { + public QueueItem setStuck(boolean stuck) { this.stuck = stuck; + return this; } public String getUrl() { return url; } - public void setUrl(String url) { + public QueueItem setUrl(String url) { this.url = url; + return this; } public String getWhy() { return why; } - public void setWhy(String why) { + public QueueItem setWhy(String why) { this.why = why; + return this; } public boolean isCancelled() { return cancelled; } - public void setCancelled(boolean cancelled) { + public QueueItem setCancelled(boolean cancelled) { this.cancelled = cancelled; + return this; } public Executable getExecutable() { return executable; } - public void setExecutable(Executable executable) { + public QueueItem setExecutable(Executable executable) { this.executable = executable; + return this; } @Override diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/QueueItemActions.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/QueueItemActions.java index 4c49ba5f..cbd6e390 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/QueueItemActions.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/QueueItemActions.java @@ -15,8 +15,9 @@ public List getCauses() { return causes; } - public void setCauses(List causes) { + public QueueItemActions setCauses(List causes) { this.causes = causes; + return this; } } diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Statis.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Statis.java index b2c601c3..bb920ea4 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Statis.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/Statis.java @@ -22,16 +22,18 @@ public List getHistory() { return history; } - public void setHistory(List history) { + public Statis setHistory(List history) { this.history = history; + return this; } public Double getLatest() { return latest; } - public void setLatest(Double latest) { + public Statis setLatest(Double latest) { this.latest = latest; + return this; } @Override diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/StringParameterDefinition.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/StringParameterDefinition.java index 740e3d77..2a89618f 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/StringParameterDefinition.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/StringParameterDefinition.java @@ -34,23 +34,26 @@ public String getName() { return name; } - public void setName(String name) { + public StringParameterDefinition setName(String name) { this.name = name; + return this; } public String getDescription() { return description; } - public void setDescription(String description) { + public StringParameterDefinition setDescription(String description) { this.description = description; + return this; } public String getDefaultValue() { return defaultValue; } - public void setDefaultValue(String defaultValue) { + public StringParameterDefinition setDefaultValue(String defaultValue) { this.defaultValue = defaultValue; + return this; } } diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/TestCase.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/TestCase.java index 8f4f3795..f3ac1331 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/TestCase.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/TestCase.java @@ -21,9 +21,10 @@ public int getAge() return age; } - public void setAge( int age ) + public TestCase setAge(int age) { this.age = age; + return this; } public String getClassName() @@ -31,9 +32,10 @@ public String getClassName() return className; } - public void setClassName( String className ) + public TestCase setClassName(String className) { this.className = className; + return this; } public double getDuration() @@ -41,9 +43,10 @@ public double getDuration() return duration; } - public void setDuration( double duration ) + public TestCase setDuration(double duration) { this.duration = duration; + return this; } public int getFailedSince() @@ -51,9 +54,10 @@ public int getFailedSince() return failedSince; } - public void setFailedSince( int failedSince ) + public TestCase setFailedSince(int failedSince) { this.failedSince = failedSince; + return this; } public String getName() @@ -61,9 +65,10 @@ public String getName() return name; } - public void setName( String name ) + public TestCase setName(String name) { this.name = name; + return this; } public boolean isSkipped() @@ -71,9 +76,10 @@ public boolean isSkipped() return skipped; } - public void setSkipped( boolean skipped ) + public TestCase setSkipped(boolean skipped) { this.skipped = skipped; + return this; } public String getStatus() @@ -81,9 +87,10 @@ public String getStatus() return status; } - public void setStatus( String status ) + public TestCase setStatus(String status) { this.status = status; + return this; } public String getErrorDetails() @@ -91,9 +98,10 @@ public String getErrorDetails() return errorDetails; } - public void setErrorDetails( String errorDetails ) + public TestCase setErrorDetails(String errorDetails) { this.errorDetails = errorDetails; + return this; } public String getErrorStackTrace() @@ -101,9 +109,10 @@ public String getErrorStackTrace() return errorStackTrace; } - public void setErrorStackTrace( String errorStackTrace ) + public TestCase setErrorStackTrace(String errorStackTrace) { this.errorStackTrace = errorStackTrace; + return this; } @Override diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/TestChild.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/TestChild.java index 516bb446..a8d50ca0 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/TestChild.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/TestChild.java @@ -12,16 +12,18 @@ public int getNumber() { return number; } - public void setNumber(int number) { + public TestChild setNumber(int number) { this.number = number; + return this; } public String getUrl() { return url; } - public void setUrl(String url) { + public TestChild setUrl(String url) { this.url = url; + return this; } @Override diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/TestChildReport.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/TestChildReport.java index da920bec..7d3ea3f5 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/TestChildReport.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/TestChildReport.java @@ -13,8 +13,18 @@ public TestChild getChild() { return child; } - public void setChild(TestChild child) { + public TestChildReport setChild(TestChild child) { this.child = child; + return this; + } + + public TestResult getResult() { + return result; + } + + public TestChildReport setResult(TestResult result) { + this.result = result; + return this; } @Override @@ -48,12 +58,4 @@ public boolean equals(Object obj) { return true; } - public TestResult getResult() { - return result; - } - - public void setResult(TestResult result) { - this.result = result; - } - } diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/TestReport.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/TestReport.java index b775c3f2..de3f0162 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/TestReport.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/TestReport.java @@ -47,40 +47,45 @@ public int getFailCount() { return failCount; } - public void setFailCount(int failCount) { + public TestReport setFailCount(int failCount) { this.failCount = failCount; + return this; } public int getSkipCount() { return skipCount; } - public void setSkipCount(int skipCount) { + public TestReport setSkipCount(int skipCount) { this.skipCount = skipCount; + return this; } public int getTotalCount() { return totalCount; } - public void setTotalCount(int totalCount) { + public TestReport setTotalCount(int totalCount) { this.totalCount = totalCount; + return this; } public String getUrlName() { return urlName; } - public void setUrlName(String urlName) { + public TestReport setUrlName(String urlName) { this.urlName = urlName; + return this; } public List getChildReports() { return childReports; } - public void setChildReports(List childReports) { + public TestReport setChildReports(List childReports) { this.childReports = childReports; + return this; } @Override diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/TestResult.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/TestResult.java index 934b32d4..5dda306f 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/TestResult.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/TestResult.java @@ -20,40 +20,54 @@ public double getDuration() { return duration; } - public void setDuration(double duration) { + public TestResult setDuration(double duration) { this.duration = duration; + return this; } public boolean isEmpty() { return empty; } - public void setEmpty(boolean empty) { + public TestResult setEmpty(boolean empty) { this.empty = empty; + return this; } public int getFailCount() { return failCount; } - public void setFailCount(int failCount) { + public TestResult setFailCount(int failCount) { this.failCount = failCount; + return this; } public int getPassCount() { return passCount; } - public void setPassCount(int passCount) { + public TestResult setPassCount(int passCount) { this.passCount = passCount; + return this; } public int getSkipCount() { return skipCount; } - public void setSkipCount(int skipCount) { + public TestResult setSkipCount(int skipCount) { this.skipCount = skipCount; + return this; + } + + public List getSuites() { + return suites; + } + + public TestResult setSuites(List suites) { + this.suites = suites; + return this; } @Override @@ -97,12 +111,4 @@ public boolean equals(Object obj) { return false; return true; } - - public List getSuites() { - return suites; - } - - public void setSuites(List suites) { - this.suites = suites; - } } diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/TestSuites.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/TestSuites.java index 45c96883..030b03b9 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/TestSuites.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/TestSuites.java @@ -19,40 +19,45 @@ public double getDuration() { return duration; } - public void setDuration(double duration) { + public TestSuites setDuration(double duration) { this.duration = duration; + return this; } public String getId() { return id; } - public void setId(String id) { + public TestSuites setId(String id) { this.id = id; + return this; } public String getName() { return name; } - public void setName(String name) { + public TestSuites setName(String name) { this.name = name; + return this; } public String getTimestamp() { return timestamp; } - public void setTimestamp(String timestamp) { + public TestSuites setTimestamp(String timestamp) { this.timestamp = timestamp; + return this; } public List getCases() { return cases; } - public void setCases(List cases) { + public TestSuites setCases(List cases) { this.cases = cases; + return this; } @Override diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/View.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/View.java index 5267e4f1..422cd5a4 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/View.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/View.java @@ -13,8 +13,9 @@ public String getName() { return name; } - public void setName(String name) { + public View setName(String name) { this.name = name; + return this; } public View() { @@ -24,16 +25,18 @@ public String getDescription() { return description; } - public void setDescription(String description) { + public View setDescription(String description) { this.description = description; + return this; } public String getUrl() { return url; } - public void setUrl(String url) { + public View setUrl(String url) { this.url = url; + return this; } @Override diff --git a/jenkins-client/src/site/asciidoc/index.adoc b/jenkins-client/src/site/asciidoc/index.adoc deleted file mode 100644 index 942df55c..00000000 --- a/jenkins-client/src/site/asciidoc/index.adoc +++ /dev/null @@ -1,7 +0,0 @@ -:revnumber: ${project-version} - -== Overview == - -Here you can see the first page. -This is the first. - diff --git a/jenkins-client/src/site/asciidoc/sub/sub.adoc b/jenkins-client/src/site/asciidoc/sub/sub.adoc deleted file mode 100644 index 345e6aef..00000000 --- a/jenkins-client/src/site/asciidoc/sub/sub.adoc +++ /dev/null @@ -1 +0,0 @@ -Test diff --git a/jenkins-client/src/test/java/com/offbytwo/jenkins/JenkinsServerTest.java b/jenkins-client/src/test/java/com/offbytwo/jenkins/JenkinsServerTest.java index 9e9d50aa..0c553ce1 100644 --- a/jenkins-client/src/test/java/com/offbytwo/jenkins/JenkinsServerTest.java +++ b/jenkins-client/src/test/java/com/offbytwo/jenkins/JenkinsServerTest.java @@ -18,6 +18,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.UUID; import org.apache.http.entity.ContentType; @@ -25,7 +26,6 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; -import com.google.common.base.Optional; import com.offbytwo.jenkins.client.JenkinsHttpClient; import com.offbytwo.jenkins.client.JenkinsHttpConnection; import com.offbytwo.jenkins.model.FolderJob; diff --git a/jenkins-client/src/test/java/com/offbytwo/jenkins/client/JenkinsHttpClientTest.java b/jenkins-client/src/test/java/com/offbytwo/jenkins/client/JenkinsHttpClientTest.java index 80f3ba38..2e3bce09 100644 --- a/jenkins-client/src/test/java/com/offbytwo/jenkins/client/JenkinsHttpClientTest.java +++ b/jenkins-client/src/test/java/com/offbytwo/jenkins/client/JenkinsHttpClientTest.java @@ -5,6 +5,12 @@ */ package com.offbytwo.jenkins.client; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; + import java.io.ByteArrayInputStream; import java.net.URI; import org.apache.http.Header; @@ -15,12 +21,7 @@ import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.protocol.HttpContext; -import static org.junit.Assert.assertEquals; import org.junit.Test; -import static org.mockito.BDDMockito.given; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.mock; @@ -30,7 +31,7 @@ */ public class JenkinsHttpClientTest { private static final String URI = "http://localhost/jenkins"; - + @Test @@ -40,8 +41,8 @@ public void testGet_String() throws Exception { final Header versionHeader = mock(Header.class); final StatusLine statusLine = mock(StatusLine.class); final HttpEntity entity = mock(HttpEntity.class); - given(client.execute(any(HttpUriRequest.class), any(HttpContext.class))).willReturn(response); - given(response.getHeaders(anyString())).willReturn(new Header[]{versionHeader}); + given(client.execute(any(HttpUriRequest.class), eq((HttpContext)null))).willReturn(response); + given(response.getHeaders("X-Jenkins")).willReturn(new Header[]{versionHeader}); given(response.getStatusLine()).willReturn(statusLine); given(versionHeader.getValue()).willReturn("1.234"); given(statusLine.getStatusCode()).willReturn(HttpStatus.SC_OK); @@ -51,15 +52,15 @@ public void testGet_String() throws Exception { final String s = jclient.get("job/someJob"); assertEquals("someJson", s); } - - - + + + @Test(expected=IllegalStateException.class) public void testClose() throws Exception { final JenkinsHttpConnection jclient = new JenkinsHttpClient(new URI(URI)); jclient.close(); jclient.close(); //check multiple calls yield no errors - jclient.get("job/someJob"); + jclient.get("job/someJob"); } diff --git a/jenkins-client/src/test/java/com/offbytwo/jenkins/client/util/EncodingUtilsTest.java b/jenkins-client/src/test/java/com/offbytwo/jenkins/client/util/EncodingUtilsTest.java new file mode 100644 index 00000000..358ac7f5 --- /dev/null +++ b/jenkins-client/src/test/java/com/offbytwo/jenkins/client/util/EncodingUtilsTest.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2019 Karl Heinz Marbaise, and contributors. + * + * Distributed under the MIT license: http://opensource.org/licenses/MIT + */ +package com.offbytwo.jenkins.client.util; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * This class is a unit test for the helper class {@link EncodingUtils}. + * + * @author Karl Heinz Marbaise + */ +public class EncodingUtilsTest { + + @Test + public void encodeShouldReturnEncodedDoubleQuoteAndSpace() { + String result = EncodingUtils.encode("!\"& "); + assertThat(result).isEqualTo("%21%22%26+"); + } + + @Test + public void encodeShouldReturnNotEncodeSafeChars() { + String result = EncodingUtils.encode("-._~!$'()*,;&=@:+"); + assertThat(result).isEqualTo("-._%7E%21%24%27%28%29*%2C%3B%26%3D%40%3A%2B"); + } + @Test + public void encodeShouldReturnNotEncodeAlpha() { + String result = EncodingUtils.encode("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); + assertThat(result).isEqualTo("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); + } + + @Test + public void encodeShouldReturnEncodingUmlautAndOthers() { + String result = EncodingUtils.encode("äöü#{}"); + assertThat(result).isEqualTo("%C3%A4%C3%B6%C3%BC%23%7B%7D"); + } + + @Test + public void encodeParamShouldReturnEncodedExclamationMarkDoubleQuoteAmpersampSpace() { + String result = EncodingUtils.formParameter("!\"& "); + assertThat(result).isEqualTo("%21%22%26+"); + } + + @Test + public void encodeParamShouldReturnNotEncodeSafeChars() { + String result = EncodingUtils.formParameter("-_.*"); + assertThat(result).isEqualTo("-_.*"); + } + + @Test + public void encodeParamShouldReturnEncodedUmlautAndOthers() { + String result = EncodingUtils.formParameter("äöü#{}"); + assertThat(result).isEqualTo("%C3%A4%C3%B6%C3%BC%23%7B%7D"); + } + + @Test + public void encodeParamShouldReturnEncodedCharacters() { + String result = EncodingUtils.formParameter("-._~!$'()*,;&=@:+"); + assertThat(result).isEqualTo("-._%7E%21%24%27%28%29*%2C%3B%26%3D%40%3A%2B"); + } + +} \ No newline at end of file diff --git a/jenkins-client/src/test/java/com/offbytwo/jenkins/helper/RangeTest.java b/jenkins-client/src/test/java/com/offbytwo/jenkins/helper/RangeTest.java index 5dcc9e38..b56aa467 100644 --- a/jenkins-client/src/test/java/com/offbytwo/jenkins/helper/RangeTest.java +++ b/jenkins-client/src/test/java/com/offbytwo/jenkins/helper/RangeTest.java @@ -6,13 +6,10 @@ package com.offbytwo.jenkins.helper; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; -import com.offbytwo.jenkins.helper.Range; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; /** *
      @@ -23,7 +20,7 @@ * The same as {0,N}. *
    • {N}: Just retrieve the N-th element. The same as {N,N+1}.
    • *
    - * + * * @author Karl Heinz Marbaise */ public class RangeTest { @@ -56,27 +53,24 @@ public void onlyGiven() { assertThat(r.getRangeString()).isEqualTo(getEscaped("3,4")); } - @Rule - public ExpectedException exception = ExpectedException.none(); - @Test public void toIsGivenLargerThanFromShouldResultInIllegalArgumentException() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("to must be greater than from"); - Range.build().from(5).to(1); + assertThatIllegalArgumentException() + .isThrownBy(() -> Range.build().from(5).to(1)) + .withMessage("to must be greater than from"); } @Test public void fromGivenNegativeValueShouldResultInIllegalArgumentException() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("from value must be greater or equal null."); - Range.build().from(-1); + assertThatIllegalArgumentException() + .isThrownBy(() -> Range.build().from(-1)) + .withMessage("from value must be greater or equal null."); } @Test public void fromGivenPositiveToNegativeValueShouldResultInIllegalArgumentException() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("to must be greater or equal null."); - Range.build().from(5).to(-1); + assertThatIllegalArgumentException() + .isThrownBy(() -> Range.build().from(5).to(-1)) + .withMessage("to must be greater or equal null."); } } diff --git a/jenkins-client/src/test/java/com/offbytwo/jenkins/integration/FolderTestsIT.java b/jenkins-client/src/test/java/com/offbytwo/jenkins/integration/FolderTestsIT.java index c6549413..098102c0 100644 --- a/jenkins-client/src/test/java/com/offbytwo/jenkins/integration/FolderTestsIT.java +++ b/jenkins-client/src/test/java/com/offbytwo/jenkins/integration/FolderTestsIT.java @@ -5,6 +5,7 @@ import hudson.model.UpdateCenter; import java.util.List; +import java.util.Optional; import java.util.Vector; import jenkins.model.Jenkins; @@ -19,7 +20,6 @@ import org.kohsuke.stapler.StaplerResponse; import org.mockito.Mockito; -import com.google.common.base.Optional; import com.offbytwo.jenkins.JenkinsServer; import com.offbytwo.jenkins.model.FolderJob; import com.offbytwo.jenkins.model.JobWithDetails; @@ -67,7 +67,7 @@ public void testFolderPluginAPIs() throws Exception { JobWithDetails root = server.getJob("root"); Assert.assertNotNull(root); - Optional rootFolder = server.getFolderJob(root); + java.util.Optional rootFolder = server.getFolderJob(root); Assert.assertTrue(rootFolder.isPresent()); server.createFolder(rootFolder.get(), "subfolder"); diff --git a/jenkins-client/src/test/java/com/offbytwo/jenkins/integration/JenkinsServerIT.java b/jenkins-client/src/test/java/com/offbytwo/jenkins/integration/JenkinsServerIT.java index d7f19a10..b32d027b 100644 --- a/jenkins-client/src/test/java/com/offbytwo/jenkins/integration/JenkinsServerIT.java +++ b/jenkins-client/src/test/java/com/offbytwo/jenkins/integration/JenkinsServerIT.java @@ -88,7 +88,7 @@ public void shouldSupportBooleanParameters() throws Exception { JobWithDetails job = server.getJobs().get(JENKINS_TEST_JOB).details(); BuildWithDetails build = job.getBuilds().get(0).details(); - assertEquals("true", build.getParameters().get("someValue")); + assertEquals(Boolean.TRUE, build.getParameters().get("someValue")); } @Test diff --git a/jenkins-client/src/test/java/com/offbytwo/jenkins/model/BuildWithDetailsTest.java b/jenkins-client/src/test/java/com/offbytwo/jenkins/model/BuildWithDetailsTest.java index 83ddd07b..dd4969b3 100644 --- a/jenkins-client/src/test/java/com/offbytwo/jenkins/model/BuildWithDetailsTest.java +++ b/jenkins-client/src/test/java/com/offbytwo/jenkins/model/BuildWithDetailsTest.java @@ -52,7 +52,7 @@ public void getBuildLogWithBuffer() { given(response.getFirstHeader(BuildWithDetails.MORE_DATA_HEADER)).willReturn(moreDataHeader); given(response.getFirstHeader(BuildWithDetails.TEXT_SIZE_HEADER)).willReturn(textSizeHeader); given(client.post_form_with_result(anyString(),anyListOf(NameValuePair.class),anyBoolean())).willReturn(response); - ConsoleLog consoleOutputText = buildWithDetails.getConsoleOutputText(500); + ConsoleLog consoleOutputText = buildWithDetails.getConsoleOutputText(500, false); assertThat(consoleOutputText.getConsoleLog()).isEqualTo(text); assertThat(consoleOutputText.getCurrentBufferSize()).isEqualTo(textLength); assertThat(consoleOutputText.getHasMoreData()).isFalse(); @@ -86,7 +86,7 @@ public void onData(String newLogChunk) { public void finished() { assertThat(buffer.toString()).isEqualTo(text); } - },1,2); + },1,2, false); } catch (IOException e) { fail("Should not return exception",e); } @@ -114,7 +114,7 @@ public void onData(String newLogChunk) { public void finished() { fail("Should timeout"); } - },1,2); + },1,2, false); } catch (IOException e) { fail("Should not return exception",e); } diff --git a/pom.xml b/pom.xml index cea2c716..f88539d9 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ com.offbytwo.jenkins jenkins-client-parent - 0.3.9-SNAPSHOT + 0.4.0-SNAPSHOT pom @@ -48,22 +48,20 @@ true true - 1.5.3 + 2.0.0 1.644 - 4.11 - 1.9.5 + 4.12 + 3.0.0 2.4 1.4.7-jenkins-1 - 1.6.1 - 3.8.1 - 17.0 + 3.9 2.4 - 4.3.6 - 4.3.3 - 4.3.6 - 2.9.6 + 4.5.8 + 4.4.11 + 4.5.8 + 2.10.3 @@ -106,9 +104,9 @@ - dom4j + org.dom4j dom4j - ${dom4j.version} + 2.1.3 @@ -126,12 +124,6 @@ - - com.google.guava - guava - ${guava.version} - - org.apache.commons commons-lang3 @@ -172,34 +164,36 @@ org.testng testng - 6.14.2 - test + 7.0.0 + + + org.junit + junit-bom + 5.5.2 + import + pom junit junit ${junit.version} - test org.mockito mockito-core ${mockito-core.version} - test org.jenkins-ci.main jenkins-test-harness ${jenkins-version} - test org.assertj assertj-core - 3.11.1 - test + 3.12.2 @@ -209,18 +203,15 @@ org.apache.logging.log4j - log4j-core - 2.11.1 - - - org.apache.logging.log4j - log4j-slf4j-impl - 2.11.1 + log4j-bom + 2.12.1 + import + pom - xml-apis - xml-apis - 1.4.01 + xerces + xmlParserAPIs + 2.6.1 @@ -228,20 +219,25 @@ + + org.apache.maven.plugins + maven-help-plugin + 3.2.0 + org.apache.maven.plugins maven-clean-plugin - 3.0.0 + 3.1.0 org.apache.maven.plugins maven-resources-plugin - 3.0.2 + 3.1.0 org.apache.maven.plugins maven-source-plugin - 3.0.1 + 3.1.0 - - font - coderay - style - 2 - ${project.version} - true - true - - - @@ -408,31 +385,18 @@ org.apache.maven.plugins maven-project-info-reports-plugin
    - @@ -480,7 +444,8 @@ attach-javadocs - jar + javadoc-no-fork + test-javadoc-no-fork @@ -493,7 +458,7 @@ repo.jenkins-ci.org - http://repo.jenkins-ci.org/public/ + https://repo.jenkins-ci.org/public/