From nmaven-commits-return-831-apmail-incubator-nmaven-commits-archive=incubator.apache.org@incubator.apache.org Thu Jul 03 08:27:33 2008 Return-Path: Delivered-To: apmail-incubator-nmaven-commits-archive@locus.apache.org Received: (qmail 9144 invoked from network); 3 Jul 2008 08:27:33 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Jul 2008 08:27:33 -0000 Received: (qmail 910 invoked by uid 500); 3 Jul 2008 08:27:34 -0000 Delivered-To: apmail-incubator-nmaven-commits-archive@incubator.apache.org Received: (qmail 871 invoked by uid 500); 3 Jul 2008 08:27:34 -0000 Mailing-List: contact nmaven-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: nmaven-dev@incubator.apache.org Delivered-To: mailing list nmaven-commits@incubator.apache.org Received: (qmail 862 invoked by uid 99); 3 Jul 2008 08:27:34 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Jul 2008 01:27:34 -0700 X-ASF-Spam-Status: No, hits=-1997.2 required=10.0 tests=ALL_TRUSTED,WEIRD_QUOTING X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Jul 2008 08:26:43 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id D85A52388A23; Thu, 3 Jul 2008 01:27:03 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r673616 [1/2] - in /incubator/nmaven/branches/NMAVEN_0.14/assemblies: ./ NMaven.ProjectImporter/ NMaven.ProjectImporter/Console/ NMaven.ProjectImporter/Console/src/ NMaven.ProjectImporter/Console/src/main/ NMaven.ProjectImporter/Console/src... Date: Thu, 03 Jul 2008 08:27:02 -0000 To: nmaven-commits@incubator.apache.org From: brett@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080703082703.D85A52388A23@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: brett Date: Thu Jul 3 01:27:01 2008 New Revision: 673616 URL: http://svn.apache.org/viewvc?rev=673616&view=rev Log: [NMAVEN-119] Ability to generate pom.xml file from an existing Visual Studio solution file Submitted by: Jan Ancajas Added: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Console/ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Console/pom.xml incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Console/src/ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Console/src/main/ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Console/src/main/csharp/ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Console/src/main/csharp/NMaven/ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Console/src/main/csharp/NMaven/ProjectImporter/ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Console/src/main/csharp/NMaven/ProjectImporter/NMavenImportRunner.cs incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/pom.xml incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Generator/ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Generator/BasePomGenerator.cs incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Generator/ProjectPomGenerator.cs incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Generator/SolutionPomGenerator.cs incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Model/ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Model/DefaultDOMElement.cs incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Model/DefaultDOMElements.cs incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Model/Project.cs incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Model/Solution.cs incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/NMavenImporter.cs incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Parser/ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Parser/DefaultDOMParser.cs incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Parser/DefaultSolutionParser.cs incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Parser/ProjectTransformer.cs incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/util/ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/util/Constants.cs incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/util/Utility.cs incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/pom.xml incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.VisualStudio.Addin/src/main/csharp/NMaven/VisualStudio/Addin/NMavenImportProjectForm.Designer.cs incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.VisualStudio.Addin/src/main/csharp/NMaven/VisualStudio/Addin/NMavenImportProjectForm.cs incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.VisualStudio.Addin/src/main/csharp/NMaven/VisualStudio/Addin/NMavenImportProjectForm.resx Modified: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.VisualStudio.Addin/pom.xml incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.VisualStudio.Addin/src/main/csharp/NMaven/VisualStudio/Addin/Connect.cs incubator/nmaven/branches/NMAVEN_0.14/assemblies/pom.xml Added: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Console/pom.xml URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Console/pom.xml?rev=673616&view=auto ============================================================================== --- incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Console/pom.xml (added) +++ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Console/pom.xml Thu Jul 3 01:27:01 2008 @@ -0,0 +1,73 @@ + + + + + + NMaven.ProjectImporter + 0.14-incubating-SNAPSHOT + NMaven.ImporterProjectParent + + 4.0.0 + NMaven.ProjectImporter + NMaven.ProjectImporterConsole + 0.14-incubating-SNAPSHOT + exe + NMaven.ProjectImporterConsole + + + + org.apache.maven.wagon + wagon-webdav + 1.0-beta-2 + + + src/main/csharp + src/test/csharp + + + org.apache.maven.dotnet.plugins + maven-compile-plugin + true + + + maven-assembly-plugin + + + src + + + + + + + + NMaven.ProjectImporter + NMaven.ProjectImporterEngine + 0.14-incubating-SNAPSHOT + library + + + NUnit + NUnit.Framework + library + 2.2.8.0 + + + Added: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Console/src/main/csharp/NMaven/ProjectImporter/NMavenImportRunner.cs URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Console/src/main/csharp/NMaven/ProjectImporter/NMavenImportRunner.cs?rev=673616&view=auto ============================================================================== --- incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Console/src/main/csharp/NMaven/ProjectImporter/NMavenImportRunner.cs (added) +++ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Console/src/main/csharp/NMaven/ProjectImporter/NMavenImportRunner.cs Thu Jul 3 01:27:01 2008 @@ -0,0 +1,60 @@ +/* + * 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.Text; +using System.Xml; +using System.IO; +using NMaven.ProjectImporter.NMaven; + + +namespace NMaven.ProjectImporter.NMaven.ProjectImporter +{ + class NMavenImportRunner + { + + public static void Main(String[] args) + { + if (args.Length == 0) + { + Console.WriteLine("please specify the solution file. e.g. : " + Environment.NewLine + @"NMaven.ProjectImporterEngine.exe " + " \"C:\\projects\\multi-module-csharp\\NMaven\\NMaven.sln\""); + + } + else + { + NMavenImporter importer = new NMavenImporter(args); + importer.GeneratePom(); + Console.WriteLine("Done Generating Project Poms...."); + + + Console.WriteLine("Solution/Parent Pom: " + importer.GeneratedSolutionPomFile ); + + foreach(string pom in importer.GeneratedProjectPomFiles) + { + Console.WriteLine("Project Pom: " + pom); + } + + } + Console.In.ReadLine(); + + } + } +} Added: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/pom.xml URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/pom.xml?rev=673616&view=auto ============================================================================== --- incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/pom.xml (added) +++ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/pom.xml Thu Jul 3 01:27:01 2008 @@ -0,0 +1,67 @@ + + + + + + NMaven.ProjectImporter + 0.14-incubating-SNAPSHOT + NMaven.ImporterProjectParent + + 4.0.0 + NMaven.ProjectImporter + NMaven.ProjectImporterEngine + 0.14-incubating-SNAPSHOT + library + NMaven.ProjectImporterEngine + + + + org.apache.maven.wagon + wagon-webdav + 1.0-beta-2 + + + src/main/csharp + src/test/csharp + + + org.apache.maven.dotnet.plugins + maven-compile-plugin + true + + + maven-assembly-plugin + + + src + + + + + + + + NUnit + NUnit.Framework + library + 2.2.8.0 + + + Added: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Generator/BasePomGenerator.cs URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Generator/BasePomGenerator.cs?rev=673616&view=auto ============================================================================== --- incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Generator/BasePomGenerator.cs (added) +++ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Generator/BasePomGenerator.cs Thu Jul 3 01:27:01 2008 @@ -0,0 +1,67 @@ +/* + * 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.Text; +using System.Xml; + +namespace NMaven.ProjectImporter.NMaven.Generator +{ + public abstract class BasePomGenerator + { + protected XmlTextWriter writer; + protected string pomFile; + + public string PomFile + { + get { return this.pomFile; } + set { this.pomFile = value; } + } + + protected void initXmlWriter(String xmlFile) + { + this.pomFile = xmlFile; + writer = new XmlTextWriter(xmlFile, null); + //writer.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'"); + writer.Formatting = Formatting.Indented; + writer.Indentation = 2; + } + + protected void writeElementString(XmlWriter writer, String element, String value) + { + writer.WriteStartElement(element); + writer.WriteString(value); + writer.WriteEndElement(); + } + + protected void writeAttributeString(XmlWriter writer, String prefix, String localName, String ns, String value) + { + writer.WriteAttributeString(prefix, localName, ns, value); + } + + protected void populateProjectAttribute(XmlWriter writer) + { + writeAttributeString(writer, null, "xmlns", null, "http://maven.apache.org/POM/4.0.0"); + writeAttributeString(writer, "xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance"); + writeAttributeString(writer, "xsi", "schemaLocation", null, "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"); + } + } +} Added: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Generator/ProjectPomGenerator.cs URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Generator/ProjectPomGenerator.cs?rev=673616&view=auto ============================================================================== --- incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Generator/ProjectPomGenerator.cs (added) +++ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Generator/ProjectPomGenerator.cs Thu Jul 3 01:27:01 2008 @@ -0,0 +1,165 @@ +/* + * 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.Text; +using NMaven.ProjectImporter.NMaven.Model; +using System.IO; +using System.Xml; +using NMaven.ProjectImporter.NMaven.util; +using System.Collections.Specialized; +using System.Xml.XPath; + +namespace NMaven.ProjectImporter.NMaven.Generator +{ + public class ProjectPomGenerator : BasePomGenerator + { + private Project project; + + private Solution solution; + + private String nmavenSettingsFile = Environment.GetEnvironmentVariable("USERPROFILE") + "/.m2/nmaven-settings.xml"; + + + public ProjectPomGenerator(Project project, Solution solution) + { + this.project = project; + this.solution = solution; + initXmlWriter(project.PathOfProjectBaseDir + Path.DirectorySeparatorChar + "pom.xml"); + //Console.WriteLine("writing..... " + project.PathOfProjectBaseDir + Path.DirectorySeparatorChar + "pom.xml"); + Utility.log("writing..... " + project.PathOfProjectBaseDir + Path.DirectorySeparatorChar + "pom.xml"); + } + + public void generatePom() //preserved indention for readability + { + + try + { + writer.WriteStartElement("project"); + populateProjectAttribute(writer); + + + if (!Constants.SOLUTION_STRUCTURE_FLAT.Equals(solution.SolutionStructureType) && (project.ParentArtifactId != "" || project.ParentGroupId != "")) + { + writer.WriteStartElement("parent"); + writeElementString(writer, Constants.ARTIFACT_ID, project.ParentArtifactId); + writeElementString(writer, Constants.GROUP_ID, project.ParentGroupId); + writeElementString(writer, Constants.VERSION, "1.0-SNAPSHOT"); + writeElementString(writer, Constants.RELATIVE_PATH, project.RelativePath); + writer.WriteEndElement(); + } + + writeElementString(writer, Constants.MODEL_VERSION, "4.0.0"); + writeElementString(writer, Constants.GROUP_ID, project.GroupId); + writeElementString(writer, Constants.ARTIFACT_ID, project.ArtifactId); + writeElementString(writer, Constants.VERSION, project.Version); + + writer.WriteStartElement("packaging"); + writer.WriteString( Utility.normalizePackaging (project.Packaging) ); + writer.WriteEndElement(); + + writeElementString(writer, Constants.NAME, project.ArtifactId); + + writer.WriteStartElement("build"); + writeElementString(writer, Constants.SOURCE_DIRECTORY, project.SourceDirectory); + + writer.WriteStartElement("plugins"); + writer.WriteStartElement("plugin"); + writeElementString(writer, Constants.GROUP_ID, "org.apache.maven.dotnet.plugins"); + writeElementString(writer, Constants.ARTIFACT_ID, "maven-compile-plugin"); + //if (project.ProjectFile.FullName.EndsWith(Constants.CSPROJ)) + // { + writeElementString(writer, "extensions", "true"); + //} + writeConfigurationElementString(writer, project.ProjectFile); + writer.WriteEndElement(); + writer.WriteEndElement(); + writer.WriteEndElement(); + + writeDependency(writer); + + writer.WriteEndElement(); + } + catch (Exception e) + { + //Console.WriteLine("exception occured writing pom.xml:" + Environment.NewLine + e.Message + Environment.NewLine + e.StackTrace); + Utility.log("exception occured writing pom.xml:" + Environment.NewLine + e.Message + Environment.NewLine + e.StackTrace); + } + finally + { + writer.Close(); + } + } + + private void writeConfigurationElementString(XmlTextWriter writer, FileInfo projectFile) + { + if (project.ProjectFile.FullName.EndsWith(Constants.VBPROJ)) + { + writer.WriteStartElement("configuration"); + writeElementString(writer, Constants.LANGUAGE, Constants.VB); + writer.WriteEndElement(); + } + } + + private void writeDependency(XmlTextWriter writer ) + { + String installRoot = ""; + String hintPath = ""; + + XPathDocument doc = new XPathDocument(nmavenSettingsFile); + XPathNavigator nav = doc.CreateNavigator(); + nav = doc.CreateNavigator(); + + //Get the Active Compiler + XPathNodeIterator iterator = nav.Select("//nmavenSettings/vendors/vendor[./vendorName = //nmavenSettings/defaultSetup/vendorName and ./vendorVersion = //nmavenSettings/defaultSetup/vendorVersion]/frameworks/framework/installRoot"); + if (iterator.MoveNext()) + { + installRoot = iterator.Current.Value; + } + + writer.WriteStartElement("dependencies"); + foreach(String key in project.References.Keys) + { + hintPath = project.References[key]; + + // no hintpath info, point to active compiler, concat w/ the dll + if (hintPath == null || hintPath.Length == 0) + { + hintPath = installRoot + Path.DirectorySeparatorChar + key + ".dll"; + } + writer.WriteStartElement("dependency"); + writeElementString(writer, Constants.GROUP_ID, key); + writeElementString(writer, Constants.ARTIFACT_ID, key); + writeElementString(writer, Constants.VERSION, "1.0"); + writeElementString(writer, Constants.SCOPE, "system"); + writeElementString(writer, Constants.SYSTEM_PATH, hintPath ); + writer.WriteEndElement(); + } + foreach (String dependencySnippet in project.DependencySnippets) + { + writer.WriteRaw(dependencySnippet); + } + + writer.WriteEndElement(); + } + } + +} Added: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Generator/SolutionPomGenerator.cs URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Generator/SolutionPomGenerator.cs?rev=673616&view=auto ============================================================================== --- incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Generator/SolutionPomGenerator.cs (added) +++ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Generator/SolutionPomGenerator.cs Thu Jul 3 01:27:01 2008 @@ -0,0 +1,120 @@ +/* + * 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.Text; +using NMaven.ProjectImporter.NMaven.Model; +using System.Xml; +using System.IO; +using System.Windows.Forms; +using NMaven.ProjectImporter.NMaven.util; + + +namespace NMaven.ProjectImporter.NMaven.Generator +{ + public class SolutionPomGenerator : BasePomGenerator + { + private Solution solution; + + private Project[] projectArray; + + public SolutionPomGenerator(Solution solution) + { + this.solution = solution; + ///writer = new XmlTextWriter(solution.SolutionFile.DirectoryName + Path.DirectorySeparatorChar + "pom.xml" , null); + initXmlWriter(solution.SolutionFile.DirectoryName + Path.DirectorySeparatorChar + "pom.xml"); + } + + public void generatePom() + { + if (projectArray == null) throw new Exception("projectArray should be initialized."); + + String module = ""; + try + { + writer.WriteStartElement("project"); + populateProjectAttribute(writer); + + writeElementString(writer, Constants.MODEL_VERSION, "4.0.0"); + writeElementString(writer, Constants.GROUP_ID, solution.GroupId); + writeElementString(writer, Constants.ARTIFACT_ID, solution.ArtifactId); + writeElementString(writer, Constants.VERSION, "1.0-SNAPSHOT"); + writeElementString(writer, Constants.PACKAGING, solution.Packaging); + writeElementString(writer, Constants.NAME, solution.ArtifactId); + + writer.WriteStartElement("modules"); + /*foreach (String key in solution.Projects.Keys) + { + writer.WriteStartElement("module"); + + module = normalizeModuleName(key, solution.Projects[key]); + + writer.WriteString(module); + writer.WriteEndElement(); + }*/ + + int i =0; + foreach (String key in solution.Projects.Keys) + { + writer.WriteStartElement("module"); + + module = normalizeModuleName(projectArray[i++].AssemblyName.ToLower(), solution.Projects[key].ToLower() ); + + writer.WriteString(module); + writer.WriteEndElement(); + } + + writer.WriteEndElement(); + + writer.WriteEndElement(); + } + catch (Exception e) + { + //Console.WriteLine("exception occured writing pom.xml:" + Environment.NewLine + e.Message + Environment.NewLine + e.StackTrace); + Utility.log("exception occured writing pom.xml:" + Environment.NewLine + e.Message + Environment.NewLine + e.StackTrace); + } + finally + { + writer.Close(); + } + } + + /* + * + */ + private String normalizeModuleName(String projectName, String pathOfProjFile) + { + String temp = pathOfProjFile; + int indexProject = temp.IndexOf(projectName); + + int totalLength = indexProject + projectName.Length; + + return pathOfProjFile.Substring(0, totalLength); + } + + public Project[] ProjectArray + { + get { return projectArray; } + set { projectArray = value; } + } + + } +} Added: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Model/DefaultDOMElement.cs URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Model/DefaultDOMElement.cs?rev=673616&view=auto ============================================================================== --- incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Model/DefaultDOMElement.cs (added) +++ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Model/DefaultDOMElement.cs Thu Jul 3 01:27:01 2008 @@ -0,0 +1,78 @@ +/* + * 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; +using System.Collections.Specialized; +using System.Text; + +namespace NMaven.ProjectImporter.NMaven.Parser +{ + public class DefaultDOMElement + { + private String tagName; + private String text; + private StringDictionary attributes; + private DefaultDOMElements childElements; + + + public DefaultDOMElement(String tagName) + { + this.tagName = tagName; + attributes = new StringDictionary(); + childElements = new DefaultDOMElements(); + this.text=""; + } + + public String TagName { + get { + return tagName; + } + set { + this.tagName = value; + } + } + public string Text { + get { + return text; + } + set { + this.text = value; + } + } + + public DefaultDOMElements ChildElements { + get { + return this.childElements; + } + } + public StringDictionary Attributes { + get { + return this.attributes; + } + } + public String Attribute(String name) { + return (String) attributes[name]; + } + + public void setAttribute(String name, String value) { + attributes.Add(name, value); + } + } +} Added: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Model/DefaultDOMElements.cs URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Model/DefaultDOMElements.cs?rev=673616&view=auto ============================================================================== --- incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Model/DefaultDOMElements.cs (added) +++ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Model/DefaultDOMElements.cs Thu Jul 3 01:27:01 2008 @@ -0,0 +1,43 @@ +/* + * 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; + +namespace NMaven.ProjectImporter.NMaven.Parser +{ + public class DefaultDOMElements: CollectionBase { + public DefaultDOMElements() + { + } + public void Add(DefaultDOMElement se) { + this.List.Add(se); + } + public DefaultDOMElement Item(int index) { + return (DefaultDOMElement) this.List[index]; + } + public Object[] ToArray() { + Object[] ar = new Object[this.List.Count]; + for (int i=0; i < this.List.Count; i++) { + ar[i] = this.List[i]; + } + return ar; + } + } +} Added: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Model/Project.cs URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Model/Project.cs?rev=673616&view=auto ============================================================================== --- incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Model/Project.cs (added) +++ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Model/Project.cs Thu Jul 3 01:27:01 2008 @@ -0,0 +1,165 @@ +/* + * 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.Text; +using System.Collections.Specialized; +using System.IO; + +namespace NMaven.ProjectImporter.NMaven.Model +{ + public class Project + { + private String rootNameSpace; + private String assemblyName; + private String packaging; + + private String groupId; + private String artifactId; + private String parentGroupId; + private String parentArtifactId; + private String parentVersion; + private String sourceDirectory; + private StringDictionary references; + private List dependencySnippets = new List(); + + private FileInfo projectFile; //the csproj file + + private String pathOfProjectBaseDir; + + private String version; + + private String relativePath; + + public String RelativePath + { + get { return relativePath; } + set { relativePath = value; } + } + + public List DependencySnippets + { + get { return dependencySnippets; } + } + + public void addDependencySnippet (String dependencySnippet) + { + dependencySnippets.Add(dependencySnippet); + } + + public String Version + { + get { return version; } + set { version = value; } + } + + + public String PathOfProjectBaseDir + { + get { return pathOfProjectBaseDir; } + set { pathOfProjectBaseDir = value; } + } + + + public FileInfo ProjectFile + { + get { return projectFile; } + set { projectFile = value; } + } + + public Project() + { + references = new StringDictionary(); + } + + public void addReference (String name, String value) + { + references.Add(name, value ); + } + + public StringDictionary References + { + get { return references; } + } + + public String SourceDirectory + { + get { return sourceDirectory; } + set { sourceDirectory = value; } + } + + public String ParentVersion + { + get { return parentVersion; } + set { parentVersion = value; } + } + + + public String ParentArtifactId + { + get { return parentArtifactId; } + set { parentArtifactId = value; } + } + + + public String ParentGroupId + { + get { return parentGroupId; } + set { parentGroupId = value; } + } + + + public String ArtifactId + { + get { return artifactId; } + set { artifactId = value; } + } + + + public String GroupId + { + get { return groupId; } + set { groupId = value; } + } + + + public String Packaging + { + get { return packaging; } + set { packaging = value; } + } + + + public String AssemblyName + { + get { return assemblyName; } + set { assemblyName = value; } + } + + + public String RootNameSpace + { + get { return rootNameSpace; } + set { rootNameSpace = value; } + } + + } +} Added: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Model/Solution.cs URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Model/Solution.cs?rev=673616&view=auto ============================================================================== --- incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Model/Solution.cs (added) +++ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Model/Solution.cs Thu Jul 3 01:27:01 2008 @@ -0,0 +1,108 @@ +/* + * 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.Text; +using System.Collections.Specialized; +using System.IO; + +namespace NMaven.ProjectImporter.NMaven.Model +{ + public class Solution + { + public const String POM = "pom"; + public const String DEFAULT_GROUP_ID = "com.mydefault.group"; + + private StringDictionary projects; + private String artifactId; + private String groupId; + private String packaging = POM; + private String version; + + // derived field(s) + private String solutionStructureType; + + + public String SolutionStructureType + { + get { return solutionStructureType; } + set { solutionStructureType = value; } + } + + public String Version + { + get { return version; } + set { version = value; } + } + + private FileInfo solutionFile; // the *.sln file + + + public Solution(FileInfo solutionFile): this(solutionFile,null, null) + { + } + + public Solution(FileInfo solutionFile, String artifactId, String groupId) + { + this.artifactId = artifactId; + this.groupId = groupId; + this.solutionFile = solutionFile; + projects = new StringDictionary(); + + //populate GroupId/ArtifactID to default values + ArtifactId = solutionFile.Name; + GroupId = DEFAULT_GROUP_ID; + } + + public void addProject(String projectName, String relativePath) + { + projects.Add(projectName, relativePath); + } + + public String GroupId + { + get{return groupId;} + set{groupId=value;} + } + + public StringDictionary Projects + { + get { return projects; } + } + + public String ArtifactId + { + get { return artifactId; } + set { artifactId = value; } + } + + public FileInfo SolutionFile + { + get { return solutionFile; } + set { solutionFile = value; } + } + + public String Packaging + { + get { return packaging; } + //set { packaging = value; } + } + } +} Added: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/NMavenImporter.cs URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/NMavenImporter.cs?rev=673616&view=auto ============================================================================== --- incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/NMavenImporter.cs (added) +++ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/NMavenImporter.cs Thu Jul 3 01:27:01 2008 @@ -0,0 +1,285 @@ +/* + * 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.Collections.Specialized; +using System.Text; +using System.Xml; +using System.IO; +using NMaven.ProjectImporter.NMaven.Parser; +using NMaven.ProjectImporter.NMaven.Model; +using NMaven.ProjectImporter.NMaven.Generator; +using NMaven.ProjectImporter.NMaven.util; +using System.Reflection; + + +namespace NMaven.ProjectImporter.NMaven +{ + public class NMavenImporter + { + private string solutionFile; + private string generatedSolutionPomFile; + private string[] generatedProjectPomFiles; + private string defaultGroupId; + + public string SolutionFile + { + get { return this.solutionFile; } + set { this.solutionFile = value; } + } + + public string GeneratedSolutionPomFile + { + get { return this.generatedSolutionPomFile; } + } + + public string[] GeneratedProjectPomFiles + { + get { return this.generatedProjectPomFiles; } + } + + // mandatory arg : solution file + // non-mandatory arg: groupId ; "-DgroupId=" + // + // TODO: put these in hashtable. + public NMavenImporter(String[] args) + { + + foreach (String arg in args) + { + if (arg.EndsWith (".sln") ) + { + this.solutionFile = arg; + } + if (arg.StartsWith("-DgroupId=")) + { + this.defaultGroupId = getParamValue(arg); + } + } + + initDefaultGroupId(); + } + + private void initDefaultGroupId() + { + String company = "my.company"; + + if (defaultGroupId == null) + { + defaultGroupId = company; + } + } + + private String getParamValue(String param) + { + String[] a = param.Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + if (a.Length > 1) + return a[1]; + + return null; + } + + + public NMavenImporter() + { + this.solutionFile = null; + } + + /* Determines if the solution is : + * a.) flat = sln and csproj/vbproj are on the same directory + * b.) multi-module = csproj/vbproj is located >= 1 directory level down from sln file + * c.) flat and multi-module = combination of a) and b) + */ + private String getSolutionStructure(Solution solution) + { + Project[] projects = new Project[solution.Projects.Count]; + StringCollection projectPaths = new StringCollection(); + + foreach (string key in solution.Projects.Keys) + { + if ( (! solution.Projects[key].Contains(""+Path.DirectorySeparatorChar) ) && solution.Projects.Count==1 ) + { + return Constants.SOLUTION_STRUCTURE_FLAT; + } + else if ((!solution.Projects[key].Contains("" + Path.DirectorySeparatorChar)) && solution.Projects.Count > 1) + { + return Constants.SOLUTION_STRUCTURE_FLAT_AND_MULTI_MODULE; + } + } + + return Constants.SOLUTION_STRUCTURE_MULTI_MODULE; + + + } + + private Project getParentProjectForFlatAndMultiModule(Solution solution) + { + string projectFile = ""; + XmlTextReader reader = null; + DefaultDOMParser domParser = null; + DefaultDOMElement element = null; + Project project = null; + ProjectTransformer transformer = null; + foreach (string key in solution.Projects.Keys) + { + if (!Utility.pathContainsDirectory(solution.Projects[key])) + { + if (!solution.SolutionFile.DirectoryName.EndsWith("" + Path.DirectorySeparatorChar)) + { + projectFile = solution.SolutionFile.DirectoryName + Path.DirectorySeparatorChar + solution.Projects[key]; + } + try + { + reader = new XmlTextReader(projectFile); + domParser = new DefaultDOMParser(); + element = domParser.parse(reader); + + transformer = new ProjectTransformer(projectFile, element, solution); + project = transformer.transformFile(); + return project; + } + finally + { + reader.Close(); + } + + } + } + return null; + } + + public void GeneratePom() + { + try + { + string projectFile = ""; + ProjectTransformer transformer = null; + XmlTextReader reader = null; + DefaultDOMParser domParser = null; + Project project = null; + ProjectPomGenerator pomGenerator = null; + DefaultDOMElement element = null; + + FileInfo file = new FileInfo(this.solutionFile); + + DefaultSolutionParser solutionParser = new DefaultSolutionParser(file); + Solution solution = solutionParser.parse(); + + solution.SolutionStructureType = getSolutionStructure(solution); + + solution.ArtifactId = file.Name.Replace(".sln", "") + "-" + Constants.PARENT; + solution.GroupId = defaultGroupId; + + + Project[] projects = new Project[solution.Projects.Count]; + StringCollection projectPoms = new StringCollection(); + + Project parentProject = null; + if (solution.SolutionStructureType.Equals(Constants.SOLUTION_STRUCTURE_FLAT_AND_MULTI_MODULE)) + { + parentProject = getParentProjectForFlatAndMultiModule(solution); + } + + int i = 0; + foreach (string key in solution.Projects.Keys) + { + if (! solution.SolutionFile.DirectoryName.EndsWith(""+Path.DirectorySeparatorChar)) + { + projectFile = solution.SolutionFile.DirectoryName + Path.DirectorySeparatorChar + solution.Projects[key]; + } + try + { + reader = new XmlTextReader(projectFile); + domParser = new DefaultDOMParser(); + element = domParser.parse(reader); + + transformer = new ProjectTransformer(projectFile, element, solution); + project = transformer.transformFile(); + + //modify again parent infos for flat and flat_and_multi_module + if (Constants.SOLUTION_STRUCTURE_FLAT.Equals(solution.SolutionStructureType)) + + { + project.ParentArtifactId = ""; + project.ParentGroupId = ""; + } + else if (Constants.SOLUTION_STRUCTURE_FLAT_AND_MULTI_MODULE.Equals(solution.SolutionStructureType) && + Utility.pathContainsDirectory(solution.Projects[key])) + { + project.ParentGroupId = parentProject.GroupId; + project.ParentArtifactId = parentProject.ArtifactId; + project.RelativePath = Utility.computeRelativePath(parentProject.ProjectFile.DirectoryName, project.ProjectFile.DirectoryName); + } + + else if (Constants.SOLUTION_STRUCTURE_FLAT_AND_MULTI_MODULE.Equals(solution.SolutionStructureType) && + ! Utility.pathContainsDirectory(solution.Projects[key])) + { + // parent project, set this to empty so it won't be generated + project.ParentGroupId = ""; + project.ParentArtifactId = ""; + + } + + //end + + pomGenerator = new ProjectPomGenerator(project, solution); + pomGenerator.generatePom(); + + projectPoms.Add(pomGenerator.PomFile); + projects[i++] = project; + + } + finally + { + reader.Close(); + } + } + + if ( Constants.SOLUTION_STRUCTURE_MULTI_MODULE.Equals(solution.SolutionStructureType)) + { + generateSolutionPom(solution, projects); + } + + + + generatedProjectPomFiles = new string[projectPoms.Count]; + projectPoms.CopyTo(generatedProjectPomFiles, 0); + + + } + catch (Exception e) + { + //Console.WriteLine("ERROR : " + e.Message + Environment.NewLine + e.StackTrace); + Utility.log("ERROR : " + e.Message + Environment.NewLine + e.StackTrace); + } + } + + private void generateSolutionPom(Solution solution, Project[] projects) + { + SolutionPomGenerator parentGenerator = new SolutionPomGenerator(solution); + parentGenerator.ProjectArray = projects; + + parentGenerator.generatePom(); + + this.generatedSolutionPomFile = parentGenerator.PomFile; + } + + } +} Added: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Parser/DefaultDOMParser.cs URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Parser/DefaultDOMParser.cs?rev=673616&view=auto ============================================================================== --- incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Parser/DefaultDOMParser.cs (added) +++ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Parser/DefaultDOMParser.cs Thu Jul 3 01:27:01 2008 @@ -0,0 +1,110 @@ +/* + * 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; +using System.Collections.Specialized; +using System.Xml; + +namespace NMaven.ProjectImporter.NMaven.Parser +{ + public class DefaultDOMParser + { + private Stack elements; + private DefaultDOMElement currentElement; + private DefaultDOMElement rootElement; + + public DefaultDOMParser() + { + elements = new Stack(); + currentElement = null; + } + + public DefaultDOMElement parse(XmlTextReader reader) + { + DefaultDOMElement defaultElement = null; + //this.reader = reader; + + + while (!reader.EOF) + { + reader.Read(); + switch (reader.NodeType) + { + case XmlNodeType.Element: + defaultElement = new DefaultDOMElement(reader.LocalName); + currentElement = defaultElement; + if (elements.Count == 0) + { + rootElement = defaultElement; + elements.Push(defaultElement); + } + else + { + DefaultDOMElement parent = (DefaultDOMElement)elements.Peek(); + parent.ChildElements.Add(defaultElement); + + if (reader.IsEmptyElement) // do nothing for "" entry + { + if (reader.HasAttributes) + { + while (reader.MoveToNextAttribute()) + { + + currentElement.setAttribute(reader.Name, reader.Value); + } + } + } + else + { + elements.Push(defaultElement); + } + } + if (reader.HasAttributes) + { + while (reader.MoveToNextAttribute()) + { + + currentElement.setAttribute(reader.Name, reader.Value); + } + } + break; + case XmlNodeType.Attribute: + defaultElement.setAttribute(reader.Name, reader.Value); + break; + case XmlNodeType.EndElement: + elements.Pop(); + break; + case XmlNodeType.Text: + currentElement.Text = reader.Value; + break; + case XmlNodeType.CDATA: + currentElement.Text = reader.Value; + break; + default: + // ignore + break; + } + } + return rootElement; + } + } +} Added: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Parser/DefaultSolutionParser.cs URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Parser/DefaultSolutionParser.cs?rev=673616&view=auto ============================================================================== --- incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Parser/DefaultSolutionParser.cs (added) +++ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Parser/DefaultSolutionParser.cs Thu Jul 3 01:27:01 2008 @@ -0,0 +1,111 @@ +/* + * 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.Text; +using System.Text.RegularExpressions; +using System.IO; +using NMaven.ProjectImporter.NMaven.Model; +using System.Collections.Specialized; +using NMaven.ProjectImporter.NMaven.util; + +namespace NMaven.ProjectImporter.NMaven.Parser +{ + public class DefaultSolutionParser + { + private Solution solution; + + public DefaultSolutionParser(FileInfo file) + { + if (file == null) throw new NullReferenceException("file reference should not be null"); + + solution = new Solution(file); + } + + public Solution parse() + { + return parse(solution.SolutionFile.FullName); + } + + private Solution parse(String fileName) + { + String contents = File.ReadAllText(fileName); + + String[] splitContents = contents.Split(new string[]{System.Environment.NewLine}, System.StringSplitOptions.RemoveEmptyEntries); + + foreach (String anEntry in splitContents) + { + + if (anEntry.StartsWith(Constants.PREFIX_PROJ_SLN_ID)) + { + String[] projectEntry = processProjectLine(anEntry); + + if (projectEntry[1].EndsWith("." + Constants.CSPROJ) ||projectEntry[1].EndsWith( "." + Constants.VBPROJ)) + { + //Console.WriteLine("project found... "); + //Console.WriteLine(" projectName :" + projectEntry[0]); + //Console.WriteLine(" relativePath :" + projectEntry[1]); + Utility.log("project found... "); + Utility.log(" projectName :" + projectEntry[0]); + Utility.log(" relativePath :" + projectEntry[1]); + solution.addProject(projectEntry[0], projectEntry[1]); + } + else + { + Utility.log("ignoring.. "); + Utility.log(" projectName :" + projectEntry[0]); + Utility.log(" relativePath :" + projectEntry[1]); + + } + + + } + } + return solution; + } + + private String[] processProjectLine(String anEntry) + { + String[] projectItems = anEntry.Split(new String[] { "=" }, System.StringSplitOptions.RemoveEmptyEntries); + String projectName = ""; + String relativePath = ""; + + int i=0; + foreach (String projectItem in projectItems) + { + + if (i++ == 0) continue; //ignore 1st token + else + { + String[] projectFields = projectItem.Split(new String[] { "," }, System.StringSplitOptions.RemoveEmptyEntries); + projectName = projectFields[0].Replace("\"","").Trim(); + relativePath = projectFields[1].Replace("\"", "").Trim(); + + return new String[] { projectName, relativePath }; + } + } + + return null; + } + } + + +} Added: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Parser/ProjectTransformer.cs URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Parser/ProjectTransformer.cs?rev=673616&view=auto ============================================================================== --- incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Parser/ProjectTransformer.cs (added) +++ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/Parser/ProjectTransformer.cs Thu Jul 3 01:27:01 2008 @@ -0,0 +1,159 @@ +/* + * 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.Text; +using NMaven.ProjectImporter.NMaven.Parser; +using System.Collections.Specialized; +using NMaven.ProjectImporter.NMaven.util; +using System.IO; + +namespace NMaven.ProjectImporter.NMaven.Model +{ + //strip out the necessary data from raw DefaultDOMElement + public class ProjectTransformer + { + private DefaultDOMElement element; + private Solution solution; + private Project project; + private StringDictionary references; + + + public ProjectTransformer(String projectFile, DefaultDOMElement defaultDomElement, Solution solution) + { + this.element = defaultDomElement; + this.solution = solution; + project = new Project(); + project.ProjectFile = new FileInfo(projectFile); + references = new StringDictionary(); + project.Version = "1.0-SNAPSHOT"; + } + + + + public Project transformFile() + { + project.ParentArtifactId = solution.ArtifactId; + project.ParentGroupId = solution.GroupId; + project.ParentVersion = solution.Version; + + project.RelativePath = Utility.computeRelativePath(solution.SolutionFile.DirectoryName, project.ProjectFile.DirectoryName); + + transformDOM(element); + return project; + } + + // given the path of csproj and the directory name of the base dir, returns the full path of the base dir + // e.g. projectFile=c:\my\path\sample.csproj, + // directoryName=my + // result: c:\my + private void setBaseProjectPath( String rootNameSpace) + { + int lengthOfBaseProject = project.ProjectFile.DirectoryName.LastIndexOf (rootNameSpace) +rootNameSpace.Length; + + project.PathOfProjectBaseDir = project.ProjectFile.DirectoryName.Substring(0, lengthOfBaseProject); + } + + private void setSourceDirectory() + { + project.SourceDirectory = project.ProjectFile.DirectoryName.Replace(project.PathOfProjectBaseDir, "." + Path.DirectorySeparatorChar); + } + + /* + * transform the csproj/vbproj to a DOM object + * + */ + private void transformDOM(DefaultDOMElement element) + { + if (Constants.ASSEMBLY_NAME.Equals(element.TagName, StringComparison.OrdinalIgnoreCase)) + { + project.AssemblyName = element.Text; + project.GroupId = solution.GroupId; + project.ArtifactId = element.Text; + + setBaseProjectPath(project.AssemblyName); + setSourceDirectory(); + } + else if (Constants.ROOT_NAME_SPACE.Equals(element.TagName, StringComparison.OrdinalIgnoreCase)) + { + project.RootNameSpace = element.Text; + } + else if (Constants.OUTPUT_TYPE.Equals(element.TagName, StringComparison.OrdinalIgnoreCase)) + { + project.Packaging = element.Text; + } + else if (Constants.ASSEMBLY_NAME.Equals(element.TagName, StringComparison.OrdinalIgnoreCase)) + { + project.AssemblyName = element.Text; + } + else if (Constants.REFERENCE.Equals(element.TagName, StringComparison.OrdinalIgnoreCase)) + { + String include = ""; + String hintPath = ""; + + foreach (String attName in element.Attributes.Keys) + { + if (Constants.INCLUDE.Equals(attName, StringComparison.OrdinalIgnoreCase)) + { + include = Utility.cleanAttribute( element.Attribute(attName) ); + break; + } + } + if (element.ChildElements.Count > 0) + { + foreach (DefaultDOMElement child in element.ChildElements) + { + if (Constants.HINTPATH.Equals(child.TagName, StringComparison.OrdinalIgnoreCase)) + { + hintPath = project.ProjectFile.DirectoryName + Path.DirectorySeparatorChar + child.Text; + break; + } + } + } + + project.addReference(include, hintPath); + } + else if (Constants.PROJECT_REFERENCE.Equals(element.TagName,StringComparison.OrdinalIgnoreCase)) + { + String projectInclude = ""; + foreach (String attName in element.Attributes.Keys) + { + if (Constants.INCLUDE.Equals(attName, StringComparison.OrdinalIgnoreCase)) + { + projectInclude = element.Attribute(attName); + break; + } + } + //Console.WriteLine( project.ProjectFile.DirectoryName+ ", " + projectInclude); + Utility.log(project.ProjectFile.DirectoryName + ", " + projectInclude); + project.addDependencySnippet( Utility.getDependencyInfo(new FileInfo (project.ProjectFile.DirectoryName +Path.DirectorySeparatorChar + projectInclude), solution) ); + } + + if (element.ChildElements.Count > 0) + { + foreach (DefaultDOMElement child in element.ChildElements) + { + transformDOM(child); + } + } + } + } +} Added: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/util/Constants.cs URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/util/Constants.cs?rev=673616&view=auto ============================================================================== --- incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/util/Constants.cs (added) +++ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/util/Constants.cs Thu Jul 3 01:27:01 2008 @@ -0,0 +1,62 @@ +/* + * 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.Text; + +namespace NMaven.ProjectImporter.NMaven.util +{ + + public static class Constants + { + public const String ROOT_NAME_SPACE = "RootNameSpace"; + public const String ASSEMBLY_NAME = "AssemblyName"; + public const String REFERENCE = "Reference"; + public const String INCLUDE = "Include"; + public const String HINTPATH = "HintPath"; + public const String OUTPUT_TYPE = "OutputType"; + public const String PREFIX_PROJ_SLN_ID = "Project(\"{"; + public const String DEFAULT_VERSION = "1.0-SNAPSHOT"; + + public const String MODEL_VERSION = "modelVersion"; + public const String GROUP_ID = "groupId"; + public const String ARTIFACT_ID = "artifactId"; + public const String VERSION = "version"; + public const String PACKAGING = "packaging"; + public const String NAME = "name"; + public const String SOURCE_DIRECTORY = "sourceDirectory"; + public const String VB = "VB"; + public const String LANGUAGE = "language"; + public const String CSPROJ = "csproj"; + public const String VBPROJ = "vbproj"; + + public const String PARENT = "parent"; + public const String SCOPE = "scope"; + public const String SYSTEM_PATH = "systemPath"; + public const String PROJECT_REFERENCE = "ProjectReference"; + public const String TYPE = "type"; + public const String RELATIVE_PATH = "relativePath"; + + public const String SOLUTION_STRUCTURE_FLAT = "PROJECT_STRUCTURE_FLAT"; + public const String SOLUTION_STRUCTURE_MULTI_MODULE = "PROJECT_STRUCTURE_MULTI_MODULE"; + public const String SOLUTION_STRUCTURE_FLAT_AND_MULTI_MODULE = "PROJECT_STRUCTURE_FLAT_AND_MULTI_MODULE"; + } +} Added: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/util/Utility.cs URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/util/Utility.cs?rev=673616&view=auto ============================================================================== --- incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/util/Utility.cs (added) +++ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/Engine/src/main/csharp/NMaven/util/Utility.cs Thu Jul 3 01:27:01 2008 @@ -0,0 +1,138 @@ +/* + * 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.Text; +using System.Xml.XPath; +using System.IO; +using NMaven.ProjectImporter.NMaven.Parser; +using System.Xml; +using NMaven.ProjectImporter.NMaven.Model; + +namespace NMaven.ProjectImporter.NMaven.util +{ + public static class Utility + { + public static string getDependencyInfo(FileInfo projFile, Solution solution) + { + + string dependencySnippet = ""; + + //having problem parsing w/ Xpath, doing the long method + // + XmlTextReader reader = new XmlTextReader(projFile.FullName); + DefaultDOMParser domParser = new DefaultDOMParser(); + DefaultDOMElement element = domParser.parse(reader); + ProjectTransformer transformer = new ProjectTransformer(projFile.FullName, element, solution); + Project project = transformer.transformFile(); + + + dependencySnippet = + Environment.NewLine + + "" + Environment.NewLine + + " <" + Constants.GROUP_ID + ">" + project.GroupId + "" + Environment.NewLine + + " <" + Constants.ARTIFACT_ID + ">" + project.ArtifactId + "" + Environment.NewLine + + " <" + Constants.VERSION + ">" + project.Version+ "" + Environment.NewLine + + " <" + Constants.TYPE + ">" + normalizePackaging(project.Packaging) + "" + Environment.NewLine + + "" + ; + + //Console.WriteLine(dependencySnippet); + return dependencySnippet; + } + + public static string normalizePackaging(string outputType) + { + if ( outputType.ToLower().Equals("library") || + outputType.ToLower().Equals("winexe") || + outputType.ToLower().Equals("module") + ) + { + return outputType.ToLower(); + } + + return "exe"; + } + + //simple logger + public static void log(String message) + { + String tempPath = System.IO.Path.GetTempPath(); + String date = DateTime.Now.ToString("yyyy-MM-dd-HH:mm:ss"); + TextWriter tw = null; + try + { + tw = new StreamWriter(tempPath + Path.DirectorySeparatorChar + "NMaven.ProjectImporter.log", true); + tw.WriteLine("["+ date +"]"+ " " + message ); + } + catch (Exception e) + { + //do nothing. + } + finally + { + tw.Close(); + } + } + + // strip out the unwanted characters, return the name only + // e.g. + // attribute is "Castle.Core, Version=1.0.0.0, Culture=neutral" + // returns "Castle.Core" + public static String cleanAttribute(String attribute) + { + String[] excludes = new String[]{ " ", ",", "=" }; + + if (attribute == null) + { + return ""; + } + + String[] result = attribute.Split(excludes, System.StringSplitOptions.RemoveEmptyEntries); + + return result[0]; + } + + public static String computeRelativePath(String parentProjectDir, String childProjectDir) + { + char sepChar = Path.DirectorySeparatorChar; + + int parentLength = parentProjectDir.Split(sepChar).Length; + int childLength = childProjectDir.Split(sepChar).Length; + + int dirLevel = childLength - parentLength; + + String relativePath = ""; + for (int i = 0; i < dirLevel; i++) + { + relativePath += ".." + sepChar; + } + relativePath += "pom.xml"; + + return relativePath; + } + + public static Boolean pathContainsDirectory(String path) + { + return path.Contains(""+Path.DirectorySeparatorChar); + } + } +} Added: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/pom.xml URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/pom.xml?rev=673616&view=auto ============================================================================== --- incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/pom.xml (added) +++ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.ProjectImporter/pom.xml Thu Jul 3 01:27:01 2008 @@ -0,0 +1,50 @@ + + + + + + NMaven + 0.14-incubating-SNAPSHOT + NMaven.Assemblies + + NMaven.ProjectImporter + 0.14-incubating-SNAPSHOT + NMaven.ImporterProjectParent + pom + 4.0.0 + ImporterParentProject + + Engine + Console + + + + + org.apache.maven.dotnet.plugins + maven-compile-plugin + true + + MICROSOFT + 2.0.50727 + + + + + Modified: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.VisualStudio.Addin/pom.xml URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.VisualStudio.Addin/pom.xml?rev=673616&r1=673615&r2=673616&view=diff ============================================================================== --- incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.VisualStudio.Addin/pom.xml (original) +++ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.VisualStudio.Addin/pom.xml Thu Jul 3 01:27:01 2008 @@ -132,7 +132,13 @@ Castle.DynamicProxy library 2.0-rc2 - + + + NMaven.ProjectImporter + NMaven.ProjectImporterEngine + 0.14-incubating-SNAPSHOT + library + Modified: incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.VisualStudio.Addin/src/main/csharp/NMaven/VisualStudio/Addin/Connect.cs URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.VisualStudio.Addin/src/main/csharp/NMaven/VisualStudio/Addin/Connect.cs?rev=673616&r1=673615&r2=673616&view=diff ============================================================================== --- incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.VisualStudio.Addin/src/main/csharp/NMaven/VisualStudio/Addin/Connect.cs (original) +++ incubator/nmaven/branches/NMAVEN_0.14/assemblies/NMaven.VisualStudio.Addin/src/main/csharp/NMaven/VisualStudio/Addin/Connect.cs Thu Jul 3 01:27:01 2008 @@ -226,6 +226,19 @@ ctl1.Caption = "Configure Maven Repository..."; ctl1.Visible = true; addReferenceControls.Add(ctl1); + + CommandBarButton ctlProjectImport = (CommandBarButton) + commandBar.Controls.Add(MsoControlType.msoControlButton, + System.Type.Missing, + System.Type.Missing, + control.Index, + true); + ctlProjectImport.Click += + new _CommandBarButtonEvents_ClickEventHandler(cbChangeProjectImportForm_Click); + ctlProjectImport.Caption = "NMaven: Import Project"; + ctlProjectImport.Visible = true; + addReferenceControls.Add(ctlProjectImport); + } else if (control.Caption.Equals("Clea&n")) { @@ -546,6 +559,14 @@ } } #endregion + + #region cbChangeProjectImportForm_Click(CommandBarButton, bool) + private void cbChangeProjectImportForm_Click(CommandBarButton btn, ref bool Cancel) + { + NMavenImportProjectForm frm = new NMavenImportProjectForm(_applicationObject); + frm.ShowDialog(); + } + #endregion #region OnBeginShutdown(Array) /// Implements the OnBeginShutdown method of the IDTExtensibility2 interface. Receives notification that the host application is being unloaded.