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); }
private static void SetNonNullManifestProperty(string property, string value, PluginBuilder pluginBuilder) { if (!string.IsNullOrWhiteSpace(value)) { pluginBuilder.SetProperty(property, value); } }
private static void AddRuleJars(string workingDirectory, PluginBuilder builder) { // Unpack and reference the required jar files SourceGenerator.UnpackReferencedJarFiles(typeof(RulesPluginBuilder).Assembly, RulesResourcesRoot, workingDirectory); foreach (string jarFile in Directory.GetFiles(workingDirectory, "*.jar")) { builder.AddReferencedJar(jarFile); } }
private static void AddRuleSources(string workingDirectory, PluginBuilder builder) { SourceGenerator.CreateSourceFiles(typeof(RulesPluginBuilder).Assembly, RulesResourcesRoot, workingDirectory, new Dictionary <string, string>()); foreach (string sourceFile in Directory.GetFiles(workingDirectory, "*.java", SearchOption.AllDirectories)) { builder.AddSourceFile(sourceFile); } }
public static PluginBuilder SetPluginName(this PluginBuilder builder, string name) { if (builder == null) { throw new ArgumentNullException("builder"); } if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException("name"); } builder.SetProperty(WellKnownPluginProperties.PluginName, name); return(builder); }
public static PluginBuilder SetPluginKey(this PluginBuilder builder, string key) { if (builder == null) { throw new ArgumentNullException("builder"); } if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException("key"); } builder.SetProperty(WellKnownPluginProperties.Key, key); return(builder); }
/// <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(); }
private static void ConfigureSourceFileReplacements(string language, PluginBuilder builder) { builder.SetSourceCodeTokenReplacement(WellKnownSourceCodeTokens.Rule_Language, language); }
private static void AddRuleSources(string workingDirectory, PluginBuilder builder) { SourceGenerator.CreateSourceFiles(typeof(RulesPluginBuilder).Assembly, RulesResourcesRoot, workingDirectory, new Dictionary<string, string>()); foreach (string sourceFile in Directory.GetFiles(workingDirectory, "*.java", SearchOption.AllDirectories)) { builder.AddSourceFile(sourceFile); } }
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); }