static bool IsProjectAnIntegrationTest(NPanday.Model.Pom.Model model) { Plugin plugin = PomHelperUtility.FindPlugin( model, "org.apache.npanday.plugins", "maven-test-plugin" ); if (plugin == null) { return false; } foreach (XmlElement elem in (ICollection<XmlElement>)plugin.configuration.Any) { if ("integrationTest".Equals(elem.Name)) { if(string.IsNullOrEmpty(elem.InnerText)) { return false; } return "true".Equals(elem.InnerText.Trim(), StringComparison.OrdinalIgnoreCase); } } return false; }
public Artifact GetArtifactFor(NPanday.Model.Pom.Model model) { Artifact artifact = new Artifact(); artifact.ArtifactId = model.artifactId; artifact.GroupId = model.groupId; artifact.Version = model.version; artifact.Extension = GetExtensionFor(model.packaging); return artifact; }
public Artifact GetArtifact(NPanday.Model.Pom.Dependency dependency) { Artifact artifact = new Artifact(); artifact.ArtifactId = dependency.artifactId; artifact.GroupId = dependency.groupId; artifact.Version = dependency.version; artifact.FileInfo = new FileInfo(GetLocalRepositoryPath(artifact, ".dll")); return artifact; }
public string[] GenerateChildPoms(ProjectDigest[] prjDigests, string groupId, string parentPomFilename, NPanday.Model.Pom.Model parentPomModel, bool writePom, string scmTag, List<Reference> missingReferences, List<string> nonPortableReferences) { List<string> generatedPoms = new List<string>(); // make the child pom NPanday.Model.Pom.Model[] models = PomConverter.ConvertProjectsToPomModels(prjDigests, parentPomFilename, parentPomModel, groupId, writePom, scmTag, missingReferences, nonPortableReferences); if (models != null && models.Length > 0) { foreach (ProjectDigest prj in prjDigests) { string fileDir = Path.GetDirectoryName(prj.FullFileName); string pomFile = Path.GetFullPath(fileDir + @"\pom.xml"); generatedPoms.Add(pomFile); } } return generatedPoms.ToArray(); }
public AbstractPomConverter(ProjectDigest projectDigest, string mainPomFile, NPanday.Model.Pom.Model parent, string groupId) { artifactContext = new ArtifactContext(); this.projectDigest = projectDigest; this.mainPomFile = mainPomFile; this.parent = parent; this.groupId = FilterID(groupId); this.version = parent != null ? parent.version : null; this.rspUtil = new RspUtility(); this.model = new NPanday.Model.Pom.Model(); // Add build Tag this.model.build = new NPanday.Model.Pom.Build(); this.missingReferences = new List<Reference>(); this.nonPortableReferences = new List<string>(); // TODO: this is a hack because of bad design. The things that talk to the local repository should be pulled out of here, and able to be stubbed/mocked instead if (testingArtifacts != null) { this.localArtifacts = testingArtifacts; } }
Plugin addPlugin(NPanday.Model.Pom.Model model, string groupId, string artifactId, string version, bool extensions) { List<NPanday.Model.Pom.Plugin> plugins = new List<NPanday.Model.Pom.Plugin>(); if (model.build.plugins != null) { plugins.AddRange(model.build.plugins); } // Add NPanday compile plugin NPanday.Model.Pom.Plugin plugin = new NPanday.Model.Pom.Plugin(); plugin.groupId = groupId; plugin.artifactId = artifactId; plugin.version = version; plugin.extensions = extensions; plugins.Add(plugin); model.build.plugins = plugins.ToArray(); return plugin; }
private static string GetSnapshotVersion(NPanday.Artifact.Artifact artifact, string repo) { WebClient client = new WebClient(); string timeStampVersion = null; string metadataPath = repo + "/" + artifact.GroupId.Replace('.', '/') + "/" + artifact.ArtifactId; string snapshot = "<snapshot>"; string metadata = "/maven-metadata.xml"; try { metadataPath = metadataPath + "/" + artifact.Version + metadata; string content = client.DownloadString(metadataPath); string[] lines = content.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); string timeStamp = null; string buildNumber = null; foreach (string line in lines) { int startIndex; int len; if (line.Contains("<timestamp>")) { startIndex = line.IndexOf("<timestamp>") + "<timestamp>".Length; len = line.IndexOf("</timestamp>") - startIndex; timeStamp = line.Substring(startIndex, len); } if (line.Contains("<buildNumber>")) { startIndex = line.IndexOf("<buildNumber>") + "<buildNumber>".Length; len = line.IndexOf("</buildNumber>") - startIndex; buildNumber = line.Substring(startIndex, len); } } if (timeStamp == null) { log.Warn("Timestamp was not specified in maven-metadata.xml - using default snapshot version"); return null; } if (buildNumber == null) { log.Warn("Build number was not specified in maven-metadata.xml - using default snapshot version"); return null; } log.Info("Resolved SNAPSHOT: Timestamp = " + timeStamp + "; Build Number = " + buildNumber); timeStampVersion = timeStamp + "-" + buildNumber; } catch (Exception e) { return null; } finally { client.Dispose(); } return timeStampVersion; }
public AzurePomConverter(ProjectDigest projectDigest, string mainPomFile, NPanday.Model.Pom.Model parent, string groupId) : base(projectDigest,mainPomFile,parent, groupId) { }
public bool IsPomDependency(NPanday.Model.Pom.Dependency dependency) { return IsPomDependency(dependency.groupId, dependency.artifactId, dependency.version); }
public bool isWebRefExistingInPom(string path, NPanday.Model.Pom.Model model) { bool exists = false; List<NPanday.Model.Pom.Plugin> plugins = new List<NPanday.Model.Pom.Plugin>(); if (model.build.plugins != null) { foreach (Plugin item in model.build.plugins) { if (item.artifactId.Equals("maven-wsdl-plugin") && item.configuration != null) { List<XmlElement> elems = new List<XmlElement>(); elems.AddRange(item.configuration.Any); XmlElement elem = getWebReferencesElement(elems.ToArray(), "webreferences"); if (elem.InnerXml.Contains(path.Replace("\\", "/"))) { exists = true; } } } } return exists; }
private string GetFileName(NPanday.Model.Pom.Dependency dependency) { RegistryKey root = Registry.ClassesRoot; string filename = string.Empty; try { String[] classTokens = dependency.classifier.Split("}".ToCharArray()); String[] versionTokens = classTokens[1].Split("-".ToCharArray()); classTokens[1] = classTokens[1].Replace("-", "\\"); String newClassifier = classTokens[0] + "}" + classTokens[1]; RegistryKey typeLib = root.OpenSubKey("TypeLib"); RegistryKey target = typeLib.OpenSubKey(classTokens[0] + "}").OpenSubKey(versionTokens[1]).OpenSubKey(versionTokens[2]).OpenSubKey("win32"); filename = target.GetValue("").ToString(); } catch (Exception exe) { Console.WriteLine(exe.Message); } return filename; }
private bool IsIntraProject(NPanday.Model.Pom.Model m, Dependency d) { string pomGroupId = (m.parent != null) ? m.parent.groupId : m.groupId; if (d.groupId == pomGroupId) { // loop through VS projects (instead of modules in parent POM) because // we need real-time list of project names in the solution foreach (Project project in solution.Projects) { if (d.artifactId == project.Name) { return true; } } } return false; }
public static NPanday.Model.Pom.Model ConvertProjectToPomModel(ProjectDigest projectDigest, string mainPomFile, NPanday.Model.Pom.Model parent, string groupId, bool writePom, string scmTag, List<Reference> missingReferences, List<string> nonPortableReferences) { if (!__converterAlgorithms.ContainsKey(projectDigest.ProjectType)) { throw new NotSupportedException("Unsupported project type: " + projectDigest.ProjectType); } else { // fudge the project type - though overall this would be better with "capabilities" or some filters instead if ((projectDigest.ProjectType & VisualStudioProjectTypeEnum.Web_Application) != 0 && projectDigest.UseMsDeploy) { projectDigest.ProjectType |= VisualStudioProjectTypeEnum.WebDeploy2; } if (projectDigest.RoleType != null && projectDigest.RoleType.Equals("Worker", StringComparison.InvariantCultureIgnoreCase)) { projectDigest.ProjectType |= VisualStudioProjectTypeEnum.WindowsAzure_Worker; } IPomConverter converter = (IPomConverter)System.Activator.CreateInstance( __converterAlgorithms[projectDigest.ProjectType], projectDigest, mainPomFile, parent, groupId); converter.ConvertProjectToPomModel(scmTag); missingReferences.AddRange(converter.GetMissingReferences()); foreach (string s in converter.GetNonPortableReferences()) { if (!nonPortableReferences.Contains(s)) nonPortableReferences.Add(s); } return converter.Model; } }
protected void ParseProjectReferences(Dictionary<string, object> dictionary, NPanday.ProjectImporter.Parser.SlnParser.Model.Project project, NPanday.ProjectImporter.Parser.SlnParser.Model.Solution solution) { if (project.ProjectSections != null) { List<Microsoft.Build.BuildEngine.Project> projectReferenceList = new List<Microsoft.Build.BuildEngine.Project>(); foreach (ProjectSection ps in project.ProjectSections) { if ("WebsiteProperties".Equals(ps.Name)) { // ProjectReferences = "{11F2FCC8-5941-418A-A0E7-42D250BA9D21}|SampleInterProject111.dll;{9F37BA7B-06F9-4B05-925D-B5BC16322E8B}|BongClassLib.dll;" try { Regex regex = new Regex(PROJECT_REFERENCE_REGEX, RegexOptions.Multiline | RegexOptions.IgnoreCase); MatchCollection matches = regex.Matches(ps.Map["ProjectReferences"]); foreach (Match match in matches) { string projectReferenceGUID = match.Groups["ProjectReferenceGUID"].ToString(); string projectReferenceDll = match.Groups["ProjectReferenceDll"].ToString(); Microsoft.Build.BuildEngine.Project prj = GetMSBuildProject(solution, projectReferenceGUID); if (prj != null) { projectReferenceList.Add(prj); } } } catch { } } else if("ProjectDependencies".Equals(ps.Name)) { //{0D80BE11-F1CE-409E-B9AC-039D3801209F} = {0D80BE11-F1CE-409E-B9AC-039D3801209F} foreach (string key in ps.Map.Keys) { Microsoft.Build.BuildEngine.Project prj = GetMSBuildProject(solution, key.Replace("{","").Replace("}", "")); if (prj != null) { projectReferenceList.Add(prj); } } } } dictionary.Add("InterProjectReferences", projectReferenceList.ToArray()); } }
public void WriteModelToPom(NPanday.Model.Pom.Model model) { PomHelperUtility.WriteModelToPom(this.pom, model); }
public void RemovePomDependency(NPanday.Model.Pom.Dependency dependency) { RemovePomDependency(dependency.groupId, dependency.artifactId, dependency.version); }
Microsoft.Build.BuildEngine.Project GetMSBuildProject(NPanday.ProjectImporter.Parser.SlnParser.Model.Solution solution, string projectGuid) { foreach (NPanday.ProjectImporter.Parser.SlnParser.Model.Project p in solution.Projects) { if (p.ProjectGUID.Equals("{" + projectGuid + "}", StringComparison.OrdinalIgnoreCase)) { string projectReferenceName = p.ProjectName; string projectReferencePath = p.ProjectPath; string projectReferenceFullPath = null; if (Path.IsPathRooted(projectReferencePath)) { projectReferenceFullPath = Path.GetFullPath(projectReferencePath); } else { projectReferenceFullPath = Path.Combine(solution.File.Directory.FullName, projectReferencePath); } Microsoft.Build.BuildEngine.Project prj = new Microsoft.Build.BuildEngine.Project(BUILD_ENGINE); try { // TODO: if we update to a .NET 3.5 minimum we can pass in ProjectLoadSettings.IgnoreMissingImports prj.Load(projectReferenceFullPath); } catch (Exception e) { log.Error("Unable to load project reference from " + projectReferenceFullPath, e); } return prj; } } return null; }
public static NPanday.Model.Pom.Model[] ConvertProjectsToPomModels(ProjectDigest[] projectDigests, string mainPomFile, NPanday.Model.Pom.Model parent, string groupId, bool writePoms, string scmTag, List<Reference> missingReferences, List<string> nonPortableReferences) { try { string version = parent != null ? parent.version : null; List<NPanday.Model.Pom.Model> models = new List<NPanday.Model.Pom.Model>(); foreach (ProjectDigest projectDigest in projectDigests) { NPanday.Model.Pom.Model model = ConvertProjectToPomModel(projectDigest, mainPomFile, parent, groupId, writePoms, scmTag, missingReferences, nonPortableReferences); models.Add(model); } return models.ToArray(); } catch { throw; } }
public static Plugin FindPlugin(NPanday.Model.Pom.Model model, string groupId, string artifactId) { if (model.build.plugins == null) { return null; } foreach (Plugin plugin in model.build.plugins) { if (groupId.ToLower().Equals(plugin.groupId.ToLower(), StringComparison.InvariantCultureIgnoreCase) && artifactId.ToLower().Equals(plugin.artifactId.ToLower(), StringComparison.InvariantCultureIgnoreCase)) { return plugin; } } return null; }
public void SystemInstall(NPanday.Model.Pom.Dependency dependency) { try { if (dependency.systemPath == null || dependency.systemPath == string.Empty) { Assembly a = System.Reflection.Assembly.LoadWithPartialName(dependency.artifactId); dependency.systemPath = a.Location; } string sourceFile = dependency.systemPath; sourceFile = sourceFile.Replace("\\", "/"); string directory = localRepository.Replace("\\", "/"); //Creating of Directories directory = directory + "/" + dependency.groupId; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } directory = directory + "/" + dependency.artifactId; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } directory = directory + "/" + dependency.version; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } string newDll = dependency.artifactId + "-" + dependency.version + "-" + dependency.classifier + "." + dependency.type; string destinationFile = localRepository + "\\" + dependency.groupId + "\\" + dependency.artifactId + "\\" + dependency.version + "\\" + newDll; destinationFile = destinationFile.Replace("\\", "/"); if (!File.Exists(destinationFile)) { File.Copy(sourceFile, destinationFile); } } catch (Exception exe) { Console.WriteLine(exe.Message); } }
public static void WriteModelToPom(FileInfo pomFile, NPanday.Model.Pom.Model model) { if (!pomFile.Directory.Exists) { pomFile.Directory.Create(); } TextWriter writer = null; XmlSerializer serializer = null; try { writer = new StreamWriter(pomFile.FullName); serializer = new XmlSerializer(typeof(NPanday.Model.Pom.Model)); serializer.Serialize(writer, model); } catch { throw; } finally { try { if (writer != null) { writer.Close(); writer.Dispose(); } } catch { log.Warn("Failed to close stream writer after writing to pom.xml."); } } }
private void LocalInstall(NPanday.Model.Pom.Dependency dependency, string fileName) { try { String[] rawName = GetFileName(dependency).Split("\\".ToCharArray()); string generatedDLL = rawName[rawName.Length - 1]; generatedDLL = generatedDLL.Replace("tlb", "dll"); string directory = localRepository.Replace("\\", "/"); //Creating of Directories directory = directory + "/" + dependency.groupId; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } directory = directory + "/" + dependency.artifactId; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } directory = directory + "/" + dependency.version; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } string newDll = dependency.artifactId + "-" + dependency.version + "-" + dependency.classifier + "." + dependency.type; string destinationFile = localRepository + "\\" + dependency.groupId + "\\" + dependency.artifactId + "\\" + dependency.version + "\\" + newDll; destinationFile = destinationFile.Replace("\\", "/"); string tempDir = "c:/Windows/Temp/NPanday"; if (!Directory.Exists(tempDir)) { Directory.CreateDirectory(tempDir); } fileName = "\"" + fileName + "\""; fileName = fileName + " /out:" + tempDir + "/" + dependency.artifactId+".dll"; GenerateDependency(fileName); string sourceFile = tempDir + "/" + dependency.artifactId + ".dll"; bool waiting = true; while (waiting) { if (File.Exists(sourceFile)) { waiting = false; } } if (!File.Exists(destinationFile)) { System.Threading.Thread.Sleep(4500); File.Copy(sourceFile, destinationFile); } } catch (Exception exe) { Console.WriteLine("[ERROR] The Reference is not located.\n"+exe.Message); } }
public void AddPomDependency(NPanday.Model.Pom.Dependency dependency) { if ("vb".Equals(NPandayCompilerPluginLanguage)) { if (rspUtil.IsVbcRspIncluded(dependency.artifactId)) return; } else { if (rspUtil.IsCscRspIncluded((dependency.artifactId))) return; } if (IsPomDependency(dependency)) { throw new Exception(string.Format( "Error in Adding Artifact Dependency [groupId: {0}, artifactId:{1}, version:{2}], \nDependency already exists in the Pom dependencies", dependency.groupId, dependency.artifactId, dependency.version)); } NPanday.Model.Pom.Model model = ReadPomAsModel(); List<Dependency> dependencies = new List<Dependency>(); if (model.dependencies != null) { dependencies.AddRange(model.dependencies); } dependencies.Add(dependency); model.dependencies = dependencies.ToArray(); WriteModelToPom(model); }