Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Quarkus Dev Mode is having trouble running main module by using Gradle with Kotlin DSL #1375

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.*;
import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -52,6 +49,7 @@ public class QuarkusModuleUtil {

public static final Pattern APPLICATION_YAML = Pattern.compile("application(-.+)?\\.ya?ml");

private static final Comparator<VirtualFile> ROOT_COMPARATOR = Comparator.comparingInt(r -> r.getPath().length());

/**
* Check if the module is a Quarkus project. Should check if some class if present
Expand Down Expand Up @@ -152,6 +150,34 @@ private static boolean isQuarkusModule(VirtualFile file, Project project) {
}

public static @Nullable VirtualFile getModuleDirPath(@NotNull Module module) {
return LocalFileSystem.getInstance().findFileByPath(ModuleUtilCore.getModuleDirPath(module));
VirtualFile[] roots = getContentRoots(module);
if (roots.length > 0) {
return roots[0];
}
return VfsUtil.findFileByIoFile(new File(ModuleUtilCore.getModuleDirPath(module)), true);
angelozerr marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Returns an array of content roots of the given module sorted with smallest path first (to eliminate generated sources roots) from all content entries.
*
* @param module the module
* @return the array of content roots.
*/
public static VirtualFile[] getContentRoots(Module module) {
VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots();
if (roots.length <= 1) {
return roots;
}
// put root with smallest path first (eliminates generated sources roots)
sortRoot(roots);
return roots;
}

public static void sortRoot(List<VirtualFile> roots) {
Collections.sort(roots, ROOT_COMPARATOR); // put root with smallest path first (eliminates generated sources roots)
}

public static void sortRoot(VirtualFile[] roots) {
Arrays.sort(roots, ROOT_COMPARATOR); // put root with smallest path first (eliminates generated sources roots)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,9 @@
package com.redhat.devtools.intellij.qute.psi.core.command;

import com.google.gson.JsonPrimitive;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.redhat.devtools.lsp4ij.commands.CommandExecutor;
import com.redhat.devtools.lsp4ij.commands.LSPCommand;
import com.redhat.devtools.lsp4ij.commands.LSPCommandAction;

import java.util.List;

public abstract class QuteAction extends LSPCommandAction {

protected String getURL(LSPCommand command) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.redhat.devtools.lsp4ij.LanguageServiceAccessor;
import com.redhat.devtools.lsp4ij.commands.CommandExecutor;
import com.redhat.devtools.lsp4ij.commands.LSPCommand;
import org.eclipse.lsp4j.Command;
import org.eclipse.lsp4j.ExecuteCommandOptions;
import org.eclipse.lsp4j.ExecuteCommandParams;
import org.eclipse.lsp4j.services.LanguageServer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public class PsiQuteProjectUtils {
* Value for Qute annotations indicating behaviour should be using the default
*/
private static final String DEFAULTED = "<<defaulted>>";
private static final Comparator<VirtualFile> ROOT_COMPARATOR = Comparator.comparingInt(r -> r.getPath().length());

private PsiQuteProjectUtils() {
}
Expand Down Expand Up @@ -104,7 +103,7 @@ private static String getTemplateBaseDir(Module javaProject) {
public static @Nullable VirtualFile findBestResourcesDir(@NotNull Module javaProject) {
List<VirtualFile> resourcesDirs = ModuleRootManager.getInstance(javaProject).getSourceRoots(JavaResourceRootType.RESOURCE);
if (!resourcesDirs.isEmpty()) {
Collections.sort(resourcesDirs, ROOT_COMPARATOR); // put root with smallest path first (eliminates generated sources roots)
QuarkusModuleUtil.sortRoot(resourcesDirs); // put root with smallest path first (eliminates generated sources roots)
// The module configure 'Resources folder'
// 1) loop for each configured resources dir and returns the first which contains 'templates' folder.
for (var dir : resourcesDirs) {
angelozerr marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -117,10 +116,6 @@ private static String getTemplateBaseDir(Module javaProject) {
return resourcesDirs.get(0);
}
// Corner usecase, the module doesn't configure 'Resources folder', use the first content roots
VirtualFile[] roots = getContentRoots(javaProject);
if (roots.length > 0) {
return roots[0];
}
return QuarkusModuleUtil.getModuleDirPath(javaProject);
}

Expand All @@ -131,12 +126,7 @@ private static String getTemplateBaseDir(Module javaProject) {
* @return the array of content roots.
*/
public static VirtualFile[] getContentRoots(Module module) {
VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots();
if (roots.length <= 1) {
return roots;
}
Arrays.sort(roots, ROOT_COMPARATOR); // put root with smallest path first (eliminates generated sources roots)
return roots;
return QuarkusModuleUtil.getContentRoots(module);
}

/**
Expand Down
Loading