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"); }
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); }
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"); }
/// <summary> /// Some of the properties in the template manifest should /// be preserved e.g. the supported SonarQube version /// </summary> private void CopyReservedPropertiesFromExistingManifest(string templateManifest) { var reader = new JarManifestReader(templateManifest); CopyValueFromExistingManifest(reader, "Sonar-Version"); CopyValueFromExistingManifest(reader, "Plugin-Dependencies"); CopyValueFromExistingManifest(reader, "Plugin-Class"); CopyValueFromExistingManifest(reader, "SonarLint-Supported"); // applies to other IDEs i.e. not VS }
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()); }
private void CopyValueFromExistingManifest(JarManifestReader reader, string property) { if (jarManifestBuilder.TryGetValue(property, out string value)) { throw new InvalidOperationException( string.Format(System.Globalization.CultureInfo.CurrentCulture, UIResources.Builder_Error_ManifestPropertyShouldBeCopiedFromTemplate, property)); } jarManifestBuilder.SetProperty(property, reader.GetValue(property)); }
public void Get_MissingSetting_Throws() { // Arrange var text = @"Manifest-Version: 1.0"; var jarReader = new JarManifestReader(text); // Act Action act = () => jarReader.GetValue("missing-key"); // Assert act.Should().ThrowExactly <InvalidOperationException>().And.Message.Should().Be("The expected setting was not found in the manifest file: missing-key"); }
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"); }