Beispiel #1
0
        public void EnsureStackDefinition(
            IActivityMonitor m,
            string stackName,
            string url,
            bool isPublic,
            NormalizedPath mappedPath = default,
            string branchName         = "master")
        {
            if (String.IsNullOrWhiteSpace(stackName))
            {
                throw new ArgumentException("Must not be empty.", nameof(stackName));
            }

            bool change = WorldLocalMapping.SetMap(m, stackName, mappedPath);

            if (FindOrCreateStackDef(m, stackName, url, isPublic, branchName))
            {
                change = true;
            }

            if (change)
            {
                UpdateReposFromDefinitions(m, StackInitializeOption.OpenAndPullRepository);
                WriteStacksToFile(m);
            }
        }
Beispiel #2
0
        public bool SetWorldMapping(IActivityMonitor m, string worldFullName, NormalizedPath mappedPath)
        {
            var worlds = ReadWorlds(m);

            if (worlds == null)
            {
                return(false);
            }
            var w = worlds.FirstOrDefault(x => x.FullName.Equals(worldFullName, StringComparison.OrdinalIgnoreCase));

            if (w == null)
            {
                m.Error($"World '{worldFullName}' not found.");
                return(false);
            }
            if (w.Root == mappedPath)
            {
                m.Trace($"World '{w.FullName}' is already mapped to '{w.Root}'.");
                return(true);
            }
            if (!mappedPath.IsRooted)
            {
                m.Error($"Invalid '{mappedPath}'. It must be rooted.");
                return(false);
            }
            if (!WorldLocalMapping.SetMap(m, w.FullName, mappedPath))
            {
                return(true);
            }
            m.Info($"World '{w.FullName}' is now mapped to '{mappedPath}'.");
            ReadWorlds(m, false);
            return(true);
        }
Beispiel #3
0
 /// <summary>
 /// Reads the Stacks.xml file and instanciates the <see cref="StackRepo"/> objects and
 /// their <see cref="WorldInfo"/>: creating the StackRepo registers the required secrets
 /// in the key store.
 /// </summary>
 /// <param name="m">The monitor to use.</param>
 internal void ReadStacksFromLocalStacksFilePath(IActivityMonitor m)
 {
     if (!File.Exists(StacksFilePath))
     {
         m.Warn($"File '{StacksFilePath}' not found.");
     }
     else
     {
         using (m.OpenInfo($"Reading '{StacksFilePath}'."))
         {
             try
             {
                 _stackRepos.Clear();
                 _stackRepos.AddRange(XDocument.Load(StacksFilePath).Root.Elements().Select(e => StackRepo.Parse(this, e)));
             }
             catch (Exception ex)
             {
                 m.Error($"Unable to read '{StacksFilePath}' file.", ex);
             }
         }
     }
     if (_stackRepos.Count == 0)
     {
         using (m.OpenInfo("Since there is no Stack defined, we initialize CK and CK-Build mapped to '/Dev/CK' by default."))
         {
             m.Info($"Use 'run World/{nameof( SetWorldMapping )}' command to update the mapping.");
             _stackRepos.Add(new StackRepo(this, new Uri("https://github.com/signature-opensource/CK-Stack.git"), true));
             _stackRepos.Add(new StackRepo(this, new Uri("https://github.com/CK-Build/CK-Build-Stack.git"), true));
             WorldLocalMapping.SetMap(m, "CK-Build", "/Dev/CK");
             WorldLocalMapping.SetMap(m, "CK", "/Dev/CK");
             WriteStacksToLocalStacksFilePath(m);
         }
     }
 }