protected ImmutableArray <KeyValuePair <string, string> > ParsePathMap(string pathMap, IList <Diagnostic> errors)
        {
            var pathMapBuilder = ArrayBuilder <KeyValuePair <string, string> > .GetInstance();

            if (pathMap.IsEmpty())
            {
                return(pathMapBuilder.ToImmutableAndFree());
            }

            foreach (var kEqualsV in pathMap.Split(','))
            {
                var kv = kEqualsV.Split('=');
                if (kv.Length != 2)
                {
                    errors.Add(Diagnostic.Create(_messageProvider, _messageProvider.ERR_InvalidPathMap, kEqualsV));
                    continue;
                }
                var from = kv[0];
                var to   = kv[1];

                if (from.Length == 0 || to.Length == 0)
                {
                    errors.Add(Diagnostic.Create(_messageProvider, _messageProvider.ERR_InvalidPathMap, kEqualsV));
                }
                else
                {
                    from = PathUtilities.EnsureTrailingSeparator(from);
                    to   = PathUtilities.EnsureTrailingSeparator(to);
                    pathMapBuilder.Add(new KeyValuePair <string, string>(from, to));
                }
            }

            return(pathMapBuilder.ToImmutableAndFree());
        }
Beispiel #2
0
        protected ProjectFile(ProjectFileLoader loader, MSB.Evaluation.Project?loadedProject, ProjectBuildManager buildManager, DiagnosticLog log)
        {
            _loader        = loader;
            _loadedProject = loadedProject;
            _buildManager  = buildManager;
            var directory = loadedProject?.DirectoryPath ?? string.Empty;

            _projectDirectory = PathUtilities.EnsureTrailingSeparator(directory);
            Log = log;
        }
Beispiel #3
0
        public SourceFileResolver(
            ImmutableArray <string> searchPaths,
            string baseDirectory,
            ImmutableArray <KeyValuePair <string, string> > pathMap)
        {
            if (searchPaths.IsDefault)
            {
                throw new ArgumentNullException(nameof(searchPaths));
            }

            if (baseDirectory != null && PathUtilities.GetPathKind(baseDirectory) != PathKind.Absolute)
            {
                throw new ArgumentException(CodeAnalysisResources.AbsolutePathExpected, nameof(baseDirectory));
            }

            _baseDirectory = baseDirectory;
            _searchPaths   = searchPaths;

            // The previous public API required paths to not end with a path separator.
            // This broke handling of root paths (e.g. "/" cannot be represented), so
            // the new requirement is for paths to always end with a path separator.
            // However, because this is a public API, both conventions must be allowed,
            // so normalize the paths here (instead of enforcing end-with-sep).
            if (!pathMap.IsDefaultOrEmpty)
            {
                var pathMapBuilder = ArrayBuilder <KeyValuePair <string, string> > .GetInstance(pathMap.Length);

                foreach (var kv in pathMap)
                {
                    var key = kv.Key;
                    if (key == null || key.Length == 0)
                    {
                        throw new ArgumentException(CodeAnalysisResources.EmptyKeyInPathMap, nameof(pathMap));
                    }

                    var value = kv.Value;
                    if (value == null)
                    {
                        throw new ArgumentException(CodeAnalysisResources.NullValueInPathMap, nameof(pathMap));
                    }

                    var normalizedKey   = PathUtilities.EnsureTrailingSeparator(key);
                    var normalizedValue = PathUtilities.EnsureTrailingSeparator(value);

                    pathMapBuilder.Add(new KeyValuePair <string, string>(normalizedKey, normalizedValue));
                }

                _pathMap = pathMapBuilder.ToImmutableAndFree();
            }
            else
            {
                _pathMap = ImmutableArray <KeyValuePair <string, string> > .Empty;
            }
        }
Beispiel #4
0
        protected ProjectFile(ProjectFileLoader loader, MSB.Evaluation.Project loadedProject, ProjectBuildManager buildManager, DiagnosticLog log)
        {
            _loader        = loader;
            _loadedProject = loadedProject;
            _buildManager  = buildManager;

            _projectDirectory = loadedProject != null
                ? PathUtilities.EnsureTrailingSeparator(loadedProject.DirectoryPath)
                : null;

            Log = log;
        }