Skip to content

Commit 7c2540a

Browse files
authored
Merge pull request #374 from mondain/master
Fixed VS 2019 by using env variables
2 parents e8ff528 + 4dcbdb5 commit 7c2540a

File tree

4 files changed

+56
-15
lines changed

4 files changed

+56
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ In your POM:
2323
<plugin>
2424
<groupId>com.github.maven-nar</groupId>
2525
<artifactId>nar-maven-plugin</artifactId>
26-
<version>3.5.1</version>
26+
<version>3.10.2-SNAPSHOT</version>
2727
<extensions>true</extensions>
2828
<configuration>
2929
...

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,12 @@
229229
<dependency>
230230
<groupId>org.codehaus.plexus</groupId>
231231
<artifactId>plexus-utils</artifactId>
232-
<version>3.0.17</version>
232+
<version>3.3.0</version>
233233
</dependency>
234234
<dependency>
235235
<groupId>org.codehaus.plexus</groupId>
236236
<artifactId>plexus-archiver</artifactId>
237-
<version>2.4.4</version>
237+
<version>4.2.3</version>
238238
<exclusions>
239239
<exclusion>
240240
<groupId>org.codehaus.plexus</groupId>

src/main/java/com/github/maven_nar/Msvc.java

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010
import java.util.regex.Matcher;
1111
import java.util.regex.Pattern;
1212

13-
import com.sun.jna.platform.win32.Advapi32Util;
1413
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
1514
import org.apache.maven.plugin.MojoExecutionException;
1615
import org.apache.maven.plugin.MojoFailureException;
17-
import org.apache.maven.plugins.annotations.Parameter;
1816
import org.apache.tools.ant.types.Environment.Variable;
1917
import org.codehaus.plexus.util.StringUtils;
2018

@@ -44,6 +42,7 @@ public class Msvc {
4442
* <li>12.0 for VS 2013</li>
4543
* <li>14.0 for VS 2015</li>
4644
* <li>15.0 for VS 2017</li>
45+
* <li>16.0 for VS 2019</li>
4746
* </ul>
4847
*/
4948
private String version = "";
@@ -540,8 +539,35 @@ private static TreeMap<String, Object> visualStudioVS7SxS(com.sun.jna.platform.w
540539
private void initVisualStudio() throws MojoFailureException, MojoExecutionException {
541540
mojo.getLog().debug(" -- Searching for usable VisualStudio ");
542541

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+
}
543570
mojo.getLog().debug("Requested Linker version is \"" + version + "\"");
544-
545571
if (version != null && version.trim().length() > 1) {
546572
String internalVersion;
547573
Pattern r = Pattern.compile("(\\d+)\\.*(\\d)");
@@ -557,8 +583,9 @@ private void initVisualStudio() throws MojoFailureException, MojoExecutionExcept
557583
// @<Major.Minor>
558584
try {
559585
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?
562589
}
563590
}
564591
if (home == null || !home.exists()) {
@@ -571,8 +598,9 @@ private void initVisualStudio() throws MojoFailureException, MojoExecutionExcept
571598
}
572599
}
573600
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 = "";
576604
// First search registry for installed items, more reliable than environment.
577605
for (final Entry<String, Object> entry : visualStudioVS7SxS(com.sun.jna.platform.win32.WinReg.HKEY_LOCAL_MACHINE,
578606
"SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7").entrySet()) {

src/main/java/com/github/maven_nar/NarProperties.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,13 @@ public static NarProperties getInstance(final MavenProject project) throws MojoF
8686
* the properties from input stream
8787
*/
8888
public static void inject(final MavenProject project, final InputStream properties) throws MojoFailureException {
89-
final Properties defaults = PropertyUtils.loadProperties(properties);
89+
Properties defaults;
90+
try {
91+
defaults = PropertyUtils.loadProperties(properties);
92+
} catch (IOException e) {
93+
// re-throw as a mojo failure
94+
throw new MojoFailureException("IOException loading properties", e);
95+
}
9096
final NarProperties nar = getInstance(project);
9197
nar.properties.putAll(defaults);
9298
}
@@ -95,7 +101,13 @@ public static void inject(final MavenProject project, final InputStream properti
95101

96102
private NarProperties(final MavenProject project, File narFile, String customPropertyLocation) throws MojoFailureException {
97103

98-
final Properties defaults = PropertyUtils.loadProperties(NarUtil.class.getResourceAsStream(AOL_PROPERTIES));
104+
Properties defaults;
105+
try {
106+
defaults = PropertyUtils.loadProperties(NarUtil.class.getResourceAsStream(AOL_PROPERTIES));
107+
} catch (IOException e) {
108+
// re-throw as a mojo failure
109+
throw new MojoFailureException("IOException loading properties", e);
110+
}
99111
if (defaults == null) {
100112
throw new MojoFailureException("NAR: Could not load default properties file: '" + AOL_PROPERTIES + "'.");
101113
}
@@ -107,13 +119,14 @@ private NarProperties(final MavenProject project, File narFile, String customPro
107119
fis = new FileInputStream(narFile);
108120
this.properties.load(fis);
109121
}
110-
} catch (final FileNotFoundException e) {
122+
} catch (FileNotFoundException e) {
111123
if (customPropertyLocation != null) {
112124
// We tried loading from a custom location - so throw the exception
113125
throw new MojoFailureException("NAR: Could not load custom properties file: '" + customPropertyLocation + "'.");
114126
}
115-
} catch (final IOException e) {
116-
// ignore (FIXME)
127+
} catch (IOException e) {
128+
// re-throw as a mojo failure
129+
throw new MojoFailureException("IOException loading properties", e);
117130
} finally {
118131
try {
119132
if (fis != null) {

0 commit comments

Comments
 (0)