package com.vmware;

import com.google.gson.annotations.Expose;
import com.vmware.util.MatcherUtils;

public class JobBuild {
    @Expose(serialize = false, deserialize = false)
    public String buildDisplayName;
    public int number;
    public String url;
    @Expose(serialize = false, deserialize = false)
    public BuildResult result;

    public JobBuild() {}

    public JobBuild(String buildDisplayName, String url, BuildResult result) {
        this.buildDisplayName = buildDisplayName;
        this.url = url;
        this.result = result;
    }

    public JobBuild(final int number, final String baseUrl, BuildResult result) {
        this.number = number;
        this.url = baseUrl + number + "/";
        this.result = result;
    }

    public JobBuild(final int number, final String baseUrl) {
        this(number, baseUrl, BuildResult.BUILDING);
    }

    public String getBaseUrl() {
        return url.substring(0, url.lastIndexOf(String.valueOf(number)));
    }

    public boolean containsUrl(String url) {
        return this.url != null && this.url.contains(url);
    }

    public String id() {
        return MatcherUtils.singleMatch(url, "http.+?/(\\d+)/*.*?");
    }

    public boolean isFailure() {
        return result == BuildResult.FAILURE || result == BuildResult.UNSTABLE;
    }

    public String getJenkinsInfoUrl() {
        return url + "api/json";
    }

    public String getConsoleOutputUrl() {
        return url + "consoleText";
    }

    public String getJenkinsStopUrl() {
        return url + "stop";
    }

    public String details(boolean includeResult) {
        String buildName = buildDisplayName != null ? buildDisplayName : "Build";
        String buildInfo = buildName + " " + url;
        if (includeResult && result != null) {
            buildInfo += " " + result.name();
        }
        return buildInfo;
    }

}

@@ -93,16 +93,85 @@
 erUtils;
+%0Aimport com.vmware.util.StringUtils;%0Aimport com.vmware.util.UrlUtils;
 %0A%0Apublic
@@ -1437,22 +1437,24 @@
  return 
-url + 
+fullUrl(
 %22api/jso
@@ -1455,16 +1455,17 @@
 pi/json%22
+)
 ;%0A    %7D%0A
@@ -1522,22 +1522,24 @@
  return 
-url + 
+fullUrl(
 %22console
@@ -1543,16 +1543,17 @@
 oleText%22
+)
 ;%0A    %7D%0A
@@ -1612,20 +1612,23 @@
 urn 
-url + 
+fullUrl(
 %22stop%22
+)
 ;%0A  
@@ -1951,10 +1951,112 @@
 %0A    %7D%0A%0A
+    private String fullUrl(String path) %7B%0A        return UrlUtils.addTrailingSlash(url) + path;%0A    %7D%0A
 %7D%0A

Standardize url construction