Search in sources :

Example 81 with CheckForNull

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;
}
Also used : Item(hudson.model.Item) Authentication(org.acegisecurity.Authentication) CauseAction(hudson.model.CauseAction) MultiBranchProject(jenkins.branch.MultiBranchProject) ACL(hudson.security.ACL) BranchSource(jenkins.branch.BranchSource) CheckForNull(javax.annotation.CheckForNull)

Example 82 with CheckForNull

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);
}
Also used : StaplerRequest(org.kohsuke.stapler.StaplerRequest) CheckForNull(javax.annotation.CheckForNull)

Example 83 with CheckForNull

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;
}
Also used : ExecutorStepExecution(org.jenkinsci.plugins.workflow.support.steps.ExecutorStepExecution) BlueRun(io.jenkins.blueocean.rest.model.BlueRun) Run(hudson.model.Run) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Queue(hudson.model.Queue) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) CheckForNull(javax.annotation.CheckForNull)

Example 84 with CheckForNull

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;
}
Also used : Jenkins(jenkins.model.Jenkins) PluginWrapper(hudson.PluginWrapper) CheckForNull(javax.annotation.CheckForNull)

Example 85 with CheckForNull

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 &quot;/&quot;, a global addressing will be used</li>
     *   <li>If the path starts with &quot;./&quot; or &quot;../&quot;, 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 &quot;.&quot; and
     * &quot;..&quot; 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);
}
Also used : Jenkins(jenkins.model.Jenkins) TopLevelItem(hudson.model.TopLevelItem) Restricted(org.kohsuke.accmod.Restricted) CheckForNull(javax.annotation.CheckForNull)

Aggregations

CheckForNull (javax.annotation.CheckForNull)149 IOException (java.io.IOException)18 Tree (org.apache.jackrabbit.oak.api.Tree)16 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)12 ArrayList (java.util.ArrayList)9 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)9 Stopwatch (com.google.common.base.Stopwatch)8 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)8 Date (java.util.Date)7 SnapshotDto (org.sonar.db.component.SnapshotDto)7 Period (org.sonar.server.computation.task.projectanalysis.period.Period)7 File (java.io.File)6 SQLException (java.sql.SQLException)6 DocumentStoreException (org.apache.jackrabbit.oak.plugins.document.DocumentStoreException)6 ExecutionException (java.util.concurrent.ExecutionException)5 ValidationModel (org.apache.sling.validation.model.ValidationModel)5 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)4 Root (org.apache.jackrabbit.oak.api.Root)4 Utils.resolveCommitRevision (org.apache.jackrabbit.oak.plugins.document.util.Utils.resolveCommitRevision)4 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)4