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 Studio .NET 2003's vcvars32.bat
36   */
37  
38  public class MSVC2003EnvFactory
39      extends AbstractMSVCEnvFactory
40  {
41      private static final String MSVS2003_INSTALL_ENV_KEY = "MSVS2003_INSTALL_DIR";
42  
43      private static final String DEFAULT_MSVS2003_INSTALL_DIR = getProgramFiles() + "/Microsoft Visual Studio .NET 2003";
44  
45      protected Map createEnvs()
46          throws NativeBuildException
47      {
48          File vcInstallDir =
49              new File( EnvUtil.getEnv( MSVS2003_INSTALL_ENV_KEY, MSVS2003_INSTALL_ENV_KEY, DEFAULT_MSVS2003_INSTALL_DIR ) );
50  
51          if ( !vcInstallDir.isDirectory() )
52          {
53              throw new NativeBuildException( vcInstallDir.getPath() + " is not a directory." );
54          }
55  
56          Map envs = new HashMap();
57  
58          File vsInstallDir = new File( vcInstallDir.getPath() + "/Common7/IDE" );
59  
60          // TODO get winhome dir
61          File frameworkDir = new File( getSystemRoot() + "/Microsoft.NET/Framework" );
62          envs.put( "FrameworkDir", frameworkDir.getPath() );
63  
64          File frameworkSDKDir = new File( vcInstallDir.getPath() + "/SDK/v1.1" );
65          envs.put( "FrameworkSDKDir", frameworkSDKDir.getPath() );
66  
67          String frameworkVersion = "v1.1.4322";
68          envs.put( "frameworkVersion", frameworkVersion );
69  
70          File devEnvDir = vsInstallDir;
71  
72          File msvcDir = new File( vcInstallDir.getPath() + "/VC7" );
73  
74          // setup new PATH
75          String currentPath = System.getProperty( "java.library.path" );
76  
77          String newPath =
78              devEnvDir.getPath() + ";" + msvcDir.getPath() + "\\BIN;" + vcInstallDir.getPath() + "\\Common7\\Tools;"
79                  + vcInstallDir.getPath() + "\\Common7\\Tools\\bin\\prerelease;" + vcInstallDir.getPath()
80                  + "\\Common7\\Tools\\bin;" + frameworkSDKDir.getPath() + "\\bin;" + frameworkDir.getPath() + "\\"
81                  + frameworkVersion + ";" + currentPath;
82  
83          envs.put( "PATH", newPath );
84  
85          // setup new INCLUDE PATH
86          String currentIncludePath = EnvUtil.getEnv( "INCLUDE" );
87  
88          String newIncludePath =
89              msvcDir.getPath() + "\\ATLMFC\\INCLUDE;" + msvcDir.getPath() + "\\INCLUDE;" + msvcDir.getPath()
90                  + "\\PlatformSDK\\include\\prerelease;" + msvcDir.getPath() + "\\PlatformSDK\\include;"
91                  + frameworkSDKDir.getPath() + "\\include;" + currentIncludePath;
92  
93          envs.put( "INCLUDE", newIncludePath );
94  
95          //
96          // setup new LIB PATH
97          //
98          String currentLibPath = EnvUtil.getEnv( "LIB" );
99  
100         String newLibPath =
101             msvcDir.getPath() + "\\ATLMFC\\LIB;" + msvcDir.getPath() + "\\LIB;" + msvcDir.getPath()
102                 + "\\PlatformSDK\\lib\\prerelease;" + msvcDir.getPath() + "\\PlatformSDK\\lib;" + currentLibPath;
103 
104         envs.put( "LIB", newLibPath );
105 
106         return envs;
107 
108     }
109 
110 }