Beispiel #1
0
        public void Load(IScriptAnalyzerContext context, LoadReference reference)
        {
#if NETCORE
            throw new NotSupportedException("The NuGet provider for #load is not supported on .NET Core.");
#else
            // Create a package reference from our load reference.
            // The package should contain the necessary include parameters to make sure
            // that .cake files are included as part of the result.
            var separator = reference.OriginalString.Contains("?") ? "&" : "?";
            var uri       = string.Concat(reference.OriginalString, $"{separator}include=./**/*.cake");
            var package   = new PackageReference(uri);

            // Find the tool folder.
            var toolPath = GetToolPath(context.Root.GetDirectory());

            // Install the NuGet package.
            var files = _installer.Install(package, PackageType.Tool, toolPath);
            if (files.Count == 0)
            {
                // No files found.
                _log.Warning("No scripts found in NuGet package {0}.", package.Package);
                return;
            }

            foreach (var file in files)
            {
                var extension = file.Path.GetExtension();
                if (extension != null && extension.Equals(".cake", StringComparison.OrdinalIgnoreCase))
                {
                    context.Analyze(file.Path);
                }
            }
#endif
        }
Beispiel #2
0
        /// <summary>
        /// Load the given reference
        /// </summary>
        /// <returns>The load.</returns>
        /// <param name="context">The context.</param>
        /// <param name="reference">The load reference.</param>
        public void Load(IScriptAnalyzerContext context, LoadReference reference)
        {
            var urlsPath = GetUrlsPath(context.Root.GetDirectory());

            var actualUrl = reference.Address;

            var referenceHash = HashMd5(actualUrl.ToString());

            var urlFile = urlsPath.CombineWithFilePath(referenceHash + ".cake").MakeAbsolute(_environment);

            if (!System.IO.File.Exists(urlFile.FullPath))
            {
                var urlFileDir = urlFile.GetDirectory().FullPath;

                // Make sure the directory exists we want to save to
                if (!System.IO.Directory.Exists(urlFileDir))
                {
                    System.IO.Directory.CreateDirectory(urlFileDir);
                }

                var http = new System.Net.Http.HttpClient();

                using (var httpStream = http.GetStreamAsync(actualUrl).Result)
                    using (var cacheStream = System.IO.File.Create(urlFile.MakeAbsolute(_environment).FullPath))
                    {
                        httpStream.CopyTo(cacheStream);
                    }
            }

            context.Analyze(urlFile);
        }
        public void Should_Not_CanLoad(string url)
        {
            var f = new UrlLoadDirectiveProviderFixture();

            var lr = new LoadReference(new Uri(url));

            var r = f.CanLoad(lr);

            Assert.False(r);
        }
        public NuGetLoadDirectiveProviderFixture()
        {
            Environment   = FakeEnvironment.CreateUnixEnvironment();
            Installer     = Substitute.For <INuGetPackageInstaller>();
            Configuration = new FakeConfiguration();
            Log           = new FakeLog();
            Reference     = new LoadReference(new Uri("nuget:?package=Cake.Recipe"));
            InstallResult = new List <FilePath>();

            Context = Substitute.For <IScriptAnalyzerContext>();
            Context.Root.Returns(new FilePath("/Working/build.cake"));
        }
        protected override void AddToContext(IScriptAnalyzerContext context, Uri uri)
        {
            var reference = new LoadReference(uri);

            foreach (var provider in _providers)
            {
                if (provider.CanLoad(context, reference))
                {
                    provider.Load(context, reference);
                }
            }
        }
        public void Load_Url_Reference(string url)
        {
            var f = new UrlLoadDirectiveProviderFixture();

            var lr = new LoadReference(new Uri(url));

            f.Load(lr);

            Assert.NotEmpty(f.LoadedReferences);

            foreach (var k in f.LoadedReferences.Keys)
            {
                Console.WriteLine(k);
            }
        }
