Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Automatically detect branch name (instead of storing it in source cod…
…e) and include both branch name and commit hash in assembly info.
  • Loading branch information
dgrunwald committed Aug 30, 2010
1 parent 2fb5d59 commit 7f67d54
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -17,3 +17,4 @@ bin/
/src/Main/ICSharpCode.SharpDevelop.Sda/ICSharpCode.SharpDevelop.Sda.dll.config
/src/Main/StartUp/Project/SharpDevelop.exe.config
/src/Main/GlobalAssemblyInfo.cs
/src/AddIns/Misc/UsageDataCollector/UsageDataCollector.AddIn/AnalyticsMonitor.AppProperties.cs
@@ -0,0 +1,17 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>

using System;

namespace ICSharpCode.UsageDataCollector
{
partial class AnalyticsMonitor
{
const string BranchName = "$INSERTBRANCHNAME$";
const string CommitHash = "$INSERTCOMMITHASH$";
}
}
Expand Up @@ -22,7 +22,7 @@ namespace ICSharpCode.UsageDataCollector
/// <summary>
/// Main singleton class of the analytics. This class is thread-safe.
/// </summary>
public sealed class AnalyticsMonitor : IAnalyticsMonitor
public sealed partial class AnalyticsMonitor : IAnalyticsMonitor
{
const string UploadUrl = "http://usagedatacollector.sharpdevelop.net/upload/UploadUsageData.svc";
const string ProductName = "sharpdevelop";
Expand Down Expand Up @@ -120,10 +120,12 @@ public void OpenSession()
static IEnumerable<UsageDataEnvironmentProperty> GetAppProperties()
{
List<UsageDataEnvironmentProperty> properties = new List<UsageDataEnvironmentProperty> {
new UsageDataEnvironmentProperty { Name = "appVersion", Value = RevisionClass.FullVersion },
new UsageDataEnvironmentProperty { Name = "appVersion", Value = RevisionClass.Major + "." + RevisionClass.Minor + "." + RevisionClass.Build + "." + RevisionClass.Revision },
new UsageDataEnvironmentProperty { Name = "language", Value = ResourceService.Language },
new UsageDataEnvironmentProperty { Name = "culture", Value = CultureInfo.CurrentCulture.Name },
new UsageDataEnvironmentProperty { Name = "userAddInCount", Value = AddInTree.AddIns.Where(a => !a.IsPreinstalled).Count().ToString() }
new UsageDataEnvironmentProperty { Name = "userAddInCount", Value = AddInTree.AddIns.Where(a => !a.IsPreinstalled).Count().ToString() },
new UsageDataEnvironmentProperty { Name = "branch", Value = BranchName },
new UsageDataEnvironmentProperty { Name = "commit", Value = CommitHash }
};
string PROCESSOR_ARCHITECTURE = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432");
if (string.IsNullOrEmpty(PROCESSOR_ARCHITECTURE)) {
Expand All @@ -132,11 +134,6 @@ static IEnumerable<UsageDataEnvironmentProperty> GetAppProperties()
if (!string.IsNullOrEmpty(PROCESSOR_ARCHITECTURE)) {
properties.Add(new UsageDataEnvironmentProperty { Name = "architecture", Value = PROCESSOR_ARCHITECTURE });
}
#pragma warning disable 0162
if (RevisionClass.BranchName != null) {
properties.Add(new UsageDataEnvironmentProperty { Name = "branch", Value = RevisionClass.BranchName });
}
#pragma warning restore 0162
#if DEBUG
properties.Add(new UsageDataEnvironmentProperty { Name = "debug", Value = "true" });
#endif
Expand Down
Expand Up @@ -5,7 +5,7 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<OutputType>Library</OutputType>
<RootNamespace>UsageDataCollector.AddIn</RootNamespace>
<RootNamespace>ICSharpCode.UsageDataCollector</RootNamespace>
<AssemblyName>UsageDataCollector.AddIn</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<OutputPath>..\..\..\..\..\AddIns\Misc\UsageDataCollector\</OutputPath>
Expand Down Expand Up @@ -56,6 +56,9 @@
<Compile Include="..\..\..\..\Main\GlobalAssemblyInfo.cs">
<Link>GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="AnalyticsMonitor.AppProperties.cs">
<DependentUpon>AnalyticsMonitor.AppProperties.template</DependentUpon>
</Compile>
<Compile Include="AnalyticsMonitor.cs" />
<Compile Include="CollectedDataView.xaml.cs" />
<Compile Include="OptionPage.xaml.cs" />
Expand All @@ -67,6 +70,7 @@
<Page Include="StartPageMessage.xaml" />
</ItemGroup>
<ItemGroup>
<None Include="AnalyticsMonitor.AppProperties.template" />
<None Include="UsageDataCollector.addin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Expand Up @@ -22,6 +22,7 @@
<CodeAnalysisRules>-Microsoft.Design#CA1020;-Microsoft.Design#CA1033;-Microsoft.Performance#CA1805;-Microsoft.Performance#CA1810</CodeAnalysisRules>
<OutputPath>..\..\..\..\bin\</OutputPath>
<DocumentationFile>..\..\..\..\bin\ICSharpCode.AvalonEdit.xml</DocumentationFile>
<NoWarn>1607</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
Expand Up @@ -34,18 +34,6 @@
)]


// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0.0.0")]

[assembly: XmlnsPrefix("http://icsharpcode.net/sharpdevelop/treeview", "treeview")]

[assembly: XmlnsDefinition("http://icsharpcode.net/sharpdevelop/treeview", "ICSharpCode.TreeView")]
Expand Up @@ -112,7 +112,7 @@ internal static Version ParseVersion(string version, string hintPath)
if (version.StartsWith("@")) {
if (version == "@SharpDevelopCoreVersion") {
if (entryVersion == null)
entryVersion = new Version(RevisionClass.FullVersion);
entryVersion = new Version(RevisionClass.Major + "." + RevisionClass.Minor + "." + RevisionClass.Build + "." + RevisionClass.Revision);
return entryVersion;
}
if (hintPath != null) {
Expand Down
8 changes: 3 additions & 5 deletions src/Main/GlobalAssemblyInfo.template
Expand Up @@ -21,7 +21,8 @@ using System.Reflection;
[assembly: AssemblyCompany("ic#code")]
[assembly: AssemblyProduct("SharpDevelop")]
[assembly: AssemblyCopyright("2000-$INSERTYEAR$ AlphaSierraPapa for the SharpDevelop Team")]
[assembly: AssemblyVersion(RevisionClass.FullVersion)]
[assembly: AssemblyVersion(RevisionClass.Major + "." + RevisionClass.Minor + "." + RevisionClass.Build + "." + RevisionClass.Revision)]
[assembly: AssemblyInformationalVersion(RevisionClass.FullVersion + "-$INSERTSHORTCOMMITHASH$")]
[assembly: NeutralResourcesLanguage("en-US")]

internal static class RevisionClass
Expand All @@ -31,8 +32,5 @@ internal static class RevisionClass
public const string Build = "0";
public const string Revision = "$INSERTREVISION$";

public const string MainVersion = Major + "." + Minor;
public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision;

public const string BranchName = null;
public const string FullVersion = Major + "." + Minor + "." + Build + ".$INSERTREVISION$$INSERTBRANCHPOSTFIX$";
}
1 change: 0 additions & 1 deletion src/Main/StartUp/Project/Dialogs/SplashScreen.cs
Expand Up @@ -31,7 +31,6 @@ public class SplashScreenForm : Form
public SplashScreenForm()
{
const string versionText = "SharpDevelop"
+ (RevisionClass.BranchName != null ? "-" + RevisionClass.BranchName : "")
+ " " + RevisionClass.FullVersion
#if DEBUG
+ " (debug)"
Expand Down
4 changes: 2 additions & 2 deletions src/Main/StartUp/Project/SharpDevelopMain.cs
Expand Up @@ -158,14 +158,14 @@ static void RunApplication()
string configDirectory = ConfigurationManager.AppSettings["settingsPath"];
if (String.IsNullOrEmpty(configDirectory)) {
startup.ConfigDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"ICSharpCode/SharpDevelop" + RevisionClass.MainVersion);
"ICSharpCode/SharpDevelop" + RevisionClass.Major + "." + RevisionClass.Minor);
} else {
startup.ConfigDirectory = Path.Combine(Path.GetDirectoryName(exe.Location), configDirectory);
}

startup.DomPersistencePath = ConfigurationManager.AppSettings["domPersistencePath"];
if (string.IsNullOrEmpty(startup.DomPersistencePath)) {
startup.DomPersistencePath = Path.Combine(Path.GetTempPath(), "SharpDevelop" + RevisionClass.MainVersion);
startup.DomPersistencePath = Path.Combine(Path.GetTempPath(), "SharpDevelop" + RevisionClass.Major + "." + RevisionClass.Minor);
#if DEBUG
startup.DomPersistencePath = Path.Combine(startup.DomPersistencePath, "Debug");
#endif
Expand Down
1 change: 1 addition & 0 deletions src/Main/StartUp/Project/StartUp.csproj
Expand Up @@ -72,6 +72,7 @@
</None>
<Compile Include="..\..\GlobalAssemblyInfo.cs">
<Link>Configuration\GlobalAssemblyInfo.cs</Link>
<DependentUpon>GlobalAssemblyInfo.template</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
Expand Down
38 changes: 36 additions & 2 deletions src/Tools/UpdateAssemblyInfo/Main.cs
Expand Up @@ -47,6 +47,10 @@ class MainClass
Input = "doc/ChangeLog.template.html",
Output = "doc/ChangeLog.html"
},
new TemplateFile {
Input = "src/AddIns/Misc/UsageDataCollector/UsageDataCollector.AddIn/AnalyticsMonitor.AppProperties.template",
Output = "src/AddIns/Misc/UsageDataCollector/UsageDataCollector.AddIn/AnalyticsMonitor.AppProperties.cs"
}
};

