public XWorld( FileSystem fileSystem, IRootedWorldName worldName, WorldStore worldStore, IEnvLocalFeedProvider localFeeds, SecretKeyStore keyStore, ArtifactCenter artifacts, CommandRegister commandRegister, IBasicApplicationLifetime appLife, Initializer initializer) : base(initializer) { _localFeeds = localFeeds; _fileSystem = fileSystem; _userMonitorFilter = initializer.Monitor.Output.Clients.OfType <IActivityMonitorFilteredClient>().FirstOrDefault(); if (_userMonitorFilter == null) { throw new InvalidOperationException(); } bool isPublic = initializer.Reader.HandleRequiredAttribute <bool>("IsPublic"); _world = new World(commandRegister, artifacts, worldStore, worldName, isPublic, _localFeeds, keyStore, _userMonitorFilter, appLife) { VersionSelector = new ReleaseVersionSelector() }; _world.DumpWorldStatus += (o, e) => OnDumpWorldStatus(e.Monitor); initializer.Services.Add(_world); fileSystem.ServiceContainer.Add <ISolutionDriverWorld>(_world); }
/// <summary> /// Initializes a new WorldSelector that exposes a <see cref="CurrentWorld"/>. /// </summary> /// <param name="store">The world store.</param> /// <param name="commandRegister">The command register.</param> /// <param name="factory">The factory for XTypedObjects.</param> /// <param name="userKeyStore">The user key store.</param> /// <param name="appLife">Simple application lifetime controller.</param> public WorldSelector(WorldStore store, CommandRegister commandRegister, XTypedFactory factory, SecretKeyStore userKeyStore, IBasicApplicationLifetime appLife) { Store = store ?? throw new ArgumentNullException(nameof(store)); _command = commandRegister ?? throw new ArgumentNullException(nameof(commandRegister)); _userKeyStore = userKeyStore ?? throw new ArgumentNullException(nameof(userKeyStore)); _appLife = appLife ?? throw new ArgumentNullException(nameof(appLife)); _factory = factory ?? throw new ArgumentNullException(nameof(factory)); commandRegister.Register(this); _existingCommands = new HashSet <ICommandHandler>(commandRegister.GetAllCommands(false)); }
public UserHost(IBasicApplicationLifetime lifetime, NormalizedPath userHostPath) { Directory.CreateDirectory(userHostPath); ApplicationLifetime = lifetime; CommandRegister = new CommandRegister(); _xTypedObjectfactory = new XTypedFactory(); UserKeyVault = new UserKeyVault(userHostPath); _worldMapping = new SimpleWorldLocalMapping(userHostPath.AppendPart("WorldLocalMapping.txt")); _store = new GitWorldStore(userHostPath, _worldMapping, UserKeyVault.KeyStore, CommandRegister); WorldSelector = new WorldSelector(_store, CommandRegister, _xTypedObjectfactory, UserKeyVault.KeyStore, lifetime); CommandRegister.Register(this); }
/// <summary> /// Encapsulates creation, initalization and run of the builds. /// Solutions are soon as version updates have been made. /// </summary> /// <param name="m">The monitor to use.</param> /// <param name="feeds">The local feeds.</param> /// <param name="ctx">The world solution context to consider.</param> /// <returns>The ZeroBuilder on success, null on error.</returns> public static ZeroBuilder EnsureZeroBuildProjects( IActivityMonitor m, IEnvLocalFeedProvider feeds, IWorldSolutionContext ctx, IBasicApplicationLifetime appLife) { using (m.OpenInfo($"Building ZeroVersion projects.")) { var builder = Create(m, feeds, ctx); if (builder == null) { return(null); } bool success = builder.Run(m, appLife, out bool mustReloadSolutions); if (mustReloadSolutions) { ctx.Refresh(m, true); } return(success ? builder : null); } }
/// <summary> /// Runs the builder: publishes the build projects that needs to be. /// This is private: <see cref="EnsureZeroBuildProjects"/> calls it. /// </summary> /// <param name="m">The monitor to use.</param> /// <param name="mustReloadSolutions">True if solutions must be reloaded.</param> /// <returns>True on success, false on error.</returns> bool Run(IActivityMonitor m, IBasicApplicationLifetime appLife, out bool mustReloadSolutions) { Debug.Assert(_mustBuild.Count == ZeroBuildProjects.Count); ReadCurrentSha(m); Debug.Assert(ZeroBuildProjects.Select(p => _context.FindDriver(p.Project)) .All(d => d.GitRepository.CheckCleanCommit(m)), "Repositories are clean."); mustReloadSolutions = false; try { using (m.OpenTrace("Analysing dependencies.")) { foreach (var p in ZeroBuildProjects) { using (m.OpenInfo($"{p} <= {(p.AllDependencies.Any() ? p.AllDependencies.Select( d => d.Name ).Concatenate() : "(no dependency)")}.")) { var driver = _context.FindDriver(p.Project); // Check cache. var currentTreeSha = _currentShas[p.Index]; if (currentTreeSha == null) { throw new Exception($"Unable to get Sha for {p}."); } if (!_sha1Cache.TryGetValue(p.Project.FullFolderPath, out var shaList)) { m.Info($"ReasonToBuild#1: No cached Sha signature found for {p.Project.FullFolderPath}."); } else if (!shaList.Contains(currentTreeSha)) { m.Info($"ReasonToBuild#2: Current Sha signature differs from the cached ones."); } else if (p.AllDependencies.Any(dep => _mustBuild.Contains(dep.FullFolderPath))) { m.Info($"ReasonToBuild#3: Rebuild dependencies are {_mustBuild.Intersect( p.AllDependencies.Select( dep => dep.FullFolderPath.Path ) ).Concatenate()}."); } else if (p.MustPack && !System.IO.File.Exists( System.IO.Path.Combine( _localFeedProvider.ZeroBuild.PhysicalPath, p.Project.SimpleProjectName + ".0.0.0-0.nupkg"))) { m.Info($"ReasonToBuild#4: {p.Project.SimpleProjectName}.0.0.0-0 does not exist in in Zero build feed."); } else if (p.Project.IsBuildProject && !System.IO.File.Exists(_localFeedProvider.GetZeroVersionCodeCakeBuilderExecutablePath(p.Project.Solution.Name))) { m.Info($"ReasonToBuild#5: Published ZeroVersion CodeCakeBuilder is missing."); } else { _mustBuild.Remove(p.Project.FullFolderPath); m.CloseGroup($"Project '{p}' is up to date. Build skipped."); } } if (appLife.StopRequested(m)) { return(false); } } } if (_mustBuild.Count == 0) { m.Info("Nothing to build. Build projects are up-to-date."); mustReloadSolutions = false; } else { mustReloadSolutions = true; using (m.OpenTrace($"Build/Publish {_mustBuild.Count} build projects: {_mustBuild.Concatenate()}")) { foreach (var p in ZeroBuildProjects.Where(p => _mustBuild.Contains(p.Project.FullFolderPath))) { var action = p.MustPack ? "Publishing" : "Building"; using (m.OpenInfo($"{action} {p}.")) { var driver = _context.FindDriver(p.Project); if (!driver.ZeroBuildProject(m, p)) { _sha1Cache.Remove(p.Project.FullFolderPath); m.CloseGroup("Failed."); return(false); } _mustBuild.Remove(p.Project.FullFolderPath); AddCurrentShaToCache(m, p); m.CloseGroup("Success."); } if (appLife.StopRequested(m)) { return(false); } } } } return(true); } finally { if (mustReloadSolutions) { SaveShaCache(m); } Debug.Assert(ZeroBuildProjects.Select(p => _context.FindDriver(p.Project)) .All(d => d.GitRepository.CheckCleanCommit(m)), "Repositories are clean."); } }