Search in sources :

Example 1 with BluePipeline

use of io.jenkins.blueocean.rest.model.BluePipeline in project blueocean-plugin by jenkinsci.

the class BranchContainerImpl method iterator.

@Override
@SuppressWarnings("unchecked")
public Iterator<BluePipeline> iterator() {
    List<BluePipeline> branches = new ArrayList<>();
    Collection<Job> jobs = pipeline.mbp.getAllJobs();
    jobs = ContainerFilter.filter(jobs);
    for (Job j : jobs) {
        branches.add(new BranchImpl(j, getLink()));
    }
    return Ordering.from(BRANCH_COMPARITOR).sortedCopy(branches).iterator();
}
Also used : ArrayList(java.util.ArrayList) BluePipeline(io.jenkins.blueocean.rest.model.BluePipeline) Job(hudson.model.Job)

Example 2 with BluePipeline

use of io.jenkins.blueocean.rest.model.BluePipeline in project blueocean-plugin by jenkinsci.

the class PipelineContainerImpl method getPipelines.

public Iterator<BluePipeline> getPipelines(Collection<? extends Item> items) {
    items = ContainerFilter.filter(items);
    List<BluePipeline> pipelines = new ArrayList<>();
    for (Item item : items) {
        BluePipeline pipeline = BluePipelineFactory.getPipelineInstance(item, this);
        if (pipeline != null) {
            pipelines.add(pipeline);
        }
    }
    return pipelines.iterator();
}
Also used : TopLevelItem(hudson.model.TopLevelItem) Item(hudson.model.Item) ArrayList(java.util.ArrayList) BluePipeline(io.jenkins.blueocean.rest.model.BluePipeline)

Example 3 with BluePipeline

use of io.jenkins.blueocean.rest.model.BluePipeline in project blueocean-plugin by jenkinsci.

the class PipelineSearch method search.

@Override
public Pageable<BluePipeline> search(Query q) {
    String s = q.param(EXCLUDED_FROM_FLATTENING_PARAM);
    String org = q.param(ORGANIZATION_PARAM);
    if (org != null && !OrganizationImpl.INSTANCE.getName().equals(org)) {
        throw new ServiceException.BadRequestExpception(String.format("Organization %s not found. Query parameter %s value: %s is invalid. ", org, ORGANIZATION_PARAM, org));
    }
    List<Class> excludeList = new ArrayList<>();
    if (s != null) {
        for (String s1 : s.split(",")) {
            Class c = null;
            try {
                c = Class.forName(s1);
            } catch (ClassNotFoundException e) {
                try {
                    //TODO: There should be better ways to find a class from a plugin.
                    Plugin p = Jenkins.getInstance().getPlugin("blueocean-pipeline-api-impl");
                    if (p != null) {
                        c = p.getWrapper().classLoader.loadClass(s1);
                    } else {
                        logger.error("blueocean-pipeline-api-impl plugin not found!");
                    }
                } catch (ClassNotFoundException e1) {
                    logger.error(e.getMessage(), e1);
                }
            //ignored, give other OmniSearch implementations chance, they might handle it
            //throw new ServiceException.BadRequestExpception(String.format("%s parameter has invalid value: %s", EXCLUDED_FROM_FLATTENING_PARAM, s1), e);
            }
            if (c != null) {
                excludeList.add(c);
            }
        }
    }
    Collection<Item> items = new ArrayList<>();
    if (!excludeList.isEmpty()) {
        for (Item item : Jenkins.getActiveInstance().getAllItems(Item.class)) {
            if (!exclude(item.getParent(), excludeList)) {
                items.add(item);
            }
        }
    } else {
        items = Jenkins.getActiveInstance().getAllItems(Item.class);
    }
    items = ContainerFilter.filter(items);
    final Iterator<BluePipeline> pipelineIterator = new PipelineContainerImpl().getPipelines(items);
    final List<BluePipeline> pipelines = new ArrayList<>();
    String pipeline = q.param(getType());
    if (pipeline == null) {
        return Pageables.wrap(new Iterable<BluePipeline>() {

            @Override
            public Iterator<BluePipeline> iterator() {
                return pipelineIterator;
            }
        });
    } else {
        while (pipelineIterator.hasNext()) {
            BluePipeline p = pipelineIterator.next();
            if (!p.getName().equals(pipeline)) {
                continue;
            }
            pipelines.add(p);
        }
        return Pageables.wrap(pipelines);
    }
}
Also used : ArrayList(java.util.ArrayList) Item(hudson.model.Item) Iterator(java.util.Iterator) BluePipeline(io.jenkins.blueocean.rest.model.BluePipeline) Plugin(hudson.Plugin)

