forked from jasder/antlr
Allow specifying the JVM vendor (default JavaSoft) and installation (default Java Runtime Environment) in the project file
This commit is contained in:
parent
092078e5bf
commit
3c0b96c413
|
@ -49,6 +49,9 @@
|
|||
<Antlr4BuildTaskLocation Condition="'$(Antlr4BuildTaskPath)'!=''">$(Antlr4BuildTaskPath)</Antlr4BuildTaskLocation>
|
||||
<Antlr4ToolLocation Condition="'$(Antlr4ToolPath)'==''">$(MSBuildBinPath)\Antlr4\antlr4-csharp-4.0.1-SNAPSHOT-complete.jar</Antlr4ToolLocation>
|
||||
<Antlr4ToolLocation Condition="'$(Antlr4ToolPath)'!=''">$(Antlr4ToolPath)</Antlr4ToolLocation>
|
||||
|
||||
<Antlr4JavaVendor Condition="'$(Antlr4JavaVendor)'==''">JavaSoft</Antlr4JavaVendor>
|
||||
<Antlr4JavaInstallation Condition="'$(Antlr4JavaInstallation)'==''">Java Runtime Environment</Antlr4JavaInstallation>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
@ -128,6 +131,8 @@
|
|||
</PropertyGroup>
|
||||
<Antlr4ClassGenerationTask
|
||||
ToolPath="$(Antlr4ToolLocation)"
|
||||
JavaVendor="$(Antlr4JavaVendor)"
|
||||
JavaInstallation="$(Antlr4JavaInstallation)"
|
||||
BuildTaskPath="$(Antlr4BuildTaskLocation)"
|
||||
OutputPath="$(IntermediateOutputPath)"
|
||||
TargetLanguage="%(Antlr4.TargetLanguage)"
|
||||
|
|
|
@ -148,6 +148,20 @@ namespace Antlr4.Build.Tasks
|
|||
set;
|
||||
}
|
||||
|
||||
[Required]
|
||||
public string JavaVendor
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Required]
|
||||
public string JavaInstallation
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Output]
|
||||
public ITaskItem[] GeneratedCodeFiles
|
||||
{
|
||||
|
@ -308,6 +322,8 @@ namespace Antlr4.Build.Tasks
|
|||
wrapper.GenerateVisitor = GenerateVisitor;
|
||||
wrapper.ForceAtn = ForceAtn;
|
||||
wrapper.AbstractGrammar = AbstractGrammar;
|
||||
wrapper.JavaVendor = JavaVendor;
|
||||
wrapper.JavaInstallation = JavaInstallation;
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
|
|
|
@ -113,6 +113,18 @@ namespace Antlr4.Build.Tasks
|
|||
set;
|
||||
}
|
||||
|
||||
public string JavaVendor
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public string JavaInstallation
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public IList<string> SourceCodeFiles
|
||||
{
|
||||
get
|
||||
|
@ -133,29 +145,29 @@ namespace Antlr4.Build.Tasks
|
|||
}
|
||||
}
|
||||
|
||||
private static string JavaHome
|
||||
private string JavaHome
|
||||
{
|
||||
get
|
||||
{
|
||||
string javaHome;
|
||||
if (TryGetJavaHome(RegistryView.Default, out javaHome))
|
||||
if (TryGetJavaHome(RegistryView.Default, JavaVendor, JavaInstallation, out javaHome))
|
||||
return javaHome;
|
||||
|
||||
if (TryGetJavaHome(RegistryView.Registry64, out javaHome))
|
||||
if (TryGetJavaHome(RegistryView.Registry64, JavaVendor, JavaInstallation, out javaHome))
|
||||
return javaHome;
|
||||
|
||||
if (TryGetJavaHome(RegistryView.Registry32, out javaHome))
|
||||
if (TryGetJavaHome(RegistryView.Registry32, JavaVendor, JavaInstallation, out javaHome))
|
||||
return javaHome;
|
||||
|
||||
throw new NotSupportedException("Could not locate a Java installation.");
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryGetJavaHome(RegistryView registryView, out string javaHome)
|
||||
private static bool TryGetJavaHome(RegistryView registryView, string vendor, string installation, out string javaHome)
|
||||
{
|
||||
javaHome = null;
|
||||
|
||||
string javaKeyName = "SOFTWARE\\JavaSoft\\Java Runtime Environment";
|
||||
string javaKeyName = "SOFTWARE\\" + vendor + "\\" + installation;
|
||||
using (var baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, registryView))
|
||||
{
|
||||
using (RegistryKey javaKey = baseKey.OpenSubKey(javaKeyName))
|
||||
|
|
Loading…
Reference in New Issue