示例#1
0
        public void Load(IScriptAnalyzerContext context, LoadReference reference)
        {
            FilePath path = null;

            if (reference.Parameters.ContainsKey("path"))
            {
                if (reference.Parameters["path"].Count == 1)
                {
                    path = reference.Parameters["path"].FirstOrDefault();
                }
                else if (reference.Parameters["path"].Count > 1)
                {
                    throw new CakeException("Query string for #load contains more than one parameter 'path'.");
                }
            }

            if (path == null)
            {
                throw new CakeException("Query string for #load is missing parameter 'path'.");
            }

            // URL decode the path.
            path = new FilePath(WebUtility.UrlDecode(path.FullPath));

            // Get the current script path.
            var current = context.Current.Path.GetDirectory();

            path = path.MakeAbsolute(current);

            // Analyze the script.
            context.Analyze(path);
        }
示例#2
0
        public void Load(IScriptAnalyzerContext context, LoadReference reference)
        {
            FilePath path = null;

            if (reference.Parameters.ContainsKey("path"))
            {
                if (reference.Parameters["path"].Count == 1)
                {
                    path = reference.Parameters["path"].FirstOrDefault();
                }
                else if (reference.Parameters["path"].Count > 1)
                {
                    throw new CakeException("Query string for #load contains more than one parameter 'path'.");
                }
            }

            if (path == null)
            {
                throw new CakeException("Query string for #load is missing parameter 'path'.");
            }

            // URL decode the path.
            path = new FilePath(WebUtility.UrlDecode(path.FullPath));

            // Get the current script path.
            var current = context.Current.Path.GetDirectory();

            path = path.MakeAbsolute(current);

            var expectedExtension = path.HasExtension ? path.GetExtension() : ".cake";
            var files             = _globber
                                    .GetFiles(path.FullPath)
                                    .Where(file =>
            {
                var extension = file.GetExtension();
                return(extension != null && (extension.Equals(".cake", StringComparison.OrdinalIgnoreCase) || extension.Equals(expectedExtension, StringComparison.OrdinalIgnoreCase)));
            })
                                    .ToArray();

            if (files.Length == 0)
            {
                // No scripts found.
                _log.Warning("No scripts found at {0}.", path);
                return;
            }

            foreach (var file in files)
            {
                context.Analyze(file);
            }
        }
示例#3
0
 public bool CanLoad(IScriptAnalyzerContext context, LoadReference reference)
 {
     return(reference.Scheme != null && reference.Scheme.Equals("local", StringComparison.OrdinalIgnoreCase));
 }