public Package ScanPackageDirectory(string directory) { try { var headerPath = Path.Combine(directory, "pkg.json"); Package discoveredPkg; // get the package name and the installed version if (File.Exists(headerPath)) { discoveredPkg = Package.FromJson(headerPath, AsLogger()); if (discoveredPkg == null) { throw new Exception(String.Format(Properties.Resources.MalformedHeaderPackage, headerPath)); } } else { throw new Exception(String.Format(Properties.Resources.NoHeaderPackage, headerPath)); } // prevent duplicates if (LocalPackages.All(pkg => pkg.Name != discoveredPkg.Name)) { this.Add(discoveredPkg); return(discoveredPkg); // success } throw new Exception(String.Format(Properties.Resources.DulicatedPackage, discoveredPkg.Name, discoveredPkg.RootDirectory)); } catch (Exception e) { Log(String.Format(Properties.Resources.ExceptionEncountered, directory), WarningLevel.Error); Log(e); } return(null); }
/// <summary> /// This method is called when custom nodes and packages need to be reloaded if there are new package paths. /// </summary> /// <param name="newPaths"></param> /// <param name="preferences"></param> /// <param name="customNodeManager"></param> public void LoadCustomNodesAndPackages(IEnumerable <string> newPaths, IPreferences preferences, CustomNodeManager customNodeManager) { foreach (var path in preferences.CustomPackageFolders) { // Append the definitions subdirectory for custom nodes. var dir = path == DynamoModel.BuiltInPackagesToken ? PathManager.BuiltinPackagesDirectory : path; dir = TransformPath(dir, PathManager.DefinitionsDirectoryName); customNodeManager.AddUninitializedCustomNodesInPath(dir, false, false); } foreach (var path in newPaths) { var packageDirectory = pathManager.PackagesDirectories.FirstOrDefault(x => x.StartsWith(path)); if (packageDirectory != null) { ScanPackageDirectories(packageDirectory, preferences); } } if (pathManager != null) { foreach (var pkg in LocalPackages) { if (Directory.Exists(pkg.BinaryDirectory)) { pathManager.AddResolutionPath(pkg.BinaryDirectory); } } } if (LocalPackages.Any()) { // Load only those recently addeed local packages (that are located in any of the new paths) var newPackages = LocalPackages.Where(x => newPaths.Any(y => x.RootDirectory.Contains(y))); LoadPackages(newPackages); } }
public async Task <bool> Execute() { Reports = Options.Reports; LocalPackages = Options.SourcePackages ?? NuGetDependencyResolver.ResolveRepositoryPath(Directory.GetCurrentDirectory()); Options.Reports.Quiet.WriteLine(string.Format("Adding NuGet package {0} to {1}", Options.NuGetPackage.Bold(), LocalPackages.Bold())); var sw = new Stopwatch(); sw.Start(); var library = NuGetPackageUtils.CreateLibraryFromNupkg(Options.NuGetPackage); using (var stream = File.OpenRead(Options.NuGetPackage)) { string packageHash = null; if (!string.IsNullOrEmpty(Options.PackageHashFilePath) && File.Exists(Options.PackageHashFilePath)) { packageHash = File.ReadAllText(Options.PackageHashFilePath); } else if (!string.IsNullOrEmpty(Options.PackageHash)) { packageHash = Options.PackageHash; } await NuGetPackageUtils.InstallFromStream(stream, library, LocalPackages, Reports.Quiet, packageHash); } Reports.Quiet.WriteLine( "{0}, {1}ms elapsed", "Add complete".Green().Bold(), sw.ElapsedMilliseconds); return(true); }
public Package GetOwnerPackage(string path) { return(LocalPackages.FirstOrDefault(ele => ele.ContainsFile(path))); }
public Package GetOwnerPackage(Type t) { return(LocalPackages.FirstOrDefault(package => package.LoadedTypes.Contains(t))); }
public Package GetPackageFromRoot(string path) { return(LocalPackages.FirstOrDefault(pkg => pkg.RootDirectory == path)); }
public bool IsUnderPackageControl(Assembly t) { return(LocalPackages.Any(package => package.LoadedAssemblies.Any(x => x.Assembly == t))); }
public bool IsUnderPackageControl(Type t) { return(LocalPackages.Any(package => package.LoadedTypes.Contains(t))); }
public bool IsUnderPackageControl(string path) { return(LocalPackages.Any(ele => ele.ContainsFile(path))); }
public Package ScanPackageDirectory(string directory, bool checkCertificates) { try { var headerPath = Path.Combine(directory, "pkg.json"); Package discoveredPackage; // get the package name and the installed version if (PathHelper.IsValidPath(headerPath)) { discoveredPackage = Package.FromJson(headerPath, AsLogger()); if (discoveredPackage == null) { throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.MalformedHeaderPackage, headerPath)); } } else { throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.NoHeaderPackage, headerPath)); } // prevent loading unsigned packages if the certificates are required on package dlls if (checkCertificates) { CheckPackageNodeLibraryCertificates(directory, discoveredPackage); } var discoveredVersion = CheckAndGetPackageVersion(discoveredPackage.VersionName, discoveredPackage.Name, discoveredPackage.RootDirectory); var existingPackage = LocalPackages.FirstOrDefault(package => (package.Name == discoveredPackage.Name) && (package.LoadState.State != PackageLoadState.StateTypes.Unloaded)); // Is this a new package? if (existingPackage == null) { Add(discoveredPackage); return(discoveredPackage); // success } // Conflict invloving a built-in package if (discoveredPackage.BuiltInPackage || existingPackage.BuiltInPackage) { // We show both packages but we mark the new one as unloaded. discoveredPackage.LoadState.SetAsUnloaded(); Add(discoveredPackage); } var existingVersion = CheckAndGetPackageVersion(existingPackage.VersionName, existingPackage.Name, existingPackage.RootDirectory); // Is this a duplicated package? if (existingVersion == discoveredVersion) { // Duplicated with the same version throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.DulicatedPackage, discoveredPackage.Name, discoveredPackage.RootDirectory)); } // Is the existing version newer? if (existingVersion > discoveredVersion) { // Older version found, show notification throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.DuplicatedOlderPackage, existingPackage.Name, discoveredPackage.RootDirectory, existingVersion.ToString(), discoveredVersion.ToString())); } // Newer version found, show notification. throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.DuplicatedNewerPackage, existingPackage.Name, discoveredPackage.RootDirectory, existingVersion.ToString(), discoveredVersion.ToString())); } catch (Exception e) { Log(String.Format(Properties.Resources.ExceptionEncountered, directory), WarningLevel.Error); Log(e); } return(null); }
public bool Execute() { Reports = Options.Reports; LocalPackages = Options.SourcePackages ?? Directory.GetCurrentDirectory(); Options.Reports.Information.WriteLine(string.Format("Committing artifacts in {0}", LocalPackages.Bold())); var sw = new Stopwatch(); sw.Start(); var local = new FileSystemRepositoryPublisher(LocalPackages) { Reports = Reports }; // Read entire index starting with 1 var index = local.MergeRepositoryChangeRecordsStartingWithIndex(1); if (index == null) { // no index at all - provide a fake "empty before 1" record index = new RepositoryChangeRecord { Next = 1, Add = new string[0], Remove = new string[0], }; } // Read file system var artifacts = local.EnumerateArtifacts(FolderPredicate, FilePredicate); // Determine difference of index and file system var record = new RepositoryChangeRecord { Next = index.Next + 1, Add = artifacts.Except(index.Add).ToArray(), Remove = index.Add.Except(artifacts).ToArray() }; // Create new index entry if not empty if (record.Add.Any() || record.Remove.Any()) { Reports.Information.WriteLine( "Creating record #{0}, {1} artifacts added, {2} artifacts removed", index.Next, record.Add.Count(), record.Remove.Count()); local.ApplyFileChanges(record); local.StoreRepositoryChangeRecord(index.Next, record); } Reports.Information.WriteLine( "{0}, {1}ms elapsed", "Commit complete".Green().Bold(), sw.ElapsedMilliseconds); return(true); }
public bool Execute() { Reports = Options.Reports; LocalPackages = Options.SourcePackages ?? Directory.GetCurrentDirectory(); RemotePackages = Options.RemotePackages; Options.Reports.Information.WriteLine( "Pushing artifacts"); Options.Reports.Information.WriteLine( " from {0}", LocalPackages.Bold()); Options.Reports.Information.WriteLine( " to {0}", RemotePackages.Bold()); var sw = new Stopwatch(); sw.Start(); IRepositoryPublisher local = new FileSystemRepositoryPublisher( LocalPackages); IRepositoryPublisher remote = RepositoryPublishers.Create( RemotePackages, Reports); // Recall what index to start pushing to remote var transmitRecord = FillOut(local.GetRepositoryTransmitRecord()); int nextIndex; if (!transmitRecord.Push.TryGetValue(RemotePackages, out nextIndex)) { nextIndex = 1; } // Read change index from that point forward var changeRecord = FillOut(local.MergeRepositoryChangeRecordsStartingWithIndex(nextIndex)); if (!changeRecord.Add.Any() && !changeRecord.Remove.Any()) { Reports.Information.WriteLine("There are no changes to push"); } else { Reports.Information.WriteLine( "Pushing {0} added and {1} removed artifacts", changeRecord.Add.Count().ToString().Bold(), changeRecord.Remove.Count().ToString().Bold()); // We now know where to start from next time transmitRecord.Push[RemotePackages] = changeRecord.Next; // Determine the latest remote change number var remoteZeroRecord = FillOut(remote.GetRepositoryChangeRecord(0)); var remoteIndexNext = remoteZeroRecord.Next; // Point remote records to point to the following remote change number changeRecord.Next = remoteIndexNext + 1; remoteZeroRecord.Next = remoteIndexNext + 1; // Apply the file changes to remote remote.ApplyFileChanges(changeRecord, local); // Correct /{id}/{version}/$index.json files based on file changes // Commit new change record to remote remote.StoreRepositoryChangeRecord(0, remoteZeroRecord); remote.StoreRepositoryChangeRecord(remoteIndexNext, changeRecord); // Locally commit where to push remotely next local.StoreRepositoryTransmitRecord(transmitRecord); } Reports.Information.WriteLine( "{0}, {1}ms elapsed", "Push complete".Green().Bold(), sw.ElapsedMilliseconds); return(true); }
/// <summary> /// Saves all packages and assets. /// </summary> /// <param name="log">The <see cref="LoggerResult"/> in which to report result.</param> public void Save(LoggerResult log) { bool packagesSaved = false; //var clock = Stopwatch.StartNew(); using (var profile = Profiler.Begin(PackageSessionProfilingKeys.Saving)) { try { // Grab all previous assets var previousAssets = new Dictionary <Guid, AssetItem>(); foreach (var assetItem in packagesCopy.SelectMany(package => package.Assets)) { previousAssets[assetItem.Id] = assetItem; } // Grab all new assets var newAssets = new Dictionary <Guid, AssetItem>(); foreach (var assetItem in LocalPackages.SelectMany(package => package.Assets)) { newAssets[assetItem.Id] = assetItem; } // Compute all assets that were removed var assetsOrPackagesToRemove = new Dictionary <UFile, object>(); foreach (var assetIt in previousAssets) { var asset = assetIt.Value; AssetItem newAsset; if (!newAssets.TryGetValue(assetIt.Key, out newAsset) || newAsset.Location != asset.Location) { assetsOrPackagesToRemove[asset.FullPath] = asset; } } // Compute packages that have been renamed // TODO: Disable for now, as not sure if we want to delete a previous package //foreach (var package in packagesCopy) //{ // var newPackage = packages.Find(package.Id); // if (newPackage != null && package.PackagePath != null && newPackage.PackagePath != package.PackagePath) // { // assetsOrPackagesToRemove[package.PackagePath] = package; // } //} // If package are not modified, return immediately if (!CheckModifiedPackages() && assetsOrPackagesToRemove.Count == 0) { return; } // Suspend tracking when saving as we don't want to receive // all notification events if (dependencies != null) { dependencies.BeginSavingSession(); } // Return immediately if there is any error if (log.HasErrors) { return; } // Delete previous files foreach (var fileIt in assetsOrPackagesToRemove) { var assetPath = fileIt.Key; var assetItemOrPackage = fileIt.Value; if (File.Exists(assetPath)) { try { File.Delete(assetPath); } catch (Exception ex) { var assetItem = assetItemOrPackage as AssetItem; if (assetItem != null) { log.Error(assetItem.Package, assetItem.ToReference(), AssetMessageCode.AssetCannotDelete, ex, assetPath); } else { var package = assetItemOrPackage as Package; if (package != null) { log.Error(package, null, AssetMessageCode.AssetCannotDelete, ex, assetPath); } } } } } // Save all dirty assets packagesCopy.Clear(); foreach (var package in LocalPackages) { // Save the package to disk and all its assets package.Save(log); // Clone the package (but not all assets inside, just the structure) var packageClone = package.Clone(false); packagesCopy.Add(packageClone); } packagesSaved = true; } finally { if (dependencies != null) { dependencies.EndSavingSession(); } // Once all packages and assets have been saved, we can save the solution (as we need to have fullpath to // be setup for the packages) if (packagesSaved) { PackageSessionHelper.SaveSolution(this, log); } } //System.Diagnostics.Trace.WriteLine("Elapsed saved: " + clock.ElapsedMilliseconds); IsDirty = false; } }
public void UpdateLocalDependency(BaseVersion dependency) { CurrentLocalDependency = dependency == null ? _globalJoker : (LocalPackages.FirstOrDefault(x => x.Equals(dependency)) ?? _globalJoker); }
private async Task UpdateNuGetInfoAsync(NuGetExecutor nuGetExecutor) { await Task.WhenAll(LocalPackages.Select(t => Task.Run(() => nuGetExecutor.Update(t)))); }
public async Task <bool> Execute() { Reports = Options.Reports; LocalPackages = Options.SourcePackages ?? NuGetDependencyResolver.ResolveRepositoryPath(Directory.GetCurrentDirectory()); Options.Reports.Information.WriteLine(string.Format("Adding NuGet package {0} to {1}", Options.NuGetPackage.Bold(), LocalPackages.Bold())); var sw = new Stopwatch(); sw.Start(); var library = NuGetPackageUtils.CreateLibraryFromNupkg(Options.NuGetPackage); using (var sha512 = SHA512.Create()) using (var stream = File.OpenRead(Options.NuGetPackage)) { Reports.Information.WriteLine("Installing {0} {1}", library.Name.Bold(), library.Version); await NuGetPackageUtils.InstallFromStream(stream, library, LocalPackages, sha512); } Reports.Information.WriteLine( "{0}, {1}ms elapsed", "Add complete".Green().Bold(), sw.ElapsedMilliseconds); return(true); }