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
36 @Deprecated(since = "4.0.0")
37 public class JavaToolchainImpl extends DefaultToolchain implements JavaToolchain {
38 private String javaHome;
39
40 public static final String KEY_JAVAHOME = "jdkHome";
41
42 JavaToolchainImpl(ToolchainModel model, Logger logger) {
43 super(model, "jdk", logger);
44 }
45
46 public String getJavaHome() {
47 return javaHome;
48 }
49
50 public void setJavaHome(String javaHome) {
51 this.javaHome = javaHome;
52 }
53
54 @Override
55 public String toString() {
56 return "JDK[" + getJavaHome() + "]";
57 }
58
59 @Override
60 public String findTool(String toolName) {
61 Path toRet = findTool(toolName, Paths.get(getJavaHome()).normalize());
62 if (toRet != null) {
63 return toRet.toAbsolutePath().toString();
64 }
65 return null;
66 }
67
68 private static Path findTool(String toolName, Path installDir) {
69 Path bin = installDir.resolve("bin");
70 if (Files.isDirectory(bin)) {
71 if (Os.IS_WINDOWS) {
72 Path tool = bin.resolve(toolName + ".exe");
73 if (Files.exists(tool)) {
74 return tool;
75 }
76 }
77 Path tool = bin.resolve(toolName);
78 if (Files.exists(tool)) {
79 return tool;
80 }
81 }
82 return null;
83 }
84 }