javax.annotation.CheckForNull Java Examples

The following examples show how to use javax.annotation.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: ServiceConfigInterceptor.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@CheckForNull
private MethodInfo getMethodInfo(MethodDescriptor<?, ?> method) {
  Map<String, MethodInfo> localServiceMethodMap = serviceMethodMap.get();
  MethodInfo info = null;
  if (localServiceMethodMap != null) {
    info = localServiceMethodMap.get(method.getFullMethodName());
  }
  if (info == null) {
    Map<String, MethodInfo> localServiceMap = serviceMap.get();
    if (localServiceMap != null) {
      info = localServiceMap.get(
          MethodDescriptor.extractFullServiceName(method.getFullMethodName()));
    }
  }
  return info;
}
 
Example #2
Source File: AnyBranchBuildStrategyImpl.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(strategies.isEmpty()){
        return false;
    }

    for (BranchBuildStrategy strategy: strategies) {
        if(strategy.automaticBuild(
            source,
            head,
            currRevision,
            lastBuiltRevision,
            lastSeenRevision,
            taskListener
        )){
            return true;
        };

    }
    return false;
}
 
Example #3
Source File: AllBranchBuildStrategyImpl.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(strategies.isEmpty()){
        return false;
    }

    for (BranchBuildStrategy strategy: strategies) {
        if(!strategy.automaticBuild(
            source,
            head,
            currRevision,
            lastBuiltRevision,
            lastSeenRevision,
            taskListener
        )){
            return false;
        };

    }
    return true;
}
 
Example #4
Source File: SourceActions.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 6 votes vote down vote up
@Nonnull
private List<Action> retrieve(@Nonnull SCMRevisionImpl revision, @CheckForNull SCMHeadEvent event, @Nonnull TaskListener listener) throws IOException, InterruptedException {
    List<Action> actions = new ArrayList<>();

    String hash = revision.getHash();
    Action linkAction = GitLabLinkAction.toCommit(source.getProject(), hash);
    actions.add(linkAction);

    SCMHead head = revision.getHead();
    if (head instanceof GitLabSCMMergeRequestHead) {
        actions.add(createHeadMetadataAction(head.getName(), ((GitLabSCMMergeRequestHead) head).getSource(), hash, linkAction.getUrlName()));
    } else if (head instanceof GitLabSCMHead) {
        actions.add(createHeadMetadataAction(head.getName(), (GitLabSCMHead) head, hash, linkAction.getUrlName()));
    }

    if (event instanceof GitLabSCMEvent) {
        actions.add(new GitLabSCMCauseAction(((GitLabSCMEvent) event).getCause()));
    }

    return actions;
}
 
Example #5
Source File: NoneBranchBuildStrategyImpl.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(strategies.isEmpty()){
        return false;
    }

    for (BranchBuildStrategy strategy: strategies) {
        if(strategy.automaticBuild(
            source,
            head,
            currRevision,
            lastBuiltRevision,
            lastSeenRevision,
            taskListener
        )){
            return false;
        };

    }
    return true;
}
 
Example #6
Source File: CustomSectionGenerator.java    From simple-pull-request-job-plugin with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public List<String> toPipeline(@CheckForNull CustomPipelineSection section)
        throws ConversionException {
    if (section == null) {
        return Collections.emptyList();
    }

    PipelineGenerator gen = PipelineGenerator.lookupForName(section.getName());
    if (gen == null) {
        throw new ConversionException("No converter for Custom Pipeline Section: " + section.getName());
    }
    return gen.toPipeline(section.getData());
}
 
Example #7
Source File: KafkaKubernetesCloud.java    From remoting-kafka-plugin with MIT License 5 votes vote down vote up
public Set<String> getNodesInProvisioning(@CheckForNull Label label) {
    if (label == null) return Collections.emptySet();
    return label.getNodes().stream()
            .filter(KafkaCloudSlave.class::isInstance)
            .filter(node -> {
                Computer computer = node.toComputer();
                return computer != null && !computer.isOnline();
            })
            .map(Node::getNodeName)
            .collect(Collectors.toSet());
}
 
Example #8
Source File: CustomSectionGeneratorTest.java    From simple-pull-request-job-plugin with Apache License 2.0 5 votes vote down vote up
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
@Nonnull
@Override
public List<String> toPipeline(@CheckForNull Object object) throws ConversionException {
    if (object == null) {
        throw new ConversionException("No data");
    }
    HashMap<String, String> data = (HashMap<String, String>)object;
    return Collections.singletonList("foo('" + data.get("field1") +"','" + data.get("field2") + "')");
}
 
Example #9
Source File: NoneBranchBuildStrategyImpl.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 #10
Source File: PipelineGenerator.java    From simple-pull-request-job-plugin with Apache License 2.0 5 votes vote down vote up
@CheckForNull
public static <T extends PipelineGenerator> T lookupConverter(Class<T> clazz) {
    for (PipelineGenerator gen : all()) {
        if (clazz.equals(gen.getClass())) {
            return clazz.cast(gen);
        }
    }
    return null;
}
 
