From bc33640c98f75b23adf5e0ea12c0a949c2a7de2d Mon Sep 17 00:00:00 2001 From: "Michael N. Lipp" Date: Mon, 24 Feb 2025 18:09:14 +0100 Subject: [PATCH] Avoid duplicate constants. --- .../jdrupes/vmoperator/common/Constants.java | 19 ++++++++++++++++--- .../jdrupes/vmoperator/manager/Constants.java | 16 ---------------- .../runner/qemu/DisplayController.java | 12 ++++++------ 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/org.jdrupes.vmoperator.common/src/org/jdrupes/vmoperator/common/Constants.java b/org.jdrupes.vmoperator.common/src/org/jdrupes/vmoperator/common/Constants.java index 5837264..9bfba8d 100644 --- a/org.jdrupes.vmoperator.common/src/org/jdrupes/vmoperator/common/Constants.java +++ b/org.jdrupes.vmoperator.common/src/org/jdrupes/vmoperator/common/Constants.java @@ -27,9 +27,6 @@ public class Constants { /** The Constant APP_NAME. */ public static final String APP_NAME = "vm-runner"; - /** The Constant COMP_DISPLAY_SECRETS. */ - public static final String COMP_DISPLAY_SECRET = "display-secret"; - /** The Constant VM_OP_NAME. */ public static final String VM_OP_NAME = "vm-operator"; @@ -41,4 +38,20 @@ public class Constants { /** The Constant VM_OP_KIND_VM_POOL. */ public static final String VM_OP_KIND_VM_POOL = "VmPool"; + + /** The Constant COMP_DISPLAY_SECRETS. */ + public static final String COMP_DISPLAY_SECRET = "display-secret"; + + /** The Constant DATA_DISPLAY_PASSWORD. */ + public static final String DATA_DISPLAY_PASSWORD = "display-password"; + + /** The Constant DATA_PASSWORD_EXPIRY. */ + public static final String DATA_PASSWORD_EXPIRY = "password-expiry"; + + /** The Constant DATA_DISPLAY_USER. */ + public static final String DATA_DISPLAY_USER = "display-user"; + + /** The Constant DATA_DISPLAY_LOGIN. */ + public static final String DATA_DISPLAY_LOGIN = "login-user"; + } diff --git a/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/Constants.java b/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/Constants.java index f12b512..c5c8528 100644 --- a/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/Constants.java +++ b/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/Constants.java @@ -18,28 +18,12 @@ package org.jdrupes.vmoperator.manager; -// TODO: Auto-generated Javadoc /** * Some constants. */ @SuppressWarnings("PMD.DataClass") public class Constants extends org.jdrupes.vmoperator.common.Constants { - /** The Constant COMP_DISPLAY_SECRET. */ - public static final String COMP_DISPLAY_SECRET = "display-secret"; - - /** The Constant DATA_DISPLAY_PASSWORD. */ - public static final String DATA_DISPLAY_PASSWORD = "display-password"; - - /** The Constant DATA_PASSWORD_EXPIRY. */ - public static final String DATA_PASSWORD_EXPIRY = "password-expiry"; - - /** The Constant DATA_DISPLAY_USER. */ - public static final String DATA_DISPLAY_USER = "display-user"; - - /** The Constant DATA_DISPLAY_LOGIN. */ - public static final String DATA_DISPLAY_LOGIN = "login-user"; - /** The Constant STATE_RUNNING. */ public static final String STATE_RUNNING = "Running"; diff --git a/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/DisplayController.java b/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/DisplayController.java index 1f9833c..fab11b1 100644 --- a/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/DisplayController.java +++ b/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/DisplayController.java @@ -23,6 +23,8 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Objects; import java.util.logging.Level; +import static org.jdrupes.vmoperator.common.Constants.DATA_DISPLAY_PASSWORD; +import static org.jdrupes.vmoperator.common.Constants.DATA_PASSWORD_EXPIRY; import org.jdrupes.vmoperator.runner.qemu.commands.QmpSetDisplayPassword; import org.jdrupes.vmoperator.runner.qemu.commands.QmpSetPasswordExpiry; import org.jdrupes.vmoperator.runner.qemu.events.ConfigureQemu; @@ -40,8 +42,6 @@ import org.jgrapes.util.events.WatchFile; @SuppressWarnings("PMD.DataflowAnomalyAnalysis") public class DisplayController extends Component { - public static final String DISPLAY_PASSWORD_FILE = "display-password"; - public static final String PASSWORD_EXPIRY_FILE = "password-expiry"; private String currentPassword; private String protocol; private final Path configDir; @@ -57,7 +57,7 @@ public class DisplayController extends Component { public DisplayController(Channel componentChannel, Path configDir) { super(componentChannel); this.configDir = configDir; - fire(new WatchFile(configDir.resolve(DISPLAY_PASSWORD_FILE))); + fire(new WatchFile(configDir.resolve(DATA_DISPLAY_PASSWORD))); } /** @@ -83,7 +83,7 @@ public class DisplayController extends Component { @Handler @SuppressWarnings("PMD.EmptyCatchBlock") public void onFileChanged(FileChanged event) { - if (event.path().equals(configDir.resolve(DISPLAY_PASSWORD_FILE))) { + if (event.path().equals(configDir.resolve(DATA_DISPLAY_PASSWORD))) { updatePassword(); } } @@ -100,7 +100,7 @@ public class DisplayController extends Component { private boolean setDisplayPassword() { String password; - Path dpPath = configDir.resolve(DISPLAY_PASSWORD_FILE); + Path dpPath = configDir.resolve(DATA_DISPLAY_PASSWORD); if (dpPath.toFile().canRead()) { logger.finer(() -> "Found display password"); try { @@ -125,7 +125,7 @@ public class DisplayController extends Component { } private void setPasswordExpiry() { - Path pePath = configDir.resolve(PASSWORD_EXPIRY_FILE); + Path pePath = configDir.resolve(DATA_PASSWORD_EXPIRY); if (!pePath.toFile().canRead()) { return; }