File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\jenkins\mvn\FilePathSettingsProvider.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
13 import org.apache.commons.lang.StringUtils;
14 import org.kohsuke.stapler.DataBoundConstructor;
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 class FilePathSettingsProvider extends SettingsProvider {
22
23 private final String path;
24
25 @DataBoundConstructor
26 public FilePathSettingsProvider(String path) {
27 this.path = path;
28 }
29
30 public String getPath() {
31 return path;
32 }
33
34 @Override
35 public FilePath supplySettings(AbstractBuild<?, ?> build, TaskListener listener) {
36 if (StringUtils.isEmpty(path)) {
37 return null;
38 }
39
40 try {
41 EnvVars env = build.getEnvironment(listener);
42 String targetPath = Util.replaceMacro(this.path, build.getBuildVariableResolver());
43 targetPath = env.expand(targetPath);
44
45 if (IOUtils.isAbsolute(targetPath)) {
46 return new FilePath(new File(targetPath));
47 } else {
48 FilePath mrSettings = build.getModuleRoot().child(targetPath);
49 FilePath wsSettings = build.getWorkspace().child(targetPath);
50 try {
51 if (!wsSettings.exists() && mrSettings.exists()) {
52 wsSettings = mrSettings;
53 }
54 } catch (Exception e) {
55 throw new IllegalStateException("failed to find settings.xml at: " + wsSettings.getRemote());
56 }
57 return wsSettings;
58 }
59 } catch (Exception e) {
60 throw new IllegalStateException("failed to prepare settings.xml");
61 }
62 }
63
64 @Extension(ordinal = 10)
65 public static class DescriptorImpl extends SettingsProviderDescriptor {
66
67 @Override
68 public String getDisplayName() {
69 return Messages.FilePathSettingsProvider_DisplayName();
70 }
71 }
72 }
73