Beispiel #7
0
        public void Load(IScriptAnalyzerContext context, LoadReference reference)
        {
            // Create a package reference from our load reference.
            // If not specified in script, the package should contain the necessary include
            // parameters to make sure that .cake files are included as part of the result.
            var          uri                  = new Uri(reference.OriginalString);
            var          parameters           = uri.GetQueryString();
            const string includeParameterName = "include";

            if (!parameters.ContainsKey(includeParameterName))
            {
                var separator = parameters.Count > 0 ? "&" : "?";
                uri = new Uri(string.Concat(reference.OriginalString, $"{separator}include=./**/*.cake"));
            }
            var package = new PackageReference(uri);

            // Find the tool folder.
            var toolPath = GetToolPath(_environment.WorkingDirectory);

            // Install the NuGet package.
            var files = _installer
                        .Install(package, PackageType.Tool, toolPath)
                        .Where(file =>
            {
                var extension = file.Path.GetExtension();
                return(extension != null && extension.Equals(".cake", StringComparison.OrdinalIgnoreCase));
            })
                        .ToArray();

            if (files.Length == 0)
            {
                // No scripts found.
                _log.Warning("No scripts found in NuGet package {0}.", package.Package);
                return;
            }

            foreach (var file in files)
            {
                context.Analyze(file.Path);
            }
        }
        public void Load(IScriptAnalyzerContext context, LoadReference reference)
        {
            if (!_cache.TryGetValue(reference, out IReadOnlyList <FilePath> result))
            {
                var provider = _loadDirectiveProviders.FirstOrDefault(x => x.CanLoad(context, reference));
                if (provider == null)
                {
                    return;
                }

                var interceptor = new InterceptingScriptAnalyzerContext(context);
                provider.Load(interceptor, reference);
                result = interceptor.FilePaths;

                _cache.Add(reference, result);
            }

            foreach (var file in result ?? Enumerable.Empty <FilePath>())
            {
                context.Analyze(file);
            }
        }
Beispiel #9
0
 public bool CanLoad(IScriptAnalyzerContext context, LoadReference reference)
 {
     return(reference.Scheme != null && reference.Scheme.Equals("nuget", StringComparison.OrdinalIgnoreCase));
 }
 public bool CanLoad(IScriptAnalyzerContext context, LoadReference reference)
 {
     return(_loadDirectiveProviders.Any(x => x.CanLoad(context, reference)));
 }
Beispiel #11
0
        /// <summary>
        /// Loads and displays the specified fileReference in the UI, which is expected to point to a valid object.
        /// This function takes a delegate which will correctly load the file pointed to by the FileReference,
        /// and another delegate which will create a correct <see cref="IRenderable"/> object from the resulting
        /// object.
        /// </summary>
        /// <param name="fileReference">A <see cref="FileReference"/> which points to the desired file.</param>
        /// <param name="referenceLoadingRoutine">A delegate which correctly loads the desired file, returning a generic type T.</param>
        /// <param name="createRenderable">A delegate which accepts a generic type T and returns a renderable object.</param>
        /// <param name="associatedControlPage">The control page which the file is associated with, that is, the one with relevant controls.</param>
        /// <param name="ct">A cancellation token for this operation.</param>
        /// <typeparam name="T">The type of object to load.</typeparam>
        private async Task DisplayRenderableFile <T>(FileReference fileReference, LoadReference <T> referenceLoadingRoutine, CreateRenderable <T> createRenderable, ControlPage associatedControlPage, CancellationToken ct)
        {
            if (fileReference == null)
            {
                throw new ArgumentNullException(nameof(fileReference));
            }

            Log.Info($"Loading \"{fileReference.FilePath}\".");

            this.StatusSpinner.Active = true;

            string modelName = fileReference.Filename;
            uint   modelStatusMessageContextID = this.MainStatusBar.GetContextId($"itemLoad_{modelName}");
            uint   modelStatusMessageID        = this.MainStatusBar.Push
                                                 (
                modelStatusMessageContextID,
                $"Loading \"{modelName}\"..."
                                                 );

            try
            {
                T item = await Task.Run
                         (
                    () => referenceLoadingRoutine(fileReference),
                    ct
                         );

                IRenderable renderable = await Task.Factory.StartNew
                                         (
                    () => createRenderable(item, fileReference),
                    ct
                                         );

                if (renderable != null)
                {
                    ct.ThrowIfCancellationRequested();

                    this.ViewportWidget.MakeCurrent();
                    this.ViewportWidget.AttachBuffers();
                    renderable.Initialize();

                    // Replace the renderable on the UI thread
                    await Task.Factory.StartNew
                    (
                        () => this.RenderingEngine.SetRenderTarget(renderable),
                        ct,
                        TaskCreationOptions.None,
                        this.UiThreadScheduler
                    );

                    EnableControlPage(associatedControlPage);

                    if (renderable is IModelInfoProvider infoProvider)
                    {
                        this.PolyCountLabel.Text   = infoProvider.PolygonCount.ToString();
                        this.VertexCountLabel.Text = infoProvider.VertexCount.ToString();
                    }
                }
            }
            catch (OperationCanceledException)
            {
                Log.Info($"Cancelled loading of {fileReference.Filename}");
            }
            finally
            {
                this.StatusSpinner.Active = false;
                this.MainStatusBar.Remove(modelStatusMessageContextID, modelStatusMessageID);
            }
        }
Beispiel #12
0
        internal void Load(LoadReference loadRef)
        {
            var p = CreateProvider();

            p.Load(ScriptAnalyzerContext, loadRef);
        }
Beispiel #13
0
        internal bool CanLoad(LoadReference loadRef)
        {
            var p = CreateProvider();

            return(p.CanLoad(ScriptAnalyzerContext, loadRef));
        }