public virtual PackageReference RetrievePomContent(PackageReference pr, MavenDownloader.Options options, Func <PackageReference, string> getPomSavedPath) { options = options ?? new MavenDownloader.Options(); var pomUrl = BuildDownloadUrl(pr, PomComponentKind.PomXml); options.LogMessage("Downloading pom: " + pomUrl); getPomSavedPath = getPomSavedPath ?? (_pr => MavenDownloader.BuildLocalCachePath(options.OutputPath, _pr, PomComponentKind.PomXml)); var pomSavedPath = getPomSavedPath(pr); if (pomSavedPath != null && !Directory.Exists(Path.GetDirectoryName(pomSavedPath))) { Directory.CreateDirectory(Path.GetDirectoryName(pomSavedPath)); } var ms = Download(pomUrl); if (pomSavedPath != null) { using (var pomFile = File.Create(pomSavedPath)) ms.CopyTo(pomFile); ms.Position = 0; } var pom = XElement.Load(ms); return(PackageReference.Load(pom)); }
public static LocalMavenDownloads PopulateFromDirectory(string directory) { var ret = new LocalMavenDownloads(); foreach (var groupDir in new DirectoryInfo(directory).GetDirectories()) { foreach (var artifactDir in groupDir.GetDirectories()) { foreach (var versionDir in artifactDir.GetDirectories()) { var pomFile = Path.Combine(versionDir.FullName, $"{artifactDir.Name}-{versionDir.Name}.pom"); var pr = PackageReference.Load(XElement.Load(pomFile)); ret.Entries.Add(new Entry(pr, PomComponentKind.PomXml, pomFile)); foreach (var jar in versionDir.GetFiles("*.jar")) { if (jar.Name.EndsWith("-sources.jar", StringComparison.OrdinalIgnoreCase)) { ret.Entries.Add(new Entry(pr, PomComponentKind.SourcesJar, jar.FullName)); } if (jar.Name.EndsWith("-javadoc.jar", StringComparison.OrdinalIgnoreCase)) { ret.Entries.Add(new Entry(pr, PomComponentKind.JavadocJar, jar.FullName)); } else { ret.Entries.Add(new Entry(pr, PomComponentKind.Binary, jar.FullName)); } } } } } return(ret); }