Author: brett Date: Fri Jun 24 19:26:22 2011 New Revision: 1139414 URL: http://svn.apache.org/viewvc?rev=1139414&view=rev Log: [NPANDAY-445] find the reference for the correct target framework also split RSP code from GAC code and other refactoring
Added: incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/NPanday/Utils/RspUtility.cs Modified: incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Converter/Algorithms/AbstractPomConverter.cs incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Converter/Algorithms/NormalPomConverter.cs incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Converter/Algorithms/WebPomConverter.cs incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Digest/Algorithms/NormalProjectDigestAlgorithm.cs incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Digest/Algorithms/WebProjectDigestAlgorithm.cs incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Digest/Model/Reference.cs incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/NPanday.Utils.csproj incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/NPanday/Utils/GacUtility.cs incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/NPanday/Utils/PomHelperUtility.cs Modified: incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Converter/Algorithms/AbstractPomConverter.cs URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Converter/Algorithms/AbstractPomConverter.cs?rev=1139414&r1=1139413&r2=1139414&view=diff ============================================================================== --- incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Converter/Algorithms/AbstractPomConverter.cs (original) +++ incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Converter/Algorithms/AbstractPomConverter.cs Fri Jun 24 19:26:22 2011 @@ -40,6 +40,7 @@ namespace NPanday.ProjectImporter.Conver public abstract class AbstractPomConverter : IPomConverter { protected GacUtility gacUtil; + protected RspUtility rspUtil; protected ArtifactContext artifactContext; protected List<Artifact.Artifact> localArtifacts; protected string mainPomFile; @@ -76,6 +77,7 @@ namespace NPanday.ProjectImporter.Conver this.groupId = FilterID(groupId); this.version = parent != null ? parent.version : null; + this.rspUtil = new RspUtility(); this.gacUtil = new GacUtility(); this.model = new NPanday.Model.Pom.Model(); @@ -472,7 +474,7 @@ namespace NPanday.ProjectImporter.Conver || "dotnet-library".Equals(refDependency.type, StringComparison.OrdinalIgnoreCase))) { // ignore gac if already in the RSP - if (gacUtil.IsRspIncluded(refDependency.artifactId, projectDigest.Language)) + if (rspUtil.IsRspIncluded(refDependency.artifactId, projectDigest.Language)) { return; } @@ -747,20 +749,25 @@ namespace NPanday.ProjectImporter.Conver return dependency; } - + List<string> refs = gacUtil.GetAssemblyInfo(reference.Name, null, projectDigest.Platform); // resolve from GAC - if (!string.IsNullOrEmpty(gacUtil.GetAssemblyInfo(reference.Name, null, projectDigest.Platform))) + if (refs.Count > 0) { // Assembly is found at the gac + //exclude ProcessArchitecture when loading assembly on a non-32 bit machine + refs = gacUtil.GetAssemblyInfo(reference.Name, reference.Version, null); + + System.Reflection.Assembly a = System.Reflection.Assembly.ReflectionOnlyLoad(new System.Reflection.AssemblyName(refs[0]).FullName); + Dependency refDependency = new Dependency(); refDependency.artifactId = reference.Name; refDependency.groupId = reference.Name; if ("MSIL".Equals(reference.ProcessorArchitecture, StringComparison.OrdinalIgnoreCase)) { - if ("4.0.0.0".Equals(reference.Version)) + if (a.ImageRuntimeVersion.StartsWith("v4.0")) { refDependency.type = "gac_msil4"; } @@ -771,7 +778,7 @@ namespace NPanday.ProjectImporter.Conver } else if ("x86".Equals(reference.ProcessorArchitecture, StringComparison.OrdinalIgnoreCase)) { - if ("4.0.0.0".Equals(reference.Version)) + if (a.ImageRuntimeVersion.StartsWith("v4.0")) { refDependency.type = "gac_32_4"; } @@ -783,7 +790,7 @@ namespace NPanday.ProjectImporter.Conver else if ("IA64".Equals(reference.ProcessorArchitecture, StringComparison.OrdinalIgnoreCase) || "AMD64".Equals(reference.ProcessorArchitecture, StringComparison.OrdinalIgnoreCase)) { - if ("4.0.0.0".Equals(reference.Version)) + if (a.ImageRuntimeVersion.StartsWith("v4.0")) { refDependency.type = "gac_64_4"; } @@ -796,7 +803,7 @@ namespace NPanday.ProjectImporter.Conver //Assemblies that with null ProcessorArchitecture esp ASP.net assmblies (e.g MVC) else if ((reference.ProcessorArchitecture == null) && ("31bf3856ad364e35".Equals(reference.PublicKeyToken.ToLower(), StringComparison.OrdinalIgnoreCase))) { - if ("4.0.0.0".Equals(reference.Version)) + if (a.ImageRuntimeVersion.StartsWith("v4.0")) { refDependency.type = "gac_msil4"; } @@ -805,7 +812,6 @@ namespace NPanday.ProjectImporter.Conver refDependency.type = "gac_msil"; } } - else { refDependency.type = "gac"; @@ -813,9 +819,6 @@ namespace NPanday.ProjectImporter.Conver refDependency.version = reference.Version ?? "1.0.0.0"; - //exclude ProcessArchitecture when loading assembly on a non-32 bit machine - System.Reflection.Assembly a = System.Reflection.Assembly.Load(new System.Reflection.AssemblyName(gacUtil.GetAssemblyInfo(reference.Name, reference.Version, null)).FullName); - if (reference.PublicKeyToken != null) { refDependency.classifier = reference.PublicKeyToken; Modified: incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Converter/Algorithms/NormalPomConverter.cs URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Converter/Algorithms/NormalPomConverter.cs?rev=1139414&r1=1139413&r2=1139414&view=diff ============================================================================== --- incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Converter/Algorithms/NormalPomConverter.cs (original) +++ incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Converter/Algorithms/NormalPomConverter.cs Fri Jun 24 19:26:22 2011 @@ -241,7 +241,7 @@ namespace NPanday.ProjectImporter.Conver { if (!string.IsNullOrEmpty(projectDigest.Language)) { - if (!gacUtil.IsRspIncluded(reference.Name, projectDigest.Language)) + if (!rspUtil.IsRspIncluded(reference.Name, projectDigest.Language)) { list.Add(reference); } Modified: incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Converter/Algorithms/WebPomConverter.cs URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Converter/Algorithms/WebPomConverter.cs?rev=1139414&r1=1139413&r2=1139414&view=diff ============================================================================== --- incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Converter/Algorithms/WebPomConverter.cs (original) +++ incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Converter/Algorithms/WebPomConverter.cs Fri Jun 24 19:26:22 2011 @@ -186,7 +186,7 @@ namespace NPanday.ProjectImporter.Conver || "dotnet-library".Equals(refDependency.type, StringComparison.OrdinalIgnoreCase))) { // ignore gac if already in the RSP - if (gacUtil.IsRspIncluded(refDependency.artifactId, projectDigest.Language)) + if (rspUtil.IsRspIncluded(refDependency.artifactId, projectDigest.Language)) { return; } Modified: incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Digest/Algorithms/NormalProjectDigestAlgorithm.cs URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Digest/Algorithms/NormalProjectDigestAlgorithm.cs?rev=1139414&r1=1139413&r2=1139414&view=diff ============================================================================== --- incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Digest/Algorithms/NormalProjectDigestAlgorithm.cs (original) +++ incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Digest/Algorithms/NormalProjectDigestAlgorithm.cs Fri Jun 24 19:26:22 2011 @@ -20,7 +20,9 @@ #endregion using System; using System.Collections.Generic; +using System.Collections; using System.IO; +using System.Reflection; using Microsoft.Build.BuildEngine; using NPanday.ProjectImporter.Parser.VisualStudioProjectTypes; using NPanday.ProjectImporter.Digest.Model; @@ -55,9 +57,6 @@ namespace NPanday.ProjectImporter.Digest } } - GacUtility gac = new GacUtility(); - - ProjectDigest projectDigest = new ProjectDigest(); string projectBasePath = Path.GetDirectoryName(project.FullFileName); projectDigest.ProjectType = (VisualStudioProjectTypeEnum)projectMap["ProjectType"]; @@ -113,7 +112,7 @@ namespace NPanday.ProjectImporter.Digest List<ComReference> comReferenceList = new List<ComReference>(); DigestBuildProperties(project, projectDigest); - DigestBuildItems(project, projectDigest, projectBasePath, projectReferences, gac, references, compiles, nones, webReferenceUrls, contents, folders, webReferencesList, embeddedResources, bootstrapperPackages, globalNamespaceImports, comReferenceList); + DigestBuildItems(project, projectDigest, projectBasePath, projectReferences, references, compiles, nones, webReferenceUrls, contents, folders, webReferencesList, embeddedResources, bootstrapperPackages, globalNamespaceImports, comReferenceList); DigestImports(project); projectDigest.ProjectReferences = projectReferences.ToArray(); @@ -165,8 +164,11 @@ namespace NPanday.ProjectImporter.Digest } } - private static void DigestBuildItems(Project project, ProjectDigest projectDigest, string projectBasePath, ICollection<ProjectReference> projectReferences, GacUtility gac, ICollection<Reference> references, ICollection<Compile> compiles, ICollection<None> nones, ICollection<WebReferenceUrl> webReferenceUrls, ICollection<Content> contents, ICollection<Folder> folders, ICollection<WebReferences> webReferencesList, ICollection<EmbeddedResource> embeddedResources, ICollection<BootstrapperPackage> bootstrapperPackages, ICollection<string> globalNamespaceImports, IList<ComReference> comReferenceList) + private static void DigestBuildItems(Project project, ProjectDigest projectDigest, string projectBasePath, ICollection<ProjectReference> projectReferences, ICollection<Reference> references, ICollection<Compile> compiles, ICollection<None> nones, ICollection<WebReferenceUrl> webReferenceUrls, ICollection<Content> contents, ICollection<Folder> folders, ICollection<WebReferences> webReferencesList, ICollection<EmbeddedResource> embeddedResources, ICollection<BootstrapperPackage> bootstrapperPackages, ICollection<string> globalNamespaceImports, IList<ComReference> comReferenceList) { + string targetFramework = projectDigest.TargetFramework != null ? projectDigest.TargetFramework.Substring(0,3) : "2.0"; + GacUtility gac = new GacUtility(); + RspUtility rsp = new RspUtility(); foreach (BuildItemGroup buildItemGroup in project.ItemGroups) { foreach (BuildItem buildItem in buildItemGroup) @@ -183,7 +185,7 @@ namespace NPanday.ProjectImporter.Digest projectReferences.Add(prjRef); break; case "Reference": - Reference reference = new Reference(projectBasePath, gac); + Reference reference = new Reference(projectBasePath); //set processorArchitecture property to platform, it will be used by GacUtility in // order to resolve artifact to right processor architecture if (!string.IsNullOrEmpty(projectDigest.Platform)) @@ -201,7 +203,39 @@ namespace NPanday.ProjectImporter.Digest } if (string.IsNullOrEmpty(reference.HintPath) || !(new FileInfo(reference.HintPath).Exists)) { - reference.AssemblyInfo = buildItem.Include; + if (buildItem.Include.Contains(",")) + { + // complete name + reference.SetAssemblyInfoValues(buildItem.Include); + } + else if (!rsp.IsRspIncluded(buildItem.Include,projectDigest.Language)) + { + // simple name needs to be resolved + List<string> refs = gac.GetAssemblyInfo(buildItem.Include, null, null); + if (refs.Count == 0) + { + Console.WriteLine("Unable to find reference '" + buildItem.Include + "' in " + string.Join("; ", refs.ToArray())); + } + else + { + if (refs.Count > 1) + { + string best = null; + string bestFramework = "0.0"; + foreach (string s in refs) + { + Assembly a = Assembly.ReflectionOnlyLoad(s); + string framework = a.ImageRuntimeVersion.Substring(1,3); + if (framework.CompareTo(targetFramework) <= 0 && framework.CompareTo(bestFramework) > 0) + { + best = s; + bestFramework = framework; + } + } + reference.SetAssemblyInfoValues(best); + } + } + } } if ("NUnit.Framework".Equals(reference.Name, StringComparison.OrdinalIgnoreCase)) { Modified: incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Digest/Algorithms/WebProjectDigestAlgorithm.cs URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Digest/Algorithms/WebProjectDigestAlgorithm.cs?rev=1139414&r1=1139413&r2=1139414&view=diff ============================================================================== --- incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Digest/Algorithms/WebProjectDigestAlgorithm.cs (original) +++ incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Digest/Algorithms/WebProjectDigestAlgorithm.cs Fri Jun 24 19:26:22 2011 @@ -40,8 +40,6 @@ namespace NPanday.ProjectImporter.Digest { public ProjectDigest DigestProject(Dictionary<string, object> projectMap) { - GacUtility gac = new GacUtility(); - ProjectDigest projectDigest = new ProjectDigest(); projectDigest.ProjectType = (VisualStudioProjectTypeEnum)projectMap["ProjectType"]; projectDigest.FullFileName = projectMap["ProjectFullPath"].ToString(); Modified: incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Digest/Model/Reference.cs URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Digest/Model/Reference.cs?rev=1139414&r1=1139413&r2=1139414&view=diff ============================================================================== --- incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Digest/Model/Reference.cs (original) +++ incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/NPanday/ProjectImporter/Digest/Model/Reference.cs Fri Jun 24 19:26:22 2011 @@ -39,30 +39,15 @@ namespace NPanday.ProjectImporter.Digest { #region Constructors - public Reference(string projectBasePath, GacUtility gac) + public Reference(string projectBasePath) : base(projectBasePath) { - this.gac = gac; } #endregion #region Properties - private GacUtility gac; - public GacUtility GacUtility - { - get - { - if (gac == null) - { - gac = new GacUtility(); - } - - return gac; - } - } - private string name; public string Name { @@ -106,21 +91,6 @@ namespace NPanday.ProjectImporter.Digest } } - public string AssemblyInfo - { - set - { - if (value.Split(',').Length > 1) - { - SetAssemblyInfoValues(value); - } - else - { - SetAssemblyValuesFromGac(value); - } - } - } - private string version; public string Version { @@ -512,11 +482,9 @@ namespace NPanday.ProjectImporter.Digest public static string Tokenize(string id) { return id.Replace(".",Path.DirectorySeparatorChar.ToString()); - } - + } - - private void SetAssemblyInfoValues(string assemblyInfo) + public void SetAssemblyInfoValues(string assemblyInfo) { if (!string.IsNullOrEmpty(assemblyInfo)) { @@ -550,15 +518,6 @@ namespace NPanday.ProjectImporter.Digest } - - - private void SetAssemblyValuesFromGac(string name) - { - this.Name = name.Split(',')[0].Trim(); - string str = GacUtility.GetAssemblyInfo(this.Name, version, processorArchitecture); - SetAssemblyInfoValues(str); - } - #endregion Modified: incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/NPanday.Utils.csproj URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/NPanday.Utils.csproj?rev=1139414&r1=1139413&r2=1139414&view=diff ============================================================================== --- incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/NPanday.Utils.csproj (original) +++ incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/NPanday.Utils.csproj Fri Jun 24 19:26:22 2011 @@ -66,6 +66,7 @@ under the License. <Compile Include="NPanday\Utils\MavenRunner.cs" /> <Compile Include="NPanday\Utils\PomHelperUtility.cs" /> <Compile Include="NPanday\Utils\RepositoryUtility.cs" /> + <Compile Include="NPanday\Utils\RspUtility.cs" /> </ItemGroup> <ItemGroup /> <ItemGroup /> Modified: incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/NPanday/Utils/GacUtility.cs URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/NPanday/Utils/GacUtility.cs?rev=1139414&r1=1139413&r2=1139414&view=diff ============================================================================== --- incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/NPanday/Utils/GacUtility.cs (original) +++ incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/NPanday/Utils/GacUtility.cs Fri Jun 24 19:26:22 2011 @@ -20,6 +20,7 @@ #endregion using System; using System.Collections.Generic; +using System.Collections; using System.Text; using System.Diagnostics; @@ -34,14 +35,15 @@ namespace NPanday.Utils public class GacUtility { private string gacs = ""; - private string vbRsp = ""; - private string csRsp = ""; public GacUtility() { // Used to determine which references exist in the GAC, used during VS project import // TODO: we need a better way to determine this by querying the GAC using .NET // rather than parsing command output + // consider this: http://www.codeproject.com/KB/dotnet/undocumentedfusion.aspx + // (works, but seems to be missing the processor architecture) + Process p = new Process(); try @@ -66,40 +68,18 @@ namespace NPanday.Utils { throw new Exception( "Unable to execute gacutil - check that your PATH has been set correctly (Message: " + exception.Message + ")" ); } - - - string msBuildPath = Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(string)).Location); - string f35 = Path.GetFullPath(Environment.SystemDirectory + @"\..\Microsoft.NET\Framework\v3.5"); - string f4 = Path.GetFullPath(Environment.SystemDirectory + @"\..\Microsoft.NET\Framework\v4.0.30319"); - if (Directory.Exists(f4)) - { - msBuildPath = f4; - } - try - { - csRsp = File.OpenText(msBuildPath + @"\csc.rsp").ReadToEnd(); - } - catch (Exception){} - - - try - { - vbRsp = File.OpenText(msBuildPath + @"\vbc.rsp").ReadToEnd(); - } - catch (Exception){} - - - } - public string GetAssemblyInfo(string assemblyName, string version, string processorArchitecture) + public List<string> GetAssemblyInfo(string assemblyName, string version, string processorArchitecture) { if (string.IsNullOrEmpty(assemblyName)) { return null; } + List<string> results = new List<string>(); + string architecture = String.Empty; if (! string.IsNullOrEmpty(processorArchitecture)) { @@ -121,66 +101,9 @@ namespace NPanday.Utils foreach (Match match in matches) { - return match.Value.Trim(); - } - - - return null; - } - - public bool IsRspIncluded(string assemblyName, string language) - { - if ("vb".Equals(language, StringComparison.OrdinalIgnoreCase)) - { - return IsVbcRspIncluded(assemblyName); - } - else - { - return IsCscRspIncluded(assemblyName); - } - } - - - - public bool IsCscRspIncluded(string assemblyName) - { - if (string.IsNullOrEmpty(assemblyName)) - { - return false; - } - - Regex regex = new Regex(@"\s*/r:" + assemblyName + @"\.dll", RegexOptions.IgnoreCase); - MatchCollection matches = regex.Matches(csRsp); - - - foreach (Match match in matches) - { - return true; - } - - - return false; - } - - - public bool IsVbcRspIncluded(string assemblyName) - { - if (string.IsNullOrEmpty(assemblyName)) - { - return false; - } - - Regex regex = new Regex(@"\s*/r:" + assemblyName + @"\.dll", RegexOptions.IgnoreCase); - MatchCollection matches = regex.Matches(csRsp); - - - foreach (Match match in matches) - { - return true; + results.Add(match.Value.Trim()); } - - - return false; + return results; } private static string GetRegexProcessorArchitectureFromString(string input) Modified: incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/NPanday/Utils/PomHelperUtility.cs URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/NPanday/Utils/PomHelperUtility.cs?rev=1139414&r1=1139413&r2=1139414&view=diff ============================================================================== --- incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/NPanday/Utils/PomHelperUtility.cs (original) +++ incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/NPanday/Utils/PomHelperUtility.cs Fri Jun 24 19:26:22 2011 @@ -43,7 +43,7 @@ namespace NPanday.Utils private FileInfo pom; public bool isWebRefEmpty = false; - GacUtility gacUtil = new GacUtility(); + RspUtility rspUtil = new RspUtility(); public PomHelperUtility(Solution solution, Project project) { @@ -814,12 +814,12 @@ namespace NPanday.Utils if ("vb".Equals(NPandayCompilerPluginLanguage)) { - if (gacUtil.IsVbcRspIncluded(dependency.artifactId)) + if (rspUtil.IsVbcRspIncluded(dependency.artifactId)) return; } else { - if (gacUtil.IsCscRspIncluded((dependency.artifactId))) + if (rspUtil.IsCscRspIncluded((dependency.artifactId))) return; } if (IsPomDependency(dependency)) Added: incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/NPanday/Utils/RspUtility.cs URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/NPanday/Utils/RspUtility.cs?rev=1139414&view=auto ============================================================================== --- incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/NPanday/Utils/RspUtility.cs (added) +++ incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/NPanday/Utils/RspUtility.cs Fri Jun 24 19:26:22 2011 @@ -0,0 +1,113 @@ +#region Apache License, Version 2.0 +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// +#endregion +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; +using System.Text.RegularExpressions; + +namespace NPanday.Utils +{ + public class RspUtility + { + private string vbRsp = ""; + private string csRsp = ""; + + public RspUtility() + { + string msBuildPath = Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(string)).Location); + string f35 = Path.GetFullPath(Environment.SystemDirectory + @"\..\Microsoft.NET\Framework\v3.5"); + string f4 = Path.GetFullPath(Environment.SystemDirectory + @"\..\Microsoft.NET\Framework\v4.0.30319"); + if (Directory.Exists(f4)) + { + msBuildPath = f4; + } + try + { + csRsp = File.OpenText(msBuildPath + @"\csc.rsp").ReadToEnd(); + } + catch (Exception) { } + + + try + { + vbRsp = File.OpenText(msBuildPath + @"\vbc.rsp").ReadToEnd(); + } + catch (Exception) { } + } + + + public bool IsRspIncluded(string assemblyName, string language) + { + if ("vb".Equals(language, StringComparison.OrdinalIgnoreCase)) + { + return IsVbcRspIncluded(assemblyName); + } + else + { + return IsCscRspIncluded(assemblyName); + } + } + + + + public bool IsCscRspIncluded(string assemblyName) + { + if (string.IsNullOrEmpty(assemblyName)) + { + return false; + } + + Regex regex = new Regex(@"\s*/r:" + assemblyName + @"\.dll", RegexOptions.IgnoreCase); + MatchCollection matches = regex.Matches(csRsp); + + + foreach (Match match in matches) + { + return true; + } + + + return false; + } + + + public bool IsVbcRspIncluded(string assemblyName) + { + if (string.IsNullOrEmpty(assemblyName)) + { + return false; + } + + Regex regex = new Regex(@"\s*/r:" + assemblyName + @"\.dll", RegexOptions.IgnoreCase); + MatchCollection matches = regex.Matches(csRsp); + + + foreach (Match match in matches) + { + return true; + } + + + return false; + } + } +}