diff --git a/build.gradle b/build.gradle
index 137c9bf..26acf86 100644
--- a/build.gradle
+++ b/build.gradle
@@ -286,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/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/AutoconfigStartup.java b/src/main/java/de/gebit/plugins/autoconfig/AutoconfigStartup.java
index 9415a42..f676f37 100644
--- a/src/main/java/de/gebit/plugins/autoconfig/AutoconfigStartup.java
+++ b/src/main/java/de/gebit/plugins/autoconfig/AutoconfigStartup.java
@@ -8,81 +8,24 @@
package de.gebit.plugins.autoconfig;
-import com.intellij.ide.impl.TrustedProjects;
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.ProjectActivity;
-import de.gebit.plugins.autoconfig.util.Notifications;
+import de.gebit.plugins.autoconfig.service.ConfigurationUpdaterService;
import kotlin.Unit;
import kotlin.coroutines.Continuation;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
-
-import static de.gebit.plugins.autoconfig.util.Notifications.showInfo;
-
/**
* Entry point for the opening of a project. The yaml configuration file is read here, the resulting configuration
* options object is passed to the CommonConfigurationHandler. At the end, a message is composed, displaying a list of
* all updated configuration options.
*/
public class AutoconfigStartup implements ProjectActivity {
- private static final com.intellij.openapi.diagnostic.Logger LOG = Logger.getInstance(AutoconfigStartup.class);
-
- public static final ExtensionPointName> EP_NAME = ExtensionPointName.create(
- "de.gebit.plugins.autoconfig.configurationUpdater");
@Nullable
@Override
public Object execute(@NotNull Project project, @NotNull Continuation super Unit> continuation) {
- return runAutoconfig(project);
- }
-
- @SuppressWarnings("UnstableApiUsage")
- public @Nullable List runAutoconfig(@NotNull Project project) {
- ConfigurationLoaderService projectService = project.getService(ConfigurationLoaderService.class);
- if (projectService == null || !projectService.hasAutoconfigDir()) {
- return null;
- }
-
- if (!TrustedProjects.isTrusted(project)) {
- showInfo("Project configuration has not been updated, because project was opened in safe mode.", project);
- return null;
- }
-
- List changedConfigs = new ArrayList<>();
-
- for (UpdateHandler> updateHandler : EP_NAME.getExtensionList()) {
- changedConfigs.addAll(processUpdateHandler(project, updateHandler, projectService));
- }
-
- if (!changedConfigs.isEmpty()) {
- String notification = String.join(", ", changedConfigs);
- showInfo("New project configurations applied: " + notification, project);
- }
-
- return changedConfigs;
- }
-
- private List processUpdateHandler(@NotNull Project project, UpdateHandler updateHandler, ConfigurationLoaderService projectService) {
- Optional extensionConfiguration = projectService.getConfiguration(updateHandler.getConfigurationClass(),
- updateHandler.getFileName());
- if (extensionConfiguration.isPresent()) {
- try {
- return updateHandler.updateConfiguration(extensionConfiguration.get(), 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);
- }
- } else {
- LOG.info("No configuration for " + updateHandler.getUpdaterName() + " found.");
- }
- return Collections.emptyList();
+ return project.getService(ConfigurationUpdaterService.class).runAutoconfig();
}
}
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/sonarlint/SonarLintHandler.java b/src/main/java/de/gebit/plugins/autoconfig/handlers/sonarlint/SonarLintHandler.java
deleted file mode 100644
index 6e15e16..0000000
--- a/src/main/java/de/gebit/plugins/autoconfig/handlers/sonarlint/SonarLintHandler.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package de.gebit.plugins.autoconfig.handlers.sonarlint;
-
-import com.intellij.openapi.module.Module;
-import com.intellij.openapi.module.ModuleManager;
-import com.intellij.openapi.project.Project;
-import de.gebit.plugins.autoconfig.UpdateHandler;
-import de.gebit.plugins.autoconfig.handlers.AbstractHandler;
-import de.gebit.plugins.autoconfig.model.Binding;
-import de.gebit.plugins.autoconfig.model.SonarLintConfiguration;
-import org.jetbrains.annotations.NonNls;
-import org.sonarlint.intellij.config.Settings;
-import org.sonarlint.intellij.config.module.SonarLintModuleSettings;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-/**
- * Configuration handler used to synchronise SonarLint module bindings in projects.
- */
-public class SonarLintHandler extends AbstractHandler implements UpdateHandler {
- private static final @NonNls String CONFIG_SCHEMA_JSON = "/schema/sonarlint.schema.json";
-
- public static final @NonNls String CONFIG_FILE_NAME = "autoconfigSonarLint.yaml";
-
- @Override
- public String getFileName() {
- return CONFIG_FILE_NAME;
- }
-
- @Override
- public String getJsonSchema() {
- return CONFIG_SCHEMA_JSON;
- }
-
- @Override
- public String getUpdaterName() {
- return "SonarLint configuration updater";
- }
-
- @Override
- public Class getConfigurationClass() {
- return SonarLintConfiguration.class;
- }
-
- @Override
- public List updateConfiguration(SonarLintConfiguration configuration, Project project) {
- if (configuration.getBindings() != null) {
- Map moduleMap = Arrays.stream(ModuleManager.getInstance(project).getModules())
- .collect(Collectors.toMap(Module::getName, m -> m));
- // create a dummy list for the purpose of collecting the number of changes only
- List changedModuleConfigs = new ArrayList<>();
- for (Binding binding : configuration.getBindings()) {
- moduleMap.entrySet().stream().filter(e -> e.getKey().matches(binding.getModulePattern())).forEach(e -> {
- SonarLintModuleSettings moduleSettings = Settings.getSettingsFor(e.getValue());
- applySetting(binding.getProjectKey(), moduleSettings.getProjectKey(), moduleSettings::setProjectKey,
- changedModuleConfigs, "unused");
- });
- }
-
- // sum up number of changes for the notification
- if (!changedModuleConfigs.isEmpty()) {
- return Collections.singletonList(
- "Updated " + changedModuleConfigs.size() + " SonarLint module project key(s).");
- }
- }
- return Collections.emptyList();
- }
-}
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 359cb82..61fc025 100644
--- a/src/main/java/de/gebit/plugins/autoconfig/service/ConfigurationUpdaterService.java
+++ b/src/main/java/de/gebit/plugins/autoconfig/service/ConfigurationUpdaterService.java
@@ -107,11 +107,9 @@ private List processUpdateHandler(@NotNull Project project, UpdateHa
try {
return updateHandler.updateConfiguration(c, project);
} catch (Exception e) {
- LOG.error("An error occurred trying to process configuration updates for \"{}\"", e,
- updateHandler.getUpdaterName());
- Notifications.showError(
- "An error occurred trying to process configuration updates for \"" + updateHandler.getUpdaterName() + "\"",
- project);
+ String errorMessage = "An error occurred trying to process configuration updates for \"" + updateHandler.getUpdaterName() + "\"";
+ LOG.error(errorMessage, e);
+ Notifications.showError(errorMessage, project);
}
return emptyList;
}).orElseGet(() -> {
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-sonarlint.xml b/src/main/resources/META-INF/plugin-sonarlint.xml
deleted file mode 100644
index 16a1027..0000000
--- a/src/main/resources/META-INF/plugin-sonarlint.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
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 4b7a215..2bbe5b6 100644
--- a/src/main/resources/META-INF/plugin.xml
+++ b/src/main/resources/META-INF/plugin.xml
@@ -10,7 +10,7 @@
Git4Idea
org.jetbrains.idea.maven
com.intellij.modules.java
- org.sonarlint.idea
+ org.sonarlint.idea
diff --git a/src/main/resources/schema/sonarlint.schema.json b/src/main/resources/schema/sonarlint.schema.json
deleted file mode 100644
index 29b2eef..0000000
--- a/src/main/resources/schema/sonarlint.schema.json
+++ /dev/null
@@ -1,30 +0,0 @@
-{
- "$id": "https://www.gebit.de/autoconfig-intellij-plugin/git.schema.json",
- "$schema": "https://json-schema.org/draft/2020-12/schema",
- "title": "SonarLint configuration",
- "type": "object",
- "properties": {
- "bindings": {
- "type": "array",
- "description": "List of module/projectKey bindings",
- "items": {
- "type": "object",
- "description": "Module binding for project keys",
- "required": [
- "modulePattern",
- "projectKey"
- ],
- "properties": {
- "modulePattern": {
- "type": "string",
- "description": "Name pattern for module name matching"
- },
- "projectKey": {
- "type": "string",
- "description": "The SonarQube project key to use for all matching modules"
- }
- }
- }
- }
- }
-}
\ No newline at end of file
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