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 si...@apache.org on 2007/06/20 22:52:00 UTC
svn commit: r549286 - in /incubator/nmaven/trunk/assemblies: ./ NMaven.Core/
NMaven.Solution/
Author: sisbell
Date: Wed Jun 20 15:51:58 2007
New Revision: 549286
URL: http://svn.apache.org/viewvc?view=rev&rev=549286
Log:
Moved the packages from Core to Solution. I need the core package for the IoC configurations, not solution generation. Also involves cleanup of the code.
Added:
incubator/nmaven/trunk/assemblies/NMaven.Solution/
incubator/nmaven/trunk/assemblies/NMaven.Solution/ExecutionException.cs
incubator/nmaven/trunk/assemblies/NMaven.Solution/Factory.cs
incubator/nmaven/trunk/assemblies/NMaven.Solution/IProjectGenerator.cs
incubator/nmaven/trunk/assemblies/NMaven.Solution/IProjectReference.cs
incubator/nmaven/trunk/assemblies/NMaven.Solution/NMaven.Solution.csproj
incubator/nmaven/trunk/assemblies/NMaven.Solution/NMaven.Solution.sln
incubator/nmaven/trunk/assemblies/NMaven.Solution/NMaven.Solution.suo (with props)
incubator/nmaven/trunk/assemblies/NMaven.Solution/ProjectGeneratorImpl.cs
incubator/nmaven/trunk/assemblies/NMaven.Solution/ProjectReferenceImpl.cs
incubator/nmaven/trunk/assemblies/NMaven.Solution/pom.xml (with props)
Removed:
incubator/nmaven/trunk/assemblies/NMaven.Core/
Modified:
incubator/nmaven/trunk/assemblies/pom.xml
Added: incubator/nmaven/trunk/assemblies/NMaven.Solution/ExecutionException.cs
URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/assemblies/NMaven.Solution/ExecutionException.cs?view=auto&rev=549286
==============================================================================
--- incubator/nmaven/trunk/assemblies/NMaven.Solution/ExecutionException.cs (added)
+++ incubator/nmaven/trunk/assemblies/NMaven.Solution/ExecutionException.cs Wed Jun 20 15:51:58 2007
@@ -0,0 +1,36 @@
+//
+// 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.
+//
+
+using System;
+using System.Runtime.Serialization;
+
+namespace NMaven.Solution
+{
+ [Serializable]
+ public class ExecutionException : Exception
+ {
+ public ExecutionException() : base(){ }
+
+ public ExecutionException(String message) : base(message) { }
+
+ public ExecutionException(String message, Exception exception) : base(message, exception) { }
+
+ public ExecutionException(SerializationInfo info, StreamingContext context) : base(info, context) { }
+ }
+}
Added: incubator/nmaven/trunk/assemblies/NMaven.Solution/Factory.cs
URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/assemblies/NMaven.Solution/Factory.cs?view=auto&rev=549286
==============================================================================
--- incubator/nmaven/trunk/assemblies/NMaven.Solution/Factory.cs (added)
+++ incubator/nmaven/trunk/assemblies/NMaven.Solution/Factory.cs Wed Jun 20 15:51:58 2007
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using NMaven.Solution.Impl;
+[assembly: CLSCompliantAttribute(true)]
+namespace NMaven.Solution
+{
+ [CLSCompliantAttribute(false)]
+ public sealed class Factory
+ {
+
+ private Factory() { }
+
+ public static IProjectReference createDefaultProjectReference()
+ {
+ return new ProjectReferenceImpl();
+ }
+
+ public static IProjectGenerator createDefaultProjectGenerator()
+ {
+ return new ProjectGeneratorImpl();
+ }
+ }
+}
Added: incubator/nmaven/trunk/assemblies/NMaven.Solution/IProjectGenerator.cs
URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/assemblies/NMaven.Solution/IProjectGenerator.cs?view=auto&rev=549286
==============================================================================
--- incubator/nmaven/trunk/assemblies/NMaven.Solution/IProjectGenerator.cs (added)
+++ incubator/nmaven/trunk/assemblies/NMaven.Solution/IProjectGenerator.cs Wed Jun 20 15:51:58 2007
@@ -0,0 +1,66 @@
+//
+// 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.
+//
+
+using System;
+using System.IO;
+using System.Collections.Generic;
+
+using NMaven.Model;
+
+namespace NMaven.Solution
+{
+ /// <summary>
+ /// Provides services for generating .NET project and solution files.
+ /// </summary>
+ [CLSCompliantAttribute(false)]
+ public interface IProjectGenerator
+ {
+
+ /// <summary>
+ /// Generates a .csproj file from the specified maven model.
+ /// </summary>
+ /// <param name="model">the pom model</param>
+ /// <param name="sourceFileDirectory">the directory containing the source files </param>
+ /// <param name="projectFileName">the name of the project: usually corresponds to the artifact id</param>
+ /// <param name="projectReferences">references to other projects that this project is dependent upon</param>
+ /// <returns></returns>
+ [CLSCompliantAttribute(false)]
+ IProjectReference GenerateProjectFor(NMaven.Model.Model model,
+ DirectoryInfo sourceFileDirectory,
+ string projectFileName,
+ ICollection<IProjectReference> projectReferences);
+
+ /// <summary>
+ /// Generates a solution file that references the specified projects.
+ /// </summary>
+ /// <param name="fileInfo">the solution file</param>
+ /// <param name="projectReferences">csproj references</param>
+ void GenerateSolutionFor(FileInfo fileInfo, ICollection<IProjectReference> projectReferences);
+
+ /// <summary>
+ /// Creates a model from the pom.
+ /// </summary>
+ /// <param name="fileName">file name of the pom.xml file</param>
+ /// <returns>a model binding of the pom file</returns>
+ ///
+ [CLSCompliantAttribute(false)]
+ NMaven.Model.Model CreatePomModelFor(string fileName);
+
+ }
+}
Added: incubator/nmaven/trunk/assemblies/NMaven.Solution/IProjectReference.cs
URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/assemblies/NMaven.Solution/IProjectReference.cs?view=auto&rev=549286
==============================================================================
--- incubator/nmaven/trunk/assemblies/NMaven.Solution/IProjectReference.cs (added)
+++ incubator/nmaven/trunk/assemblies/NMaven.Solution/IProjectReference.cs Wed Jun 20 15:51:58 2007
@@ -0,0 +1,49 @@
+//
+// 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.
+//
+
+using System;
+using System.IO;
+
+namespace NMaven.Solution
+{
+ /// <summary>
+ /// Provides services for obtaining information about a project (.csproj) reference
+ /// </summary>
+ public interface IProjectReference
+ {
+
+ FileInfo CSProjectFile
+ {
+ get;
+ set;
+ }
+
+ string ProjectName
+ {
+ get;
+ set;
+ }
+
+ Guid ProjectGuid
+ {
+ get;
+ set;
+ }
+ }
+}
Added: incubator/nmaven/trunk/assemblies/NMaven.Solution/NMaven.Solution.csproj
URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/assemblies/NMaven.Solution/NMaven.Solution.csproj?view=auto&rev=549286
==============================================================================
--- incubator/nmaven/trunk/assemblies/NMaven.Solution/NMaven.Solution.csproj (added)
+++ incubator/nmaven/trunk/assemblies/NMaven.Solution/NMaven.Solution.csproj Wed Jun 20 15:51:58 2007
@@ -0,0 +1,60 @@
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.50727</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{CC57AA41-F466-4FF4-B4D9-DC9CC646C4EA}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>NMaven.Solution</RootNamespace>
+ <AssemblyName>NMaven.Solution</AssemblyName>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>target\bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>target\bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="Microsoft.Build.Engine" />
+ <Reference Include="Microsoft.Build.Framework" />
+ <Reference Include="NMaven.Model.Pom, Version=0.14.0.0, Culture=neutral, PublicKeyToken=4b435f4d76e2f0e6, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\..\..\.m2\repository\NMaven\Model\NMaven.Model.Pom\0.14-SNAPSHOT\NMaven.Model.Pom.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Content Include="pom.xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="ExecutionException.cs" />
+ <Compile Include="Factory.cs" />
+ <Compile Include="IProjectGenerator.cs" />
+ <Compile Include="IProjectReference.cs" />
+ <Compile Include="ProjectGeneratorImpl.cs" />
+ <Compile Include="ProjectReferenceImpl.cs" />
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
\ No newline at end of file
Added: incubator/nmaven/trunk/assemblies/NMaven.Solution/NMaven.Solution.sln
URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/assemblies/NMaven.Solution/NMaven.Solution.sln?view=auto&rev=549286
==============================================================================
--- incubator/nmaven/trunk/assemblies/NMaven.Solution/NMaven.Solution.sln (added)
+++ incubator/nmaven/trunk/assemblies/NMaven.Solution/NMaven.Solution.sln Wed Jun 20 15:51:58 2007
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 9.00
+# Visual Studio 2005
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NMaven.Solution", "NMaven.Solution.csproj", "{CC57AA41-F466-4FF4-B4D9-DC9CC646C4EA}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {CC57AA41-F466-4FF4-B4D9-DC9CC646C4EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {CC57AA41-F466-4FF4-B4D9-DC9CC646C4EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {CC57AA41-F466-4FF4-B4D9-DC9CC646C4EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {CC57AA41-F466-4FF4-B4D9-DC9CC646C4EA}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
Added: incubator/nmaven/trunk/assemblies/NMaven.Solution/NMaven.Solution.suo
URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/assemblies/NMaven.Solution/NMaven.Solution.suo?view=auto&rev=549286
==============================================================================
Binary file - no diff available.
Propchange: incubator/nmaven/trunk/assemblies/NMaven.Solution/NMaven.Solution.suo
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/nmaven/trunk/assemblies/NMaven.Solution/ProjectGeneratorImpl.cs
URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/assemblies/NMaven.Solution/ProjectGeneratorImpl.cs?view=auto&rev=549286
==============================================================================
--- incubator/nmaven/trunk/assemblies/NMaven.Solution/ProjectGeneratorImpl.cs (added)
+++ incubator/nmaven/trunk/assemblies/NMaven.Solution/ProjectGeneratorImpl.cs Wed Jun 20 15:51:58 2007
@@ -0,0 +1,362 @@
+//
+// 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.
+//
+
+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.Solution;
+using NMaven.Model;
+
+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.Model model,
+ DirectoryInfo sourceFileDirectory,
+ String projectFileName,
+ ICollection<IProjectReference> projectReferences)
+ {
+ Guid projectGuid = Guid.NewGuid();
+
+ if (projectReferences == null)
+ {
+ projectReferences = new List<IProjectReference>();
+ }
+
+ Project project = GetProjectFromPomModel(model,
+ sourceFileDirectory,
+ projectFileName,
+ projectGuid,
+ @"..\..\..\target\bin\Debug\",
+ @"..\..\..\target\obj\",
+ projectReferences);
+ 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.Model CreatePomModelFor(String fileName)
+ {
+ TextReader reader = new StreamReader(fileName);
+ XmlSerializer serializer = new XmlSerializer(typeof(NMaven.Model.Model));
+ return (NMaven.Model.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.Model model,
+ DirectoryInfo sourceFileDirectory,
+ String assemblyName,
+ Guid projectGuid,
+ String assemblyOutputPath,
+ String baseIntermediateOutputPath,
+ ICollection<IProjectReference> projectReferences)
+ {
+ 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);
+ 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.Model model, DirectoryInfo sourceFileDirectory)
+ {
+ BuildItemGroup group = project.AddNewItemGroup();
+ group.AddNewItem("Reference", "System.Xml");
+ if(model.dependencies != null)
+ {
+ foreach(Dependency dependency in model.dependencies) {
+ String artifactExtension = (dependency.type == "module") ? "dll" : GetExtension(dependency.type);
+ String repoPath = Environment.GetEnvironmentVariable("SystemDrive")
+ + Environment.GetEnvironmentVariable("HOMEPATH")
+ + @"\.m2\repository\" + dependency.groupId.Replace(".", "\\")
+ + "\\" + dependency.artifactId + "\\" + dependency.version + "\\" + dependency.artifactId + "."
+ + artifactExtension;
+ 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")) 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;
+ }
+ }
+ }
+}
Added: incubator/nmaven/trunk/assemblies/NMaven.Solution/ProjectReferenceImpl.cs
URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/assemblies/NMaven.Solution/ProjectReferenceImpl.cs?view=auto&rev=549286
==============================================================================
--- incubator/nmaven/trunk/assemblies/NMaven.Solution/ProjectReferenceImpl.cs (added)
+++ incubator/nmaven/trunk/assemblies/NMaven.Solution/ProjectReferenceImpl.cs Wed Jun 20 15:51:58 2007
@@ -0,0 +1,80 @@
+//
+// 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.
+//
+
+using System;
+using System.IO;
+
+namespace NMaven.Solution.Impl
+{
+ /// <summary>
+ /// Description of ProjectReferenceImpl.
+ /// </summary>
+ internal sealed class ProjectReferenceImpl : IProjectReference
+ {
+
+ private FileInfo csProjFile;
+
+ private string projectName;
+
+ private Guid projectGuid;
+
+ internal ProjectReferenceImpl()
+ {
+ }
+
+ public FileInfo CSProjectFile
+ {
+ get
+ {
+ return csProjFile;
+ }
+
+ set
+ {
+ csProjFile = value;
+ }
+ }
+
+ public string ProjectName
+ {
+ get
+ {
+ return projectName;
+ }
+
+ set
+ {
+ projectName = value;
+ }
+ }
+
+ public Guid ProjectGuid
+ {
+ get
+ {
+ return projectGuid;
+ }
+
+ set
+ {
+ projectGuid = value;
+ }
+ }
+ }
+}
Added: incubator/nmaven/trunk/assemblies/NMaven.Solution/pom.xml
URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/assemblies/NMaven.Solution/pom.xml?view=auto&rev=549286
==============================================================================
--- incubator/nmaven/trunk/assemblies/NMaven.Solution/pom.xml (added)
+++ incubator/nmaven/trunk/assemblies/NMaven.Solution/pom.xml Wed Jun 20 15:51:58 2007
@@ -0,0 +1,46 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0">
+ <parent>
+ <groupId>NMaven</groupId>
+ <version>0.14-SNAPSHOT</version>
+ <artifactId>NMaven.Assemblies</artifactId>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>NMaven</groupId>
+ <artifactId>NMaven.Solution</artifactId>
+ <version>0.14-SNAPSHOT</version>
+ <packaging>library</packaging>
+ <name>NMaven.Solution</name>
+ <dependencies>
+ <dependency>
+ <groupId>NMaven.Model</groupId>
+ <artifactId>NMaven.Model.Pom</artifactId>
+ <type>library</type>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>Microsoft.Build.Engine</groupId>
+ <artifactId>Microsoft.Build.Engine</artifactId>
+ <type>gac_msil</type>
+ </dependency>
+ <dependency>
+ <groupId>NUnit</groupId>
+ <artifactId>NUnit.Framework</artifactId>
+ <type>library</type>
+ </dependency>
+ </dependencies>
+ <build>
+ <sourceDirectory>.</sourceDirectory>
+ <testSourceDirectory>Test</testSourceDirectory>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.dotnet.plugins</groupId>
+ <artifactId>maven-compile-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <vendor>MICROSOFT</vendor>
+ <frameworkVersion>2.0.50727</frameworkVersion>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
Propchange: incubator/nmaven/trunk/assemblies/NMaven.Solution/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/nmaven/trunk/assemblies/pom.xml
URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/assemblies/pom.xml?view=diff&rev=549286&r1=549285&r2=549286
==============================================================================
--- incubator/nmaven/trunk/assemblies/pom.xml (original)
+++ incubator/nmaven/trunk/assemblies/pom.xml Wed Jun 20 15:51:58 2007
@@ -35,7 +35,7 @@
</description>
<modules>
<module>NMaven.Artifact</module>
- <module>NMaven.Core</module>
+ <module>NMaven.Solution</module>
<module>NMaven.Logging</module>
<module>NMaven.Model/Pom</module>
<module>NMaven.Model/AutomationExtensibility</module>