incubator-nmaven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sisb...@apache.org
Subject svn commit: r509398 - in /incubator/nmaven/branches/SI_IDE/assemblies/NMaven.Core: pom.xml src/main/csharp/Core/Impl/NMavenContextImpl.cs
Date Tue, 20 Feb 2007 00:50:40 GMT
Author: sisbell
Date: Mon Feb 19 16:50:39 2007
New Revision: 509398

URL: http://svn.apache.org/viewvc?view=rev&rev=509398
Log:
FEATURE: Now handles dynamically adding dependencies to the csproj file by parsing the cs
class files and extracting dependencies.

Modified:
    incubator/nmaven/branches/SI_IDE/assemblies/NMaven.Core/pom.xml
    incubator/nmaven/branches/SI_IDE/assemblies/NMaven.Core/src/main/csharp/Core/Impl/NMavenContextImpl.cs

Modified: incubator/nmaven/branches/SI_IDE/assemblies/NMaven.Core/pom.xml
URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/SI_IDE/assemblies/NMaven.Core/pom.xml?view=diff&rev=509398&r1=509397&r2=509398
==============================================================================
--- incubator/nmaven/branches/SI_IDE/assemblies/NMaven.Core/pom.xml (original)
+++ incubator/nmaven/branches/SI_IDE/assemblies/NMaven.Core/pom.xml Mon Feb 19 16:50:39 2007
@@ -1,4 +1,4 @@
-<project>
+<project xmlns="http://maven.apache.org/POM/4.0.0">>
   <modelVersion>4.0.0</modelVersion>
   <groupId>NMaven.Core</groupId>
   <artifactId>NMaven.Core</artifactId>

Modified: incubator/nmaven/branches/SI_IDE/assemblies/NMaven.Core/src/main/csharp/Core/Impl/NMavenContextImpl.cs
URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/SI_IDE/assemblies/NMaven.Core/src/main/csharp/Core/Impl/NMavenContextImpl.cs?view=diff&rev=509398&r1=509397&r2=509398
==============================================================================
--- incubator/nmaven/branches/SI_IDE/assemblies/NMaven.Core/src/main/csharp/Core/Impl/NMavenContextImpl.cs
(original)
+++ incubator/nmaven/branches/SI_IDE/assemblies/NMaven.Core/src/main/csharp/Core/Impl/NMavenContextImpl.cs
Mon Feb 19 16:50:39 2007
@@ -4,6 +4,8 @@
 using NMaven.Model;
 using NMaven.Core;
 using Microsoft.Build.BuildEngine;
