@@ -75,15 +75,21 @@ public boolean isInQueue() {
7575 * won't get back all builds via this method. In such cases you need to use
7676 * {@link #getAllBuilds()}.
7777 *
78- * @return the list of {@link Build}.
78+ * @return the list of {@link Build}. In case of no builds have been
79+ * executed yet return {@link Collections#emptyList()}.
7980 */
8081 public List <Build > getBuilds () {
81- return transform (builds , new Function <Build , Build >() {
82- @ Override
83- public Build apply (Build from ) {
84- return buildWithClient (from );
85- }
86- });
82+ if (builds == null ) {
83+ return Collections .emptyList ();
84+ }
85+ else {
86+ return transform (builds , new Function <Build , Build >() {
87+ @ Override
88+ public Build apply (Build from ) {
89+ return buildWithClient (from );
90+ }
91+ });
92+ }
8793 }
8894
8995 /**
@@ -95,7 +101,8 @@ public Build apply(Build from) {
95101 * particular build {@link Build#details()} to reduce the amount of data
96102 * which needed to be transfered.
97103 *
98- * @return the list of {@link Build}.
104+ * @return the list of {@link Build}. In case of no builds have been
105+ * executed yet return {@link Collections#emptyList()}.
99106 * @throws IOException
100107 * In case of failure.
101108 * @see <a href="https://issues.jenkins-ci.org/browse/JENKINS-30238">Jenkins
@@ -108,12 +115,16 @@ public List<Build> getAllBuilds() throws IOException {
108115 List <Build > builds = client .get (path + "job/" + EncodingUtils .encode (this .getName ())
109116 + "?tree=allBuilds[number[*],url[*],queueId[*]]" , AllBuilds .class ).getAllBuilds ();
110117
111- return transform (builds , new Function <Build , Build >() {
112- @ Override
113- public Build apply (Build from ) {
114- return buildWithClient (from );
115- }
116- });
118+ if (builds == null ) {
119+ return Collections .emptyList ();
120+ } else {
121+ return transform (builds , new Function <Build , Build >() {
122+ @ Override
123+ public Build apply (Build from ) {
124+ return buildWithClient (from );
125+ }
126+ });
127+ }
117128 } catch (HttpResponseException e ) {
118129 // TODO: Thinks about a better handline if the job does not exist?
119130 if (e .getStatusCode () == HttpStatus .SC_NOT_FOUND ) {
@@ -142,7 +153,8 @@ public Build apply(Build from) {
142153 * {@link #getAllBuilds()}.</b>
143154 *
144155 * @param range {@link Range}
145- * @return The list of builds defined by the given range.
156+ * @return the list of {@link Build}. In case of no builds have been
157+ * executed yet return {@link Collections#emptyList()}.
146158 * @throws IOException in case of an error.
147159 */
148160 public List <Build > getAllBuilds (Range range ) throws IOException {
@@ -152,12 +164,16 @@ public List<Build> getAllBuilds(Range range) throws IOException {
152164 try {
153165 List <Build > builds = client .get (path + range .getRangeString (), AllBuilds .class ).getAllBuilds ();
154166
155- return transform (builds , new Function <Build , Build >() {
156- @ Override
157- public Build apply (Build from ) {
158- return buildWithClient (from );
159- }
160- });
167+ if (builds == null ) {
168+ return Collections .emptyList ();
169+ } else {
170+ return transform (builds , new Function <Build , Build >() {
171+ @ Override
172+ public Build apply (Build from ) {
173+ return buildWithClient (from );
174+ }
175+ });
176+ }
161177 } catch (HttpResponseException e ) {
162178 // TODO: Thinks about a better handline if the job does not exist?
163179 if (e .getStatusCode () == HttpStatus .SC_NOT_FOUND ) {
@@ -292,6 +308,7 @@ public boolean apply(Build input) {
292308 };
293309
294310 Optional <Build > optionalBuild = Iterables .tryFind (builds , isMatchingBuildNumber );
311+ //TODO: Check if we could use Build#NO...instead of Null?
295312 return optionalBuild .orNull () == null ? null : buildWithClient (optionalBuild .orNull ());
296313 }
297314
0 commit comments