View Javadoc

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