-
-
Notifications
You must be signed in to change notification settings - Fork 469
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
234 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.offbytwo.jenkins.model; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.google.common.base.Function; | ||
import com.google.common.collect.Maps; | ||
|
||
public class FolderJob extends Job { | ||
|
||
String displayName; | ||
List<Job> jobs; | ||
|
||
public FolderJob() {} | ||
|
||
public String getDisplayName() { | ||
return displayName; | ||
} | ||
|
||
/** | ||
* Determine if this FolderJob object is a valid folder or not. | ||
* | ||
* (internally: if jobs list exists) | ||
* | ||
* @return true if this job is a folder. | ||
*/ | ||
public boolean isFolder() { | ||
if (jobs != null) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Get a list of all the defined jobs in this folder | ||
* | ||
* @return list of defined jobs (summary level, for details @see Job#details | ||
* @throws IOException | ||
*/ | ||
public Map<String, Job> getJobs() { | ||
return Maps.uniqueIndex(jobs, new Function<Job, String>() { | ||
@Override | ||
public String apply(Job job) { | ||
job.setClient(client); | ||
return job.getName().toLowerCase(); | ||
} | ||
}); | ||
} | ||
|
||
/* TODO | ||
public List<Job> getJobsRecursive() { | ||
return Lists.transform(jobs, new Function<Job, Job>() { | ||
@Override | ||
public Job apply(Job job) { | ||
// TODO: try to see if each job is a folder | ||
return job; | ||
} | ||
}); | ||
} | ||
*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import java.net.URI; | ||
import java.util.Map; | ||
|
||
import org.junit.Test; | ||
|
||
import com.google.common.base.Optional; | ||
import com.offbytwo.jenkins.JenkinsServer; | ||
import com.offbytwo.jenkins.model.FolderJob; | ||
import com.offbytwo.jenkins.model.Job; | ||
|
||
|
||
|
||
public class Testz { | ||
|
||
@Test | ||
public void testStuff() { | ||
try { | ||
JenkinsServer test = new JenkinsServer(new URI("http://localhost:8080/")); | ||
Map<String, Job> jobs = test.getJobs(); | ||
for (String s : jobs.keySet()) { | ||
System.out.println("Job " + s + " is at " + jobs.get(s).getUrl()); | ||
} | ||
Job job = jobs.get("test folder"); | ||
|
||
Optional<FolderJob> ofj = test.getFolderJob(job); | ||
FolderJob fj = ofj.get(); | ||
|
||
Map<String, Job> moarJobs = fj.getJobs(); | ||
for (String s : moarJobs.keySet()) { | ||
System.out.println("Job " + s + " is at " + moarJobs.get(s).getUrl()); | ||
} | ||
|
||
System.out.println("test: " + fj.toString()); | ||
test.createFolder("testzzz"); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |