Example #1
0
        public FilePath GetFirstMatch(FilePath root, string pattern)
        {
            var first = Directory.EnumerateFiles(root.ToEnvironmentalPath(), pattern, SearchOption.TopDirectoryOnly)
                .FirstOrDefault();

            if (string.IsNullOrEmpty(first)) return null;

            return (FilePath)first;
        }
Example #2
0
 public bool DirectoryExists(FilePath p)
 {
     try
     {
         return Directory.Exists(p.ToEnvironmentalPath());
     }
     catch
     {
         return false;
     }
 }
Example #3
0
        public void DeletePath(FilePath path)
        {
            var epath = path.ToEnvironmentalPath();
            var gitPath = path.Navigate((FilePath)".git").ToEnvironmentalPath();

            if (Directory.Exists(gitPath)) Directory.Delete(gitPath, true);

            if (Directory.Exists(epath))
                Directory.Delete(epath, true);
            else
                File.Delete(epath);
        }
Example #4
0
        public void CopyBuildResultsTo(FilePath dest)
        {
            // For every file in dest, if we have a newer copy then overwrite dest file.
            // masters always override other available files
            if (!Directory.Exists(dest.ToEnvironmentalPath())) return;
            var files = Directory.GetFiles(dest.ToEnvironmentalPath(), _patterns.DependencyPattern, SearchOption.TopDirectoryOnly);
            foreach (var target in files)
            {
                var name = Path.GetFileName(target);
                if (name == null) continue;

                var source = _masters.Of(name) ?? _available.Of(name);

                if (source == null)
                {
                    Log.Verbose("No source for => " + target);
                    continue;
                }

                Log.Verbose(source.FullName + " => " + target);
                source.CopyTo(target, true);
            }
        }
Example #5
0
        static void SetByLatest(FilePath srcPath, IDictionary<string, FileInfo> repo, string pattern)
        {
            var files = Directory.GetFiles(srcPath.ToEnvironmentalPath(), pattern, SearchOption.AllDirectories);
            foreach (var file in files)
            {
                var name = Path.GetFileName(file);
                if (name == null) continue;
                var newInfo = new FileInfo(file);
                if (!repo.ContainsKey(name))
                {
                    repo.Add(name, newInfo);
                    continue;
                }

                var existing = repo[name];
                if (newInfo.LastWriteTime > existing.LastWriteTime)
                    repo[name] = newInfo;
            }
        }
Example #6
0
        public void CopyDirectory(FilePath src, FilePath dst)
        {
            if (!DirectoryExists(src)) throw new Exception("Source was not a folder or doesn't exist");

            if (IsFile(dst)) throw new Exception("Destination already exists as a file");
            if (DirectoryExists(dst))
            {
                try
                {
                    DeletePath(dst);
                }
                catch
                {
                    throw new Exception("Tried to delete " + dst + " to replace it, but failed");
                }
            }

            DirectoryCopy(src.ToEnvironmentalPath(), dst.ToEnvironmentalPath(), true);
        }
Example #7
0
 public void Should_throw_if_file_doesnt_have_an_extension(string inputPath)
 {
     var filePath = new FilePath(inputPath);
     var ex = Assert.Throws<InvalidOperationException>(()=>filePath.Extension());
     Assert.That(ex.Message, Is.EqualTo(string.Format("{0} does not have an extension", filePath.ToEnvironmentalPath())));
 }
Example #8
0
 public void UpdateAvailableDependencies(FilePath srcPath)
 {
     if (!Directory.Exists(srcPath.ToEnvironmentalPath())) return;
     // for every pattern file under srcPath, add to list if it's the newest
     SetByLatest(srcPath, _available, _patterns.DependencyPattern);
 }
Example #9
0
        void ReadModules(FilePath filePath)
        {
            Log.Verbose("Reading " + filePath.ToEnvironmentalPath());
            var lines = _files.Lines(filePath);

            var c = lines.Length;

            Repos = new string[c]; // src id => src repo
            Paths = new string[c]; // src id => file path
            Deps = new List<int>[c]; // src id => dst

            for (int i = 0; i < c; i++)
            {
                Log.Verbose(lines[i]);
                var bits = lines[i].Split('=').Select(s => s.Trim()).ToArray();

                Repos[i] = bits[1];
                Paths[i] = bits[0];
                Deps[i] = new List<int>();
            }
        }
