edu.umd.cs.findbugs.annotations.CheckForNull Java Examples

The following examples show how to use edu.umd.cs.findbugs.annotations.CheckForNull. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NamedBranchBuildStrategyImpl.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean isAutomaticBuild(@NonNull SCMSource source, @NonNull SCMHead head, @NonNull SCMRevision currRevision,
                                @CheckForNull SCMRevision lastBuiltRevision, @CheckForNull SCMRevision lastSeenRevision, @NonNull TaskListener taskListener) {
    if (head instanceof ChangeRequestSCMHead) {
        return false;
    }
    if (head instanceof TagSCMHead) {
        return false;
    }
    String name = head.getName();
    for (NameFilter filter: filters) {
        if (filter.isMatch(name)) {
            return true;
        }
    }
    return false;
}
 
Example #2
Source File: GiteaServers.java    From gitea-plugin with MIT License 6 votes vote down vote up
/**
 * Sets the list of endpoints.
 *
 * @param servers the list of endpoints.
 */
public synchronized void setServers(@CheckForNull List<? extends GiteaServer> servers) {
    Jenkins.get().checkPermission(Jenkins.ADMINISTER);
    List<GiteaServer> eps = new ArrayList<>(Util.fixNull(servers));
    // remove duplicates and empty urls
    Set<String> serverUrls = new HashSet<>();
    for (ListIterator<GiteaServer> iterator = eps.listIterator(); iterator.hasNext(); ) {
        GiteaServer endpoint = iterator.next();
        String serverUrl = endpoint.getServerUrl();
        if (StringUtils.isBlank(serverUrl) || serverUrls.contains(serverUrl)) {
            iterator.remove();
            continue;
        }
        serverUrls.add(serverUrl);
    }
    this.servers = eps;
    save();
}
 
Example #3
Source File: PrimitiveConfigurator.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@CheckForNull
@Override
public CNode describe(Object instance, ConfigurationContext context) {

    if (instance == null) return null;

    if (instance instanceof Number) {
        return new Scalar((Number) instance);
    }
    if (instance instanceof Boolean) {
        return new Scalar((Boolean) instance);
    }
    if (instance instanceof Secret) {
        // Secrets are sensitive, but they do not need masking since they are exported in the encrypted form
        return new Scalar(((Secret) instance).getEncryptedValue()).encrypted(true);
    }
    if (target.isEnum()) {
        return new Scalar((Enum) instance);
    }

    return new Scalar(SecretSourceResolver.encode(String.valueOf(instance)));
}
 
Example #4
Source File: GiteaServer.java    From gitea-plugin with MIT License 6 votes vote down vote up
/**
 * Looks up the {@link StandardCredentials} to use for auto-management of hooks.
 *
 * @return the credentials or {@code null}.
 */
@CheckForNull
public StandardCredentials credentials() {
    return StringUtils.isBlank(credentialsId) ? null : CredentialsMatchers.firstOrNull(
            CredentialsProvider.lookupCredentials(
                    StandardCredentials.class,
                    Jenkins.get(),
                    ACL.SYSTEM,
                    URIRequirementBuilder.fromUri(serverUrl).build()
            ),
            CredentialsMatchers.allOf(
                    AuthenticationTokens.matcher(GiteaAuth.class),
                    CredentialsMatchers.withId(credentialsId)
            )
    );
}
 
Example #5
Source File: GiteaSCMFileSystem.java    From gitea-plugin with MIT License 6 votes vote down vote up
protected GiteaSCMFileSystem(GiteaConnection connection, GiteaRepository repo, String ref,
                             @CheckForNull SCMRevision rev) throws IOException {
    super(rev);
    this.connection = connection;
    this.repo = repo;
    if (rev != null) {
        if (rev.getHead() instanceof PullRequestSCMHead) {
            this.ref = ((PullRequestSCMRevision) rev).getOrigin().getHash();
        } else if (rev instanceof BranchSCMRevision) {
            this.ref = ((BranchSCMRevision) rev).getHash();
        } else if (rev instanceof TagSCMRevision) {
            this.ref = ((TagSCMRevision) rev).getHash();
        } else {
            this.ref = ref;
        }
    } else {
        this.ref = ref;
    }
}
 
