File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\maven-plugin\src\main\java\hudson\maven\MavenProcessFactory.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;
25
26 import hudson.FilePath;
27 import hudson.Launcher;
28 import hudson.EnvVars;
29 import hudson.maven.agent.Main;
30 import hudson.maven.agent.Maven21Interceptor;
31 import hudson.model.BuildListener;
32 import hudson.model.Run.RunnerAbortedException;
33 import hudson.model.TaskListener;
34 import hudson.remoting.Callable;
35 import hudson.remoting.Which;
36 import hudson.tasks.Maven.MavenInstallation;
37
38 import java.io.File;
39 import java.io.FilenameFilter;
40 import java.io.IOException;
41
42
43 /**
44 * Launches the maven process.
45 *
46 * @author Kohsuke Kawaguchi
47 */
48 final class MavenProcessFactory extends AbstractMavenProcessFactory implements ProcessCache.Factory {
49
50
51 MavenProcessFactory(MavenModuleSet mms, Launcher launcher, EnvVars envVars, String mavenOpts, FilePath workDir) {
52 super( mms, launcher, envVars, mavenOpts, workDir );
53 }
54
55 @Override
56 protected String getMavenAgentClassPath(MavenInstallation mvn,boolean isMaster,FilePath slaveRoot,BuildListener listener) throws IOException, InterruptedException {
57 String classWorldsJar = getLauncher().getChannel().call(new GetClassWorldsJar(mvn.getHome(),listener));
58 String classPath =
59 ( isMaster ? Which.jarFile( Main.class ).getAbsolutePath()
60 : slaveRoot.child( "maven-agent.jar" ).getRemote() )
61 + ( getLauncher().isUnix() ? ":" : ";" )
62 + ( isMaster ? classWorldsJar : slaveRoot.child( "classworlds.jar" ).getRemote() );
63 return classPath;
64 }
65
66 protected String getMainClassName() {
67 return Main.class.getName();
68 }
69
70 @Override
71 protected String getMavenInterceptorClassPath(MavenInstallation mvn,boolean isMaster,FilePath slaveRoot) throws IOException, InterruptedException {
72 return isMaster?
73 Which.jarFile(hudson.maven.agent.AbortException.class).getAbsolutePath():
74 slaveRoot.child("maven-interceptor.jar").getRemote();
75 }
76
77 @Override
78 protected String getMavenInterceptorOverride(MavenInstallation mvn,
79 boolean isMaster, FilePath slaveRoot) throws IOException,
80 InterruptedException {
81 if(mvn.isMaven2_1(getLauncher())) {
82 return isMaster?
83 Which.jarFile(Maven21Interceptor.class).getAbsolutePath():
84 slaveRoot.child("maven2.1-interceptor.jar").getRemote();
85 }
86 return null;
87 }
88
89 /**
90 * Finds classworlds.jar
91 */
92 private static final class GetClassWorldsJar implements Callable<String,IOException> {
93 private static final long serialVersionUID = 5812919424079344101L;
94 private final String mvnHome;
95 private final TaskListener listener;
96
97 private GetClassWorldsJar(String mvnHome, TaskListener listener) {
98 this.mvnHome = mvnHome;
99 this.listener = listener;
100 }
101
102 public String call() throws IOException {
103 File home = new File(mvnHome);
104 File bootDir = new File(home, "core/boot");
105 File[] classworlds = bootDir.listFiles(CLASSWORLDS_FILTER);
106 if(classworlds==null || classworlds.length==0) {
107 // Maven 2.0.6 puts it to a different place
108 bootDir = new File(home, "boot");
109 classworlds = bootDir.listFiles(CLASSWORLDS_FILTER);
110 if(classworlds==null || classworlds.length==0) {
111 listener.error(Messages.MavenProcessFactory_ClassWorldsNotFound(home));
112 throw new RunnerAbortedException();
113 }
114 }
115 return classworlds[0].getAbsolutePath();
116 }
117 }
118
119 /**
120 * Locates classworlds jar file.
121 *
122 * Note that Maven 3.0 changed the name to plexus-classworlds
123 *
124 * <pre>
125 * $ find tools/ -name "*classworlds*.jar"
126 * tools/maven/boot/classworlds-1.1.jar
127 * tools/maven-2.2.1/boot/classworlds-1.1.jar
128 * tools/maven-3.0-alpha-2/boot/plexus-classworlds-1.3.jar
129 * tools/maven-3.0-alpha-3/boot/plexus-classworlds-2.2.2.jar
130 * tools/maven-3.0-alpha-4/boot/plexus-classworlds-2.2.2.jar
131 * tools/maven-3.0-alpha-5/boot/plexus-classworlds-2.2.2.jar
132 * tools/maven-3.0-alpha-6/boot/plexus-classworlds-2.2.2.jar
133 * </pre>
134 */
135 private static final FilenameFilter CLASSWORLDS_FILTER = new FilenameFilter() {
136 public boolean accept(File dir, String name) {
137 return name.contains("classworlds") && name.endsWith(".jar");
138 }
139 };
140
141 //-------------------------------------------------
142 // Some of those fields are used for maven 3 too
143 //-------------------------------------------------
144
145 /**
146 * Set true to produce debug output.
147 */
148 public static boolean debug = false;
149
150 public static boolean profile = Boolean.getBoolean("hudson.maven.profile");
151
152 public static int socketTimeOut = Integer.parseInt( System.getProperty( "hudson.maven.socketTimeOut", Integer.toString( 30*1000 ) ) );
153 }
154