Browse Source

Automatically detect branch name (instead of storing it in source code) and include both branch name and commit hash in assembly info.

pull/1/head
Daniel Grunwald 15 years ago
parent
commit
7f67d54541
  1. 1
      .gitignore
  2. 17
      src/AddIns/Misc/UsageDataCollector/UsageDataCollector.AddIn/AnalyticsMonitor.AppProperties.template
  3. 13
      src/AddIns/Misc/UsageDataCollector/UsageDataCollector.AddIn/AnalyticsMonitor.cs
  4. 6
      src/AddIns/Misc/UsageDataCollector/UsageDataCollector.AddIn/UsageDataCollector.AddIn.csproj
  5. 1
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/ICSharpCode.AvalonEdit.csproj
  6. 12
      src/Libraries/SharpTreeView/ICSharpCode.TreeView/Properties/AssemblyInfo.cs
  7. 2
      src/Main/Core/Project/Src/AddInTree/AddIn/AddInReference.cs
  8. 8
      src/Main/GlobalAssemblyInfo.template
  9. 1
      src/Main/StartUp/Project/Dialogs/SplashScreen.cs
  10. 4
      src/Main/StartUp/Project/SharpDevelopMain.cs
  11. 1
      src/Main/StartUp/Project/StartUp.csproj
  12. 38
      src/Tools/UpdateAssemblyInfo/Main.cs

1
.gitignore vendored

@ -17,3 +17,4 @@ bin/
/src/Main/ICSharpCode.SharpDevelop.Sda/ICSharpCode.SharpDevelop.Sda.dll.config /src/Main/ICSharpCode.SharpDevelop.Sda/ICSharpCode.SharpDevelop.Sda.dll.config
/src/Main/StartUp/Project/SharpDevelop.exe.config /src/Main/StartUp/Project/SharpDevelop.exe.config
/src/Main/GlobalAssemblyInfo.cs /src/Main/GlobalAssemblyInfo.cs
/src/AddIns/Misc/UsageDataCollector/UsageDataCollector.AddIn/AnalyticsMonitor.AppProperties.cs

17
src/AddIns/Misc/UsageDataCollector/UsageDataCollector.AddIn/AnalyticsMonitor.AppProperties.template

@ -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$";
}
}

13
src/AddIns/Misc/UsageDataCollector/UsageDataCollector.AddIn/AnalyticsMonitor.cs