Example #11
Source File: NoneBranchBuildStrategyImpl.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 #12
Source File: BranchBuildStrategyImpl.java    From basic-branch-build-strategies-plugin with MIT License 5 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;
    }
    return true;
}
 
Example #13
Source File: GitLabLinkAction.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Nonnull
public static GitLabLinkAction create(@CheckForNull String displayName, @Nonnull String iconFileName, @Nonnull String url) {
    if (displayName == null) {
        return create("", iconFileName, url);
    }
    
    return new GitLabLinkAction(displayName, iconFileName, url);
}
 
Example #14
Source File: AnyBranchBuildStrategyImpl.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 #15
Source File: SourceActions.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Nonnull
List<Action> retrieve(@Nonnull SCMHead head, @CheckForNull SCMHeadEvent event, @Nonnull TaskListener listener) throws IOException, InterruptedException {
    if (head instanceof GitLabSCMHead) {
        return retrieve((GitLabSCMHead) head, event, listener);
    }

    return emptyList();
}
 
Example #16
Source File: GerritSCMSource.java    From gerrit-code-review-plugin with Apache License 2.0 5 votes vote down vote up
@Restricted(DoNotUse.class)
@DataBoundSetter
public void setExtensions(@CheckForNull List<GitSCMExtension> extensions) {
  List<SCMSourceTrait> traits = new ArrayList<>(this.traits);
  for (Iterator<SCMSourceTrait> iterator = traits.iterator(); iterator.hasNext(); ) {
    if (iterator.next() instanceof GitSCMExtensionTrait) {
      iterator.remove();
    }
  }
  EXTENSIONS:
  for (GitSCMExtension extension : Util.fixNull(extensions)) {
    for (SCMSourceTraitDescriptor d : SCMSourceTrait.all()) {
      if (d instanceof GitSCMExtensionTraitDescriptor) {
        GitSCMExtensionTraitDescriptor descriptor = (GitSCMExtensionTraitDescriptor) d;
        if (descriptor.getExtensionClass().isInstance(extension)) {
          try {
            SCMSourceTrait trait = descriptor.convertToTrait(extension);
            if (trait != null) {
              traits.add(trait);
              continue EXTENSIONS;
            }
          } catch (UnsupportedOperationException e) {
            LOGGER.log(
                Level.WARNING,
                "Could not convert " + extension.getClass().getName() + " to a trait",
                e);
          }
        }
      }
      LOGGER.log(
          Level.FINE,
          "Could not convert {0} to a trait (likely because this option does not "
              + "make sense for a GitSCMSource)",
          extension.getClass().getName());
    }
  }
  setTraits(traits);
}
 
Example #17
Source File: GlobalKafkaConfiguration.java    From remoting-kafka-plugin with MIT License 5 votes vote down vote up
@CheckForNull
private StandardUsernamePasswordCredentials getCredential(@Nonnull String id) {
    StandardUsernamePasswordCredentials credential = null;
    List<StandardUsernamePasswordCredentials> credentials = CredentialsProvider.lookupCredentials(
            StandardUsernamePasswordCredentials.class, Jenkins.get(), ACL.SYSTEM, Collections.emptyList());
    IdMatcher matcher = new IdMatcher(id);
    for (StandardUsernamePasswordCredentials c : credentials) {
        if (matcher.matches(c)) {
            credential = c;
        }
    }
    return credential;
}
 
Example #18
Source File: KubernetesFactoryAdapter.java    From remoting-kafka-plugin with MIT License 5 votes vote down vote up
public KubernetesFactoryAdapter(String serviceAddress, String namespace, @CheckForNull String caCertData,
                                @CheckForNull String credentials, boolean skipTlsVerify, int connectTimeout, int readTimeout, int maxRequestsPerHost) {
    this.serviceAddress = serviceAddress;
    this.namespace = namespace;
    this.caCertData = caCertData;
    this.credentials = credentials != null ? getCredentials(credentials) : null;
    this.skipTlsVerify = skipTlsVerify;
    this.connectTimeout = connectTimeout;
    this.readTimeout = readTimeout;
    this.maxRequestsPerHost = maxRequestsPerHost;
}
 
Example #19
Source File: SourceActions.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Nonnull
List<Action> retrieve(@Nonnull SCMRevision revision, @CheckForNull SCMHeadEvent event, @Nonnull TaskListener listener) throws IOException, InterruptedException {
    if (revision instanceof SCMRevisionImpl) {
        return retrieve((SCMRevisionImpl) revision, event, listener);
    }

    return emptyList();
}
 
Example #20
Source File: BTree.java    From btree4j with Apache License 2.0 5 votes vote down vote up
private final BTreeNode createBTreeNode(BTreeRootInfo root, byte status,
        @CheckForNull BTreeNode parent) throws BTreeException {
    if (parent == null) {
        throw new IllegalArgumentException();
    }
    Page p = getFreePage();
    BTreeNode node = new BTreeNode(root, p, parent);
    //node.set(new Value[0], new long[0]);
    node.ph.setStatus(status);
    synchronized (_cache) {
        _cache.put(p.getPageNum(), node);
    }
    return node;
}
 
Example #21
Source File: SecretSourceResolver.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
/**
 * Encodes String so that it can be safely represented in the YAML after export.
 * @param toEncode String to encode
 * @return Encoded string
 * @since 1.25
 */
public static String encode(@CheckForNull String toEncode) {
    if (toEncode == null) {
        return null;
    }
    return toEncode.replace("${", "^${");
}
 
Example #22
Source File: GuavaCacheMetricsCompatibilityKit.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@CheckForNull
@Override
public String load(@Nonnull String key) throws Exception {
    String val = loadValue.getAndSet(null);
    if (val == null)
        throw new Exception("don't load this key");
    return val;
}
 
Example #23
Source File: GithubBuildStatusGraphListener.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
private static @CheckForNull BuildStatusAction buildStatusActionFor(FlowExecution exec) {
    BuildStatusAction buildStatusAction = null;
    Run<?, ?> run = runFor(exec);
    if (run != null) {
        buildStatusAction = run.getAction(BuildStatusAction.class);
    }
    return buildStatusAction;
}
 
Example #24
Source File: GithubBuildStatusGraphListener.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
/**
 * Gets the jenkins run object of the specified executing workflow.
 *
 * @param exec execution of a workflow
 * @return jenkins run object of a job
 */
private static @CheckForNull Run<?, ?> runFor(FlowExecution exec) {
    Queue.Executable executable;
    try {
        executable = exec.getOwner().getExecutable();
    } catch (IOException x) {
        getLogger().log(Level.WARNING, null, x);
        return null;
    }
    if (executable instanceof Run) {
        return (Run<?, ?>) executable;
    } else {
        return null;
    }
}
 
Example #25
Source File: InfluxDbNotifierConfig.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
/**
 * Returns the credentials for calling InfluxDB if they are configured.
 *
 * @return the credentials; null if not provided.
 */
@CheckForNull
public UsernamePasswordCredentials getCredentials() {
    return !StringUtils.isEmpty(influxDbCredentialsId) ?
            BuildStatusConfig.getCredentials(UsernamePasswordCredentials.class,
                    influxDbCredentialsId) :
            null;
}
 
Example #26
Source File: HttpNotifierConfig.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
/**
 * Returns credentials for accessing the HTTP endpoint if they are configured.
 *
 * @return credentials; null if not provided
 */
@CheckForNull
public UsernamePasswordCredentials getCredentials() {
    return !Strings.isNullOrEmpty(httpCredentialsId) ?
            BuildStatusConfig.getCredentials(UsernamePasswordCredentials.class,
                    httpCredentialsId) :
            null;
}
 
Example #27
Source File: StringUtils.java    From aws-codecommit-trigger-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Find and return value of uniqueKey in jsonString
 *
 * @param jsonString json string, can not null
 * @param uniqueKey  unique key in jsonString, can not null
 * @return value of <code>jsonString.uniqueKey</code>, or <code>null</code>  if not found
 */
@CheckForNull
public static String findByUniqueJsonKey(String jsonString, String uniqueKey) {
    jsonString = jsonString.trim();
    uniqueKey = uniqueKey.trim();

    String regex = String.format("\"%s\"\\s*:\\s*[^\"]*\"([^\"]+)\"", uniqueKey);
    Pattern p = Pattern.compile(regex);
    Matcher matcher = p.matcher(jsonString);
    String value = null;
    if (matcher.find() && matcher.groupCount() > 0) {
        value = matcher.group(1);
    }
    return value;
}
 
Example #28
Source File: SQSTriggerQueue.java    From aws-codecommit-trigger-plugin with Apache License 2.0 5 votes vote down vote up
@CheckForNull
@Override
public AmazonWebServicesCredentials lookupAwsCredentials() {
    if (this.credentialsId == null) {
        return null;
    }
    return AwsCredentialsHelper.getCredentials(this.credentialsId);
}
 
Example #29
Source File: SourceHeads.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 5 votes vote down vote up
@CheckForNull
SCMRevision retrieve(@Nonnull SCMHead head, @Nonnull TaskListener listener) throws IOException, InterruptedException {
    log(listener, Messages.GitLabSCMSource_retrievingRevision(head.getName()));
    try {
        return new SCMRevisionImpl(head, retrieveRevision(head));
    } catch (NoSuchElementException e) {
        return null;
    }
}
 
Example #30
Source File: AwsCredentialsHelper.java    From aws-codecommit-trigger-plugin with Apache License 2.0 5 votes vote down vote up
@CheckForNull
public static <T extends Credentials> T getCredentials(Class<T> clz, @Nullable String credentialsId) {
    if (StringUtils.isBlank(credentialsId)) {
        return null;
    }

    return CredentialsMatchers.firstOrNull(
        CredentialsProvider.lookupCredentials(clz, (Item) null, ACL.SYSTEM, null, null),
        CredentialsMatchers.withId(credentialsId)
    );
}