Skip to content

Commit

Permalink
Merge pull request #28 from 8T4/release/removing-graphviz
Browse files Browse the repository at this point in the history
Release/removing graphviz
  • Loading branch information
yanjustino authored Nov 20, 2021
2 parents 141c59f + 026e455 commit 3899fee
Show file tree
Hide file tree
Showing 26 changed files with 154 additions and 187 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches: [ main ]

env:
VERSION: 3.2.${{ github.run_number }}
VERSION: 4.0.${{ github.run_number }}
NUGET_INDEX: https://api.nuget.org/v3/index.json
BUILD_TYPE: Release

Expand All @@ -33,10 +33,14 @@ jobs:
- name: Build
run: dotnet build --no-restore --configuration Release -p:PackageVersion=${{env.VERSION}}

- name: Test
- name: Unit Tests
run: dotnet test ./tests/**/*.UnitTests.csproj --no-restore

- name: Integrated Tests
run: dotnet test ./tests/**/*.IntegratedTests.csproj --no-restore

- name: Publish Artifact
if: github.ref == 'refs/heads/main'
run: |
dotnet pack --no-restore --configuration ${{ env.BUILD_TYPE }} -p:PackageVersion=${{ env.VERSION }}
dotnet nuget push ./src/**/*.${{ env.VERSION }}.nupkg --api-key ${{ secrets.NUGET_KEY }} --source ${{ env.NUGET_INDEX }}
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ dotnet add package C4Sharp
### Dependencies

