diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..e17d65c
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,13 @@
+root = true
+
+[*]
+end_of_line = crlf
+indent_size = 4
+indent_style = space
+insert_final_newline = true
+tab_width = 4
+trim_trailing_whitespace = true
+
+[*.{csproj,config}]
+indent_size = 2
+indent_style = space
diff --git a/packages.config b/packages.config
index 02d329a..b8a59c7 100644
--- a/packages.config
+++ b/packages.config
@@ -1,6 +1,6 @@
-
-
-
+
+
+
diff --git a/src/Scoop.Validator.cs b/src/Scoop.Validator.cs
index e233dfc..32d067b 100644
--- a/src/Scoop.Validator.cs
+++ b/src/Scoop.Validator.cs
@@ -6,109 +6,78 @@
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Schema;
-namespace Scoop
-{
- public class JsonParserException : Exception
- {
+namespace Scoop {
+ public class JsonParserException : Exception {
public string FileName { get; set; }
public JsonParserException(string file, string message) : base(message) { this.FileName = file; }
public JsonParserException(string file, string message, Exception inner) : base(message, inner) { this.FileName = file; }
}
- public class Validator
- {
+ public class Validator {
private bool CI { get; set; }
public JSchema Schema { get; private set; }
public FileInfo SchemaFile { get; private set; }
public JObject Manifest { get; private set; }
public FileInfo ManifestFile { get; private set; }
public IList Errors { get; private set; }
- public string ErrorsAsString
- {
- get
- {
- return String.Join(System.Environment.NewLine, this.Errors);
- }
+ public string ErrorsAsString {
+ get { return String.Join(System.Environment.NewLine, this.Errors); }
}
- private JSchema ParseSchema(string file)
- {
- try
- {
+ private JSchema ParseSchema(string file) {
+ try {
return JSchema.Parse(File.ReadAllText(file, System.Text.Encoding.UTF8));
- }
- catch (Newtonsoft.Json.JsonReaderException e)
- {
+ } catch (Newtonsoft.Json.JsonReaderException e) {
throw new JsonParserException(Path.GetFileName(file), e.Message, e);
- }
- catch (FileNotFoundException e)
- {
+ } catch (FileNotFoundException e) {
throw e;
}
}
- private JObject ParseManifest(string file)
- {
- try
- {
+ private JObject ParseManifest(string file) {
+ try {
return JObject.Parse(File.ReadAllText(file, System.Text.Encoding.UTF8));
- }
- catch (Newtonsoft.Json.JsonReaderException e)
- {
+ } catch (Newtonsoft.Json.JsonReaderException e) {
throw new JsonParserException(Path.GetFileName(file), e.Message, e);
- }
- catch (FileNotFoundException e)
- {
+ } catch (FileNotFoundException e) {
throw e;
}
}
- public Validator(string schemaFile)
- {
+ public Validator(string schemaFile) {
this.SchemaFile = new FileInfo(schemaFile);
this.Errors = new List();
}
- public Validator(string schemaFile, bool ci)
- {
+ public Validator(string schemaFile, bool ci) {
this.SchemaFile = new FileInfo(schemaFile);
this.Errors = new List();
this.CI = ci;
}
- public bool Validate(string file)
- {
+ public bool Validate(string file) {
this.ManifestFile = new FileInfo(file);
return this.Validate();
}
- public bool Validate()
- {
- if (!this.SchemaFile.Exists)
- {
+ public bool Validate() {
+ if (!this.SchemaFile.Exists) {
Console.WriteLine("ERROR: Please provide schema.json!");
return false;
}
- if (!this.ManifestFile.Exists)
- {
+ if (!this.ManifestFile.Exists) {
Console.WriteLine("ERROR: Please provide manifest.json!");
return false;
}
this.Errors.Clear();
- try
- {
- if (this.Schema == null)
- {
+ try {
+ if (this.Schema == null) {
this.Schema = this.ParseSchema(this.SchemaFile.FullName);
}
this.Manifest = this.ParseManifest(this.ManifestFile.FullName);
- }
- catch (FileNotFoundException e)
- {
+ } catch (FileNotFoundException e) {
this.Errors.Add(e.Message);
- }
- catch (JsonParserException e)
- {
+ } catch (JsonParserException e) {
this.Errors.Add(String.Format("{0}{1}: {2}", (this.CI ? " [*] " : ""), e.FileName, e.Message));
}
@@ -119,8 +88,7 @@ public bool Validate()
this.Manifest.IsValid(this.Schema, out validationErrors);
- if (validationErrors.Count == 0)
- {
+ if (validationErrors.Count == 0) {
return true;
}
traverseErrors(validationErrors, this.CI ? 3 : 1);
@@ -129,11 +97,10 @@ public bool Validate()
}
public void traverseErrors(IList errors, int level = 1) {
- if(errors == null) {
+ if (errors == null) {
return;
}
- foreach (ValidationError error in errors)
- {
+ foreach (ValidationError error in errors) {
StringBuilder sb = new StringBuilder();
sb.Insert(sb.Length, " ", level * 2);
sb.Insert(sb.Length, this.CI ? "[*] " : "- ");
@@ -147,13 +114,13 @@ public void traverseErrors(IList errors, int level = 1) {
sb.Insert(sb.Length, this.CI ? " [^] " : " ");
sb.AppendFormat("Path: {0}/{1}", error.SchemaId, error.ErrorType);
- if(!this.CI) {
+ if (!this.CI) {
sb.Insert(sb.Length, "\n");
}
this.Errors.Add(sb.ToString());
- if(error.ChildErrors != null || error.ChildErrors.Count > 0) {
+ if (error.ChildErrors != null || error.ChildErrors.Count > 0) {
traverseErrors(error.ChildErrors, level + 1);
}
}
diff --git a/src/validator.cs b/src/validator.cs
index 4b0c735..6cf987c 100644
--- a/src/validator.cs
+++ b/src/validator.cs
@@ -4,27 +4,22 @@
using System.IO;
using System.Linq;
-namespace Scoop
-{
- public class Program
- {
- public static int Main(string[] args)
- {
+namespace Scoop {
+ public class Program {
+ public static int Main(string[] args) {
bool ci = String.Format("{0}", Environment.GetEnvironmentVariable("CI")).ToLower() == "true";
bool valid = true;
- if (args.Length < 2)
- {
+ if (args.Length < 2) {
Console.WriteLine("Usage: validator.exe [...]");
return 1;
}
-
IList manifests = args.ToList();
String schema = manifests.First();
manifests.RemoveAt(0);
String combinedArgs = String.Join("", manifests);
- if(combinedArgs.Contains("*") || combinedArgs.Contains("?")) {
+ if (combinedArgs.Contains("*") || combinedArgs.Contains("?")) {
try {
var path = new Uri(Path.Combine(Directory.GetCurrentDirectory(), combinedArgs)).LocalPath;
var drive = Path.GetPathRoot(path);
@@ -37,25 +32,21 @@ public static int Main(string[] args)
}
Scoop.Validator validator = new Scoop.Validator(schema, ci);
- foreach(var manifest in manifests) {
- if (validator.Validate(manifest))
- {
- if(ci) {
+ foreach (var manifest in manifests) {
+ if (validator.Validate(manifest)) {
+ if (ci) {
Console.WriteLine(" [+] {0} validates against the schema!", Path.GetFileName(manifest));
} else {
Console.WriteLine("- {0} validates against the schema!", Path.GetFileName(manifest));
}
- }
- else
- {
- if(ci) {
+ } else {
+ if (ci) {
Console.WriteLine(" [-] {0} has {1} Error{2}!", Path.GetFileName(manifest), validator.Errors.Count, validator.Errors.Count > 1 ? "s" : "");
} else {
Console.WriteLine("- {0} has {1} Error{2}!", Path.GetFileName(manifest), validator.Errors.Count, validator.Errors.Count > 1 ? "s" : "");
}
valid = false;
- foreach (var error in validator.Errors)
- {
+ foreach (var error in validator.Errors) {
Console.WriteLine(error);
}
}
diff --git a/validator.csproj b/validator.csproj
index e05c685..bb7bcf7 100644
--- a/validator.csproj
+++ b/validator.csproj
@@ -1,3 +1,18 @@
-
+
+
+ net45
+ Scoop.Validator
+ 1.0.3
+
+
+
+ packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll
+ True
+
+
+ packages\Newtonsoft.Json.Schema.3.0.13\lib\net45\Newtonsoft.Json.Schema.dll
+ True
+
+