Skip to content

Commit 1c91c62

Browse files
committed
fix: update plugin dependency checks, fixes #402
1 parent b78d12e commit 1c91c62

7 files changed

+101
-23
lines changed

src/main/java/de/php_perfect/intellij/ddev/node/AutoConfigureNodeInterpreterListener.java

+11
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@
66
import de.php_perfect.intellij.ddev.cmd.Description;
77
import de.php_perfect.intellij.ddev.dockerCompose.DdevComposeFileLoader;
88
import de.php_perfect.intellij.ddev.settings.DdevSettingsState;
9+
import de.php_perfect.intellij.ddev.util.PluginChecker;
910
import org.jetbrains.annotations.NotNull;
1011
import org.jetbrains.annotations.Nullable;
1112

13+
import java.util.List;
14+
1215
public final class AutoConfigureNodeInterpreterListener implements DescriptionChangedListener {
16+
private static final List<String> REQUIRED_PLUGINS = List.of(
17+
"NodeJS",
18+
"org.jetbrains.plugins.node-remote-interpreter"
19+
);
1320

1421
private final @NotNull Project project;
1522

@@ -27,6 +34,10 @@ public void onDescriptionChanged(@Nullable Description description) {
2734
return;
2835
}
2936

37+
if (PluginChecker.isMissingRequiredPlugins(this.project, REQUIRED_PLUGINS)) {
38+
return;
39+
}
40+
3041
final VirtualFile composeFile = DdevComposeFileLoader.getInstance(this.project).load();
3142

3243
if (composeFile == null || !composeFile.exists()) {

src/main/java/de/php_perfect/intellij/ddev/node/NodeInterpreterProviderImpl.java

+36-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import de.php_perfect.intellij.ddev.dockerCompose.DockerComposeCredentialProvider;
1616
import org.jetbrains.annotations.NotNull;
1717

18+
import java.util.Collection;
1819
import java.util.List;
1920

2021
public final class NodeInterpreterProviderImpl implements NodeInterpreterProvider {
@@ -28,9 +29,27 @@ public NodeInterpreterProviderImpl(final @NotNull Project project) {
2829

2930
public void configureNodeInterpreter(final @NotNull NodeInterpreterConfig nodeInterpreterConfig) {
3031
final NodeRemoteInterpreters nodeRemoteInterpreters = NodeRemoteInterpreters.getInstance();
32+
final Collection<NodeJSRemoteSdkAdditionalData> interpreters = nodeRemoteInterpreters.getInterpreters();
3133

32-
if (!nodeRemoteInterpreters.getInterpreters().isEmpty()) {
33-
return;
34+
// Normalize the target compose file path for comparison
35+
String normalizedTargetPath = normalizePath(nodeInterpreterConfig.composeFilePath());
36+
37+
// Check if we already have the remote interpreter set up
38+
if (!interpreters.isEmpty()) {
39+
for (NodeJSRemoteSdkAdditionalData interpreter : interpreters) {
40+
Object credentialsObj = interpreter.connectionCredentials().getCredentials();
41+
// Check if the credentials are of the expected type
42+
if (credentialsObj instanceof DockerComposeCredentialsHolder credentials && credentials.getComposeFilePaths() != null) {
43+
for (String composeFilePath : credentials.getComposeFilePaths()) {
44+
// Normalize the existing compose file path for comparison
45+
String normalizedExistingPath = normalizePath(composeFilePath);
46+
if (normalizedExistingPath.contains(normalizedTargetPath)) {
47+
LOG.debug("Found existing nodejs interpreter");
48+
return;
49+
}
50+
}
51+
}
52+
}
3453
}
3554

3655
LOG.debug("Creating nodejs interpreter");
@@ -60,4 +79,19 @@ private PathMappingSettings loadPathMappings(NodeJSRemoteSdkAdditionalData sdkDa
6079
return null;
6180
}
6281
}
82+
83+
/**
84+
* Normalizes a file path by replacing backslashes with forward slashes
85+
* and ensuring consistent path separators for comparison.
86+
*
87+
* @param path The path to normalize
88+
* @return The normalized path
89+
*/
90+
private String normalizePath(String path) {
91+
if (path == null) {
92+
return "";
93+
}
94+
// Replace backslashes with forward slashes for consistent comparison
95+
return path.replace('\\', '/');
96+
}
6397
}

src/main/java/de/php_perfect/intellij/ddev/php/ConfigurationProviderImpl.java

+7-16
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
package de.php_perfect.intellij.ddev.php;
22

3-
import com.intellij.ide.plugins.PluginManager;
4-
import com.intellij.openapi.extensions.PluginId;
53
import com.intellij.openapi.project.Project;
64
import com.intellij.openapi.vfs.VirtualFile;
75
import de.php_perfect.intellij.ddev.cmd.Description;
86
import de.php_perfect.intellij.ddev.dockerCompose.DdevComposeFileLoader;
9-
import de.php_perfect.intellij.ddev.notification.DdevNotifier;
107
import de.php_perfect.intellij.ddev.settings.DdevSettingsState;
8+
import de.php_perfect.intellij.ddev.util.PluginChecker;
119
import org.jetbrains.annotations.NotNull;
1210

1311
import java.util.List;
1412

1513
public final class ConfigurationProviderImpl implements ConfigurationProvider {
1614
private static final List<String> REQUIRED_PLUGINS = List.of(
15+
"com.jetbrains.php",
1716
"org.jetbrains.plugins.phpstorm-remote-interpreter",
18-
"org.jetbrains.plugins.phpstorm-docker",
19-
"Docker"
17+
"org.jetbrains.plugins.phpstorm-docker"
2018
);
2119

2220
private final @NotNull Project project;
@@ -35,21 +33,14 @@ public void configure(@NotNull Description description) {
3533
return;
3634
}
3735

38-
final VirtualFile composeFile = DdevComposeFileLoader.getInstance(this.project).load();
39-
40-
if (composeFile == null || !composeFile.exists()) {
36+
if (PluginChecker.isMissingRequiredPlugins(this.project, REQUIRED_PLUGINS)) {
4137
return;
4238
}
4339

44-
final var pluginManager = PluginManager.getInstance();
45-
46-
for (final String id : REQUIRED_PLUGINS) {
47-
final PluginId pluginId = PluginId.findId(id);
40+
final VirtualFile composeFile = DdevComposeFileLoader.getInstance(this.project).load();
4841

49-
if (pluginId == null || pluginManager.findEnabledPlugin(pluginId) == null) {
50-
DdevNotifier.getInstance(this.project).notifyMissingPlugin(id);
51-
return;
52-
}
42+
if (composeFile == null || !composeFile.exists()) {
43+
return;
5344
}
5445

5546
final DdevInterpreterConfig ddevInterpreterConfig = new DdevInterpreterConfig(description.getName(), "php" + description.getPhpVersion(), composeFile.getPath());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package de.php_perfect.intellij.ddev.util;
2+
3+
import com.intellij.ide.plugins.PluginManager;
4+
import com.intellij.openapi.extensions.PluginId;
5+
import com.intellij.openapi.project.Project;
6+
import de.php_perfect.intellij.ddev.notification.DdevNotifier;
7+
import org.jetbrains.annotations.NotNull;
8+
9+
import java.util.List;
10+
11+
/**
12+
* Utility class to check for required plugins.
13+
*/
14+
public final class PluginChecker {
15+
private PluginChecker() {
16+
// Utility class, no instances
17+
}
18+
19+
/**
20+
* Checks if any required plugin is missing.
21+
* If any plugin is missing, it will notify the user and return true.
22+
*
23+
* @param project The current project
24+
* @param requiredPlugins List of plugin IDs to check
25+
* @return true if any plugin is missing, false if all are available
26+
*/
27+
public static boolean isMissingRequiredPlugins(@NotNull Project project, @NotNull List<String> requiredPlugins) {
28+
final var pluginManager = PluginManager.getInstance();
29+
30+
for (final String id : requiredPlugins) {
31+
final PluginId pluginId = PluginId.findId(id);
32+
33+
if (pluginId == null || pluginManager.findEnabledPlugin(pluginId) == null) {
34+
DdevNotifier.getInstance(project).notifyMissingPlugin(id);
35+
return true;
36+
}
37+
}
38+
39+
return false;
40+
}
41+
}

src/main/resources/META-INF/DdevIntegration-withDocker.xml

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
<idea-plugin>
2-
<depends>Docker</depends>
3-
42
<extensions defaultExtensionNs="com.intellij">
53
<applicationService
64
serviceImplementation="de.php_perfect.intellij.ddev.dockerCompose.DockerComposeCredentialProviderImpl"

src/main/resources/META-INF/DdevIntegration-withNodeRemoteInterpreter.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<idea-plugin>
22
<depends>NodeJS</depends>
3-
<depends>org.jetbrains.plugins.phpstorm-docker</depends>
3+
<depends>org.jetbrains.plugins.node-remote-interpreter</depends>
44

55
<extensions defaultExtensionNs="com.intellij">
66
<projectService serviceImplementation="de.php_perfect.intellij.ddev.node.NodeInterpreterProviderImpl"

src/main/resources/META-INF/plugin.xml

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@
2222

2323
<idea-version since-build="232.8660.185" until-build="241.*"/>
2424
<depends>com.intellij.modules.platform</depends>
25+
<!-- Required dependencies -->
26+
<depends>intellij.platform.ijent.impl</depends> <!-- Remote Execution Agent -->
27+
<depends config-file="DdevIntegration-withDocker.xml">Docker</depends>
28+
29+
<!-- Optional dependencies -->
2530
<depends config-file="DdevIntegration-withTerminal.xml" optional="true">org.jetbrains.plugins.terminal</depends>
2631
<depends config-file="DdevIntegration-withDatabase.xml" optional="true">com.intellij.database</depends>
27-
<depends config-file="DdevIntegration-withDocker.xml" optional="true">org.jetbrains.plugins.phpstorm-docker
28-
</depends>
2932
<depends config-file="DdevIntegration-withPhp.xml" optional="true">
3033
org.jetbrains.plugins.phpstorm-remote-interpreter
3134
</depends>

0 commit comments

Comments
 (0)