File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\jenkins\mvn\SettingsProvider.java.html

1 package jenkins.mvn;
2
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;
9
10 import javax.servlet.ServletException;
11
12 import net.sf.json.JSONObject;
13
14 import org.kohsuke.stapler.StaplerRequest;
15
16 /**
17 * @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
18 * @author Dominik Bartholdi (imod)
19 * @since 1.491
20 */
21 public abstract class SettingsProvider extends AbstractDescribableImpl<SettingsProvider> implements ExtensionPoint {
22
23 /**
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.
25 *
26 * @param build
27 * @return the filepath to the provided file. <code>null</code> if no settings will be provided.
28 */
29 public abstract FilePath supplySettings(AbstractBuild<?, ?> build, TaskListener listener);
30
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();
35 }
36 return req.bindJSON(SettingsProvider.class, settings);
37 }
38
39 /**
40 * Convenience method handling all <code>null</code> checks. Provides the path on the (possible) remote settings file.
41 *
42 * @param settings
43 * the provider to be used
44 * @param build
45 * the active build
46 * @param listener
47 * the listener of the current build
48 * @return the path to the settings.xml
49 */
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);
54 }
55 return settingsPath;
56 }
57
58 /**
59 * Convenience method handling all <code>null</code> checks. Provides the path on the (possible) remote settings file.
60 *
61 * @param settings
62 * the provider to be used
63 * @param build
64 * the active build
65 * @param listener
66 * the listener of the current build
67 * @return the path to the settings.xml
68 */
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();
72 }
73
74 }
75