예제 #1
0
 private static void AssertFixedValuesInManifest(JarManifestReader reader)
 {
     reader.FindValue("Sonar-Version").Should().Be("6.7");
     reader.FindValue("Plugin-Class").Should().Be("org.sonar.plugins.roslynsdk.RoslynSdkGeneratedPlugin");
     reader.FindValue("SonarLint-Supported").Should().Be("false");
     reader.FindValue("Plugin-Dependencies").Should().Be("META-INF/lib/jsr305-1.3.9.jar META-INF/lib/commons-io-2.6.jar META-INF/lib/stax2-api-3.1.4.jar META-INF/lib/staxmate-2.0.1.jar META-INF/lib/stax-api-1.0.1.jar");
 }
예제 #2
0
        public void ReadSingleAndMultiLines()
        {
            // Arrange
            var text = @"Manifest-Version: 1.0

Plugin-Dependencies: META-INF/lib/jsr305-1.3.9.jar META-INF/lib/common
 s-io-2.6.jar META-INF/lib/stax2-api-3.1.4.jar META-INF/lib/staxmate-2
 .0.1.jar META-INF/lib/stax-api-1.0.1.jar
Plugin-SourcesUrl: https://github.com/SonarSource-VisualStudio/sonarqu
 be-roslyn-sdk-template-plugin


";
            // Act
            var jarReader = new JarManifestReader(text);

            // Assert
            jarReader.FindValue("Manifest-Version").Should().Be("1.0");

            // Multi-line value should be concatenated correctly
            jarReader.FindValue("Plugin-Dependencies").Should().Be("META-INF/lib/jsr305-1.3.9.jar META-INF/lib/commons-io-2.6.jar META-INF/lib/stax2-api-3.1.4.jar META-INF/lib/staxmate-2.0.1.jar META-INF/lib/stax-api-1.0.1.jar");

            // Multi-line with blank lines after - blanks ignored
            jarReader.FindValue("Plugin-SourcesUrl").Should().Be(@"https://github.com/SonarSource-VisualStudio/sonarqube-roslyn-sdk-template-plugin");

            // Not case-sensitive
            jarReader.FindValue("MANIFEST-VERSION").Should().Be("1.0");
        }
예제 #3
0
 private static void AssertPackagePropertiesInManifest(IPackage package, JarManifestReader manifestReader)
 {
     manifestReader.FindValue("Plugin-Name").Should().Be(package.Title);
     manifestReader.FindValue("Plugin-Version").Should().Be(package.Version.ToString());
     manifestReader.FindValue("Plugin-Description").Should().Be(package.Description);
     manifestReader.FindValue("Plugin-Organization").Should().Be(String.Join(",", package.Owners));
     manifestReader.FindValue("Plugin-Homepage").Should().Be(package.ProjectUrl.ToString());
     manifestReader.FindValue("Plugin-Developers").Should().Be(String.Join(",", package.Authors));
     manifestReader.FindValue("Plugin-TermsConditionsUrl").Should().Be(package.LicenseUrl.ToString());
 }
예제 #4
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");
        }