weirddev

Open full view…

Where to put TestMe macros.java.ft to be resolved from velocity templates?

lubos2
Tue, 05 May 2020 11:08:25 GMT

Hello. I am trying to use parts of your code of the TestMe plugin in a bigger workflow that contains as a step Unit Test generation. I am using your code not as IJ plugin but as just 'code' or library. I am developing also a IJ plugin. Unfortunatelly I am struggling with your velocity templates. From TestMe with JUnit4 & Mockito.java.ft the TestMe common macros.java.ft cannot be resolved on runtime - throwing the error: "Velocity Error Error parsing file template: Unable to find resource 'TestMe macros.java'" I would like to know where to put the referenced velocity files so that they get resolved correctly on runtime? The velocity template 'TestMe with JUnit4 & Mockito.java.ft' can obviously be found (I checked this in debug mode) but it crashes when the program tries to process the line: #parse("TestMe macros.java"). I have both: internal and testMeIncludes directories in the same directory structure as they are in your TestMe plugin. I have also tried to put the velocity files from testMeIncludes directory to internal directory, but with no success. I have seen i n your code that You have written some hacks for Velocity. If I understand your code correctly, this code (HackedRuntimeInstance.java) gets only called as a part of TestMe Plugin initialization / loading. Your help would be highly appreciated. Best regards, Lubos Dobrovoda.

Yaron
Tue, 05 May 2020 20:31:31 GMT

Hi Lubos, I can guess what is the issue based on your description, but can't be 100% sure. I hope this explanation helps. TestMe plugin is using the same Velocity Engine used by IDEA. In order to reuse the related code generation framework and get easy access to shared resources such as the user configured file headers such as `File Header.java`. Since the sdk has limited public api support, reflection was used to access internal api. In your use case, you will be initializing a Velocity engine directly. The code you referenced that performs these load time hacks is not relevant for you. all you need is to set the classpath of included resources for the velocity engine you are initializing. You can either provide a configuration file, such as https://github.com/wrdv/testme-idea/blob/master/src/main/resources/fileTemplates/velocity.properties or do that programmatically - https://velocity.apache.org/engine/1.7/developer-guide.html#miscellaneous-details. Please note that this holds true to the Velocity library used by IDEA ( I think it's v1.7). If your using version 2.x, it might be a bit different - https://velocity.apache.org/engine/devel/developer-guide.html#resource-loaders Happy hacking :) Yaron

lubos2
Fri, 08 May 2020 03:45:11 GMT

Thank You very much for your detailed answer. I have solved the problem in a different way but nevertheless once more thankx for your time ;)

henrywatson77
Wed, 21 Dec 2022 18:25:42 GMT

I had a similar problem, I had to turn to [c programming assignment help](https://www.programmingassignment.net/services/c-assignment-help/) in order to get help with a programming assignment because these problems take up a lot of my time and energy, which I can direct to other projects