+using System.Collections.Generic;
+using System.Reflection;
 
 namespace NMaven.Core.Impl {
 
@@ -33,11 +35,13 @@
 			DirectoryInfo sourcedir = new DirectoryInfo(basedir + @"src\main\csharp");
             DirectoryInfo[] directoryInfos = rootDirectoryInfo.GetDirectories();
             if(directoryInfos != null && directoryInfos.Length > 0)
-            {
+            {              	
             	if(folderGroup == null) folderGroup = project.AddNewItemGroup();
             	
             	foreach(DirectoryInfo di in directoryInfos) 
             	{
+              		if(di.FullName.Contains(".svn") || di.FullName.Contains(@"obj") || di.FullName.Contains(@"bin"))
+    					continue;             		
             		folderGroup.AddNewItem("Folder", di.FullName.Substring(sourcedir.FullName.Length
+ 1));
                 	addFoldersToProject(project, folderGroup, di);
             	}           	
@@ -54,6 +58,8 @@
             	
             	foreach(DirectoryInfo di in directoryInfos) 
             	{  
+              		if(di.FullName.Contains(".svn") || di.FullName.Contains("obj") || di.FullName.Contains("bin"))
+    					continue;       			
 	            	foreach(FileInfo fileInfo in di.GetFiles()) 
 	            	{
 	            		BuildItem buildItem = 
@@ -66,6 +72,59 @@
             }				
 		}
 		
+		private void addProjectDependencies(Project project, NMaven.Model.Model model, DirectoryInfo
rootDirectoryInfo) 
+		{
+			
+			BuildItemGroup group = project.AddNewItemGroup();
+			group.AddNewItem("Reference", "System.Xml");
+			
+			foreach(Dependency dependency in model.dependencies) {
+				String repoPath = @localRepository + dependency.groupId.Replace(".", "\\")
+					+ "\\" + dependency.artifactId + "\\" + dependency.version + "\\" + dependency.artifactId
+ ".dll";
+				BuildItem buildItem = group.AddNewItem("Reference", dependency.artifactId);
+				if(!dependency.GetType().Equals("gac")) buildItem.SetMetadata("HintPath", repoPath, true);
+			}
+			
+			DirectoryInfo sourcedir = new DirectoryInfo(basedir + @"src\main\csharp");
+            DirectoryInfo[] directoryInfos = rootDirectoryInfo.GetDirectories();
+            
+            ClassParser classParser = new ClassParser();
+            List<FileInfo> fileInfos = new List<FileInfo>();
+            addFileInfosFromSourceDirectories(rootDirectoryInfo, fileInfos);
+            List<string> dependencies = classParser.getDependencies(fileInfos);
+            foreach(string dependency in dependencies)
+            {
+            	try {
+            		DirectoryInfo fileInfo = new DirectoryInfo(@"C:\WINDOWS\assembly\GAC_MSIL\"
+ dependency);
+            		if(fileInfo.Exists) {
+            			group.AddNewItem("Reference", dependency);	
+            		} else 
+            			Console.WriteLine("FNE: " + fileInfo.FullName);
+            	}
+            	catch(Exception e) 
+            	{
+            		Console.WriteLine(e.Message);
+            	}
+            	
+            }
+		}
+		
+		
+		private void addFileInfosFromSourceDirectories(DirectoryInfo rootDirectoryInfo, List<FileInfo>
fileInfos ) 
+		{
+            DirectoryInfo[] directoryInfos = rootDirectoryInfo.GetDirectories();
+            if(directoryInfos != null && directoryInfos.Length > 0)
+            {  	
+            	foreach(DirectoryInfo di in directoryInfos) 
+            	{  
+              		if(di.FullName.Contains(".svn") || di.FullName.Contains("obj") || di.FullName.Contains("bin"))
+              			continue;
+              		fileInfos.AddRange(di.GetFiles());
+              		addFileInfosFromSourceDirectories(di, fileInfos);
+            	}           	
+            }
+		}
+		
 		private string getOutputType(String type)
 		{
 			if (type.Equals("library")) return "Library";
@@ -94,18 +153,11 @@
             
             project.AddNewImport(@"$(MSBuildBinPath)\Microsoft.CSharp.Targets", null);
 
-            DirectoryInfo rootDirectoryInfo = new DirectoryInfo(basedir + @"src\main\csharp");
           
+            DirectoryInfo rootDirectoryInfo = new DirectoryInfo(basedir + @"src\main\csharp");

+            addProjectDependencies(project, model, rootDirectoryInfo);
             addFoldersToProject(project, null, rootDirectoryInfo);
             addClassFilesToProject(project, null, rootDirectoryInfo);
-            
-			BuildItemGroup group = project.AddNewItemGroup();
-			foreach(Dependency dependency in model.dependencies) {
-				String repoPath = @localRepository + dependency.groupId.Replace(".", "\\")
-					+ "\\" + dependency.artifactId + "\\" + dependency.version + "\\" + dependency.artifactId
+ ".dll";
-				BuildItem buildItem = group.AddNewItem("Reference", dependency.artifactId);
-				if(!dependency.GetType().Equals("gac")) buildItem.SetMetadata("HintPath", repoPath, true);
-			}
-			
+            			
 			return project;
 			
 		}
@@ -118,6 +170,39 @@
 		
 		private class ClassParser {
 			
+			public List<string> getDependencies(List<FileInfo> fileInfos) 
+			{
+				List<string> dependencies = new List<string>();
+				foreach(FileInfo fileInfo in fileInfos) 
+				{
+					try 
+			        {
+			            using (StreamReader sr = new StreamReader(fileInfo.FullName)) 
+			            {
+			                String line;
+			                while ((line = sr.ReadLine()) != null) 
+			                {
+			                	if (line.StartsWith("namespace")) break;
+			                	if (line.StartsWith("//")) continue;
+			                	if (line.StartsWith("using")) {
+			                		string[] tokens = line.Remove(line.Length - 1).Split(new char[1]{' '});
+			                		if(!dependencies.Contains(tokens[1]))
+			                		{
+			                			dependencies.Add(tokens[1]);
+			                		}			                		
+			                	}
+			                }
+			            }
+			        }
+			        catch (Exception e) 
+			        {
+			            Console.WriteLine(e.Message);
+			        }
+
+				}
+				
+				return dependencies;
+			}
 		
 		}
 	}



Mime
View raw message