Example #6
Source File: TagBuildStrategyImpl.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean isAutomaticBuild(@NonNull SCMSource source, @NonNull SCMHead head, @NonNull SCMRevision currRevision,
                                @CheckForNull SCMRevision lastBuiltRevision, @CheckForNull SCMRevision lastSeenRevision, @NonNull  TaskListener taskListener) {
    if (!(head instanceof TagSCMHead)) {
        return false;
    }
    if (atLeastMillis >= 0L || atMostMillis >= 0L) {
        if (atMostMillis >= 0L && atLeastMillis > atMostMillis) {
            // stupid configuration that corresponds to never building anything, why did the user add it against
            // our advice?
            return false;
        }
        long tagAge = System.currentTimeMillis() - ((TagSCMHead)head).getTimestamp();
        if (atMostMillis >= 0L && tagAge > atMostMillis) {
            return false;
        }
        if (atLeastMillis >= 0L && tagAge < atLeastMillis) {
            return false;
        }
    }
    return true;
}
 
Example #7
Source File: GlobalConfigurationCategoryConfigurator.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@CheckForNull
@Override
public CNode describe(GlobalConfigurationCategory instance, ConfigurationContext context) {

    final Mapping mapping = new Mapping();
    Jenkins.get().getExtensionList(Descriptor.class).stream()
        .filter(this::filterDescriptors)
        .forEach(d -> describe(d, mapping, context));
    return mapping;
}
 
Example #8
Source File: NamedBranchBuildStrategyImpl.java    From basic-branch-build-strategies-plugin with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Deprecated
@Override
public boolean isAutomaticBuild(@NonNull SCMSource source, @NonNull SCMHead head, @NonNull SCMRevision currRevision,
                                @CheckForNull SCMRevision prevRevision, @NonNull TaskListener taskListener) {
    return isAutomaticBuild(source,head, currRevision, prevRevision, prevRevision, taskListener);
}
 
Example #9
Source File: NamedBranchBuildStrategyImpl.java    From basic-branch-build-strategies-plugin with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Deprecated
@Override
public boolean isAutomaticBuild(@NonNull SCMSource source, @NonNull SCMHead head, @NonNull SCMRevision currRevision,
                                @CheckForNull SCMRevision prevRevision) {
    return isAutomaticBuild(source, head, currRevision, prevRevision, new LogTaskListener(Logger.getLogger(getClass().getName()), Level.INFO));
}
 
Example #10
Source File: GitLabSCMSourceBuilder.java    From gitlab-branch-source-plugin with MIT License 5 votes vote down vote up
public GitLabSCMSourceBuilder(@CheckForNull String id, @CheckForNull String serverName,
    @CheckForNull String credentialsId, @NonNull String projectOwner,
    @NonNull String projectPath, @NonNull String projectName) {
    super(GitLabSCMSource.class, projectName);
    this.id = id;
    this.serverName = serverName;
    this.credentialsId = credentialsId;
    this.projectOwner = projectOwner;
    this.projectPath = projectPath;
    this.projectName = projectName;
}
 
Example #11
Source File: TagBuildStrategyImpl.java    From basic-branch-build-strategies-plugin with MIT License 5 votes vote down vote up
/**
 * Our constructor.
 *
 * @param atLeastDays the number of days old that the tag must be before it is considered for automatic build
 * @param atMostDays the number of days old that the tag must be after which it is no longer considered for automatic build.
 */
