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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Tom Huybrechts
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson.maven;
25
26 import hudson.Extension;
27 import hudson.Launcher;
28 import hudson.maven.reporters.SurefireReport;
29 import hudson.model.AbstractBuild;
30 import hudson.model.AbstractProject;
31 import hudson.model.BuildListener;
32 import hudson.model.Descriptor;
33 import hudson.model.Saveable;
34 import hudson.tasks.BuildStepDescriptor;
35 import hudson.tasks.BuildStepMonitor;
36 import hudson.tasks.Publisher;
37 import hudson.tasks.Recorder;
38 import hudson.tasks.junit.TestDataPublisher;
39 import hudson.tasks.junit.TestResultAction.Data;
40 import hudson.util.DescribableList;
41
42 import java.io.IOException;
43 import java.util.ArrayList;
44 import java.util.List;
45
46 import net.sf.json.JSONObject;
47
48 import org.kohsuke.stapler.StaplerRequest;
49
50 /**
51 * Augments {@link SurefireReport} by executing {@link TestDataPublisher}s.
52 * @since 1.320
53 */
54 public class MavenTestDataPublisher extends Recorder {
55
56 private final DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>> testDataPublishers;
57
58 public MavenTestDataPublisher(
59 DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>> testDataPublishers) {
60 super();
61 this.testDataPublishers = testDataPublishers;
62 }
63
64 public BuildStepMonitor getRequiredMonitorService() {
65 return BuildStepMonitor.STEP;
66 }
67
68 public boolean perform(AbstractBuild<?,?> build, Launcher launcher,
69 BuildListener listener) throws InterruptedException, IOException {
70
71 SurefireReport report = build.getAction(SurefireReport.class);
72 if (report == null) {
73 return true;
74 }
75
76 List<Data> data = new ArrayList<Data>();
77 if (testDataPublishers != null) {
78 for (TestDataPublisher tdp : testDataPublishers) {
79 Data d = tdp.getTestData(build, launcher, listener, report.getResult());
80 if (d != null) {
81 data.add(d);
82 }
83 }
84 }
85
86 report.setData(data);
87
88 return true;
89 }
90
91 public DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>> getTestDataPublishers() {
92 return testDataPublishers;
93 }
94
95 @Extension
96 public static class DescriptorImpl extends BuildStepDescriptor<Publisher> {
97
98 @Override
99 public String getDisplayName() {
100 return "Additional test report features";
101 }
102
103 @Override
104 public boolean isApplicable(Class<? extends AbstractProject> jobType) {
105 return MavenModuleSet.class.isAssignableFrom(jobType) && !TestDataPublisher.all().isEmpty();
106 }
107
108 @Override
109 public Publisher newInstance(StaplerRequest req, JSONObject formData) throws FormException {
110 DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>> testDataPublishers
111 = new DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>>(Saveable.NOOP);
112 try {
113 testDataPublishers.rebuild(req, formData, TestDataPublisher.all());
114 } catch (IOException e) {
115 throw new FormException(e,null);
116 }
117
118 return new MavenTestDataPublisher(testDataPublishers);
119 }
120
121 }
122
123 }
124