Example #10
0
 public string[] Lines(FilePath path)
 {
     return
         File.ReadAllLines(path.ToEnvironmentalPath())
         .Where(l => !l.StartsWith("#") && !string.IsNullOrWhiteSpace(l)).ToArray();
 }
Example #11
0
 public bool IsFile(FilePath target)
 {
     try
     {
         return File.Exists(target.ToEnvironmentalPath());
     }
     catch
     {
         return false;
     }
 }
Example #12
0
        void CloneMissingRepos()
        {
            for (int i = 0; i < Modules.Paths.Length; i++)
            {
                var path = new FilePath(Modules.Paths[i]);
                var expected = _rootPath.Navigate(path);
                if (_files.Exists(expected)) continue;

                Log.Info(path.ToEnvironmentalPath() + " is missing. Cloning...");
                _git.Clone(_rootPath, expected, Modules.Repos[i]);
            }
        }
Example #13
0
 public bool Exists(FilePath filePath)
 {
     return File.Exists(filePath.ToEnvironmentalPath())
         || Directory.Exists(filePath.ToEnvironmentalPath());
 }
Example #14
0
        private void RebuildByFluentMigration(FilePath projPath, FilePath psScript)
        {
            var createDatabase = projPath.Append(new FilePath("DatabaseScripts")).Append(new FilePath("CreateDatabase.sql"));
            Log.Status("Creating database from " + createDatabase.ToEnvironmentalPath());
            _builder.RunSqlScripts(projPath, createDatabase);

            Log.Status("Running RunMigrationsLocally.ps1");
            projPath.Call("powershell " + psScript.ToEnvironmentalPath(), "");
        }
Example #15
0
 public int RunSqlScripts(FilePath root, FilePath script)
 {
     Log.Status("                           " + script.LastElement());
     return root.Call("sqlcmd.exe", "-f 65001 -i \"" + script.ToEnvironmentalPath() + "\" -S . -E");
 }
Example #16
0
 public IEnumerable<FilePath> SortedDescendants(FilePath filePath, string pattern)
 {
     return Directory.GetFiles(filePath.ToEnvironmentalPath(), pattern, SearchOption.AllDirectories)
         .Select(p => new { Directory = Path.GetDirectoryName(p), Filename = Path.GetFileName(p) })
         .OrderBy(f => f.Filename)
         .Select(f => new FilePath(Path.Combine(f.Directory, f.Filename)))
         .ToList();
 }
Example #17
0
 void TryGitCommand(FilePath modulePath, int times, string command)
 {
     if (times > 3)
     {
         Log.Status("Git server keeps hanging up. Will continue with local copy");
         return;
     }
     string s_out = "";
     string s_err = "";
     if (modulePath.Call(_git, command, (o, e) =>
         {
             s_err = e;
             s_out = o;
         }) != 0)
     {
         if (
             s_err.Contains(FatalHangup) || s_out.Contains(FatalHangup)
             ||
             s_err.Contains(FatalConnect) || s_out.Contains(FatalConnect)
             )
         {
             TryGitCommand(modulePath, times + 1, command);
         }
         else throw new Exception("Git pull failed on " + modulePath.ToEnvironmentalPath() + "; Please resolve and try again");
     }
 }
Example #18
0
        public void Prepare()
        {
            _rootPath = _files.GetPlatformRoot();
            Log.Status("Started in " + _rootPath.ToEnvironmentalPath() + "; Updating self");

            _git.PullMaster(_rootPath);

            _patterns = _rules.GetRulePatterns();
            Modules = _rules.GetModules();
            try
            {
                Modules.ReadDependencies(_rootPath);
            }
            catch (UnknownModuleException ex)
            {
                Log.Error(ex.Message + ", will pull all repositories. You will need to retry platform build.");

                _locks = Modules.CreateAndSetLocks();
                PullRepos();
                CloneMissingRepos();

                throw;
            }
            Modules.SortInDependencyOrder();

            _depMgr.ReadMasters(_rootPath, _patterns.Masters);

            DeleteOldPaths();

            Log.Verbose("Processing " + string.Join(", ", Modules.Paths));
            CloneMissingRepos();

            _locks = Modules.CreateAndSetLocks();
        }