From 785585199c2eba08abc7bb1fbf691ee43eab25bb Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Wed, 17 Apr 2013 19:02:01 -0500 Subject: [PATCH] Separate MSBuild integration for .NET 3.5 and .NET 4.0 toolchains --- runtime/CSharp/Antlr4.sln | 8 +- .../{Antlr4.targets => Antlr4.v3.5.targets} | 2 +- .../Antlr4BuildTasks/Antlr4.v4.0.targets | 181 ++++++++++++++++++ .../Antlr4BuildTasks.v3.5.csproj | 81 ++++++++ ...ks.csproj => Antlr4BuildTasks.v4.0.csproj} | 16 +- .../Antlr4ClassGenerationTaskInternal.cs | 47 ++++- .../Properties/AssemblyInfo.cs | 9 +- 7 files changed, 331 insertions(+), 13 deletions(-) rename runtime/CSharp/Antlr4BuildTasks/{Antlr4.targets => Antlr4.v3.5.targets} (98%) create mode 100644 runtime/CSharp/Antlr4BuildTasks/Antlr4.v4.0.targets create mode 100644 runtime/CSharp/Antlr4BuildTasks/Antlr4BuildTasks.v3.5.csproj rename runtime/CSharp/Antlr4BuildTasks/{Antlr4BuildTasks.csproj => Antlr4BuildTasks.v4.0.csproj} (85%) diff --git a/runtime/CSharp/Antlr4.sln b/runtime/CSharp/Antlr4.sln index 7557ec324..dff9460de 100644 --- a/runtime/CSharp/Antlr4.sln +++ b/runtime/CSharp/Antlr4.sln @@ -16,7 +16,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4.Runtime.Test.v4.5", "Antlr4.Runtime.Test\Antlr4.Runtime.Test.v4.5.csproj", "{9D8C43DF-71F9-4CC9-83AD-A39FAEBCECA0}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4BuildTasks", "Antlr4BuildTasks\Antlr4BuildTasks.csproj", "{F63DFE80-AE1F-47A6-A31A-E39DA4C837BA}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4BuildTasks.v4.0", "Antlr4BuildTasks\Antlr4BuildTasks.v4.0.csproj", "{F63DFE80-AE1F-47A6-A31A-E39DA4C837BA}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4.Runtime.v4.0", "Antlr4.Runtime\Antlr4.Runtime.v4.0.csproj", "{423978DF-85A4-409E-A16C-453683FE3969}" EndProject @@ -38,6 +38,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4.Runtime.Portable", " EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4.Runtime.Test.Portable", "Antlr4.Runtime.Test\Antlr4.Runtime.Test.Portable.csproj", "{97C32E42-51B2-4A29-B005-769B63CFEFCA}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4BuildTasks.v3.5", "Antlr4BuildTasks\Antlr4BuildTasks.v3.5.csproj", "{0D3D20E9-3341-4449-80E7-76A4534F0E55}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -96,6 +98,10 @@ Global {97C32E42-51B2-4A29-B005-769B63CFEFCA}.Debug|Any CPU.Build.0 = Debug|Any CPU {97C32E42-51B2-4A29-B005-769B63CFEFCA}.Release|Any CPU.ActiveCfg = Release|Any CPU {97C32E42-51B2-4A29-B005-769B63CFEFCA}.Release|Any CPU.Build.0 = Release|Any CPU + {0D3D20E9-3341-4449-80E7-76A4534F0E55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0D3D20E9-3341-4449-80E7-76A4534F0E55}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0D3D20E9-3341-4449-80E7-76A4534F0E55}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0D3D20E9-3341-4449-80E7-76A4534F0E55}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/runtime/CSharp/Antlr4BuildTasks/Antlr4.targets b/runtime/CSharp/Antlr4BuildTasks/Antlr4.v3.5.targets similarity index 98% rename from runtime/CSharp/Antlr4BuildTasks/Antlr4.targets rename to runtime/CSharp/Antlr4BuildTasks/Antlr4.v3.5.targets index 8117daa9b..6233566df 100644 --- a/runtime/CSharp/Antlr4BuildTasks/Antlr4.targets +++ b/runtime/CSharp/Antlr4BuildTasks/Antlr4.v3.5.targets @@ -30,7 +30,7 @@ MSBuild 4.0.0.0 eb42632606e9261f - Antlr4BuildTasks, Version=$(TaskVersion), Culture=neutral, PublicKeyToken=$(TaskKeyToken) + Antlr4BuildTasks.v3.5, Version=$(TaskVersion), Culture=neutral, PublicKeyToken=$(TaskKeyToken) diff --git a/runtime/CSharp/Antlr4BuildTasks/Antlr4.v4.0.targets b/runtime/CSharp/Antlr4BuildTasks/Antlr4.v4.0.targets new file mode 100644 index 000000000..cfb9c7c9f --- /dev/null +++ b/runtime/CSharp/Antlr4BuildTasks/Antlr4.v4.0.targets @@ -0,0 +1,181 @@ + + + + MSBuild + 4.0.0.0 + eb42632606e9261f + Antlr4BuildTasks.v4.0, Version=$(TaskVersion), Culture=neutral, PublicKeyToken=$(TaskKeyToken) + + + + + $(LoadTimeSensitiveTargets); + Antlr4Compile; + + + $(LoadTimeSensitiveProperties); + Antlr4CompileDependsOn; + + + + + $(MSBuildBinPath) + $(Antlr4BuildTaskPath) + $(MSBuildBinPath)\Antlr4\antlr4-csharp-4.0.1-SNAPSHOT-complete.jar + $(Antlr4ToolPath) + + JavaSoft + Java Runtime Environment + + + + $(MSBuildProjectFile).Antlr4GeneratedCodeFileListAbsolute.txt + + + + + + + + Antlr4Compile; + Antlr4CompileAddFilesGenerated; + $(PrepareResourcesDependsOn) + + + + + + Antlr4CompileReadGeneratedFileList + + + + + + + + + + + + MSBuild:Compile + $(RootNamespace) + CSharp + true + true + false + false + + + + + + + + + + + + + Antlr4DesignTimeGrammarCompilation; + $(CoreCompileDependsOn) + + + + + + + + + + + + + + + + <_IntellisenseOnlyCompile>false + <_IntellisenseOnlyCompile Condition="'$(BuildingProject)' != 'true'">true + + + + + + + + + + + + + + + + + + + + + + + <_GeneratedCodeFiles Include="@(Antlr4GeneratedCodeFiles)" /> + + + + diff --git a/runtime/CSharp/Antlr4BuildTasks/Antlr4BuildTasks.v3.5.csproj b/runtime/CSharp/Antlr4BuildTasks/Antlr4BuildTasks.v3.5.csproj new file mode 100644 index 000000000..6938d9662 --- /dev/null +++ b/runtime/CSharp/Antlr4BuildTasks/Antlr4BuildTasks.v3.5.csproj @@ -0,0 +1,81 @@ + + + + + Debug + AnyCPU + {0D3D20E9-3341-4449-80E7-76A4534F0E55} + Library + Properties + Antlr4.Build.Tasks + Antlr4BuildTasks.v3.5 + v3.5 + 512 + obj\v3.5\ + + + true + full + false + bin\v3.5\Debug\ + DEBUG;TRACE + prompt + 4 + ExtendedDesignGuidelineRules.ruleset + + + pdbonly + true + bin\v3.5\Release\ + TRACE + prompt + 4 + + + true + + + ..\..\..\..\..\..\keys\antlr\Key.snk + + + + + + + + + + + + + + + + + + + + + + + Always + Designer + + + Key.snk + + + + + CustomDictionary.xml + + + + + \ No newline at end of file diff --git a/runtime/CSharp/Antlr4BuildTasks/Antlr4BuildTasks.csproj b/runtime/CSharp/Antlr4BuildTasks/Antlr4BuildTasks.v4.0.csproj similarity index 85% rename from runtime/CSharp/Antlr4BuildTasks/Antlr4BuildTasks.csproj rename to runtime/CSharp/Antlr4BuildTasks/Antlr4BuildTasks.v4.0.csproj index 883892bb8..a0e969037 100644 --- a/runtime/CSharp/Antlr4BuildTasks/Antlr4BuildTasks.csproj +++ b/runtime/CSharp/Antlr4BuildTasks/Antlr4BuildTasks.v4.0.csproj @@ -8,24 +8,26 @@ Library Properties Antlr4.Build.Tasks - Antlr4BuildTasks - v4.5 + Antlr4BuildTasks.v4.0 + v4.0 512 + obj\v4.0\ true full false - bin\Debug\ - DEBUG;TRACE + bin\v4.0\Debug\ + DEBUG;TRACE;NET_4_0 prompt 4 + ExtendedDesignGuidelineRules.ruleset pdbonly true - bin\Release\ - TRACE + bin\v4.0\Release\ + TRACE;NET_4_0 prompt 4 @@ -55,7 +57,7 @@ - + Always Designer diff --git a/runtime/CSharp/Antlr4BuildTasks/Antlr4ClassGenerationTaskInternal.cs b/runtime/CSharp/Antlr4BuildTasks/Antlr4ClassGenerationTaskInternal.cs index 987151198..5b0d0f58c 100644 --- a/runtime/CSharp/Antlr4BuildTasks/Antlr4ClassGenerationTaskInternal.cs +++ b/runtime/CSharp/Antlr4BuildTasks/Antlr4ClassGenerationTaskInternal.cs @@ -37,7 +37,11 @@ namespace Antlr4.Build.Tasks using System.Text.RegularExpressions; using RegistryHive = Microsoft.Win32.RegistryHive; using RegistryKey = Microsoft.Win32.RegistryKey; +#if NET_4_0 using RegistryView = Microsoft.Win32.RegistryView; +#else + using Registry = Microsoft.Win32.Registry; +#endif internal class AntlrClassGenerationTaskInternal : MarshalByRefObject { @@ -145,6 +149,7 @@ namespace Antlr4.Build.Tasks } } +#if NET_4_0 private string JavaHome { get @@ -190,13 +195,51 @@ namespace Antlr4.Build.Tasks } } } +#else + private string JavaHome + { + get + { + string javaHome; + if (TryGetJavaHome(Registry.LocalMachine, JavaVendor, JavaInstallation, out javaHome)) + return javaHome; + + throw new NotSupportedException("Could not locate a Java installation."); + } + } + + private static bool TryGetJavaHome(RegistryKey baseKey, string vendor, string installation, out string javaHome) + { + javaHome = null; + + string javaKeyName = "SOFTWARE\\" + vendor + "\\" + installation; + using (RegistryKey javaKey = baseKey.OpenSubKey(javaKeyName)) + { + if (javaKey == null) + return false; + + object currentVersion = javaKey.GetValue("CurrentVersion"); + if (currentVersion == null) + return false; + + using (var homeKey = javaKey.OpenSubKey(currentVersion.ToString())) + { + if (homeKey == null || homeKey.GetValue("JavaHome") == null) + return false; + + javaHome = homeKey.GetValue("JavaHome").ToString(); + return !string.IsNullOrEmpty(javaHome); + } + } + } +#endif public bool Execute() { try { string javaHome = JavaHome; - string java = Path.Combine(javaHome, "bin", "java.exe"); + string java = Path.Combine(Path.Combine(javaHome, "bin"), "java.exe"); List arguments = new List(); arguments.Add("-cp"); @@ -245,7 +288,7 @@ namespace Antlr4.Build.Tasks arguments.AddRange(SourceCodeFiles); - ProcessStartInfo startInfo = new ProcessStartInfo(java, string.Join(" ", arguments)) + ProcessStartInfo startInfo = new ProcessStartInfo(java, string.Join(" ", arguments.ToArray())) { UseShellExecute = false, CreateNoWindow = true, diff --git a/runtime/CSharp/Antlr4BuildTasks/Properties/AssemblyInfo.cs b/runtime/CSharp/Antlr4BuildTasks/Properties/AssemblyInfo.cs index d59caddca..ce43c9d0d 100644 --- a/runtime/CSharp/Antlr4BuildTasks/Properties/AssemblyInfo.cs +++ b/runtime/CSharp/Antlr4BuildTasks/Properties/AssemblyInfo.cs @@ -35,11 +35,16 @@ using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("Antlr4BuildTasks")] +#if NET_4_0 +[assembly: AssemblyTitle("Antlr4BuildTasks.v4.0")] +[assembly: AssemblyProduct("Antlr4BuildTasks.v4.0")] +#else +[assembly: AssemblyTitle("Antlr4BuildTasks.v3.5")] +[assembly: AssemblyProduct("Antlr4BuildTasks.v3.5")] +#endif [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Tunnel Vision Laboratories, LLC")] -[assembly: AssemblyProduct("Antlr4BuildTasks")] [assembly: AssemblyCopyright("Copyright © Sam Harwell 2013")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")]