@DataBoundConstructor
public TagBuildStrategyImpl(@CheckForNull String atLeastDays, @CheckForNull String atMostDays) {
    this(
            TimeUnit.DAYS,
            Long.parseLong(StringUtils.defaultIfBlank(atLeastDays, "-1")),
            Long.parseLong(StringUtils.defaultIfBlank(atMostDays, "-1"))
    );
}
 
Example #12
Source File: DefaultConfiguratorRegistry.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@Override
@CheckForNull
public RootElementConfigurator lookupRootElement(String name) {
    for (RootElementConfigurator c : RootElementConfigurator.all()) {
        if (c.getName().equalsIgnoreCase(name)) {
            return c;
        }
    }
    return null;
}
 
Example #13
Source File: GitLabSCMNavigator.java    From gitlab-branch-source-plugin with MIT License 5 votes vote down vote up
/**
 * Sets the behavioural traits that are applied to this navigator and any {@link
 * GitLabSCMSource} instances it discovers. The new traits will take affect on the next
 * navigation through any of the {@link #visitSources(SCMSourceObserver)} overloads or {@link
 * #visitSource(String, SCMSourceObserver)}.
 *
 * @param traits the new behavioural traits.
 */
@DataBoundSetter
public void setTraits(@CheckForNull SCMTrait[] traits) {
    this.traits = new ArrayList<>();
    if (traits != null) {
        for (SCMTrait trait : traits) {
            this.traits.add(trait);
        }
    }
}
 
Example #14
Source File: DefaultConfiguratorRegistry.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
/**
 * Looks for a configurator for exact type.
 * @param type Type
 * @return Configurator or {@code null} if it is not found
 */
@Override
@CheckForNull
public Configurator lookup(Type type) {
    try {
        return cache.get(type);
    } catch (ExecutionException e) {
        return null;
    }
}
 
Example #15
Source File: SSHCheckoutTrait.java    From gitlab-branch-source-plugin with MIT License 5 votes vote down vote up
@Restricted(NoExternalUse.class)
@SuppressWarnings("unused") // stapler form binding
public ListBoxModel doFillCredentialsIdItems(@CheckForNull @AncestorInPath Item context,
    @QueryParameter String serverUrl,
    @QueryParameter String credentialsId) {
    StandardListBoxModel result = new StandardListBoxModel();
    if (context == null) {
        if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
            // must have admin if you want the list without a context
            result.includeCurrentValue(credentialsId);
            return result;
        }
    } else {
        if (!context.hasPermission(Item.EXTENDED_READ)
            && !context.hasPermission(CredentialsProvider.USE_ITEM)) {
            // must be able to read the configuration or use the item credentials if you want the list
            result.includeCurrentValue(credentialsId);
            return result;
        }
    }
    result.includeEmptyValue();
    result.includeMatchingAs(
        context instanceof Queue.Task
            ? ((Queue.Task) context).getDefaultAuthentication()
            : ACL.SYSTEM,
        context,
        StandardUsernameCredentials.class,
        URIRequirementBuilder.fromUri(serverUrl).build(),
        CredentialsMatchers.instanceOf(SSHUserPrivateKey.class)
    );
    return result;
}
 
Example #16
Source File: GitLabSCMFileSystem.java    From gitlab-branch-source-plugin with MIT License 5 votes vote down vote up
public SCMFileSystem build(@NonNull SCMHead head, @CheckForNull SCMRevision rev,
    @NonNull GitLabApi gitLabApi, @NonNull String projectPath)
    throws IOException, InterruptedException {
    String ref;
    if (head instanceof MergeRequestSCMHead) {
        ref = ((MergeRequestSCMHead) head).getOriginName();
    } else if (head instanceof BranchSCMHead) {
        ref = head.getName();
    } else if (head instanceof GitLabTagSCMHead) {
        ref = head.getName();
    } else {
        return null;
    }
    return new GitLabSCMFileSystem(gitLabApi, projectPath, ref, rev);
}
 
