public void GrabRequiredPackages(string workingDirectory, string feedPath) { Console.WriteLine(""); Console.WriteLine("Getting required packages..."); var pkgDirs = new string[] { "pkg", "lib" }; foreach (var pkgDir in pkgDirs) { var fullPkgDir = Path.Combine(workingDirectory, pkgDir); foreach (var dir in Directory.GetDirectories(fullPkgDir)) { if (IncludeProjectPackages || !Path.GetFileName(dir).StartsWith("csAnt")) { foreach (var file in Directory.GetFiles(dir, "*.nupkg", SearchOption.AllDirectories)) { var toFile = file.Replace(fullPkgDir, feedPath); DirectoryChecker.EnsureDirectoryExists(Path.GetDirectoryName(toFile)); Console.WriteLine(" " + toFile.Replace(feedPath, "")); File.Copy(file, toFile, true); } } } } }
public void AddImportPattern(string projectName, string pattern) { var listPath = StagingDirectory + Path.DirectorySeparatorChar + projectName + Path.DirectorySeparatorChar + "patterns.txt"; var patterns = new List <string>(); pattern = pattern.Trim('/').Trim('\\'); if (File.Exists(listPath)) { patterns.AddRange(File.ReadAllLines(listPath)); } if (!patterns.Contains(pattern)) { patterns.Add(pattern); } DirectoryChecker.EnsureDirectoryExists(Path.GetDirectoryName(listPath)); File.WriteAllLines(listPath, patterns.ToArray()); }
public void ReplaceIn_DontCommit() { // Copy binary files over to test that they're skipped new FileCopier( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), WorkingDirectory ).Copy("*.dll"); var testFileName = Path.Combine(CurrentDirectory, "TestFolder/HelloWorld/TestFile.txt"); var testFileContent = "Hello World"; var searchText = "World"; var replacementText = "Universe"; DirectoryChecker.EnsureDirectoryExists(Path.GetDirectoryName(testFileName)); File.WriteAllText(testFileName, testFileContent); var replacer = new TextReplacer(); replacer.ReplaceIn(Path.Combine(CurrentDirectory, "TestFolder"), "**", searchText, replacementText, false); var newText = File.ReadAllText(testFileName); Assert.IsTrue(File.Exists(testFileName), "File name must have been changed when it shouldn't have."); Assert.IsFalse( newText.Contains(replacementText), "The replacement text was found when it shouldn't have been." ); }
public void Create() { var nuget = new NugetPacker(WorkingDirectory); nuget.Version = new Version(new VersionManager().GetVersion(WorkingDirectory)); var pkgDir = WorkingDirectory + Path.DirectorySeparatorChar + "pkg"; var specFile = pkgDir + Path.DirectorySeparatorChar + "csAnt.nuspec"; // TODO: Perform packaging in temporary directory instead of main project nuget.PackageFile(specFile); var pkgFile = FileNavigator.GetNewestFile( pkgDir + Path.DirectorySeparatorChar + "csAnt" ); var pkgToFile = FeedPath + Path.DirectorySeparatorChar + Path.GetFileName(pkgFile); DirectoryChecker.EnsureDirectoryExists(Path.GetDirectoryName(pkgToFile)); File.Copy(pkgFile, pkgToFile, true); GrabRequiredPackages(WorkingDirectory, FeedPath); }
public void MoveToTestProjectDir() { var testProjectDir = Path.GetFullPath("../TestProject"); DirectoryChecker.EnsureDirectoryExists(testProjectDir); Environment.CurrentDirectory = testProjectDir; WorkingDirectory = testProjectDir; }
public string Prepare(string setupFileName, string buildMode) { // Grab all the original files to the staging directory new FilesGrabber( OriginalDirectory, WorkingDirectory, true ).GrabOriginalFiles(); // TODO: Is this the best way to create nodes? Is this needed? new ProjectNodeCreator().CreateGroupNode(); // Build the solution new SolutionBuilder(buildMode).BuildSolution("csAnt.Tests"); // Repack the csAnt-SetUp.exe file to include dependencies new SetUpRepacker(buildMode).Repack(); // Create a test project directory var testProjectDirectory = CreateTestProjectPath(); var workingBinDirectory = WorkingDirectory + Path.DirectorySeparatorChar + "bin" + Path.DirectorySeparatorChar + buildMode + Path.DirectorySeparatorChar + "packed"; DirectoryChecker.EnsureDirectoryExists(testProjectDirectory); // Copy setup file to test project directory, ready to run new FilesGrabber( workingBinDirectory, testProjectDirectory ).GrabOriginalFiles( setupFileName ); CreateMockFeed(); // Create the path to a local copy of nuget.exe (so it doesn't get downloaded from the web) LocalNugetFilePath = WorkingDirectory + Path.DirectorySeparatorChar + "lib" + Path.DirectorySeparatorChar + "nuget.exe"; return(testProjectDirectory); }
public void Test_GetPackageDir() { var packageName = "csAnt"; var packageDir = Path.Combine(CurrentDirectory, "lib/" + packageName + ".1.2.3.4"); var generalDir = Path.Combine(CurrentDirectory, "lib/" + packageName); DirectoryChecker.EnsureDirectoryExists(packageDir); DirectoryChecker.EnsureDirectoryExists(generalDir); var unpacker = new InstallUnpacker(); var dir = unpacker.GetPackageDir("lib", packageName, new Version(0, 0, 0, 0)); Assert.AreEqual(packageDir, dir, "Wrong directory."); }
public void Download() { // TODO: Make it possible to keep this path in a config file or at least on a property var filePath = Environment.CurrentDirectory + Path.DirectorySeparatorChar + "lib" + Path.DirectorySeparatorChar + "nuget.exe"; if (IsOnline(NugetPath)) { Console.WriteLine("Downloading nuget from:"); Console.WriteLine(NugetPath); Downloader.Download(NugetPath, filePath); } else { Console.WriteLine("Copying nuget file from:"); Console.WriteLine(NugetPath); DirectoryChecker.EnsureDirectoryExists(Path.GetDirectoryName(filePath)); File.Copy(NugetPath, filePath); } }
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 ImportFile(string projectName, string relativePath, string destination, bool flattenHeirarchy) { Console.WriteLine(""); Console.WriteLine("Importing files..."); Console.WriteLine("Project name: " + projectName); Console.WriteLine("Path:"); Console.WriteLine(relativePath); if (IsVerbose) { Console.WriteLine("Destination:"); Console.WriteLine(destination); Console.WriteLine("Flatten path:"); Console.WriteLine(flattenHeirarchy.ToString()); Console.WriteLine(""); } AddImportPattern(projectName, relativePath); if (!ImportExists(projectName)) { throw new Exception("Import project '" + projectName + "' not found."); // TODO: Make a custom exception class } else { Refresh(projectName); var importDir = StagingDirectory + Path.DirectorySeparatorChar + projectName; if (Directory.Exists(importDir)) { foreach (var file in Finder.FindFiles(importDir, relativePath)) { var toFile = file.Replace(importDir, WorkingDirectory); // TODO: Implement flattenHeirarchy Console.WriteLine(""); Console.WriteLine("Copying file:"); Console.WriteLine(file); if (IsVerbose) { Console.WriteLine("To:"); Console.WriteLine(toFile); } Console.WriteLine(""); DirectoryChecker.EnsureDirectoryExists(Path.GetDirectoryName(toFile)); // TODO: Check if needed. The time checks don't seem to be necessary. //if (File.GetLastWriteTime(file) > File.GetLastWriteTime(toFile)) //{ if (File.Exists(toFile)) { Backup.Backup(toFile.Replace(importDir, "")); } File.Copy(file, toFile, true); //if (IsVerbose) // Console.WriteLine ("File is newer. Using."); //} //else if (File.GetLastWriteTime(file) == File.GetLastWriteTime(toFile)) //{ // if (IsVerbose) // Console.WriteLine ("File is same age. Skipping."); //} //else //{ // if (IsVerbose) // Console.WriteLine ("File is older. Skipping."); // } } } else { Console.WriteLine("Import directory not found: " + importDir); } } }
public void EnsureDirectoryExists( string directoryPath ) { DirectoryChecker.EnsureDirectoryExists(directoryPath); }
public string PrepareSpecifyStatus(string setupFileName, string buildMode) { // Grab all the original files new FilesGrabber( OriginalDirectory, WorkingDirectory ).GrabOriginalFiles(); var nodeManager = new ProjectNodeManager(WorkingDirectory); nodeManager.IncludeChildNodes = true; nodeManager.EnsureNodes(); var currentNode = nodeManager.State.CurrentNode; // Set the status to beta currentNode.Properties["Status"] = "beta"; currentNode.Properties["Version"] = "1.0.0.0"; currentNode.Save(); // Build the solution new SolutionBuilder(buildMode).BuildSolution("csAnt.Tests"); // Repack the csAnt-SetUp.exe file to include dependencies new SetUpRepacker(buildMode).Repack(); new FileCopier( Path.Combine(WorkingDirectory, "bin/" + BuildMode.Value + "/packed"), WorkingDirectory ).Copy("*"); // Create the package new NugetPacker() { Status = currentNode.Properties["Status"], Version = new Version(currentNode.Properties["Version"]) }.Pack(CurrentDirectory, "csAnt"); new VersionManager().IncrementVersion(currentNode, 2); // Reset the status back to alpha currentNode.Properties["Status"] = "alpha"; currentNode.Save(); // Repackage new NugetPacker() { Status = currentNode.Properties["Status"], Version = new Version(currentNode.Properties["Version"]) }.Pack(CurrentDirectory, "csAnt"); // Create a test project directory var testProjectDirectory = CreateTestProjectPath(); var workingBinDirectory = WorkingDirectory + Path.DirectorySeparatorChar + "bin" + Path.DirectorySeparatorChar + buildMode + Path.DirectorySeparatorChar + "packed"; DirectoryChecker.EnsureDirectoryExists(testProjectDirectory); // Copy setup file to test project directory, ready to run new FilesGrabber( workingBinDirectory, testProjectDirectory ).GrabOriginalFiles( setupFileName ); CreateMockFeed(); // Create the path to a local copy of nuget.exe (so it doesn't get downloaded from the web) LocalNugetFilePath = WorkingDirectory + Path.DirectorySeparatorChar + "lib" + Path.DirectorySeparatorChar + "nuget.exe"; return(testProjectDirectory); }
public void Compile(bool force, params string[] scriptNames) { // TODO: Remove binDir variable if not needed. Use ScriptAssembliesDirectory property instead var binDir = Environment.CurrentDirectory + Path.DirectorySeparatorChar + "bin" + Path.DirectorySeparatorChar + BuildMode; if (!Directory.Exists(binDir)) { Directory.CreateDirectory(binDir); } // TODO: Move to a ScriptsDirectory property var scriptsDir = Environment.CurrentDirectory + Path.DirectorySeparatorChar + "scripts"; Console.WriteLine(""); Console.WriteLine("Compiling scripts..."); if (IsVerbose) { Console.WriteLine("Scripts directory:"); Console.WriteLine(scriptsDir); Console.WriteLine("Bin directory:"); Console.WriteLine(binDir); Console.WriteLine(""); } var totalCompiled = 0; var totalFailed = 0; var totalSkipped = 0; foreach (var scriptPath in Directory.GetFiles(scriptsDir, "*.cs")) { var scriptName = Path.GetFileNameWithoutExtension(scriptPath); if (scriptNames == null || scriptNames.Length == 0 || Array.IndexOf(scriptNames, scriptName) > -1) { var assemblyFile = FileNamer.GetScriptAssemblyPath(scriptName); DirectoryChecker.EnsureDirectoryExists(FileNamer.AssembliesDirectory); Console.WriteLine(" " + scriptName); if (IsVerbose) { Console.WriteLine(" Script path:"); Console.WriteLine(" " + scriptPath); Console.WriteLine(" Assembly path:"); Console.WriteLine(" " + assemblyFile); } try { if (!File.Exists(assemblyFile) || force) { Console.WriteLine(" Compiling..."); CSScript.Compile(scriptPath, assemblyFile, BuildMode == "Debug", new string[] {}); Console.WriteLine(" Successful"); totalCompiled++; } else { Console.WriteLine(" Assembly file found. Skipping compile..."); totalSkipped++; } } catch (Exception ex) { Console.WriteLine("Script '" + scriptName + "' compile error:"); Console.WriteLine(ex.ToString()); totalFailed++; } } } Console.WriteLine(""); Console.WriteLine("Total compiled: " + totalCompiled); Console.WriteLine("Total skipped: " + totalSkipped); Console.WriteLine("Total failed: " + totalFailed); Console.WriteLine(""); Console.WriteLine("Finished!"); Console.WriteLine(""); }
public IScript ActivateScriptFromFile(string scriptPath) { if (String.IsNullOrEmpty(scriptPath)) { throw new ArgumentException("scriptPath", "A script path must be provided."); } if (!File.Exists(scriptPath)) { throw new ArgumentException("Can't find the script file: " + scriptPath); } var scriptName = Path.GetFileNameWithoutExtension(scriptPath); if (IsVerbose) { Console.WriteLine(""); Console.WriteLine("Activating script: " + scriptName); Console.WriteLine("Script path:"); Console.WriteLine(" " + scriptPath); Console.WriteLine(""); } CSScript.GlobalSettings.DefaultArguments = "/nl"; // TODO: Check if this is working //CSScript.GlobalSettings.ReportDetailedErrorInfo = IsDebug; // TODO: Check if needed var assemblyFile = FileNamer.GetScriptAssemblyPath(scriptName); DirectoryChecker.EnsureDirectoryExists(Path.GetDirectoryName(assemblyFile)); if (IsVerbose) { Console.WriteLine(""); Console.WriteLine("Assembly file..."); Console.WriteLine(" " + assemblyFile); Console.WriteLine(""); } // TODO: Check if settings are needed var scriptSettings = new Settings(); // TODO: Check if needed. // Could be causing errors with tmp dir access exception when using jenkins. // Keeping this line seems to fix errors with activation during install tests (intermittent failure) scriptSettings.InMemoryAsssembly = true; scriptSettings.HideCompilerWarnings = true; IScript script = null; // Load the script assembly try { CSScript.CacheEnabled = false; CSScript.GlobalSettings = scriptSettings; using (var helper = new AsmHelper(CSScript.Load(scriptPath))) { helper.CachingEnabled = false; script = (IScript)helper.CreateObject("*"); } // TODO: Remove if not needed // Set the assembly file last write time to the same as the script file, so it's easy to know they're matching //File.SetLastWriteTime(assemblyFile, File.GetLastWriteTime(scriptPath)); } catch (Exception ex) { throw new Exception("An error occurred when loading the '" + scriptName + "' script.", ex); } script.Construct(scriptName, ParentScript); return(script); }
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(""); } }