Search in sources :

Example 6 with CopyOnWriteList

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

the class Job method onLoad.

@Override
@SuppressWarnings("unchecked")
public void onLoad(ItemGroup<? extends Item> parent, String name) throws IOException {
    super.onLoad(parent, name);
    cascadingProject = (JobT) Functions.getItemByName(Hudson.getInstance().getAllItems(this.getClass()), cascadingProjectName);
    initAllowSave();
    TextFile f = getNextBuildNumberFile();
    if (f.exists()) {
        // assume that nextBuildNumber was read from config.xml
        try {
            synchronized (this) {
                this.nextBuildNumber = Integer.parseInt(f.readTrim());
            }
        } catch (NumberFormatException e) {
            throw new IOException2(f + " doesn't contain a number", e);
        }
    } else {
        // From the old Hudson, or doCreateItem. Create this file now.
        saveNextBuildNumber();
        // and delete it from the config.xml
        save();
    }
    if (// didn't exist < 1.72
    properties == null)
        properties = new CopyOnWriteList<JobProperty<? super JobT>>();
    if (cascadingChildrenNames == null) {
        cascadingChildrenNames = new CopyOnWriteArraySet<String>();
    }
    buildProjectProperties();
    for (JobProperty p : getAllProperties()) {
        p.setOwner(this);
    }
}
Also used : CopyOnWriteList(hudson.util.CopyOnWriteList) TextFile(hudson.util.TextFile) IOException2(hudson.util.IOException2)

Example 7 with CopyOnWriteList

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

the class Job method getAllProperties.

/**
     * List of all {@link JobProperty} exposed primarily for the remoting API.
     * List contains cascadable {@link JobProperty} if any.
     * @since 2.2.0
     */
@Exported(name = "property", inline = true)
public List<JobProperty<? super JobT>> getAllProperties() {
    CopyOnWriteList cascadingJobProperties = getCascadingJobProperties();
    List<JobProperty<? super JobT>> result = properties.getView();
    if (null != cascadingJobProperties && !cascadingJobProperties.isEmpty()) {
        result = Collections.unmodifiableList(ListUtils.union(result, cascadingJobProperties.getView()));
    }
    return result;
}
Also used : CopyOnWriteList(hudson.util.CopyOnWriteList) Exported(org.kohsuke.stapler.export.Exported)

Example 8 with CopyOnWriteList

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

the class Job method convertCascadingJobProperties.

/**
     * Method converts JobProperties to cascading values.
     * <p/>
     * If property is {@link AuthorizationMatrixProperty} - it will be skipped.
     * If property is {@link ParametersDefinitionProperty} - it will be added to list of parameterDefinition properties.
     * All the rest properties will be converted to {@link BaseProjectProperty} classes and added
     * to cascadingJobProperties set.
     *
     * @param properties list of {@link JobProperty}
     */
private void convertCascadingJobProperties(CopyOnWriteList<JobProperty<? super JobT>> properties) {
    CopyOnWriteList parameterDefinitionProperties = new CopyOnWriteList();
    for (JobProperty property : properties) {
        if (property instanceof AuthorizationMatrixProperty) {
            continue;
        }
        if (property instanceof ParametersDefinitionProperty) {
            parameterDefinitionProperties.add(property);
            continue;
        }
        BaseProjectProperty projectProperty = CascadingUtil.getBaseProjectProperty(this, property.getDescriptor().getJsonSafeClassName());
        addCascadingJobProperty(projectProperty);
    }
    if (null == getProperty(PARAMETERS_DEFINITION_JOB_PROPERTY_PROPERTY_NAME)) {
        setParameterDefinitionProperties(parameterDefinitionProperties);
    }
}
Also used : BaseProjectProperty(org.hudsonci.model.project.property.BaseProjectProperty) CopyOnWriteList(hudson.util.CopyOnWriteList) AuthorizationMatrixProperty(hudson.security.AuthorizationMatrixProperty)

Example 9 with CopyOnWriteList

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

the class CopyOnWriteListProjectPropertyTest method testGetDefaultValue.

/**
     * Verify {@link CopyOnWriteListProjectProperty#getDefaultValue()} method.
     */
@Test
public void testGetDefaultValue() {
    CopyOnWriteList defaultValue = property.getDefaultValue();
    assertNotNull(defaultValue);
    //Default value should be initialized and stored as original value
    assertTrue(property.getOriginalValue() == defaultValue);
    assertFalse(property.isOverridden());
}
Also used : CopyOnWriteList(hudson.util.CopyOnWriteList) Test(org.junit.Test)

Example 10 with CopyOnWriteList

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

the class CopyOnWriteListProjectPropertyTest method testGetOriginalValue.

/**
     * Verify {@link CopyOnWriteListProjectProperty#getOriginalValue()} method.
     */
@Test
public void testGetOriginalValue() {
    //Original value is not initialized. Default value will be used instead. Shouldn't be null
    CopyOnWriteList originalValue = property.getOriginalValue();
    assertNotNull(originalValue);
    //Value was set, so return it without modification
    assertTrue(originalValue == property.getOriginalValue());
}
Also used : CopyOnWriteList(hudson.util.CopyOnWriteList) Test(org.junit.Test)

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