Skip to content

Commit

Permalink
Allow setting of module SDK (introducing module settings) (#19)
Browse files Browse the repository at this point in the history
Allow setting of module SDK (introducing module settings)
  • Loading branch information
swesteme authored Dec 20, 2024
1 parent f7d4ee6 commit 97b6deb
Show file tree
Hide file tree
Showing 26 changed files with 880 additions and 287 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions metadata/changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<title>Changelog</title>
</head>
<body>
<h2>1.0.3</h2>
<ul>
<li>support setting of module SDK</li>
</ul>
<h2>1.0.2</h2>
<ul>
<li>support intellij 2024.3</li>
Expand Down
58 changes: 5 additions & 53 deletions src/main/java/de/gebit/plugins/autoconfig/AutoconfigStartup.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,72 +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.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.
* 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<UpdateHandler<?>>
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<String> 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<String> 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 <T> List<String> processUpdateHandler(@NotNull Project project, UpdateHandler<T> updateHandler, ConfigurationLoaderService projectService) {
Optional<T> extensionConfiguration = projectService.getConfiguration(updateHandler.getConfigurationClass(), updateHandler.getFileName());
if (extensionConfiguration.isPresent()) {
return updateHandler.updateConfiguration(extensionConfiguration.get(), project);
} else {
LOG.info("No configuration for " + updateHandler.getUpdaterName() + " found.");
return Collections.emptyList();
}
return project.getService(ConfigurationUpdaterService.class).runAutoconfig();
}
}

This file was deleted.

39 changes: 8 additions & 31 deletions src/main/java/de/gebit/plugins/autoconfig/UpdateHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,20 @@
/**
* Extension point for used to supply configuration update handlers.
*/
public interface UpdateHandler<T> {
public interface UpdateHandler<T> extends de.gebit.plugins.autoconfig.UpdateSettings<T> {

/**
* Provide the file name that is expected to contain the extensions' configuration.
*
* @return the file name that is expected to contain the extensions' configuration
*/
String getFileName();

/**
* The json schema containing/providing the information on how to write the configuration file.
*
* @return json schema containing/providing the information on how to write the configuration file
*/
String getJsonSchema();

/**
* The updater name is used for logging purposes and as a name for the json schema displayed in IntelliJ status bar.
*
* @return the name of this updater
*/
String getUpdaterName();

/**
* The configuration object class used to read/deserialize the configuration file.
*
* @return configuration object class used to read/deserialize the configuration file
*/
Class<T> getConfigurationClass();

/**
* The implementation of the configuration updates. A configuration update object is supplied containing the information gathered from the yaml
* file.
* The implementation of the configuration updates. A configuration update object is supplied containing the
* information gathered from the yaml file.
*
* @param configuration the configuration object used for this update handler
* @param project the project that will receive the configuration updates in case they can be applied
* @return list of configuration parts that have been updated
*/
List<String> updateConfiguration(T configuration, Project project);

@Override
default UpdateTarget getUpdateTarget() {
return UpdateTarget.PROJECT;
}
}
39 changes: 39 additions & 0 deletions src/main/java/de/gebit/plugins/autoconfig/UpdateModuleHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package de.gebit.plugins.autoconfig;


import com.intellij.openapi.module.Module;

import java.util.List;

/**
* Extension point for used to supply module configuration update handlers.
*/
public interface UpdateModuleHandler<T> extends UpdateSettings<T> {

/**
* Implementing handlers should carefully select the modules in which to apply any settings changes.
*
* @param configuration the configuration object used for this update handler
* @param module module to accept or deny
* @return whether the given module should be accepted for this module handler, default is {@code false} (no changes
* will be applied)
*/
default boolean acceptModule(T configuration, Module module) {
return false;
}

/**
* The implementation of the configuration updates. A configuration update object is supplied containing the
* information gathered from the yaml file.
*
* @param configuration the configuration object used for this update handler
* @param module the module that will receive the configuration updates in case they can be applied
* @return list of configuration parts that have been updated
*/
List<String> updateConfiguration(T configuration, Module module);

@Override
default UpdateTarget getUpdateTarget() {
return UpdateTarget.MODULE;
}
}
43 changes: 43 additions & 0 deletions src/main/java/de/gebit/plugins/autoconfig/UpdateSettings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package de.gebit.plugins.autoconfig;


/**
* Common interface for update handlers. Meta information about the handler is returned from the given methods.
*/
public interface UpdateSettings<T> {
/**
* Provide the file name that is expected to contain the extensions' configuration.
*
* @return the file name that is expected to contain the extensions' configuration
*/
String getFileName();

/**
* The json schema containing/providing the information on how to write the configuration file.
*
* @return json schema containing/providing the information on how to write the configuration file
*/
String getJsonSchema();

/**
* The updater name is used for logging purposes and as a name for the json schema displayed in IntelliJ status
* bar.
*
* @return the name of this updater
*/
String getUpdaterName();

/**
* The configuration object class used to read/deserialize the configuration file.
*
* @return configuration object class used to read/deserialize the configuration file
*/
Class<T> getConfigurationClass();

/**
* Specifies, whether modules or projects are target for this handler object.
*
* @return whether modules or projects are target for this handler object
*/
UpdateTarget getUpdateTarget();
}
9 changes: 9 additions & 0 deletions src/main/java/de/gebit/plugins/autoconfig/UpdateTarget.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package de.gebit.plugins.autoconfig;


/**
* Specifies, whether projects or modules are target of configuration updates.
*/
public enum UpdateTarget {
PROJECT, MODULE
}
Loading

0 comments on commit 97b6deb

Please sign in to comment.