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

[Bug fix request] Files that use Apache Velocity for name generation create empty files instead of mapping to file templates #20

Open
iwb-cgalvarez opened this issue Feb 23, 2024 · 5 comments

Comments

@iwb-cgalvarez
Copy link

First of all, I would like to thank you for your reactivity and for implementing the feature requested in our previous issue.

After updating to the latest version of the plugin 1.6.6, we noticed that the splitting of the folders based on the folder name generation through apache velocity works fine now (which is the request feature, thank you for that🙏) but the files that use apache velocity create now empty files.

Steps to reproduce

Given the following file template:

Screenshot 2024-02-23 at 15 08 45

Given the following module template:

Screenshot 2024-02-23 at 15 16 40

When I create a module using the file and module templates and the configuration shown below

Screenshot 2024-02-23 at 15 18 20

I want to see the Hello, World! shown in the template but it's empty instead:

Screenshot 2024-02-23 at 15 28 42

Please find attached here the file and module templates to reproduce the issue:
module_templates_files.zip

Thank you very much in advance and please don't hesitate to ask if you need further clarifications 🙏

@dengzii
Copy link
Owner

dengzii commented Feb 26, 2024

Hello,

whether all file templates are unavailable or this one alone ?

The statement

${StringUtils.removeAndHump(${FEATURE_NAME.replaceAll("[^\w]", "_")})}Module.kt

reported an error when I reproduced the problem, but I tried fix it in v1.6.7.

@iwb-cgalvarez
Copy link
Author

Hello,

Thank you for your response. It happens to all the files that use Apache Velocity on the name definition.

@dengzii
Copy link
Owner

dengzii commented Feb 28, 2024

I apologize, but this nested ApacheVelocity statement has been consistently causing errors and preventing file creation on my end. Non-nested structures seem to work fine. Please consider using an alternative approach, such as employing a new placeholder. 🙇‍♂️

@iwb-cgalvarez
Copy link
Author

Hello @dengzii,

Thank you for the suggestion. The problem is that placeholders cannot use apache velocity, do they?

This used to work fine before the fix for this issue, so I think the problem is the mapping between the file name using apache velocity between the realChildren and the fileTemplates keys in the moduleTemplate json configuration.

I think the mapping is happening between the result of the apache velocity function on the file names under realChildren against the unprocessed value of the key under fileTemplates.

To give you an example:

Imagine that we have a the module template definition that I posted in the issue:

${StringUtils.removeAndHump(${FEATURE_NAME.replaceAll("[^\w]", "_")})}Module.kt

This same file name definition is used in the file name under the folder example in the screenshot of the issue and under one of the keys under fileTemplates pointing to the file template Example.

I think in the code, when trying to find which file template you need to use, the program is using the processed value of the file (TestDemoModule.kt) against the key which is unprocessed (${StringUtils.removeAndHump(${FEATURE_NAME.replaceAll("[^\w]", "_")})}Module.kt) and they are indeed not equal.

If you are busy, I can try to fix it on my side when I have a bit of time. Would you accept an external pull request?

@dengzii
Copy link
Owner

dengzii commented Feb 29, 2024

Hello! Yes, I’ve been quite busy lately. I’ve already considered the points you mentioned. The crucial issue is that the results of running ApacheVelocity statements in unit tests differ from run compile plugin in the IDEA.

This is the code for simulating the parsing of a node tree in unit tests:

image

If you could help fix with this, I would greatly appreciate it. 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants