Skip to content

Commit 5076509

Browse files
authored
feat: Enable using the Maven Wrapper (mvnw) (#198)
Signed-off-by: Chao Wang <[email protected]>
1 parent ca87829 commit 5076509

File tree

8 files changed

+87
-2
lines changed

8 files changed

+87
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ according to your preferences.
8585
<br >If the paths are not provided, your IDE's `PATH` and `JAVA_HONE` environments will be used to locate the
8686
executables.
8787

88+
- **Maven Wrappers** :
89+
<br >`preferWrapper`: Configure whether to use Maven wrapper. There are three options available:
90+
<br >`true`: Always use the wrapper regardless of `Build,Execution,Deployment › Build Tools > Maven: Maven home path` setting
91+
<br >`false`: Never use the wrapper regardless of `Build,Execution,Deployment › Build Tools > Maven: Maven home path` setting
92+
<br >`fallback`: Use IntelliJ's `Build,Execution,Deployment › Build Tools > Maven: Maven home path` setting (default behavior)
93+
8894
- **Node** :
8995
<br >Set the full path of the Node executable, which allows Exhort to locate and run one of the corresponding `npm`, `pnpm` or `yarn` command to resolve
9096
dependencies for Node projects.

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ideaVersion=2025.1
99
gradleVersion=8.5
1010

1111
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
12-
platformBundledPlugins=org.jetbrains.plugins.yaml,com.intellij.java
12+
platformBundledPlugins=org.jetbrains.plugins.yaml,com.intellij.java,org.jetbrains.idea.maven
1313
platformPlugins=com.redhat.devtools.intellij.telemetry:1.1.0.52,org.jetbrains.plugins.go:251.23774.200,Docker:251.23774.37
1414

1515
# Opt-out flag for bundling Kotlin standard library -> https://jb.gg/intellij-platform-kotlin-stdlib

src/main/java/org/jboss/tools/intellij/exhort/ApiService.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.redhat.exhort.api.v4.AnalysisReport;
2424
import com.redhat.exhort.impl.ExhortApi;
2525
import org.jboss.tools.intellij.settings.ApiSettingsState;
26+
import org.jboss.tools.intellij.settings.MavenSettingsUtil;
2627

2728
import java.io.IOException;
2829
import java.nio.file.Files;
@@ -133,7 +134,20 @@ private void setRequestProperties(final String manifestName) {
133134
} else {
134135
System.clearProperty("EXHORT_MVN_PATH");
135136
}
136-
if (settings.gradlePath != null && !settings.gradlePath.isBlank()) {
137+
138+
if (settings.useMavenWrapper.equals("fallback")) {
139+
if (MavenSettingsUtil.isMavenWrapperSelected()) {
140+
System.setProperty("EXHORT_PREFER_MVNW", settings.useMavenWrapper);
141+
} else {
142+
System.clearProperty("EXHORT_PREFER_MVNW");
143+
}
144+
} else if (settings.useMavenWrapper.equals("true")) {
145+
System.setProperty("EXHORT_PREFER_MVNW", settings.useMavenWrapper);
146+
} else {
147+
System.clearProperty("EXHORT_PREFER_MVNW");
148+
}
149+
150+
if (settings.gradlePath != null && !settings.gradlePath.isBlank()) {
137151
System.setProperty("EXHORT_GRADLE_PATH", settings.gradlePath);
138152
} else {
139153
System.clearProperty("EXHORT_GRADLE_PATH");

src/main/java/org/jboss/tools/intellij/settings/ApiSettingsComponent.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
package org.jboss.tools.intellij.settings;
1313

1414
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
15+
import com.intellij.openapi.ui.ComboBox;
1516
import com.intellij.openapi.ui.TextComponentAccessor;
1617
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
1718
import com.intellij.ui.components.JBCheckBox;
@@ -27,6 +28,10 @@ public class ApiSettingsComponent {
2728

2829
private final static String mvnPathLabel = "<html>Maven > Executable: <b>Path</b>"
2930
+ "<br>Specifies absolute path of <b>mvn</b> executable.</html>";
31+
private final static String useMavenWrapperLabel = "<html>Maven: <b>Prefer Wrapper</b>"
32+
+ "<br>Specifies whether to use the local maven wrapper."
33+
+ "<br>The 'fallback' option will default to Build,Execution,Deployment › Build Tools > Maven: Maven home path setting"
34+
+ "<br>Else defaulting to 'true'.</html>";
3035
private final static String javaPathLabel = "<html>Maven > JAVA_HOME: <b>Path</b>"
3136
+ "<br>Specifies absolute path of Java installation directory.</html>";
3237
private final static String npmPathLabel = "<html>Npm > Executable: <b>Path</b>"
@@ -73,6 +78,7 @@ public class ApiSettingsComponent {
7378
private final JPanel mainPanel;
7479

7580
private final TextFieldWithBrowseButton mvnPathText;
81+
private final ComboBox useMavenWrapperCombo;
7682
private final TextFieldWithBrowseButton javaPathText;
7783
private final TextFieldWithBrowseButton npmPathText;
7884
private final TextFieldWithBrowseButton pnpmPathText;
@@ -108,6 +114,10 @@ public ApiSettingsComponent() {
108114
TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT
109115
);
110116

117+
useMavenWrapperCombo = new ComboBox<>(new String[]{"fallback", "true", "false"});
118+
useMavenWrapperCombo.setEditable(false);
119+
useMavenWrapperCombo.setSelectedIndex(0);
120+
111121
javaPathText = new TextFieldWithBrowseButton();
112122
javaPathText.addBrowseFolderListener(
113123
null,
@@ -257,6 +267,8 @@ public ApiSettingsComponent() {
257267
mainPanel = FormBuilder.createFormBuilder()
258268
.addLabeledComponent(new JBLabel(mvnPathLabel), mvnPathText, 1, true)
259269
.addVerticalGap(10)
270+
.addLabeledComponent(new JBLabel(useMavenWrapperLabel), useMavenWrapperCombo, 1, true)
271+
.addVerticalGap(10)
260272
.addLabeledComponent(new JBLabel(javaPathLabel), javaPathText, 1, true)
261273
.addSeparator(10)
262274
.addVerticalGap(10)
@@ -324,6 +336,14 @@ public void setMvnPathText(@NotNull String text) {
324336
mvnPathText.setText(text);
325337
}
326338

339+
public String getUseMavenWrapperCombo() {
340+
return useMavenWrapperCombo.getSelectedItem().toString();
341+
}
342+
343+
public void setUseMavenWrapperCombo(@NotNull String text) {
344+
useMavenWrapperCombo.setSelectedItem(text);
345+
}
346+
327347
@NotNull
328348
public String getJavaPathText() {
329349
return javaPathText.getText();

src/main/java/org/jboss/tools/intellij/settings/ApiSettingsConfigurable.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public JComponent getPreferredFocusedComponent() {
4040
public boolean isModified() {
4141
ApiSettingsState settings = ApiSettingsState.getInstance();
4242
boolean modified = !settingsComponent.getMvnPathText().equals(settings.mvnPath);
43+
modified |= settingsComponent.getUseMavenWrapperCombo() != settings.useMavenWrapper;
4344
modified |= !settingsComponent.getJavaPathText().equals(settings.javaPath);
4445
modified |= !settingsComponent.getNpmPathText().equals(settings.npmPath);
4546
modified |= !settingsComponent.getPnpmPathText().equals(settings.pnpmPath);
@@ -68,6 +69,7 @@ public boolean isModified() {
6869
public void apply() {
6970
ApiSettingsState settings = ApiSettingsState.getInstance();
7071
settings.mvnPath = settingsComponent.getMvnPathText();
72+
settings.useMavenWrapper = settingsComponent.getUseMavenWrapperCombo();
7173
settings.javaPath = settingsComponent.getJavaPathText();
7274
settings.npmPath = settingsComponent.getNpmPathText();
7375
settings.pnpmPath = settingsComponent.getPnpmPathText();
@@ -95,6 +97,7 @@ public void apply() {
9597
public void reset() {
9698
ApiSettingsState settings = ApiSettingsState.getInstance();
9799
settingsComponent.setMvnPathText(settings.mvnPath != null ? settings.mvnPath : "");
100+
settingsComponent.setUseMavenWrapperCombo(settings.useMavenWrapper);
98101
settingsComponent.setJavaPathText(settings.javaPath != null ? settings.javaPath : "");
99102
settingsComponent.setNpmPathText(settings.npmPath != null ? settings.npmPath : "");
100103
settingsComponent.setPnpmPathText(settings.pnpmPath != null ? settings.pnpmPath : "");

src/main/java/org/jboss/tools/intellij/settings/ApiSettingsState.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public final class ApiSettingsState implements PersistentStateComponent<ApiSetti
3636
public String rhdaToken;
3737

3838
public String mvnPath;
39+
public String useMavenWrapper = "fallback";
3940
public String javaPath;
4041

4142
public String npmPath;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.jboss.tools.intellij.settings;
2+
3+
import com.intellij.openapi.project.Project;
4+
import com.intellij.openapi.project.ProjectManager;
5+
import org.jetbrains.annotations.Nullable;
6+
import org.jetbrains.idea.maven.project.MavenGeneralSettings;
7+
import org.jetbrains.idea.maven.project.MavenHomeType;
8+
import org.jetbrains.idea.maven.project.MavenWorkspaceSettingsComponent;
9+
import org.jetbrains.idea.maven.project.MavenWrapper;
10+
11+
public final class MavenSettingsUtil {
12+
13+
private MavenSettingsUtil() {
14+
// no‑op
15+
}
16+
17+
@Nullable
18+
public static boolean isMavenWrapperSelected() {
19+
Project project;
20+
Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
21+
if (openProjects.length > 0) {
22+
project = openProjects[0];
23+
} else {
24+
project = ProjectManager.getInstance().getDefaultProject();
25+
}
26+
MavenGeneralSettings settings = MavenWorkspaceSettingsComponent.getInstance(project).getSettings().getGeneralSettings();
27+
MavenHomeType mavenHomeType = settings.getMavenHomeType();
28+
return mavenHomeType instanceof MavenWrapper;
29+
}
30+
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@
9797
<br>If the paths are not provided, your IDE's <code>PATH</code> and <code>JAVA_HONE</code> environments will be
9898
used to locate the executables.
9999
</li>
100+
101+
<li>
102+
<b>Maven Wrapper</b>:
103+
<br><code>preferWrapper</code> : Configure whether to use Maven wrapper. There are three options available
104+
<br><code>true</code>: Always use the wrapper regardless of Build,Execution,Deployment › Build Tools > Maven: Maven home path setting
105+
<br><code>false</code>: Never use the wrapper regardless of Build,Execution,Deployment › Build Tools > Maven: Maven home path setting
106+
<br><code>fallback</code>: Use IntelliJ's Build,Execution,Deployment › Build Tools > Maven: Maven home path setting (default behavior)
107+
</li>
108+
100109
<li>
101110
<b>Node</b>:
102111
<br>Set the full path of the Node executable, which allows Exhort to locate and execute one of the corresponding <code>npm</code>, <code>pnpm</code> or <code>yarn</code> command
@@ -421,6 +430,8 @@
421430
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
422431
on how to target different products -->
423432
<depends>com.intellij.modules.lang</depends>
433+
<depends>com.intellij.java</depends>
434+
<depends>org.jetbrains.idea.maven</depends>
424435
<depends>com.redhat.devtools.intellij.telemetry</depends>
425436
<depends>Docker</depends>
426437
<depends config-file="go.xml" optional="true">org.jetbrains.plugins.go</depends>

0 commit comments

Comments
 (0)