下面列出了hudson.model.Describable#hudson.util.PersistedList 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Internal method used to configure update center to avoid network traffic.
* @param jenkins the Jenkins to configure
* @since 2.50
*/
public static void _configureUpdateCenter(Jenkins jenkins) throws Exception {
final String updateCenterUrl;
jettyLevel(Level.WARNING);
try {
updateCenterUrl = "http://localhost:"+ JavaNetReverseProxy.getInstance().localPort+"/update-center.json";
} finally {
jettyLevel(Level.INFO);
}
// don't waste bandwidth talking to the update center
DownloadService.neverUpdate = true;
UpdateSite.neverUpdate = true;
PersistedList<UpdateSite> sites = jenkins.getUpdateCenter().getSites();
sites.clear();
sites.add(new UpdateSite("default", updateCenterUrl));
}
protected Attribute createAttribute(String name, final TypePair type) {
boolean multiple =
type.rawType.isArray()
|| Collection.class.isAssignableFrom(type.rawType);
// If attribute is a Collection|Array of T, we need to introspect further to determine T
Class c = multiple ? getComponentType(type) : type.rawType;
if (c == null) {
throw new IllegalStateException("Unable to detect type of attribute " + getTarget() + '#' + name);
}
// special collection types with dedicated handlers to manage data replacement / possible values
if (DescribableList.class.isAssignableFrom(type.rawType)) {
return new DescribableListAttribute(name, c);
} else if (PersistedList.class.isAssignableFrom(type.rawType)) {
return new PersistedListAttribute(name, c);
}
Attribute attribute;
if (!c.isPrimitive() && !c.isEnum() && Modifier.isAbstract(c.getModifiers())) {
if (!Describable.class.isAssignableFrom(c)) {
// Not a Describable, so we don't know how to detect concrete implementation type
LOGGER.warning("Can't handle "+getTarget()+"#"+name+": type is abstract but not Describable.");
return null;
}
attribute = new DescribableAttribute(name, c);
} else {
attribute = new Attribute(name, c);
}
attribute.multiple(multiple);
return attribute;
}
/**
* Configures the update center setting for the test.
* By default, we load updates from local proxy to avoid network traffic as much as possible.
*/
protected void configureUpdateCenter() throws Exception {
final String updateCenterUrl = "http://localhost:"+ JavaNetReverseProxy.getInstance().localPort+"/update-center.json";
// don't waste bandwidth talking to the update center
DownloadService.neverUpdate = true;
UpdateSite.neverUpdate = true;
PersistedList<UpdateSite> sites = jenkins.getUpdateCenter().getSites();
sites.clear();
sites.add(new UpdateSite("default", updateCenterUrl));
}
/**
* Common initialization that is invoked when either a new project is created with the constructor
* {@link TemplateDrivenMultiBranchProject#TemplateDrivenMultiBranchProject(ItemGroup, String)} or when a project
* is loaded from disk with {@link #onLoad(ItemGroup, String)}.
*/
protected void init3() {
if (disabledSubProjects == null) {
disabledSubProjects = new PersistedList<>(this);
}
// Owner doesn't seem to be set when loading from XML
disabledSubProjects.setOwner(this);
try {
XmlFile templateXmlFile = Items.getConfigFile(getTemplateDir());
if (templateXmlFile.getFile().isFile()) {
/*
* Do not use Items.load here, since it uses getRootDirFor(i) during onLoad,
* which returns the wrong location since template would still be unset.
* Instead, read the XML directly into template and then invoke onLoad.
*/
//noinspection unchecked
template = (P) templateXmlFile.read();
template.onLoad(this, TEMPLATE);
} else {
/*
* Don't use the factory here because newInstance calls setBranch, attempting
* to save the project before template is set. That would invoke
* getRootDirFor(i) and get the wrong directory to save into.
*/
template = newTemplate();
}
// Prevent tampering
if (!(template.getScm() instanceof NullSCM)) {
template.setScm(new NullSCM());
}
template.disable();
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Failed to load template project " + getTemplateDir(), e);
}
}
@Override
public PersistedList getValue(Owner o) throws Exception {
return (PersistedList) super.getValue(o);
}
@Override
public PersistedList getValue(Owner o) throws Exception {
return (PersistedList) super.getValue(o);
}