class TemplateFile
Expand Down Expand Up @@ -86,7 +90,8 @@ public static int Main(string[] args)
"versionInfo",
new XElement("version", fullVersionNumber),
new XElement("revision", revisionNumber),
new XElement("commitHash", gitCommitHash)
new XElement("commitHash", gitCommitHash),
new XElement("branchName", gitBranchName)
));
doc.Save("REVISION");
}
Expand All @@ -108,8 +113,12 @@ static void UpdateFiles()
content = content.Replace("$INSERTVERSION$", fullVersionNumber);
content = content.Replace("$INSERTREVISION$", revisionNumber);
content = content.Replace("$INSERTCOMMITHASH$", gitCommitHash);
content = content.Replace("$INSERTSHORTCOMMITHASH$", gitCommitHash.Substring(0, 8));
content = content.Replace("$INSERTDATE$", DateTime.Now.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture));
content = content.Replace("$INSERTYEAR$", DateTime.Now.Year.ToString());
content = content.Replace("$INSERTBRANCHNAME$", gitBranchName);
bool isDefaultBrach = string.IsNullOrEmpty(gitBranchName) || gitBranchName == "master" || char.IsDigit(gitBranchName, 0);
content = content.Replace("$INSERTBRANCHPOSTFIX$", isDefaultBrach ? "" : ("-" + gitBranchName));
if (File.Exists(file.Output)) {
using (StreamReader r = new StreamReader(file.Output)) {
if (r.ReadToEnd() == content) {
Expand Down Expand Up @@ -173,12 +182,14 @@ static void SetVersionInfo(string fileName, Regex regex, string replacement)
static string revisionNumber;
static string fullVersionNumber;
static string gitCommitHash;
static string gitBranchName;

static void RetrieveRevisionNumber()
{
if (revisionNumber == null) {
if (Directory.Exists(".git")) {
ReadRevisionNumberFromGit();
ReadBranchNameFromGit();
} else {
Console.WriteLine("There's no git working copy in " + Path.GetFullPath("."));
}
Expand All @@ -192,7 +203,7 @@ static void RetrieveRevisionNumber()

static void ReadRevisionNumberFromGit()
{
ProcessStartInfo info = new ProcessStartInfo("cmd", "/c git rev-list --first-parent " + BaseCommit + "..HEAD");
ProcessStartInfo info = new ProcessStartInfo("cmd", "/c git rev-list " + BaseCommit + "..HEAD");
string path = Environment.GetEnvironmentVariable("PATH");
path += ";" + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "git\\bin");
info.EnvironmentVariables["PATH"] = path;
Expand All @@ -215,12 +226,35 @@ static void ReadRevisionNumberFromGit()
}
}

static void ReadBranchNameFromGit()
{
ProcessStartInfo info = new ProcessStartInfo("cmd", "/c git branch");
string path = Environment.GetEnvironmentVariable("PATH");
path += ";" + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "git\\bin");
info.EnvironmentVariables["PATH"] = path;
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
using (Process p = Process.Start(info)) {
string line;
gitBranchName = "(no branch)";
while ((line = p.StandardOutput.ReadLine()) != null) {
if (line.StartsWith("* ", StringComparison.Ordinal)) {
gitBranchName = line.Substring(2);
}
}
p.WaitForExit();
if (p.ExitCode != 0)
throw new Exception("git-branch exit code was " + p.ExitCode);
}
}

static void ReadRevisionFromFile()
{
try {
XDocument doc = XDocument.Load("REVISION");
revisionNumber = (string)doc.Root.Element("revision");
gitCommitHash = (string)doc.Root.Element("commitHash");
gitBranchName = (string)doc.Root.Element("branchName");
} catch (Exception e) {
Console.WriteLine(e.Message);
Console.WriteLine();
Expand Down

0 comments on commit 7f67d54

Please sign in to comment.