public override void ConvertProjectToPomModel(bool writePom, string scmTag) { // relies on this being set everywhere - if it were set per project, this would need to be evaluated on the project references if (!projectDigest.UseMsDeploy) { throw new Exception("You must use Web Deploy 2.0 to package web applications when using Azure projects"); } GenerateHeader("azure-cloud-service"); //Add SCM Tag if (scmTag != null && scmTag != string.Empty && Model.parent == null) { Scm scmHolder = new Scm(); scmHolder.connection = string.Format("scm:svn:{0}", scmTag); scmHolder.developerConnection = string.Format("scm:svn:{0}", scmTag); scmHolder.url = scmTag; Model.scm = scmHolder; } // Add Com Reference Dependencies if (projectDigest.ComReferenceList.Length > 0) { AddComReferenceDependency(); } //Add Project WebReferences AddWebReferences(); //Add EmbeddedResources maven-resgen-plugin AddEmbeddedResources(); // Add Project Inter-dependencies foreach (ProjectReference projectRef in projectDigest.ProjectReferences) { AddProjectReference(projectRef); } // Add Project Reference Dependencies // override the one from the parent to add new types for Azure AddProjectReferenceDependenciesToList(true); Plugin plugin = AddPlugin("org.apache.npanday.plugins", "azure-maven-plugin"); if (!string.IsNullOrEmpty(projectDigest.TargetFramework)) { AddPluginConfiguration(plugin, "frameworkVersion", projectDigest.TargetFramework); } else { // TODO: crude hack until the plugin doesn't require this and picks the right minimum default AddPluginConfiguration(plugin, "frameworkVersion", "4.0"); } if (!string.IsNullOrEmpty(projectDigest.ProductVersion) && projectDigest.ProductVersion != "1.6") { AddPluginConfiguration(plugin, "executableVersion", projectDigest.ProductVersion); } if (!string.IsNullOrEmpty(projectDigest.CloudConfig)) { AddPluginConfiguration(plugin, "serviceConfigurationFile", projectDigest.CloudConfig); } Dictionary <string, string> extraRoleContent = new Dictionary <string, string>(); foreach (Content content in projectDigest.Contents) { Regex r = new Regex(@"(\w+)Content\\(.+)"); Match m = r.Match(content.IncludePath); if (m.Success) { string role = m.Groups[1].Value; string include = m.Groups[2].Value; if (extraRoleContent.ContainsKey(role)) { extraRoleContent[role] = extraRoleContent[role] + "," + include; } else { extraRoleContent.Add(role, include); } } else { log.WarnFormat("Not copying content declared in project from an unknown path: {0}", content.IncludePath); } } if (extraRoleContent.Count > 0) { Plugin antPlugin = AddPlugin("org.apache.maven.plugins", "maven-antrun-plugin", null, false); Dictionary <string, string> configuration = new Dictionary <string, string>(); AddPluginExecution(antPlugin, "copy-files", new string[] { "run" }, "prepare-package"); XmlDocument xmlDocument = new XmlDocument(); string xmlns = @"http://maven.apache.org/POM/4.0.0"; XmlElement tasks = xmlDocument.CreateElement("tasks", xmlns); foreach (string role in extraRoleContent.Keys) { XmlElement copyTask = xmlDocument.CreateElement("copy", xmlns); copyTask.SetAttribute("todir", @"${project.build.directory}/packages/" + projectDigest.ProjectName + "/" + role); XmlElement fileset = xmlDocument.CreateElement("fileset", xmlns); fileset.SetAttribute("dir", role + "Content"); fileset.SetAttribute("includes", extraRoleContent[role]); copyTask.AppendChild(fileset); tasks.AppendChild(copyTask); } PluginExecutionConfiguration config = new PluginExecutionConfiguration(); config.Any = new XmlElement[] { tasks }; antPlugin.executions[0].configuration = config; } if (writePom) { PomHelperUtility.WriteModelToPom(new FileInfo(Path.Combine(projectDigest.FullDirectoryName, "pom.xml")), Model); } }
public override void ConvertProjectToPomModel(bool writePom, string scmTag) { // relies on this being set everywhere - if it were set per project, this would need to be evaluated on the project references if (!projectDigest.UseMsDeploy) { throw new Exception("You must use Web Deploy 2.0 to package web applications when using Azure projects"); } GenerateHeader("azure-cloud-service"); //Add SCM Tag if (scmTag != null && scmTag != string.Empty && Model.parent==null) { Scm scmHolder = new Scm(); scmHolder.connection = string.Format("scm:svn:{0}", scmTag); scmHolder.developerConnection = string.Format("scm:svn:{0}", scmTag); scmHolder.url = scmTag; Model.scm = scmHolder; } // Add Com Reference Dependencies if (projectDigest.ComReferenceList.Length > 0) { AddComReferenceDependency(); } //Add Project WebReferences AddWebReferences(); //Add EmbeddedResources maven-resgen-plugin AddEmbeddedResources(); // Add Project Inter-dependencies foreach (ProjectReference projectRef in projectDigest.ProjectReferences) { AddProjectReference(projectRef); } // Add Project Reference Dependencies // override the one from the parent to add new types for Azure AddProjectReferenceDependenciesToList(true); Plugin plugin = AddPlugin("org.apache.npanday.plugins", "azure-maven-plugin"); if (!string.IsNullOrEmpty(projectDigest.TargetFramework)) AddPluginConfiguration(plugin, "frameworkVersion", projectDigest.TargetFramework); else { // TODO: crude hack until the plugin doesn't require this and picks the right minimum default AddPluginConfiguration(plugin, "frameworkVersion", "4.0"); } if (!string.IsNullOrEmpty(projectDigest.ProductVersion) && projectDigest.ProductVersion != "1.6") AddPluginConfiguration(plugin, "executableVersion", projectDigest.ProductVersion); if (!string.IsNullOrEmpty(projectDigest.CloudConfig)) { AddPluginConfiguration(plugin, "serviceConfigurationFile", projectDigest.CloudConfig); } Dictionary<string, string> extraRoleContent = new Dictionary<string,string>(); foreach (Content content in projectDigest.Contents) { Regex r = new Regex(@"(\w+)Content\\(.+)"); Match m = r.Match(content.IncludePath); if (m.Success) { string role = m.Groups[1].Value; string include = m.Groups[2].Value; if (extraRoleContent.ContainsKey(role)) { extraRoleContent[role] = extraRoleContent[role] + "," + include; } else { extraRoleContent.Add(role, include); } } else { log.WarnFormat("Not copying content declared in project from an unknown path: {0}", content.IncludePath); } } if (extraRoleContent.Count > 0) { Plugin antPlugin = AddPlugin("org.apache.maven.plugins", "maven-antrun-plugin", null, false); Dictionary<string, string> configuration = new Dictionary<string, string>(); AddPluginExecution(antPlugin, "copy-files", new string[] { "run" }, "prepare-package"); XmlDocument xmlDocument = new XmlDocument(); string xmlns = @"http://maven.apache.org/POM/4.0.0"; XmlElement tasks = xmlDocument.CreateElement("tasks", xmlns); foreach (string role in extraRoleContent.Keys) { XmlElement copyTask = xmlDocument.CreateElement("copy", xmlns); copyTask.SetAttribute("todir", @"${project.build.directory}/packages/" + projectDigest.ProjectName + "/" + role); XmlElement fileset = xmlDocument.CreateElement("fileset", xmlns); fileset.SetAttribute("dir", role + "Content"); fileset.SetAttribute("includes", extraRoleContent[role]); copyTask.AppendChild(fileset); tasks.AppendChild(copyTask); } PluginExecutionConfiguration config = new PluginExecutionConfiguration(); config.Any = new XmlElement[] { tasks }; antPlugin.executions[0].configuration = config; } if (writePom) { PomHelperUtility.WriteModelToPom(new FileInfo(Path.Combine(projectDigest.FullDirectoryName, "pom.xml")), Model); } }
protected void AddPluginExecution(Plugin plugin, string id, string[] goals, string phase, Dictionary<string,string> configuration) { if (goals.Length == 0) throw new Exception("Plugin execution must contain goals"); List<PluginExecution> list = new List<PluginExecution>(); if (plugin.executions == null) { plugin.executions = new List<PluginExecution>().ToArray(); list.AddRange(plugin.executions); } PluginExecution exe = new PluginExecution(); exe.id = id; exe.goals = goals; exe.phase = phase; if (configuration != null) { PluginExecutionConfiguration config = new PluginExecutionConfiguration(); List<XmlElement> elems = new List<XmlElement>(); XmlDocument xmlDocument = new XmlDocument(); foreach (string key in configuration.Keys) { XmlElement elem = xmlDocument.CreateElement(key, @"http://maven.apache.org/POM/4.0.0"); elem.InnerText = configuration[key]; elems.Add(elem); } config.Any = elems.ToArray(); exe.configuration = config; } list.Add(exe); plugin.executions = list.ToArray(); }