Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-50882] Make generator work on multibranch and org folders
Sigh - I didn't realize that Snippetizer actually had to do the same
thing in three places (well, more accurately, two of those are in
workflow-multibranch but are otherwise identical to what's in
Snippetizer). So here are `TransientActionFactory`s added for
`OrganizationFolder` and `WorkflowMultiBranchProject` (aka multibranch
folder), and a refinement of the `WorkflowJob` one too.
  • Loading branch information
abayer committed Apr 19, 2018
1 parent 2249ecb commit ee78d7a
Showing 1 changed file with 53 additions and 6 deletions.
Expand Up @@ -30,13 +30,17 @@
import hudson.model.Descriptor;
import hudson.model.Item;
import hudson.model.Job;
import jenkins.branch.OrganizationFolder;
import jenkins.model.Jenkins;
import jenkins.model.TransientActionFactory;
import net.sf.json.JSONObject;
import org.jenkinsci.plugins.structs.SymbolLookup;
import org.jenkinsci.plugins.structs.describable.UninstantiatedDescribable;
import org.jenkinsci.plugins.workflow.cps.Snippetizer;
import org.jenkinsci.plugins.workflow.cps.SnippetizerLink;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.multibranch.AbstractWorkflowMultiBranchProjectFactory;
import org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject;
import org.jenkinsci.plugins.workflow.steps.StepDescriptor;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.DoNotUse;
Expand Down Expand Up @@ -132,15 +136,58 @@ public static String getSymbolForDescriptor(Descriptor d) {
}

@Restricted(DoNotUse.class)
@Extension public static class PerJobAdder extends TransientActionFactory<Job> {
@Extension
public static class PerWorkflowJobAdder extends TransientActionFactory<WorkflowJob> {

@Override public Class<Job> type() {
return Job.class;
@Override
public Class<WorkflowJob> type() {
return WorkflowJob.class;
}

@Override
@Nonnull
public Collection<? extends Action> createFor(@Nonnull WorkflowJob target) {
if (target.hasPermission(Item.EXTENDED_READ)) {
return Collections.singleton(new DirectiveGenerator());
} else {
return Collections.emptySet();
}
}
}

@Restricted(DoNotUse.class)
@Extension
public static class PerOrgFolderAdder extends TransientActionFactory<OrganizationFolder> {

@Override
public Class<OrganizationFolder> type() {
return OrganizationFolder.class;
}

@Override public Collection<? extends Action> createFor(Job target) {
// TODO probably want an API for FlowExecutionContainer or something
if (target.getClass().getName().equals("org.jenkinsci.plugins.workflow.job.WorkflowJob") && target.hasPermission(Item.EXTENDED_READ)) {
@Override
@Nonnull
public Collection<? extends Action> createFor(@Nonnull OrganizationFolder target) {
if (target.getProjectFactories().get(AbstractWorkflowMultiBranchProjectFactory.class) != null && target.hasPermission(Item.EXTENDED_READ)) {
return Collections.singleton(new DirectiveGenerator());
} else {
return Collections.emptySet();
}
}
}

@Restricted(DoNotUse.class)
@Extension
public static class PerMultiBranchFolderAdder extends TransientActionFactory<WorkflowMultiBranchProject> {

@Override
public Class<WorkflowMultiBranchProject> type() {
return WorkflowMultiBranchProject.class;
}

@Override
@Nonnull
public Collection<? extends Action> createFor(@Nonnull WorkflowMultiBranchProject target) {
if (target.hasPermission(Item.EXTENDED_READ)) {
return Collections.singleton(new DirectiveGenerator());
} else {
return Collections.emptySet();
Expand Down

0 comments on commit ee78d7a

Please sign in to comment.