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 import org.apache.maven.toolchain.DefaultToolchain;
23 import org.apache.maven.toolchain.model.ToolchainModel;
24 import org.codehaus.plexus.util.FileUtils;
25 import org.codehaus.plexus.util.Os;
26 import org.slf4j.Logger;
27
28
29
30
31
32
33
34 class JavaToolchainImpl extends DefaultToolchain implements JavaToolchain {
35 private String javaHome;
36
37 public static final String KEY_JAVAHOME = "jdkHome";
38
39 JavaToolchainImpl(ToolchainModel model, Logger logger) {
40 super(model, "jdk", logger);
41 }
42
43 public String getJavaHome() {
44 return javaHome;
45 }
46
47 public void setJavaHome(String javaHome) {
48 this.javaHome = javaHome;
49 }
50
51 public String toString() {
52 return "JDK[" + getJavaHome() + "]";
53 }
54
55 public String findTool(String toolName) {
56 File toRet = findTool(toolName, new File(FileUtils.normalize(getJavaHome())));
57 if (toRet != null) {
58 return toRet.getAbsolutePath();
59 }
60 return null;
61 }
62
63 private static File findTool(String toolName, File installFolder) {
64 File bin = new File(installFolder, "bin");
65 if (bin.exists()) {
66 boolean isWindows = Os.isFamily("windows");
67 if (isWindows) {
68 File tool = new File(bin, toolName + ".exe");
69 if (tool.exists()) {
70 return tool;
71 }
72 }
73 File tool = new File(bin, toolName);
74 if (tool.exists()) {
75 return tool;
76 }
77 }
78 return null;
79 }
80 }