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: WIP let gradle main module find templates #1240

Closed
wants to merge 1 commit into from

Conversation

fbricon
Copy link
Contributor

@fbricon fbricon commented Oct 18, 2023

Signed-off-by: Fred Bricon [email protected]

@sonarcloud
Copy link

sonarcloud bot commented Oct 18, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
12.3% 12.3% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@angelozerr
Copy link
Contributor

It would be really nice to copy / paste tests with Qute codelens, document link and validation from https://github.com/redhat-developer/intellij-quarkus/tree/main/src/test/java/com/redhat/devtools/intellij/qute/psi/java and adapt them for gradle by using the same templates.

.collect(Collectors.toList()), templateBaseDir);
}

private static String getTemplateBaseDir(Module javaProject) {
List<VirtualFile> resourcesDirs = ModuleRootManager.getInstance(javaProject).getSourceRoots(JavaResourceRootType.RESOURCE);
if (!resourcesDirs.isEmpty()) {
for (var dir : resourcesDirs) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should remove TEMPLATES_BASE_DIR constants ad have:

  • TEMPLATES_FOLDER_NAME = "templates"
  • RESOURCES_BASE_DIR = "src/main"

List<VirtualFile> resourcesDirs = ModuleRootManager.getInstance(javaProject).getSourceRoots(JavaResourceRootType.RESOURCE);
if (!resourcesDirs.isEmpty()) {
for (var dir : resourcesDirs) {
var templatesDir = dir.findChild("templates");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var templatesDir = dir.findChild(TEMPLATES_FOLDER_NAME);

return LSPIJUtils.toUri(templatesDir).toASCIIString();
}
}
return LSPIJUtils.toUri(resourcesDirs.get(0)).resolve("templates").toASCIIString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return LSPIJUtils.toUri(resourcesDirs.get(0)).resolve(TEMPLATES_FOLDER_NAME).toASCIIString();

}
}
return LSPIJUtils.toUri(resourcesDirs.get(0)).resolve("templates").toASCIIString();
}
return LSPIJUtils.toUri(javaProject).resolve(TEMPLATES_BASE_DIR).toASCIIString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return LSPIJUtils.toUri(javaProject).rsolve(RESOURCES_BASE_DIR ).resolve(TEMPLATES_BASE_DIR).toASCIIString();

return LSPIJUtils.toUri(javaProject).resolve(TEMPLATES_BASE_DIR).toASCIIString();
}

public List<VirtualFile> getSortedSourceRoots(Module module) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method seems unused

@@ -203,8 +208,12 @@ private VirtualFile getTemplateFile(Module project, String templateFilePathWitho

@Nullable
private VirtualFile getVirtualFile(Module project, String templateFilePathWithoutExtension, String suffix) {
VirtualFile @NotNull [] roots = ModuleRootManager.getInstance(project).getContentRoots();
Copy link
Contributor

@angelozerr angelozerr Oct 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the main problem is that templateFilePathWithoutExtension starts with src/main/resources/templates (ex : src/main/resources/templates/page). templateFilePathWithoutExtension should not starts with src/main/resources but just with templates (we will need to change that in the future too to support several known templates folder to scan like web for Quarkus Web Asset, but let's keep simple for the moment)

If templateFilePathWithoutExtension doesn't contains src/main/resources, you can use the same logic than getTemplateBaseDir(Module javaProject) by using:

List<VirtualFile> resourcesDirs = ModuleRootManager.getInstance(javaProject).getSourceRoots(JavaResourceRootType.RESOURCE);

instead of using ModuleRootManager.getInstance(project).getContentRoots(); and perhaps avoid having a mergeUri method.

@angelozerr
Copy link
Contributor

Close for #1237

@angelozerr angelozerr closed this Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants