diff --git a/build.gradle b/build.gradle index 03ea066fec..598a9bf1bf 100644 --- a/build.gradle +++ b/build.gradle @@ -443,19 +443,8 @@ task generateWebapp(type: NpmTask) { args = ['run', 'prod'] } -task versionTxt() { - dependsOn generateWebapp - doLast { - new File(projectDir.getAbsolutePath() + "/src/main/resources", "version.json").text = """{ - "buildTime": "${new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date())}", - "version": "$version" -} -""" - } -} - task finalizeWebapp(type: Copy) { - dependsOn versionTxt + dependsOn generateWebapp // 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/tasks/VersionTask.java b/src/main/java/com/github/tomakehurst/wiremock/admin/tasks/VersionTask.java deleted file mode 100644 index ed50e597c2..0000000000 --- a/src/main/java/com/github/tomakehurst/wiremock/admin/tasks/VersionTask.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2023 Thomas Akehurst - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.github.tomakehurst.wiremock.admin.tasks; - -import static com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder.responseDefinition; -import static java.net.HttpURLConnection.HTTP_OK; - -import com.github.tomakehurst.wiremock.admin.AdminTask; -import com.github.tomakehurst.wiremock.admin.model.VersionResult; -import com.github.tomakehurst.wiremock.common.Json; -import com.github.tomakehurst.wiremock.common.url.PathParams; -import com.github.tomakehurst.wiremock.core.Admin; -import com.github.tomakehurst.wiremock.http.ResponseDefinition; -import com.github.tomakehurst.wiremock.stubbing.ServeEvent; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - -public class VersionTask implements AdminTask { - - private static VersionResult versionResult; - - static { - try { - InputStream inputStream = VersionTask.class.getResourceAsStream("/version.json"); - String json = readFromInputStream(inputStream); - versionResult = Json.read(json, VersionResult.class); - } catch (IOException e) { - versionResult = new VersionResult("unknown", "unknown"); - } - } - - @Override - public ResponseDefinition execute(Admin admin, ServeEvent serveEvent, PathParams pathParams) { - - return responseDefinition() - .withStatus(HTTP_OK) - .withStatusMessage("Wiremock is ok") - .withBody(Json.write(versionResult)) - .withHeader("Content-Type", "application/json") - .build(); - } - - private static String readFromInputStream(InputStream inputStream) throws IOException { - StringBuilder resultStringBuilder = new StringBuilder(); - try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) { - String line; - while ((line = br.readLine()) != null) { - resultStringBuilder.append(line).append("\n"); - } - } - return resultStringBuilder.toString(); - } -} diff --git a/webapp/wiremock/src/app/components/home/home.component.html b/webapp/wiremock/src/app/components/home/home.component.html index cd6f983093..20dabce5b9 100644 --- a/webapp/wiremock/src/app/components/home/home.component.html +++ b/webapp/wiremock/src/app/components/home/home.component.html @@ -113,15 +113,10 @@ Shutdown - + - -
-  {{ versionTooltip }}
-  
-
diff --git a/webapp/wiremock/src/app/components/home/home.component.ts b/webapp/wiremock/src/app/components/home/home.component.ts index 4039e81664..f692c558e5 100644 --- a/webapp/wiremock/src/app/components/home/home.component.ts +++ b/webapp/wiremock/src/app/components/home/home.component.ts @@ -30,7 +30,6 @@ export class HomeComponent implements OnInit, OnDestroy { currentRecordingStatus?: RecordingStatus; version?: string; - versionTooltip?: string; RecordingStatus = RecordingStatus; @@ -83,10 +82,6 @@ export class HomeComponent implements OnInit, OnDestroy { this.wiremockService.getVersion().subscribe({ next: version => { this.version = `Version: ${version.version}`; - this.versionTooltip = `WireMock: ${version.version.substring( - 0, - version.version.lastIndexOf(".") - )}\nBuildTime: ${version.buildTime}`; }, }); } diff --git a/webapp/wiremock/src/app/model/wiremock/version.ts b/webapp/wiremock/src/app/model/wiremock/version.ts index 68cf71f099..23ce1cb85f 100644 --- a/webapp/wiremock/src/app/model/wiremock/version.ts +++ b/webapp/wiremock/src/app/model/wiremock/version.ts @@ -1,4 +1,3 @@ export class Version { version!: string; - buildTime!: string; } diff --git a/webapp/wiremock/src/app/services/wiremock.service.ts b/webapp/wiremock/src/app/services/wiremock.service.ts index e5468e9a9e..b10e739984 100644 --- a/webapp/wiremock/src/app/services/wiremock.service.ts +++ b/webapp/wiremock/src/app/services/wiremock.service.ts @@ -122,7 +122,19 @@ export class WiremockService { } getVersion(): Observable { - return this.defaultPipe(this.http.get(WiremockService.getUrl("version"))); + return this.defaultPipe( + this.http + .get(WiremockService.getUrl("version"), { + responseType: "text", + }) + .pipe( + map(v => { + const version = new Version(); + version.version = v; + return version; + }) + ) + ); } shutdown(): Observable { @@ -213,7 +225,7 @@ export class WiremockService { if (error.error instanceof ErrorEvent) { console.error("An error occurred:", error.error.message); } else { - console.error("An error occurred:", error); + console.error("An error occurred:", JSON.stringify(error)); } } console.log(`Attempt ${count}: retrying in ${count * delay}ms`);