diff --git a/gradle.properties b/gradle.properties
index 8e2f3f6..970e3b9 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,5 +1,5 @@
# Autoconfig Plugin Properties
-pluginVersion = 1.0.0
+pluginVersion = 1.0.1
preRelease = false
hidden = false
pluginGroup = de.gebit.plugins.autoconfig
diff --git a/metadata/changelog.html b/metadata/changelog.html
index d5238f2..cb3bc55 100644
--- a/metadata/changelog.html
+++ b/metadata/changelog.html
@@ -5,10 +5,11 @@
Changelog
-1.0.0
+1.0.1
- initial public release
- allow disabling of async stack traces debugger agent
+ - allow setting project SDK
0.0.6
diff --git a/src/main/java/de/gebit/plugins/autoconfig/ConfigurationLoaderService.java b/src/main/java/de/gebit/plugins/autoconfig/ConfigurationLoaderService.java
index 57187e1..fbb1de4 100644
--- a/src/main/java/de/gebit/plugins/autoconfig/ConfigurationLoaderService.java
+++ b/src/main/java/de/gebit/plugins/autoconfig/ConfigurationLoaderService.java
@@ -78,7 +78,6 @@ public boolean hasAutoconfigDir() {
private Optional getConfigDirectory() {
var projectFile = project.getProjectFile();
- ProjectKt.getStateStore(project).getDirectoryStorePath();
if (projectFile == null) {
// Fallback to find autoconfig directory. May happen when project is first opened and no misc.xml can be found
Path directoryStorePath = ProjectKt.getStateStore(project).getDirectoryStorePath();
diff --git a/src/main/java/de/gebit/plugins/autoconfig/handlers/CommonConfigurationHandler.java b/src/main/java/de/gebit/plugins/autoconfig/handlers/CommonConfigurationHandler.java
index bb9957a..31222eb 100644
--- a/src/main/java/de/gebit/plugins/autoconfig/handlers/CommonConfigurationHandler.java
+++ b/src/main/java/de/gebit/plugins/autoconfig/handlers/CommonConfigurationHandler.java
@@ -13,14 +13,24 @@
import com.intellij.codeInsight.actions.onSave.OptimizeImportsOnSaveOptions;
import com.intellij.externalDependencies.ExternalDependenciesManager;
import com.intellij.externalDependencies.impl.ExternalDependenciesManagerImpl;
+import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.externalSystem.autoimport.ExternalSystemProjectTrackerSettings;
import com.intellij.openapi.project.Project;
+import com.intellij.openapi.projectRoots.SdkType;
+import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.updateSettings.impl.UpdateSettings;
import com.intellij.openapi.vcs.IssueNavigationConfiguration;
import com.intellij.openapi.vcs.IssueNavigationLink;
import de.gebit.plugins.autoconfig.UpdateHandler;
-import de.gebit.plugins.autoconfig.model.*;
+import de.gebit.plugins.autoconfig.model.Formatting;
+import de.gebit.plugins.autoconfig.model.GeneralConfiguration;
+import de.gebit.plugins.autoconfig.model.IssueNavigation;
+import de.gebit.plugins.autoconfig.model.OnSave;
+import de.gebit.plugins.autoconfig.model.ProjectSDK;
+import de.gebit.plugins.autoconfig.model.ReloadProjectAutomatically;
+import de.gebit.plugins.autoconfig.sdk.JDKResolver;
import de.gebit.plugins.autoconfig.state.TransientPluginStateService;
+import de.gebit.plugins.autoconfig.util.Notifications;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
@@ -29,7 +39,8 @@
import java.util.List;
/**
- * The main class used to update the IntelliJ configuration. All supported options are checked, updated and logged in a list of changed configs.
+ * The main class used to update the IntelliJ configuration. All supported options are checked, updated and logged in a
+ * list of changed configs.
*/
public class CommonConfigurationHandler extends AbstractHandler implements UpdateHandler {
private static final @NonNls String CONFIG_SCHEMA_JSON = "/schema/config.schema.json";
@@ -65,20 +76,24 @@ public List updateConfiguration(GeneralConfiguration options, Project pr
applyPluginHosts(options.getGlobalPluginRepositories(), project, updatedConfigs);
applyOnSaveOptions(options.getOnSave(), project, updatedConfigs);
applyReloadConfiguration(options.getReloadProjectAutomatically(), project, updatedConfigs);
+ applyProjectSDKOptions(options.getProjectSDK(), project, updatedConfigs);
return updatedConfigs;
}
private void applyReloadConfiguration(ReloadProjectAutomatically reloadProjectAutomatically, Project project, List updatedConfigs) {
if (reloadProjectAutomatically != null) {
- final ExternalSystemProjectTrackerSettings instance = ExternalSystemProjectTrackerSettings.getInstance(project);
+ final ExternalSystemProjectTrackerSettings instance = ExternalSystemProjectTrackerSettings.getInstance(
+ project);
if (Boolean.FALSE.equals(reloadProjectAutomatically.getEnabled())) {
- applySetting(ExternalSystemProjectTrackerSettings.AutoReloadType.NONE, instance.getAutoReloadType(), instance::setAutoReloadType, updatedConfigs, "Automatic project reload deactivated");
+ applySetting(ExternalSystemProjectTrackerSettings.AutoReloadType.NONE, instance.getAutoReloadType(),
+ instance::setAutoReloadType, updatedConfigs, "Automatic project reload deactivated");
instance.setAutoReloadType(ExternalSystemProjectTrackerSettings.AutoReloadType.NONE);
} else if (reloadProjectAutomatically.getMode() != null) {
applySetting(switch (reloadProjectAutomatically.getMode()) {
- case ANY_CHANGES -> ExternalSystemProjectTrackerSettings.AutoReloadType.ALL;
- case EXTERNAL_CHANGES -> ExternalSystemProjectTrackerSettings.AutoReloadType.SELECTIVE;
- }, instance.getAutoReloadType(), instance::setAutoReloadType, updatedConfigs, "Automatic project reload activated");
+ case ANY_CHANGES -> ExternalSystemProjectTrackerSettings.AutoReloadType.ALL;
+ case EXTERNAL_CHANGES -> ExternalSystemProjectTrackerSettings.AutoReloadType.SELECTIVE;
+ }, instance.getAutoReloadType(), instance::setAutoReloadType, updatedConfigs,
+ "Automatic project reload activated");
}
}
}
@@ -89,9 +104,11 @@ private void applyIssueNavigationConfiguration(List issueNaviga
var newSettingsList = new ArrayList();
for (IssueNavigation navigationConfig : issueNavigationConfig) {
- newSettingsList.add(new IssueNavigationLink(navigationConfig.getExpression(), navigationConfig.getUrl()));
+ newSettingsList.add(
+ new IssueNavigationLink(navigationConfig.getExpression(), navigationConfig.getUrl()));
}
- applySetting(newSettingsList, issueNavigationSettings.getLinks(), issueNavigationSettings::setLinks, updatedConfigs, "Issue navigation links");
+ applySetting(newSettingsList, issueNavigationSettings.getLinks(), issueNavigationSettings::setLinks,
+ updatedConfigs, "Issue navigation links");
}
}
@@ -100,15 +117,37 @@ private void applyOnSaveOptions(OnSave options, Project project, List up
// first, initialise the application state service used for code formatter options
Formatting optionsFormat = options.getFormat();
Formatting optionsOptimizeImports = options.getOptimizeImports();
- TransientPluginStateService.getInstance().initFormatterSettings(getFileTypes(optionsFormat), getFileTypes(optionsOptimizeImports));
+ TransientPluginStateService.getInstance()
+ .initFormatterSettings(getFileTypes(optionsFormat), getFileTypes(optionsOptimizeImports));
- setFormattingOptions(updatedConfigs, optionsFormat, "Code format on save", FormatOnSaveOptions.getInstance(project));
- setFormattingOptions(updatedConfigs, optionsOptimizeImports, "Optimize imports on save", OptimizeImportsOnSaveOptions.getInstance(project));
+ setFormattingOptions(updatedConfigs, optionsFormat, "Code format on save",
+ FormatOnSaveOptions.getInstance(project));
+ setFormattingOptions(updatedConfigs, optionsOptimizeImports, "Optimize imports on save",
+ OptimizeImportsOnSaveOptions.getInstance(project));
+ }
+ }
+
+ private void applyProjectSDKOptions(ProjectSDK sdkOptions, Project project, List updatedConfigs) {
+ if (sdkOptions != null) {
+ SdkType sdk = SdkType.findByName(sdkOptions.getType());
+ if (sdk != null) {
+ String projectSdk = JDKResolver.findProjectSdk(sdkOptions.getName(), project);
+ if (projectSdk != null) {
+ ProjectRootManager projectRootManager = ProjectRootManager.getInstance(project);
+ applySetting(projectSdk, projectRootManager.getProjectSdkName(), sdkName -> WriteAction.runAndWait(
+ () -> projectRootManager.setProjectSdkName(sdkName, sdkOptions.getType())), updatedConfigs,
+ "Project SDK");
+ }
+ } else {
+ Notifications.showWarning(
+ "SDK type \"" + sdkOptions.getType() + "\" has not been found for auto configuration", project);
+ }
}
}
private void setFormattingOptions(List updatedConfigs, Formatting optionsFormat, String description, FormatOnSaveOptionsBase> format) {
- applySetting(optionsFormat != null, format.isRunOnSaveEnabled(), format::setRunOnSaveEnabled, updatedConfigs, description);
+ applySetting(optionsFormat != null, format.isRunOnSaveEnabled(), format::setRunOnSaveEnabled, updatedConfigs,
+ description);
}
private List getFileTypes(@Nullable Formatting formattingOptions) {
diff --git a/src/main/java/de/gebit/plugins/autoconfig/handlers/maven/MavenHandler.java b/src/main/java/de/gebit/plugins/autoconfig/handlers/maven/MavenHandler.java
index 8833f77..d3224c6 100644
--- a/src/main/java/de/gebit/plugins/autoconfig/handlers/maven/MavenHandler.java
+++ b/src/main/java/de/gebit/plugins/autoconfig/handlers/maven/MavenHandler.java
@@ -10,12 +10,9 @@
import com.intellij.conversion.impl.ConversionContextImpl;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.projectRoots.ProjectJdkTable;
-import com.intellij.openapi.projectRoots.Sdk;
import de.gebit.plugins.autoconfig.UpdateHandler;
import de.gebit.plugins.autoconfig.handlers.AbstractHandler;
import de.gebit.plugins.autoconfig.model.MavenConfiguration;
-import de.gebit.plugins.autoconfig.sdk.JDKResolver;
import org.jetbrains.idea.maven.execution.MavenRunner;
import org.jetbrains.idea.maven.project.MavenProjectBundle;
import org.jetbrains.idea.maven.project.MavenProjectsManager;
@@ -24,6 +21,8 @@
import java.util.ArrayList;
import java.util.List;
+import static de.gebit.plugins.autoconfig.sdk.JDKResolver.findProjectSdk;
+
/**
* Maven configuration update handler.
*/
@@ -114,19 +113,4 @@ private String getMavenHome(Boolean useMavenWrapperConfig) {
}
}
}
-
- private String findProjectSdk(String sdkName, Project project) {
- if (sdkName == null) {
- return null;
- }
- for (Sdk jdk : ProjectJdkTable.getInstance().getAllJdks()) {
- if (jdk.getName().equals(sdkName)) {
- return jdk.getName();
- }
- }
-
- JDKResolver.resolveMissingJDK(sdkName, project);
-
- return sdkName;
- }
}
diff --git a/src/main/java/de/gebit/plugins/autoconfig/sdk/JDKResolver.java b/src/main/java/de/gebit/plugins/autoconfig/sdk/JDKResolver.java
index feaf792..5eb5b14 100644
--- a/src/main/java/de/gebit/plugins/autoconfig/sdk/JDKResolver.java
+++ b/src/main/java/de/gebit/plugins/autoconfig/sdk/JDKResolver.java
@@ -10,8 +10,13 @@
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.JavaSdk;
import com.intellij.openapi.projectRoots.ProjectJdkTable;
+import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.SdkType;
-import com.intellij.openapi.projectRoots.impl.*;
+import com.intellij.openapi.projectRoots.impl.UnknownSdkCollector;
+import com.intellij.openapi.projectRoots.impl.UnknownSdkFix;
+import com.intellij.openapi.projectRoots.impl.UnknownSdkFixAction;
+import com.intellij.openapi.projectRoots.impl.UnknownSdkSnapshot;
+import com.intellij.openapi.projectRoots.impl.UnknownSdkTracker;
import com.intellij.openapi.roots.ui.configuration.UnknownSdk;
import com.intellij.openapi.ui.MessageType;
import de.gebit.plugins.autoconfig.util.Notifications;
@@ -30,6 +35,21 @@ private JDKResolver() {
// nothing
}
+ public static String findProjectSdk(String sdkName, Project project) {
+ if (sdkName == null) {
+ return null;
+ }
+ for (Sdk jdk : ProjectJdkTable.getInstance().getAllJdks()) {
+ if (jdk.getName().equals(sdkName)) {
+ return jdk.getName();
+ }
+ }
+
+ resolveMissingJDK(sdkName, project);
+
+ return sdkName;
+ }
+
/**
* Ensures, that the currently missing JDK is made available for the project. If the JDK is not found on the system
* it tries to assist the user in applying the IDEs suggestions.
diff --git a/src/main/java/de/gebit/plugins/autoconfig/util/Notifications.java b/src/main/java/de/gebit/plugins/autoconfig/util/Notifications.java
index 24b2831..f2c2bd4 100644
--- a/src/main/java/de/gebit/plugins/autoconfig/util/Notifications.java
+++ b/src/main/java/de/gebit/plugins/autoconfig/util/Notifications.java
@@ -33,6 +33,10 @@ public static void showInfo(String text, Project project) {
getNotifier().createNotification(text, MessageType.INFO).notify(project);
}
+ public static void showWarning(String text, Project project) {
+ getNotifier().createNotification(text, MessageType.WARNING).notify(project);
+ }
+
public static void showError(String text, Project project) {
getNotifier().createNotification(text, MessageType.ERROR).notify(project);
}
diff --git a/src/main/resources/schema/config.schema.json b/src/main/resources/schema/config.schema.json
index 2e097c4..02d332c 100644
--- a/src/main/resources/schema/config.schema.json
+++ b/src/main/resources/schema/config.schema.json
@@ -93,6 +93,24 @@
}
}
}
+ },
+ "projectSDK": {
+ "type": "object",
+ "description": "The project SDK settings.",
+ "required": [
+ "name",
+ "type"
+ ],
+ "properties": {
+ "name": {
+ "type": "string",
+ "description": "The SDK name, e.g. a version or a distributor"
+ },
+ "type": {
+ "type": "string",
+ "description": "The SDK type, e.g. \"JavaSDK\", \"IDEA JDK\", \"KotlinSDK\" or \"Android SDK\"."
+ }
+ }
}
}
}