From d76d558621cc32eec4db6b97b10943834db80322 Mon Sep 17 00:00:00 2001 From: holomekc <30546982+holomekc@users.noreply.github.com> Date: Mon, 1 Apr 2024 11:23:47 +0200 Subject: [PATCH] feat: Update to Wiremock 3.5.2 adjust version endpoint --- .gitignore | 1 + build.gradle | 15 +++++++++- .../wiremock/admin/model/VersionResult.java | 11 +++++-- .../wiremock/admin/tasks/GetVersionTask.java | 4 +-- .../tomakehurst/wiremock/core/Version.java | 29 ++++++++++++++----- .../standalone/CommandLineOptions.java | 3 ++ .../standalone/WireMockServerRunner.java | 3 +- .../app/components/home/home.component.html | 1 + .../src/app/components/home/home.component.ts | 3 +- .../src/app/model/wiremock/version.ts | 4 ++- .../src/app/services/wiremock.service.ts | 12 +++++--- 11 files changed, 67 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 2165313e71..6d6d07128c 100644 --- a/.gitignore +++ b/.gitignore @@ -73,3 +73,4 @@ notes.txt # MINE # Guide.txt docker +wiremock-gui-version.properties diff --git a/build.gradle b/build.gradle index 038a083700..dd857586e6 100644 --- a/build.gradle +++ b/build.gradle @@ -461,8 +461,21 @@ task generateWebapp(type: NpmTask) { args = ['run', 'prod'] } -task finalizeWebapp(type: Copy) { +task versionTxt() { dependsOn generateWebapp + doLast { + def wiremockVersionProps = new Properties() + wiremockVersionProps.load(new FileInputStream(projectDir.getAbsolutePath() + "/src/main/resources/version.properties")) + def wiremockVersion = wiremockVersionProps.getProperty("version") + new File(projectDir.getAbsolutePath() + "/src/main/resources", "wiremock-gui-version.properties").text = """# version file +gui-version=$version +version=$wiremockVersion +""" + } +} + +task finalizeWebapp(type: Copy) { + dependsOn versionTxt // Because of: https://github.com/angular/angular-cli/issues/26304 // we need to copy some things around. from 'webapp/wiremock/dist/browser' diff --git a/src/main/java/com/github/tomakehurst/wiremock/admin/model/VersionResult.java b/src/main/java/com/github/tomakehurst/wiremock/admin/model/VersionResult.java index ed3e2c75cd..e79a2fdb94 100644 --- a/src/main/java/com/github/tomakehurst/wiremock/admin/model/VersionResult.java +++ b/src/main/java/com/github/tomakehurst/wiremock/admin/model/VersionResult.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Thomas Akehurst + * Copyright (C) 2023-2024 Thomas Akehurst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,11 +18,18 @@ public class VersionResult { private final String version; - public VersionResult(String version) { + private final String guiVersion; + + public VersionResult(String version, String guiVersion) { this.version = version; + this.guiVersion = guiVersion; } public String getVersion() { return version; } + + public String getGuiVersion() { + return guiVersion; + } } diff --git a/src/main/java/com/github/tomakehurst/wiremock/admin/tasks/GetVersionTask.java b/src/main/java/com/github/tomakehurst/wiremock/admin/tasks/GetVersionTask.java index f9aaa4d55e..2066f24697 100644 --- a/src/main/java/com/github/tomakehurst/wiremock/admin/tasks/GetVersionTask.java +++ b/src/main/java/com/github/tomakehurst/wiremock/admin/tasks/GetVersionTask.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Thomas Akehurst + * Copyright (C) 2023-2024 Thomas Akehurst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,7 +44,7 @@ public ResponseDefinition execute(Admin admin, ServeEvent serveEvent, PathParams .build(); } - var versionResult = new VersionResult(Version.getCurrentVersion()); + var versionResult = new VersionResult(Version.getCurrentVersion(), Version.getGuiVersion()); return jsonResponse(versionResult); } } diff --git a/src/main/java/com/github/tomakehurst/wiremock/core/Version.java b/src/main/java/com/github/tomakehurst/wiremock/core/Version.java index 0ff6996620..26da5b793b 100644 --- a/src/main/java/com/github/tomakehurst/wiremock/core/Version.java +++ b/src/main/java/com/github/tomakehurst/wiremock/core/Version.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Thomas Akehurst + * Copyright (C) 2023-2024 Thomas Akehurst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,19 +22,34 @@ import java.util.Properties; public class Version { - private static final Lazy version = lazy(Version::load); + private static final Lazy version = lazy(Version::load); public static String getCurrentVersion() { - return version.get(); + return version.get().version; } - private static String load() { + public static String getGuiVersion() { + return version.get().guiVersion; + } + + private static EnhancedVersion load() { try { Properties properties = new Properties(); - properties.load(Version.class.getResourceAsStream("/version.properties")); - return properties.getProperty("version"); + properties.load(Version.class.getResourceAsStream("/wiremock-gui-version.properties")); + return new EnhancedVersion( + properties.getProperty("version"), properties.getProperty("gui-version")); } catch (NullPointerException | IOException e) { - return "unknown"; + return new EnhancedVersion("unknown", "unknown"); + } + } + + private static class EnhancedVersion { + String version; + String guiVersion; + + public EnhancedVersion(final String version, final String guiVersion) { + this.version = version; + this.guiVersion = guiVersion; } } } diff --git a/src/main/java/com/github/tomakehurst/wiremock/standalone/CommandLineOptions.java b/src/main/java/com/github/tomakehurst/wiremock/standalone/CommandLineOptions.java index 03f8dae18b..a969c94e7a 100644 --- a/src/main/java/com/github/tomakehurst/wiremock/standalone/CommandLineOptions.java +++ b/src/main/java/com/github/tomakehurst/wiremock/standalone/CommandLineOptions.java @@ -61,6 +61,7 @@ public class CommandLineOptions implements Options { private static final String HELP = "help"; private static final String VERSION = "version"; + private static final String GUI_VERSION = "gui-version"; private static final String RECORD_MAPPINGS = "record-mappings"; private static final String MATCH_HEADERS = "match-headers"; private static final String PROXY_ALL = "proxy-all"; @@ -785,6 +786,8 @@ public String toString() { map.put(VERSION, Version.getCurrentVersion()); + map.put(GUI_VERSION, Version.getGuiVersion()); + if (actualHttpPort != null) { map.put(PORT, actualHttpPort); } diff --git a/src/main/java/com/github/tomakehurst/wiremock/standalone/WireMockServerRunner.java b/src/main/java/com/github/tomakehurst/wiremock/standalone/WireMockServerRunner.java index 5b84641638..07003d6bee 100644 --- a/src/main/java/com/github/tomakehurst/wiremock/standalone/WireMockServerRunner.java +++ b/src/main/java/com/github/tomakehurst/wiremock/standalone/WireMockServerRunner.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2023 Thomas Akehurst + * Copyright (C) 2011-2024 Thomas Akehurst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -58,6 +58,7 @@ public void run(String... args) { } if (options.version()) { out.println(Version.getCurrentVersion()); + out.println(Version.getGuiVersion()); return; } diff --git a/webapp/wiremock/src/app/components/home/home.component.html b/webapp/wiremock/src/app/components/home/home.component.html index 20dabce5b9..7fc09fa4f8 100644 --- a/webapp/wiremock/src/app/components/home/home.component.html +++ b/webapp/wiremock/src/app/components/home/home.component.html @@ -114,6 +114,7 @@ + diff --git a/webapp/wiremock/src/app/components/home/home.component.ts b/webapp/wiremock/src/app/components/home/home.component.ts index a43b0e8bf2..ae622e9c7c 100644 --- a/webapp/wiremock/src/app/components/home/home.component.ts +++ b/webapp/wiremock/src/app/components/home/home.component.ts @@ -30,7 +30,7 @@ export class HomeComponent implements OnInit, OnDestroy { currentRecordingStatus?: RecordingStatus; version?: string; - versionTooltip?: string; + guiVersion?: string; RecordingStatus = RecordingStatus; @@ -83,6 +83,7 @@ export class HomeComponent implements OnInit, OnDestroy { this.wiremockService.getVersion().subscribe({ next: version => { this.version = `Version: ${version.version}`; + this.guiVersion = `GUI Version: ${version.guiVersion}`; }, }); } diff --git a/webapp/wiremock/src/app/model/wiremock/version.ts b/webapp/wiremock/src/app/model/wiremock/version.ts index 8740ae545f..d07c779b6f 100644 --- a/webapp/wiremock/src/app/model/wiremock/version.ts +++ b/webapp/wiremock/src/app/model/wiremock/version.ts @@ -1,7 +1,9 @@ export class Version { version!: string; + guiVersion!: string; - constructor(version: string) { + constructor(version: string, guiVersion: string) { this.version = version; + this.guiVersion = guiVersion; } } diff --git a/webapp/wiremock/src/app/services/wiremock.service.ts b/webapp/wiremock/src/app/services/wiremock.service.ts index 1513cbe1ff..c1d92b3d3a 100644 --- a/webapp/wiremock/src/app/services/wiremock.service.ts +++ b/webapp/wiremock/src/app/services/wiremock.service.ts @@ -122,10 +122,14 @@ export class WiremockService { } getVersion(): Observable { - return this.defaultPipe(this.http.get(WiremockService.getUrl('version'), { - responseType: 'text' - }).pipe(map(v => { - return new Version(v); + const options = { + headers: { + "Accept": "application/json" + } + }; + return this.defaultPipe(this.http.get(WiremockService.getUrl('version'), options) + .pipe(map(v => { + return new Version(v.version, v.guiVersion); }))); }