Yaml<->Props conversion commands, tests, integration in VSCode, Eclipse
This commit is contained in:
@@ -20,6 +20,7 @@ import {registerClasspathService} from "@pivotal-tools/commons-vscode/lib/classp
|
||||
import {registerJavaDataService} from "@pivotal-tools/commons-vscode/lib/java-data";
|
||||
import * as setLogLevelUi from './set-log-levels-ui';
|
||||
import { startTestJarSupport } from "./test-jar-launch";
|
||||
import { startPropertiesConversionSupport } from "./convert-props-yaml";
|
||||
|
||||
const PROPERTIES_LANGUAGE_ID = "spring-boot-properties";
|
||||
const YAML_LANGUAGE_ID = "spring-boot-properties-yaml";
|
||||
@@ -157,7 +158,16 @@ export function activate(context: ExtensionContext): Thenable<ExtensionAPI> {
|
||||
liveHoverUi.activate(client, options, context);
|
||||
rewrite.activate(client, options, context);
|
||||
setLogLevelUi.activate(client, options, context);
|
||||
startPropertiesConversionSupport(context);
|
||||
|
||||
registerMiscCommands(context);
|
||||
|
||||
return new ApiManager(client).api;
|
||||
});
|
||||
}
|
||||
|
||||
function registerMiscCommands(context: ExtensionContext) {
|
||||
context.subscriptions.push(
|
||||
commands.registerCommand('vscode-spring-boot.spring.modulith.metadata.refresh', async () => {
|
||||
const modulithProjects = await commands.executeCommand('sts/modulith/projects');
|
||||
const projectNames = Object.keys(modulithProjects);
|
||||
@@ -170,14 +180,12 @@ export function activate(context: ExtensionContext): Thenable<ExtensionAPI> {
|
||||
);
|
||||
commands.executeCommand('sts/modulith/metadata/refresh', modulithProjects[projectName]);
|
||||
}
|
||||
});
|
||||
}),
|
||||
|
||||
commands.registerCommand('vscode-spring-boot.open.url', (openUrl) => {
|
||||
const openWithExternalBrowser = workspace.getConfiguration("spring.tools").get("openWith") === "external";
|
||||
const browserCommand = openWithExternalBrowser ? "vscode.open" : "simpleBrowser.api.open";
|
||||
return commands.executeCommand(browserCommand, Uri.parse(openUrl));
|
||||
});
|
||||
|
||||
return new ApiManager(client).api;
|
||||
});
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import * as path from "path";
|
||||
import { existsSync } from "fs";
|
||||
import { ExtensionContext, Uri, commands, window, workspace } from "vscode";
|
||||
|
||||
export function startPropertiesConversionSupport(extension: ExtensionContext) {
|
||||
extension.subscriptions.push(
|
||||
commands.registerCommand('vscode-spring-boot.props-to-yaml', async (uri) => {
|
||||
|
||||
if (!uri && window.activeTextEditor) {
|
||||
const activeUri = window.activeTextEditor.document.uri;
|
||||
if (".properties" === path.extname(activeUri.path)) {
|
||||
uri = activeUri;
|
||||
}
|
||||
}
|
||||
|
||||
if (!uri) {
|
||||
throw new Error("No '.properties' file selected");
|
||||
}
|
||||
|
||||
return await commands.executeCommand("sts/boot/props-to-yaml", uri.toString(), Uri.file(getTargetFile(uri.path, "yml")).toString(), shouldReplace());
|
||||
}),
|
||||
|
||||
commands.registerCommand('vscode-spring-boot.yaml-to-props', async (uri) => {
|
||||
|
||||
if (!uri && window.activeTextEditor) {
|
||||
const activeUri = window.activeTextEditor.document.uri;
|
||||
const ext = path.extname(activeUri.path)
|
||||
if (".yml" === ext || ".yaml" === ext) {
|
||||
uri = activeUri;
|
||||
}
|
||||
}
|
||||
|
||||
if (!uri) {
|
||||
throw new Error("No '.yaml' file selected");
|
||||
}
|
||||
|
||||
return await commands.executeCommand("sts/boot/yaml-to-props", uri.toString(), Uri.file(getTargetFile(uri.path, "properties")).toString(), shouldReplace());
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
function getTargetFile(sourcePath: string, ext: string): string {
|
||||
const dir = path.dirname(sourcePath);
|
||||
const fileName = path.basename(sourcePath);
|
||||
const filenameNoExt = path.basename(sourcePath).substring(0, fileName.length - path.extname(fileName).length);
|
||||
let targetPath = path.join(dir, `${filenameNoExt}.${ext}`);
|
||||
for (let i = 1; i < Number.MAX_SAFE_INTEGER && existsSync(targetPath); i++) {
|
||||
targetPath = path.join(dir, `${filenameNoExt}-${i}.${ext}`)
|
||||
}
|
||||
return targetPath;
|
||||
}
|
||||
|
||||
function shouldReplace(): boolean {
|
||||
return workspace.getConfiguration("spring.tools.properties").get("replace-converted-file");
|
||||
}
|
||||
|
||||
@@ -82,6 +82,16 @@
|
||||
"when": "resourceFilename == pom.xml || resourceFilename == build.gradle",
|
||||
"command": "vscode-spring-boot.rewrite.list.boot-upgrades",
|
||||
"group": "SpringBoot"
|
||||
},
|
||||
{
|
||||
"when": "editorLangId == spring-boot-properties",
|
||||
"command": "vscode-spring-boot.props-to-yaml",
|
||||
"group": "SpringBoot"
|
||||
},
|
||||
{
|
||||
"when": "editorLangId == spring-boot-properties-yaml",
|
||||
"command": "vscode-spring-boot.yaml-to-props",
|
||||
"group": "SpringBoot"
|
||||
}
|
||||
],
|
||||
"explorer/context": [
|
||||
@@ -94,6 +104,26 @@
|
||||
"when": "(resourceFilename == pom.xml || resourceFilename == build.gradle) && config.boot-java.rewrite.refactorings.on == true",
|
||||
"command": "vscode-spring-boot.rewrite.list.boot-upgrades",
|
||||
"group": "SpringBoot"
|
||||
},
|
||||
{
|
||||
"when": "resourceExtname == .properties",
|
||||
"command": "vscode-spring-boot.props-to-yaml",
|
||||
"group": "SpringBoot"
|
||||
},
|
||||
{
|
||||
"when": "resourceExtname == .yml || resourceExtname == .yaml",
|
||||
"command": "vscode-spring-boot.yaml-to-props",
|
||||
"group": "SpringBoot"
|
||||
}
|
||||
],
|
||||
"commandPalette": [
|
||||
{
|
||||
"command": "vscode-spring-boot.props-to-yaml",
|
||||
"when": "false"
|
||||
},
|
||||
{
|
||||
"command": "vscode-spring-boot.yaml-to-props",
|
||||
"when": "false"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -140,6 +170,16 @@
|
||||
"title": "Open Boot App Page URL",
|
||||
"category": "Spring Boot",
|
||||
"enablement": "never"
|
||||
},
|
||||
{
|
||||
"command": "vscode-spring-boot.props-to-yaml",
|
||||
"title": "Convert .properties to .yaml",
|
||||
"category": "Spring Boot"
|
||||
},
|
||||
{
|
||||
"command": "vscode-spring-boot.yaml-to-props",
|
||||
"title": "Convert .yaml to .properties",
|
||||
"category": "Spring Boot"
|
||||
}
|
||||
],
|
||||
"configuration": [
|
||||
@@ -245,6 +285,11 @@
|
||||
"default": true,
|
||||
"description": "Enable/Disable Spring Boot TestJars launch environment variables"
|
||||
},
|
||||
"spring.tools.properties.replace-converted-file": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "Replace converted properties file"
|
||||
},
|
||||
"spring.tools.openWith": {
|
||||
"default": "integrated",
|
||||
"type": "string",
|
||||
|
||||
Reference in New Issue
Block a user