Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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;
                    string     target = null;

                    if (dependencyValue is JsonObject)
                    {
                        // "dependencies" : { "Name" : { "version": "1.0", "type": "build", "target": "project" } }
                        var dependencyValueAsObject = (JsonObject)dependencyValue;
                        dependencyVersionAsString = dependencyValueAsObject.ValueAsString("version");

                        // Remove support for flags (we only support build and nothing right now)
                        var type = dependencyValueAsObject.ValueAsString("type");
                        if (type != null)
                        {
                            dependencyTypeValue = LibraryDependencyType.Parse(type.Value);
                        }

                        // Read the target if specified
                        target = dependencyValueAsObject.ValueAsString("target")?.Value;
                    }
                    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,
                            Target       = target
                        },
                        Type = dependencyTypeValue
                    });
                }
            }
        }
Exemplo n.º 4
0
        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
                    });
                }
            }
        }
Exemplo n.º 5
0
 static LibraryDependencyType()
 {
     Default = Parse(new[] { "default" });
 }
Exemplo n.º 6
0
 static LibraryDependencyType()
 {
     Default = Parse(new[] { "default" });
 }