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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
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.reporters;
25
26 import hudson.maven.MavenModule;
27 import hudson.maven.MavenReporter;
28 import hudson.maven.MavenReporterDescriptor;
29 import hudson.maven.MavenBuildProxy;
30 import hudson.maven.MojoInfo;
31 import hudson.maven.MavenBuild;
32 import hudson.maven.MavenBuildProxy.BuildCallable;
33 import hudson.model.BuildListener;
34 import jenkins.model.Jenkins;
35 import hudson.Extension;
36 import org.apache.maven.project.MavenProject;
37 import org.codehaus.plexus.configuration.PlexusConfiguration;
38 import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
39
40 import java.io.IOException;
41 import java.util.Set;
42 import java.util.HashSet;
43 import java.util.Arrays;
44 import java.util.Map;
45 import java.util.HashMap;
46 import java.util.Map.Entry;
47
48 /**
49 * @author Kohsuke Kawaguchi
50 */
51 public class BuildInfoRecorder extends MavenReporter {
52
53 private static final Set<String> keys = new HashSet<String>(Arrays.asList(
54 "maven-jar-plugin:jar",
55 "maven-jar-plugin:test-jar",
56 "maven-war-plugin:war",
57 "maven-ear-plugin:ear"
58 ));
59
60 public boolean preExecute(MavenBuildProxy build, MavenProject pom, MojoInfo mojo, BuildListener listener) throws InterruptedException, IOException {
61 if(mojo.pluginName.groupId.equals("org.apache.maven.plugins")
62 && keys.contains(mojo.pluginName.artifactId+':'+mojo.getGoal())) {
63 // touch <archive><manifestEntries><Build-Numer>#n
64
65 Map<String,String> props = build.execute(new BuildCallable<Map<String,String>,IOException>() {
66 private static final long serialVersionUID = 7810179928341972415L;
67
68 public Map<String,String> call(MavenBuild build) throws IOException, InterruptedException {
69 Map<String,String> r = new HashMap<String, String>();
70 // leave Hudson for backward comp
71 r.put("Hudson-Build-Number",String.valueOf(build.getNumber()));
72 r.put("Hudson-Project",build.getParent().getParent().getName());
73 r.put("Hudson-Version", Jenkins.VERSION);
74 r.put("Jenkins-Build-Number",String.valueOf(build.getNumber()));
75 r.put("Jenkins-Project",build.getParent().getParent().getName());
76 r.put("Jenkins-Version", Jenkins.VERSION);
77 return r;
78 }
79 });
80
81 PlexusConfiguration archive = mojo.configuration.getChild("archive");
82 PlexusConfiguration manifestEntries = archive.getChild("manifestEntries",true);
83 for (Entry<String,String> e : props.entrySet()) {
84 if(manifestEntries.getChild(e.getKey(),false)!=null)
85 continue; // if the configuration is already given, use that.
86 XmlPlexusConfiguration configuration = new XmlPlexusConfiguration(e.getKey());
87 configuration.setValue(e.getValue());
88 manifestEntries.addChild(configuration);
89 }
90 }
91
92 return super.preExecute(build, pom, mojo, listener);
93 }
94
95 @Extension
96 public static final class DescriptorImpl extends MavenReporterDescriptor {
97 public String getDisplayName() {
98 return Messages.BuildInfoRecorder_DisplayName();
99 }
100
101
102 public BuildInfoRecorder newAutoInstance(MavenModule module) {
103 return new BuildInfoRecorder();
104 }
105 }
106
107 private static final long serialVersionUID = 1L;
108 }
109