sts4
sts4 copied to clipboard
.properties <-> .yml converter
A command to automatically convert properties to YAML files (and vice versa) would be very handy.
Is this the request for Spring Boot Tools for vscode plugin?
Yes just a simple command that can be triggered from within the editor or context menu:

Here is another related feature request to have yml -> properties convention: https://github.com/spring-projects/spring-ide/issues/331.
It looks to me like we have three parts of this:
- convert properties -> yml
- convert yml -> properties
- make both available in Eclipse as well as VSCode
So this sounds to me like we should move the existing implementation for converting properties -> yml into the language server and make it available via a command to the client. Then, we could serve this as menu item / command in the various clients. Maybe the command can be generic in terms of which conversion should happen so that we can use the same command with different params for converting properties -> yml and then, down the line, for yml -> properties as well (so that the command is on the level of "convert" and the params specify the "to" format maybe. The input file would/could determine the "from" format.
Another thought here: If we allow the conversion to change the existing file (rename + content conversion), we would need to make sure that the conversion is exact and nothing gets lost in the conversion. This might be hard to achieve.
As a consequence, we could also always create a new file (in addition to the existing one) and put the converted content in the new file without deleting the existing file. That would prevent the user from loosing something in case the conversion is not fully complete or missed something.
We could also add a preference for this to switch between the modes ("delete file after property conversion") that would be disabled at the beginning and users could enable this if they think the old file should always be deleted.
Has a lot of sense what you are proposing.
In that way keeping the 2 files, the original and converted. Is assumed that in Spring Boot exists a priority about what file to choice if exists both with the same name but with different extension (.properties/.yml/.yaml). But it is other history and is assumed the developer knows what to do - either keep both files or delete the former when the latter was generated from the former (manually or automatically according with your propose).
We are moving back from yml format to property files, so that automatic conversion would be quite handy to have also in Eclipse STS. Unfortunately, I guess this will come too late for us...
We are moving back from yml format to property files, so that automatic conversion would be quite handy to have also in Eclipse STS. Unfortunately, I guess this will come too late for us...
Let's see what @BoykoAlex things about this when he is back, maybe we can pull something off soonish.
If I was to do this properly I would:
- Create 2 commands for properties->yaml and yaml->properties on the Boot LS side. Both commands apply workspace edit at the end. Parameters for the commands would provide info whether new file should be created or existing file replaced
- The workspace edit would have
needsConfirmation
flag set to bring up the refactoring preview (maybe only for replacing a file?) - Implements support in LSP4E to bring up refactoring preview in Eclipse (not difficult, but perhaps with some limitations)
(Currently in Eclipse the action shows refactor preview. If we are to keep this behaviour then we'd need needsConfirmation
LSP flag support. Alternative is just not show refactor preview and perhaps make creating new file the default behaviour)
Perhaps we could add a menu item just for Eclipse to convert boot properties from yaml -> properties? I'm curious how difficult this might turn out to be. This work could later be used for the proper LSP-based solution. Then later we might improve things to keep comments in the right places using OpenRewrite but this would be in a longer term...
POC in Eclipse seems to work... of course it would need to be unit tested before it goes into the snapshot builds. It also has similar limitations of removing comments as props -> yaml has.
If you need a tester for Linux, I am here available, it for Ubuntu and Fedora. Same thought for Windows 10.
Pushed Eclipse only yaml -> props support: 3a0ee635f2c09498218bde903d071e40c13142fc Will look into refactor preview in LSP4E next and then move yaml -> props and props -> yaml to LS
Try Eclipse snapshots from: https://cdn.spring.io/spring-tools/snapshot/STS4/nightly-distributions.html
Just to be in the same picture...
- Should be installed the IDE (nightly)
- Create a new Spring Boot project
- Create a new application.properties file
- Convert the .properties file to application.yml file
- Revert the conversion from .yml to .properties
Am I correct?
Sure, just wait 1.5 hours from now for the eclipse distro snapshot build to finish.
Understood. I am going to test them starting this Friday in the afternoon.
Report I
Working with the installer for windows:
-
spring-tool-suite-4-4.22.1.202403251831-SNAPSHOT-e4.32.0-win32.win32.x86_64.self-extracting.jar
Unpacked and nothing more done prior to start it.
Creating at https://start.spring.io
a simple demo.zip
project based on Maven
with:
<artifactId>spring-boot-starter-data-jpa</artifactId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<artifactId>spring-boot-starter-web</artifactId>
<artifactId>h2</artifactId>
<artifactId>mysql-connector-j</artifactId>
Imported in the IDE and editing the application.properties
file
spring.application.name=demo
spring.profiles.active=mysql,no-cache
spring.datasource.url=jdbc:h2:mem:ensamble_presentation_v2
spring.datasource.username=sa
spring.datasource.password=password
spring.sql.init.mode=embedded
spring.sql.init.schema-locations=classpath:/com/manuel/jordan/h2/v2/schema-h2.sql
spring.sql.init.data-locations=classpath:/com/manuel/jordan/h2/v2/data-h2.sql
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.use_sql_comments=true
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
spring.messages.basename=i18n/messages,i18n.labels
spring.thymeleaf.cache=true
spring.thymeleaf.enabled=true
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.mvc.hiddenmethod.filter.enabled=true
server.port=8080
In this application.properties
file, being open in the default internal editor, applying:
-
Right click ->
Convert .properties to .yaml
Sorry about the huge size of the Figures, in this way works Ms Paint on Windows 10 Home.
Pressed OK
, is generated the application.yaml
file and the application.properties
file is deleted.
The application.yaml
file content is as follows:
logging:
level:
org:
hibernate:
SQL: DEBUG
type:
descriptor:
sql:
BasicBinder: TRACE
server:
port: 8080
spring:
application:
name: demo
datasource:
password: password
url: jdbc:h2:mem:ensamble_presentation_v2
username: sa
jpa:
properties:
hibernate:
format_sql: true
show_sql: true
use_sql_comments: true
show-sql: true
messages:
basename: i18n/messages,i18n.labels
mvc:
hiddenmethod:
filter:
enabled: true
profiles:
active: mysql,no-cache
sql:
init:
data-locations: classpath:/com/manuel/jordan/h2/v2/data-h2.sql
mode: embedded
schema-locations: classpath:/com/manuel/jordan/h2/v2/schema-h2.sql
thymeleaf:
cache: true
enabled: true
prefix: classpath:/templates/
suffix: .html
Now having the application.yaml
file, being open in the default internal editor, and applying
-
Right click ->
Convert .yaml to .properties
happens:
Is pressed the Abort
button. Is generated the application.properties
file and the application.yaml
file is not deleted.
BTW the error message is:
Is not possible delete the application.yaml
file, always appears:
The unique way to delete this file is closing and opening the project. Wait few seconds prior to re-open
Note: This error happens even if the application.yaml
file is closed when the transform process is applied.
So the logical question is: What is the other process?
Wait me for the report for Ubuntu and Fedora. Thanks for your understanding
@manueljordan I have just fixed the issue of "the file being used by another process" on Win: e528454f2c72a0dd80446270ca194b0e5225f042
Thanks for giving it a spin :-)
@BoykoAlex thanks for the quick update for Windows, pls let me know when is ready/built the new installer - it about to wait 1.5hrs
Thanks for giving it a spin :-)
Np - I enjoy this IDE
Report II
Working with the installer for Linux (Ubuntu and Fedora):
-
spring-tool-suite-4-4.22.1.202403261702-SNAPSHOT-e4.32.0-linux.gtk.x86_64.tar.gz
Unpacked and nothing more done prior to start it.
Same instructions as indicated for Windows experience, it works fine, but appears the following:
The warning message is the same for the three points
And just in case, that Warning message appeared just once in Windows too, but not anymore, it remains in Linux/Ubuntu. I am assuming it would happen and should remain as in Linux, it based with the new installer
As summary:
- From
.properties
to.yaml
works and the former file is deleted and replaced by the latter (and the message warning appears) - From
.yaml
to.properties
works and the former file is deleted and replaced by the latter
Thanks to your quick patch and I did do realize and confirmed that any comment disappears. And finally:
- all the properties are sorted alphabetically
- Any empty line dissappears too
It seems it is almost completed (I must re-test Windows), but I did do realize the following.
- After to did do a conversion, if within the opened file is do right click, appears the context menu as expected, but is enabled the item about Undo Ctrl + Z and it throws an error if is executed. Should be enabled that item/option?
- For any conversion scenario, all the properties keys are sorted alphabetically. But if from the scratch prior to do any conversion (take as reference my original .properties file), how is expected to sort that content? If within the opened file is done right click to open the context menu, there is no option to reach this goal. Pls confirm if once solved this Issue of conversion - I should create a new issue to request this feature.
Thanks for your understanding
@manueljordan build has succeeded and ready to for testing
@BoykoAlex it works fine now, same behavior as Linux.
@manueljordan awesome!!! Thanks very much for testing!-) I'm moving the refactoring logic on the Boot LS side now to make yaml <-> props conversions available in both Eclipse and VSCode (and Theia therefore).
@BoykoAlex no problem :) - let me know your thoughts about points 1 and 2.
@manueljordan Regarding the two points:
- Is this about performing "Undo" action once conversion is applied? I did notice that it refuses to execute with a warning dialog that renamed file has been changed etc. Looks like this was the initial limitation with props -> yaml conversion. I'd treat this as a separate issue and curious if it is Eclipse only issue.
- I observer this only with props -> yaml. The yaml -> props seems to keep the initial order. I'll look into it but consider it as a low priority things which could factored out in a separate issue.
Thanks @BoykoAlex
Understood. It seems they are candidates to create two new issues. And even would exist a 3rd one, it to suggest and apply a refactoring to solve the mentioned warning messages shown in the .yaml
files - what do you think?
@manueljordan I'd create 2 additional issues once this issue is resolved as there is a chance to resolve them once conversion is an LS command. Is the 3rd issue about warnings/errors inside of the produced yaml files in a form of comments?
@BoykoAlex
Is the 3rd issue about warnings/errors inside of the produced yaml files in a form of comments?
Yes, about that
Pushed in the Boot LS based yaml <-> props conversion. It is now available on both VSCode and Eclipse. I was able to somewhat maintain the order of keys for props -> yaml conversion. The undo still didn't work properly in Eclipse therefore in Eclipse you'd be only able to create new file without replacing the old. The old file could be replaced in VSCode if preference setting for replacing the old file is on (by default it is off). The change is: aed212796faa2b4a18d4aaa600e81023b9f1ac15
I was able to somewhat maintain the order of keys for props -> yaml conversion.
Sounds great.
The undo still didn't work properly in Eclipse therefore in Eclipse you'd be only able to create new file without replacing the old.
Two files in parallel, right? .properties and .yaml?
@manueljordan Exactly - in the same folder.