View Javadoc

1   package org.apache.maven.toolchain.java;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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   * @author Milos Kleint
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"; //NOI18N
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" ); //NOI18N
76          if ( bin.exists() )
77          {
78              File tool = new File( bin, toolName + ( Os.isFamily( "windows" ) ? ".exe" : "" ) ); // NOI18N
79              if ( tool.exists() )
80              {
81                  return tool;
82              }
83          }
84          return null;
85     }
86  }