Skip to content

Commit ef5d1c5

Browse files
authored
Linux support in ci (#15)
* extended output on failed verapdf execution * fixed error message creation code * fixed linux testsetup * nonfunctional changes * dropped things that didnt do anything * dropped unused variable * Added notes about dependencies * Moved forward to async implementation, Fixed some compile warnings * Updated ubuntu 20.04 cook book * Major version increased
1 parent 7098c3d commit ef5d1c5

21 files changed

+446
-138
lines changed

.editorconfig

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
# Remove the line below if you want to inherit .editorconfig settings from higher directories
2+
root = true
3+
4+
# C# files
5+
[*.cs]
6+
7+
#### Core EditorConfig Options ####
8+
9+
# Indentation and spacing
10+
indent_size = 4
11+
indent_style = space
12+
tab_width = 4
13+
14+
# New line preferences
15+
end_of_line = crlf
16+
insert_final_newline = false
17+
18+
#### .NET Coding Conventions ####
19+
20+
# Organize usings
21+
dotnet_separate_import_directive_groups = false
22+
dotnet_sort_system_directives_first = false
23+
24+
# this. and Me. preferences
25+
dotnet_style_qualification_for_event = false:silent
26+
dotnet_style_qualification_for_field = false:silent
27+
dotnet_style_qualification_for_method = false:silent
28+
dotnet_style_qualification_for_property = false:silent
29+
30+
# Language keywords vs BCL types preferences
31+
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
32+
dotnet_style_predefined_type_for_member_access = true:silent
33+
34+
# Parentheses preferences
35+
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
36+
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
37+
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
38+
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
39+
40+
# Modifier preferences
41+
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
42+
43+
# Expression-level preferences
44+
dotnet_style_coalesce_expression = true:suggestion
45+
dotnet_style_collection_initializer = true:suggestion
46+
dotnet_style_explicit_tuple_names = true:suggestion
47+
dotnet_style_null_propagation = true:suggestion
48+
dotnet_style_object_initializer = true:suggestion
49+
dotnet_style_prefer_auto_properties = true:silent
50+
dotnet_style_prefer_compound_assignment = true:suggestion
51+
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
52+
dotnet_style_prefer_conditional_expression_over_return = true:silent
53+
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
54+
dotnet_style_prefer_inferred_tuple_names = true:suggestion
55+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
56+
dotnet_style_prefer_simplified_interpolation = true:suggestion
57+
58+
# Field preferences
59+
dotnet_style_readonly_field = true:suggestion
60+
61+
# Parameter preferences
62+
dotnet_code_quality_unused_parameters = all:suggestion
63+
64+
#### C# Coding Conventions ####
65+
66+
# var preferences
67+
csharp_style_var_elsewhere = true:silent
68+
csharp_style_var_for_built_in_types = true:silent
69+
csharp_style_var_when_type_is_apparent = true:silent
70+
71+
# Expression-bodied members
72+
csharp_style_expression_bodied_accessors = true:silent
73+
csharp_style_expression_bodied_constructors = false:silent
74+
csharp_style_expression_bodied_indexers = true:silent
75+
csharp_style_expression_bodied_lambdas = true:silent
76+
csharp_style_expression_bodied_local_functions = false:silent
77+
csharp_style_expression_bodied_methods = false:silent
78+
csharp_style_expression_bodied_operators = false:silent
79+
csharp_style_expression_bodied_properties = true:silent
80+
81+
# Pattern matching preferences
82+
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
83+
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
84+
csharp_style_prefer_switch_expression = true:suggestion
85+
86+
# Null-checking preferences
87+
csharp_style_conditional_delegate_call = true:suggestion
88+
89+
# Modifier preferences
90+
csharp_prefer_static_local_function = true:suggestion
91+
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:silent
92+
93+
# Code-block preferences
94+
csharp_prefer_braces = true:silent
95+
csharp_prefer_simple_using_statement = true:suggestion
96+
97+
# Expression-level preferences
98+
csharp_prefer_simple_default_expression = true:suggestion
99+
csharp_style_deconstructed_variable_declaration = true:suggestion
100+
csharp_style_inlined_variable_declaration = true:suggestion
101+
csharp_style_pattern_local_over_anonymous_function = true:suggestion
102+
csharp_style_prefer_index_operator = true:suggestion
103+
csharp_style_prefer_range_operator = true:suggestion
104+
csharp_style_throw_expression = true:suggestion
105+
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
106+
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
107+
108+
# 'using' directive preferences
109+
csharp_using_directive_placement = outside_namespace:silent
110+
111+
#### C# Formatting Rules ####
112+
113+
# New line preferences
114+
csharp_new_line_before_catch = true
115+
csharp_new_line_before_else = true
116+
csharp_new_line_before_finally = true
117+
csharp_new_line_before_members_in_anonymous_types = true
118+
csharp_new_line_before_members_in_object_initializers = true
119+
csharp_new_line_before_open_brace = all
120+
csharp_new_line_between_query_expression_clauses = true
121+
122+
# Indentation preferences
123+
csharp_indent_block_contents = true
124+
csharp_indent_braces = false
125+
csharp_indent_case_contents = true
126+
csharp_indent_case_contents_when_block = true
127+
csharp_indent_labels = one_less_than_current
128+
csharp_indent_switch_labels = true
129+
130+
# Space preferences
131+
csharp_space_after_cast = false
132+
csharp_space_after_colon_in_inheritance_clause = true
133+
csharp_space_after_comma = true
134+
csharp_space_after_dot = false
135+
csharp_space_after_keywords_in_control_flow_statements = true
136+
csharp_space_after_semicolon_in_for_statement = true
137+
csharp_space_around_binary_operators = before_and_after
138+
csharp_space_around_declaration_statements = false
139+
csharp_space_before_colon_in_inheritance_clause = true
140+
csharp_space_before_comma = false
141+
csharp_space_before_dot = false
142+
csharp_space_before_open_square_brackets = false
143+
csharp_space_before_semicolon_in_for_statement = false
144+
csharp_space_between_empty_square_brackets = false
145+
csharp_space_between_method_call_empty_parameter_list_parentheses = false
146+
csharp_space_between_method_call_name_and_opening_parenthesis = false
147+
csharp_space_between_method_call_parameter_list_parentheses = false
148+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
149+
csharp_space_between_method_declaration_name_and_open_parenthesis = false
150+
csharp_space_between_method_declaration_parameter_list_parentheses = false
151+
csharp_space_between_parentheses = false
152+
csharp_space_between_square_brackets = false
153+
154+
# Wrapping preferences
155+
csharp_preserve_single_line_blocks = true
156+
csharp_preserve_single_line_statements = true
157+
158+
#### Naming styles ####
159+
160+
# Naming rules
161+
162+
dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
163+
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
164+
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
165+
166+
dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
167+
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
168+
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
169+
170+
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
171+
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
172+
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
173+
174+
# Symbol specifications
175+
176+
dotnet_naming_symbols.interface.applicable_kinds = interface
177+
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
178+
dotnet_naming_symbols.interface.required_modifiers =
179+
180+
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
181+
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
182+
dotnet_naming_symbols.types.required_modifiers =
183+
184+
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
185+
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
186+
dotnet_naming_symbols.non_field_members.required_modifiers =
187+
188+
# Naming styles
189+
190+
dotnet_naming_style.pascal_case.required_prefix =
191+
dotnet_naming_style.pascal_case.required_suffix =
192+
dotnet_naming_style.pascal_case.word_separator =
193+
dotnet_naming_style.pascal_case.capitalization = pascal_case
194+
195+
dotnet_naming_style.begins_with_i.required_prefix = I
196+
dotnet_naming_style.begins_with_i.required_suffix =
197+
dotnet_naming_style.begins_with_i.word_separator =
198+
dotnet_naming_style.begins_with_i.capitalization = pascal_case

PdfAValidator.sln

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PdfAValidatorWebApi", "PdfA
1111
EndProject
1212
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{49D9D2CB-EF79-4962-B4C3-2F1BAFD9DCC8}"
1313
ProjectSection(SolutionItems) = preProject
14+
.editorconfig = .editorconfig
1415
appveyor.yml = appveyor.yml
1516
LICENSE = LICENSE
1617
README.md = README.md
1718
EndProjectSection
1819
EndProject
19-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PdfAValidatorWebApiTest", "PdfAValidatorWebApiTest\PdfAValidatorWebApiTest.csproj", "{92E8D03D-F39B-46BD-98BF-1F2BB0AE21BA}"
20+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PdfAValidatorWebApiTest", "PdfAValidatorWebApiTest\PdfAValidatorWebApiTest.csproj", "{92E8D03D-F39B-46BD-98BF-1F2BB0AE21BA}"
2021
EndProject
2122
Global
2223
GlobalSection(SolutionConfigurationPlatforms) = preSolution

PdfAValidator/IPdfAValidator.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
4+
namespace Codeuctivity
5+
{
6+
/// <summary>
7+
/// PdfAValidator is a VeraPdf wrapper
8+
/// </summary>
9+
public interface IPdfAValidator : IDisposable
10+
{
11+
/// <summary>
12+
/// Validates a pdf to be compliant with the pdfa standard claimed by its meta data
13+
/// </summary>
14+
/// <param name="pathToPdfFile"></param>
15+
/// <returns>True for compliant PdfA Files</returns>
16+
Task<bool> ValidateAsync(string pathToPdfFile);
17+
18+
/// <summary>
19+
/// Validates a pdf and returns a detailed compliance report
20+
/// </summary>
21+
/// <param name="pathToPdfFile"></param>
22+
/// <returns></returns>
23+
Task<Report> ValidateWithDetailedReportAsync(string pathToPdfFile);
24+
}
25+
}

PdfAValidator/PdfAValidator.cs

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
1-
using System;
1+
using Codeuctivity.Properties;
2+
using System;
23
using System.Diagnostics;
34
using System.IO;
45
using System.IO.Compression;
56
using System.Reflection;
67
using System.Runtime.InteropServices;
8+
using System.Threading;
79
using System.Threading.Tasks;
810
using System.Xml;
911
using System.Xml.Serialization;
1012

11-
namespace PdfAValidator
13+
namespace Codeuctivity
1214
{
1315
/// <summary>
1416
/// PdfAValidator is a VeraPdf wrapper
1517
/// </summary>
16-
public class PdfAValidator : IDisposable
18+
19+
public class PdfAValidator : IPdfAValidator
1720
{
1821
private const string maskedQuote = "\"";
1922
private const int maxLengthTempdirectoryThatVeraPdfFitsIn = 206;
20-
private const string OsNotSupportedMessage = "Sorry, only supporting linux and windows.";
21-
private readonly object lockObject = new object();
2223
private string? pathVeraPdfDirectory;
2324
private bool disposed;
25+
private static readonly SemaphoreSlim semaphore = new SemaphoreSlim(1, 1);
2426

2527
/// <summary>
2628
/// Path to java jre used by windows
@@ -57,12 +59,9 @@ protected virtual void Dispose(bool disposing)
5759
return;
5860
}
5961

60-
if (disposing)
62+
if (disposing && !customVerapdfAndJavaLocations && Directory.Exists(pathVeraPdfDirectory))
6163
{
62-
if (!customVerapdfAndJavaLocations && Directory.Exists(pathVeraPdfDirectory))
63-
{
64-
Directory.Delete(pathVeraPdfDirectory, true);
65-
}
64+
Directory.Delete(pathVeraPdfDirectory, true);
6665
}
6766
disposed = true;
6867
}
@@ -84,26 +83,27 @@ public PdfAValidator(string pathToVeraPdfBin, string pathToJava)
8483
/// Use this constructor to use the embedded veraPdf binaries
8584
/// </summary>
8685
public PdfAValidator()
87-
{ }
86+
{
87+
}
8888

8989
/// <summary>
9090
/// Validates a pdf to be compliant with the pdfa standard claimed by its meta data
9191
/// </summary>
9292
/// <param name="pathToPdfFile"></param>
9393
/// <returns>True for compliant PdfA Files</returns>
94-
public bool Validate(string pathToPdfFile)
94+
public async Task<bool> ValidateAsync(string pathToPdfFile)
9595
{
96-
return ValidateWithDetailedReport(pathToPdfFile).BatchSummary.ValidationReports.Compliant == "1";
96+
return (await ValidateWithDetailedReportAsync(pathToPdfFile).ConfigureAwait(false)).BatchSummary.ValidationReports.Compliant == "1";
9797
}
9898

9999
/// <summary>
100100
/// Validates a pdf and returns a detailed compliance report
101101
/// </summary>
102102
/// <param name="pathToPdfFile"></param>
103103
/// <returns></returns>
104-
public Report ValidateWithDetailedReport(string pathToPdfFile)
104+
public async Task<Report> ValidateWithDetailedReportAsync(string pathToPdfFile)
105105
{
106-
IntiPathToVeraPdfBinAndJava();
106+
await IntiPathToVeraPdfBinAndJava().ConfigureAwait(false);
107107
var absolutePathToPdfFile = Path.GetFullPath(pathToPdfFile);
108108

109109
if (!File.Exists(absolutePathToPdfFile))
@@ -172,9 +172,10 @@ private static T DeserializeXml<T>(string sourceXML) where T : class
172172
return (T)serializer.Deserialize(xmlReader);
173173
}
174174

175-
private void IntiPathToVeraPdfBinAndJava()
175+
private async Task IntiPathToVeraPdfBinAndJava()
176176
{
177-
lock (lockObject)
177+
await semaphore.WaitAsync().ConfigureAwait(false);
178+
try
178179
{
179180
if (IsInitialized)
180181
{
@@ -191,24 +192,28 @@ private void IntiPathToVeraPdfBinAndJava()
191192

192193
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
193194
{
194-
ExtractBinaryFromManifest("PdfAValidator.VeraPdf.Windows.zip");
195+
await ExtractBinaryFromManifest("Codeuctivity.VeraPdf.Windows.zip").ConfigureAwait(false);
195196
VeraPdfStartScript = Path.Combine(pathVeraPdfDirectory, "verapdf", "verapdf.bat");
196197
// took from https://adoptopenjdk.net/releases.html?variant=openjdk8&jvmVariant=hotspot#x64_win
197198
PathJava = Path.Combine(pathVeraPdfDirectory, "verapdf", "jdk8u202-b08-jre", "bin", "java");
198199
}
199200
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
200201
{
201-
ExtractBinaryFromManifest("PdfAValidator.VeraPdf.Linux.zip");
202+
await ExtractBinaryFromManifest("Codeuctivity.VeraPdf.Linux.zip").ConfigureAwait(false);
202203
VeraPdfStartScript = Path.Combine(pathVeraPdfDirectory, "verapdf", "verapdf");
203204
SetLinuxFileExecuteable(VeraPdfStartScript);
204205
}
205206
else
206207
{
207-
throw new NotImplementedException(OsNotSupportedMessage);
208+
throw new NotImplementedException(Resources.OsNotSupportedMessage);
208209
}
209210

210211
IsInitialized = true;
211212
}
213+
finally
214+
{
215+
semaphore.Release();
216+
}
212217
}
213218

214219
private static void SetLinuxFileExecuteable(string filePath)
@@ -232,15 +237,15 @@ private static void SetLinuxFileExecuteable(string filePath)
232237
process.WaitForExit();
233238
}
234239

235-
private void ExtractBinaryFromManifest(string resourceName)
240+
private async Task ExtractBinaryFromManifest(string resourceName)
236241
{
237242
var pathZipVeraPdf = Path.Combine(pathVeraPdfDirectory, "VeraPdf.zip");
238243
var assembly = Assembly.GetExecutingAssembly();
239244
using (var stream = assembly.GetManifestResourceStream(resourceName))
240245
using (var fileStream = File.Create(pathZipVeraPdf))
241246
{
242247
stream.Seek(0, SeekOrigin.Begin);
243-
stream.CopyTo(fileStream);
248+
await stream.CopyToAsync(fileStream).ConfigureAwait(false);
244249
}
245250

246251
ZipFile.ExtractToDirectory(pathZipVeraPdf, pathVeraPdfDirectory);

0 commit comments

Comments
 (0)