public static PluginBuilder SetProperties(this PluginBuilder builder, PluginManifest definition) { if (builder == null) { throw new ArgumentNullException("builder"); } if (definition == null) { throw new ArgumentNullException("definition"); } SetNonNullManifestProperty(WellKnownPluginProperties.License, definition.License, builder); SetNonNullManifestProperty(WellKnownPluginProperties.OrganizationUrl, definition.OrganizationUrl, builder); SetNonNullManifestProperty(WellKnownPluginProperties.Version, definition.Version, builder); SetNonNullManifestProperty(WellKnownPluginProperties.Homepage, definition.Homepage, builder); SetNonNullManifestProperty(WellKnownPluginProperties.SourcesUrl, definition.SourcesUrl, builder); SetNonNullManifestProperty(WellKnownPluginProperties.Developers, definition.Developers, builder); SetNonNullManifestProperty(WellKnownPluginProperties.IssueTrackerUrl, definition.IssueTrackerUrl, builder); SetNonNullManifestProperty(WellKnownPluginProperties.TermsAndConditionsUrl, definition.TermsConditionsUrl, builder); SetNonNullManifestProperty(WellKnownPluginProperties.OrganizationName, definition.Organization, builder); SetNonNullManifestProperty(WellKnownPluginProperties.PluginName, definition.Name, builder); SetNonNullManifestProperty(WellKnownPluginProperties.Description, definition.Description, builder); SetNonNullManifestProperty(WellKnownPluginProperties.Key, definition.Key, builder); return(builder); }
private static void DoConfigureBuilder(PluginBuilder builder, PluginManifest definition, string language, string rulesFilePath, string sqaleFilePath, string workingFolder) { string uniqueId = Guid.NewGuid().ToString(); AddRuleSources(workingFolder, builder); ConfigureSourceFileReplacements(language, builder); builder.SetSourceCodeTokenReplacement("[RESOURCE_ID]", uniqueId); builder.AddExtension(RulesExtensionClassName); AddRuleJars(workingFolder, builder); // Add the rules and sqale files as resources // The files are uniquely named to avoid issues with multiple resources // of the same name in different jars on the classpath. This shouldn't be // an issue with SonarQube as plugins should be loaded in isolation from each other // but it simplifies testing. builder.AddResourceFile(rulesFilePath, "resources/" + uniqueId + ".rules.xml"); if (!string.IsNullOrEmpty(sqaleFilePath)) { builder.AddResourceFile(rulesFilePath, "resources/" + uniqueId + ".sqale.xml"); } // TODO: consider moving - not specific to the rules plugin builder.SetProperties(definition); }
public static PluginBuilder SetProperties(this PluginBuilder builder, PluginManifest definition) { if (builder == null) { throw new ArgumentNullException("builder"); } if (definition == null) { throw new ArgumentNullException("definition"); } SetNonNullManifestProperty(WellKnownPluginProperties.License, definition.License, builder); SetNonNullManifestProperty(WellKnownPluginProperties.OrganizationUrl, definition.OrganizationUrl, builder); SetNonNullManifestProperty(WellKnownPluginProperties.Version, definition.Version, builder); SetNonNullManifestProperty(WellKnownPluginProperties.Homepage, definition.Homepage, builder); SetNonNullManifestProperty(WellKnownPluginProperties.SourcesUrl, definition.SourcesUrl, builder); SetNonNullManifestProperty(WellKnownPluginProperties.Developers, definition.Developers, builder); SetNonNullManifestProperty(WellKnownPluginProperties.IssueTrackerUrl, definition.IssueTrackerUrl, builder); SetNonNullManifestProperty(WellKnownPluginProperties.TermsAndConditionsUrl, definition.TermsConditionsUrl, builder); SetNonNullManifestProperty(WellKnownPluginProperties.OrganizationName, definition.Organization, builder); SetNonNullManifestProperty(WellKnownPluginProperties.PluginName, definition.Name, builder); SetNonNullManifestProperty(WellKnownPluginProperties.Description, definition.Description, builder); SetNonNullManifestProperty(WellKnownPluginProperties.Key, definition.Key, builder); return builder; }
public void Defn_Serialization() { string testDir = TestUtils.CreateTestDirectory(this.TestContext); string filePath = Path.Combine(testDir, "defn1.txt"); PluginManifest originalDefn = new PluginManifest() { Name = "name", Class = "class", Description = "description", Key = "key", Developers = "developers", Homepage = "homepage", IssueTrackerUrl = "issuetracker", License ="license", Organization = "organization", OrganizationUrl = "organizationurl", SourcesUrl ="sources", TermsConditionsUrl = "terms", Version = "version" }; originalDefn.Save(filePath); Assert.IsTrue(File.Exists(filePath), "File was not created: {0}", filePath); PluginManifest reloadedDefn = PluginManifest.Load(filePath); Assert.IsNotNull(reloadedDefn, "Reloaded object should not be null"); Assert.AreEqual("name", reloadedDefn.Name, "Unexpected name"); Assert.AreEqual("class", reloadedDefn.Class, "Unexpected class"); Assert.AreEqual("description", reloadedDefn.Description, "Unexpected description"); Assert.AreEqual("key", reloadedDefn.Key, "Unexpected key"); Assert.AreEqual("issuetracker", reloadedDefn.IssueTrackerUrl, "Unexpected issue tracker url"); Assert.AreEqual("license", reloadedDefn.License, "Unexpected license"); Assert.AreEqual("developers", reloadedDefn.Developers, "Unexpected developers"); Assert.AreEqual("homepage", reloadedDefn.Homepage, "Unexpected homepage"); Assert.AreEqual("organization", reloadedDefn.Organization, "Unexpected organization"); Assert.AreEqual("organizationurl", reloadedDefn.OrganizationUrl, "Unexpected organization url"); Assert.AreEqual("sources", reloadedDefn.SourcesUrl, "Unexpected sources"); Assert.AreEqual("terms", reloadedDefn.TermsConditionsUrl, "Unexpected terms"); Assert.AreEqual("version", reloadedDefn.Version, "Unexpected version"); this.TestContext.AddResultFile(filePath); }
public static PluginManifest Load(string filePath) { if (string.IsNullOrWhiteSpace(filePath)) { throw new ArgumentNullException("filePath"); } XmlSerializer serializer = new XmlSerializer(typeof(PluginManifest)); PluginManifest defn = null; using (Stream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { defn = serializer.Deserialize(stream) as PluginManifest; } defn.FilePath = filePath; return(defn); }
/// <summary> /// Configures the supplied builder to add a new repository with the specified /// rules and (optionally) SQALE information /// </summary> /// <param name="builder">The builder to configure</param> /// <param name="pluginManifest">Manifest that describes the plugin to SonarQube</param> /// <param name="language">The language for the rules</param> /// <param name="rulesFilePath">Path to the file containing the rule definitions</param> /// <param name="sqaleFilePath">(Optional) path to the file containing SQALE information for the new rules</param> public static void ConfigureBuilder(PluginBuilder builder, PluginManifest pluginManifest, string language, string rulesFilePath, string sqaleFilePath) { if (builder == null) { throw new ArgumentNullException("builder"); } if (pluginManifest == null) { throw new ArgumentNullException("pluginManifest"); } if (string.IsNullOrWhiteSpace(language)) { throw new ArgumentNullException("language"); } if (string.IsNullOrWhiteSpace(rulesFilePath)) { throw new ArgumentNullException("rulesFilePath"); } if (!File.Exists(rulesFilePath)) { throw new FileNotFoundException(UIResources.Gen_Error_RulesFileDoesNotExists, rulesFilePath); } if (!string.IsNullOrEmpty(sqaleFilePath) && !File.Exists(sqaleFilePath)) { throw new FileNotFoundException(UIResources.Gen_Error_SqaleFileDoesNotExists, sqaleFilePath); } // TODO: move - not specific to rules plugins ValidateManifest(pluginManifest); // Temp folder which resources will be unpacked into string tempWorkingDir = Path.Combine(Path.GetTempPath(), ".plugins", Guid.NewGuid().ToString()); Directory.CreateDirectory(tempWorkingDir); DoConfigureBuilder(builder, pluginManifest, language, rulesFilePath, sqaleFilePath, tempWorkingDir); }
/// <summary> /// Configures the supplied builder to add a new repository with the specified /// rules and (optionally) SQALE information /// </summary> /// <param name="builder">The builder to configure</param> /// <param name="pluginManifest">Manifest that describes the plugin to SonarQube</param> /// <param name="language">The language for the rules</param> /// <param name="rulesFilePath">Path to the file containing the rule definitions</param> /// <param name="sqaleFilePath">(Optional) path to the file containing SQALE information for the new rules</param> public static void ConfigureBuilder(PluginBuilder builder, PluginManifest pluginManifest, string language, string rulesFilePath, string sqaleFilePath) { if (builder == null) { throw new ArgumentNullException("builder"); } if (pluginManifest == null) { throw new ArgumentNullException("pluginManifest"); } if (string.IsNullOrWhiteSpace(language)) { throw new ArgumentNullException("language"); } if (string.IsNullOrWhiteSpace(rulesFilePath)) { throw new ArgumentNullException("rulesFilePath"); } if (!File.Exists(rulesFilePath)) { throw new FileNotFoundException(UIResources.Gen_Error_RulesFileDoesNotExists, rulesFilePath); } if (!string.IsNullOrEmpty(sqaleFilePath) && !File.Exists(sqaleFilePath)) { throw new FileNotFoundException(UIResources.Gen_Error_SqaleFileDoesNotExists, sqaleFilePath); } // TODO: move - not specific to rules plugins ValidateManifest(pluginManifest); // Temp folder which resources will be unpacked into string tempWorkingDir = Path.Combine(Path.GetTempPath(), ".plugins", Guid.NewGuid().ToString()); Directory.CreateDirectory(tempWorkingDir); DoConfigureBuilder(builder, pluginManifest, language, rulesFilePath, sqaleFilePath, tempWorkingDir); }
//TODO: remove once the tests have been refactored to test "ConfigureBuilder" public void GeneratePlugin(PluginManifest definition, string language, string rulesFilePath, string fullJarFilePath) { if (definition == null) { throw new ArgumentNullException("definition"); } if (string.IsNullOrWhiteSpace(rulesFilePath)) { throw new ArgumentNullException("rulesFilePath"); } if (string.IsNullOrWhiteSpace(fullJarFilePath)) { throw new ArgumentNullException("fullJarFilePath"); } if (!File.Exists(rulesFilePath)) { throw new FileNotFoundException(UIResources.Gen_Error_RulesFileDoesNotExists, rulesFilePath); } if (!this.jdkWrapper.IsJdkInstalled()) { throw new InvalidOperationException(UIResources.JarB_JDK_NotInstalled); } if (File.Exists(fullJarFilePath)) { this.logger.LogWarning(UIResources.Gen_ExistingJarWillBeOvewritten); } PluginBuilder builder = new PluginBuilder(jdkWrapper, logger); ConfigureBuilder(builder, definition, language, rulesFilePath, null); builder.SetJarFilePath(fullJarFilePath); builder.Build(); }
//TODO: remove once the tests have been refactored to test "ConfigureBuilder" public void GeneratePlugin(PluginManifest definition, string language, string rulesFilePath, string fullJarFilePath) { if (definition == null) { throw new ArgumentNullException("definition"); } if (string.IsNullOrWhiteSpace(rulesFilePath)) { throw new ArgumentNullException("rulesFilePath"); } if (string.IsNullOrWhiteSpace(fullJarFilePath)) { throw new ArgumentNullException("fullJarFilePath"); } if (!File.Exists(rulesFilePath)) { throw new FileNotFoundException(UIResources.Gen_Error_RulesFileDoesNotExists, rulesFilePath); } if (!this.jdkWrapper.IsJdkInstalled()) { throw new InvalidOperationException(UIResources.JarB_JDK_NotInstalled); } if (File.Exists(fullJarFilePath)) { this.logger.LogWarning(UIResources.Gen_ExistingJarWillBeOvewritten); } PluginBuilder builder = new PluginBuilder(jdkWrapper, logger); ConfigureBuilder(builder, definition, language, rulesFilePath, null); builder.SetJarFilePath(fullJarFilePath); builder.Build(); }
private static void DoConfigureBuilder(PluginBuilder builder, PluginManifest definition, string language, string rulesFilePath, string sqaleFilePath, string workingFolder) { string uniqueId = Guid.NewGuid().ToString(); AddRuleSources(workingFolder, builder); ConfigureSourceFileReplacements(language, builder); builder.SetSourceCodeTokenReplacement("[RESOURCE_ID]", uniqueId); builder.AddExtension(RulesExtensionClassName); AddRuleJars(workingFolder, builder); // Add the rules and sqale files as resources // The files are uniquely named to avoid issues with multiple resources // of the same name in different jars on the classpath. This shouldn't be // an issue with SonarQube as plugins should be loaded in isolation from each other // but it simplifies testing. builder.AddResourceFile(rulesFilePath, "resources/" + uniqueId + ".rules.xml"); if (!string.IsNullOrEmpty(sqaleFilePath)) { builder.AddResourceFile(rulesFilePath, "resources/" + uniqueId + ".sqale.xml"); } // TODO: consider moving - not specific to the rules plugin builder.SetProperties(definition); }
private static void ValidateManifest(PluginManifest definition) { // TODO CheckPropertyIsSet(definition.Key, "Key"); CheckPropertyIsSet(definition.Name, "Name"); }
private static void DoConfigureBuilder(PluginBuilder builder, PluginManifest definition, string language, string rulesFilePath, string sqaleFilePath, string workingFolder) { AddRuleSources(workingFolder, builder); ConfigureSourceFileReplacements(language, builder); builder.AddExtension(RulesExtensionClassName); AddRuleJars(workingFolder, builder); // Add the rules and sqale files as resources builder.AddResourceFile(rulesFilePath, "resources/rules.xml"); if (!string.IsNullOrEmpty(sqaleFilePath)) { builder.AddResourceFile(rulesFilePath, "resources/sqale.xml"); } // TODO: consider moving - not specific to the rules plugin builder.SetProperties(definition); }
private static void ValidateManifest(PluginManifest definition) { // TODO CheckPropertyIsSet(definition.Key, "Key"); CheckPropertyIsSet(definition.Name, "Name"); }