View Javadoc
1   /*
2    * The MIT License (MIT)
3    *
4    * Copyright (c) 2013-2026 The Coveralls Maven Plugin Project Contributors:
5    *     https://github.com/hazendaz/coveralls-maven-plugin/graphs/contributors
6    *
7    * Permission is hereby granted, free of charge, to any person obtaining a copy
8    * of this software and associated documentation files (the "Software"), to deal
9    * in the Software without restriction, including without limitation the rights
10   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11   * copies of the Software, and to permit persons to whom the Software is
12   * furnished to do so, subject to the following conditions:
13   *
14   * The above copyright notice and this permission notice shall be included in
15   * all copies or substantial portions of the Software.
16   *
17   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23   * THE SOFTWARE.
24   */
25  package org.eluder.coveralls.maven.plugin.domain;
26  
27  import java.util.Properties;
28  
29  import org.eluder.coveralls.maven.plugin.domain.Git.Remote;
30  import org.eluder.coveralls.maven.plugin.validation.JobValidator;
31  import org.eluder.coveralls.maven.plugin.validation.ValidationErrors;
32  
33  /**
34   * The Class Job.
35   */
36  public class Job {
37  
38      /** The repo token. */
39      private String repoToken;
40  
41      /** The service name. */
42      private String serviceName;
43  
44      /** The service job id. */
45      private String serviceJobId;
46  
47      /** The service build number. */
48      private String serviceBuildNumber;
49  
50      /** The service build url. */
51      private String serviceBuildUrl;
52  
53      /** The parallel. */
54      private boolean parallel;
55  
56      /** The service environment. */
57      private Properties serviceEnvironment;
58  
59      /** The timestamp. */
60      private Long timestamp;
61  
62      /** The dry run. */
63      private boolean dryRun;
64  
65      /** The branch. */
66      private String branch;
67  
68      /** The pull request. */
69      private String pullRequest;
70  
71      /** The git. */
72      private Git git;
73  
74      /**
75       * Instantiates a new job.
76       */
77      public Job() {
78          // noop
79      }
80  
81      /**
82       * With repo token.
83       *
84       * @param repoToken
85       *            the repo token
86       *
87       * @return the job
88       */
89      public Job withRepoToken(final String repoToken) {
90          this.repoToken = repoToken;
91          return this;
92      }
93  
94      /**
95       * With service name.
96       *
97       * @param serviceName
98       *            the service name
99       *
100      * @return the job
101      */
102     public Job withServiceName(final String serviceName) {
103         this.serviceName = serviceName;
104         return this;
105     }
106 
107     /**
108      * With service job id.
109      *
110      * @param serviceJobId
111      *            the service job id
112      *
113      * @return the job
114      */
115     public Job withServiceJobId(final String serviceJobId) {
116         this.serviceJobId = serviceJobId;
117         return this;
118     }
119 
120     /**
121      * With service build number.
122      *
123      * @param serviceBuildNumber
124      *            the service build number
125      *
126      * @return the job
127      */
128     public Job withServiceBuildNumber(final String serviceBuildNumber) {
129         this.serviceBuildNumber = serviceBuildNumber;
130         return this;
131     }
132 
133     /**
134      * With service build url.
135      *
136      * @param serviceBuildUrl
137      *            the service build url
138      *
139      * @return the job
140      */
141     public Job withServiceBuildUrl(final String serviceBuildUrl) {
142         this.serviceBuildUrl = serviceBuildUrl;
143         return this;
144     }
145 
146     /**
147      * With parallel.
148      *
149      * @param parallel
150      *            the parallel
151      *
152      * @return the job
153      */
154     public Job withParallel(final boolean parallel) {
155         this.parallel = parallel;
156         return this;
157     }
158 
159     /**
160      * With service environment.
161      *
162      * @param serviceEnvironment
163      *            the service environment
164      *
165      * @return the job
166      */
167     public Job withServiceEnvironment(final Properties serviceEnvironment) {
168         this.serviceEnvironment = serviceEnvironment;
169         return this;
170     }
171 
172     /**
173      * With timestamp.
174      *
175      * @param timestamp
176      *            the timestamp
177      *
178      * @return the job
179      */
180     public Job withTimestamp(final Long timestamp) {
181         this.timestamp = timestamp;
182         return this;
183     }
184 
185     /**
186      * With dry run.
187      *
188      * @param dryRun
189      *            the dry run
190      *
191      * @return the job
192      */
193     public Job withDryRun(final boolean dryRun) {
194         this.dryRun = dryRun;
195         return this;
196     }
197 
198     /**
199      * With branch.
200      *
201      * @param branch
202      *            the branch
203      *
204      * @return the job
205      */
206     public Job withBranch(final String branch) {
207         this.branch = branch;
208         return this;
209     }
210 
211     /**
212      * With pull request.
213      *
214      * @param pullRequest
215      *            the pull request
216      *
217      * @return the job
218      */
219     public Job withPullRequest(final String pullRequest) {
220         this.pullRequest = pullRequest;
221         return this;
222     }
223 
224     /**
225      * With git.
226      *
227      * @param git
228      *            the git
229      *
230      * @return the job
231      */
232     public Job withGit(final Git git) {
233         this.git = git;
234         return this;
235     }
236 
237     /**
238      * Gets the repo token.
239      *
240      * @return the repo token
241      */
242     public String getRepoToken() {
243         return this.repoToken;
244     }
245 
246     /**
247      * Gets the service name.
248      *
249      * @return the service name
250      */
251     public String getServiceName() {
252         return this.serviceName;
253     }
254 
255     /**
256      * Gets the service job id.
257      *
258      * @return the service job id
259      */
260     public String getServiceJobId() {
261         return this.serviceJobId;
262     }
263 
264     /**
265      * Gets the service build number.
266      *
267      * @return the service build number
268      */
269     public String getServiceBuildNumber() {
270         return this.serviceBuildNumber;
271     }
272 
273     /**
274      * Gets the service build url.
275      *
276      * @return the service build url
277      */
278     public String getServiceBuildUrl() {
279         return this.serviceBuildUrl;
280     }
281 
282     /**
283      * Gets the service environment.
284      *
285      * @return the service environment
286      */
287     public Properties getServiceEnvironment() {
288         return this.serviceEnvironment;
289     }
290 
291     /**
292      * Gets the timestamp.
293      *
294      * @return the timestamp
295      */
296     public Long getTimestamp() {
297         return this.timestamp;
298     }
299 
300     /**
301      * Checks if is parallel.
302      *
303      * @return true, if is parallel
304      */
305     public boolean isParallel() {
306         return this.parallel;
307     }
308 
309     /**
310      * Checks if is dry run.
311      *
312      * @return true, if is dry run
313      */
314     public boolean isDryRun() {
315         return this.dryRun;
316     }
317 
318     /**
319      * Gets the branch.
320      *
321      * @return the branch
322      */
323     public String getBranch() {
324         if (this.branch != null && this.getGit() != null && this.getGit().getRemotes() != null) {
325             for (final Remote remote : this.getGit().getRemotes()) {
326                 if (this.branch.startsWith(remote.getName() + "/")) {
327                     return this.branch.substring(remote.getName().length() + 1);
328                 }
329             }
330         }
331         return this.branch;
332     }
333 
334     /**
335      * Gets the pull request.
336      *
337      * @return the pull request
338      */
339     public String getPullRequest() {
340         return this.pullRequest;
341     }
342 
343     /**
344      * Gets the git.
345      *
346      * @return the git
347      */
348     public Git getGit() {
349         return this.git;
350     }
351 
352     /**
353      * Validate.
354      *
355      * @return the validation errors
356      */
357     public ValidationErrors validate() {
358         final var validator = new JobValidator(this);
359         return validator.validate();
360     }
361 }