mirror of https://github.com/abpframework/abp.git
8 changed files with 247 additions and 80 deletions
@ -0,0 +1,67 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.Cli.Build |
|||
{ |
|||
public class DefaultBuildProjectListSorter : IBuildProjectListSorter, ITransientDependency |
|||
{ |
|||
public List<DotNetProjectInfo> SortByDependencies( |
|||
List<DotNetProjectInfo> source, |
|||
IEqualityComparer<DotNetProjectInfo> comparer = null) |
|||
{ |
|||
/* See: http://www.codeproject.com/Articles/869059/Topological-sorting-in-Csharp
|
|||
* http://en.wikipedia.org/wiki/Topological_sorting
|
|||
*/ |
|||
|
|||
var sorted = new List<DotNetProjectInfo>(); |
|||
var visited = new Dictionary<DotNetProjectInfo, bool>(comparer); |
|||
|
|||
foreach (var item in source) |
|||
{ |
|||
SortByDependenciesVisit(source, item, sorted, visited); |
|||
} |
|||
|
|||
return sorted; |
|||
} |
|||
|
|||
private void SortByDependenciesVisit( |
|||
List<DotNetProjectInfo> source, |
|||
DotNetProjectInfo item, |
|||
List<DotNetProjectInfo> sorted, |
|||
Dictionary<DotNetProjectInfo, bool> visited) |
|||
{ |
|||
bool inProcess; |
|||
var alreadyVisited = visited.TryGetValue(item, out inProcess); |
|||
|
|||
if (alreadyVisited) |
|||
{ |
|||
if (inProcess) |
|||
{ |
|||
throw new ArgumentException("Cyclic dependency found! Item: " + item); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
visited[item] = true; |
|||
|
|||
var dependencies = item.Dependencies; |
|||
if (dependencies != null) |
|||
{ |
|||
foreach (var dependency in dependencies) |
|||
{ |
|||
var dependencyItem = source.FirstOrDefault(e => e.CsProjPath == dependency.CsProjPath); |
|||
if (dependencyItem != null) |
|||
{ |
|||
SortByDependenciesVisit(source, dependencyItem, sorted, visited); |
|||
} |
|||
} |
|||
} |
|||
|
|||
visited[item] = false; |
|||
sorted.Add(item); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.Cli.Build |
|||
{ |
|||
public interface IBuildProjectListSorter |
|||
{ |
|||
List<DotNetProjectInfo> SortByDependencies( |
|||
List<DotNetProjectInfo> source, |
|||
IEqualityComparer<DotNetProjectInfo> comparer = null); |
|||
} |
|||
} |
|||
@ -0,0 +1,86 @@ |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using Shouldly; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.Cli.Build |
|||
{ |
|||
public class GitRepositoryBuildStatus_Tests : AbpCliTestBase |
|||
{ |
|||
[Fact] |
|||
public void Add_New_Build_Status_Test() |
|||
{ |
|||
var existingBuildStatus = new GitRepositoryBuildStatus("volo", "dev") |
|||
{ |
|||
SucceedProjects = new List<DotNetProjectBuildStatus> |
|||
{ |
|||
new DotNetProjectBuildStatus |
|||
{ |
|||
CsProjPath = "project1.csproj", |
|||
CommitId = "1" |
|||
} |
|||
} |
|||
}; |
|||
|
|||
var newBuildStatus = new GitRepositoryBuildStatus( |
|||
existingBuildStatus.RepositoryName, |
|||
existingBuildStatus.BranchName |
|||
) |
|||
{ |
|||
SucceedProjects = new List<DotNetProjectBuildStatus> |
|||
{ |
|||
new DotNetProjectBuildStatus |
|||
{ |
|||
CsProjPath = "project2.csproj", |
|||
CommitId = "2" |
|||
} |
|||
} |
|||
}; |
|||
|
|||
existingBuildStatus.MergeWith(newBuildStatus); |
|||
|
|||
existingBuildStatus.SucceedProjects.Count.ShouldBe(2); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Update_Existing_Build_Status_Test() |
|||
{ |
|||
var existingBuildStatus = new GitRepositoryBuildStatus("volo", "dev") |
|||
{ |
|||
SucceedProjects = new List<DotNetProjectBuildStatus> |
|||
{ |
|||
new DotNetProjectBuildStatus |
|||
{ |
|||
CsProjPath = "project1.csproj", |
|||
CommitId = "1" |
|||
} |
|||
} |
|||
}; |
|||
|
|||
var newBuildStatus = new GitRepositoryBuildStatus( |
|||
existingBuildStatus.RepositoryName, |
|||
existingBuildStatus.BranchName |
|||
) |
|||
{ |
|||
SucceedProjects = new List<DotNetProjectBuildStatus> |
|||
{ |
|||
new DotNetProjectBuildStatus |
|||
{ |
|||
CsProjPath = "project1.csproj", |
|||
CommitId = "2" |
|||
}, |
|||
new DotNetProjectBuildStatus |
|||
{ |
|||
CsProjPath = "project2.csproj", |
|||
CommitId = "2" |
|||
} |
|||
} |
|||
}; |
|||
|
|||
existingBuildStatus.MergeWith(newBuildStatus); |
|||
existingBuildStatus.SucceedProjects.Count.ShouldBe(2); |
|||
existingBuildStatus.GetSelfOrChild("volo").SucceedProjects.First(p => p.CsProjPath == "project1.csproj").CommitId.ShouldBe("2"); |
|||
existingBuildStatus.GetSelfOrChild("volo").SucceedProjects.First(p => p.CsProjPath == "project2.csproj").CommitId.ShouldBe("2"); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue