下面列出了怎么用javax.annotation.CheckForNull的API类实例代码及写法,或者点击链接到github查看源代码。
@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;
}
@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;
}
/**
* {@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;
}
/**
* {@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;
}
/**
* {@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;
}
private void retrieveTags(@CheckForNull SCMSourceCriteria criteria, @Nonnull SCMHeadObserver observer, @Nonnull TaskListener listener) throws IOException, InterruptedException {
if (source.getSourceSettings().getTagMonitorStrategy().getMonitored()) {
log(listener, Messages.GitLabSCMSource_retrievingTags());
for (GitlabTag tag : api().getTags(source.getProjectId())) {
checkInterrupt();
observe(criteria, observer, tag, listener);
}
}
}
@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);
}
@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;
}
@Nonnull
public static List<String> convert(@Nonnull String converterName, @CheckForNull Object object) throws ConversionException {
PipelineGenerator gen = lookupForName(converterName);
if (gen == null) {
// TODO: add better diagnostics (field matching)
throw new ConversionException("Cannot find converter for the type: " + converterName);
}
//TODO: handle raw type conversion risks
return gen.toPipeline(object);
}
@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());
}
@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") + "')");
}
/**
* {@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));
}
/**
* {@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);
}
/**
* {@inheritDoc}
*/
@Override
public boolean isAutomaticBuild(@NonNull SCMSource source, @NonNull SCMHead head, @NonNull SCMRevision currRevision,
@CheckForNull SCMRevision lastBuiltRevision, @CheckForNull SCMRevision lastSeenRevision, @NonNull TaskListener taskListener) {
if (lastSeenRevision != null) {
return true;
}
return false;
}
private void retrieveBranches(@CheckForNull SCMSourceCriteria criteria, @Nonnull SCMHeadObserver observer, @Nonnull TaskListener listener) throws InterruptedException, IOException {
if (source.getSourceSettings().getBranchMonitorStrategy().getMonitored()) {
log(listener, Messages.GitLabSCMSource_retrievingBranches());
for (GitlabBranch branch : api().getBranches(source.getProjectId())) {
checkInterrupt();
if (!source.isExcluded(branch.getName())) {
observe(criteria, observer, branch, listener);
}
}
}
}
/**
* {@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);
}
/**
* {@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;
}
/**
* {@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);
}
@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();
}
@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);
}
@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;
}
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;
}
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());
}
@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();
}
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;
}
/**
* 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("${", "^${");
}
@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;
}
private static @CheckForNull BuildStatusAction buildStatusActionFor(FlowExecution exec) {
BuildStatusAction buildStatusAction = null;
Run<?, ?> run = runFor(exec);
if (run != null) {
buildStatusAction = run.getAction(BuildStatusAction.class);
}
return buildStatusAction;
}
/**
* 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;
}
}
/**
* 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;
}