hudson.util.PersistedList Java Examples

The following examples show how to use hudson.util.PersistedList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JenkinsRule.java    From jenkins-test-harness with MIT License 6 votes vote down vote up
/**
 * 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));
}
 
Example #2
Source File: BaseConfigurator.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
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;
    }
 
Example #3
Source File: HudsonTestCase.java    From jenkins-test-harness with MIT License 5 votes vote down vote up
/**
 * 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));
}
 
Example #4
Source File: TemplateDrivenMultiBranchProject.java    From multi-branch-project-plugin with MIT License 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #5
Source File: PersistedListAttribute.java    From configuration-as-code-plugin with MIT License 4 votes vote down vote up
@Override
public PersistedList getValue(Owner o) throws Exception {
    return (PersistedList) super.getValue(o);
}
 
Example #6
Source File: DescribableListAttribute.java    From configuration-as-code-plugin with MIT License 4 votes vote down vote up
@Override
public PersistedList getValue(Owner o) throws Exception {
    return (PersistedList) super.getValue(o);
}