Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong usage of CauseAction, rename some method. #54

Merged
merged 2 commits into from
Mar 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 17 additions & 20 deletions src/main/java/com/sonyericsson/rebuild/RebuildAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,7 @@ public void parameterizedRebuild(Run currentBuild, StaplerResponse response) thr
project.checkPermission(Item.BUILD);
if (isRebuildAvailable()) {

List<Action> actions = copyBuildCausesAndAddUserCause(currentBuild);
ParametersAction action = currentBuild.getAction(ParametersAction.class);
actions.add(action);
List<Action> actions = constructRebuildActions(build, currentBuild.getAction(ParametersAction.class));

Hudson.getInstance().getQueue().schedule((Queue.Task) build.getParent(), 0, actions);
response.sendRedirect("../../");
Expand All @@ -251,7 +249,7 @@ public void nonParameterizedRebuild(Run currentBuild, StaplerResponse
response) throws ServletException, IOException, InterruptedException {
getProject().checkPermission(Item.BUILD);

List<Action> actions = constructRebuildCause(build, null);
List<Action> actions = constructRebuildActions(build, null);
Hudson.getInstance().getQueue().schedule((Queue.Task) currentBuild.getParent(), 0, actions);
response.sendRedirect("../../");
}
Expand Down Expand Up @@ -310,7 +308,7 @@ public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws Servl
}
}

List<Action> actions = constructRebuildCause(build, new ParametersAction(values));
List<Action> actions = constructRebuildActions(build, new ParametersAction(values));
Hudson.getInstance().getQueue().schedule((Queue.Task) build.getParent(), 0, actions);

rsp.sendRedirect("../../");
Expand All @@ -320,29 +318,27 @@ public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws Servl
/**
* Extracts the build causes and adds or replaces the {@link hudson.model.Cause.UserIdCause}. The result is a
* list of all build causes from the original build (might be an empty list), plus a
* {@link hudson.model.Cause.UserIdCause} for the user who started the rebuild.
* {@link hudson.model.Cause.UserIdCause} for the user who started the rebuild, plus a
* {@link RebuildCause} for this rebuild.
*
* @param fromBuild the build to copy the causes from.
* @return list with all original causes and a {@link hudson.model.Cause.UserIdCause}.
*/
private List<Action> copyBuildCausesAndAddUserCause(Run<?, ?> fromBuild) {
List currentBuildCauses = fromBuild.getCauses();
private List<Cause> constructRebuildCauses(Run<?, ?> fromBuild) {
List<Cause> currentBuildCauses = new ArrayList<Cause>(fromBuild.getCauses());

List<Action> actions = new ArrayList<Action>(currentBuildCauses.size());
boolean hasUserCause = false;
for (Object buildCause : currentBuildCauses) {
if (buildCause instanceof Cause.UserIdCause) {
hasUserCause = true;
actions.add(new CauseAction(new Cause.UserIdCause()));
} else {
actions.add(new CauseAction((Cause)buildCause));
}
}
if (!hasUserCause) {
actions.add(new CauseAction(new Cause.UserIdCause()));
currentBuildCauses.add(new Cause.UserIdCause());
}
currentBuildCauses.add(new RebuildCause(fromBuild));

return actions;
return currentBuildCauses;
}

/**
Expand Down Expand Up @@ -374,14 +370,14 @@ public boolean isRebuildAvailable() {
&& project.hasPermission(Item.BUILD)
&& project.isBuildable()
&& project instanceof Queue.Task
&& !isMatrixRun()
&& !isMatrixRun()
&& !isRebuildDisabled();

}

private boolean isRebuildDisabled() {
RebuildSettings settings = (RebuildSettings)getProject().getProperty(RebuildSettings.class);

if (settings != null && settings.getRebuildDisabled()) {
return true;
}
Expand Down Expand Up @@ -460,15 +456,16 @@ private ParameterValue cloneParameter(ParameterValue oldValue, String newValue)
throw new IllegalArgumentException("Unrecognized parameter type: " + oldValue.getClass());
}
/**
* Method for constructing Rebuild cause.
* Method for constructing Rebuild actions.
*
* @param up AbsstractBuild
* @param paramAction ParametersAction.
* @return actions List<Action>
*/
private List<Action> constructRebuildCause(Run up, ParametersAction paramAction) {
List<Action> actions = copyBuildCausesAndAddUserCause(up);
actions.add(new CauseAction(new RebuildCause(up)));
private List<Action> constructRebuildActions(Run up, ParametersAction paramAction) {
List<Cause> causes = constructRebuildCauses(up);
List<Action> actions = new ArrayList<Action>();
actions.add(new CauseAction(causes));
if (paramAction != null) {
actions.add(paramAction);
}
Expand Down