jenkins.model.Jenkins.getItem()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(341)

本文整理了Java中jenkins.model.Jenkins.getItem()方法的一些代码示例,展示了Jenkins.getItem()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jenkins.getItem()方法的具体详情如下:
包路径:jenkins.model.Jenkins
类名称:Jenkins
方法名:getItem

Jenkins.getItem介绍

[英]. Note that the look up is case-insensitive.
[中]。请注意,查找不区分大小写。

代码示例

代码示例来源:origin: jenkinsci/jenkins

public final <T extends Item> T getItem(String pathName, ItemGroup context, @Nonnull Class<T> type) {
  Item r = getItem(pathName, context);
  if (type.isInstance(r))
    return type.cast(r);
  return null;
}

代码示例来源:origin: jenkinsci/jenkins

public final Item getItem(String pathName, Item context) {
  return getItem(pathName,context!=null?context.getParent():null);
}

代码示例来源:origin: jenkinsci/jenkins

public final <T extends Item> T getItem(String pathName, Item context, Class<T> type) {
  return getItem(pathName,context!=null?context.getParent():null,type);
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Does the opposite of {@link #toNameList(Collection)}.
 */
public static <T extends Item> List<T> fromNameList(ItemGroup context, @Nonnull String list, @Nonnull Class<T> type) {
  final Jenkins jenkins = Jenkins.getInstance();
  
  List<T> r = new ArrayList<T>();
  if (jenkins == null) {
    return r;
  }
  
  StringTokenizer tokens = new StringTokenizer(list,",");
  while(tokens.hasMoreTokens()) {
    String fullName = tokens.nextToken().trim();
    if (StringUtils.isNotEmpty(fullName)) {
      T item = jenkins.getItem(fullName, context, type);
      if(item!=null)
        r.add(item);
    }
  }
  return r;
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * True if there is no item in Jenkins that has this name
 * @param name The name to test
 * @param currentJobName The name of the job that the user is configuring
 */
boolean isNameUnique(String name, String currentJobName) {
  Item item = getItem(name);
  if(null==item) {
    // the candidate name didn't return any items so the name is unique
    return true;
  }
  else if(item.getName().equals(currentJobName)) {
    // the candidate name returned an item, but the item is the item
    // that the user is configuring so this is ok
    return true;
  }
  else {
    // the candidate name returned an item, so it is not unique
    return false;
  }
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Finds an item whose name (when referenced from the specified context) is closest to the given name.
 * @param <T> the type of item being considered
 * @param type same as {@code T}
 * @param name the supplied name
 * @param context a context to start from (used to compute relative names)
 * @return the closest available item
 * @since 1.538
 */
public static @CheckForNull <T extends Item> T findNearest(Class<T> type, String name, ItemGroup context) {
  List<String> names = new ArrayList<>();
  for (T item: Jenkins.getInstance().allItems(type)) {
    names.add(item.getRelativeNameFrom(context));
  }
  String nearest = EditDistance.findNearest(name, names);
  return Jenkins.getInstance().getItem(nearest, context, type);
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Auto-completion for the "copy from" field in the new job page.
 */
@Restricted(DoNotUse.class)
public AutoCompletionCandidates doAutoCompleteCopyNewItemFrom(@QueryParameter final String value, @AncestorInPath ItemGroup<?> container) {
  AutoCompletionCandidates candidates = AutoCompletionCandidates.ofJobNames(TopLevelItem.class, value, container);
  if (container instanceof DirectlyModifiableTopLevelItemGroup) {
    DirectlyModifiableTopLevelItemGroup modifiableContainer = (DirectlyModifiableTopLevelItemGroup) container;
    Iterator<String> it = candidates.getValues().iterator();
    while (it.hasNext()) {
      TopLevelItem item = Jenkins.getInstance().getItem(it.next(), container, TopLevelItem.class);
      if (item == null) {
        continue; // ?
      }
      if (!modifiableContainer.canAdd(item)) {
        it.remove();
      }
    }
  }
  return candidates;
}

代码示例来源:origin: jenkinsci/jenkins

public FormValidation doCheckUpstreamProjects(@AncestorInPath Job project, @QueryParameter String value) {
  if (!project.hasPermission(Item.CONFIGURE)) {
    return FormValidation.ok();
  }
  StringTokenizer tokens = new StringTokenizer(Util.fixNull(value),",");
  boolean hasProjects = false;
  while(tokens.hasMoreTokens()) {
    String projectName = tokens.nextToken().trim();
    if (StringUtils.isNotBlank(projectName)) {
      Job item = Jenkins.getInstance().getItem(projectName, project, Job.class);
      if (item == null) {
        Job nearest = Items.findNearest(Job.class, projectName, project.getParent());
        String alternative = nearest != null ? nearest.getRelativeNameFrom(project) : "?";
        return FormValidation.error(hudson.tasks.Messages.BuildTrigger_NoSuchProject(projectName, alternative));
      }
      hasProjects = true;
    }
  }
  if (!hasProjects) {
    return FormValidation.error(hudson.tasks.Messages.BuildTrigger_NoProjectSpecified());
  }
  return FormValidation.ok();
}

代码示例来源:origin: jenkinsci/jenkins

String projectName = tokens.nextToken().trim();
if (StringUtils.isNotBlank(projectName)) {
  Item item = Jenkins.getInstance().getItem(projectName,project,Item.class);
  if (item == null) {
    Job<?, ?> nearest = Items.findNearest(Job.class, projectName, project.getParent());

代码示例来源:origin: jenkinsci/jenkins

Item src = Jenkins.getInstance().getItem(from, parent);
if(src==null) {
  if(Util.fixEmpty(from)==null)

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

public final <T extends Item> T getItem(String pathName, ItemGroup context, @Nonnull Class<T> type) {
  Item r = getItem(pathName, context);
  if (type.isInstance(r))
    return type.cast(r);
  return null;
}

代码示例来源:origin: hudson.plugins/project-inheritance

public static InheritanceProject getProjectByName(String name) {
  TopLevelItem item = Jenkins.getInstance().getItem(name);
  if (item instanceof InheritanceProject) {
    return (InheritanceProject) item;
  }
  return null;
}

代码示例来源:origin: org.jenkins-ci.plugins/disk-usage

public static List<String> parseExcludedJobsFromString(String jobs){
  List<String> list = new ArrayList<String>();
  String jobNames[] = jobs.split(",");
  for(String name: jobNames){
    name = name.trim();
    Item item = Jenkins.getInstance().getItem(name);
    if(item!=null && item instanceof AbstractProject)
      list.add(name);
  }
  return list;
}

代码示例来源:origin: Diabol/delivery-pipeline-plugin

public static WorkflowJob getWorkflowJob(String projectName,
                     ItemGroup<? extends TopLevelItem> ownerItemGroup)
    throws PipelineException {
  Jenkins jenkins = JenkinsUtil.getInstance();
  WorkflowJob job = jenkins.getItem(projectName, ownerItemGroup, WorkflowJob.class);
  if (job == null) {
    throw new PipelineException("Could not find project: " + projectName);
  }
  return job;
}

代码示例来源:origin: jenkinsci/cloudbees-folder-plugin

/**
 * {@inheritDoc}
 */
@Override
protected SearchItem get(String key) {
  return Jenkins.get().getItem(key, grp());
}

代码示例来源:origin: org.jenkins-ci.plugins/cloudbees-folder

/**
 * {@inheritDoc}
 */
@Override
protected SearchItem get(String key) {
  return Jenkins.getActiveInstance().getItem(key, grp());
}

代码示例来源:origin: jenkinsci/cloudbees-folder-plugin

@Override
  public void evaluate() throws Throwable {
    TopLevelItem i = r.j.jenkins.getItem("instance");
    assertThat("Item loaded from disk", i, instanceOf(ComputedFolderImpl.class));
    ComputedFolderImpl instance = (ComputedFolderImpl) i;
    checkComputedFolder(instance, 0, ChildNameGeneratorTest.this.inferNormalizerForm());
  }
});

代码示例来源:origin: org.jenkins-ci.plugins/build-pipeline-plugin

@Override
public ProjectGrid build(BuildPipelineView owner) {
  final AbstractProject<?, ?> project = Jenkins.getInstance().getItem(firstJob, 
    owner.getOwnerItemGroup(), AbstractProject.class);            
  if (project != null) {
    this.firstJobLink = project.getUrl();
  } else {
    this.firstJobLink = "";
  }
  return new GridImpl(owner.getOwnerItemGroup(), getFirstJob(owner));
}

代码示例来源:origin: jenkinsci/mercurial-plugin

@Bug(4510)
@LocalData
@Test public void pickingUpAlternativeBrowser() throws Exception {
  FreeStyleProject p = (FreeStyleProject) j.jenkins.getItem("foo");
  MercurialSCM ms = (MercurialSCM) p.getScm();
  final HgBrowser browser = ms.getBrowser();
  assertEquals("wrong url", new URL("http://bitbucket.org/"), browser.getUrl());
  assertTrue("class:" + browser.getClass(), browser instanceof BitBucket);
  j.assertEqualBeans(new BitBucket("http://bitbucket.org/"), browser, "url");
}

代码示例来源:origin: jenkinsci/mercurial-plugin

@Bug(4514)
@LocalData
@Test public void browsersAvailableInDropDown() throws Exception {
  FreeStyleProject p = (FreeStyleProject) j.jenkins.getItem("foo");
  MercurialSCM ms = (MercurialSCM) p.getScm();
  final HgBrowser browser = ms.getBrowser();
  assertEquals("wrong url", new URL("http://bitbucket.org/"), browser.getUrl());
  assertTrue("class:" + browser.getClass(), browser instanceof BitBucket);
  j.assertEqualBeans(new BitBucket("http://bitbucket.org/"), browser, "url");
  final List<Descriptor<RepositoryBrowser<?>>> browserDescriptors = ms.getDescriptor().getBrowserDescriptors();
  assertTrue("Could not find BitBucket in " + browserDescriptors, browserDescriptors.contains(browser.getDescriptor()));
}

相关文章

Jenkins类方法