Search in sources :

Example 1 with TreeResponse

use of io.jenkins.blueocean.commons.stapler.TreeResponse in project blueocean-plugin by jenkinsci.

the class BluePipeline method update.

/**
     * Updates this pipeline using {@link BluePipelineUpdateRequest}
     * @param staplerRequest stapler request
     * @return Updated BluePipeline instance
     * @throws IOException throws IOException in certain cases
     */
@PUT
@WebMethod(name = "")
@TreeResponse
public BluePipeline update(StaplerRequest staplerRequest) throws IOException {
    JSONObject body = JSONObject.fromObject(IOUtils.toString(staplerRequest.getReader()));
    if (body.get("$class") == null) {
        throw new ServiceException.BadRequestExpception("$class is required element");
    }
    BluePipelineUpdateRequest request = staplerRequest.bindJSON(BluePipelineUpdateRequest.class, body);
    return update(request);
}
Also used : JSONObject(net.sf.json.JSONObject) WebMethod(org.kohsuke.stapler.WebMethod) TreeResponse(io.jenkins.blueocean.commons.stapler.TreeResponse) PUT(org.kohsuke.stapler.verb.PUT)

Example 2 with TreeResponse

use of io.jenkins.blueocean.commons.stapler.TreeResponse in project blueocean-plugin by jenkinsci.

the class PipelineMetadataService method doAgentMetadata.

/**
 * Function to return all {@link DeclarativeAgent}s present in the system when accessed through the REST API
 */
@GET
@TreeResponse
public ExportedDescribableModel[] doAgentMetadata() {
    List<ExportedDescribableModel> models = new ArrayList<>();
    for (DeclarativeAgentDescriptor d : DeclarativeAgentDescriptor.all()) {
        try {
            DescribableModel<? extends DeclarativeAgent> model = new DescribableModel<>(d.clazz);
            String symbol = symbolForObject(d);
            if ("label".equals(symbol)) {
                // Label has 2 symbols, but we need "node"
                symbol = "node";
            }
            models.add(new ExportedDescribableModel(model, symbol));
        } catch (NoStaplerConstructorException e) {
        // Ignore!
        }
    }
    return models.toArray(new ExportedDescribableModel[models.size()]);
}
Also used : DeclarativeAgentDescriptor(org.jenkinsci.plugins.pipeline.modeldefinition.agent.DeclarativeAgentDescriptor) ArrayList(java.util.ArrayList) DescribableModel(org.jenkinsci.plugins.structs.describable.DescribableModel) NoStaplerConstructorException(org.kohsuke.stapler.NoStaplerConstructorException) TreeResponse(io.jenkins.blueocean.commons.stapler.TreeResponse) GET(org.kohsuke.stapler.verb.GET)

Example 3 with TreeResponse

use of io.jenkins.blueocean.commons.stapler.TreeResponse in project blueocean-plugin by jenkinsci.

the class PipelineMetadataService method doToolMetadata.

/**
 * Function to return all {@link ExportedToolDescriptor}s present in the system when accessed through the REST API,
 * pipeline scripts need: symbol and name to specify tools
 */
@GET
@TreeResponse
public ExportedToolDescriptor[] doToolMetadata() {
    List<ExportedToolDescriptor> models = new ArrayList<>();
    for (ToolDescriptor<? extends ToolInstallation> d : ToolInstallation.all()) {
        ExportedToolDescriptor descriptor = new ExportedToolDescriptor(d.getDisplayName(), symbolForObject(d), d.getClass());
        models.add(descriptor);
        for (ToolInstallation installation : d.getInstallations()) {
            descriptor.addInstallation(new ExportedToolDescriptor.ExportedToolInstallation(installation.getName(), installation.getClass()));
        }
    }
    return models.toArray(new ExportedToolDescriptor[models.size()]);
}
Also used : ArrayList(java.util.ArrayList) ToolInstallation(hudson.tools.ToolInstallation) TreeResponse(io.jenkins.blueocean.commons.stapler.TreeResponse) GET(org.kohsuke.stapler.verb.GET)

Example 4 with TreeResponse

