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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Olivier Lamy
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.FilePath;
28 import hudson.Launcher;
29 import hudson.model.BuildListener;
30 import hudson.model.Run.RunnerAbortedException;
31 import hudson.model.TaskListener;
32 import hudson.remoting.Callable;
33 import hudson.remoting.Which;
34 import hudson.tasks.Maven.MavenInstallation;
35
36 import java.io.File;
37 import java.io.FilenameFilter;
38 import java.io.IOException;
39
40 import org.jvnet.hudson.maven3.agent.Maven3Main;
41 import org.jvnet.hudson.maven3.launcher.Maven3Launcher;
42
43 /**
44 * @author Olivier Lamy
45 *
46 */
47 public class Maven3ProcessFactory extends AbstractMavenProcessFactory implements ProcessCache.Factory
48 {
49
50 Maven3ProcessFactory(MavenModuleSet mms, Launcher launcher, EnvVars envVars, String mavenOpts, FilePath workDir) {
51 super( mms, launcher, envVars, mavenOpts, workDir );
52 }
53
54 @Override
55 protected String getMavenAgentClassPath(MavenInstallation mvn,boolean isMaster,FilePath slaveRoot,BuildListener listener) throws IOException, InterruptedException {
56 String classWorldsJar = getLauncher().getChannel().call(new GetClassWorldsJar(mvn.getHome(),listener));
57
58 return (isMaster? Which.jarFile(Maven3Main.class).getAbsolutePath():slaveRoot.child("maven3-agent.jar").getRemote())+
59 (getLauncher().isUnix()?":":";")+classWorldsJar;
60 }
61
62 @Override
63 protected String getMainClassName() {
64 return Maven3Main.class.getName();
65 }
66
67 @Override
68 protected String getMavenInterceptorClassPath(MavenInstallation mvn,boolean isMaster,FilePath slaveRoot) throws IOException, InterruptedException {
69 return isMaster?
70 Which.jarFile(Maven3Launcher.class).getAbsolutePath():
71 slaveRoot.child("maven3-interceptor.jar").getRemote();
72 }
73
74 @Override
75 protected String getMavenInterceptorOverride(MavenInstallation mvn,
76 boolean isMaster, FilePath slaveRoot) throws IOException,
77 InterruptedException {
78 return null;
79 }
80
81 /**
82 * Finds classworlds.jar
83 */
84 private static final class GetClassWorldsJar implements Callable<String,IOException> {
85 private static final long serialVersionUID = -2599434124883557137L;
86 private final String mvnHome;
87 private final TaskListener listener;
88
89 private GetClassWorldsJar(String mvnHome, TaskListener listener) {
90 this.mvnHome = mvnHome;
91 this.listener = listener;
92 }
93
94 public String call() throws IOException {
95 File home = new File(mvnHome);
96 if (MavenProcessFactory.debug)
97 listener.getLogger().println("Using mvnHome: "+ mvnHome);
98 File bootDir = new File(home, "boot");
99 File[] classworlds = bootDir.listFiles(CLASSWORLDS_FILTER);
100 if(classworlds==null || classworlds.length==0) {
101 listener.error(Messages.MavenProcessFactory_ClassWorldsNotFound(home));
102 throw new RunnerAbortedException();
103 }
104 return classworlds[0].getAbsolutePath();
105 }
106 }
107 /**
108 * Locates classworlds jar file.
109 *
110 * Note that Maven 3.0 changed the name to plexus-classworlds
111 *
112 * <pre>
113 * $ find tools/ -name "plexus-classworlds*.jar"
114 * tools/maven-3.0-alpha-2/boot/plexus-classworlds-1.3.jar
115 * tools/maven-3.0-alpha-3/boot/plexus-classworlds-2.2.2.jar
116 * tools/maven-3.0-alpha-4/boot/plexus-classworlds-2.2.2.jar
117 * tools/maven-3.0-alpha-5/boot/plexus-classworlds-2.2.2.jar
118 * tools/maven-3.0-alpha-6/boot/plexus-classworlds-2.2.2.jar
119 * </pre>
120 */
121 private static final FilenameFilter CLASSWORLDS_FILTER = new FilenameFilter() {
122 public boolean accept(File dir, String name) {
123 return name.contains("plexus-classworlds") && name.endsWith(".jar");
124 }
125 };
126
127 }
128