Search in sources :

Example 1 with CopyOnWriteList

use of hudson.util.CopyOnWriteList in project hudson-2.x by hudson.

the class CopyOnWriteListProjectPropertyTest method testClearOriginalValue.

/**
     * Verify {@link CopyOnWriteListProjectProperty#clearOriginalValue(hudson.util.CopyOnWriteList)} method.
     */
@Test
public void testClearOriginalValue() {
    //Overridden flag should be cleared to false. Pre-set true value
    property.setOverridden(true);
    assertTrue(property.isOverridden());
    CopyOnWriteList originalValue = new CopyOnWriteList(Arrays.asList(new Object()));
    property.clearOriginalValue(originalValue);
    //Original value should be set with overridden flag == false
    assertFalse(property.isOverridden());
    assertTrue(originalValue == property.getOriginalValue());
}
Also used : CopyOnWriteList(hudson.util.CopyOnWriteList) Test(org.junit.Test)

Example 2 with CopyOnWriteList

use of hudson.util.CopyOnWriteList in project hudson-2.x by hudson.

the class CopyOnWriteListProjectPropertyTest method testReturnOriginalValue.

/**
     * Verify {@link CopyOnWriteListProjectProperty#returnOriginalValue()} method.
     */
@Test
public void testReturnOriginalValue() {
    //Return cascading is property is not overridden and is empty.
    assertFalse(property.returnOriginalValue());
    //Return properties' originalValue if it was overridden
    property.setOverridden(true);
    assertTrue(property.returnOriginalValue());
    //If property has not empty value - return it (basically for non-cascadable projects)
    property.setOriginalValue(new CopyOnWriteList(Arrays.asList(new Object())), false);
    assertTrue(property.returnOriginalValue());
    //If property has not empty value and was overridden - return it
    property.setOriginalValue(new CopyOnWriteList(Arrays.asList(new Object())), true);
    assertTrue(property.returnOriginalValue());
}
Also used : CopyOnWriteList(hudson.util.CopyOnWriteList) Test(org.junit.Test)

Example 3 with CopyOnWriteList

use of hudson.util.CopyOnWriteList in project hudson-2.x by hudson.

the class Job method submit.

/**
     * Derived class can override this to perform additional config submission
     * work.
     */
protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException {
    JSONObject json = req.getSubmittedForm();
    description = req.getParameter("description");
    keepDependencies = req.getParameter("keepDependencies") != null;
    properties.clear();
    setCascadingProjectName(StringUtils.trimToNull(req.getParameter("cascadingProjectName")));
    CopyOnWriteList parameterDefinitionProperties = new CopyOnWriteList();
    int i = 0;
    for (JobPropertyDescriptor d : JobPropertyDescriptor.getPropertyDescriptors(Job.this.getClass())) {
        if (!CascadingUtil.isCascadableJobProperty(d)) {
            String name = "jobProperty" + i;
            JSONObject config = json.getJSONObject(name);
            JobProperty prop = d.newInstance(req, config);
            if (null != prop) {
                prop.setOwner(this);
                if (prop instanceof AuthorizationMatrixProperty) {
                    properties.add(prop);
                } else if (prop instanceof ParametersDefinitionProperty) {
                    parameterDefinitionProperties.add(prop);
                }
            }
        } else {
            BaseProjectProperty property = CascadingUtil.getBaseProjectProperty(this, d.getJsonSafeClassName());
            JobProperty prop = d.newInstance(req, json.getJSONObject(d.getJsonSafeClassName()));
            if (null != prop) {
                prop.setOwner(this);
            }
            property.setValue(prop);
            addCascadingJobProperty(property);
        }
        i++;
    }
    setParameterDefinitionProperties(parameterDefinitionProperties);
    LogRotator logRotator = null;
    if (null != req.getParameter("logrotate")) {
        logRotator = LogRotator.DESCRIPTOR.newInstance(req, json.getJSONObject("logrotate"));
    }
    setLogRotator(logRotator);
}
Also used : BaseProjectProperty(org.hudsonci.model.project.property.BaseProjectProperty) JSONObject(net.sf.json.JSONObject) LogRotator(hudson.tasks.LogRotator) CopyOnWriteList(hudson.util.CopyOnWriteList) AuthorizationMatrixProperty(hudson.security.AuthorizationMatrixProperty) ExtensionPoint(hudson.ExtensionPoint)

Example 4 with CopyOnWriteList

use of hudson.util.CopyOnWriteList in project hudson-2.x by hudson.

the class Job method getCascadingJobProperties.

/**
     * @return list of cascading {@link JobProperty} instances. Includes {@link ParametersDefinitionProperty} and
     *         children of {@link JobProperty} from external plugins.
     */
private CopyOnWriteList getCascadingJobProperties() {
    CopyOnWriteList result = new CopyOnWriteList();
    CopyOnWriteList<ParametersDefinitionProperty> definitionProperties = getParameterDefinitionProperties();
    if (null != cascadingJobProperties && !cascadingJobProperties.isEmpty()) {
        for (String key : cascadingJobProperties) {
            IProjectProperty projectProperty = CascadingUtil.getProjectProperty(this, key);
            Object value = projectProperty.getValue();
            if (null != value) {
                result.add(value);
            }
        }
    }
    if (null != definitionProperties && !definitionProperties.isEmpty()) {
        result.addAll(definitionProperties.getView());
    }
    return result;
}
Also used : IProjectProperty(org.hudsonci.api.model.IProjectProperty) CopyOnWriteList(hudson.util.CopyOnWriteList) JSONObject(net.sf.json.JSONObject)

Example 5 with CopyOnWriteList

use of hudson.util.CopyOnWriteList in project hudson-2.x by hudson.

the class CopyOnWriteListProjectProperty method getDefaultValue.

@Override
public CopyOnWriteList getDefaultValue() {
    CopyOnWriteList result = new CopyOnWriteList();
    setOriginalValue(result, false);
    return result;
}
Also used : CopyOnWriteList(hudson.util.CopyOnWriteList)

Aggregations

CopyOnWriteList (hudson.util.CopyOnWriteList)10 Test (org.junit.Test)4 AuthorizationMatrixProperty (hudson.security.AuthorizationMatrixProperty)2 JSONObject (net.sf.json.JSONObject)2 BaseProjectProperty (org.hudsonci.model.project.property.BaseProjectProperty)2 ExtensionPoint (hudson.ExtensionPoint)1 LogRotator (hudson.tasks.LogRotator)1 IOException2 (hudson.util.IOException2)1 TextFile (hudson.util.TextFile)1 IProjectProperty (org.hudsonci.api.model.IProjectProperty)1 Exported (org.kohsuke.stapler.export.Exported)1