diff --git a/build.gradle b/build.gradle
index a005494..26acf86 100644
--- a/build.gradle
+++ b/build.gradle
@@ -46,7 +46,7 @@ signPlugin {
}
publishPlugin {
- token = System.getenv("PUBLISH_TOKEN")
+ token = System.getenv("PUBLISH_TOKEN")
setHidden(findProperty("hidden").toBoolean())
channels = findProperty("preRelease").toBoolean() ? ["autoconfig-beta"] : ["default", "autoconfig-beta"]
}
@@ -72,7 +72,8 @@ intellij {
"Git4Idea",
"junit",
"org.jetbrains.plugins.yaml",
- "org.jetbrains.idea.maven"
+ "org.jetbrains.idea.maven",
+ "org.sonarlint.idea:10.8.1.79205"
]
}
buildSearchableOptions.enabled = false // Disable because it takes a long time and the plugin doesn't need it
@@ -285,7 +286,7 @@ jsonSchema2Pojo {
useOptionalForGetters = false
// properties to exclude from generated toString
- toStringExcludes = ["someProperty"]
+ toStringExcludes = []
// What Java version to target with generated source code (1.6, 1.8, 9, 11, etc).
// By default, the version will be taken from the Gradle Java plugin's 'sourceCompatibility',
diff --git a/gradle.properties b/gradle.properties
index c3c901d..db70320 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,5 +1,5 @@
# Autoconfig Plugin Properties
-pluginVersion = 1.0.2
+pluginVersion = 1.1.0
preRelease = false
hidden = false
pluginGroup = de.gebit.plugins.autoconfig
diff --git a/metadata/changelog.html b/metadata/changelog.html
index c8a957a..3d4f07a 100644
--- a/metadata/changelog.html
+++ b/metadata/changelog.html
@@ -5,9 +5,10 @@
Changelog
-1.0.3
+1.1.0
- support setting of module SDK
+ - support setting of module SonarQube project keys
1.0.2
diff --git a/src/main/java/de/gebit/plugins/autoconfig/UpdateModuleHandler.java b/src/main/java/de/gebit/plugins/autoconfig/UpdateModuleHandler.java
index 544d4fb..db90c76 100644
--- a/src/main/java/de/gebit/plugins/autoconfig/UpdateModuleHandler.java
+++ b/src/main/java/de/gebit/plugins/autoconfig/UpdateModuleHandler.java
@@ -36,4 +36,8 @@ default boolean acceptModule(T configuration, Module module) {
default UpdateTarget getUpdateTarget() {
return UpdateTarget.MODULE;
}
+
+ default boolean matchesAnyName(Module module, List patterns) {
+ return patterns.stream().anyMatch(p -> module.getName().matches(p));
+ }
}
diff --git a/src/main/java/de/gebit/plugins/autoconfig/handlers/common/CommonModuleConfigurationHandler.java b/src/main/java/de/gebit/plugins/autoconfig/handlers/common/CommonModuleConfigurationHandler.java
index 910c030..69b2aad 100644
--- a/src/main/java/de/gebit/plugins/autoconfig/handlers/common/CommonModuleConfigurationHandler.java
+++ b/src/main/java/de/gebit/plugins/autoconfig/handlers/common/CommonModuleConfigurationHandler.java
@@ -18,6 +18,7 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.function.Consumer;
/**
* Allow setting module SDK for a limited number of matching modules.
@@ -54,10 +55,6 @@ public boolean acceptModule(GeneralModuleConfiguration configuration, Module mod
return matchesAnyName(module, configuration.getModuleFilter());
}
- private static boolean matchesAnyName(Module module, List patterns) {
- return patterns.stream().anyMatch(p -> module.getName().matches(p));
- }
-
@Override
public List updateConfiguration(GeneralModuleConfiguration configuration, Module module) {
List updatedConfigs = new ArrayList<>();
@@ -78,17 +75,12 @@ private void applyModuleSDKOptions(ModuleSDK sdkOptions, Module module, List {
- modifiableModel.inheritSdk();
- modifiableModel.commit();
- });
+ commitModifiableModelChange(modifiableModel, ModifiableRootModel::inheritSdk);
updatedConfigs.add("Module SDK");
}
} else {
- applySetting(moduleSdk, currentModuleSdk, s -> WriteAction.runAndWait(() -> {
- modifiableModel.setSdk(s);
- modifiableModel.commit();
- }), updatedConfigs, "Module SDK");
+ applySetting(moduleSdk, currentModuleSdk, s -> commitModifiableModelChange(modifiableModel,
+ modifiableRootModel -> modifiableRootModel.setSdk(s)), updatedConfigs, "Module SDK");
}
}
} else {
@@ -98,4 +90,11 @@ private void applyModuleSDKOptions(ModuleSDK sdkOptions, Module module, List consumer) {
+ WriteAction.runAndWait(() -> {
+ consumer.accept(modifiableModel);
+ modifiableModel.commit();
+ });
+ }
}
diff --git a/src/main/java/de/gebit/plugins/autoconfig/handlers/sonarqube/SonarQubeModuleHandler.java b/src/main/java/de/gebit/plugins/autoconfig/handlers/sonarqube/SonarQubeModuleHandler.java
new file mode 100644
index 0000000..f4fabf7
--- /dev/null
+++ b/src/main/java/de/gebit/plugins/autoconfig/handlers/sonarqube/SonarQubeModuleHandler.java
@@ -0,0 +1,59 @@
+package de.gebit.plugins.autoconfig.handlers.sonarqube;
+
+import com.intellij.openapi.module.Module;
+import de.gebit.plugins.autoconfig.UpdateModuleHandler;
+import de.gebit.plugins.autoconfig.handlers.AbstractHandler;
+import de.gebit.plugins.autoconfig.model.SonarQubeConfiguration;
+import org.jetbrains.annotations.NonNls;
+import org.sonarlint.intellij.config.Settings;
+import org.sonarlint.intellij.config.module.SonarLintModuleSettings;
+import org.sonarlint.intellij.config.project.SonarLintProjectSettings;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Configuration handler used to synchronise SonarQube module bindings in projects.
+ */
+public class SonarQubeModuleHandler extends AbstractHandler implements UpdateModuleHandler {
+ private static final @NonNls String CONFIG_SCHEMA_JSON = "/schema/sonarqubeModule.schema.json";
+
+ public static final @NonNls String CONFIG_FILE_NAME = "autoconfigSonarQubeModule.yaml";
+
+ @Override
+ public String getFileName() {
+ return CONFIG_FILE_NAME;
+ }
+
+ @Override
+ public String getJsonSchema() {
+ return CONFIG_SCHEMA_JSON;
+ }
+
+ @Override
+ public String getUpdaterName() {
+ return "SonarQube module configuration updater";
+ }
+
+ @Override
+ public Class getConfigurationClass() {
+ return SonarQubeConfiguration.class;
+ }
+
+ @Override
+ public boolean acceptModule(SonarQubeConfiguration configuration, Module module) {
+ return matchesAnyName(module, configuration.getModuleFilter());
+ }
+
+ @Override
+ public List updateConfiguration(SonarQubeConfiguration configuration, Module module) {
+ List updatedConfigs = new ArrayList<>();
+ SonarLintProjectSettings projectSettings = Settings.getSettingsFor(module.getProject());
+ if (projectSettings.isBindingEnabled() && configuration.getProjectKey() != null) {
+ SonarLintModuleSettings moduleSettings = Settings.getSettingsFor(module);
+ applySetting(configuration.getProjectKey(), moduleSettings.getProjectKey(), moduleSettings::setProjectKey,
+ updatedConfigs, "SonarQube module key");
+ }
+ return updatedConfigs;
+ }
+}
diff --git a/src/main/java/de/gebit/plugins/autoconfig/service/ConfigurationUpdaterService.java b/src/main/java/de/gebit/plugins/autoconfig/service/ConfigurationUpdaterService.java
index 18a642b..61fc025 100644
--- a/src/main/java/de/gebit/plugins/autoconfig/service/ConfigurationUpdaterService.java
+++ b/src/main/java/de/gebit/plugins/autoconfig/service/ConfigurationUpdaterService.java
@@ -12,6 +12,7 @@
import de.gebit.plugins.autoconfig.AutoconfigStartup;
import de.gebit.plugins.autoconfig.UpdateHandler;
import de.gebit.plugins.autoconfig.UpdateModuleHandler;
+import de.gebit.plugins.autoconfig.util.Notifications;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -101,9 +102,19 @@ private List processModuleUpdateHandler(@NotNull List List processUpdateHandler(@NotNull Project project, UpdateHandler updateHandler, ConfigurationLoaderService projectService, VirtualFile configDirectory) {
Optional extensionConfiguration = projectService.getConfiguration(updateHandler.getConfigurationClass(),
updateHandler.getFileName(), configDirectory);
- return extensionConfiguration.map(c -> updateHandler.updateConfiguration(c, project)).orElseGet(() -> {
+ final List emptyList = Collections.emptyList();
+ return extensionConfiguration.map(c -> {
+ try {
+ return updateHandler.updateConfiguration(c, project);
+ } catch (Exception e) {
+ String errorMessage = "An error occurred trying to process configuration updates for \"" + updateHandler.getUpdaterName() + "\"";
+ LOG.error(errorMessage, e);
+ Notifications.showError(errorMessage, project);
+ }
+ return emptyList;
+ }).orElseGet(() -> {
LOG.info("No configuration for " + updateHandler.getUpdaterName() + " found.");
- return Collections.emptyList();
+ return emptyList;
});
}
diff --git a/src/main/resources/META-INF/plugin-git.xml b/src/main/resources/META-INF/plugin-git.xml
index db118c8..e75beb5 100644
--- a/src/main/resources/META-INF/plugin-git.xml
+++ b/src/main/resources/META-INF/plugin-git.xml
@@ -1,4 +1,5 @@
+ de.gebit.plugins.autoconfig
diff --git a/src/main/resources/META-INF/plugin-java.xml b/src/main/resources/META-INF/plugin-java.xml
index 861604b..82e2c15 100644
--- a/src/main/resources/META-INF/plugin-java.xml
+++ b/src/main/resources/META-INF/plugin-java.xml
@@ -1,4 +1,5 @@
+ de.gebit.plugins.autoconfig
diff --git a/src/main/resources/META-INF/plugin-maven.xml b/src/main/resources/META-INF/plugin-maven.xml
index 808d8a8..3f9e148 100644
--- a/src/main/resources/META-INF/plugin-maven.xml
+++ b/src/main/resources/META-INF/plugin-maven.xml
@@ -1,4 +1,5 @@
+ de.gebit.plugins.autoconfig
diff --git a/src/main/resources/META-INF/plugin-sonarqube.xml b/src/main/resources/META-INF/plugin-sonarqube.xml
new file mode 100644
index 0000000..2fdb240
--- /dev/null
+++ b/src/main/resources/META-INF/plugin-sonarqube.xml
@@ -0,0 +1,6 @@
+
+ de.gebit.plugins.autoconfig
+
+
+
+
diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml
index 7c52721..2bbe5b6 100644
--- a/src/main/resources/META-INF/plugin.xml
+++ b/src/main/resources/META-INF/plugin.xml
@@ -10,6 +10,7 @@
Git4Idea
org.jetbrains.idea.maven
com.intellij.modules.java
+ org.sonarlint.idea
diff --git a/src/main/resources/schema/sonarqubeModule.schema.json b/src/main/resources/schema/sonarqubeModule.schema.json
new file mode 100644
index 0000000..454377e
--- /dev/null
+++ b/src/main/resources/schema/sonarqubeModule.schema.json
@@ -0,0 +1,23 @@
+{
+ "$id": "https://www.gebit.de/autoconfig-intellij-plugin/sonarqubeModule.schema.json",
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "title": "SonarQube configuration",
+ "type": "object",
+ "required": [
+ "moduleFilter"
+ ],
+ "properties": {
+ "moduleFilter": {
+ "type": "array",
+ "description": "List of modules/module regex patterns. Modules that match any of the names/patterns will be configured by this configuration.",
+ "items": {
+ "type": "string",
+ "description": "Module name/pattern"
+ }
+ },
+ "projectKey": {
+ "type": "string",
+ "description": "The SonarQube project key to use for all matching modules"
+ }
+ }
+}
\ No newline at end of file