/// <summary> /// Robustly determines the SVN status of a path using the output of the SVN status command. /// Handles both files and directories, in the case of a directory the status of the directory only, and not all the file-system entries within it. /// Handles warnings by turning them into into the associated <see cref="ItemStatus"/> value. /// Resolves the ambiguous <see cref="ItemStatus.NotFound"/> item status by walking up the path hierarchy until an items status is found. /// </summary> public static SvnStringPathStatus StatusRobust(this SvnCommand svnCommand, AbsolutePath path) { var nonDirectoryIndicatedPath = PathUtilities.EnsurePathIsNotDirectoryIndicated(path.Value).AsAbsolutePath(); var status = svnCommand.StatusRobust_Internal(nonDirectoryIndicatedPath); if (status.ItemStatus != ItemStatus.NotFound) { return(status); } // Determine whether the item is in 1) an ignored directory or 2) an unversioned directory by walking up the path hierarchy until var parentItemStatus = ItemStatus.None; var parentPath = path; do { parentPath = PathUtilities.GetParentDirectoryPath(parentPath); var parentStatus = svnCommand.StatusRobust_Internal(parentPath); parentItemStatus = parentStatus.ItemStatus; }while (parentItemStatus == ItemStatus.NotFound); var output = new SvnStringPathStatus { Path = path.Value, ItemStatus = parentItemStatus }; return(output); }
/// <summary> /// Tests both the development and non-development secrets directory locations for whether they contain a development machine names text file with the given file name. /// </summary> public static bool DevelopmentMachineNamesTextFileExists(string developmentMachineNamesTextFileName, out string developmentMachineNamesTextFilePath) { // Order of testing locations is biased towards non-development. // Start with the non-development secrets location. var nonDevelopmentLocationForDevelopmentMachineNamesTextFile = PathUtilities.Combine(Utilities.NonDevelopmentSecretsDirectoryPathValue, developmentMachineNamesTextFileName); if (PathUtilities.ExistsFilePath(nonDevelopmentLocationForDevelopmentMachineNamesTextFile)) { developmentMachineNamesTextFilePath = nonDevelopmentLocationForDevelopmentMachineNamesTextFile; return(true); } // Then try the development secrets location. var developmentLocationForDevelopmentMachineNamesTextFile = PathUtilities.Combine(Utilities.DevelopmentSecretsDirectoryPathValue, developmentMachineNamesTextFileName); if (PathUtilities.ExistsFilePath(developmentLocationForDevelopmentMachineNamesTextFile)) { developmentMachineNamesTextFilePath = developmentLocationForDevelopmentMachineNamesTextFile; return(true); } // Else, the development machine names text file does not exist. developmentMachineNamesTextFilePath = BasePathUtilities.UnsetPathValue; return(false); }
public static string GetPropertyValue(FilePath svnExecutableFilePath, AbsolutePath path, string propertyName, ILogger logger) { logger.LogDebug($"Getting value of SVN property {propertyName} for {path}..."); var arguments = $@"propget {propertyName} ""{path}"" --xml"; var outputCollector = SvnCommandServicesProvider.Run(svnExecutableFilePath, arguments); // Parse output. var svnOutput = outputCollector.GetOutputText(); var document = XDocument.Parse(svnOutput); var properties = document.Element("properties"); if (!properties.Elements().Any()) { throw new Exception($"SVN automation failure.\nReceived:\n{svnOutput}"); } var expectedPath = PathUtilities.EnsureNonWindowsDirectorySeparator(path.Value); // Path value is converted to a non-Windows path. var property = properties.Elements("target").Where(x => x.Attribute("path").Value == expectedPath).Single().Element("property"); if (property.Attribute("name").Value != propertyName) { throw new Exception($"SVN automation failure.\nReceived:\n{svnOutput}"); } var output = property.Value; logger.LogInformation($"Got value of SVN property {propertyName} for {path}."); return(output); }
/// <summary> /// GitHub does not allow empty directories to be checked in (nor directories that only contain empty directories, i.e. recursively-empty directories). /// Thus many times there are recursively empty unversioned diretories that will be flagged as an uncommitted change, but should not be considered as uncommitted simply because they can't be committed! /// </summary> public static IEnumerable <SvnStringPathStatus> GetUncommittedChangesWithGitHubExceptions(this SvnCommand svnCommand, DirectoryPath directoryPath) { var allUncommittedStatuses = svnCommand.GetAllUncommittedChanges(directoryPath); foreach (var uncommittedStatus in allUncommittedStatuses) { // Unless it's an unversioned, recursively empty directory! var isUnversioned = uncommittedStatus.ItemStatus == ItemStatus.Unversioned; if (isUnversioned) { // Is the path a directory? var isDirectory = PathUtilities.IsDirectory(uncommittedStatus.Path); if (isDirectory) { // Is the directory recursively empty? var isDirectoryRecursivelyEmpty = PathUtilities.IsDirectoryRecursivelyEmpty(uncommittedStatus.Path); if (isDirectoryRecursivelyEmpty) { continue; // Nothing to see here. } } } yield return(uncommittedStatus); } }
public static int Update(FilePath svnExecutableFilePath, AbsolutePath path, ILogger logger) { var nonDirectoryIndicatedPath = PathUtilities.EnsurePathIsNotDirectoryIndicated(path.Value).AsAbsolutePath(); logger.LogDebug($"SVN updating {path}..."); // Use the specified path. var arguments = $@"update ""{nonDirectoryIndicatedPath}"""; // Use the non-directory indicated path. var outputCollector = SvnCommandServicesProvider.Run(svnExecutableFilePath, arguments); var lines = new List <string>(); using (var reader = outputCollector.GetOutputReader()) { while (!reader.ReadLineIsEnd(out var line)) { lines.Add(line); } } var lastLine = lines.Last(); var trimmedLastLine = lastLine.TrimEnd('.'); var tokens = trimmedLastLine.Split(' '); var revisionNumber = tokens[tokens.Length - 1]; var revision = Int32.Parse(revisionNumber); logger.LogInformation($"SVN updated {path}.\nRevision: {revision}"); return(revision); }
public static string GetSecretsFilePath(string fileName) { var secretsDirectoryPath = Utilities.SecretsDirectoryPathValue; var secretFilePath = PathUtilities.Combine(secretsDirectoryPath, fileName); return(secretFilePath); }
/// <summary> /// Returns an ASP.NET Core environment-specific JSON file-name for a base file-name and ASP.NET Core environment name. /// </summary> public static FileName GetJsonFileNameForEnvironment(FileNameWithoutExtension baseFileNameWithoutExtension, string aspNetCoreEnvironmentName) { var fileNameWithoutExtension = PathUtilities.Combine(baseFileNameWithoutExtension, aspNetCoreEnvironmentName.AsFileNameSegment()).AsFileNameWithoutExtension(); var output = PathUtilities.GetFileName(fileNameWithoutExtension, FileExtensions.Json); return(output); }
public static NuspecFileName GetNuspecFileName(PackageID packageID) { var packageFileSystemName = Utilities.GetPackageNuspecFileSystemName(packageID); var nuspecFileNameWithoutExtension = Utilities.GetNuspecFileNameWithoutExtension(packageFileSystemName); var nuspecFileName = PathUtilities.GetFileName(nuspecFileNameWithoutExtension, NuspecFileExtension.Instance).AsNuspecFileName(); return(nuspecFileName); }
public static string AppendDefaultOrganizationDirectory(string directoryPath, IOrganization organization) { var defaultOrganizationDirectoryNameValue = organization.GetDefaultDirectoryNameValue(); var output = PathUtilities.Combine(directoryPath, defaultOrganizationDirectoryNameValue); return(output); }
public static PackageID GetDefaultPackageID(ProjectFileName projectFileName) { var projectFileNameWithoutExtension = PathUtilities.GetFileNameWithoutExtension(projectFileName); var packageID = Utilities.GetDefaultPackageID(projectFileNameWithoutExtension); return(packageID); }
public static NupkgFileName GetNupkgFileName(PackageID packageID, Version version) { var packageFileSystemName = Utilities.GetPackageNupkgFileSystemName(packageID); var versionFileSystemName = Utilities.GetVersionFileSystemName(version); var nupkgFileNameWithoutExtension = Utilities.GetNupkgFileNameWithoutExtension(packageFileSystemName, versionFileSystemName); var nupkgFileName = PathUtilities.GetFileName(nupkgFileNameWithoutExtension, FileExtensions.Nupkg).AsNupkgFileName(); return(nupkgFileName); }
public static void Pack(FilePath dotnetExecutableFilePath, ProjectFilePath projectFilePath, NupkgFilePath nupkgFilePath, ILogger logger) { var packageDirectoryPath = PathUtilities.GetDirectoryPath(nupkgFilePath); // Use the pack command to get the package file-path created by dotnet. var defaultPackageFilePath = DotnetCommandServicesProvider.Pack(dotnetExecutableFilePath, projectFilePath, packageDirectoryPath, logger); // If the package file-path created by dotnet is not the same as the specified package file-path, copy the file to the new path. if (nupkgFilePath.Value != defaultPackageFilePath.Value) { File.Copy(defaultPackageFilePath.Value, nupkgFilePath.Value, true); File.Delete(defaultPackageFilePath.Value); } }
public static void CreateProjectFile(DotnetNewProjectType projectType, ProjectFilePath projectFilePath, DotnetNewConventions conventions, ILogger logger) { var projectDirectoryPath = PathUtilities.GetDirectoryPath(projectFilePath).AsProjectDirectoryPath(); var projectFileName = PathUtilities.GetFileName(projectFilePath).AsProjectFileName(); var projectFileNameWithoutExtension = PathUtilities.GetFileNameWithoutExtension(projectFileName); var projectName = conventions.ProjectNameFromProjectFileNameWithoutExtension(projectFileNameWithoutExtension); var createdProjectFilePath = DotnetCommandServicesProvider.CreateProjectFile(projectType, projectName, projectDirectoryPath, logger); // Throw an exception if the solution file-path created by dotnet new is not the one we were expecting. if (createdProjectFilePath.Value != projectFilePath.Value) { throw new Exception($"Project creation file path mismatch.\nExpected: {projectFilePath}\nCreated: {createdProjectFilePath}"); } }
/// <summary> /// Creates a solution file at the specified file-path. /// </summary> /// <remarks> /// This method feeds the solution directory-path and solution-name value required to have the dotnet new command create a solution-file at the specified path. /// </remarks> public static void CreateSolutionFile(SolutionFilePath solutionFilePath, DotnetNewConventions conventions, ILogger logger) { var solutionDirectoryPath = PathUtilities.GetDirectoryPath(solutionFilePath).AsSolutionDirectoryPath(); var solutionFileName = PathUtilities.GetFileName(solutionFilePath).AsSolutionFileName(); var solutionFileNameWithoutExtension = PathUtilities.GetFileNameWithoutExtension(solutionFileName); var solutionName = conventions.SolutionNameFromSolutionFileNameWithoutExtension(solutionFileNameWithoutExtension); var createdSolutionFilePath = DotnetCommandServicesProvider.CreateSolutionFile(solutionDirectoryPath, solutionName, logger); // Throw an exception if the solution file-path created by dotnet new is not the one we were expecting. if (createdSolutionFilePath.Value != solutionFilePath.Value) { throw new Exception($"Solution creation file path mismatch.\nExpected: {solutionFilePath}\nCreated: {createdSolutionFilePath}"); } }
public static CheckoutResult Checkout(this SvnCommand svnCommand, string repositoryUrl, string localDirectoryPath) { svnCommand.Logger.LogDebug($"SVN checkout of '{repositoryUrl}' to '{localDirectoryPath}'..."); // Need to ensure the local directory path is NOT directory indicated (does NOT end with a directory separator). var correctedLocalDirectoryPath = PathUtilities.EnsureFilePathNotDirectoryIndicated(localDirectoryPath); var arguments = SvnCommandServicesProvider.GetCheckoutArguments(repositoryUrl, correctedLocalDirectoryPath); var commandOutput = SvnCommandServicesProvider.Run(svnCommand.SvnExecutableFilePath, arguments); var lines = commandOutput.GetOutputLines().ToList(); var lastLine = lines.Last(); var lastLineTokens = lastLine.Split(' '); var revisionNumberToken = lastLineTokens.Last().TrimEnd('.'); var revisionNumber = Int32.Parse(revisionNumberToken); var entryUpdateLines = lines.ExceptLast(); var statuses = new List <EntryUpdateStatus>(); foreach (var line in entryUpdateLines) { var lineTokens = line.Split(new[] { " " }, 2, StringSplitOptions.RemoveEmptyEntries); var statusToken = lineTokens[0]; var relativePath = lineTokens[1]; var updateStatus = statusToken.ToUpdateStatus(); var status = new EntryUpdateStatus { UpdateStatus = updateStatus, RelativePath = relativePath, }; statuses.Add(status); } var result = new CheckoutResult { RevisionNumber = revisionNumber, Statuses = statuses.ToArray(), }; svnCommand.Logger.LogInformation($"SVN checkout of '{repositoryUrl}' to '{localDirectoryPath}' complete."); return(result); }
public void SetFileCopyToOutputDirectory(ProjectFilePath projectFilePath, FilePath filePath) { var fileProjectFileRelativePath = PathUtilities.GetRelativePath(projectFilePath.Value, filePath.Value); this.Logger.LogDebug($"{projectFilePath} - Setting copy to output directory for file:\n{fileProjectFileRelativePath}"); // Read the project file path in as XML. var xmlDoc = new XmlDocument(); xmlDoc.Load(projectFilePath.Value); // Create the new node. var copyToOutputDirectoryNode = xmlDoc.CreateElement("CopyToOutputDirectory"); copyToOutputDirectoryNode.InnerText = "PreserveNewest"; var noneNode = xmlDoc.CreateElement("None"); noneNode.AppendChild(copyToOutputDirectoryNode); var updateAttributeNode = xmlDoc.CreateAttribute("Update"); updateAttributeNode.Value = fileProjectFileRelativePath; noneNode.Attributes.Append(updateAttributeNode); var itemGroupNode = xmlDoc.CreateElement("ItemGroup"); itemGroupNode.AppendChild(noneNode); var projectNode = xmlDoc.ChildNodes[0]; var firstItemGroup = projectNode.ChildNodes[0]; projectNode.InsertAfter(itemGroupNode, firstItemGroup); xmlDoc.Save(projectFilePath.Value); this.Logger.LogInformation($"{projectFilePath} - Set copy to output directory for file:\n{fileProjectFileRelativePath}"); }
private static void ProcessListProjectProjectReferencesOutput(object sender, DataReceivedEventArgs e, ProjectFilePath projectFilePath, List <ProjectFilePath> projectFilePaths) { var projectDirectoryPath = PathUtilities.GetDirectoryPath(projectFilePath); var dataString = e.Data ?? String.Empty; using (var reader = new StringReader(dataString)) { while (!reader.ReadLineIsEnd(out string line)) { if (String.IsNullOrWhiteSpace(line) || line == "Project reference(s)" || line == "--------------------" || line.BeginsWith("There are no Project to Project references in project")) { continue; } var referencedProjectFileRelativePath = new FileRelativePath(line); // Project file relative paths are relative to the project directory path. var referenedProjectFilePath = PathUtilitiesExtra.GetFilePath(projectDirectoryPath, referencedProjectFileRelativePath).AsProjectFilePath(); projectFilePaths.Add(referenedProjectFilePath); } } }
public static ProjectFileName GetProjectFileName(ProjectFilePath projectFilePath) { var projectFileName = PathUtilities.GetFileName(projectFilePath).AsProjectFileName(); return(projectFileName); }
public static FileNameWithoutExtension GetNupkgFileNameWithoutExtension(PackageFileSystemName packageFileSystemName, VersionFileSystemName versionFileSystemName) { var nupkgFileNameWithoutExtension = PathUtilities.GetFileNameWithoutExtension(packageFileSystemName, versionFileSystemName); return(nupkgFileNameWithoutExtension); }
public static string AppendDropboxDirectory(string directoryPath) { var output = PathUtilities.Combine(directoryPath, Constants.DropboxDirectoryNameValue); return(output); }
public static FilePath GetDirectoryBuildPropsFilePath(ProjectDirectoryPath projectDirectoryPath) { var directoryBuildPropsFilePath = PathUtilities.Combine(projectDirectoryPath.Value, Constants.DirectoryBuildPropsFileName.Value).AsFilePath(); return(directoryBuildPropsFilePath); }
/// <summary> /// The directory containing the solution-file is the solution-directory. /// </summary> public static SolutionDirectoryPath GetSolutionDirectoryPath(SolutionFilePath solutionFilePath) { var solutionDirectoryPath = PathUtilities.GetDirectoryPath(solutionFilePath).AsSolutionDirectoryPath(); return(solutionDirectoryPath); }
/// <summary> /// The directory containing the project-directory is the solution-directory. /// </summary> public static SolutionDirectoryPath GetSolutionDirectoryPath(ProjectDirectoryPath projectDirectoryPath) { var solutionDirectoryPath = PathUtilities.GetParentDirectoryPath(projectDirectoryPath).AsSolutionDirectoryPath(); return(solutionDirectoryPath); }
public static SolutionFileName GetSolutionFileName(FileNameWithoutExtension solutionFileNameWithoutExtension) { var solutionFileName = PathUtilities.GetFileName(solutionFileNameWithoutExtension, FileExtensions.Sln).AsSolutionFileName(); return(solutionFileName); }
/// <summary> /// The directory containing the project-file is the project-directory. /// </summary> public static ProjectDirectoryPath GetProjectDirectoryPath(ProjectFilePath projectFilePath) { var projectDirectoryPath = PathUtilities.GetDirectoryPath(projectFilePath).AsProjectDirectoryPath(); return(projectDirectoryPath); }
public static ProjectFileName GetCSharpProjectFileName(FileNameWithoutExtension projectfileNameWithoutExtension) { var projectFileName = PathUtilities.GetFileName(projectfileNameWithoutExtension, CSharpProjectFileExtension.Instance).AsProjectFileName(); return(projectFileName); }