Skip to content
Permalink
Browse files

JENKINS-41578 Add a system property/environment variable to specify d…

…efault display url impl
  • Loading branch information
i386 committed Jan 30, 2017
1 parent fe66185 commit b195da450cb9d79573f70d4a1d72d80a444df370
Showing with 29 additions and 1 deletion.
  1. +29 −1 src/main/java/org/jenkinsci/plugins/displayurlapi/DisplayURLProvider.java
@@ -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)
@@ -27,7 +31,20 @@ public static DisplayURLProvider get() {
}

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 */
@@ -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.
You can’t perform that action at this time.