Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -260,7 +262,7 @@ public View getView(FolderJob folder, String name) throws IOException {
* @throws IOException in case of an error.
*/
public JobWithDetails getJob(String jobName) throws IOException {
return getJob(null, jobName);
return getJob(null, parseFullName(jobName));
}

/**
Expand Down Expand Up @@ -288,7 +290,7 @@ public JobWithDetails getJob(FolderJob folder, String jobName) throws IOExceptio
}

public MavenJobWithDetails getMavenJob(String jobName) throws IOException {
return getMavenJob(null, jobName);
return getMavenJob(null, parseFullName(jobName));
}

public MavenJobWithDetails getMavenJob(FolderJob folder, String jobName) throws IOException {
Expand Down Expand Up @@ -562,7 +564,6 @@ public PluginManager getPluginManager() throws IOException {
/**
* Update the xml description of an existing view
*
* @throws IOException in case of an error.
* @param viewName name of the view.
* @param viewXml the view configuration.
* @throws IOException in case of an error.
Expand Down Expand Up @@ -903,7 +904,18 @@ private String toBaseUrl(FolderJob folder) {
* @return converted base url.
*/
private String toJobBaseUrl(FolderJob folder, String jobName) {
return toBaseUrl(folder) + "job/" + EncodingUtils.encode(jobName);
String jobBaseUrl = toBaseUrl(folder) + "job/";

String[] jobNameParts = jobName.split("/");
for (int i = 0; i < jobNameParts.length; i++) {
jobBaseUrl += EncodingUtils.encode(jobNameParts[i]);

if (i != jobNameParts.length - 1) {
jobBaseUrl += "/";
}
}

return jobBaseUrl;
}

/**
Expand All @@ -917,4 +929,29 @@ private String toViewBaseUrl(FolderJob folder, String name) {
return toBaseUrl(folder) + "view/" + EncodingUtils.encode(name);
}

/**
* Parses the provided job name for folders to get the full path for the job.
* @param jobName the fullName of the job.
* @return the path of the job including folders if present.
*/
private String parseFullName(String jobName)
{
if (!jobName.contains("/")) {
return jobName;
}

List<String> foldersAndJob = Arrays.asList(jobName.split("/"));

String foldersAndJobName = "";

for (int i = 0; i < foldersAndJob.size(); i++) {
foldersAndJobName += foldersAndJob.get(i);

if (i != foldersAndJob.size() -1) {
foldersAndJobName += "/job/";
}
}

return foldersAndJobName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public FolderJob() {
public FolderJob(String name, String url) {
super(name, url);
}

public FolderJob(String name, String url, String fullName) {
super(name, url, fullName);
}

public String getDisplayName() {
return displayName;
Expand Down
19 changes: 17 additions & 2 deletions jenkins-client/src/main/java/com/offbytwo/jenkins/model/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,23 @@ public class Job extends BaseModel {

private String name;
private String url;
private String fullName;

public Job() {
}

public Job(String name, String url) {
this();
this.name = name;
this.url = url;
this.fullName = null;
}

public Job(String name, String url, String fullName) {
this();
this.name = name;
this.url = url;
this.fullName = fullName;
}

public String getName() {
Expand All @@ -40,6 +49,10 @@ public String getName() {
public String getUrl() {
return url;
}

public String getFullName() {
return fullName;
}

public JobWithDetails details() throws IOException {
return client.get(url, JobWithDetails.class);
Expand Down Expand Up @@ -126,14 +139,16 @@ public boolean equals(Object o) {
return false;
if (url != null ? !url.equals(job.url) : job.url != null)
return false;
if (fullName != null ? !fullName.equals(job.fullName) : job.fullName != null)
return false;

return true;
}

@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (url != null ? url.hashCode() : 0);
result = 31 * result + (url != null ? url.hashCode() : 0) + (fullName != null ? fullName.hashCode() : 0);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class JobWithDetails extends Job {
private List<Job> downstreamProjects;

private List<Job> upstreamProjects;

public String getDescription() {
return description;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public MavenJob() {
public MavenJob(String name, String url) {
super(name, url);
}

public MavenJob(String name, String url, String fullName) {
super(name, url, fullName);
}

public MavenJobWithDetails mavenDetails() throws IOException {
return client.get(getUrl(), MavenJobWithDetails.class);
Expand Down