public static VersionVariables GetVersion(string directory, Authentication authentication, bool noFetch, IFileSystem fileSystem) { var gitDir = GitDirFinder.TreeWalkForDotGitDir(directory); using (var repo = RepositoryLoader.GetRepo(gitDir)) { var ticks = DirectoryDateFinder.GetLastDirectoryWrite(directory); var key = string.Format("{0}:{1}:{2}", repo.Head.CanonicalName, repo.Head.Tip.Sha, ticks); CachedVersion result; if (versionCacheVersions.TryGetValue(key, out result)) { if (result.Timestamp != ticks) { Logger.WriteInfo("Change detected. flushing cache."); result.VersionVariables = ExecuteCore.ExecuteGitVersion(fileSystem, null, null, authentication, null, noFetch, directory, null); } return(result.VersionVariables); } Logger.WriteInfo("Version not in cache. Calculating version."); return((versionCacheVersions[key] = new CachedVersion { VersionVariables = ExecuteCore.ExecuteGitVersion(fileSystem, null, null, authentication, null, noFetch, directory, null), Timestamp = ticks }).VersionVariables); } }
public static bool TryGetVersion(string directory, out CachedVersion versionAndBranch, Config configuration) { var gitDirectory = GitDirFinder.TreeWalkForGitDir(directory); if (string.IsNullOrEmpty(gitDirectory)) { var message = "No .git directory found in provided solution path. This means the assembly may not be versioned correctly. " + "To fix this warning either clone the repository using git or remove the `GitVersionTask` nuget package. " + "To temporarily work around this issue add a AssemblyInfo.cs with an appropriate `AssemblyVersionAttribute`. " + "If it is detected that this build is occurring on a CI server an error may be thrown."; Logger.WriteWarning(message); versionAndBranch = null; return(false); } if (!processedDirectories.Contains(directory)) { processedDirectories.Add(directory); var authentication = new Authentication(); foreach (var buildServer in BuildServerList.GetApplicableBuildServers(authentication)) { Logger.WriteInfo(string.Format("Executing PerformPreProcessingSteps for '{0}'.", buildServer.GetType().Name)); buildServer.PerformPreProcessingSteps(gitDirectory); } } versionAndBranch = VersionCache.GetVersion(gitDirectory, configuration); return(true); }
public static VersionVariables GetVersion(string directory, Authentication authentication, bool noFetch, IFileSystem fileSystem) { var gitDir = GitDirFinder.TreeWalkForDotGitDir(directory); using (var repo = RepositoryLoader.GetRepo(gitDir)) { var ticks = DirectoryDateFinder.GetLastDirectoryWrite(directory); var key = string.Format("{0}:{1}:{2}", repo.Head.CanonicalName, repo.Head.Tip.Sha, ticks); CachedVersion result; if (versionCacheVersions.TryGetValue(key, out result)) { if (result.Timestamp != ticks) { Logger.WriteInfo("Change detected. flushing cache."); result.VersionVariables = ExecuteCore.ExecuteGitVersion(fileSystem, null, null, authentication, null, noFetch, directory, null); } return result.VersionVariables; } Logger.WriteInfo("Version not in cache. Calculating version."); return (versionCacheVersions[key] = new CachedVersion { VersionVariables = ExecuteCore.ExecuteGitVersion(fileSystem, null, null, authentication, null, noFetch, directory, null), Timestamp = ticks }).VersionVariables; } }
/// <summary> /// 单个资源更新加载完成 /// </summary> /// <param name="flag"></param> /// <param name="name"></param> private void OnResItemUpdated(bool flag, string name) { if (CachedVersion != default) { CachedVersion.RemoveUpdate(name); float min = CachedVersion.UpdatingLoaded; float max = CachedVersion.UpdatingMax; bool isCompleted = min >= max; UpdateHandler?.Invoke(isCompleted, isCompleted ? 1f : min / max); bool isFinished = min >= max; if (isFinished) { CachedVersion.res_version = mRemoteResVersion; CachedVersion.WriteAsCached(); CachedVersion.ResetUpdatingsCount(); } else { } } else { } }
public void CacheResVersion(bool isExit) { if (CachedVersion != default) { if (CachedVersion.resVersionType == ResDataVersionType.Cached) { CachedVersion?.WriteAsCached(); } else { } if (isExit) { CachedVersion.Clean(); CachedVersion = default; } else { } } else { } }
public static CachedVersion GetVersion(string gitDirectory) { using (var repo = RepositoryLoader.GetRepo(gitDirectory)) { var ticks = DirectoryDateFinder.GetLastDirectoryWrite(gitDirectory); var key = string.Format("{0}:{1}:{2}", repo.Head.CanonicalName, repo.Head.Tip.Sha, ticks); CachedVersion cachedVersion; if (versionCacheVersions.TryGetValue(key, out cachedVersion)) { if (cachedVersion.Timestamp != ticks) { Logger.WriteInfo("Change detected. flushing cache."); cachedVersion.SemanticVersion = GitVersionFinder.GetSemanticVersion(repo); cachedVersion.MasterReleaseDate = LastVersionOnMasterFinder.Execute(repo, repo.Head.Tip); } return(cachedVersion); } Logger.WriteInfo("Version not in cache. Calculating version."); //TODO: cope with githubflow //if (GitVersionFinder.ShouldGitHubFlowVersioningSchemeApply(repo)) //{ // return rd; //} return(versionCacheVersions[key] = new CachedVersion { SemanticVersion = GitVersionFinder.GetSemanticVersion(repo), MasterReleaseDate = LastVersionOnMasterFinder.Execute(repo, repo.Head.Tip), Timestamp = ticks }); } }
public static CachedVersion GetVersion(string gitDirectory, Config configuration) { using (var repo = RepositoryLoader.GetRepo(gitDirectory)) { var versionFinder = new GitVersionFinder(); var context = new GitVersionContext(repo, configuration); var ticks = DirectoryDateFinder.GetLastDirectoryWrite(gitDirectory); var key = string.Format("{0}:{1}:{2}", repo.Head.CanonicalName, repo.Head.Tip.Sha, ticks); CachedVersion cachedVersion; if (versionCacheVersions.TryGetValue(key, out cachedVersion)) { if (cachedVersion.Timestamp != ticks) { Logger.WriteInfo("Change detected. flushing cache."); cachedVersion.SemanticVersion = versionFinder.FindVersion(context); cachedVersion.MasterReleaseDate = LastMinorVersionFinder.Execute(repo, new Config(), repo.Head.Tip); } return(cachedVersion); } Logger.WriteInfo("Version not in cache. Calculating version."); return(versionCacheVersions[key] = new CachedVersion { SemanticVersion = versionFinder.FindVersion(context), MasterReleaseDate = LastMinorVersionFinder.Execute(repo, new Config(), repo.Head.Tip), Timestamp = ticks }); } }
public static bool TryGetVersion(string directory, out CachedVersion versionAndBranch, Config configuration) { var gitDirectory = GitDirFinder.TreeWalkForGitDir(directory); if (string.IsNullOrEmpty(gitDirectory)) { var message = "No .git directory found in provided solution path. This means the assembly may not be versioned correctly. " + "To fix this warning either clone the repository using git or remove the `GitVersionTask` nuget package. " + "To temporarily work around this issue add a AssemblyInfo.cs with an appropriate `AssemblyVersionAttribute`. " + "If it is detected that this build is occurring on a CI server an error may be thrown."; Logger.WriteWarning(message); versionAndBranch = null; return false; } if (!processedDirectories.Contains(directory)) { processedDirectories.Add(directory); var authentication = new Authentication(); foreach (var buildServer in BuildServerList.GetApplicableBuildServers(authentication)) { Logger.WriteInfo(string.Format("Executing PerformPreProcessingSteps for '{0}'.", buildServer.GetType().Name)); buildServer.PerformPreProcessingSteps(gitDirectory); } } versionAndBranch = VersionCache.GetVersion(gitDirectory, configuration); return true; }
public static CachedVersion GetVersion(string gitDirectory, Config configuration) { using (var repo = RepositoryLoader.GetRepo(gitDirectory)) { var versionFinder = new GitVersionFinder(); var context = new GitVersionContext(repo, configuration); var ticks = DirectoryDateFinder.GetLastDirectoryWrite(gitDirectory); var key = string.Format("{0}:{1}:{2}", repo.Head.CanonicalName, repo.Head.Tip.Sha, ticks); CachedVersion cachedVersion; if (versionCacheVersions.TryGetValue(key, out cachedVersion)) { if (cachedVersion.Timestamp != ticks) { Logger.WriteInfo("Change detected. flushing cache."); cachedVersion.SemanticVersion = versionFinder.FindVersion(context); cachedVersion.MasterReleaseDate = LastMinorVersionFinder.Execute(repo, new Config(), repo.Head.Tip); } return cachedVersion; } Logger.WriteInfo("Version not in cache. Calculating version."); return versionCacheVersions[key] = new CachedVersion { SemanticVersion = versionFinder.FindVersion(context), MasterReleaseDate = LastMinorVersionFinder.Execute(repo, new Config(), repo.Head.Tip), Timestamp = ticks }; } }
private void OnLoadComplete(bool success, Loader.Loader target) { if (success) { string json = target.TextData; target.Dispose(); ResDataVersion remoteVersions = JsonUtility.FromJson <ResDataVersion>(json); remoteVersions.resVersionType = ResDataVersionType.Remote; CreateVersionsCached(ref remoteVersions); RemoteAppVersion = remoteVersions.app_version; if (VersionInvalidHandler != default) { bool flag = VersionInvalidHandler(); if (flag) { #if LOG_CLIENT_VERSIONING "warning:There have a newer App inistaller.".Log(); #endif return; } else { } } else { } mRemoteResVersion = remoteVersions.res_version; List <ResVersion> resUpdate = CachedVersion.CheckUpdates(Versions, ref remoteVersions); CachedVersion.WriteAsCached(); #if LOG_CLIENT_VERSIONING "log:Remote res update count is {0}".Log(resUpdate.Count.ToString()); "log:UpdateHandler is null: {0}".Log((UpdateHandler == default).ToString()); #endif if (resUpdate.Count == 0) { UpdateHandler?.Invoke(true, 1f); } else { StartLoadPatchRes(ref resUpdate); } } else { "error: Load remote version failed, url is {0}".Log(target.Url); } }
public void WriteIntegrationParameters(CachedVersion cachedVersion, IEnumerable <IBuildServer> applicableBuildServers, VersionVariables variables) { foreach (var buildServer in applicableBuildServers) { logger.LogInfo(string.Format("Executing GenerateSetVersionMessage for '{0}'.", buildServer.GetType().Name)); logger.LogInfo(buildServer.GenerateSetVersionMessage(cachedVersion.SemanticVersion.ToString())); logger.LogInfo(string.Format("Executing GenerateBuildLogOutput for '{0}'.", buildServer.GetType().Name)); foreach (var buildParameter in BuildOutputFormatter.GenerateBuildLogOutput(buildServer, variables)) { logger.LogInfo(buildParameter); } } }
void CreateTempAssemblyInfo(CachedVersion semanticVersion) { var versioningScheme = GetAssemblyVersioningScheme(); var assemblyInfoBuilder = new AssemblyInfoBuilder { CachedVersion = semanticVersion, AssemblyVersioningScheme = versioningScheme, }; var assemblyInfo = assemblyInfoBuilder.GetAssemblyInfoText(); var tempFileName = string.Format("AssemblyInfo_{0}_{1}.g.cs", Path.GetFileNameWithoutExtension(ProjectFile), Path.GetRandomFileName()); AssemblyInfoTempFilePath = Path.Combine(TempFileTracker.TempPath, tempFileName); File.WriteAllText(AssemblyInfoTempFilePath, assemblyInfo); }
void CreateTempAssemblyInfo(CachedVersion semanticVersion, EffectiveConfiguration configuration) { if (IntermediateOutputPath == null) { var tempFileName = string.Format("AssemblyInfo_{0}_{1}.g.cs", Path.GetFileNameWithoutExtension(ProjectFile), Path.GetRandomFileName()); AssemblyInfoTempFilePath = Path.Combine(TempFileTracker.TempPath, tempFileName); } else { AssemblyInfoTempFilePath = Path.Combine(IntermediateOutputPath, "GitVersionTaskAssemblyInfo.g.cs"); } var assemblyInfoBuilder = new AssemblyInfoBuilder { CachedVersion = semanticVersion }; var assemblyInfo = assemblyInfoBuilder.GetAssemblyInfoText(configuration); File.WriteAllText(AssemblyInfoTempFilePath, assemblyInfo); }
public static VersionAndBranch GetVersion(string gitDirectory) { using (var repo = RepositoryLoader.GetRepo(gitDirectory)) { var branch = repo.Head; if (branch.Tip == null) { throw new ErrorException("No Tip found. Has repo been initialize?"); } var ticks = DirectoryDateFinder.GetLastDirectoryWrite(gitDirectory); var key = string.Format("{0}:{1}:{2}", repo.Head.CanonicalName, repo.Head.Tip.Sha, ticks); CachedVersion cachedVersion; VersionAndBranch versionAndBranch; if (versionCacheVersions.TryGetValue(key, out cachedVersion)) { Logger.WriteInfo("Version read from cache."); if (cachedVersion.Timestamp == ticks) { versionAndBranch = cachedVersion.VersionAndBranch; } else { Logger.WriteInfo("Change detected. flushing cache."); versionAndBranch = cachedVersion.VersionAndBranch = GetSemanticVersion(repo); } } else { Logger.WriteInfo("Version not in cache. Calculating version."); versionAndBranch = GetSemanticVersion(repo); versionCacheVersions[key] = new CachedVersion { VersionAndBranch = versionAndBranch, Timestamp = ticks }; } return versionAndBranch; } }