File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\jenkins\mvn\GlobalSettingsProvider.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 GlobalSettingsProvider extends AbstractDescribableImpl<GlobalSettingsProvider> implements ExtensionPoint {
22
23 /**
24 * configure maven launcher argument list with adequate settings path
25 *
26 * @param build
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.
29 */
30 public abstract FilePath supplySettings(AbstractBuild<?, ?> build, TaskListener listener);
31
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();
36 }
37 return req.bindJSON(GlobalSettingsProvider.class, settings);
38 }
39
40 /**
41 * Convenience method handling all <code>null</code> checks. Provides the path on the (possible) remote settings file.
42 *
43 * @param settings
44 * the provider to be used
45 * @param build
46 * the active build
47 * @param listener
48 * the listener of the current build
49 * @return the path to the global settings.xml
50 */
51 public static final FilePath getSettingsFilePath(GlobalSettingsProvider settings, AbstractBuild<?, ?> build, TaskListener listener) {
52 FilePath settingsPath = null;
53 if (settings != null) {
54 try {
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");
58 }
59 }
60 return settingsPath;
61 }
62
63 /**
64 * Convenience method handling all <code>null</code> checks. Provides the path on the (possible) remote settings file.
65 *
66 * @param settings
67 * the provider to be used
68 * @param build
69 * the active build
70 * @param listener
71 * the listener of the current build
72 * @return the path to the global settings.xml
73 */
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();
77 }
78
79 }
80