View Javadoc
1   package org.codehaus.mojo.natives.msvc;
2   
3   /*
4    * The MIT License
5    *
6    * Copyright (c) 2004, The Codehaus
7    *
8    * Permission is hereby granted, free of charge, to any person obtaining a copy of
9    * this software and associated documentation files (the "Software"), to deal in
10   * the Software without restriction, including without limitation the rights to
11   * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12   * of the Software, and to permit persons to whom the Software is furnished to do
13   * so, subject to the following conditions:
14   *
15   * The above copyright notice and this permission notice shall be included in all
16   * copies or substantial portions of the Software.
17   *
18   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24   * SOFTWARE.
25   */
26  
27  import java.io.File;
28  import java.util.HashMap;
29  import java.util.Map;
30  
31  import org.codehaus.mojo.natives.NativeBuildException;
32  import org.codehaus.mojo.natives.util.EnvUtil;
33  
34  /**
35   * Equivalent of Microsoft Visual C++ Toolkit 2003's vcvars32.bat
36   */
37  
38  public class MSVC2003ToolkitEnvFactory
39      extends AbstractMSVCEnvFactory
40  {
41      private static final String MSVC2003_TOOLKIT_INSTALL_ENV_KEY = "MSVC2003_TOOLKIT_INSTALL_DIR";
42  
43      private static final String DEFAULT_MSVC2003_TOOLKT_INSTALL_DIR = getProgramFiles()
44          + "/Microsoft Visual C++ Toolkit 2003";
45  
46      protected Map createEnvs()
47          throws NativeBuildException
48      {
49          File vcInstallDir =
50              new File( EnvUtil.getEnv( MSVC2003_TOOLKIT_INSTALL_ENV_KEY, MSVC2003_TOOLKIT_INSTALL_ENV_KEY,
51                                        DEFAULT_MSVC2003_TOOLKT_INSTALL_DIR ) );
52  
53          if ( !vcInstallDir.isDirectory() )
54          {
55              throw new NativeBuildException( vcInstallDir.getPath() + " is not a directory." );
56          }
57  
58          Map envs = new HashMap();
59  
60          // setup new PATH
61          String currentPath = System.getProperty( "java.library.path" );
62  
63          String newPath = vcInstallDir.getPath() + "\\BIN;" + currentPath;
64  
65          envs.put( "PATH", newPath );
66  
67          // setup new INCLUDE PATH
68          String currentIncludePath = EnvUtil.getEnv( "INCLUDE" );
69  
70          String newIncludePath = vcInstallDir.getPath() + "\\INCLUDE;" + currentIncludePath;
71  
72          envs.put( "INCLUDE", newIncludePath );
73  
74          //
75          // setup new LIB PATH
76          //
77          String currentLibPath = EnvUtil.getEnv( "LIB" );
78  
79          String newLibPath = vcInstallDir.getPath() + "\\LIB;" + currentLibPath;
80  
81          envs.put( "LIB", newLibPath );
82  
83          return envs;
84  
85      }
86  
87  }