3
import hudson.ExtensionPoint;
4
import hudson.FilePath;
5
import hudson.model.AbstractBuild;
6
import hudson.model.AbstractDescribableImpl;
7
import hudson.model.Descriptor;
8
import hudson.model.TaskListener;
10
import javax.servlet.ServletException;
12
import net.sf.json.JSONObject;
14
import org.kohsuke.stapler.StaplerRequest;
17
* @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
18
* @author Dominik Bartholdi (imod)
21
public abstract class SettingsProvider extends AbstractDescribableImpl<SettingsProvider> implements ExtensionPoint {
24
* Configure maven launcher argument list with adequate settings path. Implementations should be aware that this method might get called multiple times during a build.
27
* @return the filepath to the provided file. <code>null</code> if no settings will be provided.
29
public abstract FilePath supplySettings(AbstractBuild<?, ?> build, TaskListener listener);
31
public static SettingsProvider parseSettingsProvider(StaplerRequest req) throws Descriptor.FormException, ServletException {
32
JSONObject settings = req.getSubmittedForm().getJSONObject("settings");
33
if (settings == null) {
34
return new DefaultSettingsProvider();
36
return req.bindJSON(SettingsProvider.class, settings);
40
* Convenience method handling all <code>null</code> checks. Provides the path on the (possible) remote settings file.
43
* the provider to be used
47
* the listener of the current build
48
* @return the path to the settings.xml
50
public static final FilePath getSettingsFilePath(SettingsProvider settings, AbstractBuild<?, ?> build, TaskListener listener) {
51
FilePath settingsPath = null;
52
if (settings != null) {
53
settingsPath = settings.supplySettings(build, listener);
59
* Convenience method handling all <code>null</code> checks. Provides the path on the (possible) remote settings file.
62
* the provider to be used
66
* the listener of the current build
67
* @return the path to the settings.xml
69
public static final String getSettingsRemotePath(SettingsProvider settings, AbstractBuild<?, ?> build, TaskListener listener) {
70
FilePath fp = getSettingsFilePath(settings, build, listener);
71
return fp == null ? null : fp.getRemote();