Example #17
Source File: GitLabServers.java    From gitlab-branch-source-plugin with MIT License 5 votes vote down vote up
/**
 * Checks to see if the supplied server URL is defined in the global configuration.
 *
 * @param serverName the server url to check.
 * @return the global configuration for the specified server url or {@code null} if not defined.
 */
@CheckForNull
public GitLabServer findServer(@CheckForNull String serverName) {
    List<GitLabServer> servers = new ArrayList<>(getServers());
    return servers.stream()
        .filter(server -> server.getName().equals(serverName))
        .findAny()
        .orElse(null);
}
 
Example #18
Source File: GitLabServers.java    From gitlab-branch-source-plugin with MIT License 5 votes vote down vote up
/**
 * Sets the list of GitLab Servers
 *
 * @param servers the list of endpoints.
 */
public void setServers(@CheckForNull List<? extends GitLabServer> servers) {
    Jenkins.get().checkPermission(Jenkins.ADMINISTER);
    this.servers = fixNull(servers).stream()
        .filter(distinctByKey(GitLabServer::getName)).collect(Collectors.toList());
    save();
}
 
Example #19
Source File: GiteaServer.java    From gitea-plugin with MIT License 5 votes vote down vote up
/**
 * Constructor
 *
 * @param displayName   Optional name to use to describe the end-point.
 * @param serverUrl     The URL of this Gitea Server
 * @param manageHooks   {@code true} if and only if Jenkins is supposed to auto-manage hooks for this end-point.
 * @param credentialsId The {@link StandardUsernamePasswordCredentials#getId()} of the credentials to use for
 *                      auto-management of hooks.
 * @param aliasUrl      The URL this Gitea Server thinks it is at.
 * @since 1.0.5
 */
@DataBoundConstructor
public GiteaServer(@CheckForNull String displayName, @NonNull String serverUrl, boolean manageHooks,
                   @CheckForNull String credentialsId, @CheckForNull String aliasUrl) {
    this.manageHooks = manageHooks && StringUtils.isNotBlank(credentialsId);
    this.credentialsId = manageHooks ? credentialsId : null;
    this.serverUrl = GiteaServers.normalizeServerUrl(serverUrl);
    this.displayName = StringUtils.isBlank(displayName)
            ? SCMName.fromUrl(this.serverUrl, COMMON_PREFIX_HOSTNAMES)
            : displayName;
    this.aliasUrl = StringUtils.trimToNull(GiteaServers.normalizeServerUrl(aliasUrl));
}
 
Example #20
Source File: TagBuildStrategyImpl.java    From basic-branch-build-strategies-plugin with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Deprecated
@Override
public boolean isAutomaticBuild(@NonNull SCMSource source, @NonNull SCMHead head, @NonNull SCMRevision currRevision,
                                @CheckForNull SCMRevision prevRevision) {
    return isAutomaticBuild(source, head, currRevision, prevRevision, new LogTaskListener(Logger.getLogger(getClass().getName()), Level.INFO));
}
 
Example #21
Source File: TagBuildStrategyImpl.java    From basic-branch-build-strategies-plugin with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Deprecated
@Override
public boolean isAutomaticBuild(@NonNull SCMSource source, @NonNull SCMHead head, @NonNull SCMRevision currRevision,
                                @CheckForNull SCMRevision prevRevision, @NonNull  TaskListener taskListener) {
    return isAutomaticBuild(source,head, currRevision, prevRevision, prevRevision, taskListener);
}
 
Example #22
Source File: ChangeRequestBuildStrategyImpl.java    From basic-branch-build-strategies-plugin with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Deprecated
@Override
public boolean isAutomaticBuild(@NonNull SCMSource source, @NonNull SCMHead head, @NonNull SCMRevision currRevision,
                                @CheckForNull SCMRevision prevRevision) {
    return isAutomaticBuild(source, head, currRevision, prevRevision, new LogTaskListener(Logger.getLogger(getClass().getName()), Level.INFO));
}
 
