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

.properties <-> .yml converter #739

Closed
javahacks opened this issue Feb 18, 2022 · 30 comments
Closed

.properties <-> .yml converter #739

javahacks opened this issue Feb 18, 2022 · 30 comments
Assignees
Labels
for: eclipse something that is specific for Eclipse for: vscode something that is specific for VSCode theme: property-editing-support type: enhancement

Comments

@javahacks
Copy link

A command to automatically convert properties to YAML files (and vice versa) would be very handy.

@BoykoAlex
Copy link
Contributor

Is this the request for Spring Boot Tools for vscode plugin?

@javahacks
Copy link
Author

Yes just a simple command that can be triggered from within the editor or context menu:

image

@martinlippert
Copy link
Member

Here is another related feature request to have yml -> properties convention: spring-attic/spring-ide#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.

@martinlippert
Copy link
Member

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.

@martinlippert martinlippert added this to the 4.15.0.RELEASE milestone Mar 24, 2022
@javahacks javahacks reopened this Mar 24, 2022
@manueljordan
Copy link

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).

@martinlippert martinlippert removed this from the 4.15.0.RELEASE milestone Jul 1, 2022
@hbrands
Copy link

hbrands commented Mar 12, 2024

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...

@martinlippert martinlippert added this to the Backlog milestone Mar 12, 2024
@martinlippert
Copy link
Member

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.

@BoykoAlex
Copy link
Contributor

BoykoAlex commented Mar 19, 2024

If I was to do this properly I would:

  1. 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
  2. The workspace edit would have needsConfirmation flag set to bring up the refactoring preview (maybe only for replacing a file?)
  3. 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...

@BoykoAlex
Copy link
Contributor

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.

@martinlippert martinlippert modified the milestones: Backlog, 4.22.1.RELEASE Mar 20, 2024
@manueljordan
Copy link

If you need a tester for Linux, I am here available, it for Ubuntu and Fedora. Same thought for Windows 10.

@BoykoAlex
Copy link
Contributor

BoykoAlex commented Mar 20, 2024

Pushed Eclipse only yaml -> props support: 3a0ee63
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

@manueljordan
Copy link

Just to be in the same picture...

  1. Should be installed the IDE (nightly)
  2. Create a new Spring Boot project
  3. Create a new application.properties file
  4. Convert the .properties file to application.yml file
  5. Revert the conversion from .yml to .properties

Am I correct?

@BoykoAlex
Copy link
Contributor

Sure, just wait 1.5 hours from now for the eclipse distro snapshot build to finish.

@manueljordan
Copy link

Understood. I am going to test them starting this Friday in the afternoon.

@manueljordan
Copy link

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.

image_2024-03-26_084129911

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

image_2024-03-26_084527454

happens:

image_2024-03-26_085514509

Is pressed the Abort button. Is generated the application.properties file and the application.yaml file is not deleted.

BTW the error message is:

image_2024-03-26_090303688

Is not possible delete the application.yaml file, always appears:

image

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

@BoykoAlex
Copy link
Contributor

@manueljordan I have just fixed the issue of "the file being used by another process" on Win: e528454

Thanks for giving it a spin :-)

@manueljordan
Copy link

@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

@manueljordan
Copy link

manueljordan commented Mar 26, 2024

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:

sts4-01

sts4-02

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

@manueljordan
Copy link

It seems it is almost completed (I must re-test Windows), but I did do realize the following.

  1. 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?
  2. 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

@BoykoAlex
Copy link
Contributor

@manueljordan build has succeeded and ready to for testing

@manueljordan
Copy link

@BoykoAlex it works fine now, same behavior as Linux.

@BoykoAlex
Copy link
Contributor

@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).

@manueljordan
Copy link

@BoykoAlex no problem :) - let me know your thoughts about points 1 and 2.

@BoykoAlex
Copy link
Contributor

BoykoAlex commented Mar 27, 2024

@manueljordan Regarding the two points:

  1. 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.
  2. 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.

@manueljordan
Copy link

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?

@BoykoAlex
Copy link
Contributor

@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?

@manueljordan
Copy link

@BoykoAlex

Is the 3rd issue about warnings/errors inside of the produced yaml files in a form of comments?

Yes, about that

@BoykoAlex
Copy link
Contributor

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: aed2127

@manueljordan
Copy link

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?

@BoykoAlex
Copy link
Contributor

@manueljordan Exactly - in the same folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: eclipse something that is specific for Eclipse for: vscode something that is specific for VSCode theme: property-editing-support type: enhancement
Projects
None yet
Development

No branches or pull requests

5 participants