10
10
import java .util .regex .Matcher ;
11
11
import java .util .regex .Pattern ;
12
12
13
- import com .sun .jna .platform .win32 .Advapi32Util ;
14
13
import org .apache .maven .artifact .versioning .DefaultArtifactVersion ;
15
14
import org .apache .maven .plugin .MojoExecutionException ;
16
15
import org .apache .maven .plugin .MojoFailureException ;
17
- import org .apache .maven .plugins .annotations .Parameter ;
18
16
import org .apache .tools .ant .types .Environment .Variable ;
19
17
import org .codehaus .plexus .util .StringUtils ;
20
18
@@ -44,6 +42,7 @@ public class Msvc {
44
42
* <li>12.0 for VS 2013</li>
45
43
* <li>14.0 for VS 2015</li>
46
44
* <li>15.0 for VS 2017</li>
45
+ * <li>16.0 for VS 2019</li>
47
46
* </ul>
48
47
*/
49
48
private String version = "" ;
@@ -540,8 +539,35 @@ private static TreeMap<String, Object> visualStudioVS7SxS(com.sun.jna.platform.w
540
539
private void initVisualStudio () throws MojoFailureException , MojoExecutionException {
541
540
mojo .getLog ().debug (" -- Searching for usable VisualStudio " );
542
541
542
+ /* New env values used by VS 2019
543
+ VCIDEInstallDir=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\VC\
544
+ VCINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\
545
+ VCToolsInstallDir=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\
546
+ VCToolsRedistDir=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Redist\MSVC\14.28.29325\
547
+ VCToolsVersion=14.28.29333
548
+ VisualStudioVersion=16.0
549
+ VS160COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\
550
+ VSCMD_ARG_app_plat=Desktop
551
+ VSCMD_ARG_HOST_ARCH=x64
552
+ VSCMD_ARG_TGT_ARCH=x64
553
+ VSCMD_VER=16.8.5
554
+ VSINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\
555
+ WindowsLibPath=C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.18362.0;C:\Program Files (x86)\Windows Kits\10\References\10.0.18362.0
556
+ WindowsSdkBinPath=C:\Program Files (x86)\Windows Kits\10\bin\
557
+ WindowsSdkDir=C:\Program Files (x86)\Windows Kits\10\
558
+ WindowsSDKLibVersion=10.0.18362.0\
559
+ WindowsSdkVerBinPath=C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\
560
+ WindowsSDKVersion=10.0.18362.0\
561
+ */
562
+ // don't attempt to subvert the version setting from the pom
563
+ if (version == null || version .trim ().length () < 1 ) {
564
+ // examine the VS version variable before attempting to read older registry entries which are not supported in later VS versions
565
+ String envVisualStudioVersion = System .getenv ("VisualStudioVersion" );
566
+ if (envVisualStudioVersion != null && envVisualStudioVersion .length () > 3 ) {
567
+ this .version = envVisualStudioVersion ;
568
+ }
569
+ }
543
570
mojo .getLog ().debug ("Requested Linker version is \" " + version + "\" " );
544
-
545
571
if (version != null && version .trim ().length () > 1 ) {
546
572
String internalVersion ;
547
573
Pattern r = Pattern .compile ("(\\ d+)\\ .*(\\ d)" );
@@ -557,8 +583,9 @@ private void initVisualStudio() throws MojoFailureException, MojoExecutionExcept
557
583
// @<Major.Minor>
558
584
try {
559
585
home = new File (registryGet32StringValue (com .sun .jna .platform .win32 .WinReg .HKEY_LOCAL_MACHINE ,
560
- "SOFTWARE\\ Microsoft\\ VisualStudio\\ SxS\\ VS7" , version ));
561
- } finally {
586
+ "SOFTWARE\\ Microsoft\\ VisualStudio\\ SxS\\ VS7" , version ));
587
+ } catch (Exception e ) {
588
+ // is there interest in knowing about an Win32Exception here for newer VS versions?
562
589
}
563
590
}
564
591
if (home == null || !home .exists ()) {
@@ -571,8 +598,9 @@ private void initVisualStudio() throws MojoFailureException, MojoExecutionExcept
571
598
}
572
599
}
573
600
mojo .getLog ().debug (String .format (" VisualStudio %1s (%2s) found %3s " , version , internalVersion , home ));
574
- } else {
575
- this .version = "" ; //
601
+ } else {
602
+ // reset
603
+ this .version = "" ;
576
604
// First search registry for installed items, more reliable than environment.
577
605
for (final Entry <String , Object > entry : visualStudioVS7SxS (com .sun .jna .platform .win32 .WinReg .HKEY_LOCAL_MACHINE ,
578
606
"SOFTWARE\\ Microsoft\\ VisualStudio\\ SxS\\ VS7" ).entrySet ()) {
0 commit comments