Skip to content

Commit

Permalink
feat: Update to Wiremock 3.5.2
Browse files Browse the repository at this point in the history
adjust version endpoint
  • Loading branch information
holomekc committed Apr 1, 2024
1 parent f9f2f9a commit d76d558
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,4 @@ notes.txt
# MINE #
Guide.txt
docker
wiremock-gui-version.properties
15 changes: 14 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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);
}
}
29 changes: 22 additions & 7 deletions src/main/java/com/github/tomakehurst/wiremock/core/Version.java
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -22,19 +22,34 @@
import java.util.Properties;

public class Version {
private static final Lazy<String> version = lazy(Version::load);
private static final Lazy<EnhancedVersion> 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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -58,6 +58,7 @@ public void run(String... args) {
}
if (options.version()) {
out.println(Version.getCurrentVersion());
out.println(Version.getGuiVersion());
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
</button>
<div class="dropdown-divider"></div>
<h6 class="dropdown-header">{{ version }}</h6>
<h6 class="dropdown-header">{{ guiVersion }}</h6>
</div>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion webapp/wiremock/src/app/components/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class HomeComponent implements OnInit, OnDestroy {

currentRecordingStatus?: RecordingStatus;
version?: string;
versionTooltip?: string;
guiVersion?: string;

RecordingStatus = RecordingStatus;

Expand Down Expand Up @@ -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}`;
},
});
}
Expand Down
4 changes: 3 additions & 1 deletion webapp/wiremock/src/app/model/wiremock/version.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
12 changes: 8 additions & 4 deletions webapp/wiremock/src/app/services/wiremock.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,14 @@ export class WiremockService {
}

getVersion(): Observable<Version> {
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<Version>(WiremockService.getUrl('version'), options)
.pipe(map(v => {
return new Version(v.version, v.guiVersion);
})));
}

Expand Down

0 comments on commit d76d558

Please sign in to comment.