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 GlobalSettingsProvider extends AbstractDescribableImpl<GlobalSettingsProvider> implements ExtensionPoint {
24
* configure maven launcher argument list with adequate settings path
27
* the build to provide the settigns for
28
* @return the filepath to the provided file. <code>null</code> if no settings will be provided.
30
public abstract FilePath supplySettings(AbstractBuild<?, ?> build, TaskListener listener);
32
public static GlobalSettingsProvider parseSettingsProvider(StaplerRequest req) throws Descriptor.FormException, ServletException {
33
JSONObject settings = req.getSubmittedForm().getJSONObject("globalSettings");
34
if (settings == null) {
35
return new DefaultGlobalSettingsProvider();
37
return req.bindJSON(GlobalSettingsProvider.class, settings);
41
* Convenience method handling all <code>null</code> checks. Provides the path on the (possible) remote settings file.
44
* the provider to be used
48
* the listener of the current build
49
* @return the path to the global settings.xml
51
public static final FilePath getSettingsFilePath(GlobalSettingsProvider settings, AbstractBuild<?, ?> build, TaskListener listener) {
52
FilePath settingsPath = null;
53
if (settings != null) {
55
settingsPath = settings.supplySettings(build, listener);
56
} catch (Exception e) {
57
listener.getLogger().print("failed to get the path to the alternate global settings.xml");
64
* Convenience method handling all <code>null</code> checks. Provides the path on the (possible) remote settings file.
67
* the provider to be used
71
* the listener of the current build
72
* @return the path to the global settings.xml
74
public static final String getSettingsRemotePath(GlobalSettingsProvider provider, AbstractBuild<?, ?> build, TaskListener listener) {
75
FilePath fp = getSettingsFilePath(provider, build, listener);
76
return fp == null ? null : fp.getRemote();