Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
JENKINS-41578 Add a system property/environment variable to specify d…
…efault display url impl
  • Loading branch information
James Dumay committed Jan 30, 2017
1 parent fe66185 commit b195da4
Showing 1 changed file with 29 additions and 1 deletion.
@@ -1,14 +1,18 @@
package org.jenkinsci.plugins.displayurlapi;

import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import hudson.ExtensionPoint;
import hudson.Util;
import hudson.model.Job;
import hudson.model.Run;
import jenkins.model.Jenkins;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.displayurlapi.actions.AbstractDisplayAction;

import static org.apache.commons.lang.StringUtils.isNotEmpty;

/**
* Generates URLs for well known UI locations for use in notifications (e.g. mailer, HipChat, Slack, IRC, etc)
* Extensible to allow plugins to override common URLs (e.g. Blue Ocean or another future secondary UI)
Expand All @@ -27,7 +31,20 @@ public static Iterable<DisplayURLProvider> all() {
}

public static DisplayURLProvider getDefault() {
return Iterables.find(all(), Predicates.instanceOf(ClassicDisplayURLProvider.class));
DisplayURLProvider defaultProvider = Iterables.find(all(), Predicates.instanceOf(ClassicDisplayURLProvider.class));

// Get the default provider from environment variable or system property
final String clazz = findClass();
if (isNotEmpty(clazz)) {
defaultProvider = Iterables.find(DisplayURLProvider.all(), new Predicate<DisplayURLProvider>() {
@Override
public boolean apply(DisplayURLProvider input) {
return input.getClass().getName().equals(clazz);
}
});
}

return defaultProvider;
}

/** Fully qualified URL for the Root display URL */
Expand Down Expand Up @@ -84,11 +101,22 @@ public String getTestUrl(hudson.tasks.test.TestResult result) {
}
}

private static String findClass() {
String clazz = System.getenv(JENKINS_DISPLAYURL_PROVIDER_ENV);
if (StringUtils.isEmpty(clazz)) {
clazz = System.getProperty(JENKINS_DISPLAYURL_PROVIDER_PROP);
}
return clazz;
}

private static Jenkins getJenkins() {
Jenkins jenkins = Jenkins.getInstance();
if (jenkins == null) {
throw new IllegalStateException("Jenkins has not started");
}
return jenkins;
}

private static final String JENKINS_DISPLAYURL_PROVIDER_ENV = "JENKINS_DISPLAYURL_PROVIDER";
private static final String JENKINS_DISPLAYURL_PROVIDER_PROP = "jenkins.displayurl.provider";
}

0 comments on commit b195da4

Please sign in to comment.