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.component.annotations.Component;
27 import org.codehaus.plexus.logging.Logger;
28 import org.codehaus.plexus.util.FileUtils;
29 import org.codehaus.plexus.util.Os;
30
31
32
33
34 @Component( role = JavaToolChain.class )
35 public class DefaultJavaToolChain
36 extends DefaultToolchain
37 implements JavaToolChain
38 {
39 private String javaHome;
40
41 public static final String KEY_JAVAHOME = "jdkHome";
42
43 public DefaultJavaToolChain( ToolchainModel model, Logger logger )
44 {
45 super( model, "jdk", logger );
46 }
47
48 public String getJavaHome()
49 {
50 return javaHome;
51 }
52
53 public void setJavaHome( String javaHome )
54 {
55 this.javaHome = javaHome;
56 }
57
58 public String toString()
59 {
60 return "JDK[" + getJavaHome() + "]";
61 }
62
63 public String findTool( String toolName )
64 {
65 File toRet = findTool( toolName, new File( FileUtils.normalize( getJavaHome() ) ) );
66 if ( toRet != null )
67 {
68 return toRet.getAbsolutePath();
69 }
70 return null;
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, toolName + ( Os.isFamily( "windows" ) ? ".exe" : "" ) );
79 if ( tool.exists() )
80 {
81 return tool;
82 }
83 }
84 return null;
85 }
86 }