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.nio.file.Files;
22 import java.nio.file.Path;
23 import java.nio.file.Paths;
24
25 import org.apache.maven.toolchain.DefaultToolchain;
26 import org.apache.maven.toolchain.model.ToolchainModel;
27 import org.apache.maven.utils.Os;
28 import org.slf4j.Logger;
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 Path toRet = findTool(toolName, Paths.get(getJavaHome()).normalize());
58 if (toRet != null) {
59 return toRet.toAbsolutePath().toString();
60 }
61 return null;
62 }
63
64 private static Path findTool(String toolName, Path installDir) {
65 Path bin = installDir.resolve("bin");
66 if (Files.isDirectory(bin)) {
67 if (Os.IS_WINDOWS) {
68 Path tool = bin.resolve(toolName + ".exe");
69 if (Files.exists(tool)) {
70 return tool;
71 }
72 }
73 Path tool = bin.resolve(toolName);
74 if (Files.exists(tool)) {
75 return tool;
76 }
77 }
78 return null;
79 }
80 }