1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.toolchain.java;
20
21 import java.io.File;
22
23 import org.apache.maven.toolchain.DefaultToolchain;
24 import org.apache.maven.toolchain.model.ToolchainModel;
25 import org.codehaus.plexus.logging.Logger;
26 import org.codehaus.plexus.util.FileUtils;
27 import org.codehaus.plexus.util.Os;
28
29
30
31
32
33
34
35 public class JavaToolchainImpl extends DefaultToolchain implements JavaToolchain {
36 private String javaHome;
37
38 public static final String KEY_JAVAHOME = "jdkHome";
39
40 JavaToolchainImpl(ToolchainModel model, Logger logger) {
41 super(model, "jdk", logger);
42 }
43
44 public String getJavaHome() {
45 return javaHome;
46 }
47
48 public void setJavaHome(String javaHome) {
49 this.javaHome = javaHome;
50 }
51
52 public String toString() {
53 return "JDK[" + getJavaHome() + "]";
54 }
55
56 public String findTool(String toolName) {
57 File toRet = findTool(toolName, new File(FileUtils.normalize(getJavaHome())));
58 if (toRet != null) {
59 return toRet.getAbsolutePath();
60 }
61 return null;
62 }
63
64 private static File findTool(String toolName, File installDir) {
65 File bin = new File(installDir, "bin");
66 if (bin.exists()) {
67 boolean isWindows = Os.isFamily("windows");
68 if (isWindows) {
69 File tool = new File(bin, toolName + ".exe");
70 if (tool.exists()) {
71 return tool;
72 }
73 }
74 File tool = new File(bin, toolName);
75 if (tool.exists()) {
76 return tool;
77 }
78 }
79 return null;
80 }
81 }