1 package org.codehaus.mojo.natives.msvc;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 import java.io.File;
25 import java.io.IOException;
26 import java.util.HashMap;
27 import java.util.Map;
28
29 import org.codehaus.mojo.natives.NativeBuildException;
30 import org.codehaus.mojo.natives.util.EnvUtil;
31
32
33
34
35
36 public class MSVC2008x86AMD64EnvFactory
37 extends AbstractMSVCEnvFactory
38 {
39 private static final String VS90COMNTOOLS_ENV_KEY = "VS90COMNTOOLS";
40
41 protected Map createEnvs()
42 throws NativeBuildException
43 {
44 Map envs = new HashMap();
45
46 File vsCommonToolDir = this.getCommonToolDirectory();
47
48 File vsInstallDir = this.getVisualStudioInstallDirectory( vsCommonToolDir );
49
50 if ( !vsInstallDir.isDirectory() )
51 {
52 throw new NativeBuildException( vsInstallDir.getPath() + " is not a directory." );
53 }
54 envs.put( "VSINSTALLDIR", vsInstallDir.getPath() );
55
56 File vcInstallDir = new File( vsInstallDir.getPath() + "\\VC" );
57 if ( !vcInstallDir.isDirectory() )
58 {
59 throw new NativeBuildException( vcInstallDir.getPath() + " is not a directory." );
60 }
61 envs.put( "VCINSTALLDIR", vcInstallDir.getPath() );
62
63 File frameworkDir = new File( getSystemRoot() + "\\Microsoft.NET\\Framework" );
64 envs.put( "FrameworkDir", frameworkDir.getPath() );
65
66 File windowsSDKDir = new File( "C:\\Program Files" + "\\Microsoft SDKs\\Windows\\v6.0A" );
67 String value =
68 RegQuery.getValue( "REG_SZ", "HKLM\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows", "CurrentInstallFolder" );
69 if ( value != null )
70 {
71 windowsSDKDir = new File( value );
72 }
73
74 envs.put( "WindowsSdkDir", windowsSDKDir.getPath() );
75
76 String frameworkVersion = "v2.0.50727";
77 envs.put( "FrameworkVersion", frameworkVersion );
78
79 String framework35Version = "v3.5";
80 envs.put( "Framework35Version", framework35Version );
81
82 String devEnvDir = vsCommonToolDir + "\\..\\IDE";
83 envs.put( "DevEnvDir", devEnvDir );
84
85
86
87
88
89
90
91
92 String currentPathEnv = System.getProperty( "java.library.path" );
93
94 String newPathEnv =
95 devEnvDir + ";" + vcInstallDir.getPath() + "\\bin\\x86_amd64;" + vcInstallDir.getPath() + "\\bin" + ";"
96 + vsCommonToolDir + ";" + frameworkDir + "\\" + framework35Version + ";" + frameworkDir + "\\"
97 + frameworkVersion + ";" + vcInstallDir.getPath() + "\\VCPackages" + ";" + windowsSDKDir.getPath()
98 + "\\bin;" + currentPathEnv;
99
100 envs.put( "PATH", newPathEnv );
101
102
103
104
105
106 String currentIncludeEnv = EnvUtil.getEnv( "INCLUDE" );
107
108 String newIncludeEnv =
109 vcInstallDir.getPath() + "\\ATLMFC\\INCLUDE;" + vcInstallDir.getPath() + "\\INCLUDE;"
110 + windowsSDKDir.getPath() + "\\include;" + currentIncludeEnv;
111
112 envs.put( "INCLUDE", newIncludeEnv );
113
114
115
116
117 String currentLibEnv = EnvUtil.getEnv( "LIB" );
118
119 String newLibEnv =
120 vcInstallDir.getPath() + "\\ATLMFC\\LIB\\amd64;" + vcInstallDir.getPath() + "\\LIB\\amd64;"
121 + windowsSDKDir.getPath() + "\\LIB\\x64;" + currentLibEnv;
122
123 envs.put( "LIB", newLibEnv );
124
125
126
127
128
129 String currentLibPathEnv = EnvUtil.getEnv( "LIBPATH" );
130
131 String newLibPathEnv =
132 frameworkDir + "\\" + framework35Version + ";" + frameworkDir + "\\" + frameworkVersion + ";"
133 + vcInstallDir.getPath() + "\\ATLMFC\\LIB\\amd64;" + vcInstallDir.getPath() + "\\LIB\\amd64;"
134 + currentLibPathEnv;
135
136 envs.put( "LIBPATH", newLibPathEnv );
137
138 return envs;
139
140 }
141
142 private File getCommonToolDirectory()
143 throws NativeBuildException
144 {
145 String envValue = System.getenv( VS90COMNTOOLS_ENV_KEY );
146 if ( envValue == null )
147 {
148 throw new NativeBuildException( "Environment variable: " + VS90COMNTOOLS_ENV_KEY + " not available." );
149 }
150
151 return new File( envValue );
152 }
153
154 private File getVisualStudioInstallDirectory( File commonToolDir )
155 throws NativeBuildException
156 {
157 try
158 {
159 return new File( commonToolDir, "../.." ).getCanonicalFile();
160 }
161 catch ( IOException e )
162 {
163 throw new NativeBuildException( "Unable to contruct Visual Studio install directory using: "
164 + commonToolDir, e );
165 }
166 }
167
168 }