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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Red Hat, Inc., Victor Glushenkov
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.AbstractBuild;
28 import hudson.model.TaskListener;
29 import hudson.util.ReflectionUtils;
30
31 import java.io.File;
32 import java.io.IOException;
33 import java.lang.reflect.Method;
34 import java.util.Calendar;
35 import java.util.logging.Level;
36 import java.util.logging.Logger;
37
38 public abstract class AbstractMavenBuild<P extends AbstractMavenProject<P,B>,B extends AbstractMavenBuild<P,B>> extends AbstractBuild<P, B> {
39
40 /**
41 * Extra verbose debug switch.
42 */
43 public static boolean debug = false;
44
45 protected AbstractMavenBuild(P job) throws IOException {
46 super(job);
47 }
48
49 public AbstractMavenBuild(P job, Calendar timestamp) {
50 super(job, timestamp);
51 }
52
53 public AbstractMavenBuild(P project, File buildDir) throws IOException {
54 super(project, buildDir);
55 }
56
57 @Override
58 public EnvVars getEnvironment(TaskListener log) throws IOException, InterruptedException {
59 EnvVars envs = super.getEnvironment(log);
60
61 String opts = getMavenOpts(log,envs);
62
63 if(opts!=null)
64 envs.put("MAVEN_OPTS", opts);
65
66 return envs;
67 }
68
69 /**
70 * Obtains the fully resolved MAVEN_OPTS with all the tokens and variables expanded.
71 *
72 * @see MavenModuleSet#getMavenOpts()
73 * @param envVars
74 * Caller must pass in the environment variables obtained from {@link #getEnvironment(TaskListener)}
75 * This method takes this as a parameter as opposed to recomputing it since the caller always have this handy.
76 */
77 public abstract String getMavenOpts(TaskListener listener, EnvVars envVars);
78
79 /**
80 * Expand tokens with token macro.
81 */
82 protected final String expandTokens(TaskListener listener, String str) {
83 if (str==null) return null;
84 try {
85 Class<?> clazz = Class.forName( "org.jenkinsci.plugins.tokenmacro.TokenMacro" );
86 Method expandMethod =
87 ReflectionUtils.findMethod(clazz, "expand", new Class[]{AbstractBuild.class, TaskListener.class, String.class});
88 return (String) expandMethod.invoke( null, this, listener, str );
89 //opts = TokenMacro.expand(this, listener, opts);
90 }
91 catch(Exception tokenException) {
92 //Token plugin not present. Ignore, this is OK.
93 LOGGER.log(Level.FINE, "Ignore problem in expanding tokens", tokenException);
94 }
95 catch(LinkageError linkageError) {
96 // Token plugin not present. Ignore, this is OK.
97 LOGGER.log(Level.FINE, "Ignore problem in expanding tokens", linkageError);
98 }
99 return str;
100 }
101
102 private static final Logger LOGGER = Logger.getLogger(AbstractMavenBuild.class.getName());
103 }
104