public void Test_Retrieve_SpecifyStatus() { // Copy the nuget.exe file into the current test directory so the retriever can skip downloading it new FileCopier( OriginalDirectory, CurrentDirectory ).Copy( "lib/nuget.exe" ); new FileNodeManager().EnsureNodes(); new MockNugetPackageCreator().Create("TestPackage", new Version("1.0.0"), "beta"); new MockNugetPackageCreator().Create("TestPackage", new Version("1.0.1"), "alpha"); var retriever = new InstallerNugetPackageRetriever() { NugetSourcePath = PathConverter.ToAbsolute("pkg"), NugetPath = Path.Combine(OriginalDirectory, "lib/nuget.exe") // This shouldn't be required but leave it in just to ensure the test never tries to download the file from the web }; retriever.Retrieve("TestPackage", new Version(0, 0, 0, 0), "beta"); var expectedDir = PathConverter.ToAbsolute("lib/TestPackage.1.0.0-beta"); Assert.IsTrue(Directory.Exists(expectedDir), "The expected lib directory wasn't found."); }
public void Create(string name, Version version, string status) { var spec = new NugetPackageSpec(); spec.MetaData.ID = name; spec.MetaData.Version = version.ToString(); if (!String.IsNullOrEmpty(status)) { spec.MetaData.Version += "-" + status; } var helloWorldFile = "HelloWorld.txt"; File.WriteAllText( PathConverter.ToAbsolute(helloWorldFile), "Hello world" ); spec.AddFiles(helloWorldFile); spec.Save(); Packer.PackageFile(spec.FilePath); }
public string Backup(string relativeFilePath) { relativeFilePath = PathConverter.ToRelative(relativeFilePath); Console.WriteLine(""); Console.WriteLine("Backing up file:"); Console.WriteLine(" " + relativeFilePath); Console.WriteLine(""); var fromFullFilePath = String.Empty; fromFullFilePath = PathConverter.ToAbsolute(relativeFilePath); var toFilePath = Environment.CurrentDirectory + Path.DirectorySeparatorChar + "_bak" + Path.DirectorySeparatorChar + relativeFilePath; var timeStamp = String.Format( "[{0}-{1}-{2}--{3}-{4}-{5}]", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second ); var ext = Path.GetExtension(toFilePath); var toFileName = Path.GetFileNameWithoutExtension(toFilePath); toFilePath = Path.GetDirectoryName(toFilePath) + Path.DirectorySeparatorChar + toFileName + ext + Path.DirectorySeparatorChar + toFileName + "-" + timeStamp + ext + ".bak"; // Add .bak extention to disable certain files which are used based on their extension Console.WriteLine("To:"); Console.WriteLine(" " + PathConverter.ToRelative(toFilePath)); if (!Directory.Exists(Path.GetDirectoryName(toFilePath))) { Directory.CreateDirectory(Path.GetDirectoryName(toFilePath)); } File.Copy( fromFullFilePath, toFilePath ); return(toFilePath); }
public void Test_GetVersionFromPackageFileName() { var currentVersion = new Version(2, 0, 0, 0); var checker = new PackageChecker(currentVersion); var version = "1.2.3.4"; var fileName = PathConverter.ToAbsolute("pkg/csAnt/csAnt." + version + ".nupkg"); var returnedVersion = checker.GetVersionFromPackageFileName(fileName); Assert.AreEqual(version, returnedVersion.ToString(), "Wrong version."); }
public string GetPackageDir(string libDir, string packageName, Version versionQuery) { var pkgDir = String.Empty; if (versionQuery != null && versionQuery > new Version(0, 0, 0, 0)) { pkgDir = PathConverter.ToAbsolute( libDir + Path.DirectorySeparatorChar + packageName + "." + versionQuery.ToString() ); } else { var versions = new List <SemanticVersion>(); foreach (var dir in Directory.GetDirectories(PathConverter.ToAbsolute(libDir), packageName + ".*")) { var versionString = Path.GetFileName(dir).Replace(packageName, ""); versionString = versionString.Trim('.'); if (!String.IsNullOrEmpty(versionString)) { var version = new SemanticVersion(versionString); versions.Add(version); } } versions.Sort(); var latestVersion = versions[versions.Count - 1]; pkgDir = PathConverter.ToAbsolute( libDir + Path.DirectorySeparatorChar + packageName + "." + latestVersion.ToString() ); } return(pkgDir); }
public void Test_FixArgument() { // TODO: Should this be moved to FixArgumentTestFixture var testFile = PathConverter.ToAbsolute("TestFile.txt"); File.WriteAllText(testFile, "Hello world"); var starter = new ProcessStarter(); var toFileName = "Test File 2.txt"; var fixedFileName = starter.FixArgument(toFileName); var expected = "\"" + toFileName + "\""; Assert.AreEqual(expected, fixedFileName, "The argument wasn't fixed."); }
public void Test_RequiresBuild_True() { new FilesGrabber( OriginalDirectory, WorkingDirectory ).GrabOriginalFiles(); var checker = new SolutionBuildChecker(); var timeStampsFile = PathConverter.ToAbsolute("src/TimeStamps.txt"); if (File.Exists(timeStampsFile)) { File.Delete(timeStampsFile); } Assert.IsTrue(checker.RequiresBuild(CurrentDirectory)); }
public Version GetLatestPackageVersion(string packageName) { var dir = PathConverter.ToAbsolute("pkg/" + packageName); var version = new Version(0, 0, 0, 0); if (Directory.Exists(dir)) { var latestFilePath = FileNavigator.GetNewestFile(dir); if (!String.IsNullOrEmpty(latestFilePath)) { version = GetVersionFromPackageFileName(latestFilePath); } } return(version); }
public void Test_Start() { var testFile = PathConverter.ToAbsolute("TestFile.txt"); File.WriteAllText(testFile, "Hello world"); var starter = new ProcessStarter(); if (Platform.IsLinux) { starter.Start("cp", "TestFile.txt", "TestFile2.txt"); } else { throw new NotImplementedException("Windows support is yet to be implemented."); } Assert.IsTrue(File.Exists(PathConverter.ToAbsolute("TestFile2.txt")), "File wasn't copied."); }
public void Test_Install_Clone() { var installer = new LocalInstaller( OriginalDirectory, WorkingDirectory, "csAnt", true ); installer.CloneSource = OriginalDirectory; installer.Clone = true; installer.Install(); Assert.IsTrue( Directory.Exists(PathConverter.ToAbsolute(".git")), "The .git folder wasn't found." ); }
public void Test_Install_Clone() { MoveToTestProjectDir(); var installer = new Installer( CreateMockInstallerRetriever( OriginalDirectory, WorkingDirectory ) ); installer.CloneSource = OriginalDirectory; installer.Clone = true; installer.Install(); // Check that csAnt still runs new HelloWorldScriptLauncher().Launch(); Assert.IsTrue( Directory.Exists(PathConverter.ToAbsolute(".git")), "The .git folder wasn't found." ); }
public string ToAbsolute(string relativePath) { return(PathConverter.ToAbsolute(relativePath)); }
public void Test_ImportFile_FileExists() { // TODO: Overhaul test to use Importer instead of using a dummy script var script = (DummyScript)GetDummyScript(); new FilesGrabber( script.OriginalDirectory, script.CurrentDirectory ).GrabOriginalFiles(); script.IsVerbose = true; var dir = Path.GetDirectoryName(script.CurrentDirectory); var projectsDir = dir; var destinationProjectDir = projectsDir + Path.DirectorySeparatorChar + "DestinationProject"; var sourceProjectDir = projectsDir + Path.DirectorySeparatorChar + "SourceProject"; Console.WriteLine(""); Console.WriteLine("Destination project:"); Console.WriteLine(destinationProjectDir); Console.WriteLine("Source project:"); Console.WriteLine(sourceProjectDir); Console.WriteLine(""); script.EnsureDirectoryExists(destinationProjectDir); script.EnsureDirectoryExists(sourceProjectDir); // Move to source project script.Relocate(sourceProjectDir); // Create files nodes script.CreateNodes(); // Initialize git script.Git.Init(); var scriptsDir = sourceProjectDir + Path.DirectorySeparatorChar + "scripts"; var scriptFile = scriptsDir + Path.DirectorySeparatorChar + "TestScript.cs"; script.EnsureDirectoryExists(scriptsDir); var scriptContent = "after"; // Create the script file File.WriteAllText(scriptFile, scriptContent); // Add the script file to git script.Git.Add(scriptFile); // Git commit script.Git.Commit(); // Switch back to destination project script.Relocate(destinationProjectDir); // Create the required file nodes script.CreateNodes(); // Add project 2 as import script.Importer.AddImport("SourceProject", sourceProjectDir); var destinationScriptFile = destinationProjectDir + Path.DirectorySeparatorChar + "scripts" + Path.DirectorySeparatorChar + "TestScript.cs"; DirectoryChecker.EnsureDirectoryExists(Path.GetDirectoryName(destinationScriptFile)); File.WriteAllText(destinationScriptFile, "before"); // Import the file script.Importer.ImportFile("SourceProject", "scripts/TestScript.cs", "scripts", false); Assert.AreEqual("after", File.ReadAllText(destinationScriptFile), "File wasn't imported."); var bakDir = PathConverter.ToAbsolute("_bak"); // Check that the file was backed up Assert.IsTrue(Directory.Exists(bakDir)); }
public void ExportFile(string projectName, string relativePath, string destination, bool flattenHeirarchy) { if (PathConverter.IsAbsolute(relativePath)) { relativePath = PathConverter.ToRelative(relativePath); } destination = PathConverter.ToAbsolute(destination); AddImportPattern(projectName, relativePath); Console.WriteLine(""); Console.WriteLine("Exporting files..."); Console.WriteLine("Project name:"); Console.WriteLine(projectName); Console.WriteLine("Path:"); Console.WriteLine(relativePath); Console.WriteLine("Destination:"); Console.WriteLine(destination); Console.WriteLine("Flatten path:"); Console.WriteLine(flattenHeirarchy.ToString()); Console.WriteLine(""); Console.WriteLine("Files:"); if (!ImportExists(projectName)) { throw new Exception("Import project '" + projectName + "' not found."); // TODO: Create custom exception class } else { Refresh(projectName); var importedProjectDirectory = StagingDirectory + Path.DirectorySeparatorChar + projectName; Console.WriteLine(""); Console.WriteLine("Relative path:"); Console.WriteLine(relativePath); Console.WriteLine(""); foreach (var file in Finder.FindFiles(Environment.CurrentDirectory, relativePath)) { var fixedPath = PathConverter.ToRelative(relativePath); if (flattenHeirarchy) { fixedPath = Path.GetFileName(relativePath); } Console.WriteLine(""); Console.WriteLine("Fixed path:"); Console.WriteLine(fixedPath); Console.WriteLine(""); var toFile = importedProjectDirectory + Path.DirectorySeparatorChar + fixedPath; Console.WriteLine(""); Console.WriteLine("Exporting (copying) file:"); Console.WriteLine(file); Console.WriteLine("To:"); Console.WriteLine(toFile); Console.WriteLine(""); DirectoryChecker.EnsureDirectoryExists(Path.GetDirectoryName(toFile)); // TODO: Check if need. Git should be keeping backups stored so this backup shouldn't be required. /*if (File.Exists(toFile)) * { * Backup.Backup(toFile); * }*/ File.Copy(file, toFile, true); var sourcePath = File.ReadAllText(importedProjectDirectory + Path.DirectorySeparatorChar + "source.txt"); Console.WriteLine("Source path:"); Console.WriteLine(sourcePath); Git.AddTo(importedProjectDirectory, toFile); // TODO: Find a better way to get the project name var name = Path.GetFileName(WorkingDirectory); Git.CommitTo(importedProjectDirectory, "Exported from '" + name + "' project."); // Get the remote name var remoteName = Path.GetFileName(importedProjectDirectory); // Add the importable project directory as a remote to the original Git.AddRemoteTo(sourcePath, remoteName, importedProjectDirectory); // Pull changes to back to the original project Git.PullTo(sourcePath, remoteName); } } Console.WriteLine(""); Console.WriteLine("Exporting complete."); Console.WriteLine(""); }
public void Repack() { Console.WriteLine(""); Console.WriteLine("Repacking " + Path.GetFileName(AssemblyPath) + " file to include " + Dependencies.Length + " dependencies."); Console.WriteLine(""); AssemblyPath = FixPath(AssemblyPath, BuildMode); Dependencies = FixPaths(Dependencies, BuildMode); Console.WriteLine("Current directory:"); Console.WriteLine(" " + Environment.CurrentDirectory); Console.WriteLine(""); Console.WriteLine("Assembly path:"); Console.WriteLine(" " + AssemblyPath); Console.WriteLine(""); Console.WriteLine("Build mode:"); Console.WriteLine(" " + BuildMode); Console.WriteLine(""); Console.WriteLine("Dependencies:"); foreach (var dependency in Dependencies) { Console.WriteLine(" " + dependency); } Console.WriteLine(""); var outFile = PackedBinDirectory + Path.DirectorySeparatorChar + Path.GetFileName(AssemblyPath); outFile = FixPath(outFile, BuildMode); var arguments = new List <string>(); var isNewer = File.GetLastWriteTime(outFile) < File.GetLastWriteTime(PathConverter.ToAbsolute(AssemblyPath)); if (!File.Exists(outFile) || isNewer) { // Output arguments.Add("/out:" + outFile); // Target type arguments.Add("/target:" + Target); // Verbose if (IsVerbose) { arguments.Add("/verbose"); } // Assembly path arguments.Add(PathConverter.ToRelative(AssemblyPath)); // Dependencies arguments.AddRange(Dependencies); Console.WriteLine("Output file:"); Console.WriteLine(" " + outFile); Console.WriteLine(""); DirectoryChecker.EnsureDirectoryExists(Path.GetDirectoryName(PathConverter.ToAbsolute(outFile))); Starter.Start(ILRepackAssemblyPath, arguments.ToArray()); var lastWriteTime = File.GetLastWriteTime(PathConverter.ToAbsolute(AssemblyPath)); File.SetLastWriteTime(PathConverter.ToAbsolute(outFile), lastWriteTime); Console.WriteLine(""); Console.WriteLine("Repacking complete."); Console.WriteLine(""); } else { Console.WriteLine(""); Console.WriteLine("Repacked files are up to date. Skipping repack."); Console.WriteLine(""); } }