public LibraryDependency( Library library, LibraryDependencyType type) { Library = library; Type = type; }
public static LibraryDependencyType Parse(IEnumerable<string> keywords) { var type = new LibraryDependencyType(); foreach (var keyword in keywords.Select(LibraryDependencyTypeKeyword.Parse)) { type = type.Combine(keyword.FlagsToAdd, keyword.FlagsToRemove); } return type; }
public static LibraryDependencyType Parse(IEnumerable <string> keywords) { var type = new LibraryDependencyType(); foreach (var keyword in keywords.Select(LibraryDependencyTypeKeyword.Parse)) { type = type.Combine(keyword.FlagsToAdd, keyword.FlagsToRemove); } return(type); }
public LibraryDependency( string name, SemanticVersion version, bool isGacOrFrameworkReference, LibraryDependencyType type) : this( new Library { Name = name, Version = version, IsGacOrFrameworkReference = isGacOrFrameworkReference }, type) { }
static LibraryDependencyType() { Default = Parse(new[] { "default" }); }
private static void PopulateDependencies( string projectPath, IList <LibraryDependency> results, JsonObject settings, string propertyName, bool isGacOrFrameworkReference) { var dependencies = settings.ValueAsJsonObject(propertyName); if (dependencies != null) { foreach (var dependencyKey in dependencies.Keys) { if (string.IsNullOrEmpty(dependencyKey)) { throw FileFormatException.Create( "Unable to resolve dependency ''.", dependencies.Value(dependencyKey), projectPath); } var dependencyValue = dependencies.Value(dependencyKey); var dependencyTypeValue = LibraryDependencyType.Default; JsonString dependencyVersionAsString = null; if (dependencyValue is JsonObject) { // "dependencies" : { "Name" : { "version": "1.0", "type": "build" } } var dependencyValueAsObject = (JsonObject)dependencyValue; dependencyVersionAsString = dependencyValueAsObject.ValueAsString("version"); IEnumerable <string> strings; if (TryGetStringEnumerable(dependencyValueAsObject, "type", out strings)) { dependencyTypeValue = LibraryDependencyType.Parse(strings); } } else if (dependencyValue is JsonString) { // "dependencies" : { "Name" : "1.0" } dependencyVersionAsString = (JsonString)dependencyValue; } else { throw FileFormatException.Create( string.Format("Invalid dependency version: {0}. The format is not recognizable.", dependencyKey), dependencyValue, projectPath); } SemanticVersionRange dependencyVersionRange = null; if (!string.IsNullOrEmpty(dependencyVersionAsString?.Value)) { try { dependencyVersionRange = VersionUtility.ParseVersionRange(dependencyVersionAsString.Value); } catch (Exception ex) { throw FileFormatException.Create( ex, dependencyValue, projectPath); } } results.Add(new LibraryDependency { LibraryRange = new LibraryRange(dependencyKey, isGacOrFrameworkReference) { VersionRange = dependencyVersionRange, FileName = projectPath, Line = dependencyValue.Line, Column = dependencyValue.Column }, Type = dependencyTypeValue }); } } }
static LibraryDependencyType() { Default = Parse(new[] { "default" }); }
private static void PopulateDependencies( string projectPath, IList <LibraryDependency> results, JObject settings, string propertyName, bool isGacOrFrameworkReference) { var dependencies = settings[propertyName] as JObject; if (dependencies != null) { foreach (var dependency in dependencies.Properties()) { if (string.IsNullOrEmpty(dependency.Name)) { throw FileFormatException.Create( "Unable to resolve dependency ''.", dependency, projectPath); } // Support // "dependencies" : { // "Name" : "1.0" // } var dependencyValue = dependency.Value; var dependencyTypeValue = LibraryDependencyType.Default; string dependencyVersionValue = null; JToken dependencyVersionToken = dependencyValue; if (dependencyValue.Type == JTokenType.String) { dependencyVersionValue = dependencyValue.Value <string>(); } else { if (dependencyValue.Type == JTokenType.Object) { dependencyVersionToken = dependencyValue["version"]; if (dependencyVersionToken != null && dependencyVersionToken.Type == JTokenType.String) { dependencyVersionValue = dependencyVersionToken.Value <string>(); } } IEnumerable <string> strings; if (TryGetStringEnumerable(dependencyValue["type"], out strings)) { dependencyTypeValue = LibraryDependencyType.Parse(strings); } } SemanticVersionRange dependencyVersionRange = null; if (!string.IsNullOrEmpty(dependencyVersionValue)) { try { dependencyVersionRange = VersionUtility.ParseVersionRange(dependencyVersionValue); } catch (Exception ex) { throw FileFormatException.Create( ex, dependencyVersionToken, projectPath); } } var dependencyLineInfo = (IJsonLineInfo)dependency; results.Add(new LibraryDependency { LibraryRange = new LibraryRange { Name = dependency.Name, VersionRange = dependencyVersionRange, IsGacOrFrameworkReference = isGacOrFrameworkReference, FileName = projectPath, Line = dependencyLineInfo.LineNumber, Column = dependencyLineInfo.LinePosition }, Type = dependencyTypeValue }); } } }
private static void PopulateDependencies( IList <LibraryDependency> results, JObject settings, string propertyName, bool isGacOrFrameworkReference) { var dependencies = settings[propertyName] as JObject; if (dependencies != null) { foreach (var dependency in dependencies) { if (String.IsNullOrEmpty(dependency.Key)) { throw new InvalidDataException("Unable to resolve dependency ''."); } // Support // "dependencies" : { // "Name" : "1.0" // } var dependencyValue = dependency.Value; string dependencyVersionValue = null; var dependencyTypeValue = LibraryDependencyType.Default; if (dependencyValue.Type == JTokenType.String) { dependencyVersionValue = dependencyValue.Value <string>(); } else { if (dependencyValue.Type == JTokenType.Object) { var dependencyVersionToken = dependencyValue["version"]; if (dependencyVersionToken != null && dependencyVersionToken.Type == JTokenType.String) { dependencyVersionValue = dependencyVersionToken.Value <string>(); } } IEnumerable <string> strings; if (TryGetStringEnumerable(dependencyValue["type"], out strings)) { dependencyTypeValue = LibraryDependencyType.Parse(strings); } } SemanticVersion dependencyVersion = null; if (!String.IsNullOrEmpty(dependencyVersionValue)) { dependencyVersion = SemanticVersion.Parse(dependencyVersionValue); } results.Add(new LibraryDependency( name: dependency.Key, version: dependencyVersion, isGacOrFrameworkReference: isGacOrFrameworkReference, type: dependencyTypeValue )); } } }