View Javadoc
1   /*
2    * The MIT License (MIT)
3    *
4    * Copyright (c) 2013 - 2023, Tapio Rautonen
5    *
6    * Permission is hereby granted, free of charge, to any person obtaining a copy
7    * of this software and associated documentation files (the "Software"), to deal
8    * in the Software without restriction, including without limitation the rights
9    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10   * copies of the Software, and to permit persons to whom the Software is
11   * furnished to do so, subject to the following conditions:
12   *
13   * The above copyright notice and this permission notice shall be included in
14   * all copies or substantial portions of the Software.
15   *
16   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22   * THE SOFTWARE.
23   */
24  package org.eluder.coveralls.maven.plugin.domain;
25  
26  import java.util.Date;
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  public class Job {
34  
35      private String repoToken;
36      private String serviceName;
37      private String serviceJobId;
38      private String serviceBuildNumber;
39      private String serviceBuildUrl;
40      private boolean parallel;
41      private Properties serviceEnvironment;
42      private Date timestamp;
43      private boolean dryRun;
44      private String branch;
45      private String pullRequest;
46      private Git git;
47  
48      public Job() {
49          // noop
50      }
51  
52      public Job withRepoToken(final String repoToken) {
53          this.repoToken = repoToken;
54          return this;
55      }
56  
57      public Job withServiceName(final String serviceName) {
58          this.serviceName = serviceName;
59          return this;
60      }
61  
62      public Job withServiceJobId(final String serviceJobId) {
63          this.serviceJobId = serviceJobId;
64          return this;
65      }
66  
67      public Job withServiceBuildNumber(final String serviceBuildNumber) {
68          this.serviceBuildNumber = serviceBuildNumber;
69          return this;
70      }
71  
72      public Job withServiceBuildUrl(final String serviceBuildUrl) {
73          this.serviceBuildUrl = serviceBuildUrl;
74          return this;
75      }
76  
77      public Job withParallel(final boolean parallel) {
78          this.parallel = parallel;
79          return this;
80      }
81  
82      public Job withServiceEnvironment(final Properties serviceEnvironment) {
83          this.serviceEnvironment = serviceEnvironment;
84          return this;
85      }
86  
87      public Job withTimestamp(final Date timestamp) {
88          this.timestamp = timestamp;
89          return this;
90      }
91  
92      public Job withDryRun(final boolean dryRun) {
93          this.dryRun = dryRun;
94          return this;
95      }
96  
97      public Job withBranch(final String branch) {
98          this.branch = branch;
99          return this;
100     }
101 
102     public Job withPullRequest(final String pullRequest) {
103         this.pullRequest = pullRequest;
104         return this;
105     }
106 
107     public Job withGit(final Git git) {
108         this.git = git;
109         return this;
110     }
111 
112     public String getRepoToken() {
113         return repoToken;
114     }
115 
116     public String getServiceName() {
117         return serviceName;
118     }
119 
120     public String getServiceJobId() {
121         return serviceJobId;
122     }
123 
124     public String getServiceBuildNumber() {
125         return serviceBuildNumber;
126     }
127 
128     public String getServiceBuildUrl() {
129         return serviceBuildUrl;
130     }
131 
132     public Properties getServiceEnvironment() {
133         return serviceEnvironment;
134     }
135 
136     public Date getTimestamp() {
137         return timestamp;
138     }
139 
140     public boolean isParallel() {
141         return parallel;
142     }
143 
144     public boolean isDryRun() {
145         return dryRun;
146     }
147 
148     public String getBranch() {
149         if (branch != null && getGit() != null && getGit().getRemotes() != null) {
150             for (Remote remote : getGit().getRemotes()) {
151                 if (branch.startsWith(remote.getName() + "/")) {
152                     return branch.substring(remote.getName().length() + 1);
153                 }
154             }
155         }
156         return branch;
157     }
158 
159     public String getPullRequest() {
160         return pullRequest;
161     }
162 
163     public Git getGit() {
164         return git;
165     }
166 
167     public ValidationErrors validate() {
168         JobValidator validator = new JobValidator(this);
169         return validator.validate();
170     }
171 }