Beispiel #1
0
        private void CheckJarGeneratedForPackage(string rootDir, DiagnosticAnalyzer analyzer, IPackage package)
        {
            string jarFilePath = GetGeneratedJars(rootDir).SingleOrDefault(r => r.Contains(package.Id.Replace(".", "").ToLower()));

            jarFilePath.Should().NotBeNull();

            // Check the content of the files embedded in the jar
            ZipFileChecker jarChecker = new ZipFileChecker(TestContext, jarFilePath);

            // Check the contents of the embedded config file
            string embeddedConfigFile     = jarChecker.AssertFileExists("org\\sonar\\plugins\\roslynsdk\\configuration.xml");
            RoslynSdkConfiguration config = RoslynSdkConfiguration.Load(embeddedConfigFile);

            // Check the config settings
            package.Should().NotBeNull("Unexpected repository differentiator");

            string pluginId = package.Id.ToLower();

            config.RepositoryKey.Should().Be("roslyn." + pluginId + ".cs", "Unexpected repository key");
            config.RepositoryLanguage.Should().Be("cs", "Unexpected language");
            config.RepositoryName.Should().Be("dummy title", "Unexpected repository name");

            // Check for the expected property values required by the C# plugin
            // Property name prefixes should be lower case; the case of the value should be the same as the package id
            AssertExpectedPropertyDefinitionValue(pluginId + ".cs.analyzerId", package.Id, config);
            AssertExpectedPropertyDefinitionValue(pluginId + ".cs.ruleNamespace", package.Id, config);
            AssertExpectedPropertyDefinitionValue(pluginId + ".cs.nuget.packageId", package.Id, config);
            AssertExpectedPropertyDefinitionValue(pluginId + ".cs.nuget.packageVersion", package.Version.ToString(), config);
            AssertExpectedPropertyDefinitionValue(pluginId + ".cs.staticResourceName", package.Id + "." + package.Version + ".zip", config);
            AssertExpectedPropertyDefinitionValue(pluginId + ".cs.pluginKey", pluginId.Replace(".", ""), config);
            AssertExpectedPropertyDefinitionValue(pluginId + ".cs.pluginVersion", package.Version.ToString(), config);

            // Check the contents of the manifest
            string actualManifestFilePath = jarChecker.AssertFileExists("META-INF\\MANIFEST.MF");

            var manifestReader = new JarManifestReader(File.ReadAllText(actualManifestFilePath));

            manifestReader.FindValue(WellKnownPluginProperties.Key).Should().Be(pluginId.Replace(".", ""));

            AssertPackagePropertiesInManifest(package, manifestReader);
            AssertFixedValuesInManifest(manifestReader);

            // Check the rules
            string actualRuleFilePath = jarChecker.AssertFileExists("." + config.RulesXmlResourcePath);

            AssertExpectedRulesExist(analyzer, actualRuleFilePath);

            // Now create another checker to check the contents of the zip file (strict check this time)
            CheckEmbeddedAnalyzerPayload(jarChecker, "static\\" + pluginId + "." + package.Version + ".zip",
                                         /* zip file contents */
                                         "analyzers\\RoslynAnalyzer11.dll");
        }
Beispiel #2
0
        private void CheckCanGenerateForThirdPartyAssembly(string packageId, SemanticVersion version)
        {
            // Arrange
            var logger    = new TestLogger();
            var outputDir = TestUtils.CreateTestDirectory(TestContext, ".out");
            var localPackageDestination    = TestUtils.CreateTestDirectory(TestContext, ".localpackages");
            var localRepoWithRemotePackage = InstallRemotePackageLocally(packageId, version);

            // Act
            var nuGetHandler = new NuGetPackageHandler(localRepoWithRemotePackage, localPackageDestination, logger);

            var apg    = new AnalyzerPluginGenerator(nuGetHandler, logger);
            var args   = new ProcessedArgs(packageId, version, "cs", null, false, false, outputDir);
            var result = apg.Generate(args);

            // Assert
            result.Should().BeTrue();

            // Expecting one plugin per dependency with analyzers
            AssertJarsGenerated(outputDir, 1);

            var jarFilePath            = Directory.GetFiles(outputDir, "*.jar", SearchOption.TopDirectoryOnly).Single();
            var jarChecker             = new ZipFileChecker(TestContext, jarFilePath);
            var actualManifestFilePath = jarChecker.AssertFileExists("META-INF\\MANIFEST.MF");

            JarManifestReader reader = new JarManifestReader(File.ReadAllText(actualManifestFilePath));

            AssertFixedValuesInManifest(reader);
        }
Beispiel #3
0
        private void CheckEmbeddedAnalyzerPayload(ZipFileChecker jarChecker, string staticResourceName,
                                                  params string[] expectedZipContents)
        {
            // Now create another checker to check the contents of the zip file (strict check this time)
            string embeddedZipFilePath = jarChecker.AssertFileExists(staticResourceName);

            ZipFileChecker embeddedFileChecker = new ZipFileChecker(TestContext, embeddedZipFilePath);

            embeddedFileChecker.AssertZipContainsOnlyExpectedFiles(expectedZipContents);
        }