Skip to content

Commit 04b2606

Browse files
authored
fix: fix listQuarkusDependencies build task error popup (#1450)
* fix: fix listQuarkusDependencies build task error popup Signed-off-by: Stephane Bouchet <sbouchet@redhat.com> * fix: refactor MavenEmbeddedWrapper creation Signed-off-by: Stephane Bouchet <sbouchet@redhat.com> * fix: bump gradle version to 8.7 to avoid windows build errors Signed-off-by: Stephane Bouchet <sbouchet@redhat.com> * fix: bump gradle version to 8.7 to avoid windows build errors Signed-off-by: Stephane Bouchet <sbouchet@redhat.com> --------- Signed-off-by: Stephane Bouchet <sbouchet@redhat.com>
1 parent 908b2a7 commit 04b2606

File tree

10 files changed

+74
-57
lines changed

10 files changed

+74
-57
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ platformVersion=2023.3
1616
platformBundledPlugins=com.intellij.java, org.jetbrains.idea.maven, org.jetbrains.plugins.gradle, com.intellij.properties, org.jetbrains.plugins.yaml
1717
platformPlugins=com.redhat.devtools.intellij.telemetry:1.2.1.62
1818
# Gradle Releases -> https://github.com/gradle/gradle/releases
19-
gradleVersion=8.6
19+
gradleVersion=8.7
2020
channel=nightly
2121
quarkusVersion=3.15.1
2222
lsp4mpVersion=0.13.0

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew.bat

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
4343
%JAVA_EXE% -version >NUL 2>&1
4444
if %ERRORLEVEL% equ 0 goto execute
4545

46-
echo.
47-
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
48-
echo.
49-
echo Please set the JAVA_HOME variable in your environment to match the
50-
echo location of your Java installation.
46+
echo. 1>&2
47+
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
48+
echo. 1>&2
49+
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
50+
echo location of your Java installation. 1>&2
5151

5252
goto fail
5353

@@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
5757

5858
if exist "%JAVA_EXE%" goto execute
5959

60-
echo.
61-
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
62-
echo.
63-
echo Please set the JAVA_HOME variable in your environment to match the
64-
echo location of your Java installation.
60+
echo. 1>&2
61+
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
62+
echo. 1>&2
63+
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
64+
echo location of your Java installation. 1>&2
6565

6666
goto fail
6767

src/main/java/com/redhat/devtools/intellij/quarkus/QuarkusDeploymentSupport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public CompletableFuture<Void> updateClasspathWithQuarkusDeploymentAsync(Module
9090
* @param module the module.
9191
* @param progressIndicator the progress indicator.
9292
*/
93-
public static void updateClasspathWithQuarkusDeployment(Module module, ProgressIndicator progressIndicator) {
93+
public void updateClasspathWithQuarkusDeployment(Module module, ProgressIndicator progressIndicator) {
9494
if (module.isDisposed())
9595
return;
9696
LOGGER.info("Ensuring library to " + module.getName());
@@ -141,7 +141,7 @@ private static boolean isOutOfDated(CompletableFuture<Void> loader) {
141141
}
142142

143143
@NotNull
144-
private synchronized static CompletableFuture<Void> internalUpdateClasspathWithQuarkusDeployment(Module module) {
144+
private synchronized CompletableFuture<Void> internalUpdateClasspathWithQuarkusDeployment(Module module) {
145145
CompletableFuture<Void> deploymentSupport = module.getUserData(QUARKUS_DEPLOYMENT_SUPPORT_KEY);
146146
if (!isOutOfDated(deploymentSupport)) {
147147
return deploymentSupport;

src/main/java/com/redhat/devtools/intellij/quarkus/buildtool/gradle/AbstractGradleToolDelegate.java

Lines changed: 53 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
import com.intellij.ide.util.newProjectWizard.AddModuleWizard;
1919
import com.intellij.openapi.application.ReadAction;
2020
import com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings;
21+
import com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode;
2122
import com.intellij.openapi.externalSystem.service.project.ProjectDataManager;
2223
import com.intellij.openapi.externalSystem.service.project.manage.ProjectDataImportListener;
24+
import com.intellij.openapi.externalSystem.task.TaskCallback;
2325
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
2426
import com.intellij.openapi.externalSystem.util.ExternalSystemUtil;
2527
import com.intellij.openapi.module.ModifiableModuleModel;
@@ -116,14 +118,34 @@ private void processDownload(Module module, Set<String> deploymentIds, List<Virt
116118
Path outputPath = Files.createTempFile(null, ".txt");
117119
Path customBuildFile = generateCustomGradleBuild(getModuleDirPath(module), outputPath, deploymentIds);
118120
Path customSettingsFile = generateCustomGradleSettings(getModuleDirPath(module), customBuildFile);
121+
TaskCallback callback = new TaskCallback() {
122+
@Override
123+
public void onSuccess() {
124+
cleanCustomFiles();
125+
}
126+
127+
@Override
128+
public void onFailure() {
129+
LOGGER.error("Failed to run custom gradle build");
130+
cleanCustomFiles();
131+
}
132+
133+
private void cleanCustomFiles() {
134+
try {
135+
Files.delete(customBuildFile);
136+
Files.delete(customSettingsFile);
137+
} catch (IOException e) {
138+
LOGGER.warn(e.getLocalizedMessage(), e);
139+
}
140+
}
141+
142+
};
119143
try {
120-
collectDependencies(module, customBuildFile, customSettingsFile, outputPath, result);
144+
collectDependencies(module, customSettingsFile, outputPath, result, callback);
121145
} catch (IOException e) {
122146
LOGGER.warn(e.getLocalizedMessage(), e);
123147
} finally {
124148
Files.delete(outputPath);
125-
Files.delete(customBuildFile);
126-
Files.delete(customSettingsFile);
127149
}
128150
}
129151

@@ -149,37 +171,32 @@ private String getModuleDirPath(Module module) {
149171
/**
150172
* Collect all deployment JARs and dependencies through a Gradle specific task.
151173
*
152-
* @param module the module to analyze
153-
* @param customBuildFile the custom Gradle build file with the specific task
154-
* @param outputPath the file where the result of the specific task is stored
155-
* @param result the list where to place results to
174+
* @param module the module to analyze
175+
* @param outputPath the file where the result of the specific task is stored
176+
* @param result the list where to place results to
177+
* @param callback the callback to call after running the task
156178
* @throws IOException if an error occurs running Gradle
157179
*/
158-
private void collectDependencies(Module module, Path customBuildFile, Path customSettingsFile, Path outputPath, List<VirtualFile>[] result) throws IOException {
180+
private void collectDependencies(Module module, Path customSettingsFile, Path outputPath, List<VirtualFile>[] result, TaskCallback callback) throws IOException {
159181
try {
160182
ExternalSystemTaskExecutionSettings executionSettings = new ExternalSystemTaskExecutionSettings();
161183
executionSettings.setExternalSystemIdString(GradleConstants.SYSTEM_ID.toString());
162184
executionSettings.setTaskNames(Collections.singletonList("listQuarkusDependencies"));
163185
executionSettings.setScriptParameters(String.format("-c %s -q --console plain", customSettingsFile.toString()));
164186
executionSettings.setExternalProjectPath(getModuleDirPath(module));
165-
ExternalSystemUtil.runTask(
166-
executionSettings,
167-
DefaultRunExecutor.EXECUTOR_ID,
168-
module.getProject(),
169-
GradleConstants.SYSTEM_ID
170-
);
187+
ExternalSystemUtil.runTask(executionSettings,DefaultRunExecutor.EXECUTOR_ID,
188+
module.getProject(),
189+
GradleConstants.SYSTEM_ID, callback, ProgressExecutionMode.IN_BACKGROUND_ASYNC, false);
171190
try (BufferedReader reader = Files.newBufferedReader(outputPath)) {
172191
String id;
173192

174193
while ((id = reader.readLine()) != null) {
175194
String file = reader.readLine();
176195
String[] ids = id.split(":");
177-
if (!isDependency(ModuleRootManager.getInstance(module), ids[0], ids[1])) {
178-
if (file != null) {
179-
VirtualFile jarFile = getJarFile(file);
180-
if (jarFile != null) {
181-
result[file.endsWith("sources.jar") ? SOURCES : BINARY].add(jarFile);
182-
}
196+
if (!isDependency(ModuleRootManager.getInstance(module), ids[0], ids[1]) && file != null) {
197+
VirtualFile jarFile = getJarFile(file);
198+
if (jarFile != null) {
199+
result[file.endsWith("sources.jar") ? SOURCES : BINARY].add(jarFile);
183200
}
184201
}
185202
}
@@ -233,6 +250,7 @@ private Path generateCustomGradleSettings(String basePath, Path customBuildFile)
233250
try (Reader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
234251
content = IOUtils.toString(reader);
235252
} catch (IOException e) {
253+
LOGGER.warn(e.getLocalizedMessage(), e);
236254
}
237255
content += System.lineSeparator() + "rootProject.buildFileName =\"" + customBuildFile.getFileName().toFile().getName() + "\"";
238256
Path customPath = Files.createTempFile(base, null, getScriptExtension());
@@ -252,7 +270,7 @@ private Path generateCustomGradleSettings(String basePath, Path customBuildFile)
252270
* @return the content of the custom build file
253271
*/
254272
private String appendQuarkusResolution(String content, Path outputPath, Set<String> deploymentIds) {
255-
StringBuffer buffer = new StringBuffer(content);
273+
StringBuilder buffer = new StringBuilder(content);
256274
buffer.append(System.lineSeparator());
257275
buffer.append(createQuarkusConfiguration()).append(System.lineSeparator());
258276
buffer.append("dependencies {").append(System.lineSeparator());
@@ -281,29 +299,27 @@ private void processLibrary(Library library, ModuleRootManager manager, Set<Stri
281299
* @return the File object
282300
*/
283301
public static File getDeploymentFile(String artifactId) {
284-
String path = toPath(artifactId, File.separatorChar);
302+
String path = toPath(artifactId);
285303
if (path != null) {
286304
return new File(M2_REPO, path);
287305
}
288306
return null;
289307
}
290308

291-
private static String toPath(String artifactId, char separator) {
309+
private static String toPath(String artifactId) {
292310
String[] comps = artifactId.split(":");
293311
if (comps.length == 3) {
294-
StringBuffer buffer = new StringBuffer(comps[0].replace('.', separator));
295-
buffer.append(separator).append(comps[1]).append(separator).append(comps[2]).append(separator).append(comps[1]).append('-').append(comps[2]).append(".jar");
296-
return buffer.toString();
312+
return comps[0].replace('.', File.separatorChar) + File.separatorChar + comps[1] + File.separatorChar + comps[2] + File.separatorChar + comps[1] + '-' + comps[2] + ".jar";
297313
}
298314
return null;
299315
}
300316

301317
private boolean isDependency(ModuleRootManager manager, String deploymentIdStr) {
302-
return Stream.of(manager.getOrderEntries()).filter(entry -> entry instanceof LibraryOrderEntry && (GRADLE_LIBRARY_PREFIX + deploymentIdStr).equals(((LibraryOrderEntry) entry).getLibraryName())).findFirst().isPresent();
318+
return Stream.of(manager.getOrderEntries()).anyMatch(entry -> entry instanceof LibraryOrderEntry && (GRADLE_LIBRARY_PREFIX + deploymentIdStr).equals(((LibraryOrderEntry) entry).getLibraryName()));
303319
}
304320

305321
private boolean isDependency(ModuleRootManager manager, String groupId, String artifactId) {
306-
return Stream.of(manager.getOrderEntries()).filter(entry -> entry instanceof LibraryOrderEntry && ((LibraryOrderEntry) entry).getLibraryName().startsWith(GRADLE_LIBRARY_PREFIX + groupId + ':' + artifactId)).findFirst().isPresent();
322+
return Stream.of(manager.getOrderEntries()).anyMatch(entry -> entry instanceof LibraryOrderEntry && ((LibraryOrderEntry) entry).getLibraryName().startsWith(GRADLE_LIBRARY_PREFIX + groupId + ':' + artifactId));
307323
}
308324

309325
@Override
@@ -381,16 +397,16 @@ public void onImportFinished(@Nullable String projectPath) {
381397
}
382398

383399
ReadAction.nonBlocking(() -> {
384-
List<Module> modules = new ArrayList<>();
385-
Module[] existingModules = ModuleManager.getInstance(project).getModules();
386-
for (Module module : existingModules) {
387-
// Check if the module is a Gradle project
388-
if (GradleRunnerUtil.isGradleModule(module) && isValidGradleModule(module)) {
389-
modules.add(module);
390-
}
400+
List<Module> modules = new ArrayList<>();
401+
Module[] existingModules = ModuleManager.getInstance(project).getModules();
402+
for (Module module : existingModules) {
403+
// Check if the module is a Gradle project
404+
if (GradleRunnerUtil.isGradleModule(module) && isValidGradleModule(module)) {
405+
modules.add(module);
391406
}
392-
listener.importFinished(modules);
393-
})
407+
}
408+
listener.importFinished(modules);
409+
})
394410
.inSmartMode(project)
395411
.submit(NonUrgentExecutor.getInstance());
396412
}

src/main/java/com/redhat/devtools/intellij/quarkus/buildtool/maven/MavenToolDelegate.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@
3939
import org.jetbrains.idea.maven.project.MavenProject;
4040
import org.jetbrains.idea.maven.project.MavenProjectsManager;
4141
import org.jetbrains.idea.maven.server.MavenEmbedderWrapper;
42-
import org.jetbrains.idea.maven.server.MavenServerManager;
4342
import org.jetbrains.idea.maven.utils.MavenUtil;
4443
import org.slf4j.Logger;
4544
import org.slf4j.LoggerFactory;
4645

4746
import java.util.*;
4847

48+
import static org.jetbrains.idea.maven.project.MavenEmbeddersManager.FOR_DEPENDENCIES_RESOLVE;
49+
4950
public class MavenToolDelegate implements BuildToolDelegate {
5051
private static final Logger LOGGER = LoggerFactory.getLogger(MavenToolDelegate.class);
5152

@@ -154,7 +155,7 @@ private boolean processDependency(MavenProject mavenProject, List<VirtualFile>[]
154155
private Set<MavenArtifact> resolveDeploymentArtifacts(Module module, MavenProject mavenProject, Set<MavenId> deploymentIds, String classifier, ProgressIndicator progressIndicator) {
155156
Set<MavenArtifact> deploymentArtifacts = new HashSet<>();
156157
try {
157-
MavenEmbedderWrapper serverWrapper = MavenServerManager.getInstance().createEmbedder(module.getProject(), true, mavenProject.getDirectory());
158+
MavenEmbedderWrapper serverWrapper = MavenProjectsManager.getInstance(module.getProject()).getEmbeddersManager().getEmbedder(mavenProject, FOR_DEPENDENCIES_RESOLVE);
158159
if (classifier != null) {
159160
for (MavenId id : deploymentIds) {
160161
deploymentArtifacts.add(serverWrapper.resolve(new MavenArtifactInfo(id, "jar", classifier), mavenProject.getRemoteRepositories()));

src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/GradlePropertiesManagerLocationUsingVertxTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void setUp() throws Exception {
3737
}
3838

3939
@Test
40-
public void testUsingVertxTest() throws Exception {
40+
public void testUsingVertxTest() {
4141
Module javaProject = getModule("using-vertx.main");
4242
QuarkusDeploymentSupport.getInstance(javaProject.getProject()).updateClasspathWithQuarkusDeployment(javaProject, new EmptyProgressIndicator());
4343

src/test/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/core/LSP4MPMavenModuleImportingTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected Module loadMavenProject(String projectName) throws Exception {
3131
protected Module loadMavenProject(String projectName, boolean collectAndAddQuarkusDeploymentDependencies) throws Exception {
3232
Module module = createMavenModule(new File("projects/lsp4mp/projects/maven/" + projectName));
3333
if(collectAndAddQuarkusDeploymentDependencies) {
34-
QuarkusDeploymentSupport.updateClasspathWithQuarkusDeployment(module, new EmptyProgressIndicator());
34+
QuarkusDeploymentSupport.getInstance(myTestFixture.getProject()).updateClasspathWithQuarkusDeployment(module, new EmptyProgressIndicator());
3535
}
3636
return module;
3737
}

src/test/java/com/redhat/devtools/intellij/quarkus/completion/MavenApplicationPropertiesCompletionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected Module loadMavenProject(String projectName) throws Exception {
8181
protected Module loadMavenProject(String projectName, boolean collectAndAddQuarkusDeploymentDependencies) throws Exception {
8282
Module module = createMavenModule(new File("projects/quarkus/projects/maven/" + projectName));
8383
if(collectAndAddQuarkusDeploymentDependencies) {
84-
QuarkusDeploymentSupport.updateClasspathWithQuarkusDeployment(module, new EmptyProgressIndicator());
84+
QuarkusDeploymentSupport.getInstance(myTestFixture.getProject()).updateClasspathWithQuarkusDeployment(module, new EmptyProgressIndicator());
8585
}
8686
return module;
8787
}

src/test/java/com/redhat/microprofile/psi/quarkus/QuarkusMavenModuleImportingTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected Module loadMavenProject(String projectName) throws Exception {
3131
protected Module loadMavenProject(String projectName, boolean collectAndAddQuarkusDeploymentDependencies) throws Exception {
3232
Module module = createMavenModule(new File("projects/quarkus/projects/maven/" + projectName));
3333
if(collectAndAddQuarkusDeploymentDependencies) {
34-
QuarkusDeploymentSupport.updateClasspathWithQuarkusDeployment(module, new EmptyProgressIndicator());
34+
QuarkusDeploymentSupport.getInstance(myTestFixture.getProject()).updateClasspathWithQuarkusDeployment(module, new EmptyProgressIndicator());
3535
}
3636
return module;
3737
}

0 commit comments

Comments
 (0)