hudson.triggers.TriggerDescriptor Java Examples

The following examples show how to use hudson.triggers.TriggerDescriptor. 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: TemplateUtils.java    From ez-templates with Apache License 2.0 6 votes vote down vote up
private static void fixBuildTriggers(AbstractProject implementationProject, Map<TriggerDescriptor, Trigger> oldTriggers) {
    List<Trigger<?>> triggersToReplace = ProjectUtils.getTriggers(implementationProject);
    if (triggersToReplace == null) {
        throw new NullPointerException("triggersToReplace");
    }

    if (!triggersToReplace.isEmpty() || !oldTriggers.isEmpty()) {
        //noinspection SynchronizationOnLocalVariableOrMethodParameter
        synchronized (triggersToReplace) {
            triggersToReplace.clear();
            for (Trigger trigger : oldTriggers.values()) {
                triggersToReplace.add(trigger);
            }
        }
    }
}
 
Example #2
Source File: TemplateStaplerRequestWrapper.java    From multi-branch-project-plugin with MIT License 5 votes vote down vote up
/**
 * Overrides certain parameter names with certain values needed when setting the configuration for
 * template projects.  Otherwise, relies on the standard implementation.
 * <br>
 * {@inheritDoc}
 */
@Override
public String getParameter(String name) {
    // Sanitize the following parameters
    if ("name".equals(name)) {
        // Don't set the name
        return null;
    } else if ("description".equals(name)) {
        // Don't set the description
        return null;
    } else if ("disable".equals(name)) {
        // Mark disabled
        return "";
    }

    /*
     * Parameters for conflicting triggers should return null if the
     * corresponding JSON was not provided.  Otherwise, NPEs occur when
     * trying to update the triggers for the template project.
     */
    DescriptorExtensionList<Trigger<?>, TriggerDescriptor> triggerDescriptors = Trigger.all();
    for (TriggerDescriptor triggerDescriptor : triggerDescriptors) {
        String safeName = triggerDescriptor.getJsonSafeClassName();

        try {
            if (name.equals(safeName) && getSubmittedForm().getJSONObject(safeName).isNullObject()) {
                return null;
            }
        } catch (ServletException e) {
            throw new IllegalStateException("Exception getting data from submitted JSON", e);
        }
    }

    // Fallback to standard functionality
    return super.getParameter(name);
}
 
Example #3
Source File: TemplateUtils.java    From ez-templates with Apache License 2.0 4 votes vote down vote up
public static void handleTemplateImplementationSaved(AbstractProject implementationProject, TemplateImplementationProperty property) throws IOException {
	
    if (property.getTemplateJobName().equals("null")) {
        LOG.warning(String.format("Implementation [%s] was saved. No template selected.", implementationProject.getFullDisplayName()));
        return;
    }
	
    LOG.info(String.format("Implementation [%s] was saved. Syncing with [%s].", implementationProject.getFullDisplayName(), property.getTemplateJobName()));
    
    AbstractProject templateProject = property.findTemplate();        
    if (templateProject == null) {
    	
    	// If the template can't be found, then it's probably a bug
        throw new IllegalStateException(String.format("Cannot find template [%s] used by job [%s]", property.getTemplateJobName(), implementationProject.getFullDisplayName()));
    }

    //Capture values we want to keep
    @SuppressWarnings("unchecked")
    boolean implementationIsTemplate = implementationProject.getProperty(TemplateProperty.class) != null;
    List<ParameterDefinition> oldImplementationParameters = findParameters(implementationProject);
    @SuppressWarnings("unchecked")
    Map<TriggerDescriptor, Trigger> oldTriggers = implementationProject.getTriggers();
    boolean shouldBeDisabled = implementationProject.isDisabled();
    String description = implementationProject.getDescription();
    String displayName = implementationProject.getDisplayNameOrNull();
    AuthorizationMatrixProperty oldAuthMatrixProperty = (AuthorizationMatrixProperty) implementationProject.getProperty(AuthorizationMatrixProperty.class);
    SCM oldScm = (SCM) implementationProject.getScm();
    JobProperty oldOwnership = implementationProject.getProperty("com.synopsys.arc.jenkins.plugins.ownership.jobs.JobOwnerJobProperty");
    Label oldLabel = implementationProject.getAssignedLabel();

    AxisList oldAxisList = null;
    if (implementationProject instanceof MatrixProject && !property.getSyncMatrixAxis()) {
        MatrixProject matrixProject = (MatrixProject) implementationProject;
        oldAxisList = matrixProject.getAxes();
    }

    implementationProject = synchronizeConfigFiles(implementationProject, templateProject);

    // Reverse all the fields that we've marked as "Don't Sync" so that they appear that they haven't changed.

    //Set values that we wanted to keep via reflection to prevent infinite save recursion
    fixProperties(implementationProject, property, implementationIsTemplate);
    fixParameters(implementationProject, oldImplementationParameters);

    ReflectionUtils.setFieldValue(AbstractItem.class, implementationProject, "displayName", displayName);

    if (!property.getSyncBuildTriggers()) {
        fixBuildTriggers(implementationProject, oldTriggers);
    }

    if (!property.getSyncDisabled()) {
        ReflectionUtils.setFieldValue(AbstractProject.class, implementationProject, "disabled", shouldBeDisabled);
    }

    if (oldAxisList != null && implementationProject instanceof MatrixProject && !property.getSyncMatrixAxis()) {
        fixAxisList((MatrixProject) implementationProject, oldAxisList);
    }

    if (!property.getSyncDescription() && description != null) {
        ReflectionUtils.setFieldValue(AbstractItem.class, implementationProject, "description", description);
    }

    if (!property.getSyncSecurity() && oldAuthMatrixProperty != null) {
        implementationProject.removeProperty(AuthorizationMatrixProperty.class);
        implementationProject.addProperty(oldAuthMatrixProperty);
    }

    if (!property.getSyncScm() && oldScm != null) {
        implementationProject.setScm(oldScm);
    }

    if (!property.getSyncOwnership() && oldOwnership != null) {
        implementationProject.removeProperty(oldOwnership.getClass());
        implementationProject.addProperty(oldOwnership);
    }

    if (!property.getSyncAssignedLabel()) {
        implementationProject.setAssignedLabel(oldLabel);
    }

    if (Jenkins.getInstance().getPlugin("promoted-builds") != null) {
        PromotedBuildsTemplateUtils.addPromotions(implementationProject, templateProject);
    } 

    ProjectUtils.silentSave(implementationProject);
}