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