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

In VS Code, right-clicking a .properties file and selecting "Convert .properties to .yaml" does nothing #1478

Open
GrahamHannington opened this issue Feb 19, 2025 · 3 comments
Labels
for: vscode something that is specific for VSCode theme: property-editing-support

Comments

@GrahamHannington
Copy link

GrahamHannington commented Feb 19, 2025

Any idea why?

With apologies if I should be reporting this (that is, asking for help) somewhere else (please let me know).

Environment

  • Microsoft Visual Studio Code (VS Code) 1.96.4 on Windows 10
  • Relevant VS Code extensions (and their versions):
    • Language Support for Java by Red Hat (1.39.0)
    • Spring Boot Tools (1.60.0)
  • VS Code shows language mode "Spring Boot Properties" when I'm editing a .properties file

exthost.log extract

2025-02-19 10:16:42.263 [warning] [redhat.java] Accessing a resource scoped configuration without providing a resource is not expected. To get the effective value for '[java]', provide the URI of a resource or 'null' for any resource.
2025-02-19 10:16:43.291 [info] ExtensionService#_doActivateExtension vmware.vscode-spring-boot, startup: false, activationEvent: 'onLanguage:spring-boot-properties'
2025-02-19 10:16:46.022 [warning] [redhat.java] Accessing a resource scoped configuration without providing a resource is not expected. To get the effective value for '[java]', provide the URI of a resource or 'null' for any resource.
2025-02-19 10:16:49.690 [error] Error: command 'sts/boot/props-to-yaml' not found
    at O9e.n (vscode-file://vscode-app/c:/Program%20Files/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1315:1341)
    at O9e.executeCommand (vscode-file://vscode-app/c:/Program%20Files/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1315:1273) vscode-spring-boot.props-to-yaml {"value":"vmware.vscode-spring-boot","_lower":"vmware.vscode-spring-boot"}

Example .properties file

I doubt this is relevant, because I don't think the processing is getting this far ("command 'sts/boot/props-to-yaml' not found"), but for what it's worth (note: this is deliberately a trivially small test case):

server.port=9070

Thoughts

I've Googled for:

[warning] [redhat.java] Accessing a resource scoped configuration without providing a resource is not expected. To get the effective value for '[java]', provide the URI of a resource or 'null' for any resource.

found some hits, but I'm none the wiser about what to do. (Well, I've tried adding an empty "[java]": {} to my VS Code settings.json, but that's just grasping at straws.)

@BoykoAlex
Copy link
Contributor

@GrahamHannington this is the proper venue to report bugs or asking for help.
The log states that the command sts/boot/yaml-to-props cannot be found. This command should be registered at the startup of the Boot Language Server. I suspect that the language server process probably failed to start or not started in your case. Is your application.yaml file inside the Spring Boot project? Or is it standalone without a spring boot project? If your boot properties file is inside my-boot-project/main/resources for instance then i don't see a reason why it wouldn't work. I jave just tried the yaml-props conversion feature with spring petclinic - it worked just fine.

@GrahamHannington
Copy link
Author

GrahamHannington commented Feb 20, 2025

Hi @BoykoAlex, thanks very much for the quick reply. 👍

In brief

It's stand-alone.

What minimal set of files, and contents, must be present for "Convert .properties to .yaml" to work?

In detail

Background

I'm a Java beginner. I code in other languages, but in the context of this issue, I'm primarily a technical writer.

I write the docs (user documentation) for a Spring Boot application. The application developers wrote the "wrapper" startup methods for the application, such as a *nix shell script, to expect externalized application configuration properties to be in a single, monolothic YAML file. And that's what I've described in the docs.

However, application users have expressed a requirement to split the configuration properties across multiple files.

I've read the Spring Boot documentation on "Externalized Configuration". I understand that Spring Boot supports multiple property sources, including multiple .yaml (or .properties) configuration files. I've come up with recommendations to the developers for changing the "wrappers" that start the application to take advantage of that flexibility, rather than (artificially) requiring a single file. They're open to this (especially since users have asked for it!).

What I'm doing

A stand-alone collection of example configurations

I've created a stand-alone Git repository that contains multiple example application configurations. It's just some README.md files and a bunch of .yaml files in various descendant directories.

Each immediate child directory of the repo is intended to be used as the current directory of a Java command that starts the application.

Each of those child directories demonstrates a different example application configuration; a different arrangement of configuration files.

For example, let's say the application is called "Nexus" (it's not 🙂), and the root directory of my repo is called nexus-config-examples. Here's an immediate child directory, where the README.md explains that the example expects the property spring.config.name=nexus to be set ("early": for example, as a Java command-line argument).

nexus-config-examples/override-order-simple/
  README.md
  nexus.yaml
  config/
    nexus.yaml
    a/
      nexus.yaml
    b/
      nexus.yaml
    c/
      nexus.yaml

That is, there's a nexus.yaml file in each of the default locations where Spring Boot will automatically find and load them (in ., ./config, and immediate child directories of ./config).

Each file contains a different value for one or more properties. This example demonstrates Spring Boot's "last wins" approach: the properties in config/c/nexus.yaml prevail. You might think, "Well, duh". But if you're an application user coming from a background where only a single configuration file was "allowed", then such an example might usefully open your eyes to the possibilities.

I have over a dozen such example configurations, each in its own immediate child directory of the repo. Some of the examples use spring.config.import; some, which I have yet to write, will use profiles.

Some examples are deliberate monsters; some examples might get used by the product testers for QA; some might make it in the product, and/or product user documentation, as samples.

I'd prefer to keep this set of examples completely separate from the application source repository; in a separate repository, not just in a separate branch of the application source repository. And I don't particularly want to "bloat" my tiny repo of YAML files with a copy of the application Java source.

Why I'm interested in converting .properties to .yaml

I actually have limited interest in .properties files. I understand that both .properties and .yaml files can be used as property sources, but I don't use .properties files for that purpose. For this application, the product team has chosen to promote the
use of .yaml files, and I'm happy with that.

I'm really only interested in .properties files because that's the format in which I can get the "merged" set of properties as loaded by the Spring Boot application. I want to be able to review that merged set of properties as a YAML document; that is, in the same format in which users specify the (multiple) input configuration files. For details on this requirement, see Spring Boot GitHub issue "Configuration property to export environment configuration properties to .properties or .yaml file", #44289 (I created that issue).

I'm already using external tools to convert .properties to .yaml, such as the Environment Variable Generator website. I'd like to try these Spring Boot Tools in VS Code, too.

What does the Spring Boot Tools "Convert .properties to .yaml" require beyond an input .properties file?

As mentioned, I'm already converting .properties to .yaml using tools that require nothing more than an input .properties file.

So, I'm curious about the additional requirements of the Spring Boot Tools "Convert .properties to .yaml" in VS Code.

Like I said, I'm just a Java beginner, and I might be completely wrong about this, but it occurs to me that the Spring Boot Tools "Convert .properties to .yaml" (and vice versa) might parse the Java source of classes marked with the @ConfigurationProperties annotation.

In any case, I'd be interested to hear more about this. Some of the configuration properties in "my" application configuration YAML files don't have corresponding static Java code; no private String customPropertyName; in a @ConfigurationProperties class.

@martinlippert
Copy link
Member

In the end, the Spring Boot tooling requires the project (which contains the property files in your case) to be a regular Spring Boot Java project with the Spring Boot libraries on the classpath, for example via dependency management via Maven or Gradle. The easiest way to create and import such a project (in VSCode) is to have the Spring Initializr extension installed. This provides commands from the command palette like Spring Initializr: Create a Maven project. It is basically the extension to use https://start.spring.io directly from VSCode.

The reason for that is: the Spring Tools require to resolve types and meta information from the resolved classpath on the project, in the case of the property files to "know" about which properties exist, what format they have, and more.

@martinlippert martinlippert added theme: property-editing-support for: vscode something that is specific for VSCode labels Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: vscode something that is specific for VSCode theme: property-editing-support
Projects
None yet
Development

No branches or pull requests

3 participants