Renamed GitLink.Test to GitLink.Tests

This commit is contained in:
Geert van Horrik 2014-11-06 13:00:00 +01:00
Родитель 0b651feb0f
Коммит d0daeb211d
20 изменённых файлов: 367 добавлений и 360 удалений

Просмотреть файл

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<repositories>
<repository path="..\src\GitLink.Test\packages.config" />
<repository path="..\src\GitLink.Tests\packages.config" />
<repository path="..\src\GitLink\packages.config" />
</repositories>

Просмотреть файл

@ -5,7 +5,7 @@
// --------------------------------------------------------------------------------------------------------------------
namespace GitLink.Test
namespace GitLink.Tests
{
using Catel.Test;
using NUnit.Framework;
@ -44,6 +44,14 @@ namespace GitLink.Test
Assert.IsTrue(context.IsHelp);
}
[TestCase]
public void CorrectlyParsesSolutionFile()
{
var context = ArgumentParser.ParseArguments("solutionDirectory -u http://github.com/CatenaLogic/GitLink -f someSolution");
Assert.AreEqual("someSolution", context.SolutionFile);
}
[TestCase]
public void CorrectlyParsesUrlAndBranchName()
{

Просмотреть файл

@ -5,7 +5,7 @@
// --------------------------------------------------------------------------------------------------------------------
namespace GitLink.Test
namespace GitLink.Tests
{
using Catel.Test;
using GitLink.Providers;

Просмотреть файл

@ -5,7 +5,7 @@
// --------------------------------------------------------------------------------------------------------------------
namespace GitLink.Test.Extensions
namespace GitLink.Tests.Extensions
{
using GitLink.Providers;
using NUnit.Framework;

Просмотреть файл

@ -6,8 +6,8 @@
<ProjectGuid>{ED2B9579-59D2-40F2-BC5E-F4DC3DAB9A56}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>GitLink.Test</RootNamespace>
<AssemblyName>GitLink.Test</AssemblyName>
<RootNamespace>GitLink.Tests</RootNamespace>
<AssemblyName>GitLink.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
@ -21,7 +21,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\output\debug\Test\</OutputPath>
<OutputPath>..\..\output\debug\Tests\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
@ -29,7 +29,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\output\release\Test\</OutputPath>
<OutputPath>..\..\output\release\Tests\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>

Просмотреть файл

@ -5,7 +5,7 @@
// --------------------------------------------------------------------------------------------------------------------
namespace GitLink.Test.IntegrationTests
namespace GitLink.Tests.IntegrationTests
{
using NUnit.Framework;

Просмотреть файл

@ -5,7 +5,7 @@
// --------------------------------------------------------------------------------------------------------------------
namespace GitLink.Test.IntegrationTests
namespace GitLink.Tests.IntegrationTests
{
using NUnit.Framework;

Просмотреть файл

@ -5,7 +5,7 @@
// --------------------------------------------------------------------------------------------------------------------
namespace GitLink.Test.IntegrationTests
namespace GitLink.Tests.IntegrationTests
{
using System;
using System.Diagnostics;

Просмотреть файл

@ -12,11 +12,11 @@ using System.Runtime.InteropServices;
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("GitLink.Test")]
[assembly: AssemblyTitle("GitLink.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GitLink.Test")]
[assembly: AssemblyProduct("GitLink.Tests")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Просмотреть файл

@ -5,7 +5,7 @@
// --------------------------------------------------------------------------------------------------------------------
namespace GitLink.Test.Providers
namespace GitLink.Tests.Providers
{
using GitLink.Providers;
using NUnit.Framework;

Просмотреть файл

@ -5,7 +5,7 @@
// --------------------------------------------------------------------------------------------------------------------
namespace GitLink.Test.Providers
namespace GitLink.Tests.Providers
{
using GitLink.Providers;
using NUnit.Framework;

Просмотреть файл

@ -5,7 +5,7 @@
// --------------------------------------------------------------------------------------------------------------------
namespace GitLink.Test.Providers
namespace GitLink.Tests.Providers
{
using System;
using GitLink.Providers;

Просмотреть файл

Просмотреть файл

@ -22,9 +22,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{88214CBE-4B9
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{A5FCE4FA-083A-4814-B38C-2AED9C37647F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{D435DFD9-F741-4FCA-A65A-28B7D251983D}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{D435DFD9-F741-4FCA-A65A-28B7D251983D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitLink.Test", "GitLink.Test\GitLink.Test.csproj", "{ED2B9579-59D2-40F2-BC5E-F4DC3DAB9A56}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitLink.Tests", "GitLink.Tests\GitLink.Tests.csproj", "{ED2B9579-59D2-40F2-BC5E-F4DC3DAB9A56}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NuGet", "NuGet", "{2A773B1D-106C-4583-8021-9AC0BB3E5408}"
EndProject

Просмотреть файл

@ -1,141 +1,141 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ArgumentParser.cs" company="CatenaLogic">
// Copyright (c) 2014 - 2014 CatenaLogic. All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace GitLink
{
using System;
using System.Collections.Generic;
using System.Linq;
using Catel.Logging;
using GitLink.Providers;
public static class ArgumentParser
{
private static readonly ILog Log = LogManager.GetCurrentClassLogger();
public static Context ParseArguments(string commandLineArguments)
{
return ParseArguments(commandLineArguments.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList(),
new ProviderManager());
}
public static Context ParseArguments(params string[] commandLineArguments)
{
return ParseArguments(commandLineArguments.ToList(), new ProviderManager());
}
public static Context ParseArguments(List<string> commandLineArguments, IProviderManager providerManager)
{
var context = new Context(providerManager);
if (commandLineArguments.Count == 0)
{
Log.ErrorAndThrowException<GitLinkException>("Invalid number of arguments");
}
var firstArgument = commandLineArguments.First();
if (IsHelp(firstArgument))
{
context.IsHelp = true;
return context;
}
if (commandLineArguments.Count < 3)
{
Log.ErrorAndThrowException<GitLinkException>("Invalid number of arguments");
}
context.SolutionDirectory = firstArgument;
var namedArguments = commandLineArguments.Skip(1).ToList();
EnsureArgumentsEvenCount(commandLineArguments, namedArguments);
for (var index = 0; index < namedArguments.Count; index = index + 2)
{
var name = namedArguments[index];
var value = namedArguments[index + 1];
if (IsSwitch("l", name))
{
context.LogFile = value;
continue;
}
if (IsSwitch("c", name))
{
context.ConfigurationName = value;
continue;
}
if (IsSwitch("u", name))
{
context.TargetUrl = value;
continue;
}
if (IsSwitch("b", name))
{
context.TargetBranch = value;
continue;
}
if (IsSwitch("s", name))
{
context.ShaHash = value;
continue;
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ArgumentParser.cs" company="CatenaLogic">
// Copyright (c) 2014 - 2014 CatenaLogic. All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace GitLink
{
using System;
using System.Collections.Generic;
using System.Linq;
using Catel.Logging;
using GitLink.Providers;
public static class ArgumentParser
{
private static readonly ILog Log = LogManager.GetCurrentClassLogger();
public static Context ParseArguments(string commandLineArguments)
{
return ParseArguments(commandLineArguments.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList(),
new ProviderManager());
}
public static Context ParseArguments(params string[] commandLineArguments)
{
return ParseArguments(commandLineArguments.ToList(), new ProviderManager());
}
public static Context ParseArguments(List<string> commandLineArguments, IProviderManager providerManager)
{
var context = new Context(providerManager);
if (commandLineArguments.Count == 0)
{
Log.ErrorAndThrowException<GitLinkException>("Invalid number of arguments");
}
var firstArgument = commandLineArguments.First();
if (IsHelp(firstArgument))
{
context.IsHelp = true;
return context;
}
if (commandLineArguments.Count < 3)
{
Log.ErrorAndThrowException<GitLinkException>("Invalid number of arguments");
}
context.SolutionDirectory = firstArgument;
var namedArguments = commandLineArguments.Skip(1).ToList();
EnsureArgumentsEvenCount(commandLineArguments, namedArguments);
for (var index = 0; index < namedArguments.Count; index = index + 2)
{
var name = namedArguments[index];
var value = namedArguments[index + 1];
if (IsSwitch("l", name))
{
context.LogFile = value;
continue;
}
if (IsSwitch("f", name))
{
context.SolutionFile = value;
continue;
}
Log.ErrorAndThrowException<GitLinkException>("Could not parse command line parameter '{0}'.", name);
}
if (!string.IsNullOrEmpty(context.TargetUrl))
{
context.Provider = providerManager.GetProvider(context.TargetUrl);
}
return context;
}
private static bool IsSwitch(string switchName, string value)
{
if (value.StartsWith("-"))
{
value = value.Remove(0, 1);
}
if (value.StartsWith("/"))
{
value = value.Remove(0, 1);
}
return (string.Equals(switchName, value));
}
private static void EnsureArgumentsEvenCount(IEnumerable<string> commandLineArguments, List<string> namedArguments)
{
if (namedArguments.Count.IsOdd())
{
Log.ErrorAndThrowException<GitLinkException>("Could not parse arguments: '{0}'.", string.Join(" ", commandLineArguments));
}
}
private static bool IsHelp(string singleArgument)
{
return (singleArgument == "?") ||
IsSwitch("h", singleArgument) ||
IsSwitch("help", singleArgument) ||
IsSwitch("?", singleArgument);
}
}
if (IsSwitch("c", name))
{
context.ConfigurationName = value;
continue;
}
if (IsSwitch("u", name))
{
context.TargetUrl = value;
continue;
}
if (IsSwitch("b", name))
{
context.TargetBranch = value;
continue;
}
if (IsSwitch("s", name))
{
context.ShaHash = value;
continue;
}
if (IsSwitch("f", name))
{
context.SolutionFile = value;
continue;
}
Log.ErrorAndThrowException<GitLinkException>("Could not parse command line parameter '{0}'.", name);
}
if (!string.IsNullOrEmpty(context.TargetUrl))
{
context.Provider = providerManager.GetProvider(context.TargetUrl);
}
return context;
}
private static bool IsSwitch(string switchName, string value)
{
if (value.StartsWith("-"))
{
value = value.Remove(0, 1);
}
if (value.StartsWith("/"))
{
value = value.Remove(0, 1);
}
return (string.Equals(switchName, value));
}
private static void EnsureArgumentsEvenCount(IEnumerable<string> commandLineArguments, List<string> namedArguments)
{
if (namedArguments.Count.IsOdd())
{
Log.ErrorAndThrowException<GitLinkException>("Could not parse arguments: '{0}'.", string.Join(" ", commandLineArguments));
}
}
private static bool IsHelp(string singleArgument)
{
return (singleArgument == "?") ||
IsSwitch("h", singleArgument) ||
IsSwitch("help", singleArgument) ||
IsSwitch("?", singleArgument);
}
}
}

Просмотреть файл

@ -1,206 +1,205 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Linker.cs" company="CatenaLogic">
// Copyright (c) 2014 - 2014 CatenaLogic. All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace GitLink
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Catel;
using Catel.Logging;
using Git;
using Microsoft.Build.Evaluation;
/// <summary>
/// Class Linker.
/// </summary>
public static class Linker
{
private static readonly ILog Log = LogManager.GetCurrentClassLogger();
public static int Link(Context context)
{
int? exitCode = null;
var stopWatch = new Stopwatch();
stopWatch.Start();
context.ValidateContext();
if (!string.IsNullOrEmpty(context.LogFile))
{
var fileLogListener = new FileLogListener(context.LogFile, 25 * 1024);
fileLogListener.IgnoreCatelLogging = true;
LogManager.AddListener(fileLogListener);
}
if (!PdbStrHelper.IsPdbStrAvailable())
{
Log.Error("PdbStr is not found on the computer, please install 'Debugging Tools for Windows'");
return -1;
}
try
{
var projects = new List<Project>();
string[] solutionFiles;
if (string.IsNullOrEmpty(context.SolutionFile))
{
solutionFiles = Directory.GetFiles(context.SolutionDirectory, "*.sln", SearchOption.AllDirectories);
}
else
{
var pathToSolutionFile = Path.Combine(context.SolutionDirectory, context.SolutionFile);
if (File.Exists(pathToSolutionFile) == false)
{
Log.Error("Could not find solution file: " + pathToSolutionFile);
return -1;
}
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Linker.cs" company="CatenaLogic">
// Copyright (c) 2014 - 2014 CatenaLogic. All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
solutionFiles = new[] { pathToSolutionFile };
}
foreach (var solutionFile in solutionFiles)
{
var solutionProjects = ProjectHelper.GetProjects(solutionFile, context.ConfigurationName);
projects.AddRange(solutionProjects);
}
var provider = context.Provider;
if (provider == null)
{
Log.ErrorAndThrowException<GitLinkException>("Cannot find a matching provider for '{0}'", context.TargetUrl);
}
Log.Info("Using provider '{0}'", provider.GetType().Name);
var shaHash = context.Provider.GetShaHashOfCurrentBranch(context);
Log.Info("Using commit sha '{0}' as version stamp", shaHash);
var projectCount = projects.Count();
var failedProjects = new List<Project>();
Log.Info("Found '{0}' project(s)", projectCount);
foreach (var project in projects)
{
try
{
if (!LinkProject(context, project, shaHash))
{
failedProjects.Add(project);
}
}
catch (Exception)
{
failedProjects.Add(project);
}
}
Log.Info("All projects are done. {0} of {1} succeeded", projectCount - failedProjects.Count, projectCount);
if (failedProjects.Count > 0)
{
Log.Info(string.Empty);
Log.Info("The following projects have failed:");
Log.Indent();
foreach (var failedProject in failedProjects)
{
Log.Info("* {0}", context.GetRelativePath(failedProject.GetProjectName()));
}
Log.Unindent();
}
exitCode = (failedProjects.Count == 0) ? 0 : -1;
}
catch (GitLinkException ex)
{
Log.Error(ex, "An error occurred");
}
catch (Exception ex)
{
Log.Error(ex, "An unexpected error occurred");
}
stopWatch.Stop();
Log.Info(string.Empty);
Log.Info("Completed in '{0}'", stopWatch.Elapsed);
return exitCode ?? -1;
}
private static bool LinkProject(Context context, Project project, string shaHash)
{
Argument.IsNotNull(() => context);
Argument.IsNotNull(() => project);
try
{
var projectName = project.GetProjectName();
Log.Info("Handling project '{0}'", projectName);
Log.Indent();
var compilables = project.GetCompilableItems().Select(x => x.GetFullFileName());
var projectPdbFile = Path.GetFullPath(project.GetOutputPdbFile());
var projectStcSrvFile = Path.GetFullPath(project.GetOutputSrcSrvFile());
if (!File.Exists(projectPdbFile))
{
Log.Warning("No pdb file found for '{0}', is project built in '{1}' mode with pdb files enabled?", projectName, context.ConfigurationName);
return false;
}
Log.Info("Verifying pdb file");
var missingFiles = project.VerifyPdbFiles(compilables);
foreach (var missingFile in missingFiles)
{
Log.Warning("Missing file '{0}' or checksum '{1}' did not match", missingFile.Key, missingFile.Value);
}
var rawUrl = string.Format("{0}/{{0}}/%var2%", context.Provider.RawGitUrl);
var paths = new Dictionary<string, string>();
foreach (var compilable in compilables)
{
var relativePathForUrl = compilable.Replace(context.SolutionDirectory, string.Empty)
.Replace("\\", "/");
while (relativePathForUrl.StartsWith("/"))
{
relativePathForUrl = relativePathForUrl.Substring(1, relativePathForUrl.Length - 1);
}
paths.Add(compilable, relativePathForUrl);
}
project.CreateSrcSrv(rawUrl, shaHash, paths);
Log.Debug("Created source server link file, updating pdb file '{0}'", context.GetRelativePath(projectPdbFile));
PdbStrHelper.Execute(projectPdbFile, projectStcSrvFile);
}
catch (Exception ex)
{
Log.Warning(ex, "An error occurred while processing project '{0}'", project.GetProjectName());
throw;
}
finally
{
Log.Unindent();
Log.Info(string.Empty);
}
return true;
}
}
namespace GitLink
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Catel;
using Catel.Logging;
using Git;
using Microsoft.Build.Evaluation;
/// <summary>
/// Class Linker.
/// </summary>
public static class Linker
{
private static readonly ILog Log = LogManager.GetCurrentClassLogger();
public static int Link(Context context)
{
int? exitCode = null;
var stopWatch = new Stopwatch();
stopWatch.Start();
context.ValidateContext();
if (!string.IsNullOrEmpty(context.LogFile))
{
var fileLogListener = new FileLogListener(context.LogFile, 25 * 1024);
fileLogListener.IgnoreCatelLogging = true;
LogManager.AddListener(fileLogListener);
}
if (!PdbStrHelper.IsPdbStrAvailable())
{
Log.Error("PdbStr is not found on the computer, please install 'Debugging Tools for Windows'");
return -1;
}
try
{
var projects = new List<Project>();
string[] solutionFiles;
if (string.IsNullOrEmpty(context.SolutionFile))
{
solutionFiles = Directory.GetFiles(context.SolutionDirectory, "*.sln", SearchOption.AllDirectories);
}
else
{
var pathToSolutionFile = Path.Combine(context.SolutionDirectory, context.SolutionFile);
if (!File.Exists(pathToSolutionFile))
{
Log.Error("Could not find solution file: " + pathToSolutionFile);
return -1;
}
solutionFiles = new[] { pathToSolutionFile };
}
foreach (var solutionFile in solutionFiles)
{
var solutionProjects = ProjectHelper.GetProjects(solutionFile, context.ConfigurationName);
projects.AddRange(solutionProjects);
}
var provider = context.Provider;
if (provider == null)
{
Log.ErrorAndThrowException<GitLinkException>("Cannot find a matching provider for '{0}'", context.TargetUrl);
}
Log.Info("Using provider '{0}'", provider.GetType().Name);
var shaHash = context.Provider.GetShaHashOfCurrentBranch(context);
Log.Info("Using commit sha '{0}' as version stamp", shaHash);
var projectCount = projects.Count();
var failedProjects = new List<Project>();
Log.Info("Found '{0}' project(s)", projectCount);
foreach (var project in projects)
{
try
{
if (!LinkProject(context, project, shaHash))
{
failedProjects.Add(project);
}
}
catch (Exception)
{
failedProjects.Add(project);
}
}
Log.Info("All projects are done. {0} of {1} succeeded", projectCount - failedProjects.Count, projectCount);
if (failedProjects.Count > 0)
{
Log.Info(string.Empty);
Log.Info("The following projects have failed:");
Log.Indent();
foreach (var failedProject in failedProjects)
{
Log.Info("* {0}", context.GetRelativePath(failedProject.GetProjectName()));
}
Log.Unindent();
}
exitCode = (failedProjects.Count == 0) ? 0 : -1;
}
catch (GitLinkException ex)
{
Log.Error(ex, "An error occurred");
}
catch (Exception ex)
{
Log.Error(ex, "An unexpected error occurred");
}
stopWatch.Stop();
Log.Info(string.Empty);
Log.Info("Completed in '{0}'", stopWatch.Elapsed);
return exitCode ?? -1;
}
private static bool LinkProject(Context context, Project project, string shaHash)
{
Argument.IsNotNull(() => context);
Argument.IsNotNull(() => project);
try
{
var projectName = project.GetProjectName();
Log.Info("Handling project '{0}'", projectName);
Log.Indent();
var compilables = project.GetCompilableItems().Select(x => x.GetFullFileName());
var projectPdbFile = Path.GetFullPath(project.GetOutputPdbFile());
var projectStcSrvFile = Path.GetFullPath(project.GetOutputSrcSrvFile());
if (!File.Exists(projectPdbFile))
{
Log.Warning("No pdb file found for '{0}', is project built in '{1}' mode with pdb files enabled?", projectName, context.ConfigurationName);
return false;
}
Log.Info("Verifying pdb file");
var missingFiles = project.VerifyPdbFiles(compilables);
foreach (var missingFile in missingFiles)
{
Log.Warning("Missing file '{0}' or checksum '{1}' did not match", missingFile.Key, missingFile.Value);
}
var rawUrl = string.Format("{0}/{{0}}/%var2%", context.Provider.RawGitUrl);
var paths = new Dictionary<string, string>();
foreach (var compilable in compilables)
{
var relativePathForUrl = compilable.Replace(context.SolutionDirectory, string.Empty).Replace("\\", "/");
while (relativePathForUrl.StartsWith("/"))
{
relativePathForUrl = relativePathForUrl.Substring(1, relativePathForUrl.Length - 1);
}
paths.Add(compilable, relativePathForUrl);
}
project.CreateSrcSrv(rawUrl, shaHash, paths);
Log.Debug("Created source server link file, updating pdb file '{0}'", context.GetRelativePath(projectPdbFile));
PdbStrHelper.Execute(projectPdbFile, projectStcSrvFile);
}
catch (Exception ex)
{
Log.Warning(ex, "An error occurred while processing project '{0}'", project.GetProjectName());
throw;
}
finally
{
Log.Unindent();
Log.Info(string.Empty);
}
return true;
}
}
}