casid / jte-intellij

IntelliJ plugin for jte template files.
https://github.com/casid/jte
Apache License 2.0
23 stars 5 forks source link

Multi-module maven project and JSP to JTE conversion using IDEA plugin #12

Closed izogfif closed 3 years ago

izogfif commented 3 years ago

I have a multi-module Maven project. I created Module1JspToJteConverter that extends JspToJteConverter in module1. Converted .tag file inside module1 using Intellij IDEA plugin. Everything was fine. Then I created Module2JspToJteConverter in module2. It has different settings (e.g. converter.setPrefix contains different list of @import directives). When I open in Intellij IDEA .tag file that resides inside module2 and go to menu Code->Convert JSP file to jte file, Module1JspToJteConverter starts instead of Module2JspToJteConverter.

casid commented 3 years ago

Ugh, that's probably because I'm looking for the converter class in the project of the psi file to convert (https://github.com/casid/jte-intellij/blob/571dad30c2d81436c066f0d6a83be43c9d85941d/src/main/java/org/jusecase/jte/intellij/language/convert/JteConvertFromJspAction.java#L37).

PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE);
if (psiFile == null) {
    return;
}

Project project = psiFile.getProject();

PsiClass converterBaseClass = JavaPsiFacade.getInstance(project).findClass(CONVERTER_BASE_CLASS, GlobalSearchScope.everythingScope(project));

I'll have a look if I can search in the module of that file instead.

casid commented 3 years ago

I transferred this issue over to the jte-intellij plugin.

And I think I have a fix for it. It now works with multiple modules in my dummy project.

I'll try to release a new version of the plugin this weekend.

casid commented 3 years ago

I've uploaded a new version of the plugin!

Thank you for submitting a 1.4.1 version of jte plugin, it has been successfully uploaded to the plugins repository and now pending JetBrains' review and approval in order to be publicly available.

All new updates are normally reviewed within two business days. You will receive a notification as soon as status of this review changes.
izogfif commented 3 years ago

@casid can you add a tag and release for 1.4.1 version of this plugin? So that it can be downloaded from https://github.com/casid/jte-intellij/releases page. "Two business days" means that it won't be available from Intellij IDEA plugin marketplace until at least Tuesday. Update: the plugin was approved in Intellij IDEA marketplace. Great. Still, I think that it should also be placed in https://github.com/casid/jte-intellij/releases page. For consistency.

izogfif commented 3 years ago

@casid I've installed the plugin and I'm getting this error message now:

Could not locate class 'gg.jte.convert.jsp.JspToJteConverter' on the classpath. You're probably missing the jte-jsp-converter dependency.

I've even changed scope from test to compile and added code

JspToJteConverter g = new JspToJteConverter(Path.of("/"), Path.of("/"), "");

in one of .java files inside src/main/java of the module. The project compiled successfully, i.e. the issue is not that I forgot to add a dependency.

After studying your commit, I think I found the issue. Method com.intellij.psi.search.GlobalSearchScope.moduleScope has this JavaDoc:

Returns module scope including sources and tests, excluding libraries and dependencies.

Maybe you should use GlobalSearchScope.moduleWithDependenciesAndLibrariesScope instead?

Update: I've changed all occurrences of moduleScope in plugin code to moduleWithDependenciesAndLibrariesScope (I found two of them), built it, installed into IDEA, restarted IDEA, then ran "Code->Convert JSP to jte file" command again. Now it works the way it is supposed to.

casid commented 3 years ago

Thanks for the investigation. I released a hotfix version of the plugin.