use of io.jenkins.blueocean.commons.stapler.TreeResponse in project blueocean-plugin by jenkinsci.

the class PipelineMetadataService method doPipelineStepMetadata.

/**
 * Function to return all step descriptors present in the system when accessed through the REST API
 */
@GET
@TreeResponse
public ExportedPipelineFunction[] doPipelineStepMetadata() {
    List<ExportedPipelineFunction> pd = new ArrayList<>();
    for (StepDescriptor d : StepDescriptor.all()) {
        if (includeStep(d)) {
            ExportedPipelineStep step = getStepMetadata(d);
            if (step != null) {
                pd.add(step);
            }
        }
    }
    List<Descriptor<?>> metaStepDescriptors = new ArrayList<Descriptor<?>>();
    populateMetaSteps(metaStepDescriptors, Builder.class);
    populateMetaSteps(metaStepDescriptors, Publisher.class);
    for (Descriptor<?> d : metaStepDescriptors) {
        ExportedPipelineFunction metaStep = getStepMetadata(d);
        if (metaStep != null) {
            pd.add(metaStep);
        }
    }
    return pd.toArray(new ExportedPipelineFunction[pd.size()]);
}
Also used : ArrayList(java.util.ArrayList) StepDescriptor(org.jenkinsci.plugins.workflow.steps.StepDescriptor) DeclarativeAgentDescriptor(org.jenkinsci.plugins.pipeline.modeldefinition.agent.DeclarativeAgentDescriptor) ToolDescriptor(hudson.tools.ToolDescriptor) Descriptor(hudson.model.Descriptor) StepDescriptor(org.jenkinsci.plugins.workflow.steps.StepDescriptor) TreeResponse(io.jenkins.blueocean.commons.stapler.TreeResponse) GET(org.kohsuke.stapler.verb.GET)

Example 5 with TreeResponse

use of io.jenkins.blueocean.commons.stapler.TreeResponse in project blueocean-plugin by jenkinsci.

the class PipelineMetadataService method doBuildConditions.

/**
 * Function to return the names of all build conditions present in the system when accessed through the REST API
 */
@GET
@TreeResponse
public ExportedBuildCondition[] doBuildConditions() {
    List<ExportedBuildCondition> exported = new ArrayList<>();
    for (BuildCondition c : BuildCondition.all()) {
        exported.add(new ExportedBuildCondition(symbolForObject(c), c.getDescription()));
    }
    Collections.sort(exported, new Comparator<ExportedBuildCondition>() {

        @Override
        public int compare(ExportedBuildCondition o1, ExportedBuildCondition o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    return exported.toArray(new ExportedBuildCondition[exported.size()]);
}
Also used : ArrayList(java.util.ArrayList) BuildCondition(org.jenkinsci.plugins.pipeline.modeldefinition.model.BuildCondition) TreeResponse(io.jenkins.blueocean.commons.stapler.TreeResponse) GET(org.kohsuke.stapler.verb.GET)

Aggregations

TreeResponse (io.jenkins.blueocean.commons.stapler.TreeResponse)5 ArrayList (java.util.ArrayList)4 GET (org.kohsuke.stapler.verb.GET)4 DeclarativeAgentDescriptor (org.jenkinsci.plugins.pipeline.modeldefinition.agent.DeclarativeAgentDescriptor)2 Descriptor (hudson.model.Descriptor)1 ToolDescriptor (hudson.tools.ToolDescriptor)1 ToolInstallation (hudson.tools.ToolInstallation)1 JSONObject (net.sf.json.JSONObject)1 BuildCondition (org.jenkinsci.plugins.pipeline.modeldefinition.model.BuildCondition)1 DescribableModel (org.jenkinsci.plugins.structs.describable.DescribableModel)1 StepDescriptor (org.jenkinsci.plugins.workflow.steps.StepDescriptor)1 NoStaplerConstructorException (org.kohsuke.stapler.NoStaplerConstructorException)1 WebMethod (org.kohsuke.stapler.WebMethod)1 PUT (org.kohsuke.stapler.verb.PUT)1