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();
}
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();
}
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);
}
}
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;
}
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()));
}
}
Aggregations