本文整理了Java中hudson.model.TopLevelItem
类的一些代码示例,展示了TopLevelItem
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TopLevelItem
类的具体详情如下:
包路径:hudson.model.TopLevelItem
类名称:TopLevelItem
[英]Item that can be directly displayed under jenkins.model.Jenkins or other containers. (A "container" would be any ItemGroup , such as a folder of projects.) Ones that don't need to be under specific parent (say, unlike MatrixConfiguration), and thus can be freely moved, copied, etc.
To register a custom TopLevelItem class from a plugin, put Extension on your TopLevelItemDescriptor. Also see Items#XSTREAM.
[中]可以直接显示在jenkins下的项目。模型詹金斯或其他容器。(容器可以是任何项目组,例如项目文件夹。)不需要位于特定父项下(例如,与MatrixConfiguration不同),因此可以自由移动、复制等的。
要从插件注册自定义TopLevelItem类,请在TopLevelItemDescriptor上添加扩展名。另请参见项目#XSTREAM。
代码示例来源:origin: jenkinsci/jenkins
protected int run() throws Exception {
Jenkins h = Jenkins.getActiveInstance();
final Collection<TopLevelItem> jobs;
View view = h.getView(name);
final Item item = h.getItemByFullName(name);
stdout.println(item.getName());
代码示例来源:origin: jenkinsci/jenkins
/**
* Overwrites the existing item by new one.
*
* <p>
* This is a short cut for deleting an existing job and adding a new one.
*/
public synchronized void putItem(TopLevelItem item) throws IOException, InterruptedException {
String name = item.getName();
TopLevelItem old = items.get(name);
if (old ==item) return; // noop
checkPermission(Item.CREATE);
if (old!=null)
old.delete();
items.put(name,item);
ItemListener.fireOnCreated(item);
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Computes the redirection target URL for the newly created {@link TopLevelItem}.
*/
protected String redirectAfterCreateItem(StaplerRequest req, TopLevelItem result) throws IOException {
return req.getContextPath()+'/'+result.getUrl()+"configure";
}
代码示例来源:origin: jenkinsci/jenkins
void addDisplayNamesToSearchIndex(SearchIndexBuilder sib, Collection<TopLevelItem> items) {
for(TopLevelItem item : items) {
if(LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine((String.format("Adding url=%s,displayName=%s",
item.getSearchUrl(), item.getDisplayName())));
}
sib.add(item.getSearchUrl(), item.getDisplayName());
}
}
代码示例来源:origin: jenkinsci/jenkins
/**
* This method checks all existing jobs to see if displayName is
* unique. It does not check the displayName against the displayName of the
* job that the user is configuring though to prevent a validation warning
* if the user sets the displayName to what it currently is.
* @param displayName
* @param currentJobName
*/
boolean isDisplayNameUnique(String displayName, String currentJobName) {
Collection<TopLevelItem> itemCollection = items.values();
// if there are a lot of projects, we'll have to store their
// display names in a HashSet or something for a quick check
for(TopLevelItem item : itemCollection) {
if(item.getName().equals(currentJobName)) {
// we won't compare the candidate displayName against the current
// item. This is to prevent an validation warning if the user
// sets the displayName to what the existing display name is
continue;
}
else if(displayName.equals(item.getDisplayName())) {
return false;
}
}
return true;
}
代码示例来源:origin: jenkinsci/jenkins
Jenkins j = Jenkins.getInstance();
o.put("install", j.getLegacyInstanceId());
o.put("servletContainer", j.servletContext.getServerInfo());
o.put("version", Jenkins.VERSION);
for( Computer c : j.getComputers() ) {
JSONObject n = new JSONObject();
if(c.getNode()==j) {
TopLevelItemDescriptor[] descriptors = Items.all().toArray(new TopLevelItemDescriptor[0]);
int counts[] = new int[descriptors.length];
for (TopLevelItem item: j.allItems(TopLevelItem.class)) {
TopLevelItemDescriptor d = item.getDescriptor();
for (int i = 0; i < descriptors.length; i++) {
if (d == descriptors[i]) {
代码示例来源:origin: jenkinsci/jenkins
public synchronized <T extends TopLevelItem> T copy(T src, String name) throws IOException {
acl.checkPermission(Item.CREATE);
src.checkPermission(Item.EXTENDED_READ);
XmlFile srcConfigFile = Items.getConfigFile(src);
if (!src.hasPermission(Item.CONFIGURE)) {
Matcher matcher = AbstractItem.SECRET_PATTERN.matcher(srcConfigFile.asString());
while (matcher.find()) {
if (Secret.decrypt(matcher.group(1)) != null) {
throw new AccessDeniedException(Messages.ItemGroupMixIn_may_not_copy_as_it_contains_secrets_and_(src.getFullName(), Jenkins.getAuthentication().getName(), Item.PERMISSIONS.title, Item.EXTENDED_READ.name, Item.CONFIGURE.name));
src.getDescriptor().checkApplicableIn(parent);
acl.getACL().checkCreatePermission(parent, src.getDescriptor());
ItemListener.checkBeforeCopy(src, parent);
T result = (T)createProject(src.getDescriptor(),name,false);
Files.copy(Util.fileToPath(srcConfigFile.getFile()), Util.fileToPath(Items.getConfigFile(result).getFile()),
StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
final File rootDir = result.getRootDir();
result = Items.whileUpdatingByXml(new NotReallyRoleSensitiveCallable<T,IOException>() {
@Override public T call() throws IOException {
return (T) Items.load(parent, rootDir);
result.onCopiedFrom(src);
Jenkins.getInstance().rebuildDependencyGraphAsync();
代码示例来源:origin: jenkinsci/jenkins
public synchronized TopLevelItem createProject( TopLevelItemDescriptor type, String name, boolean notify )
throws IOException {
acl.checkPermission(Item.CREATE);
type.checkApplicableIn(parent);
acl.getACL().checkCreatePermission(parent, type);
Jenkins.getInstance().getProjectNamingStrategy().checkName(name);
Items.verifyItemDoesNotAlreadyExist(parent, name, null);
TopLevelItem item = type.newInstance(parent, name);
item.onCreatedFromScratch();
item.save();
add(item);
Jenkins.getInstance().rebuildDependencyGraphAsync();
if (notify)
ItemListener.fireOnCreated(item);
return item;
}
代码示例来源:origin: jenkinsci/jenkins
public synchronized TopLevelItem createProjectFromXML(String name, InputStream xml) throws IOException {
acl.checkPermission(Item.CREATE);
Jenkins.getInstance().getProjectNamingStrategy().checkName(name);
Items.verifyItemDoesNotAlreadyExist(parent, name, null);
File configXml = Items.getConfigFile(getRootDirFor(name)).getFile();
final File dir = configXml.getParentFile();
dir.mkdirs();
TopLevelItem result = Items.whileUpdatingByXml(new NotReallyRoleSensitiveCallable<TopLevelItem,IOException>() {
@Override public TopLevelItem call() throws IOException {
return (TopLevelItem) Items.load(parent, dir);
success = acl.getACL().hasCreatePermission(Jenkins.getAuthentication(), parent, result.getDescriptor())
&& result.getDescriptor().isApplicableIn(parent);
代码示例来源:origin: groupon/DotCi
protected String redirectAfterCreateItem(StaplerRequest req, TopLevelItem result) throws IOException {
return Jenkins.getInstance().getRootUrl() + result.getUrl();
}
代码示例来源:origin: org.jenkins-ci.plugins/disk-usage
Node node = null;
if(nodeName.isEmpty()){
node = Jenkins.getInstance();
node = Jenkins.getInstance().getNode(nodeName);
LOGGER.log(Level.WARNING, "Can not get workspace for " + item.getDisplayName() + " on " + node.getDisplayName(), e);
代码示例来源:origin: jenkinsci/jenkins
protected int run() throws Exception {
Jenkins jenkins = Jenkins.getActiveInstance();
if (jenkins.getItemByFullName(dst)!=null) {
throw new IllegalStateException("Job '"+dst+"' already exists");
}
ModifiableTopLevelItemGroup ig = jenkins;
int i = dst.lastIndexOf('/');
if (i > 0) {
String group = dst.substring(0, i);
Item item = jenkins.getItemByFullName(group);
if (item == null) {
throw new IllegalArgumentException("Unknown ItemGroup " + group);
}
if (item instanceof ModifiableTopLevelItemGroup) {
ig = (ModifiableTopLevelItemGroup) item;
} else {
throw new IllegalStateException("Can't create job from CLI in " + group);
}
dst = dst.substring(i + 1);
}
ig.copy(src,dst).save();
return 0;
}
}
代码示例来源:origin: org.jenkins-ci.plugins/security-inspector
@Override
protected Boolean getEntryReport(TopLevelItem column, Permission item) {
final Authentication auth;
try {
auth = user4report.impersonate();
} catch (UsernameNotFoundException ex) {
return Boolean.FALSE;
}
SecurityContext initialContext = null;
Item i = JenkinsHelper.getInstanceOrFail().getItemByFullName(column.getFullName());
if (i == null) {
return Boolean.FALSE;
}
try {
initialContext = hudson.security.ACL.impersonate(auth);
return i.hasPermission(item);
} finally {
if (initialContext != null) {
SecurityContextHolder.setContext(initialContext);
}
}
}
代码示例来源:origin: jenkinsci/subversion-plugin
private void verifyCompatibility(String resourceName, Class<? extends WorkspaceUpdater> expected) throws Exception {
TopLevelItem item = r.jenkins.getItem("update");
if (item != null) {
item.delete();
}
AbstractProject job = (AbstractProject) r.jenkins.createProjectFromXML("update", getClass().getResourceAsStream(resourceName));
assertEquals(expected, ((SubversionSCM)job.getScm()).getWorkspaceUpdater().getClass());
}
代码示例来源:origin: hudson/hudson-2.x
/**
* Copies an existing {@link TopLevelItem} to a new name.
*
* The caller is responsible for calling {@link ItemListener#fireOnCopied(Item, Item)}. This method
* cannot do that because it doesn't know how to make the newly added item reachable from the parent.
*/
@SuppressWarnings({"unchecked"})
public synchronized <T extends TopLevelItem> T copy(T src, String name) throws IOException {
acl.checkPermission(Job.CREATE);
T result = (T)createProject(src.getDescriptor(),name,false);
// copy config
Util.copyFile(Items.getConfigFile(src).getFile(),Items.getConfigFile(result).getFile());
// reload from the new config
result = (T)Items.load(parent,result.getRootDir());
result.onCopiedFrom(src);
add(result);
ItemListener.fireOnCopied(src,result);
return result;
}
代码示例来源:origin: jenkinsci/jenkins
public void run(Reactor session) throws Exception {
if(!Items.getConfigFile(subdir).exists()) {
//Does not have job config file, so it is not a jenkins job hence skip it
return;
}
TopLevelItem item = (TopLevelItem) Items.load(Jenkins.this, subdir);
items.put(item.getName(), item);
loadedNames.add(item.getName());
}
}));
代码示例来源:origin: jenkinsci/gerrit-trigger-plugin
/**
* Tests that configuring an existing project via jenkins cli doesn't produce duplicated triggers
* and that the trigger is configured for the new project pattern.
*
* @throws Exception if so
*/
@Test
@LocalData
public void testReconfigureUsingCli() throws Exception {
assertNrOfEventListeners(0);
TopLevelItem testProj = j.jenkins.getItem("testProj");
String gerritProjectPattern = "someotherproject";
Document document = loadConfigXmlViaCli(testProj);
String xml = changeConfigXml(gerritProjectPattern, document);
List<String> cmd = javaCliJarCmd("update-job", testProj.getFullName());
Process process = Runtime.getRuntime().exec(cmd.toArray(new String[cmd.size()]));
OutputStream output = process.getOutputStream();
IOUtils.write(xml, output);
IOUtils.closeQuietly(output);
String response = IOUtils.toString(process.getInputStream());
System.out.println(response);
assertEquals(0, process.waitFor());
assertNrOfEventListeners(0);
assertEventListenerWithSomeOtherProjectSet(gerritProjectPattern);
}
代码示例来源:origin: jenkinsci/jenkins
@Override
protected String getName(TopLevelItem o) {
// return the name instead of the display for suggestion searching
return o.getName();
}
});
代码示例来源:origin: org.eclipse.hudson.main/hudson-core
/**
* {@inheritDoc}
* <p/>
* If {@link Hudson#HUDSON_WORKSPACES_PROPERTY_KEY} is set through JNDI
* or system properties or environment variables. workspaceRoot will be set based on property value.
*/
public FilePath getWorkspaceFor(TopLevelItem item) {
String workspaceRoot = getConfiguredWorkspaceRoot();
if (StringUtils.isNotBlank(workspaceRoot)) {
return new FilePath(new File(workspaceRoot + "/" + item.getName(), WORKSPACE_DIRNAME));
} else {
return new FilePath(new File(item.getRootDir(), WORKSPACE_DIRNAME));
}
}
代码示例来源:origin: org.jvnet.hudson.main/hudson-core
public void run(Reactor session) throws Exception {
TopLevelItem item = (TopLevelItem) Items.load(Hudson.this, subdir);
items.put(item.getName(), item);
}
});
内容来源于网络,如有侵权,请联系作者删除!