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

1 package jenkins.mvn;
2
3 import hudson.EnvVars;
4 import hudson.Extension;
5 import hudson.FilePath;
6 import hudson.Util;
7 import hudson.model.AbstractBuild;
8 import hudson.model.TaskListener;
9 import hudson.util.IOUtils;
10
11 import java.io.File;
12 import java.io.IOException;
13
14 import org.apache.commons.lang.StringUtils;
15 import org.kohsuke.stapler.DataBoundConstructor;
16
17 /**
18 * @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
19 * @author Dominik Bartholdi (imod)
20 * @since 1.491
21 */
22 public class FilePathGlobalSettingsProvider extends GlobalSettingsProvider {
23
24 private final String path;
25
26 @DataBoundConstructor
27 public FilePathGlobalSettingsProvider(String path) {
28 this.path = path;
29 }
30
31 public String getPath() {
32 return path;
33 }
34
35 @Override
36 public FilePath supplySettings(AbstractBuild<?, ?> build, TaskListener listener) {
37 if (StringUtils.isEmpty(path)) {
38 return null;
39 }
40
41 try {
42 EnvVars env = build.getEnvironment(listener);
43 String targetPath = Util.replaceMacro(this.path, build.getBuildVariableResolver());
44 targetPath = env.expand(targetPath);
45
46 if (IOUtils.isAbsolute(targetPath)) {
47 return new FilePath(new File(targetPath));
48 } else {
49 FilePath mrSettings = build.getModuleRoot().child(targetPath);
50 FilePath wsSettings = build.getWorkspace().child(targetPath);
51 try {
52 if (!wsSettings.exists() && mrSettings.exists()) {
53 wsSettings = mrSettings;
54 }
55 } catch (Exception e) {
56 throw new IllegalStateException("failed to find settings.xml at: " + wsSettings.getRemote());
57 }
58 return wsSettings;
59 }
60 } catch (Exception e) {
61 throw new IllegalStateException("failed to prepare global settings.xml");
62 }
63
64 }
65
66 @Extension(ordinal = 10)
67 public static class DescriptorImpl extends GlobalSettingsProviderDescriptor {
68
69 @Override
70 public String getDisplayName() {
71 return Messages.FilePathGlobalSettingsProvider_DisplayName();
72 }
73
74 }
75 }
76