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

[JENKINS-41591] Fix pipeline support using TransientActionFactory #55

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
15 changes: 12 additions & 3 deletions src/main/java/com/sonyericsson/rebuild/RebuildAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public class RebuildAction implements Action {
private transient String p = "parameter";
private transient Run<?, ?> build;
private transient ParametersDefinitionProperty pdp;
private transient boolean isTransient = false;
private static final String PARAMETERIZED_URL = "parameterized";
/**
* Rebuild Descriptor.
Expand All @@ -93,6 +94,14 @@ public class RebuildAction implements Action {
public RebuildAction() {
}

/**
* RebuildAction constructor.
* @param isTransient true to mark it as transient
*/
RebuildAction(boolean isTransient) {
this.isTransient = isTransient;
}

/**
* Getter method for pdp.
*
Expand Down Expand Up @@ -168,7 +177,7 @@ public Job getProject() {

@Override
public String getIconFileName() {
if (isRebuildAvailable()) {
if (isTransient && isRebuildAvailable()) {
return "clock.png";
} else {
return null;
Expand All @@ -177,7 +186,7 @@ public String getIconFileName() {

@Override
public String getDisplayName() {
if (isRebuildAvailable()) {
if (isTransient && isRebuildAvailable()) {
return "Rebuild";
} else {
return null;
Expand All @@ -186,7 +195,7 @@ public String getDisplayName() {

@Override
public String getUrlName() {
if (isRebuildAvailable()) {
if (isTransient && isRebuildAvailable()) {
return "rebuild";
} else {
return null;
Expand Down
31 changes: 18 additions & 13 deletions src/main/java/com/sonyericsson/rebuild/RebuildActionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
*/
package com.sonyericsson.rebuild;

import hudson.matrix.MatrixConfiguration;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.matrix.MatrixConfiguration;
import hudson.model.Action;
import hudson.model.Queue;
import hudson.model.Run;
import hudson.model.TransientBuildActionFactory;
import jenkins.model.Jenkins;

import jenkins.model.TransientActionFactory;
import java.util.Collection;

import static java.util.Collections.emptyList;
Expand All @@ -40,28 +40,33 @@
* Enables rebuild for builds that ran before installing the rebuild plugin.
*/
@Extension
public class RebuildActionFactory extends TransientBuildActionFactory {
public class RebuildActionFactory extends TransientActionFactory<Run> {

@Override
public Class<Run> type() {
return Run.class;
}

@NonNull
@Override
public Collection<? extends Action> createFor(Run build) {
public Collection<? extends Action> createFor(@NonNull Run run) {

// TODO should this not just use RebuildAction.isRebuildAvailable? Or conversely, is that method needed if we are already filtering here?
if (build.getParent() instanceof MatrixConfiguration) {
if (run.getParent() instanceof MatrixConfiguration) {
return emptyList();
}
if (!(build.getParent() instanceof Queue.Task)) {
if (!(run.getParent() instanceof Queue.Task)) {
return emptyList();
}

boolean hasRebuildAction = build.getAction(RebuildAction.class) != null;
if (hasRebuildAction) {
return emptyList();
}
for (RebuildValidator rebuildValidator : Jenkins.get().
getExtensionList(RebuildValidator.class)) {
if (rebuildValidator.isApplicable(build)) {
if (rebuildValidator.isApplicable(run)) {
return emptyList();
}
}
return singleton(new RebuildAction());

return singleton(new RebuildAction(true));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
*/
public class RebuildLastCompletedBuildAction extends RebuildAction {

public RebuildLastCompletedBuildAction(boolean isTransient) {
super(isTransient);
}

@Override
public String getUrlName() {
Job project = getProject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,35 @@
*/
package com.sonyericsson.rebuild;

import hudson.matrix.MatrixConfiguration;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.model.AbstractProject;
import hudson.matrix.MatrixConfiguration;
import hudson.model.Action;
import hudson.model.TransientProjectActionFactory;

import hudson.model.Job;
import jenkins.model.TransientActionFactory;
import java.util.Collection;

import static java.util.Collections.singleton;
import static java.util.Collections.emptyList;
import static java.util.Collections.singleton;

/**
* Makes the rebuild button available on the project level.
* Rebuilds the last completed build.
*/
@Extension
// TODO when depending on 1.548+, switch to TransientActionFactory (also for RebuildActionFactory) and take Job not AbstractProject (again consider consolidating logic with isRebuildAvailable)
Dohbedoh marked this conversation as resolved.
Show resolved Hide resolved
public class RebuildProjectActionFactory extends TransientProjectActionFactory {
public class RebuildProjectActionFactory extends TransientActionFactory<Job> {

@Override
public Class<Job> type() {
return Job.class;
}

@NonNull
@Override
public Collection<? extends Action> createFor(AbstractProject abstractProject) {
if (abstractProject instanceof MatrixConfiguration) {
public Collection<? extends Action> createFor(@NonNull Job job) {
if (job instanceof MatrixConfiguration) {
return emptyList();
}
return singleton(new RebuildLastCompletedBuildAction());
return singleton(new RebuildLastCompletedBuildAction(true));
}
}
62 changes: 0 additions & 62 deletions src/main/java/com/sonyericsson/rebuild/Rebuilder.java

This file was deleted.