Skip to content

Commit

Permalink
[JENKINS-41591] Fix pipeline support using TransientActionFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
Dohbedoh committed Jan 16, 2020
1 parent 78990a8 commit 2c0da93
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 82 deletions.
33 changes: 20 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,15 @@
*/
package com.sonyericsson.rebuild;

import hudson.matrix.MatrixConfiguration;
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 javax.annotation.Nonnull;
import java.util.Collection;

import static java.util.Collections.emptyList;
Expand All @@ -40,28 +41,34 @@
* 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) {
return emptyList();
}
if (!(build.getParent() instanceof Queue.Task)) {
if (run.getParent() instanceof MatrixConfiguration) {
return emptyList();
}

boolean hasRebuildAction = build.getAction(RebuildAction.class) != null;
if (hasRebuildAction) {
if (!(run.getParent() instanceof Queue.Task)) {
return emptyList();
}
for (RebuildValidator rebuildValidator : Jenkins.getInstance().

for (RebuildValidator rebuildValidator : Jenkins.getInstanceOrNull().
getExtensionList(RebuildValidator.class)) {
if (rebuildValidator.isApplicable(build)) {
if (rebuildValidator.isApplicable(run)) {
return emptyList();
}
}

return singleton(new RebuildAction());
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,34 @@
*/
package com.sonyericsson.rebuild;

import hudson.matrix.MatrixConfiguration;
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 javax.annotation.Nonnull;
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)
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());
Expand Down
61 changes: 0 additions & 61 deletions src/main/java/com/sonyericsson/rebuild/Rebuilder.java

This file was deleted.

0 comments on commit 2c0da93

Please sign in to comment.