@ -22,7 +22,7 @@ namespace ICSharpCode.UsageDataCollector
/// <summary> /// <summary>
/// Main singleton class of the analytics. This class is thread-safe. /// Main singleton class of the analytics. This class is thread-safe.
/// </summary> /// </summary>
public sealed class AnalyticsMonitor : IAnalyticsMonitor public sealed partial class AnalyticsMonitor : IAnalyticsMonitor
{ {
const string UploadUrl = "http://usagedatacollector.sharpdevelop.net/upload/UploadUsageData.svc"; const string UploadUrl = "http://usagedatacollector.sharpdevelop.net/upload/UploadUsageData.svc";
const string ProductName = "sharpdevelop"; const string ProductName = "sharpdevelop";
@ -120,10 +120,12 @@ namespace ICSharpCode.UsageDataCollector
static IEnumerable<UsageDataEnvironmentProperty> GetAppProperties() static IEnumerable<UsageDataEnvironmentProperty> GetAppProperties()
{ {
List<UsageDataEnvironmentProperty> properties = new List<UsageDataEnvironmentProperty> { 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 = "language", Value = ResourceService.Language },
new UsageDataEnvironmentProperty { Name = "culture", Value = CultureInfo.CurrentCulture.Name }, 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"); string PROCESSOR_ARCHITECTURE = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432");
if (string.IsNullOrEmpty(PROCESSOR_ARCHITECTURE)) { if (string.IsNullOrEmpty(PROCESSOR_ARCHITECTURE)) {
@ -132,11 +134,6 @@ namespace ICSharpCode.UsageDataCollector
if (!string.IsNullOrEmpty(PROCESSOR_ARCHITECTURE)) { if (!string.IsNullOrEmpty(PROCESSOR_ARCHITECTURE)) {
properties.Add(new UsageDataEnvironmentProperty { Name = "architecture", Value = 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 #if DEBUG
properties.Add(new UsageDataEnvironmentProperty { Name = "debug", Value = "true" }); properties.Add(new UsageDataEnvironmentProperty { Name = "debug", Value = "true" });
#endif #endif

6
src/AddIns/Misc/UsageDataCollector/UsageDataCollector.AddIn/UsageDataCollector.AddIn.csproj

@ -5,7 +5,7 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<RootNamespace>UsageDataCollector.AddIn</RootNamespace> <RootNamespace>ICSharpCode.UsageDataCollector</RootNamespace>
<AssemblyName>UsageDataCollector.AddIn</AssemblyName> <AssemblyName>UsageDataCollector.AddIn</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<OutputPath>..\..\..\..\..\AddIns\Misc\UsageDataCollector\</OutputPath> <OutputPath>..\..\..\..\..\AddIns\Misc\UsageDataCollector\</OutputPath>
@ -56,6 +56,9 @@
<Compile Include="..\..\..\..\Main\GlobalAssemblyInfo.cs"> <Compile Include="..\..\..\..\Main\GlobalAssemblyInfo.cs">
<Link>GlobalAssemblyInfo.cs</Link> <Link>GlobalAssemblyInfo.cs</Link>
</Compile> </Compile>
<Compile Include="AnalyticsMonitor.AppProperties.cs">
<DependentUpon>AnalyticsMonitor.AppProperties.template</DependentUpon>
</Compile>
<Compile Include="AnalyticsMonitor.cs" /> <Compile Include="AnalyticsMonitor.cs" />
<Compile Include="CollectedDataView.xaml.cs" /> <Compile Include="CollectedDataView.xaml.cs" />
<Compile Include="OptionPage.xaml.cs" /> <Compile Include="OptionPage.xaml.cs" />
@ -67,6 +70,7 @@
<Page Include="StartPageMessage.xaml" /> <Page Include="StartPageMessage.xaml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="AnalyticsMonitor.AppProperties.template" />
<None Include="UsageDataCollector.addin"> <None Include="UsageDataCollector.addin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>

1
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/ICSharpCode.AvalonEdit.csproj

@ -22,6 +22,7 @@
<CodeAnalysisRules>-Microsoft.Design#CA1020;-Microsoft.Design#CA1033;-Microsoft.Performance#CA1805;-Microsoft.Performance#CA1810</CodeAnalysisRules> <CodeAnalysisRules>-Microsoft.Design#CA1020;-Microsoft.Design#CA1033;-Microsoft.Performance#CA1805;-Microsoft.Performance#CA1810</CodeAnalysisRules>
<OutputPath>..\..\..\..\bin\</OutputPath> <OutputPath>..\..\..\..\bin\</OutputPath>
<DocumentationFile>..\..\..\..\bin\ICSharpCode.AvalonEdit.xml</DocumentationFile> <DocumentationFile>..\..\..\..\bin\ICSharpCode.AvalonEdit.xml</DocumentationFile>
<NoWarn>1607</NoWarn>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>

12
src/Libraries/SharpTreeView/ICSharpCode.TreeView/Properties/AssemblyInfo.cs

@ -34,18 +34,6 @@ using System.Windows.Markup;
)] )]
// 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: XmlnsPrefix("http://icsharpcode.net/sharpdevelop/treeview", "treeview")]
[assembly: XmlnsDefinition("http://icsharpcode.net/sharpdevelop/treeview", "ICSharpCode.TreeView")] [assembly: XmlnsDefinition("http://icsharpcode.net/sharpdevelop/treeview", "ICSharpCode.TreeView")]

2
src/Main/Core/Project/Src/AddInTree/AddIn/AddInReference.cs

@ -112,7 +112,7 @@ namespace ICSharpCode.Core
if (version.StartsWith("@")) { if (version.StartsWith("@")) {
if (version == "@SharpDevelopCoreVersion") { if (version == "@SharpDevelopCoreVersion") {
if (entryVersion == null) if (entryVersion == null)
entryVersion = new Version(RevisionClass.FullVersion); entryVersion = new Version(RevisionClass.Major + "." + RevisionClass.Minor + "." + RevisionClass.Build + "." + RevisionClass.Revision);
return entryVersion; return entryVersion;
} }
if (hintPath != null) { if (hintPath != null) {

8
src/Main/GlobalAssemblyInfo.template

@ -21,7 +21,8 @@ using System.Reflection;
[assembly: AssemblyCompany("ic#code")] [assembly: AssemblyCompany("ic#code")]
[assembly: AssemblyProduct("SharpDevelop")] [assembly: AssemblyProduct("SharpDevelop")]
[assembly: AssemblyCopyright("2000-$INSERTYEAR$ AlphaSierraPapa for the SharpDevelop Team")] [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")] [assembly: NeutralResourcesLanguage("en-US")]
internal static class RevisionClass internal static class RevisionClass
@ -31,8 +32,5 @@ internal static class RevisionClass
public const string Build = "0"; public const string Build = "0";
public const string Revision = "$INSERTREVISION$"; public const string Revision = "$INSERTREVISION$";
public const string MainVersion = Major + "." + Minor; public const string FullVersion = Major + "." + Minor + "." + Build + ".$INSERTREVISION$$INSERTBRANCHPOSTFIX$";
public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision;
public const string BranchName = null;
} }

1
src/Main/StartUp/Project/Dialogs/SplashScreen.cs

@ -31,7 +31,6 @@ namespace ICSharpCode.SharpDevelop
public SplashScreenForm() public SplashScreenForm()
{ {
const string versionText = "SharpDevelop" const string versionText = "SharpDevelop"
+ (RevisionClass.BranchName != null ? "-" + RevisionClass.BranchName : "")
+ " " + RevisionClass.FullVersion + " " + RevisionClass.FullVersion
#if DEBUG #if DEBUG
+ " (debug)" + " (debug)"

4
src/Main/StartUp/Project/SharpDevelopMain.cs

@ -158,14 +158,14 @@ namespace ICSharpCode.SharpDevelop
string configDirectory = ConfigurationManager.AppSettings["settingsPath"]; string configDirectory = ConfigurationManager.AppSettings["settingsPath"];
if (String.IsNullOrEmpty(configDirectory)) { if (String.IsNullOrEmpty(configDirectory)) {
startup.ConfigDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), startup.ConfigDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"ICSharpCode/SharpDevelop" + RevisionClass.MainVersion); "ICSharpCode/SharpDevelop" + RevisionClass.Major + "." + RevisionClass.Minor);
} else { } else {
startup.ConfigDirectory = Path.Combine(Path.GetDirectoryName(exe.Location), configDirectory); startup.ConfigDirectory = Path.Combine(Path.GetDirectoryName(exe.Location), configDirectory);
} }
startup.DomPersistencePath = ConfigurationManager.AppSettings["domPersistencePath"]; startup.DomPersistencePath = ConfigurationManager.AppSettings["domPersistencePath"];
if (string.IsNullOrEmpty(startup.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 #if DEBUG
startup.DomPersistencePath = Path.Combine(startup.DomPersistencePath, "Debug"); startup.DomPersistencePath = Path.Combine(startup.DomPersistencePath, "Debug");
#endif #endif

1
src/Main/StartUp/Project/StartUp.csproj

@ -72,6 +72,7 @@
</None> </None>
<Compile Include="..\..\GlobalAssemblyInfo.cs"> <Compile Include="..\..\GlobalAssemblyInfo.cs">
<Link>Configuration\GlobalAssemblyInfo.cs</Link> <Link>Configuration\GlobalAssemblyInfo.cs</Link>
<DependentUpon>GlobalAssemblyInfo.template</DependentUpon>
</Compile> </Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

38
src/Tools/UpdateAssemblyInfo/Main.cs

@ -47,6 +47,10 @@ namespace UpdateAssemblyInfo
Input = "doc/ChangeLog.template.html", Input = "doc/ChangeLog.template.html",
Output = "doc/ChangeLog.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 class TemplateFile
@ -86,7 +90,8 @@ namespace UpdateAssemblyInfo
"versionInfo", "versionInfo",
new XElement("version", fullVersionNumber), new XElement("version", fullVersionNumber),
new XElement("revision", revisionNumber), new XElement("revision", revisionNumber),
new XElement("commitHash", gitCommitHash) new XElement("commitHash", gitCommitHash),
new XElement("branchName", gitBranchName)
)); ));
doc.Save("REVISION"); doc.Save("REVISION");
} }
@ -108,8 +113,12 @@ namespace UpdateAssemblyInfo
content = content.Replace("$INSERTVERSION$", fullVersionNumber); content = content.Replace("$INSERTVERSION$", fullVersionNumber);
content = content.Replace("$INSERTREVISION$", revisionNumber); content = content.Replace("$INSERTREVISION$", revisionNumber);
content = content.Replace("$INSERTCOMMITHASH$", gitCommitHash); 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("$INSERTDATE$", DateTime.Now.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture));
content = content.Replace("$INSERTYEAR$", DateTime.Now.Year.ToString()); 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)) { if (File.Exists(file.Output)) {
using (StreamReader r = new StreamReader(file.Output)) { using (StreamReader r = new StreamReader(file.Output)) {
if (r.ReadToEnd() == content) { if (r.ReadToEnd() == content) {
@ -173,12 +182,14 @@ namespace UpdateAssemblyInfo
static string revisionNumber; static string revisionNumber;
static string fullVersionNumber; static string fullVersionNumber;
static string gitCommitHash; static string gitCommitHash;
static string gitBranchName;
static void RetrieveRevisionNumber() static void RetrieveRevisionNumber()
{ {
if (revisionNumber == null) { if (revisionNumber == null) {
if (Directory.Exists(".git")) { if (Directory.Exists(".git")) {
ReadRevisionNumberFromGit(); ReadRevisionNumberFromGit();
ReadBranchNameFromGit();
} else { } else {
Console.WriteLine("There's no git working copy in " + Path.GetFullPath(".")); Console.WriteLine("There's no git working copy in " + Path.GetFullPath("."));
} }
@ -192,7 +203,7 @@ namespace UpdateAssemblyInfo
static void ReadRevisionNumberFromGit() 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"); string path = Environment.GetEnvironmentVariable("PATH");
path += ";" + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "git\\bin"); path += ";" + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "git\\bin");
info.EnvironmentVariables["PATH"] = path; info.EnvironmentVariables["PATH"] = path;
@ -215,12 +226,35 @@ namespace UpdateAssemblyInfo
} }
} }
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() static void ReadRevisionFromFile()
{ {
try { try {
XDocument doc = XDocument.Load("REVISION"); XDocument doc = XDocument.Load("REVISION");
revisionNumber = (string)doc.Root.Element("revision"); revisionNumber = (string)doc.Root.Element("revision");
gitCommitHash = (string)doc.Root.Element("commitHash"); gitCommitHash = (string)doc.Root.Element("commitHash");
gitBranchName = (string)doc.Root.Element("branchName");
} catch (Exception e) { } catch (Exception e) {
Console.WriteLine(e.Message); Console.WriteLine(e.Message);
Console.WriteLine(); Console.WriteLine();

Loading…
Cancel
Save