Skip to content

Commit

Permalink
Making it configurable for all non-synced properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelJ committed Apr 11, 2013
1 parent 14ee1a3 commit a993065
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,37 @@ public class TemplateImplementationProperty extends JobProperty<AbstractProject<
private static final Logger LOG = Logger.getLogger("ez-templates");

private final String templateJobName;
private final boolean syncDescription;
private final boolean syncBuildTriggers;
private final boolean syncDisabled;
private final boolean syncMatrixAxis;

@DataBoundConstructor
public TemplateImplementationProperty(String templateJobName, boolean syncMatrixAxis) {
public TemplateImplementationProperty(String templateJobName, boolean syncMatrixAxis, boolean syncDescription, boolean syncBuildTriggers, boolean syncDisabled) {
this.templateJobName = templateJobName;
this.syncMatrixAxis = syncMatrixAxis;
this.syncDescription = syncDescription;
this.syncBuildTriggers = syncBuildTriggers;
this.syncDisabled = syncDisabled;
}

@Exported
public String getTemplateJobName() {
return templateJobName;
}

public boolean getSyncDescription() {
return syncDescription;
}

public boolean getSyncBuildTriggers() {
return syncBuildTriggers;
}

public boolean getSyncDisabled() {
return syncDisabled;
}

@Exported
public boolean getSyncMatrixAxis() {
return syncMatrixAxis;
Expand Down Expand Up @@ -68,9 +86,12 @@ public JobProperty<?> newInstance(StaplerRequest request, JSONObject formData) t
}
}

boolean syncDescription = useTemplate.getBoolean("syncDescription");
boolean syncBuildTriggers = useTemplate.getBoolean("syncBuildTriggers");
boolean syncDisabled = useTemplate.getBoolean("syncDisabled");
boolean syncMatrixAxis = useTemplate.getBoolean("syncMatrixAxis");

return new TemplateImplementationProperty(templateJobName, syncMatrixAxis);
return new TemplateImplementationProperty(templateJobName, syncDescription, syncBuildTriggers, syncDisabled, syncMatrixAxis);
} else {
@SuppressWarnings("unchecked")
TemplateImplementationProperty oldTemplateImplementationProperty = (TemplateImplementationProperty) thisProject.getProperty(TemplateImplementationProperty.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,25 @@ public static void handleImplementation(AbstractProject implementationProject, T

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);
fixBuildTriggers(implementationProject, oldTriggers);
ReflectionUtils.setFieldValue(AbstractProject.class, implementationProject, "disabled", shouldBeDisabled);

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(description != null) {
if(!property.getSyncDescription() && description != null) {
ReflectionUtils.setFieldValue(AbstractItem.class, implementationProject, "description", description);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@
<f:entry field="templateJobName" title="${%Name of job to use as template}">
<f:textbox/>
</f:entry>
<f:entry field="syncDescription" title="${%Sync Description}">
<f:checkbox />
</f:entry>
<f:entry field="syncBuildTriggers" title="${%Sync Build Triggers}">
<f:checkbox />
</f:entry>
<f:entry field="syncDisabled" title="${%Sync Enabled/Disabled State}">
<f:checkbox />
</f:entry>
<f:entry field="syncMatrixAxis" title="${%Sync Matrix Axis Configuration}">
<f:checkbox default="true"/>
<f:checkbox />
</f:entry>
</f:optionalBlock>
</j:jelly>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
<div id="templateImplementationWarning">
${%This job is implementing a template.
You can change the name, description, build triggers, and whether or not the build is enabled.}
You can change only the fields specified in the configuration and the default build parameters.}
<b>${%All other fields will be overwritten with the template's configuration.}</b>
</div>
<link rel="stylesheet" type="text/css" href="${rootURL}/plugin/ez-templates/implementationPage.css"/>
Expand Down

0 comments on commit a993065

Please sign in to comment.