private ISet <TargetRelativePath> DeployDirectoryContents(IFileSystemDirectory depDir, string directoryPath, string subDir) { var result = new HashSet <TargetRelativePath>(); //Files foreach (var file in repository.ListFiles(directoryPath)) { var fileName = Path.GetFileName(file); repository.Copy(file, depDir, Path.Combine(subDir, fileName)); result.Add(new TargetRelativePath(targetRoot.GetRelativePath(depDir), Path.Combine(subDir, fileName))); } //Child directories var directory = new LocalFileSystemDirectory(directoryPath); foreach (var childDirectory in directory.ChildDirectories) { var dir = directory.GetChildDirectory(childDirectory); var dirContents = DeployDirectoryContents(depDir, dir.ToString(), Path.Combine(subDir, childDirectory)); foreach (var path in dirContents) { result.Add(path); } } return(result); }
public void SetUp() { kernel = new StandardKernel(); tmp = new TempDirectory(); rootDir = new LocalFileSystemDirectory(tmp); using (var writer = rootDir.CreateTextFile("file1")) writer.WriteLine("Contents of file 1"); using (var writer = rootDir.CreateTextFile("file2")) writer.WriteLine("Contents of file 2"); using (var writer = rootDir.CreateTextFile("file3")) writer.WriteLine("Contents of file 3"); sourceSet1 = new SourceSet("test1"); sourceSet1.Add(new SuiteRelativePath("file1")); sourceSet1.Add(new SuiteRelativePath("file2")); sourceSet2 = new SourceSet("test2"); sourceSet2.Add(new SuiteRelativePath("file1")); sourceSet2.Add(new SuiteRelativePath("file3")); kernel.Bind<IFileSystemDirectory>().ToConstant(rootDir).WhenTargetHas<SuiteRootAttribute>(); var factoryMock = new Mock<ISourceSetFingerprintFactory>(); factoryMock.Setup( f => f.CreateSourceSetFingerprint(It.IsAny<IEnumerable<SuiteRelativePath>>(), It.IsAny<Func<string, bool>>(), It.IsAny<bool>())) .Returns<IEnumerable<SuiteRelativePath>, Func<string, bool>, bool>( (files, exclusions, fullDependency) => new SourceSetFingerprint(rootDir, files, exclusions, fullDependency)); fingerprintFactory = factoryMock.Object; }
private void AddDlls(DirectoryInfo libRoot, List <string> result, LocalFileSystemDirectory localRoot) { var lib40full = libRoot.GetDirectories("net40-full").FirstOrDefault(); var lib40 = libRoot.GetDirectories("net40").FirstOrDefault() ?? libRoot.GetDirectories("net4").FirstOrDefault(); var lib40client = libRoot.GetDirectories("net40-client").FirstOrDefault(); var lib35 = libRoot.GetDirectories("net35").FirstOrDefault(); var lib20 = libRoot.GetDirectories("net20").FirstOrDefault() ?? libRoot.GetDirectories("20").FirstOrDefault(); if (lib40full != null) { result.AddRange(GetDllsIn(localRoot, lib40full)); } else if (lib40 != null) { result.AddRange(GetDllsIn(localRoot, lib40)); } else if (lib40client != null) { result.AddRange(GetDllsIn(localRoot, lib40client)); } else if (lib35 != null) { result.AddRange(GetDllsIn(localRoot, lib35)); } else if (lib20 != null) { result.AddRange(GetDllsIn(localRoot, lib20)); } else { result.AddRange(GetDllsIn(localRoot, libRoot)); } }
public void SetUp() { kernel = new StandardKernel(); tmp = new TempDirectory(); rootDir = new LocalFileSystemDirectory(tmp); using (var writer = rootDir.CreateTextFile("file1")) writer.WriteLine("Contents of file 1"); using (var writer = rootDir.CreateTextFile("file2")) writer.WriteLine("Contents of file 2"); using (var writer = rootDir.CreateTextFile("file3")) writer.WriteLine("Contents of file 3"); sourceSet1 = new SourceSet("test1"); sourceSet1.Add(new SuiteRelativePath("file1")); sourceSet1.Add(new SuiteRelativePath("file2")); sourceSet2 = new SourceSet("test2"); sourceSet2.Add(new SuiteRelativePath("file1")); sourceSet2.Add(new SuiteRelativePath("file3")); kernel.Bind <IFileSystemDirectory>().ToConstant(rootDir).WhenTargetHas <SuiteRootAttribute>(); var factoryMock = new Mock <ISourceSetFingerprintFactory>(); factoryMock.Setup( f => f.CreateSourceSetFingerprint(It.IsAny <IEnumerable <SuiteRelativePath> >(), It.IsAny <Func <string, bool> >(), It.IsAny <bool>())) .Returns <IEnumerable <SuiteRelativePath>, Func <string, bool>, bool>( (files, exclusions, fullDependency) => new SourceSetFingerprint(rootDir, files, exclusions, fullDependency)); fingerprintFactory = factoryMock.Object; }
private IEnumerable <string> GetAllIn(LocalFileSystemDirectory root, DirectoryInfo dir) { log.DebugFormat("Getting all files from {0} relative to {1}...", dir.FullName, root.AbsolutePath); return(from file in dir.RecursiveGetFiles() let relPath = GetRelativePath(file.FullName, root) select relPath); }
public void EmptyDirectoryLooksEmpty() { using (var tmp = new TempDirectory()) { var dir = new LocalFileSystemDirectory(tmp); dir.ChildDirectories.Should().BeEmpty(); dir.Files.Should().BeEmpty(); } }
public void GetChildDirectoryForNonExistingDirectoryReturnsNull() { using (var tmp = new TempDirectory()) { var dir = new LocalFileSystemDirectory(tmp); var subdir = dir.GetChildDirectory("dir1"); subdir.Should().BeNull(); } }
static int Main(string[] args) { var consoleParams = new ConsoleParameters(args); if (consoleParams.VerboseOutput) EnableConsoleDebugLog(); var root = Kernel.Root; // Binding UI interfaces root.Bind<IUserOutput>().To<ConsoleUserInterface>().InSingletonScope(); root.Bind<IParameters>().ToConstant(consoleParams).InSingletonScope(); // Binding special directories var suiteRoot = new LocalFileSystemDirectory(Environment.CurrentDirectory); root.Bind<IFileSystemDirectory>() .ToConstant(suiteRoot) .WhenTargetHas<SuiteRootAttribute>(); root.Bind<IFileSystemDirectory>() .ToConstant(suiteRoot.GetChildDirectory("target", createIfMissing: true)) .WhenTargetHas<TargetRootAttribute>(); // Binding core services Kernel.RegisterCoreBindings(); // Binding default cache var cacheDir = suiteRoot.GetChildDirectory("cache", createIfMissing: true) .GetChildDirectory(consoleParams.Goal, createIfMissing: true); root.Bind<IFileSystemDirectory>() .ToConstant(cacheDir) .WhenTargetHas<CacheRootAttribute>(); root.Bind<IBuildCache>().To<FileBuildCache>(); // Loading fix plugins root.Load(GetOrderedModuleList(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Bari.Plugins.*.dll")); // Initializing the cache cleaner root.Bind<ICleanExtension>().ToConstant(new CacheCleaner(cacheDir, root.Get<IBuilderEnumerator>())); var process = root.Get<MainProcess>(); try { if (process.Run()) return 0; else return 1; } catch (Exception ex) { System.Console.ForegroundColor = ConsoleColor.Red; System.Console.WriteLine(ex.ToString()); System.Console.ForegroundColor = ConsoleColor.Gray; return 2; } }
public void CreateDirectoryWorks() { using (var tmp = new TempDirectory()) { var dir = new LocalFileSystemDirectory(tmp); dir.CreateDirectory("testdir"); dir.ChildDirectories.Should().Contain("testdir"); Directory.Exists(Path.Combine(tmp, "testdir")).Should().BeTrue(); } }
public LocalFileSystemDirectory Get(string absolutePath) { LocalFileSystemDirectory result; if (!fileInfos.TryGetValue(absolutePath, out result)) { result = new LocalFileSystemDirectory(absolutePath); fileInfos.Add(absolutePath, result); } return result; }
public void GetChildDirectoryWorks() { using (var tmp = new TempDirectory()) { Directory.CreateDirectory(Path.Combine(tmp, "dir1")); var dir = new LocalFileSystemDirectory(tmp); var subdir = dir.GetChildDirectory("dir1"); subdir.Should().NotBeNull(); } }
public void CreateTextFileWorks() { using (var tmp = new TempDirectory()) { var dir = new LocalFileSystemDirectory(tmp); using (var writer = dir.CreateTextFile("test.txt")) writer.WriteLine("Hello world"); dir.Files.Should().Contain("test.txt"); File.Exists(Path.Combine(tmp, "test.txt")).Should().BeTrue(); } }
public LocalFileSystemDirectory Get(string absolutePath) { LocalFileSystemDirectory result; if (!fileInfos.TryGetValue(absolutePath, out result)) { result = new LocalFileSystemDirectory(absolutePath); fileInfos.Add(absolutePath, result); } return(result); }
public void FilesAddedLaterAreEnumerated() { using (var tmp = new TempDirectory()) { using (File.Create(Path.Combine(tmp, "test1.txt"))) {} var dir = new LocalFileSystemDirectory(tmp); using (File.Create(Path.Combine(tmp, "test2.bin"))) {} dir.ChildDirectories.Should().BeEmpty(); dir.Files.Should().HaveCount(2); dir.Files.Should().Contain("test1.txt"); dir.Files.Should().Contain("test2.bin"); } }
public void DirectoriesAddedLaterAreEnumerated() { using (var tmp = new TempDirectory()) { Directory.CreateDirectory(Path.Combine(tmp, "dir1")); var dir = new LocalFileSystemDirectory(tmp); Directory.CreateDirectory(Path.Combine(tmp, "dir2")); dir.ChildDirectories.Should().HaveCount(2); dir.ChildDirectories.Should().Contain("dir1"); dir.ChildDirectories.Should().Contain("dir2"); dir.Files.Should().BeEmpty(); } }
public void GetLastModifiedDateReturnsLastModifiedDateInUTC() { using (var tmp = new TempDirectory()) { var dir = new LocalFileSystemDirectory(tmp); using (var writer = dir.CreateTextFile("test.txt")) writer.WriteLine("Hello world"); var lastWriteTime = File.GetLastWriteTimeUtc(Path.Combine(tmp, "test.txt")); var lastModifiedDate = dir.GetLastModifiedDate("test.txt"); lastModifiedDate.Should().Be(lastWriteTime); } }
private void AddDlls(DirectoryInfo libRoot, List <string> result, LocalFileSystemDirectory localRoot, NugetLibraryProfile maxProfile) { var lib45 = GetChild(libRoot, "net45-full") ?? GetChild(libRoot, "net45"); var lib40 = GetChild(libRoot, "net40-full") ?? GetChild(libRoot, "net40") ?? GetChild(libRoot, "net4"); var lib40client = GetChild(libRoot, "net40-client"); var lib35 = GetChild(libRoot, "net35"); var lib35client = GetChild(libRoot, "net35-client"); var lib20 = GetChild(libRoot, "net20") ?? GetChild(libRoot, "20"); var lib20standard = GetChild(libRoot, "netstandard2.0"); if (lib45 != null && maxProfile == NugetLibraryProfile.Net45) { result.AddRange(GetDllsIn(localRoot, lib45)); } else if (lib40 != null && maxProfile >= NugetLibraryProfile.Net4) { result.AddRange(GetDllsIn(localRoot, lib40)); } else if (lib40client != null && maxProfile >= NugetLibraryProfile.Net4Client) { result.AddRange(GetDllsIn(localRoot, lib40client)); } else if (lib35 != null && maxProfile != NugetLibraryProfile.Net35) { result.AddRange(GetDllsIn(localRoot, lib35)); } else if (lib35client != null && maxProfile != NugetLibraryProfile.Net35Client) { result.AddRange(GetDllsIn(localRoot, lib35client)); } else if (lib20 != null && maxProfile != NugetLibraryProfile.Net2) { result.AddRange(GetDllsIn(localRoot, lib20)); } else if (lib20standard != null && maxProfile >= NugetLibraryProfile.Net472) { result.AddRange(GetDllsIn(localRoot, lib20standard)); } else { result.AddRange(GetDllsIn(localRoot, libRoot)); } }
public void GetRelativePathWorks() { using (var tmp = new TempDirectory()) { Directory.CreateDirectory(Path.Combine(tmp, "dir1")); Directory.CreateDirectory(Path.Combine(tmp, "dir1", "dir2")); var dir = new LocalFileSystemDirectory(tmp); var dir1 = dir.GetChildDirectory("dir1"); var dir2 = dir1.GetChildDirectory("dir2"); dir1.Should().NotBeNull(); dir2.Should().NotBeNull(); dir.GetRelativePath(dir1).Should().Be("dir1"); dir.GetRelativePath(dir2).Should().Be(Path.Combine("dir1", "dir2")); } }
private void AddDlls(DirectoryInfo libRoot, List<string> result, LocalFileSystemDirectory localRoot) { var lib40full = libRoot.GetDirectories("net40-full").FirstOrDefault(); var lib40 = libRoot.GetDirectories("net40").FirstOrDefault() ?? libRoot.GetDirectories("net4").FirstOrDefault(); var lib40client = libRoot.GetDirectories("net40-client").FirstOrDefault(); var lib35 = libRoot.GetDirectories("net35").FirstOrDefault(); var lib20 = libRoot.GetDirectories("net20").FirstOrDefault() ?? libRoot.GetDirectories("20").FirstOrDefault(); if (lib40full != null) result.AddRange(GetDllsIn(localRoot, lib40full)); else if (lib40 != null) result.AddRange(GetDllsIn(localRoot, lib40)); else if (lib40client != null) result.AddRange(GetDllsIn(localRoot, lib40client)); else if (lib35 != null) result.AddRange(GetDllsIn(localRoot, lib35)); else if (lib20 != null) result.AddRange(GetDllsIn(localRoot, lib20)); else result.AddRange(GetDllsIn(localRoot, libRoot)); }
public void FillProjectSpecificMissingInfo(Project project, LocalFileSystemDirectory targetDir) { }
public void FillProjectSpecificMissingInfo(Project project, CppCliMode cliMode, LocalFileSystemDirectory targetDir) { if (targetDir != null) { PDBFileName = string.Format("{0}\\{1}.{2}.pdb", targetDir.AbsolutePath, project.Module.Name, project.Name); } if (cliMode != CppCliMode.Disabled) { // Fixing some settings to support C++/CLI mode switch (cliMode) { case CppCliMode.Enabled: CompileAsManaged = ManagedCppType.Managed; break; case CppCliMode.Pure: CompileAsManaged = ManagedCppType.Pure; break; case CppCliMode.Safe: CompileAsManaged = ManagedCppType.Safe; break; case CppCliMode.OldSyntax: CompileAsManaged = ManagedCppType.OldSyntax; break; } if (DebugInformationFormat == DebugInformationFormat.EditAndContinue) DebugInformationFormat = DebugInformationFormat.ProgramDatabase; MinimalRebuild = false; SmallerTypeCheck = false; FloatingPointExceptions = false; if (project.Type == ProjectType.StaticLibrary) { Defines = Defines.Concat(new[] {"_LIB"}).ToArray(); } } }
static int Main(string[] args) { var consoleParams = new ConsoleParameters(args); if (consoleParams.VerboseOutput) { EnableConsoleDebugLog(); } var root = Kernel.Root; // Binding UI interfaces root.Bind <IUserOutput>().To <ConsoleUserInterface>().InSingletonScope(); root.Bind <IParameters>().ToConstant(consoleParams).InSingletonScope(); // Binding special directories var suiteRoot = new LocalFileSystemDirectory(Environment.CurrentDirectory); root.Bind <IFileSystemDirectory>() .ToConstant(suiteRoot) .WhenTargetHas <SuiteRootAttribute>(); root.Bind <IFileSystemDirectory>() .ToConstant(suiteRoot.GetChildDirectory("target", createIfMissing: true)) .WhenTargetHas <TargetRootAttribute>(); // Binding core services Kernel.RegisterCoreBindings(); // Binding default cache var cacheDir = suiteRoot.GetChildDirectory("cache", createIfMissing: true) .GetChildDirectory(consoleParams.Goal, createIfMissing: true); root.Bind <IFileSystemDirectory>() .ToConstant(cacheDir) .WhenTargetHas <CacheRootAttribute>(); root.Bind <IBuildCache>().To <FileBuildCache>(); // Loading fix plugins root.Load(GetOrderedModuleList(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Bari.Plugins.*.dll")); // Initializing the cache cleaner root.Bind <ICleanExtension>().ToConstant(new CacheCleaner(cacheDir, root.Get <IBuilderEnumerator>())); var process = root.Get <MainProcess>(); try { if (process.Run()) { return(0); } else { return(1); } } catch (Exception ex) { System.Console.ForegroundColor = ConsoleColor.Red; System.Console.WriteLine(ex.ToString()); System.Console.ForegroundColor = ConsoleColor.Gray; return(2); } }
private string GetRelativePath(string path, LocalFileSystemDirectory root) { return(path.Substring(root.AbsolutePath.Length).TrimStart(Path.DirectorySeparatorChar)); }
public void FillProjectSpecificMissingInfo(Project project, CppCliMode cliMode, LocalFileSystemDirectory targetDir) { if (targetDir != null) { PDBFileName = string.Format("{0}\\{1}.{2}.pdb", targetDir.AbsolutePath, project.Module.Name, project.Name); } if (cliMode != CppCliMode.Disabled) { // Fixing some settings to support C++/CLI mode switch (cliMode) { case CppCliMode.Enabled: CompileAsManaged = ManagedCppType.Managed; break; case CppCliMode.Pure: CompileAsManaged = ManagedCppType.Pure; break; case CppCliMode.Safe: CompileAsManaged = ManagedCppType.Safe; break; case CppCliMode.OldSyntax: CompileAsManaged = ManagedCppType.OldSyntax; break; } if (DebugInformationFormat == DebugInformationFormat.EditAndContinue) { DebugInformationFormat = DebugInformationFormat.ProgramDatabase; } MinimalRebuild = false; SmallerTypeCheck = false; FloatingPointExceptions = false; if (project.Type == ProjectType.StaticLibrary) { Defines = Defines.Concat(new[] { "_LIB" }).ToArray(); } } }
public void FillProjectSpecificMissingInfo(Project project, CppCliMode cliMode, LocalFileSystemDirectory targetDir) { if (targetDir != null) { PDBFileName = string.Format("{0}{3}{1}.{2}.pdb", targetDir.AbsolutePath, project.Module.Name, project.Name, Path.DirectorySeparatorChar); } if (cliMode != CppCliMode.Disabled) { // Fixing some settings to support C++/CLI mode switch (cliMode) { case CppCliMode.Enabled: CompileAsManaged = ManagedCppType.Managed; break; case CppCliMode.Pure: CompileAsManaged = ManagedCppType.Pure; break; case CppCliMode.Safe: CompileAsManaged = ManagedCppType.Safe; break; case CppCliMode.OldSyntax: CompileAsManaged = ManagedCppType.OldSyntax; break; } if (!IsDebugInformationFormatSpecified && suite.ActiveGoal.Has(Suite.DebugGoal.Name)) { DebugInformationFormat = DebugInformationFormat.ProgramDatabase; } MinimalRebuild = false; SmallerTypeCheck = false; FloatingPointExceptions = false; if (project.Type == ProjectType.StaticLibrary) { Defines = Defines.Concat(new[] { "_LIB" }).ToArray(); } } if (project.EffectiveVersion != null) { Defines = Defines.Concat(new[] { String.Format("BARI_PROJECT_VERSION=\"{0}\"", project.EffectiveVersion) }).ToArray(); } if (project.EffectiveCopyright != null) { Defines = Defines.Concat(new[] { String.Format("BARI_PROJECT_COPYRIGHT=\"{0}\"", project.EffectiveCopyright) }).ToArray(); } }
private void AddContents(DirectoryInfo contentRoot, List <string> result, LocalFileSystemDirectory localRoot) { result.AddRange(GetAllIn(localRoot, contentRoot)); }
public void PartialDelete() { using (var tmp = new TempDirectory()) { var dir = new LocalFileSystemDirectory(tmp); Directory.CreateDirectory(Path.Combine(tmp, "dir1")); Directory.CreateDirectory(Path.Combine(tmp, "dir1", "dir2")); using (var f = File.CreateText(Path.Combine(tmp, "dir1", "file.delete"))) f.WriteLine("test"); using (var f = File.CreateText(Path.Combine(tmp, "dir1", "file.keep"))) f.WriteLine("test"); using (var f = File.CreateText(Path.Combine(tmp, "dir1", "dir2", "file.delete"))) f.WriteLine("test"); var paths = new HashSet <string>(); dir.Delete(p => { paths.Add(p); return(false); }); paths.Should().HaveCount(3); paths.Should().Contain(Path.Combine("dir1", "file.delete")); paths.Should().Contain(Path.Combine("dir1", "file.keep")); paths.Should().Contain(Path.Combine("dir1", "dir2", "file.delete")); Directory.Exists(tmp).Should().BeTrue(); Directory.Exists(Path.Combine(tmp, "dir1")).Should().BeTrue(); Directory.Exists(Path.Combine(tmp, "dir1", "dir2")).Should().BeTrue(); File.Exists(Path.Combine(tmp, "dir1", "file.delete")).Should().BeTrue(); File.Exists(Path.Combine(tmp, "dir1", "file.keep")).Should().BeTrue(); File.Exists(Path.Combine(tmp, "dir1", "dir2", "file.delete")).Should().BeTrue(); paths.Clear(); dir.Delete(p => { paths.Add(p); return(!p.EndsWith(".keep", System.StringComparison.InvariantCulture)); }); paths.Should().HaveCount(4); paths.Should().Contain(Path.Combine("dir1", "file.delete")); paths.Should().Contain(Path.Combine("dir1", "file.keep")); paths.Should().Contain(Path.Combine("dir1", "dir2")); paths.Should().Contain(Path.Combine("dir1", "dir2", "file.delete")); Directory.Exists(tmp).Should().BeTrue(); Directory.Exists(Path.Combine(tmp, "dir1")).Should().BeTrue(); Directory.Exists(Path.Combine(tmp, "dir1", "dir2")).Should().BeFalse(); File.Exists(Path.Combine(tmp, "dir1", "file.delete")).Should().BeFalse(); File.Exists(Path.Combine(tmp, "dir1", "file.keep")).Should().BeTrue(); File.Exists(Path.Combine(tmp, "dir1", "dir2", "file.delete")).Should().BeFalse(); paths.Clear(); dir.Delete(p => { paths.Add(p); return(true); }); paths.Should().HaveCount(3); paths.Should().Contain(Path.Combine("dir1", "file.keep")); paths.Should().Contain("dir1"); paths.Should().Contain(""); Directory.Exists(tmp).Should().BeFalse(); } }
static int Main(string[] args) { var consoleParams = new ConsoleParameters(args); if (consoleParams.VerboseOutput) EnableConsoleDebugLog(); var root = Kernel.Root; // Binding UI interfaces root.Bind<IUserOutput>().To<ConsoleUserInterface>().InSingletonScope(); root.Bind<IParameters>().ToConstant(consoleParams).InSingletonScope(); // Binding special directories var suiteRoot = new LocalFileSystemDirectory(Environment.CurrentDirectory); root.Bind<IFileSystemDirectory>() .ToConstant(suiteRoot) .WhenTargetHas<SuiteRootAttribute>(); root.Bind<IFileSystemDirectory>() .ToConstant(suiteRoot.GetChildDirectory("target", createIfMissing: true)) .WhenTargetHas<TargetRootAttribute>(); // Binding core services Kernel.RegisterCoreBindings(); // Binding default cache var cacheDir = new Lazy<IFileSystemDirectory>(() => suiteRoot.GetChildDirectory("cache", createIfMissing: true) .GetChildDirectory(root.Get<Suite>().ActiveGoal.Name, createIfMissing: true)); root.Bind<Lazy<IFileSystemDirectory>>() .ToConstant(cacheDir) .WhenTargetHas<CacheRootAttribute>(); root.Bind<IBuildCache>().To<FileBuildCache>(); // Loading fix plugins var pluginLoader = root.Get<IPluginLoader>(); foreach (var module in GetOrderedModuleList(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Bari.Plugins.*.dll")) pluginLoader.Load(module); // Initializing builder store Kernel.InitializeBuilderStore(); // Initializing the cache cleaner root.Bind<ICleanExtension>().ToConstant(new CacheCleaner(cacheDir, root.Get<IBuilderEnumerator>(), () => root.Get<ISoftCleanPredicates>())); var process = root.Get<MainProcess>(); try { if (process.Run()) return 0; else return 1; } catch (Exception ex) { var output = root.Get<IUserOutput>(); output.Error(ex.ToString()); return 2; } }
private void AddContents(DirectoryInfo contentRoot, List<string> result, LocalFileSystemDirectory localRoot) { result.AddRange(GetAllIn(localRoot, contentRoot)); }
public void PartialDelete() { using (var tmp = new TempDirectory()) { var dir = new LocalFileSystemDirectory(tmp); Directory.CreateDirectory(Path.Combine(tmp, "dir1")); Directory.CreateDirectory(Path.Combine(tmp, "dir1", "dir2")); using (var f = File.CreateText(Path.Combine(tmp, "dir1", "file.delete"))) f.WriteLine("test"); using (var f = File.CreateText(Path.Combine(tmp, "dir1", "file.keep"))) f.WriteLine("test"); using (var f = File.CreateText(Path.Combine(tmp, "dir1", "dir2", "file.delete"))) f.WriteLine("test"); var paths = new HashSet<string>(); dir.Delete(p => { paths.Add(p); return false; }); paths.Should().HaveCount(3); paths.Should().Contain(Path.Combine("dir1", "file.delete")); paths.Should().Contain(Path.Combine("dir1", "file.keep")); paths.Should().Contain(Path.Combine("dir1", "dir2", "file.delete")); Directory.Exists(tmp).Should().BeTrue(); Directory.Exists(Path.Combine(tmp, "dir1")).Should().BeTrue(); Directory.Exists(Path.Combine(tmp, "dir1", "dir2")).Should().BeTrue(); File.Exists(Path.Combine(tmp, "dir1", "file.delete")).Should().BeTrue(); File.Exists(Path.Combine(tmp, "dir1", "file.keep")).Should().BeTrue(); File.Exists(Path.Combine(tmp, "dir1", "dir2", "file.delete")).Should().BeTrue(); paths.Clear(); dir.Delete(p => { paths.Add(p); return !p.EndsWith(".keep", System.StringComparison.InvariantCulture); }); paths.Should().HaveCount(4); paths.Should().Contain(Path.Combine("dir1", "file.delete")); paths.Should().Contain(Path.Combine("dir1", "file.keep")); paths.Should().Contain(Path.Combine("dir1", "dir2")); paths.Should().Contain(Path.Combine("dir1", "dir2", "file.delete")); Directory.Exists(tmp).Should().BeTrue(); Directory.Exists(Path.Combine(tmp, "dir1")).Should().BeTrue(); Directory.Exists(Path.Combine(tmp, "dir1", "dir2")).Should().BeFalse(); File.Exists(Path.Combine(tmp, "dir1", "file.delete")).Should().BeFalse(); File.Exists(Path.Combine(tmp, "dir1", "file.keep")).Should().BeTrue(); File.Exists(Path.Combine(tmp, "dir1", "dir2", "file.delete")).Should().BeFalse(); paths.Clear(); dir.Delete(p => { paths.Add(p); return true; }); paths.Should().HaveCount(3); paths.Should().Contain(Path.Combine("dir1", "file.keep")); paths.Should().Contain("dir1"); paths.Should().Contain(""); Directory.Exists(tmp).Should().BeFalse(); } }
private IEnumerable<string> GetAllIn(LocalFileSystemDirectory root, DirectoryInfo dir) { log.DebugFormat("Getting all files from {0} relative to {1}...", dir.FullName, root.AbsolutePath); return from file in dir.RecursiveGetFiles() let relPath = GetRelativePath(file.FullName, root) select relPath; }
static int Main(string[] args) { var consoleParams = new ConsoleParameters(args); if (consoleParams.VerboseOutput) { EnableConsoleDebugLog(); } var root = Kernel.Root; // Binding UI interfaces root.Bind <IUserOutput>().To <ConsoleUserInterface>().InSingletonScope(); root.Bind <IParameters>().ToConstant(consoleParams).InSingletonScope(); // Binding special directories var suiteRoot = new LocalFileSystemDirectory(Environment.CurrentDirectory); root.Bind <IFileSystemDirectory>() .ToConstant(suiteRoot) .WhenTargetHas <SuiteRootAttribute>(); root.Bind <IFileSystemDirectory>() .ToConstant(suiteRoot.GetChildDirectory("target", createIfMissing: true)) .WhenTargetHas <TargetRootAttribute>(); // Binding core services Kernel.RegisterCoreBindings(); // Binding default cache var cacheDir = new Lazy <IFileSystemDirectory>(() => suiteRoot.GetChildDirectory("cache", createIfMissing: true) .GetChildDirectory(root.Get <Suite>().ActiveGoal.Name, createIfMissing: true)); root.Bind <Lazy <IFileSystemDirectory> >() .ToConstant(cacheDir) .WhenTargetHas <CacheRootAttribute>(); root.Bind <IBuildCache>().To <FileBuildCache>(); // Loading fix plugins var pluginLoader = root.Get <IPluginLoader>(); foreach (var module in GetOrderedModuleList(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Bari.Plugins.*.dll")) { pluginLoader.Load(module); } // Initializing builder store Kernel.InitializeBuilderStore(); // Initializing the cache cleaner root.Bind <ICleanExtension>().ToConstant(new CacheCleaner(cacheDir, root.Get <IBuilderEnumerator>(), () => root.Get <ISoftCleanPredicates>())); var process = root.Get <MainProcess>(); try { if (process.Run()) { return(0); } else { return(1); } } catch (Exception ex) { var output = root.Get <IUserOutput>(); output.Error(ex.ToString()); return(2); } }
private string GetRelativePath(string path, LocalFileSystemDirectory root) { return path.Substring(root.AbsolutePath.Length).TrimStart('\\'); }
private void AddDlls(DirectoryInfo libRoot, List<string> result, LocalFileSystemDirectory localRoot, NugetLibraryProfile maxProfile) { var lib45 = GetChild(libRoot, "net45-full") ?? GetChild(libRoot, "net45"); var lib40 = GetChild(libRoot, "net40-full") ?? GetChild(libRoot, "net40") ?? GetChild(libRoot, "net4"); var lib40client = GetChild(libRoot, "net40-client"); var lib35 = GetChild(libRoot, "net35"); var lib35client = GetChild(libRoot, "net35-client"); var lib20 = GetChild(libRoot, "net20") ?? GetChild(libRoot, "20"); if (lib45 != null && maxProfile == NugetLibraryProfile.Net45) result.AddRange(GetDllsIn(localRoot, lib45)); else if (lib40 != null && maxProfile >= NugetLibraryProfile.Net4) result.AddRange(GetDllsIn(localRoot, lib40)); else if (lib40client != null && maxProfile >= NugetLibraryProfile.Net4Client) result.AddRange(GetDllsIn(localRoot, lib40client)); else if (lib35 != null && maxProfile != NugetLibraryProfile.Net35) result.AddRange(GetDllsIn(localRoot, lib35)); else if (lib35client != null && maxProfile != NugetLibraryProfile.Net35Client) result.AddRange(GetDllsIn(localRoot, lib35client)); else if (lib20 != null && maxProfile != NugetLibraryProfile.Net2) result.AddRange(GetDllsIn(localRoot, lib20)); else result.AddRange(GetDllsIn(localRoot, libRoot)); }