@Override
protected int run() throws Exception {
job.checkPermission(Item.BUILD);
SubProjectsAction sp = null;
SubProjectsJobProperty spjp = (SubProjectsJobProperty)
job.getProperty(SubProjectsJobProperty.class);
if (!subJobs.isEmpty()) {
if (spjp == null) {
throw new AbortException(
String.format(
"%s does not allow sub-job selection but sub-jobs were"
+ " specified.",
job.getDisplayName()));
}
Set<String> subProjects = Sets.<String>newHashSet();
Set<String> excludeProjects = Sets.<String>newHashSet();
for (String subJob : subJobs) {
boolean exclude = false;
if (subJob.charAt(0) == '-') {
exclude = true;
subJob = subJob.substring(1, subJob.length());
}
AbstractProject project = projectFinder.findProject(subJob);
if (project == null) {
throw new AbortException(
String.format(
"Project does not exist: %s",
subJob));
}
if (!job.contains((TopLevelItem) project)) {
throw new AbortException(
String.format(
"%s does not exist in Master Project: %s",
subJob,
job.getDisplayName()));
}
if (exclude) {
excludeProjects.add(subJob);
} else {
subProjects.add(subJob);
}
}
sp = new SubProjectsAction(subProjects, excludeProjects);
} else if (spjp != null) {
stdout.println(
String.format(
"Executing DEFAULT sub-jobs: %s",
spjp.getDefaultSubProjectsString()));