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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, CloudBees, Inc.
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.EnvVars;
27 import hudson.model.AbstractProject;
28 import hudson.model.Action;
29 import jenkins.model.Jenkins;
30 import hudson.remoting.Channel;
31 import hudson.util.RemotingDiagnostics;
32 import hudson.util.RemotingDiagnostics.HeapDump;
33 import org.kohsuke.stapler.StaplerRequest;
34 import org.kohsuke.stapler.StaplerResponse;
35
36 import javax.servlet.ServletException;
37 import java.io.IOException;
38 import java.util.Map;
39
40 /**
41 * UI for probing Maven process.
42 *
43 * <p>
44 * This action is added to a build when it's started, and removed
45 * when it's completed.
46 *
47 * @author Kohsuke Kawaguchi
48 * @since 1.175
49 */
50 public final class MavenProbeAction implements Action {
51 private final transient Channel channel;
52
53 public final AbstractProject<?,?> owner;
54
55 MavenProbeAction(AbstractProject<?,?> owner, Channel channel) {
56 this.channel = channel;
57 this.owner = owner;
58 }
59
60 public String getIconFileName() {
61 if(channel==null) return null;
62 return "computer.gif";
63 }
64
65 public String getDisplayName() {
66 return Messages.MavenProbeAction_DisplayName();
67 }
68
69 public String getUrlName() {
70 if(channel==null) return null;
71 return "probe";
72 }
73
74 /**
75 * Gets the system properties of the JVM on this computer.
76 * If this is the master, it returns the system property of the master computer.
77 */
78 public Map<Object,Object> getSystemProperties() throws IOException, InterruptedException {
79 return RemotingDiagnostics.getSystemProperties(channel);
80 }
81
82 /**
83 * Gets the environment variables of the JVM on this computer.
84 * If this is the master, it returns the system property of the master computer.
85 */
86 public Map<String,String> getEnvVars() throws IOException, InterruptedException {
87 return EnvVars.getRemote(channel);
88 }
89
90 /**
91 * Gets the thread dump of the slave JVM.
92 * @return
93 * key is the thread name, and the value is the pre-formatted dump.
94 */
95 public Map<String,String> getThreadDump() throws IOException, InterruptedException {
96 return RemotingDiagnostics.getThreadDump(channel);
97 }
98
99 public void doScript( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
100 // ability to run arbitrary script is dangerous,
101 // so tie it to the admin access
102 owner.checkPermission(Jenkins.RUN_SCRIPTS);
103
104 String text = req.getParameter("script");
105 if(text!=null) {
106 try {
107 req.setAttribute("output",
108 RemotingDiagnostics.executeGroovy(text,channel));
109 } catch (InterruptedException e) {
110 throw new ServletException(e);
111 }
112 }
113
114 req.getView(this,"_script.jelly").forward(req,rsp);
115 }
116
117 /**
118 * Obtains the heap dump.
119 */
120 public HeapDump getHeapDump() throws IOException {
121 return new HeapDump(owner,channel);
122 }
123 }
124