use of javax.annotation.CheckForNull in project blueocean-plugin by jenkinsci.
the class GitPipelineUpdateRequest method update.
@CheckForNull
@Override
@SuppressWarnings("unchecked")
public BluePipeline update(BluePipeline pipeline) throws IOException {
Item item = Jenkins.getInstance().getItemByFullName(pipeline.getFullName());
if (item instanceof MultiBranchProject) {
ACL acl = Jenkins.getInstance().getACL();
Authentication a = Jenkins.getAuthentication();
if (!acl.hasPermission(a, Item.CONFIGURE)) {
throw new ServiceException.ForbiddenException(String.format("Failed to update Git pipeline: %s. User %s doesn't have Job configure permission", pipeline.getName(), a.getName()));
}
MultiBranchProject mbp = (MultiBranchProject) item;
BranchSource branchSource = getGitScmSource(mbp);
if (branchSource != null) {
mbp.getSourcesList().replaceBy(Collections.singleton(branchSource));
mbp.scheduleBuild2(0, new CauseAction(new Cause.UserIdCause()));
}
}
return pipeline;
}
use of javax.annotation.CheckForNull in project blueocean-plugin by jenkinsci.
the class BlueUrlTokenizer method parseCurrentRequest.
/**
* Parse the {@link Stapler#getCurrentRequest() current Stapler request} and return a {@link BlueUrlTokenizer} instance
* iff the URL is a Blue Ocean UI URL.
*
* @return A {@link BlueUrlTokenizer} instance iff the URL is a Blue Ocean UI URL, otherwise {@code null}.
* @throws IllegalStateException Called outside the scope of an active {@link StaplerRequest}.
*/
@CheckForNull
public static BlueUrlTokenizer parseCurrentRequest() throws IllegalStateException {
StaplerRequest currentRequest = Stapler.getCurrentRequest();
if (currentRequest == null) {
throw new IllegalStateException("Illegal call to BlueoceanUrl.parseCurrentRequest outside the scope of an active StaplerRequest.");
}
String path = currentRequest.getOriginalRequestURI();
String contextPath = currentRequest.getContextPath();
path = path.substring(contextPath.length());
return parse(path);
}
use of javax.annotation.CheckForNull in project blueocean-plugin by jenkinsci.
the class PipelineNodeUtil method getCauseOfBlockage.
/**
* Gives cause of block for declarative style plugin where agent (node block) is declared inside a stage.
* <pre>
* pipeline {
* agent none
* stages {
* stage ('first') {
* agent {
* label 'first'
* }
* steps{
* sh 'echo "from first"'
* }
* }
* }
* }
* </pre>
*
* @param stage stage's {@link FlowNode}
* @param nodeBlock agent or node block's {@link FlowNode}
* @param run {@link WorkflowRun} instance
* @return cause of block if present, nul otherwise
* @throws IOException in case of IOException
* @throws InterruptedException in case of Interrupted exception
*/
@CheckForNull
public static String getCauseOfBlockage(@Nonnull FlowNode stage, @Nullable FlowNode nodeBlock, @Nonnull WorkflowRun run) throws IOException, InterruptedException {
if (nodeBlock != null) {
//Check and see if this node block is inside this stage
for (FlowNode p : nodeBlock.getParents()) {
if (p.equals(stage)) {
//see if there is blocked item in queue
for (Queue.Item i : Jenkins.getInstance().getQueue().getItems()) {
if (i.task instanceof ExecutorStepExecution.PlaceholderTask) {
ExecutorStepExecution.PlaceholderTask task = (ExecutorStepExecution.PlaceholderTask) i.task;
String cause = i.getCauseOfBlockage().getShortDescription();
if (task.getCauseOfBlockage() != null) {
cause = task.getCauseOfBlockage().getShortDescription();
}
Run r = task.runForDisplay();
//Set cause if its there and run and node block in the queue is same as the one we
if (cause != null && r != null && r.equals(run) && task.getNode() != null && task.getNode().equals(nodeBlock)) {
return cause;
}
}
}
}
}
}
return null;
}
use of javax.annotation.CheckForNull in project promoted-builds-plugin by jenkinsci.
the class JobDslPromotionProcessConverter method obtainClassOwnership.
@CheckForNull
private String obtainClassOwnership() {
if (this.classOwnership != null) {
return this.classOwnership;
}
if (pm == null) {
Jenkins j = Jenkins.getInstance();
if (j != null) {
pm = j.getPluginManager();
}
}
if (pm == null) {
return null;
}
// TODO: possibly recursively scan super class to discover dependencies
PluginWrapper p = pm.whichPlugin(hudson.plugins.promoted_builds.PromotionProcess.class);
this.classOwnership = p != null ? p.getShortName() + '@' + trimVersion(p.getVersion()) : null;
return this.classOwnership;
}
use of javax.annotation.CheckForNull in project promoted-builds-plugin by jenkinsci.
the class ItemPathResolver method getByPath.
/**
* Gets an {@link Item} of the specified type by absolute or relative path.
* <p>
* The implementation retains the original behavior in {@link PromotedBuildParameterDefinition},
* but this method also provides a support of multi-level addressing including special markups
* for the relative addressing.
* </p>
* Effectively, the resolution order is following:
* <ul>
* <li><b>Optional</b> Legacy behavior, which can be enabled by {@link #ENABLE_LEGACY_RESOLUTION_AGAINST_ROOT}.
* If an item for the name exists on the top Jenkins level, it will be returned</li>
* <li>If the path starts with "/", a global addressing will be used</li>
* <li>If the path starts with "./" or "../", a relative addressing will be used</li>
* <li>If there is no prefix, a relative addressing will be tried. If it
* fails, the method falls back to a global one</li>
* </ul>
* For the relative and absolute addressing the engine supports "." and
* ".." markers within the path.
* The first one points to the current element, the second one - to the upper element.
* If the search cannot get a new top element (e.g. reached the root), the method returns {@code null}.
*
* @param <T> Type of the {@link Item} to be retrieved
* @param path Path string to the item.
* @param baseItem Base {@link Item} for the relative addressing. If null,
* this addressing approach will be skipped
* @param type Type of the {@link Item} to be retrieved
* @return Found {@link Item}. Null if it has not been found by all addressing modes
* or the type differs.
*/
@CheckForNull
@SuppressWarnings("unchecked")
@Restricted(NoExternalUse.class)
public static <T extends Item> T getByPath(@Nonnull String path, @CheckForNull Item baseItem, @Nonnull Class<T> type) {
final Jenkins jenkins = Jenkins.getInstance();
if (jenkins == null) {
return null;
}
// Legacy behavior
if (isEnableLegacyResolutionAgainstRoot()) {
TopLevelItem topLevelItem = jenkins.getItem(path);
if (topLevelItem != null && type.isAssignableFrom(topLevelItem.getClass())) {
return (T) topLevelItem;
}
}
// Explicit global addressing
if (path.startsWith("/")) {
return findPath(jenkins, path.substring(1), type);
}
// Try the relative addressing if possible
if (baseItem != null) {
final ItemGroup<?> relativeRoot = baseItem instanceof ItemGroup<?> ? (ItemGroup<?>) baseItem : baseItem.getParent();
final T item = findPath(relativeRoot, path, type);
if (item != null) {
return item;
}
}
// Fallback to the default behavior (addressing from the Jenkins root)
return findPath(jenkins, path, type);
}
Aggregations