public ProcessedArgs(NuGetReference analyzerRef, string sqaleFilePath)
 {
     if (analyzerRef == null)
     {
         throw new ArgumentNullException("analyzerRef");
     }
     this.analyzerRef = analyzerRef;
     this.sqaleFilePath = sqaleFilePath; // can be null
 }
Beispiel #2
0
        private bool TryParseAnalyzerRef(IEnumerable<ArgumentInstance> arguments, out NuGetReference analyzerRef)
        {
            analyzerRef = null;
            ArgumentInstance analyzerArg = arguments.SingleOrDefault(a => ArgumentDescriptor.IdComparer.Equals(KeywordIds.AnalyzerRef, a.Descriptor.Id));

            if (analyzerArg != null)
            {
                analyzerRef = TryParseNuGetReference(analyzerArg.Value);
            }
            return analyzerRef != null;
        }
        public ProcessedArgs(NuGetReference analyzerRef, string sqaleFilePath, string language)
        {
            if (analyzerRef == null)
            {
                throw new ArgumentNullException("analyzerRef");
            }
            SupportedLanguages.ThrowIfNotSupported(language);

            this.analyzerRef = analyzerRef;
            this.sqaleFilePath = sqaleFilePath; // can be null
            this.language = language;
        }
Beispiel #4
0
        public ProcessedArgs(NuGetReference analyzerRef, string sqaleFilePath, string language)
        {
            if (analyzerRef == null)
            {
                throw new ArgumentNullException("analyzerRef");
            }
            SupportedLanguages.ThrowIfNotSupported(language);

            this.analyzerRef   = analyzerRef;
            this.sqaleFilePath = sqaleFilePath; // can be null
            this.language      = language;
        }
        public bool Generate(NuGetReference analyzeRef, string sqaleFilePath)
        {
            // sqale file path is optional
            if (analyzeRef == null)
            {
                throw new ArgumentNullException("analyzeRef");
            }

            string baseDirectory = Path.Combine(
                Path.GetTempPath(),
                Assembly.GetEntryAssembly().GetName().Name);

            string nuGetDirectory = Path.Combine(baseDirectory, ".nuget");

            NuGetPackageHandler downloader = new NuGetPackageHandler(logger);

            IPackage package = downloader.FetchPackage(NuGetPackageSource, analyzeRef.PackageId, analyzeRef.Version, nuGetDirectory);

            if (package != null)
            {
                // TODO: support multiple languages
                string language = SupportedLanguages.CSharp;
                PluginManifest pluginDefn = CreatePluginDefinition(package);

                string outputDirectory = Path.Combine(baseDirectory, ".output", Guid.NewGuid().ToString());
                Directory.CreateDirectory(outputDirectory);

                string rulesFilePath = Path.Combine(outputDirectory, "rules.xml");

                // TODO: we shouldn't try to work out where the content files have been installed by NuGet.
                // Instead, we should use the methods on IPackage to locate the assemblies e.g. Package.GetFiles()
                string packageDirectory = Path.Combine(nuGetDirectory, package.Id + "." + package.Version.ToString());
                Debug.Assert(Directory.Exists(packageDirectory), "Expected package directory does not exist: {0}", packageDirectory);

                bool success = TryGenerateRulesFile(packageDirectory, nuGetDirectory, rulesFilePath);

                if (success)
                {
                    BuildPlugin(analyzeRef, sqaleFilePath, language, pluginDefn, rulesFilePath, outputDirectory, package);
                }
            }

            return package != null;
        }
        public bool Generate(NuGetReference analyzeRef, string language, string sqaleFilePath, string outputDirectory)
        {
            // sqale file path is optional
            if (analyzeRef == null)
            {
                throw new ArgumentNullException("analyzeRef");
            }
            if (string.IsNullOrWhiteSpace(language))
            {
                throw new ArgumentNullException("language");
            }
            SupportedLanguages.ThrowIfNotSupported(language);

            string nuGetDirectory = Utilities.CreateTempDirectory(".nuget");
            IPackage package = this.packageHandler.FetchPackage(analyzeRef.PackageId, analyzeRef.Version, nuGetDirectory);

            if (package != null)
            {
                // Create a uniquely-named temp directory for this generation run
                string baseDirectory = Utilities.CreateTempDirectory(".gen");
                baseDirectory = CreateSubDirectory(baseDirectory, Guid.NewGuid().ToString());
                this.logger.LogDebug(UIResources.APG_CreatedTempWorkingDir, baseDirectory);

                PluginManifest pluginDefn = CreatePluginDefinition(package);

                string rulesFilePath = Path.Combine(baseDirectory, "rules.xml");

                bool success = TryGenerateRulesFile(package, nuGetDirectory, baseDirectory, rulesFilePath, language);

                if (success)
                {
                    BuildPlugin(package, language, rulesFilePath, sqaleFilePath, pluginDefn, baseDirectory, outputDirectory);
                }
            }

            return package != null;
        }
        private bool TryParseAnalyzerRef(IEnumerable<ArgumentInstance> arguments, out NuGetReference analyzerRef)
        {
            analyzerRef = null;
            ArgumentInstance analyzerArg = arguments.SingleOrDefault(a => ArgumentDescriptor.IdComparer.Equals(KeywordIds.AnalyzerRef, a.Descriptor.Id));

            if (analyzerArg != null)
            {
                analyzerRef = TryParseNuGetReference(analyzerArg.Value);
            }
            return analyzerRef != null;
        }
        private void BuildPlugin(NuGetReference analyzeRef, string sqaleFilePath, string language, PluginManifest pluginDefn, string rulesFilePath, string tempDirectory, IPackage package)
        {
            this.logger.LogInfo(UIResources.APG_GeneratingPlugin);

            string fullJarPath = Path.Combine(Directory.GetCurrentDirectory(),
                analyzeRef.PackageId + "-plugin." + pluginDefn.Version + ".jar");

            PluginBuilder builder = new PluginBuilder(logger);
            RulesPluginBuilder.ConfigureBuilder(builder, pluginDefn, language, rulesFilePath, sqaleFilePath);

            AddRoslynMetadata(tempDirectory, builder, package);

            builder.SetJarFilePath(fullJarPath);
            builder.Build();

            this.logger.LogInfo(UIResources.APG_PluginGenerated, fullJarPath);
        }