You need these things to run C4Sharp:
- [.NET Standard 2.1](https://docs.microsoft.com/pt-br/dotnet/standard/net-standard)
- [.NET 5.0+](https://docs.microsoft.com/pt-br/dotnet/standard/net-standard)
- [Java](https://www.java.com/en/download/)
- [Graphviz](https://plantuml.com/graphviz-dot)

### Coding

Expand Down
4 changes: 2 additions & 2 deletions samples/C4Sharp.Sample.Orders/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using C4Sharp.Diagrams;
using C4Sharp.Models.Plantuml;
using C4Sharp.Models.Plantuml.IO;

namespace C4Sharp.Sample.Orders
{
internal static class Program
{
private static void Main(string[] args)
private static void Main()
{
var diagrams = new Diagram[]
{
Expand Down
5 changes: 2 additions & 3 deletions samples/C4Sharp.Sample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using C4Sharp.Diagrams;
using C4Sharp.Models;
using C4Sharp.Models.Plantuml;
using C4Sharp.Models.Plantuml.IO;
using C4Sharp.Sample.Diagrams;

namespace C4Sharp.Sample
{
internal static class Program
{
private static void Main(string[] args)
private static void Main()
{
var diagrams = new Diagram[]
{
Expand Down
7 changes: 4 additions & 3 deletions src/C4Sharp/C4Sharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
<RepositoryUrl>https://github.com/8T4/c4sharp</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>c4, diagrams</PackageTags>
<PackageVersion>3.2.0</PackageVersion>
<PackageVersion>4.0.0</PackageVersion>
<PackageIconUrl>https://github.com/8T4/c4sharp/blob/main/LICENSE</PackageIconUrl>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<LangVersion>9</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand All @@ -34,8 +35,8 @@
<ItemGroup>
<None Remove="Resources\*.puml" />
<None Remove="Resources\plantuml.jar" />

<EmbeddedResource Include="Resources\*.puml" />
<EmbeddedResource Include="Resources\plantuml.jar" />
<EmbeddedResource Include="Resources\plantuml.jar" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/C4Sharp/Diagrams/Diagram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public abstract record Diagram
public bool LayoutWithLegend { get; set; }
public bool ShowLegend { get; set; }
public bool LayoutAsSketch { get; set; }
public string Title { get; set; }
public string? Title { get; set; }
public DiagramLayout FlowVisualization { get; set; }
public Structure[] Structures { get; set; }
public Relationship[] Relationships { get; set; }
Expand Down
17 changes: 5 additions & 12 deletions src/C4Sharp/Extensions/ResourceMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;
using C4Sharp.Models.Plantuml;
using C4Sharp.Models.Plantuml.IO;

namespace C4Sharp.Extensions
{
Expand All @@ -12,24 +12,17 @@ namespace C4Sharp.Extensions
[ExcludeFromCodeCoverage]
internal static class ResourceMethods
{
/// <summary>
/// Get Stream from plantuml.jar file
/// </summary>
/// <returns>Stream</returns>
/// <exception cref="PlantumlException"></exception>
public static Stream GetPlantumlResource() => GetResourceByName("C4Sharp.Resources.plantuml.jar");

/// <summary>
/// Get resource string content from resource file
/// </summary>
/// <param name="name">file name</param>
/// <returns>resource content</returns>
/// <exception cref="PlantumlException"></exception>
public static string GetResource(string name)
public static string GetResourceContent(string name)
{
try
{
using var stream = GetResourceByName($"C4Sharp.Resources.{name}");
using var stream = GetResourceStream(name);
using var reader = new StreamReader(stream ?? throw new InvalidOperationException());
return reader.ReadToEnd();
}
Expand All @@ -45,13 +38,13 @@ public static string GetResource(string name)
/// <param name="name"></param>
/// <returns></returns>
/// <exception cref="PlantumlException"></exception>
private static Stream GetResourceByName(string name)
public static Stream? GetResourceStream(string name)
{
try
{
return Assembly
.GetExecutingAssembly()
.GetManifestResourceStream(name);
.GetManifestResourceStream($"C4Sharp.Resources.{name}");
}
catch (Exception e)
{
Expand Down
43 changes: 0 additions & 43 deletions src/C4Sharp/FileSystem/C4SharpDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,48 +17,5 @@ internal static class C4SharpDirectory
/// Default Resource Folder Name
/// </summary>
public static string ResourcesFolderName => Path.Join("..", ".c4s");

/// <summary>
/// Load all C4_Plantuml files
/// </summary>
public static void LoadResources(string path = null)
{
var local = path is null
? Path.Join(DirectoryName, ResourcesFolderName)
: Path.Join(path, ResourcesFolderName);

LoadResource(local, "C4");
LoadResource(local, "C4_Component");
LoadResource(local, "C4_Container");
LoadResource(local, "C4_Context");
LoadResource(local, "C4_Deployment");
}

/// <summary>
/// Load C4_Plantuml file
/// </summary>
/// <param name="resourcesPath"></param>
/// <param name="resourceName"></param>
/// <exception cref="C4FileException"></exception>
private static void LoadResource(string resourcesPath, string resourceName)
{
try
{
var path = Path.Join(resourcesPath, $"{resourceName}.puml");

if (File.Exists(path))
{
return;
}

var stream = ResourceMethods.GetResource($"{resourceName}.puml");
Directory.CreateDirectory(resourcesPath);
File.WriteAllText(path, stream);
}
catch (Exception e)
{
throw new C4FileException("An exception occured while the package try loading the resource files", e);
}
}
}
}
2 changes: 1 addition & 1 deletion src/C4Sharp/Models/Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ namespace C4Sharp.Models
/// </summary>
public sealed record Component(string Alias, string Label) : Structure(Alias, Label)
{
public string Technology { get; init; }
public string? Technology { get; init; }
}
}
2 changes: 1 addition & 1 deletion src/C4Sharp/Models/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public sealed record Container(string Alias, string Label) : Structure(Alias, La
{
private readonly Dictionary<int, Container> _instances = new();
public ContainerType ContainerType{ get; init; }
public string Technology { get; init; }
public string? Technology { get; init; }
public Container this[int index] => this.GetInstance(index);

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/C4Sharp/Models/ContainerBoundary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace C4Sharp.Models
/// </summary>
public sealed record ContainerBoundary(string Alias, string Label) : Structure(Alias, Label)
{
public IEnumerable<Component> Components { get; init; }
public IEnumerable<Component> Components { get; init; } = Array.Empty<Component>();
public IEnumerable<Relationship> Relationships { get; init; } = Array.Empty<Relationship>();
}
}
4 changes: 2 additions & 2 deletions src/C4Sharp/Models/DeploymentNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace C4Sharp.Models
public sealed record DeploymentNode(string Alias, string Label) : Structure(Alias, Label)
{
public IEnumerable<DeploymentNode> Nodes { get; init; } = Array.Empty<DeploymentNode>();
public Dictionary<string, string> Properties { get; init; }
public Container Container { get; init; }
public Dictionary<string, string> Properties { get; init; } = new();
public Container? Container { get; init; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using C4Sharp.Diagrams;
using C4Sharp.FileSystem;

namespace C4Sharp.Models.Plantuml
namespace C4Sharp.Models.Plantuml.Extensions
{
/// <summary>
/// Parser Diagram to PlantUML
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using C4Sharp.Models.Relationships;

namespace C4Sharp.Models.Plantuml
namespace C4Sharp.Models.Plantuml.Extensions
{
/// <summary>
/// Parser Relationship to PlantUML
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using C4Sharp.Extensions;
using C4Sharp.Models.Relationships;

namespace C4Sharp.Models.Plantuml
namespace C4Sharp.Models.Plantuml.Extensions
{
/// <summary>
/// PlantUML Parser
Expand Down Expand Up @@ -134,19 +134,19 @@ private static string ToPumlString(this DeploymentNode deployment, int concat =
stream.AppendLine();
}

if (deployment.Properties != null)
if (deployment.Properties.Any())
{
foreach (var (key, value) in deployment.Properties)
{
stream.AppendLine($"{spaces}AddProperty(\"{key}\", \"{value}\")");
}
}

stream.AppendLine(deployment.Tags is null
stream.AppendLine(!deployment.Tags.Any()
? $"{spaces}Deployment_Node({deployment.Alias}, \"{deployment.Label}\", \"{deployment.Description}\") {{"
: $"{spaces}Deployment_Node({deployment.Alias}, \"{deployment.Label}\", \"{deployment.Description}\", $tags=\"{string.Join(',', deployment.Tags)}\") {{");

if (deployment.Nodes != null)
if (deployment.Nodes.Any())
{
foreach (var node in deployment.Nodes)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace C4Sharp.Models.Plantuml
namespace C4Sharp.Models.Plantuml.IO
{
/// <summary>
/// PlantumlException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using C4Sharp.Diagrams;
using C4Sharp.FileSystem;
using System;
using System;
using System.Collections.Generic;
using System.IO;
using C4Sharp.Diagrams;
using C4Sharp.FileSystem;
using C4Sharp.Models.Plantuml.Extensions;

namespace C4Sharp.Models.Plantuml
namespace C4Sharp.Models.Plantuml.IO
{
/// <summary>
/// PUML File Utils
Expand Down Expand Up @@ -55,7 +56,6 @@ public static void Export(this PlantumlSession session, string path, IEnumerable
{
session.Execute(path, true, "svg");
}

}

/// <summary>
Expand All @@ -70,7 +70,6 @@ private static void Save(Diagram diagram, string path, PlantumlSession session)
{
lock (Lock)
{
C4SharpDirectory.LoadResources(path);
var filePath = Path.Combine(path, $"{diagram.Slug()}.puml");
Directory.CreateDirectory(path);
File.WriteAllText(filePath, diagram.ToPumlString(session.StandardLibraryBaseUrl));
Expand Down
Loading

0 comments on commit 3899fee

Please sign in to comment.