1 package org.apache.maven.toolchain.java;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23
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 class JavaToolchainImpl
37 extends DefaultToolchain
38 implements JavaToolchain
39 {
40 private String javaHome;
41
42 public static final String KEY_JAVAHOME = "jdkHome";
43
44 JavaToolchainImpl( ToolchainModel model, Logger logger )
45 {
46 super( model, "jdk", logger );
47 }
48
49 public String getJavaHome()
50 {
51 return javaHome;
52 }
53
54 public void setJavaHome( String javaHome )
55 {
56 this.javaHome = javaHome;
57 }
58
59 public String toString()
60 {
61 return "JDK[" + getJavaHome() + "]";
62 }
63
64 public String findTool( String toolName )
65 {
66 File toRet = findTool( toolName, new File( FileUtils.normalize( getJavaHome() ) ) );
67 if ( toRet != null )
68 {
69 return toRet.getAbsolutePath();
70 }
71 return null;
72 }
73
74 private static File findTool( String toolName, File installFolder )
75 {
76 File bin = new File( installFolder, "bin" );
77 if ( bin.exists() )
78 {
79 File tool = new File( bin, toolName + ( Os.isFamily( "windows" ) ? ".exe" : "" ) );
80 if ( tool.exists() )
81 {
82 return tool;
83 }
84 }
85 return null;
86 }
87 }