From f67ea827eb8520be77d5a07f9623600756fd003f Mon Sep 17 00:00:00 2001 From: James Dumay Date: Thu, 15 Dec 2016 12:45:58 +1100 Subject: [PATCH] JENKINS-40446 Links broken in GitHub status for matrix projects --- pom.xml | 5 ++ .../BlueOceanDisplayURLImpl.java | 69 +++++++++++++------ 2 files changed, 52 insertions(+), 22 deletions(-) diff --git a/pom.xml b/pom.xml index 3c2c460f9..f166385e5 100644 --- a/pom.xml +++ b/pom.xml @@ -76,6 +76,11 @@ workflow-job 2.6 + + org.jenkins-ci.main + maven-plugin + 2.14 + org.jenkins-ci.plugins.workflow workflow-multibranch diff --git a/src/main/java/org/jenkinsci/plugins/blueoceandisplayurl/BlueOceanDisplayURLImpl.java b/src/main/java/org/jenkinsci/plugins/blueoceandisplayurl/BlueOceanDisplayURLImpl.java index 7df76a81d..5c98b2c23 100644 --- a/src/main/java/org/jenkinsci/plugins/blueoceandisplayurl/BlueOceanDisplayURLImpl.java +++ b/src/main/java/org/jenkinsci/plugins/blueoceandisplayurl/BlueOceanDisplayURLImpl.java @@ -1,13 +1,16 @@ package org.jenkinsci.plugins.blueoceandisplayurl; +import com.google.common.collect.ImmutableSet; import hudson.Extension; import hudson.Util; +import hudson.maven.AbstractMavenBuild; +import hudson.model.FreeStyleBuild; +import hudson.model.FreeStyleProject; import hudson.model.Job; import hudson.model.Run; -import jenkins.model.Jenkins; - import hudson.tasks.test.TestResult; import jenkins.branch.MultiBranchProject; +import jenkins.model.Jenkins; import org.jenkinsci.plugins.displayurlapi.DisplayURLProvider; import org.jenkinsci.plugins.workflow.job.WorkflowJob; import org.jenkinsci.plugins.workflow.job.WorkflowRun; @@ -19,6 +22,9 @@ @Extension public class BlueOceanDisplayURLImpl extends DisplayURLProvider { + private static final ImmutableSet> SUPPORTED_RUNS = ImmutableSet.of(FreeStyleBuild.class, WorkflowRun.class, AbstractMavenBuild.class); + private static final ImmutableSet> SUPPORTED_JOBS = ImmutableSet.of(MultiBranchProject.class, FreeStyleProject.class); + @Override public String getDisplayName() { return "Blue Ocean"; @@ -39,41 +45,60 @@ public String getRoot() { @Override public String getRunURL(Run run) { - if(run instanceof WorkflowRun) { - WorkflowJob job = ((WorkflowRun) run).getParent(); - if(job.getParent() instanceof MultiBranchProject) { - return getJobURL(((MultiBranchProject) job.getParent()))+ "detail/" + Util.rawEncode(job.getDisplayName()) + "/" + run.getNumber() + "/"; + if (isSupported(run)) { + if (run instanceof WorkflowRun) { + WorkflowJob job = ((WorkflowRun) run).getParent(); + if (job.getParent() instanceof MultiBranchProject) { + return getJobURL(((MultiBranchProject) job.getParent())) + "detail/" + Util.rawEncode(job.getDisplayName()) + "/" + run.getNumber() + "/"; + } } + Job job = run.getParent(); + return getJobURL(job) + "detail/" + Util.rawEncode(job.getDisplayName()) + "/" + run.getNumber() + "/"; + } else { + return DisplayURLProvider.getDefault().getRunURL(run); } - - Job job = run.getParent(); - return getJobURL(job) + "detail/" + Util.rawEncode(job.getDisplayName()) + "/" + run.getNumber() + "/"; } @Override public String getChangesURL(Run run) { - return getRunURL(run) + "changes"; + if (isSupported(run)) { + return getRunURL(run) + "changes"; + } else { + return DisplayURLProvider.getDefault().getChangesURL(run); + } } - public String getJobURL(MultiBranchProject project) { - String jobPath = Util.rawEncode(project.getFullName()); - - return getRoot() + "organizations/jenkins/" + jobPath + "/"; - } @Override - public String getJobURL(Job project) { - String jobPath; - if(project.getParent() instanceof MultiBranchProject) { - jobPath = Util.rawEncode(project.getParent().getFullName()); + public String getJobURL(Job job) { + if (isSupported(job)) { + String jobPath; + if(job.getParent() instanceof MultiBranchProject) { + jobPath = Util.rawEncode(job.getParent().getFullName()); + } else { + jobPath = Util.rawEncode(job.getFullName()); + } + return getRoot() + "organizations/jenkins/" + jobPath + "/"; } else { - jobPath = Util.rawEncode(project.getFullName()); + return DisplayURLProvider.getDefault().getJobURL(job); } - - return getRoot() + "organizations/jenkins/" + jobPath + "/"; } @Override public String getTestUrl(TestResult result) { return getRunURL(result.getRun()) + "/tests"; } + + static boolean isSupported(Run run) { + return SUPPORTED_RUNS.contains(run.getClass()); + } + + static boolean isSupported(Job job) { + return SUPPORTED_JOBS.contains(job.getClass()); + } + + private String getJobURL(MultiBranchProject project) { + String jobPath = Util.rawEncode(project.getFullName()); + + return getRoot() + "organizations/jenkins/" + jobPath + "/"; + } }