Example #23
Source File: ChangeRequestBuildStrategyImpl.java    From basic-branch-build-strategies-plugin with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Restricted(ProtectedExternally.class)
@Deprecated
@Override
public boolean isAutomaticBuild(@NonNull SCMSource source, @NonNull SCMHead head, @NonNull SCMRevision currRevision,
                                @CheckForNull SCMRevision prevRevision, @NonNull TaskListener taskListener) {
    return isAutomaticBuild(source,head, currRevision, prevRevision, prevRevision, taskListener);
}
 
Example #24
Source File: ChangeRequestBuildStrategyImpl.java    From basic-branch-build-strategies-plugin with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Restricted(ProtectedExternally.class)
@Override
public boolean isAutomaticBuild(@NonNull SCMSource source, @NonNull SCMHead head, @NonNull SCMRevision currRevision,
                                @CheckForNull SCMRevision lastBuiltRevision, @CheckForNull SCMRevision lastSeenRevision, @NonNull TaskListener listener) {
    if (!(head instanceof ChangeRequestSCMHead)) {
        return false;
    }
    if (ignoreTargetOnlyChanges
            && currRevision instanceof ChangeRequestSCMRevision
            && lastBuiltRevision instanceof ChangeRequestSCMRevision) {
        ChangeRequestSCMRevision<?> curr = (ChangeRequestSCMRevision<?>) currRevision;
        if (curr.isMerge() && curr.equivalent((ChangeRequestSCMRevision<?>) lastBuiltRevision)) {
            return false;
        }
    }
    try {
        if (ignoreUntrustedChanges && !currRevision.equals(source.getTrustedRevision(currRevision, listener))) {
            return false;
        }
    } catch (IOException | InterruptedException e) {
        LogRecord lr = new LogRecord(Level.WARNING,
                "Could not determine trust status for revision {0} of {1}, assuming untrusted");
        lr.setParameters(new Object[] {currRevision, head});
        lr.setThrown(e);
        Functions.printLogRecord(lr);
        return false;
    }
    return true;
}
 
Example #25
Source File: GiteaServers.java    From gitea-plugin with MIT License 5 votes vote down vote up
/**
 * Removes an endpoint.
 *
 * @param serverUrl the server URL to remove.
 * @return {@code true} if the list of endpoints was modified
 */
public synchronized boolean removeServer(@CheckForNull String serverUrl) {
    serverUrl = normalizeServerUrl(serverUrl);
    boolean modified = false;
    List<GiteaServer> endpoints = new ArrayList<>(getServers());
    for (Iterator<GiteaServer> iterator = endpoints.iterator(); iterator.hasNext(); ) {
        if (serverUrl.equals(iterator.next().getServerUrl())) {
            iterator.remove();
            modified = true;
        }
    }
    setServers(endpoints);
    return modified;
}
 
Example #26
Source File: SSHCheckoutTrait.java    From gitea-plugin with MIT License 5 votes vote down vote up
@Restricted(NoExternalUse.class)
@SuppressWarnings("unused") // stapler form binding
public ListBoxModel doFillCredentialsIdItems(@CheckForNull @AncestorInPath Item context,
                                             @QueryParameter String serverUrl,
                                             @QueryParameter String credentialsId) {
    StandardListBoxModel result = new StandardListBoxModel();
    if (context == null) {
        if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
            // must have admin if you want the list without a context
            result.includeCurrentValue(credentialsId);
            return result;
        }
    } else {
        if (!context.hasPermission(Item.EXTENDED_READ)
                && !context.hasPermission(CredentialsProvider.USE_ITEM)) {
            // must be able to read the configuration or use the item credentials if you want the list
            result.includeCurrentValue(credentialsId);
            return result;
        }
    }
    result.add(Messages.SSHCheckoutTrait_useAgentKey(), "");
    result.includeMatchingAs(
            context instanceof Queue.Task ?
                    ((Queue.Task) context).getDefaultAuthentication()
                    : ACL.SYSTEM,
            context,
            StandardUsernameCredentials.class,
            URIRequirementBuilder.fromUri(serverUrl).build(),
            CredentialsMatchers.instanceOf(SSHUserPrivateKey.class)
    );
    return result;
}
 