Example 4 with BluePipeline

use of io.jenkins.blueocean.rest.model.BluePipeline in project blueocean-plugin by jenkinsci.

the class PipelineStatePreloader method getFetchData.

@Override
protected FetchData getFetchData(@Nonnull BlueUrlTokenizer blueUrl) {
    // e.g. /blue/organizations/jenkins/Pipeline (or a url on that)
    if (!blueUrl.hasPart(BlueUrlTokenizer.UrlPart.PIPELINE)) {
        // Not interested in it
        return null;
    }
    Jenkins jenkins = Jenkins.getInstance();
    String pipelineFullName = blueUrl.getPart(BlueUrlTokenizer.UrlPart.PIPELINE);
    try {
        Item pipelineJobItem = jenkins.getItemByFullName(pipelineFullName);
        if (pipelineJobItem != null) {
            BluePipeline bluePipeline = (BluePipeline) BluePipelineFactory.resolve(pipelineJobItem);
            if (bluePipeline != null) {
                try {
                    return new FetchData(bluePipeline.getLink().getHref(), ModelObjectSerializer.toJson(bluePipeline));
                } catch (IOException e) {
                    LOGGER.log(Level.FINE, String.format("Unable to preload pipeline '%s'. Serialization error.", pipelineJobItem.getUrl()), e);
                    return null;
                }
            } else {
                LOGGER.log(Level.FINE, String.format("Unable to preload pipeline '%s'. Failed to convert to Blue Ocean Resource.", pipelineJobItem.getUrl()));
                return null;
            }
        }
    } catch (Exception e) {
        LOGGER.log(Level.FINE, String.format("Unable to find pipeline named '%s'.", pipelineFullName), e);
        return null;
    }
    // Don't preload any data on the page.
    return null;
}
Also used : Jenkins(jenkins.model.Jenkins) Item(hudson.model.Item) BluePipeline(io.jenkins.blueocean.rest.model.BluePipeline) IOException(java.io.IOException) IOException(java.io.IOException)

Example 5 with BluePipeline

use of io.jenkins.blueocean.rest.model.BluePipeline in project blueocean-plugin by jenkinsci.

the class BlueOceanWebURLBuilder method getPipelineModelMapping.

private static BlueOceanModelMapping getPipelineModelMapping(Job job) {
    BluePipeline blueResource = (BluePipeline) BluePipelineFactory.resolve(job);
    if (blueResource instanceof BranchImpl) {
        // No abstract "Branch" type?
        ItemGroup multibranchJob = job.getParent();
        BluePipeline multibranchJobResource = (BluePipeline) BluePipelineFactory.resolve((Item) multibranchJob);
        return new BlueOceanModelMapping(multibranchJob, multibranchJobResource, getOrgPrefix() + "/" + encodeURIComponent(multibranchJobResource.getFullName()));
    } else {
        return new BlueOceanModelMapping(job, blueResource, getOrgPrefix() + "/" + encodeURIComponent(blueResource.getFullName()));
    }
}
Also used : Item(hudson.model.Item) ItemGroup(hudson.model.ItemGroup) BranchImpl(io.jenkins.blueocean.rest.impl.pipeline.BranchImpl) BluePipeline(io.jenkins.blueocean.rest.model.BluePipeline)

Aggregations

BluePipeline (io.jenkins.blueocean.rest.model.BluePipeline)9 Item (hudson.model.Item)5 ArrayList (java.util.ArrayList)5 IOException (java.io.IOException)3 Jenkins (jenkins.model.Jenkins)2 Plugin (hudson.Plugin)1 ItemGroup (hudson.model.ItemGroup)1 Job (hudson.model.Job)1 TopLevelItem (hudson.model.TopLevelItem)1 BranchImpl (io.jenkins.blueocean.rest.impl.pipeline.BranchImpl)1 BlueQueueItem (io.jenkins.blueocean.rest.model.BlueQueueItem)1 BlueRun (io.jenkins.blueocean.rest.model.BlueRun)1 BlueRunContainer (io.jenkins.blueocean.rest.model.BlueRunContainer)1 Resource (io.jenkins.blueocean.rest.model.Resource)1 Iterator (java.util.Iterator)1 List (java.util.List)1 JSONArray (net.sf.json.JSONArray)1 StaplerRequest (org.kohsuke.stapler.StaplerRequest)1