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