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 | 0 | super( model, "jdk", logger ); |
44 | 0 | } |
45 | |
|
46 | |
public String getJavaHome( ) |
47 | |
{ |
48 | 0 | return javaHome; |
49 | |
} |
50 | |
|
51 | |
public void setJavaHome( String javaHome ) |
52 | |
{ |
53 | 0 | this.javaHome = javaHome; |
54 | 0 | } |
55 | |
|
56 | |
public String toString( ) |
57 | |
{ |
58 | 0 | return "JDK[" + getJavaHome( ) + "]"; |
59 | |
} |
60 | |
|
61 | |
public String findTool( String toolName ) |
62 | |
{ |
63 | 0 | File toRet = findTool( toolName, |
64 | |
new File( FileUtils.normalize( getJavaHome( ) ) ) ); |
65 | 0 | if ( toRet != null ) |
66 | |
{ |
67 | 0 | return toRet.getAbsolutePath( ); |
68 | |
} |
69 | 0 | return null; |
70 | |
} |
71 | |
|
72 | |
|
73 | |
private static File findTool( String toolName, File installFolder ) |
74 | |
{ |
75 | 0 | File bin = new File( installFolder, "bin" ); |
76 | 0 | if ( bin.exists( ) ) |
77 | |
{ |
78 | 0 | File tool = new File( bin, |
79 | |
toolName + (Os.isFamily( "windows" ) ? ".exe" : "") ); |
80 | 0 | if ( tool.exists( ) ) |
81 | |
{ |
82 | 0 | return tool; |
83 | |
} |
84 | |
} |
85 | 0 | return null; |
86 | |
} |
87 | |
} |