You are viewing a plain text version of this content. The canonical link for it is here.
Posted to nmaven-commits@incubator.apache.org by br...@apache.org on 2008/06/30 12:54:03 UTC
svn commit: r672753 [5/9] - in /incubator/nmaven/branches/NMAVEN_0.14:
archetypes/maven-archetype-dotnet-simple/src/main/resources/archetype-resources/src/main/csharp/Sample/
archetypes/maven-archetype-dotnet-simple/src/main/resources/archetype-resourc...
Modified: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.Solution/ProjectGeneratorImpl.cs
URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.Solution/ProjectGeneratorImpl.cs?rev=672753&r1=672752&r2=672753&view=diff
==============================================================================
--- incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.Solution/ProjectGeneratorImpl.cs (original)
+++ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.Solution/ProjectGeneratorImpl.cs Mon Jun 30 05:54:00 2008
@@ -1,370 +1,370 @@
-#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.IO;
-using System.Reflection;
-using System.Text;
-using System.Xml.Serialization;
-
-using Microsoft.Build.BuildEngine;
-
-using NMaven.Artifact;
-using NMaven.Solution;
-using NMaven.Model.Pom;
-
-namespace NMaven.Solution.Impl
-{
- /// <summary>
- /// Implementation of the IProjectGenerator.
- /// </summary>
- internal sealed class ProjectGeneratorImpl : IProjectGenerator
- {
-
- /// <summary>
- /// Constructor
- /// </summary>
- internal ProjectGeneratorImpl()
- {
- }
-
- public IProjectReference GenerateProjectFor(NMaven.Model.Pom.Model model,
- DirectoryInfo sourceFileDirectory,
- String projectFileName,
- ICollection<IProjectReference> projectReferences,
- DirectoryInfo localRepository)
- {
- Guid projectGuid = Guid.NewGuid();
-
- if (projectReferences == null)
- {
- projectReferences = new List<IProjectReference>();
- }
-
- Project project = GetProjectFromPomModel(model,
- sourceFileDirectory,
- projectFileName,
- projectGuid,
- @"..\..\..\target\bin\Debug\",
- @"..\..\..\target\obj\",
- projectReferences,
- localRepository);
- FileInfo fileInfo = new FileInfo(sourceFileDirectory.FullName + @"\" + projectFileName + ".csproj");
- project.Save(fileInfo.FullName);
-
- IProjectReference projectReference = Factory.createDefaultProjectReference();
- projectReference.CSProjectFile = fileInfo;
- projectReference.ProjectGuid = projectGuid;
- projectReference.ProjectName = projectFileName;
- return projectReference;
- }
-
- public void GenerateSolutionFor(FileInfo fileInfo, ICollection<IProjectReference> projectReferences)
- {
- TextWriter writer =
- new StreamWriter(fileInfo.FullName, false, System.Text.Encoding.UTF8);
- writer.WriteLine("");
- writer.WriteLine("Microsoft Visual Studio Solution File, Format Version 9.00");
- writer.WriteLine("# Visual Studio 2005");
- writer.WriteLine("# SharpDevelop 2.1.0.2376");
-
- Guid solutionGuid = Guid.NewGuid();
- foreach(IProjectReference projectReference in projectReferences)
- {
- writer.Write("Project(\"{");
- writer.Write("FAE04EC0-301F-11D3-BF4B-00C04F79EFBC");
- writer.Write("}\") = \"");
- writer.Write(projectReference.ProjectName);
- writer.Write("\", \"");
- writer.Write(projectReference.CSProjectFile.FullName);
- writer.Write("\", \"{");
- writer.Write(projectReference.ProjectGuid.ToString());
- writer.WriteLine("}\"");
- writer.WriteLine("EndProject");
-
- }
- writer.Flush();
- writer.Close();
- Console.WriteLine("NMAVEN-000-000: Generate solution file: File Name = " + fileInfo.FullName);
- }
-
- public NMaven.Model.Pom.Model CreatePomModelFor(String fileName)
- {
- TextReader reader = new StreamReader(fileName);
- XmlSerializer serializer = new XmlSerializer(typeof(NMaven.Model.Pom.Model));
- return (NMaven.Model.Pom.Model) serializer.Deserialize(reader);
- }
-
- /// <summary>
- /// Returns a project binding (xmlns="http://schemas.microsoft.com/developer/msbuild/2003") from the given model
- /// (pom.xml) file
- /// </summary>
- /// <param name="model">the model binding for a pom.xml file</param>
- /// <param name="sourceFileDirectory">the directory containing the source files</param>
- /// <param name="assemblyName">the name of the assembly: often corresponds to the artifact id from the pom</param>
- /// <param name="projectGuid">the GUID of the project</param>
- /// <param name="assemblyOutputPath">directory where the IDE output files are placed</param>
- /// <param name="baseIntermediateOutputPath">directory where the IDE output files are placed</param>
- /// <param name="projectReferences">references to other projects that this project is dependent upon</param>
- /// <returns>Returns a project binding for the specified model</returns>
- private Project GetProjectFromPomModel(NMaven.Model.Pom.Model model,
- DirectoryInfo sourceFileDirectory,
- String assemblyName,
- Guid projectGuid,
- String assemblyOutputPath,
- String baseIntermediateOutputPath,
- ICollection<IProjectReference> projectReferences,
- DirectoryInfo localRepository)
- {
- if(model == null || sourceFileDirectory == null)
- {
- throw new ExecutionException("NMAVEN-000-000: Missing required parameter.");
- }
- Engine engine = new Engine(Environment.GetEnvironmentVariable("SystemRoot") + @"\Microsoft.NET\Framework\v2.0.50727");
- Project project = new Project(engine);
-
- Console.WriteLine("ProjectGuid = " + projectGuid.ToString() + ", RootNameSpace = " +
- model.groupId + ", AssemblyName = " + assemblyName + ", BaseIntPath = " +
- baseIntermediateOutputPath + ", OutputType = " + GetOutputType(model.packaging) +
- ", Packaging = " + model.packaging);
- //Main Properties
- BuildPropertyGroup groupProject = project.AddNewPropertyGroup(false);
- groupProject.AddNewProperty("ProjectGuid", "{" + projectGuid.ToString() + "}");
- BuildProperty buildProperty = groupProject.AddNewProperty("Configuration", "Debug");
- buildProperty.Condition = " '$(Configuration)' == '' ";
- groupProject.AddNewProperty("RootNameSpace", model.groupId);
- groupProject.AddNewProperty("AssemblyName", assemblyName);
- groupProject.AddNewProperty("BaseIntermediateOutputPath", baseIntermediateOutputPath);
- groupProject.AddNewProperty("OutputType", GetOutputType(model.packaging));
-
- //Debug Properties
- groupProject = project.AddNewPropertyGroup(false);
- buildProperty.Condition = " '$(Configuration)' == '' ";
- groupProject.AddNewProperty( "OutputPath", assemblyOutputPath, false);
-
- project.AddNewImport(@"$(MSBuildBinPath)\Microsoft.CSharp.Targets", null);
- DirectoryInfo configDirectory = new DirectoryInfo(Environment.CurrentDirectory + @"\src\main\config");
- if(configDirectory.Exists)
- {
- BuildItemGroup configGroup = project.AddNewItemGroup();
- foreach(FileInfo fileInfo in configDirectory.GetFiles())
- {
- if(fileInfo.Extension.Equals("exe.config"))
- {
- configGroup.AddNewItem("None", @"src\main\config\" + fileInfo.Name);
- }
- }
- }
- AddProjectDependencies(project, model, sourceFileDirectory, localRepository);
- AddFoldersToProject(project, null, sourceFileDirectory, sourceFileDirectory);
- AddClassFilesToProject(project, null, sourceFileDirectory, sourceFileDirectory);
- AddProjectReferences(project, assemblyName, projectReferences);
- return project;
-
- }
-
- private void AddProjectReferences(Project project, String projectName, ICollection<IProjectReference> projectReferences)
- {
- BuildItemGroup itemGroup = project.AddNewItemGroup();
- foreach(IProjectReference projectReference in projectReferences)
- {
- BuildItem buildItem = itemGroup.AddNewItem("ProjectReference", projectReference.CSProjectFile.FullName);
- buildItem.SetMetadata("Project", "{" + projectReference.ProjectGuid.ToString() + "}");
- buildItem.SetMetadata("Name", projectName);
- }
- }
-
- private void AddFoldersToProject(Project project, BuildItemGroup folderGroup, DirectoryInfo rootDirectory,
- DirectoryInfo sourceFileDirectory)
- {
- DirectoryInfo[] directoryInfos = rootDirectory.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(sourceFileDirectory.FullName.Length));
- AddFoldersToProject(project, folderGroup, di, sourceFileDirectory);
- }
- }
- }
-
- private void AddClassFilesToProject(Project project, BuildItemGroup compileGroup, DirectoryInfo rootDirectory,
- DirectoryInfo sourceFileDirectory)
- {
- DirectoryInfo[] directoryInfos = rootDirectory.GetDirectories();
- if(directoryInfos != null && directoryInfos.Length > 0)
- {
- if (compileGroup == null)
- {
- compileGroup = project.AddNewItemGroup();
- }
-
- 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 =
- compileGroup.AddNewItem("Compile",
- fileInfo.FullName.Substring(sourceFileDirectory.FullName.Length));
- }
- AddClassFilesToProject(project, compileGroup, di, sourceFileDirectory);
- }
- }
- }
-
- private void AddProjectDependencies(Project project, NMaven.Model.Pom.Model model, DirectoryInfo sourceFileDirectory,
- DirectoryInfo localRepository)
- {
- BuildItemGroup group = project.AddNewItemGroup();
- group.AddNewItem("Reference", "System.Xml");
- if(model.dependencies != null)
- {
- ArtifactContext artifactContext = new ArtifactContext();
- foreach(Dependency dependency in model.dependencies)
- {
- //String artifactExtension = (dependency.type == "module") ? "dll" : GetExtension(dependency.type);
- NMaven.Artifact.Artifact dependencyArtifact = artifactContext.CreateArtifact(dependency.groupId,
- dependency.artifactId, dependency.version, dependency.type);
-
- String repoPath = PathUtil.GetUserAssemblyCacheFileFor(dependencyArtifact, localRepository).FullName;
- BuildItem buildItem = group.AddNewItem("Reference", dependency.artifactId);
- //TODO: Fix this. Just because it is in the GAC on the system that builds the .csproj does not mean
- //it is in the GAC on another system.
- if (!dependency.GetType().Equals("gac") && !IsInGac(dependency.artifactId))
- {
- buildItem.SetMetadata("HintPath", repoPath, false);
- }
- }
- }
-
- DirectoryInfo[] directoryInfos = sourceFileDirectory.GetDirectories();
-
- ClassParser classParser = new ClassParser();
- List<FileInfo> fileInfos = new List<FileInfo>();
- AddFileInfosFromSourceDirectories(sourceFileDirectory, fileInfos);
- List<String> dependencies = classParser.GetDependencies(fileInfos);
- foreach(String dependency in dependencies)
- {
- try {
- String assembly = GetAssemblyFor(dependency);
- if(IsInGac(assembly)) {
- group.AddNewItem("Reference", assembly);
- }
- }
- catch(Exception e)
- {
- Console.WriteLine("NMAVEN-000-000: Could not find assembly dependency", e.Message);
- }
- }
- }
-
- private bool IsInGac(String assembly)
- {
- return new DirectoryInfo(Environment.GetEnvironmentVariable("SystemRoot")
- + @"\assembly\GAC_MSIL\" + assembly).Exists;
- }
-
- private String GetAssemblyFor(String dependency)
- {
- return (dependency.Trim().Equals("System.Resources")) ? "System.Windows.Forms" : dependency;
- }
-
- private void AddFileInfosFromSourceDirectories(DirectoryInfo sourceFileDirectory, List<FileInfo> fileInfos )
- {
- DirectoryInfo[] directoryInfos = sourceFileDirectory.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") || type.Equals("netplugin") || type.Equals("visual-studio-addin")
- || type.Equals("sharp-develop-addin") || type.Equals("nar")) return "Library";
- else if (type.Equals("exe")) return "Exe";
- else if (type.Equals("winexe")) return "WinExe";
- else if (type.Equals("module")) return "Module";
- return null;
- }
-
- private String GetExtension(String type)
- {
- if (type.Equals("library") || type.Equals("netplugin") ) return "dll";
- else if (type.Equals("exe")) return "exe";
- else if (type.Equals("winexe")) return "exe";
- else if (type.Equals("module")) return "netmodule";
- return null;
- }
-
- 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;
- }
- }
- }
-}
+#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.IO;
+using System.Reflection;
+using System.Text;
+using System.Xml.Serialization;
+
+using Microsoft.Build.BuildEngine;
+
+using NMaven.Artifact;
+using NMaven.Solution;
+using NMaven.Model.Pom;
+
+namespace NMaven.Solution.Impl
+{
+ /// <summary>
+ /// Implementation of the IProjectGenerator.
+ /// </summary>
+ internal sealed class ProjectGeneratorImpl : IProjectGenerator
+ {
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ internal ProjectGeneratorImpl()
+ {
+ }
+
+ public IProjectReference GenerateProjectFor(NMaven.Model.Pom.Model model,
+ DirectoryInfo sourceFileDirectory,
+ String projectFileName,
+ ICollection<IProjectReference> projectReferences,
+ DirectoryInfo localRepository)
+ {
+ Guid projectGuid = Guid.NewGuid();
+
+ if (projectReferences == null)
+ {
+ projectReferences = new List<IProjectReference>();
+ }
+
+ Project project = GetProjectFromPomModel(model,
+ sourceFileDirectory,
+ projectFileName,
+ projectGuid,
+ @"..\..\..\target\bin\Debug\",
+ @"..\..\..\target\obj\",
+ projectReferences,
+ localRepository);
+ FileInfo fileInfo = new FileInfo(sourceFileDirectory.FullName + @"\" + projectFileName + ".csproj");
+ project.Save(fileInfo.FullName);
+
+ IProjectReference projectReference = Factory.createDefaultProjectReference();
+ projectReference.CSProjectFile = fileInfo;
+ projectReference.ProjectGuid = projectGuid;
+ projectReference.ProjectName = projectFileName;
+ return projectReference;
+ }
+
+ public void GenerateSolutionFor(FileInfo fileInfo, ICollection<IProjectReference> projectReferences)
+ {
+ TextWriter writer =
+ new StreamWriter(fileInfo.FullName, false, System.Text.Encoding.UTF8);
+ writer.WriteLine("");
+ writer.WriteLine("Microsoft Visual Studio Solution File, Format Version 9.00");
+ writer.WriteLine("# Visual Studio 2005");
+ writer.WriteLine("# SharpDevelop 2.1.0.2376");
+
+ Guid solutionGuid = Guid.NewGuid();
+ foreach(IProjectReference projectReference in projectReferences)
+ {
+ writer.Write("Project(\"{");
+ writer.Write("FAE04EC0-301F-11D3-BF4B-00C04F79EFBC");
+ writer.Write("}\") = \"");
+ writer.Write(projectReference.ProjectName);
+ writer.Write("\", \"");
+ writer.Write(projectReference.CSProjectFile.FullName);
+ writer.Write("\", \"{");
+ writer.Write(projectReference.ProjectGuid.ToString());
+ writer.WriteLine("}\"");
+ writer.WriteLine("EndProject");
+
+ }
+ writer.Flush();
+ writer.Close();
+ Console.WriteLine("NMAVEN-000-000: Generate solution file: File Name = " + fileInfo.FullName);
+ }
+
+ public NMaven.Model.Pom.Model CreatePomModelFor(String fileName)
+ {
+ TextReader reader = new StreamReader(fileName);
+ XmlSerializer serializer = new XmlSerializer(typeof(NMaven.Model.Pom.Model));
+ return (NMaven.Model.Pom.Model) serializer.Deserialize(reader);
+ }
+
+ /// <summary>
+ /// Returns a project binding (xmlns="http://schemas.microsoft.com/developer/msbuild/2003") from the given model
+ /// (pom.xml) file
+ /// </summary>
+ /// <param name="model">the model binding for a pom.xml file</param>
+ /// <param name="sourceFileDirectory">the directory containing the source files</param>
+ /// <param name="assemblyName">the name of the assembly: often corresponds to the artifact id from the pom</param>
+ /// <param name="projectGuid">the GUID of the project</param>
+ /// <param name="assemblyOutputPath">directory where the IDE output files are placed</param>
+ /// <param name="baseIntermediateOutputPath">directory where the IDE output files are placed</param>
+ /// <param name="projectReferences">references to other projects that this project is dependent upon</param>
+ /// <returns>Returns a project binding for the specified model</returns>
+ private Project GetProjectFromPomModel(NMaven.Model.Pom.Model model,
+ DirectoryInfo sourceFileDirectory,
+ String assemblyName,
+ Guid projectGuid,
+ String assemblyOutputPath,
+ String baseIntermediateOutputPath,
+ ICollection<IProjectReference> projectReferences,
+ DirectoryInfo localRepository)
+ {
+ if(model == null || sourceFileDirectory == null)
+ {
+ throw new ExecutionException("NMAVEN-000-000: Missing required parameter.");
+ }
+ Engine engine = new Engine(Environment.GetEnvironmentVariable("SystemRoot") + @"\Microsoft.NET\Framework\v2.0.50727");
+ Project project = new Project(engine);
+
+ Console.WriteLine("ProjectGuid = " + projectGuid.ToString() + ", RootNameSpace = " +
+ model.groupId + ", AssemblyName = " + assemblyName + ", BaseIntPath = " +
+ baseIntermediateOutputPath + ", OutputType = " + GetOutputType(model.packaging) +
+ ", Packaging = " + model.packaging);
+ //Main Properties
+ BuildPropertyGroup groupProject = project.AddNewPropertyGroup(false);
+ groupProject.AddNewProperty("ProjectGuid", "{" + projectGuid.ToString() + "}");
+ BuildProperty buildProperty = groupProject.AddNewProperty("Configuration", "Debug");
+ buildProperty.Condition = " '$(Configuration)' == '' ";
+ groupProject.AddNewProperty("RootNameSpace", model.groupId);
+ groupProject.AddNewProperty("AssemblyName", assemblyName);
+ groupProject.AddNewProperty("BaseIntermediateOutputPath", baseIntermediateOutputPath);
+ groupProject.AddNewProperty("OutputType", GetOutputType(model.packaging));
+
+ //Debug Properties
+ groupProject = project.AddNewPropertyGroup(false);
+ buildProperty.Condition = " '$(Configuration)' == '' ";
+ groupProject.AddNewProperty( "OutputPath", assemblyOutputPath, false);
+
+ project.AddNewImport(@"$(MSBuildBinPath)\Microsoft.CSharp.Targets", null);
+ DirectoryInfo configDirectory = new DirectoryInfo(Environment.CurrentDirectory + @"\src\main\config");
+ if(configDirectory.Exists)
+ {
+ BuildItemGroup configGroup = project.AddNewItemGroup();
+ foreach(FileInfo fileInfo in configDirectory.GetFiles())
+ {
+ if(fileInfo.Extension.Equals("exe.config"))
+ {
+ configGroup.AddNewItem("None", @"src\main\config\" + fileInfo.Name);
+ }
+ }
+ }
+ AddProjectDependencies(project, model, sourceFileDirectory, localRepository);
+ AddFoldersToProject(project, null, sourceFileDirectory, sourceFileDirectory);
+ AddClassFilesToProject(project, null, sourceFileDirectory, sourceFileDirectory);
+ AddProjectReferences(project, assemblyName, projectReferences);
+ return project;
+
+ }
+
+ private void AddProjectReferences(Project project, String projectName, ICollection<IProjectReference> projectReferences)
+ {
+ BuildItemGroup itemGroup = project.AddNewItemGroup();
+ foreach(IProjectReference projectReference in projectReferences)
+ {
+ BuildItem buildItem = itemGroup.AddNewItem("ProjectReference", projectReference.CSProjectFile.FullName);
+ buildItem.SetMetadata("Project", "{" + projectReference.ProjectGuid.ToString() + "}");
+ buildItem.SetMetadata("Name", projectName);
+ }
+ }
+
+ private void AddFoldersToProject(Project project, BuildItemGroup folderGroup, DirectoryInfo rootDirectory,
+ DirectoryInfo sourceFileDirectory)
+ {
+ DirectoryInfo[] directoryInfos = rootDirectory.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(sourceFileDirectory.FullName.Length));
+ AddFoldersToProject(project, folderGroup, di, sourceFileDirectory);
+ }
+ }
+ }
+
+ private void AddClassFilesToProject(Project project, BuildItemGroup compileGroup, DirectoryInfo rootDirectory,
+ DirectoryInfo sourceFileDirectory)
+ {
+ DirectoryInfo[] directoryInfos = rootDirectory.GetDirectories();
+ if(directoryInfos != null && directoryInfos.Length > 0)
+ {
+ if (compileGroup == null)
+ {
+ compileGroup = project.AddNewItemGroup();
+ }
+
+ 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 =
+ compileGroup.AddNewItem("Compile",
+ fileInfo.FullName.Substring(sourceFileDirectory.FullName.Length));
+ }
+ AddClassFilesToProject(project, compileGroup, di, sourceFileDirectory);
+ }
+ }
+ }
+
+ private void AddProjectDependencies(Project project, NMaven.Model.Pom.Model model, DirectoryInfo sourceFileDirectory,
+ DirectoryInfo localRepository)
+ {
+ BuildItemGroup group = project.AddNewItemGroup();
+ group.AddNewItem("Reference", "System.Xml");
+ if(model.dependencies != null)
+ {
+ ArtifactContext artifactContext = new ArtifactContext();
+ foreach(Dependency dependency in model.dependencies)
+ {
+ //String artifactExtension = (dependency.type == "module") ? "dll" : GetExtension(dependency.type);
+ NMaven.Artifact.Artifact dependencyArtifact = artifactContext.CreateArtifact(dependency.groupId,
+ dependency.artifactId, dependency.version, dependency.type);
+
+ String repoPath = PathUtil.GetUserAssemblyCacheFileFor(dependencyArtifact, localRepository).FullName;
+ BuildItem buildItem = group.AddNewItem("Reference", dependency.artifactId);
+ //TODO: Fix this. Just because it is in the GAC on the system that builds the .csproj does not mean
+ //it is in the GAC on another system.
+ if (!dependency.GetType().Equals("gac") && !IsInGac(dependency.artifactId))
+ {
+ buildItem.SetMetadata("HintPath", repoPath, false);
+ }
+ }
+ }
+
+ DirectoryInfo[] directoryInfos = sourceFileDirectory.GetDirectories();
+
+ ClassParser classParser = new ClassParser();
+ List<FileInfo> fileInfos = new List<FileInfo>();
+ AddFileInfosFromSourceDirectories(sourceFileDirectory, fileInfos);
+ List<String> dependencies = classParser.GetDependencies(fileInfos);
+ foreach(String dependency in dependencies)
+ {
+ try {
+ String assembly = GetAssemblyFor(dependency);
+ if(IsInGac(assembly)) {
+ group.AddNewItem("Reference", assembly);
+ }
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("NMAVEN-000-000: Could not find assembly dependency", e.Message);
+ }
+ }
+ }
+
+ private bool IsInGac(String assembly)
+ {
+ return new DirectoryInfo(Environment.GetEnvironmentVariable("SystemRoot")
+ + @"\assembly\GAC_MSIL\" + assembly).Exists;
+ }
+
+ private String GetAssemblyFor(String dependency)
+ {
+ return (dependency.Trim().Equals("System.Resources")) ? "System.Windows.Forms" : dependency;
+ }
+
+ private void AddFileInfosFromSourceDirectories(DirectoryInfo sourceFileDirectory, List<FileInfo> fileInfos )
+ {
+ DirectoryInfo[] directoryInfos = sourceFileDirectory.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") || type.Equals("netplugin") || type.Equals("visual-studio-addin")
+ || type.Equals("sharp-develop-addin") || type.Equals("nar")) return "Library";
+ else if (type.Equals("exe")) return "Exe";
+ else if (type.Equals("winexe")) return "WinExe";
+ else if (type.Equals("module")) return "Module";
+ return null;
+ }
+
+ private String GetExtension(String type)
+ {
+ if (type.Equals("library") || type.Equals("netplugin") ) return "dll";
+ else if (type.Equals("exe")) return "exe";
+ else if (type.Equals("winexe")) return "exe";
+ else if (type.Equals("module")) return "netmodule";
+ return null;
+ }
+
+ 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;
+ }
+ }
+ }
+}
Propchange: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.Solution/ProjectGeneratorImpl.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.Solution/ProjectReferenceImpl.cs
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.VisualStudio.Addin/src/main/csharp/NMaven/VisualStudio/Addin/AddArtifactsForm.Designer.cs
URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.VisualStudio.Addin/src/main/csharp/NMaven/VisualStudio/Addin/AddArtifactsForm.Designer.cs?rev=672753&r1=672752&r2=672753&view=diff
==============================================================================
--- incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.VisualStudio.Addin/src/main/csharp/NMaven/VisualStudio/Addin/AddArtifactsForm.Designer.cs (original)
+++ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.VisualStudio.Addin/src/main/csharp/NMaven/VisualStudio/Addin/AddArtifactsForm.Designer.cs Mon Jun 30 05:54:00 2008
@@ -1,179 +1,179 @@
-#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
-
-namespace NMaven.VisualStudio.Addin
-{
- using System.Windows.Forms;
-
- partial class AddArtifactsForm
- {
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.IContainer components = null;
-
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
- #region Windows Form Designer generated code
-
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.addArtifact = new System.Windows.Forms.Button();
- this.button2 = new System.Windows.Forms.Button();
- this.remoteTabPage = new System.Windows.Forms.TabPage();
- this.treeView1 = new System.Windows.Forms.TreeView();
- this.localTabPage = new System.Windows.Forms.TabPage();
- this.localListView = new System.Windows.Forms.ListView();
- this.ArtifactNameHeader = new System.Windows.Forms.ColumnHeader();
- this.versionHeader = new System.Windows.Forms.ColumnHeader();
- this.artifactTabControl = new System.Windows.Forms.TabControl();
- this.remoteTabPage.SuspendLayout();
- this.localTabPage.SuspendLayout();
- this.artifactTabControl.SuspendLayout();
- this.SuspendLayout();
- //
- // addArtifact
- //
- this.addArtifact.Location = new System.Drawing.Point(447, 374);
- this.addArtifact.Name = "addArtifact";
- this.addArtifact.Size = new System.Drawing.Size(75, 23);
- this.addArtifact.TabIndex = 1;
- this.addArtifact.Text = "Add";
- this.addArtifact.UseVisualStyleBackColor = true;
- this.addArtifact.Click += new System.EventHandler(this.addArtifact_Click);
- //
- // button2
- //
- this.button2.Location = new System.Drawing.Point(546, 374);
- this.button2.Name = "button2";
- this.button2.Size = new System.Drawing.Size(75, 23);
- this.button2.TabIndex = 2;
- this.button2.Text = "Cancel";
- this.button2.UseVisualStyleBackColor = true;
- this.button2.Click += new System.EventHandler(this.button2_Click);
- //
- // remoteTabPage
- //
- this.remoteTabPage.Controls.Add(this.treeView1);
- this.remoteTabPage.Location = new System.Drawing.Point(4, 25);
- this.remoteTabPage.Name = "remoteTabPage";
- this.remoteTabPage.Padding = new System.Windows.Forms.Padding(3);
- this.remoteTabPage.Size = new System.Drawing.Size(628, 309);
- this.remoteTabPage.TabIndex = 1;
- this.remoteTabPage.Text = "Remote";
- this.remoteTabPage.UseVisualStyleBackColor = true;
- //
- // treeView1
- //
- this.treeView1.Location = new System.Drawing.Point(23, 18);
- this.treeView1.Name = "treeView1";
- this.treeView1.Size = new System.Drawing.Size(582, 272);
- this.treeView1.TabIndex = 0;
- //
- // localTabPage
- //
- this.localTabPage.Controls.Add(this.localListView);
- this.localTabPage.Location = new System.Drawing.Point(4, 25);
- this.localTabPage.Name = "localTabPage";
- this.localTabPage.Padding = new System.Windows.Forms.Padding(3);
- this.localTabPage.Size = new System.Drawing.Size(628, 309);
- this.localTabPage.TabIndex = 0;
- this.localTabPage.Text = "Local";
- this.localTabPage.UseVisualStyleBackColor = true;
- //
- // localListView
- //
- this.localListView.BackgroundImageTiled = true;
- this.localListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
- this.ArtifactNameHeader,
- this.versionHeader});
- this.localListView.Location = new System.Drawing.Point(22, 19);
- this.localListView.Name = "localListView";
- this.localListView.Size = new System.Drawing.Size(583, 270);
- this.localListView.Sorting = System.Windows.Forms.SortOrder.Ascending;
- this.localListView.TabIndex = 0;
- this.localListView.UseCompatibleStateImageBehavior = false;
- //
- // ArtifactNameHeader
- //
- this.ArtifactNameHeader.Text = "Artifact Name";
- this.ArtifactNameHeader.Width = 240;
- //
- // versionHeader
- //
- this.versionHeader.Text = "Version";
- this.versionHeader.Width = 120;
- //
- // artifactTabControl
- //
- this.artifactTabControl.Controls.Add(this.localTabPage);
- this.artifactTabControl.Controls.Add(this.remoteTabPage);
- this.artifactTabControl.Location = new System.Drawing.Point(12, 12);
- this.artifactTabControl.Name = "artifactTabControl";
- this.artifactTabControl.SelectedIndex = 0;
- this.artifactTabControl.Size = new System.Drawing.Size(636, 338);
- this.artifactTabControl.TabIndex = 0;
- //
- // AddArtifactsForm
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(677, 413);
- this.Controls.Add(this.button2);
- this.Controls.Add(this.addArtifact);
- this.Controls.Add(this.artifactTabControl);
- this.Name = "AddArtifactsForm";
- this.Text = "Add Maven Artifact";
- this.remoteTabPage.ResumeLayout(false);
- this.localTabPage.ResumeLayout(false);
- this.artifactTabControl.ResumeLayout(false);
- this.ResumeLayout(false);
-
- }
-
- #endregion
-
- private System.Windows.Forms.Button addArtifact;
- private System.Windows.Forms.Button button2;
- private System.Windows.Forms.TabPage remoteTabPage;
- private System.Windows.Forms.TreeView treeView1;
- private System.Windows.Forms.TabPage localTabPage;
- private System.Windows.Forms.ListView localListView;
- private System.Windows.Forms.ColumnHeader ArtifactNameHeader;
- private System.Windows.Forms.ColumnHeader versionHeader;
- private System.Windows.Forms.TabControl artifactTabControl;
- }
+#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
+
+namespace NMaven.VisualStudio.Addin
+{
+ using System.Windows.Forms;
+
+ partial class AddArtifactsForm
+ {
+ /// <summary>
+ /// Required designer variable.
+ /// </summary>
+ private System.ComponentModel.IContainer components = null;
+
+ /// <summary>
+ /// Clean up any resources being used.
+ /// </summary>
+ /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ /// <summary>
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ /// </summary>
+ private void InitializeComponent()
+ {
+ this.addArtifact = new System.Windows.Forms.Button();
+ this.button2 = new System.Windows.Forms.Button();
+ this.remoteTabPage = new System.Windows.Forms.TabPage();
+ this.treeView1 = new System.Windows.Forms.TreeView();
+ this.localTabPage = new System.Windows.Forms.TabPage();
+ this.localListView = new System.Windows.Forms.ListView();
+ this.ArtifactNameHeader = new System.Windows.Forms.ColumnHeader();
+ this.versionHeader = new System.Windows.Forms.ColumnHeader();
+ this.artifactTabControl = new System.Windows.Forms.TabControl();
+ this.remoteTabPage.SuspendLayout();
+ this.localTabPage.SuspendLayout();
+ this.artifactTabControl.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // addArtifact
+ //
+ this.addArtifact.Location = new System.Drawing.Point(447, 374);
+ this.addArtifact.Name = "addArtifact";
+ this.addArtifact.Size = new System.Drawing.Size(75, 23);
+ this.addArtifact.TabIndex = 1;
+ this.addArtifact.Text = "Add";
+ this.addArtifact.UseVisualStyleBackColor = true;
+ this.addArtifact.Click += new System.EventHandler(this.addArtifact_Click);
+ //
+ // button2
+ //
+ this.button2.Location = new System.Drawing.Point(546, 374);
+ this.button2.Name = "button2";
+ this.button2.Size = new System.Drawing.Size(75, 23);
+ this.button2.TabIndex = 2;
+ this.button2.Text = "Cancel";
+ this.button2.UseVisualStyleBackColor = true;
+ this.button2.Click += new System.EventHandler(this.button2_Click);
+ //
+ // remoteTabPage
+ //
+ this.remoteTabPage.Controls.Add(this.treeView1);
+ this.remoteTabPage.Location = new System.Drawing.Point(4, 25);
+ this.remoteTabPage.Name = "remoteTabPage";
+ this.remoteTabPage.Padding = new System.Windows.Forms.Padding(3);
+ this.remoteTabPage.Size = new System.Drawing.Size(628, 309);
+ this.remoteTabPage.TabIndex = 1;
+ this.remoteTabPage.Text = "Remote";
+ this.remoteTabPage.UseVisualStyleBackColor = true;
+ //
+ // treeView1
+ //
+ this.treeView1.Location = new System.Drawing.Point(23, 18);
+ this.treeView1.Name = "treeView1";
+ this.treeView1.Size = new System.Drawing.Size(582, 272);
+ this.treeView1.TabIndex = 0;
+ //
+ // localTabPage
+ //
+ this.localTabPage.Controls.Add(this.localListView);
+ this.localTabPage.Location = new System.Drawing.Point(4, 25);
+ this.localTabPage.Name = "localTabPage";
+ this.localTabPage.Padding = new System.Windows.Forms.Padding(3);
+ this.localTabPage.Size = new System.Drawing.Size(628, 309);
+ this.localTabPage.TabIndex = 0;
+ this.localTabPage.Text = "Local";
+ this.localTabPage.UseVisualStyleBackColor = true;
+ //
+ // localListView
+ //
+ this.localListView.BackgroundImageTiled = true;
+ this.localListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
+ this.ArtifactNameHeader,
+ this.versionHeader});
+ this.localListView.Location = new System.Drawing.Point(22, 19);
+ this.localListView.Name = "localListView";
+ this.localListView.Size = new System.Drawing.Size(583, 270);
+ this.localListView.Sorting = System.Windows.Forms.SortOrder.Ascending;
+ this.localListView.TabIndex = 0;
+ this.localListView.UseCompatibleStateImageBehavior = false;
+ //
+ // ArtifactNameHeader
+ //
+ this.ArtifactNameHeader.Text = "Artifact Name";
+ this.ArtifactNameHeader.Width = 240;
+ //
+ // versionHeader
+ //
+ this.versionHeader.Text = "Version";
+ this.versionHeader.Width = 120;
+ //
+ // artifactTabControl
+ //
+ this.artifactTabControl.Controls.Add(this.localTabPage);
+ this.artifactTabControl.Controls.Add(this.remoteTabPage);
+ this.artifactTabControl.Location = new System.Drawing.Point(12, 12);
+ this.artifactTabControl.Name = "artifactTabControl";
+ this.artifactTabControl.SelectedIndex = 0;
+ this.artifactTabControl.Size = new System.Drawing.Size(636, 338);
+ this.artifactTabControl.TabIndex = 0;
+ //
+ // AddArtifactsForm
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(677, 413);
+ this.Controls.Add(this.button2);
+ this.Controls.Add(this.addArtifact);
+ this.Controls.Add(this.artifactTabControl);
+ this.Name = "AddArtifactsForm";
+ this.Text = "Add Maven Artifact";
+ this.remoteTabPage.ResumeLayout(false);
+ this.localTabPage.ResumeLayout(false);
+ this.artifactTabControl.ResumeLayout(false);
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.Button addArtifact;
+ private System.Windows.Forms.Button button2;
+ private System.Windows.Forms.TabPage remoteTabPage;
+ private System.Windows.Forms.TreeView treeView1;
+ private System.Windows.Forms.TabPage localTabPage;
+ private System.Windows.Forms.ListView localListView;
+ private System.Windows.Forms.ColumnHeader ArtifactNameHeader;
+ private System.Windows.Forms.ColumnHeader versionHeader;
+ private System.Windows.Forms.TabControl artifactTabControl;
+ }
}
\ No newline at end of file
Propchange: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.VisualStudio.Addin/src/main/csharp/NMaven/VisualStudio/Addin/AddArtifactsForm.Designer.cs
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.VisualStudio.Addin/src/main/csharp/NMaven/VisualStudio/Addin/AddArtifactsForm.cs
URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.VisualStudio.Addin/src/main/csharp/NMaven/VisualStudio/Addin/AddArtifactsForm.cs?rev=672753&r1=672752&r2=672753&view=diff
==============================================================================
--- incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.VisualStudio.Addin/src/main/csharp/NMaven/VisualStudio/Addin/AddArtifactsForm.cs (original)
+++ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.VisualStudio.Addin/src/main/csharp/NMaven/VisualStudio/Addin/AddArtifactsForm.cs Mon Jun 30 05:54:00 2008
@@ -1,336 +1,336 @@
-#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 Extensibility;
-using EnvDTE;
-using EnvDTE80;
-
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Drawing;
-using System.IO;
-using System.Net;
-using System.Reflection;
-using System.Text;
-using System.Text.RegularExpressions;
-using System.Windows.Forms;
-using System.Xml;
-using System.Xml.Serialization;
-
-using VSLangProj;
-
-using NMaven.Artifact;
-using NMaven.Logging;
-using NMaven.Model.Pom;
-using NMaven.Model.Setting;
-using Castle.Windsor;
-
-namespace NMaven.VisualStudio.Addin
-{
- public partial class AddArtifactsForm : Form
- {
- private List<NMaven.Artifact.Artifact> localArtifacts = new List<NMaven.Artifact.Artifact>();
- private ArtifactContext artifactContext;
- private Project project;
- private NMaven.Logging.Logger logger;
-
- /// <summary>
- /// For Testing
- /// </summary>
- public AddArtifactsForm()
- {
- //InitializeForm();
- InitializeComponent();
- // localListView.View = View.Details;
- }
-
- public AddArtifactsForm(Project project, IWindsorContainer container, Logger logger)
- {
- this.project = project;
- this.logger = logger;
- InitializeForm();
- InitializeComponent();
- localListView.View = View.Details;
- artifactContext = (ArtifactContext) container[typeof(ArtifactContext)];
- }
-
- private void InitializeForm()
- {
- this.SuspendLayout();
- //
- // AddArtifactsForm
- //
- this.ClientSize = new System.Drawing.Size(292, 260);
- this.Name = "AddArtifactsForm";
- this.Load += new System.EventHandler(this.AddArtifactsForm_Load);
- this.ResumeLayout(false);
- }
-
- private void AddArtifactsForm_Load(object sender, EventArgs e)
- {
- localArtifacts = artifactContext.GetArtifactRepository().GetArtifacts();
- foreach (NMaven.Artifact.Artifact artifact in localArtifacts)
- {
- System.Windows.Forms.ListViewItem item = new System.Windows.Forms.ListViewItem(new string[] {
- artifact.ArtifactId, artifact.Version}, -1);
- item.Tag = artifact;
- localListView.Items.Add(item);
- }
-
- String settingsPath = SettingsUtil.GetUserSettingsPath();
- Settings settings = null;
- try
- {
- settings = SettingsUtil.ReadSettings(new FileInfo(settingsPath));
- }
- catch (Exception ex)
- {
- MessageBox.Show("Invalid Settings File: " + ex.Message + ex.StackTrace);
- return;
- }
-
- if (settings == null || settings.profiles == null)
- {
- MessageBox.Show("No Profile Found. Configure repository: ");
- return;
- }
-
- String url = null;
-
- foreach (NMaven.Model.Setting.Profile profile in settings.profiles)
- {
- foreach (NMaven.Model.Setting.Repository repository in profile.repositories)
- {
- if (repository.id.Equals("nmaven.id"))
- {
- url = repository.url;
- }
- }
- }
-
- if (url == null)
- {
- MessageBox.Show("Remote repository not set: Try 'Add Maven Repository' option from menu. Will" +
- " require restart of addin.");
- return;
- }
-
- SetUnsafeHttpHeaderParsing();
-
- List<TreeNode> treeNodes = GetNodesFor(url);
- treeView1.Nodes.AddRange(treeNodes.ToArray());
- treeView1.MouseClick += new System.Windows.Forms.MouseEventHandler(treeView_MouseUp);
- }
-
- private void addArtifact_Click(object sender, EventArgs e)
- {
- String pomFileName =
- (new FileInfo(project.FileName).Directory).FullName + @"\pom.xml";
- if (!new FileInfo(pomFileName).Exists)//No flat directory structure.
- {
- pomFileName = (new FileInfo(project.FileName).Directory.Parent.Parent.Parent).FullName
- + @"\pom.xml";
-
- if (!new FileInfo(pomFileName).Exists)
- {
- MessageBox.Show("Could not add reference. Missing pom file: File = " + pomFileName);
- return;
- }
- }
-
- XmlReader reader = XmlReader.Create(pomFileName);
- XmlSerializer serializer = new XmlSerializer(typeof(NMaven.Model.Pom.Model));
- if (!serializer.CanDeserialize(reader))
- {
- MessageBox.Show("Could not add reference. Corrupted pom file: File = " + pomFileName);
- return;
- }
-
- NMaven.Model.Pom.Model model = (NMaven.Model.Pom.Model)serializer.Deserialize(reader);
- List<Dependency> dependencies = new List<Dependency>();
- if (model.dependencies != null)
- {
- dependencies.AddRange(model.dependencies);
- }
-
- ListView.SelectedListViewItemCollection selectedItems = localListView.SelectedItems;
- if (selectedItems != null)
- {
- foreach (ListViewItem item in selectedItems)
- {
- NMaven.Artifact.Artifact artifact = (NMaven.Artifact.Artifact)item.Tag;
- Dependency dependency = new Dependency();
- dependency.artifactId = artifact.ArtifactId;
- dependency.groupId = artifact.GroupId;
- dependency.version = artifact.Version;
- dependency.type = "library";
- //dependency.scope = artifact.ArtifactScope;
-
- dependencies.Add(dependency);
- VSProject vsProject = (VSProject)project.Object;
- vsProject.References.Add(artifact.FileInfo.FullName);
- }
- }
-
- TreeNode treeNode = treeView1.SelectedNode;
- if (treeNode != null)
- {
- String uri = (String)treeNode.Tag;
- int length = uri.Length - uri.LastIndexOf("/maven2/") - 8;
- String paths = uri.Substring(uri.LastIndexOf("/maven2/") + 8, length);
- NMaven.Artifact.Artifact artifact1 =
- artifactContext.GetArtifactRepository().GetArtifactFor(paths);
- Dependency dependency1 = new Dependency();
- dependency1.artifactId = artifact1.ArtifactId;
- dependency1.groupId = artifact1.GroupId;
- dependency1.version = artifact1.Version;
- dependency1.type = "library";
- dependencies.Add(dependency1);
-
- //Download
- artifact1.FileInfo.Directory.Create();
- WebClient client = new WebClient();
- byte[] assembly = client.DownloadData(uri);
- FileStream stream = new FileStream(artifact1.FileInfo.FullName, FileMode.Create);
- stream.Write(assembly, 0, assembly.Length);
- stream.Close();
-
- VSProject vsProject1 = (VSProject)project.Object;
- //File must exist
- vsProject1.References.Add(artifact1.FileInfo.FullName);
- }
- reader.Close();
-
- model.dependencies = dependencies.ToArray();
- TextWriter writer = new StreamWriter(pomFileName);
- serializer.Serialize(writer, model);
- writer.Close();
- this.Close();
- }
-
- private Boolean IsIncluded(String name, String uri)
- {
- if (name.StartsWith(".") || name.Equals("Parent Directory") || name.Equals("Terms of Use"))
- {
- return false;
- }
-
- if (uri.Contains("."))
- {
- String[] tokens = name.Split(".".ToCharArray());
- String extension = tokens[tokens.Length -1];
- if (extension.Equals("txt") || extension.Equals("pom") ||
- extension.Equals("md5") || extension.Equals("sha1") ||
- extension.Equals("xml") || extension.Equals("tar") ||
- extension.Equals("gz") || extension.Equals("rb") ||
- extension.Equals("htm") || extension.Equals("html") ||
- extension.Equals("jsp"))
- {
- return false;
- }
- }
- if (uri.ToLower().StartsWith("http") || uri.ToLower().StartsWith("mailto"))
- {
- return false;
- }
- return true;
- }
-
- private Boolean IsDirectory(String name)
- {
- if (name.Contains("."))
- {
- String[] tokens = name.Split(".".ToCharArray());
- String extension = tokens[tokens.Length - 1];
-
- if (extension.Equals("dll") || extension.Equals("jar") ||
- extension.Equals("exe"))
- {
- return false;
- }
- }
- return true;
- }
-
- private List<TreeNode> GetNodesFor(String url)
- {
- List<TreeNode> treeNodes = new List<TreeNode>();
-
- WebClient webClient = new WebClient();
- byte[] page = webClient.DownloadData(url);
- String pattern =
- (@"<a[^>]*href\s*=\s*[\""\']?(?<URI>[^""'>\s]*)[\""\']?[^>]*>(?<Name>[^<]+|.*?)?</a\s*>");
- MatchCollection matches = Regex.Matches(Encoding.ASCII.GetString(page), pattern, RegexOptions.IgnoreCase);
-
- // treeView1.ImageList = imageList1;
- foreach (Match match in matches)
- {
- String name = match.Groups["Name"].Value;
- String uri = match.Groups["URI"].Value;
- if (IsIncluded(name, uri))
- {
- TreeNode node = new TreeNode(name);
- if (!IsDirectory(name))
- {
- node.ImageIndex = 1;
- }
-
- node.Tag = url + "/" + uri.TrimEnd("/".ToCharArray());
- treeNodes.Add(node);
- }
- }
- return treeNodes;
- }
-
- private void treeView_MouseUp(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left)
- {
- Point point = new Point(e.X, e.Y);
- TreeNode node = treeView1.GetNodeAt(point);
- List<TreeNode> treeNodes = GetNodesFor( (String) node.Tag);
- node.Nodes.Clear();
- node.Nodes.AddRange(treeNodes.ToArray());
- }
- }
-
- private void button2_Click(object sender, EventArgs e)
- {
- this.Close();
- }
-
- public static void SetUnsafeHttpHeaderParsing()
- {
- Assembly assembly = Assembly.GetAssembly(typeof(System.Net.Configuration.SettingsSection));
- Type settingsSectionType = assembly.GetType("System.Net.Configuration.SettingsSectionInternal");
-
- object settingsSection = settingsSectionType.InvokeMember("Section",
- BindingFlags.Static | BindingFlags.GetProperty | BindingFlags.NonPublic,
- null, null, new object[] { });
-
- FieldInfo fieldInfo = settingsSectionType.GetField("useUnsafeHeaderParsing",
- BindingFlags.NonPublic | BindingFlags.Instance);
- fieldInfo.SetValue(settingsSection, true);
- }
-
- }
+#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 Extensibility;
+using EnvDTE;
+using EnvDTE80;
+
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Drawing;
+using System.IO;
+using System.Net;
+using System.Reflection;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Windows.Forms;
+using System.Xml;
+using System.Xml.Serialization;
+
+using VSLangProj;
+
+using NMaven.Artifact;
+using NMaven.Logging;
+using NMaven.Model.Pom;
+using NMaven.Model.Setting;
+using Castle.Windsor;
+
+namespace NMaven.VisualStudio.Addin
+{
+ public partial class AddArtifactsForm : Form
+ {
+ private List<NMaven.Artifact.Artifact> localArtifacts = new List<NMaven.Artifact.Artifact>();
+ private ArtifactContext artifactContext;
+ private Project project;
+ private NMaven.Logging.Logger logger;
+
+ /// <summary>
+ /// For Testing
+ /// </summary>
+ public AddArtifactsForm()
+ {
+ //InitializeForm();
+ InitializeComponent();
+ // localListView.View = View.Details;
+ }
+
+ public AddArtifactsForm(Project project, IWindsorContainer container, Logger logger)
+ {
+ this.project = project;
+ this.logger = logger;
+ InitializeForm();
+ InitializeComponent();
+ localListView.View = View.Details;
+ artifactContext = (ArtifactContext) container[typeof(ArtifactContext)];
+ }
+
+ private void InitializeForm()
+ {
+ this.SuspendLayout();
+ //
+ // AddArtifactsForm
+ //
+ this.ClientSize = new System.Drawing.Size(292, 260);
+ this.Name = "AddArtifactsForm";
+ this.Load += new System.EventHandler(this.AddArtifactsForm_Load);
+ this.ResumeLayout(false);
+ }
+
+ private void AddArtifactsForm_Load(object sender, EventArgs e)
+ {
+ localArtifacts = artifactContext.GetArtifactRepository().GetArtifacts();
+ foreach (NMaven.Artifact.Artifact artifact in localArtifacts)
+ {
+ System.Windows.Forms.ListViewItem item = new System.Windows.Forms.ListViewItem(new string[] {
+ artifact.ArtifactId, artifact.Version}, -1);
+ item.Tag = artifact;
+ localListView.Items.Add(item);
+ }
+
+ String settingsPath = SettingsUtil.GetUserSettingsPath();
+ Settings settings = null;
+ try
+ {
+ settings = SettingsUtil.ReadSettings(new FileInfo(settingsPath));
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("Invalid Settings File: " + ex.Message + ex.StackTrace);
+ return;
+ }
+
+ if (settings == null || settings.profiles == null)
+ {
+ MessageBox.Show("No Profile Found. Configure repository: ");
+ return;
+ }
+
+ String url = null;
+
+ foreach (NMaven.Model.Setting.Profile profile in settings.profiles)
+ {
+ foreach (NMaven.Model.Setting.Repository repository in profile.repositories)
+ {
+ if (repository.id.Equals("nmaven.id"))
+ {
+ url = repository.url;
+ }
+ }
+ }
+
+ if (url == null)
+ {
+ MessageBox.Show("Remote repository not set: Try 'Add Maven Repository' option from menu. Will" +
+ " require restart of addin.");
+ return;
+ }
+
+ SetUnsafeHttpHeaderParsing();
+
+ List<TreeNode> treeNodes = GetNodesFor(url);
+ treeView1.Nodes.AddRange(treeNodes.ToArray());
+ treeView1.MouseClick += new System.Windows.Forms.MouseEventHandler(treeView_MouseUp);
+ }
+
+ private void addArtifact_Click(object sender, EventArgs e)
+ {
+ String pomFileName =
+ (new FileInfo(project.FileName).Directory).FullName + @"\pom.xml";
+ if (!new FileInfo(pomFileName).Exists)//No flat directory structure.
+ {
+ pomFileName = (new FileInfo(project.FileName).Directory.Parent.Parent.Parent).FullName
+ + @"\pom.xml";
+
+ if (!new FileInfo(pomFileName).Exists)
+ {
+ MessageBox.Show("Could not add reference. Missing pom file: File = " + pomFileName);
+ return;
+ }
+ }
+
+ XmlReader reader = XmlReader.Create(pomFileName);
+ XmlSerializer serializer = new XmlSerializer(typeof(NMaven.Model.Pom.Model));
+ if (!serializer.CanDeserialize(reader))
+ {
+ MessageBox.Show("Could not add reference. Corrupted pom file: File = " + pomFileName);
+ return;
+ }
+
+ NMaven.Model.Pom.Model model = (NMaven.Model.Pom.Model)serializer.Deserialize(reader);
+ List<Dependency> dependencies = new List<Dependency>();
+ if (model.dependencies != null)
+ {
+ dependencies.AddRange(model.dependencies);
+ }
+
+ ListView.SelectedListViewItemCollection selectedItems = localListView.SelectedItems;
+ if (selectedItems != null)
+ {
+ foreach (ListViewItem item in selectedItems)
+ {
+ NMaven.Artifact.Artifact artifact = (NMaven.Artifact.Artifact)item.Tag;
+ Dependency dependency = new Dependency();
+ dependency.artifactId = artifact.ArtifactId;
+ dependency.groupId = artifact.GroupId;
+ dependency.version = artifact.Version;
+ dependency.type = "library";
+ //dependency.scope = artifact.ArtifactScope;
+
+ dependencies.Add(dependency);
+ VSProject vsProject = (VSProject)project.Object;
+ vsProject.References.Add(artifact.FileInfo.FullName);
+ }
+ }
+
+ TreeNode treeNode = treeView1.SelectedNode;
+ if (treeNode != null)
+ {
+ String uri = (String)treeNode.Tag;
+ int length = uri.Length - uri.LastIndexOf("/maven2/") - 8;
+ String paths = uri.Substring(uri.LastIndexOf("/maven2/") + 8, length);
+ NMaven.Artifact.Artifact artifact1 =
+ artifactContext.GetArtifactRepository().GetArtifactFor(paths);
+ Dependency dependency1 = new Dependency();
+ dependency1.artifactId = artifact1.ArtifactId;
+ dependency1.groupId = artifact1.GroupId;
+ dependency1.version = artifact1.Version;
+ dependency1.type = "library";
+ dependencies.Add(dependency1);
+
+ //Download
+ artifact1.FileInfo.Directory.Create();
+ WebClient client = new WebClient();
+ byte[] assembly = client.DownloadData(uri);
+ FileStream stream = new FileStream(artifact1.FileInfo.FullName, FileMode.Create);
+ stream.Write(assembly, 0, assembly.Length);
+ stream.Close();
+
+ VSProject vsProject1 = (VSProject)project.Object;
+ //File must exist
+ vsProject1.References.Add(artifact1.FileInfo.FullName);
+ }
+ reader.Close();
+
+ model.dependencies = dependencies.ToArray();
+ TextWriter writer = new StreamWriter(pomFileName);
+ serializer.Serialize(writer, model);
+ writer.Close();
+ this.Close();
+ }
+
+ private Boolean IsIncluded(String name, String uri)
+ {
+ if (name.StartsWith(".") || name.Equals("Parent Directory") || name.Equals("Terms of Use"))
+ {
+ return false;
+ }
+
+ if (uri.Contains("."))
+ {
+ String[] tokens = name.Split(".".ToCharArray());
+ String extension = tokens[tokens.Length -1];
+ if (extension.Equals("txt") || extension.Equals("pom") ||
+ extension.Equals("md5") || extension.Equals("sha1") ||
+ extension.Equals("xml") || extension.Equals("tar") ||
+ extension.Equals("gz") || extension.Equals("rb") ||
+ extension.Equals("htm") || extension.Equals("html") ||
+ extension.Equals("jsp"))
+ {
+ return false;
+ }
+ }
+ if (uri.ToLower().StartsWith("http") || uri.ToLower().StartsWith("mailto"))
+ {
+ return false;
+ }
+ return true;
+ }
+
+ private Boolean IsDirectory(String name)
+ {
+ if (name.Contains("."))
+ {
+ String[] tokens = name.Split(".".ToCharArray());
+ String extension = tokens[tokens.Length - 1];
+
+ if (extension.Equals("dll") || extension.Equals("jar") ||
+ extension.Equals("exe"))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private List<TreeNode> GetNodesFor(String url)
+ {
+ List<TreeNode> treeNodes = new List<TreeNode>();
+
+ WebClient webClient = new WebClient();
+ byte[] page = webClient.DownloadData(url);
+ String pattern =
+ (@"<a[^>]*href\s*=\s*[\""\']?(?<URI>[^""'>\s]*)[\""\']?[^>]*>(?<Name>[^<]+|.*?)?</a\s*>");
+ MatchCollection matches = Regex.Matches(Encoding.ASCII.GetString(page), pattern, RegexOptions.IgnoreCase);
+
+ // treeView1.ImageList = imageList1;
+ foreach (Match match in matches)
+ {
+ String name = match.Groups["Name"].Value;
+ String uri = match.Groups["URI"].Value;
+ if (IsIncluded(name, uri))
+ {
+ TreeNode node = new TreeNode(name);
+ if (!IsDirectory(name))
+ {
+ node.ImageIndex = 1;
+ }
+
+ node.Tag = url + "/" + uri.TrimEnd("/".ToCharArray());
+ treeNodes.Add(node);
+ }
+ }
+ return treeNodes;
+ }
+
+ private void treeView_MouseUp(object sender, MouseEventArgs e)
+ {
+ if (e.Button == MouseButtons.Left)
+ {
+ Point point = new Point(e.X, e.Y);
+ TreeNode node = treeView1.GetNodeAt(point);
+ List<TreeNode> treeNodes = GetNodesFor( (String) node.Tag);
+ node.Nodes.Clear();
+ node.Nodes.AddRange(treeNodes.ToArray());
+ }
+ }
+
+ private void button2_Click(object sender, EventArgs e)
+ {
+ this.Close();
+ }
+
+ public static void SetUnsafeHttpHeaderParsing()
+ {
+ Assembly assembly = Assembly.GetAssembly(typeof(System.Net.Configuration.SettingsSection));
+ Type settingsSectionType = assembly.GetType("System.Net.Configuration.SettingsSectionInternal");
+
+ object settingsSection = settingsSectionType.InvokeMember("Section",
+ BindingFlags.Static | BindingFlags.GetProperty | BindingFlags.NonPublic,
+ null, null, new object[] { });
+
+ FieldInfo fieldInfo = settingsSectionType.GetField("useUnsafeHeaderParsing",
+ BindingFlags.NonPublic | BindingFlags.Instance);
+ fieldInfo.SetValue(settingsSection, true);
+ }
+
+ }
}
\ No newline at end of file
Propchange: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.VisualStudio.Addin/src/main/csharp/NMaven/VisualStudio/Addin/AddArtifactsForm.cs
------------------------------------------------------------------------------
svn:eol-style = native