Example #27
Source File: GiteaSCMBuilder.java    From gitea-plugin with MIT License 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param source   the {@link GiteaSCMSource}.
 * @param head     the {@link SCMHead}
 * @param revision the (optional) {@link SCMRevision}
 */
public GiteaSCMBuilder(@NonNull GiteaSCMSource source,
                       @NonNull SCMHead head, @CheckForNull SCMRevision revision) {
    super(
            head,
            revision,
            checkoutUriTemplate(null, source.getServerUrl(), null, null)
                    .set("owner", source.getRepoOwner())
                    .set("repository", source.getRepository())
                    .expand(),
            source.getCredentialsId()
    );
    this.context = source.getOwner();
    serverUrl = source.getServerUrl();
    repoOwner = source.getRepoOwner();
    repository = source.getRepository();
    sshRemote = source.getSshRemote();
    // now configure the ref specs
    withoutRefSpecs();
    String repoUrl;
    if (head instanceof PullRequestSCMHead) {
        PullRequestSCMHead h = (PullRequestSCMHead) head;
        withRefSpec("+refs/pull/" + h.getId() + "/head:refs/remotes/@{remote}/" + head
                .getName());
        repoUrl = repositoryUrl(h.getOriginOwner(), h.getOriginRepository());
    } else if (head instanceof TagSCMHead) {
        withRefSpec("+refs/tags/" + head.getName() + ":refs/tags/@{remote}/" + head.getName());
        repoUrl = repositoryUrl(repoOwner, repository);
    } else {
        withRefSpec("+refs/heads/" + head.getName() + ":refs/remotes/@{remote}/" + head.getName());
        repoUrl = repositoryUrl(repoOwner, repository);
    }
    // pre-configure the browser
    withBrowser(new GiteaBrowser(repoUrl));
}
 
Example #28
Source File: GiteaServers.java    From gitea-plugin with MIT License 5 votes vote down vote up
/**
 * Checks to see if the supplied server URL is defined in the global configuration.
 *
 * @param serverUrl the server url to check.
 * @return the global configuration for the specified server url or {@code null} if not defined.
 */
@CheckForNull
public synchronized GiteaServer findServer(@CheckForNull String serverUrl) {
    serverUrl = normalizeServerUrl(serverUrl);
    for (GiteaServer endpoint : getServers()) {
        if (serverUrl.equals(endpoint.getServerUrl())) {
            return endpoint;
        }
    }
    return null;
}
 
Example #29
Source File: Configurator.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
/**
 * Describe a component as a Configuration Nodes {@link CNode} to be exported as yaml.
 * Only export attributes which are <b>not</b> set to default value.
 */
@CheckForNull
default CNode describe(T instance, ConfigurationContext context) throws Exception {
    Mapping mapping = new Mapping();
    for (Attribute attribute : getAttributes()) {
        CNode value = attribute.describe(instance, context);
        if (value != null) {
            mapping.put(attribute.getName(), value);
        }
    }
    return mapping;
}
 
Example #30
Source File: PermissionFinder.java    From folder-auth-plugin with MIT License 5 votes vote down vote up
/**
 * Attempt to match a given permission to what is defined in the UI.
 * @param id String of the form "Title/Permission" (Look in the UI) for a particular permission
 * @return a matched permission
 */
@CheckForNull
public static Permission findPermission(String id) {
    if (id.contains("/")) {
        final String resolvedId = findPermissionId(id);
        return resolvedId != null ? Permission.fromId(resolvedId) : null;
    } else {
        return Permission.fromId(id);
    }
}