private static void CheckGetValidKeyThrows(string input) { // Should throw on input that cannot be corrected Action action = () => PluginKeyUtilities.GetValidKey(input); action.Should().Throw <ArgumentException>(); }
private static void TestGetValidKey(string input, string expected) { string actual = PluginKeyUtilities.GetValidKey(input); Assert.AreEqual(expected, actual, "Unexpected plugin key returned"); PluginKeyUtilities.ThrowIfInvalid(expected); // should not throw on values returned by GetValidKey }
private string FindPluginKey() { jarManifestBuilder.TryGetValue(WellKnownPluginProperties.Key, out string pluginKey); if (pluginKey != null) { pluginKey = PluginKeyUtilities.GetValidKey(pluginKey); } return(pluginKey); }
public void CreatePluginManifest_AllProperties() { // All properties present, all properties expected. // Arrange DataServicePackage testPackage = CreateTestDataServicePackage(); testPackage.Description = "Test Description"; testPackage.Authors = "TestAuthor1,TestAuthor2"; testPackage.ProjectUrl = new Uri("http://test.project.url"); testPackage.Id = "Test.Id"; testPackage.Title = "Test Title"; testPackage.Owners = "TestOwner1,TestOwner2"; testPackage.Version = "1.1.1-RC5"; testPackage.LicenseUrl = new Uri("http://test.license.url"); testPackage.LicenseNames = "Test License1;Test License2"; // Act PluginManifest actualPluginManifest = AnalyzerPluginGenerator.CreatePluginManifest(testPackage); // Assert actualPluginManifest.Should().NotBeNull(); actualPluginManifest.Description.Should().Be(testPackage.Description); actualPluginManifest.Developers.Should().Be(testPackage.Authors); actualPluginManifest.Homepage.Should().Be(testPackage.ProjectUrl.ToString()); actualPluginManifest.Key.Should().Be(PluginKeyUtilities.GetValidKey(testPackage.Id)); actualPluginManifest.Name.Should().Be(testPackage.Title); actualPluginManifest.Organization.Should().Be(testPackage.Owners); actualPluginManifest.Version.Should().Be(testPackage.Version); actualPluginManifest.TermsConditionsUrl.Should().Be(testPackage.LicenseUrl.ToString()); actualPluginManifest.License.Should().Be(testPackage.LicenseNames); }
public /* for test */ static PluginManifest CreatePluginManifest(IPackage package) { // The manifest properties supported by SonarQube are documented at // http://docs.sonarqube.org/display/DEV/Build+plugin PluginManifest pluginDefn = new PluginManifest(); pluginDefn.Description = GetValidManifestString(package.Description); pluginDefn.Developers = GetValidManifestString(ListToString(package.Authors)); pluginDefn.Homepage = GetValidManifestString(package.ProjectUrl?.ToString()); pluginDefn.Key = PluginKeyUtilities.GetValidKey(package.Id); if (!String.IsNullOrWhiteSpace(package.Title)) { pluginDefn.Name = GetValidManifestString(package.Title); } else { // Process the package ID to replace dot separators with spaces for use as a fallback pluginDefn.Name = GetValidManifestString(package.Id.Replace(".", " ")); } // Fall back to using the authors if owners is empty string organisation; if (package.Owners.Any()) { organisation = ListToString(package.Owners); } else { organisation = ListToString(package.Authors); } pluginDefn.Organization = GetValidManifestString(organisation); pluginDefn.Version = GetValidManifestString(package.Version?.ToNormalizedString()); // The TermsConditionsUrl is only displayed in the "Update Center - Available" page // i.e. for plugins that are available through the public Update Center. // If the property has a value then the link will be displayed with a checkbox // for acceptance. // It is not used when plugins are directly dropped into the extensions\plugins // folder of the SonarQube server. pluginDefn.TermsConditionsUrl = GetValidManifestString(package.LicenseUrl?.ToString()); // Packages from the NuGet website may have friendly short licensenames heuristically assigned, but this requires a downcast DataServicePackage dataServicePackage = package as DataServicePackage; if (!String.IsNullOrWhiteSpace(dataServicePackage?.LicenseNames)) { pluginDefn.License = GetValidManifestString(dataServicePackage.LicenseNames); } else { // Fallback - use a raw URL. Not as nice-looking in the UI, but acceptable. pluginDefn.License = pluginDefn.TermsConditionsUrl; } return(pluginDefn); }
private static void CheckGetValidKeyThrows(string input) { // Should throw on input that cannot be corrected AssertException.Expect <ArgumentException>(() => PluginKeyUtilities.GetValidKey(input)); }