/// <summary> /// Facade for Digesting parsed projects /// calls NPanday.ProjectImporter.Digest.ProjectDigester.DigestProjects(List<Dictionary<string, object>>) /// </summary> /// <param name="projects">list retured from ParseSolution</param> /// <returns></returns> public static ProjectDigest[] DigestProjects(List <Dictionary <string, object> > projects, DependencySearchConfiguration depSearchConfig, ref string warningMsg) { return(ProjectDigester.DigestProjects(projects, depSearchConfig, ref warningMsg)); }
public static string[] ImportProject(string solutionFile, string groupId, string artifactId, string version, string scmTag, bool verifyTests, bool useMsDeploy, string configuration, string cloudConfig, DependencySearchConfiguration depSearchConfig, Dictionary <string, string> globalProperties, ref string warningMsg) { VerifyProjectToImport method = verifyTests ? VerifyUnitTestsToUser.VerifyTests : (VerifyProjectToImport)null; return(ImportProject(solutionFile, groupId, artifactId, version, scmTag, method, useMsDeploy, configuration, cloudConfig, depSearchConfig, globalProperties, ref warningMsg)); }
/// <summary> /// Imports a specified Visual Studio Projects in a Solution to an NPanday Pom, /// This is the Project-Importer Entry Method, /// This method accepts a delegate to use as A project Verifier algorithm /// </summary> /// <param name="solutionFile">Path to your Visual Studio Solution File *.sln </param> /// <param name="groupId">Project Group ID, for maven groupId</param> /// <param name="artifactId">Project Parent Pom Artifact ID, used as a maven artifact ID for the parent pom.xml</param> /// <param name="version">Project version, used as a maven version for the entire pom.xmls</param> /// <param name="verifyProjectToImport">A delegate That will Accept a method for verifying Projects To Import</param> /// <param name="scmTag">adds scm tags to parent pom.xml if not string.empty or null</param> /// <returns>An array of generated pom.xml filenames</returns> public static string[] ImportProject(string solutionFile, string groupId, string artifactId, string version, string scmTag, VerifyProjectToImport verifyProjectToImport, bool useMsDeploy, string configuration, string cloudConfig, DependencySearchConfiguration depSearchConfig, Dictionary <string, string> globalProperties, ref string warningMsg) { string[] result = null; if (depSearchConfig == null) { depSearchConfig = new DependencySearchConfiguration(); } FileInfo solutionFileInfo = new FileInfo(solutionFile); List <Dictionary <string, object> > list = ParseSolution(solutionFileInfo, globalProperties, ref warningMsg); if (configuration != null) { foreach (Dictionary <string, object> projectMap in list) { projectMap.Add("Configuration", configuration); } } //Checks for Invalid folder structure HasValidFolderStructure(list); ProjectDigest[] prjDigests = DigestProjects(list, depSearchConfig, ref warningMsg); ProjectStructureType structureType = GetProjectStructureType(solutionFile, prjDigests); // Filtering of unsupported project types. String UnsupportedProjectsMessage = string.Empty; List <ProjectDigest> filteredPrjDigests = new List <ProjectDigest>(); foreach (ProjectDigest pDigest in prjDigests) { if (PomConverter.__converterAlgorithms.ContainsKey(pDigest.ProjectType)) { // set the project flag so that converters can look at it later pDigest.UseMsDeploy = useMsDeploy; pDigest.CloudConfig = cloudConfig; pDigest.DependencySearchConfig = depSearchConfig; filteredPrjDigests.Add(pDigest); } else { if (UnsupportedProjectsMessage == string.Empty) { UnsupportedProjectsMessage += pDigest.FullFileName; } else { UnsupportedProjectsMessage += ", " + pDigest.FullFileName; } } } if (!string.Empty.Equals(UnsupportedProjectsMessage)) { warningMsg = string.Format("{0}\n Unsupported Projects: {1}", warningMsg, UnsupportedProjectsMessage); } prjDigests = filteredPrjDigests.ToArray(); if (verifyProjectToImport != null && filteredPrjDigests.Count > 0) { verifyProjectToImport(ref prjDigests, structureType, solutionFile, ref groupId, ref artifactId, ref version); } List <Reference> missingReferences = new List <Reference>(); List <string> nonPortableReferences = new List <string>(); result = ImportProjectType(structureType, filteredPrjDigests.ToArray(), solutionFile, groupId, artifactId, version, scmTag, missingReferences, nonPortableReferences); if (missingReferences.Count > 0) { warningMsg += "\nThe following references could not be resolved from Maven or the GAC:"; foreach (Reference missingReference in missingReferences) { warningMsg += "\n\t" + missingReference.Name + " (" + missingReference.Version + ")"; } warningMsg += "\nPlease update the defaults in pom.xml and re-sync references, or re-add them using 'Add Maven Artifact'."; } if (nonPortableReferences.Count > 0) { if (depSearchConfig.CopyToMaven) { warningMsg += "The following artifacts were copied to the local Maven repository:"; } else { warningMsg += "\nThe build may not be portable if local references are used:"; } warningMsg += "\n\t" + string.Join("\n\t", nonPortableReferences.ToArray()) + "\nDeploying the reference to a Repository will make the code portable to other machines."; } return(result); }
/// <summary> /// Facade for Digesting parsed projects /// calls NPanday.ProjectImporter.Digest.ProjectDigester.DigestProjects(List<Dictionary<string, object>>) /// </summary> /// <param name="projects">list retured from ParseSolution</param> /// <returns></returns> public static ProjectDigest[] DigestProjects(List<Dictionary<string, object>> projects, DependencySearchConfiguration depSearchConfig, ref string warningMsg) { return ProjectDigester.DigestProjects(projects, depSearchConfig, ref warningMsg); }
public static string[] ImportProject(string solutionFile, string groupId, string artifactId, string version, string scmTag, bool verifyTests, bool useMsDeploy, string configuration, string cloudConfig, DependencySearchConfiguration depSearchConfig, ref string warningMsg) { return(ImportProject(solutionFile, groupId, artifactId, version, scmTag, verifyTests, useMsDeploy, configuration, cloudConfig, depSearchConfig, null, ref warningMsg)); }
/// <summary> /// Imports a specified Visual Studio Projects in a Solution to an NPanday Pom, /// This is the Project-Importer Entry Method, /// This method accepts a delegate to use as A project Verifier algorithm /// </summary> /// <param name="solutionFile">Path to your Visual Studio Solution File *.sln </param> /// <param name="groupId">Project Group ID, for maven groupId</param> /// <param name="artifactId">Project Parent Pom Artifact ID, used as a maven artifact ID for the parent pom.xml</param> /// <param name="version">Project version, used as a maven version for the entire pom.xmls</param> /// <param name="verifyProjectToImport">A delegate That will Accept a method for verifying Projects To Import</param> /// <param name="scmTag">adds scm tags to parent pom.xml if not string.empty or null</param> /// <returns>An array of generated pom.xml filenames</returns> public static string[] ImportProject(string solutionFile, string groupId, string artifactId, string version, string scmTag, VerifyProjectToImport verifyProjectToImport, bool useMsDeploy, string configuration, string cloudConfig, DependencySearchConfiguration depSearchConfig, Dictionary<string, string> globalProperties, ref string warningMsg) { string[] result = null; if (depSearchConfig == null) depSearchConfig = new DependencySearchConfiguration(); FileInfo solutionFileInfo = new FileInfo(solutionFile); List<Dictionary<string, object>> list = ParseSolution(solutionFileInfo, globalProperties, ref warningMsg); if (configuration != null) { foreach (Dictionary<string, object> projectMap in list) { projectMap.Add("Configuration", configuration); } } //Checks for Invalid folder structure HasValidFolderStructure(list); ProjectDigest[] prjDigests = DigestProjects(list, depSearchConfig, ref warningMsg); ProjectStructureType structureType = GetProjectStructureType(solutionFile, prjDigests); // Filtering of unsupported project types. String UnsupportedProjectsMessage = string.Empty; List<ProjectDigest> filteredPrjDigests = new List<ProjectDigest>(); foreach (ProjectDigest pDigest in prjDigests) { if (PomConverter.__converterAlgorithms.ContainsKey(pDigest.ProjectType)) { // set the project flag so that converters can look at it later pDigest.UseMsDeploy = useMsDeploy; pDigest.CloudConfig = cloudConfig; pDigest.DependencySearchConfig = depSearchConfig; filteredPrjDigests.Add(pDigest); } else { if (UnsupportedProjectsMessage == string.Empty) { UnsupportedProjectsMessage += pDigest.FullFileName; } else { UnsupportedProjectsMessage += ", " + pDigest.FullFileName; } } } if (!string.Empty.Equals(UnsupportedProjectsMessage)) { warningMsg = string.Format("{0}\n Unsupported Projects: {1}", warningMsg, UnsupportedProjectsMessage); } prjDigests = filteredPrjDigests.ToArray(); if (verifyProjectToImport != null && filteredPrjDigests.Count > 0) { verifyProjectToImport(ref prjDigests, structureType, solutionFile, ref groupId, ref artifactId, ref version); } List<Reference> missingReferences = new List<Reference>(); List<string> nonPortableReferences = new List<string>(); result = ImportProjectType(structureType, filteredPrjDigests.ToArray(), solutionFile, groupId, artifactId, version, scmTag, missingReferences, nonPortableReferences); if (missingReferences.Count > 0) { warningMsg += "\nThe following references could not be resolved from Maven or the GAC:"; foreach (Reference missingReference in missingReferences) { warningMsg += "\n\t" + missingReference.Name + " (" + missingReference.Version + ")"; } warningMsg += "\nPlease update the defaults in pom.xml and re-sync references, or re-add them using 'Add Maven Artifact'."; } if (nonPortableReferences.Count > 0) { if (depSearchConfig.CopyToMaven) { warningMsg += "The following artifacts were copied to the local Maven repository:"; } else { warningMsg += "\nThe build may not be portable if local references are used:"; } warningMsg += "\n\t" + string.Join("\n\t", nonPortableReferences.ToArray()) + "\nDeploying the reference to a Repository will make the code portable to other machines."; } return result; }
public static string[] ImportProject(string solutionFile, string groupId, string artifactId, string version, string scmTag, bool verifyTests, bool useMsDeploy, string configuration, string cloudConfig, DependencySearchConfiguration depSearchConfig, Dictionary<string, string> globalProperties, ref string warningMsg) { VerifyProjectToImport method = verifyTests ? VerifyUnitTestsToUser.VerifyTests : (VerifyProjectToImport)null; return ImportProject(solutionFile, groupId, artifactId, version, scmTag, method, useMsDeploy, configuration, cloudConfig, depSearchConfig, globalProperties, ref warningMsg); }
public static string[] ImportProject(string solutionFile, string groupId, string artifactId, string version, string scmTag, bool verifyTests, bool useMsDeploy, string configuration, string cloudConfig, DependencySearchConfiguration depSearchConfig, ref string warningMsg) { return ImportProject(solutionFile, groupId, artifactId, version, scmTag, verifyTests, useMsDeploy, configuration, cloudConfig, depSearchConfig, null, ref warningMsg); }
private void btnGenerate_Click(object sender, EventArgs e) { string configuration = null; if (configComboBox.SelectedItem != "(Default)") { configuration = (string) configComboBox.SelectedItem; } string cloudConfig = null; if (cloudConfigComboBox.SelectedItem != "(Default)") { cloudConfig = (string)cloudConfigComboBox.SelectedItem; } DependencySearchConfiguration depSearchConfig = new DependencySearchConfiguration(); depSearchConfig.SearchFramework = searchFrameworkCheckBox.Checked; depSearchConfig.SearchAssemblyFoldersEx = searchAssemblyFoldersExCheckBox.Checked; depSearchConfig.SearchGac = searchGacCheckBox.Checked; depSearchConfig.CopyToMaven = copyToMavenCheckBox.Checked; //Refactored code for easier Unit Testing try { GeneratePom(txtBrowseDotNetSolutionFile.Text, txtGroupId.Text.Trim(), txtVersion.Text.Trim(), txtSCMTag.Text, useMsDeployCheckBox.Checked, configuration, cloudConfig, depSearchConfig); } catch (Exception exception) { log.Debug("Import error", exception); MessageBox.Show(exception.Message, "NPanday Import Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
protected void GeneratePom(String solutionFile, String groupId, String version, String scmTag, bool useMsDeploy, string configuration, string cloudConfig, DependencySearchConfiguration depSearchConfig) { string warningMsg = string.Empty; String mavenVerRegex = "^[0-9]+(" + Regex.Escape(".") + "?[0-9]+){0,3}$"; String hasAlpha = "[a-zA-Z]"; String singleMavenVer = "[0-9]+"; bool isMatch = false; if (version.Length > 1) { if (Regex.IsMatch(version, hasAlpha) && version.ToUpper().EndsWith("-SNAPSHOT")) { isMatch = Regex.IsMatch(version.ToUpper().Replace("-SNAPSHOT", ""), mavenVerRegex, RegexOptions.Singleline); } else { isMatch = Regex.IsMatch(version, mavenVerRegex, RegexOptions.Singleline); } } else if (version.Length == 1) { isMatch = Regex.IsMatch(version, singleMavenVer); } if (!String.Empty.Equals(solutionFile) && System.IO.File.Exists(solutionFile) && (!String.Empty.Equals(groupId)) && (!String.Empty.Equals(version)) && isMatch) { // Generate here FileInfo file = new FileInfo(solutionFile); string artifactId = FilterID(ConvertToPascalCase(file.Name.Replace(".sln", ""))) + "-parent"; groupId = FilterID(groupId); if (scmTag == null) { scmTag = string.Empty; } if (scmTag.ToUpper().Contains("OPTIONAL")) { scmTag = string.Empty; } if (scmTag.Contains("scm:svn:")) { scmTag = scmTag.Remove(scmTag.IndexOf("scm:svn:"), 8); } try { if (!scmTag.Equals(string.Empty)) { if (!scmTag.Contains(@"://")) scmTag = string.Format(@"http://{0}", scmTag); Regex urlValidator = new Regex(@"^((ht|f)tp(s?)\:\/\/|~/|/)?([\w]+:\w+@)?([a-zA-Z]{1}([\w\-]+\.)+([\w]{2,5}))(:[\d]{1,5})?((/?\w+/)+|/?)(\w+\.[\w]{3,4})?((\?\w+=\w+)?(&\w+=\w+)*)?"); if (!urlValidator.IsMatch(scmTag)) throw new Exception(string.Format("SCM tag {0} is incorrect format", scmTag)); verifyRemoteAccess(scmTag, null); } } catch { if (DialogResult.Yes == MessageBox.Show(string.Format("SCM tag {0} was not accessible, would you still like to proceed with Project import?", scmTag), "SCM Tag", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)) { warningMsg = string.Format("\n The SCM URL {0} was added to the POM but could not be resolved and may not be valid.", scmTag); } else { return; } } validateSolutionStructure(); resyncAllArtifacts(); // TODO: nicer to have some sort of structure / flags for the Msdeploy bit, or this dialog will get out of control over time - perhaps a "project configuration" dialog can replace the test popup Dictionary<string, string> globalProperties = new Dictionary<string, string>(); globalProperties.Add("VisualStudioVersion", applicationObject.Version); string[] generatedPoms = ProjectImporter.NPandayImporter.ImportProject(file.FullName, groupId, artifactId, version, scmTag, true, useMsDeploy, configuration, cloudConfig, depSearchConfig, globalProperties, ref warningMsg); string str = string.Format("NPanday Import Project has Successfully Generated POM Files!\n"); foreach (string pom in generatedPoms) { str = str + string.Format("\n Generated Pom XML File: {0} ", pom); } if (!string.IsNullOrEmpty(warningMsg)) { str = string.Format("{0}\n\nwith Warning(s):{1}", str, warningMsg); } MessageBox.Show(str, this.Text); // Close the Dialog Here this.DialogResult = DialogResult.OK; this.Close(); } else { string message = (!(!"".Equals(solutionFile) && System.IO.File.Exists(solutionFile))) ? string.Format("Solution File Not Found: {0} ", solutionFile) : ""; if (String.IsNullOrEmpty(message)) { message = message + (String.IsNullOrEmpty(groupId) ? "Group Id is empty." : ""); } else { message = message + Environment.NewLine + (String.IsNullOrEmpty(groupId) ? "Group Id is empty." : ""); } //Adding error message for empty Version field if (String.IsNullOrEmpty(version)) { message += Environment.NewLine + "Version is empty."; } else if (!isMatch) { message += Environment.NewLine + "Version should be in the form major.minor.build.revision-SNAPSHOT"; } throw new Exception(message); } }