下面列出了怎么用hudson.model.AbstractItem的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void onLoad(final ItemGroup<? extends Item> parent, final String name) throws IOException {
try {
final Field parentField = AbstractItem.class.getDeclaredField("parent");
parentField.setAccessible(true);
ReflectionUtils.setField(parentField, this, parent);
} catch (final Exception e) {
throw new RuntimeException(e);
}
doSetName(name);
if (this.transientActions == null) {
this.transientActions = new Vector<>();
}
updateTransientActions();
getBuildersList().setOwner(this);
getPublishersList().setOwner(this);
getBuildWrappersList().setOwner(this);
initRepos();
}
/**
* Get all {@link AbstractFolder}s in the system
*
* @return full names of all {@link AbstractFolder}s in the system
*/
@GET
@Nonnull
@Restricted(NoExternalUse.class)
public JSONArray doGetAllFolders() {
Jenkins jenkins = Jenkins.get();
jenkins.checkPermission(Jenkins.ADMINISTER);
List<AbstractFolder> folders;
try (ACLContext ignored = ACL.as(ACL.SYSTEM)) {
folders = jenkins.getAllItems(AbstractFolder.class);
}
return JSONArray.fromObject(folders.stream().map(AbstractItem::getFullName).collect(Collectors.toList()));
}
/**
* {@inheritDoc}
*/
@Nonnull
@Override
public SidACL getACL(AbstractItem item) {
String fullName = item.getFullName();
SidACL acl = jobAclCache.getIfPresent(fullName);
if (acl != null) {
return acl;
}
String[] splits = fullName.split(FOLDER_SEPARATOR);
StringBuilder sb = new StringBuilder(fullName.length());
acl = globalAcl;
// Roles on a folder are applicable to all children
for (String str : splits) {
sb.append(str);
SidACL newAcl = jobAcls.get(sb.toString());
if (newAcl != null) {
acl = acl.newInheritingACL(newAcl);
}
sb.append(FOLDER_SEPARATOR);
}
jobAclCache.put(fullName, acl);
return acl;
}
@Issue("JENKINS-56641")
@Test
public void testAuditOnItemUpdate() throws Exception {
FreeStyleProject project = j.createFreeStyleProject("Test build");
AbstractItem item = (AbstractItem) project;
item.setDescription("Item created for testing the updates");
item.save();
List<LogEvent> events = app.getEvents();
assertThat(events).hasSize(2);
assertThat(events).extracting(event -> ((AuditMessage) event.getMessage()).getId().toString()).containsSequence("createItem", "updateItem");
}
public static Map<String, Boolean> getPermissions(AbstractItem item){
return ImmutableMap.of(
BluePipeline.CREATE_PERMISSION, item.getACL().hasPermission(Item.CREATE),
BluePipeline.CONFIGURE_PERMISSION, item.getACL().hasPermission(Item.CONFIGURE),
BluePipeline.READ_PERMISSION, item.getACL().hasPermission(Item.READ),
BluePipeline.START_PERMISSION, item.getACL().hasPermission(Item.BUILD),
BluePipeline.STOP_PERMISSION, item.getACL().hasPermission(Item.CANCEL)
);
}
@Override
public String getName() {
if(folder instanceof AbstractItem)
return ((AbstractItem) folder).getName();
else
return folder.getDisplayName();
}
@Override
public Map<String, Boolean> getPermissions() {
if(folder instanceof AbstractItem){
AbstractItem item = (AbstractItem) folder;
return AbstractPipelineImpl.getPermissions(item);
}else{
return null;
}
}
/**
* Gets the {@link ACL} for a {@link Job}
*
* @return the {@link ACL} for the {@link Job}
*/
@Nonnull
@Override
public SidACL getACL(Job<?, ?> project) {
return getACL((AbstractItem) project);
}
@Override
public ACL getACL(AbstractItem item) {
return new ACLImpl(item.getFullName());
}
@Override
public ACL getACL(Job<?, ?> project) {
return getACL((AbstractItem) project); // stupid overload
}
@PostLoad
private void restoreName(final DBObject dbObj) {
GReflectionUtils.setField(AbstractItem.class, "name", this, dbObj.get("name"));
}