diff --git a/.gitignore b/.gitignore index 720ce466..0f3d8184 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ src/main/java/module-info.java -src/main/java/de/bwravencl/controllerbuddy/metadata/Metadata.java +src/main/java/de/bwravencl/controllerbuddy/constants/Constants.java src/main/resources/gamecontrollerdb.txt # Created by https://www.toptal.com/developers/gitignore/api/gradle,java,jetbrains,windows,linux,macos diff --git a/build.gradle b/build.gradle index a08494c0..02dec66a 100644 --- a/build.gradle +++ b/build.gradle @@ -42,7 +42,7 @@ ext { os = DefaultNativePlatform.currentOperatingSystem moduleInfoFile = 'src/main/java/module-info.java' - metadataFile = 'src/main/java/de/bwravencl/controllerbuddy/metadata/Metadata.java' + constantsFile = 'src/main/java/de/bwravencl/controllerbuddy/constants/Constants.java' resourcesDir = 'src/main/resources' tmpDir = layout.buildDirectory.dir 'tmp' @@ -79,9 +79,9 @@ tasks.register('cleanModuleInfo') { doLast { delete moduleInfoFile } } -tasks.register('cleanMetadata') { - description = "Removes the \'$metadataFile\' source file" - doLast { delete metadataFile } +tasks.register('cleanConstants') { + description = "Removes the \'$constantsFile\' source file" + doLast { delete constantsFile } } tasks.register('cleanGameControllerDB') { @@ -89,7 +89,7 @@ tasks.register('cleanGameControllerDB') { doLast { delete gamecontrollerdbFile } } -clean.dependsOn cleanModuleInfo, cleanMetadata, cleanGameControllerDB +clean.dependsOn cleanModuleInfo, cleanConstants, cleanGameControllerDB dependencies { errorprone('com.google.errorprone:error_prone_core:2.30.0') @@ -231,7 +231,7 @@ spotless { encoding 'UTF-8' java { target 'src/main/java/de/bwravencl/**/*.java' - targetExclude moduleInfoFile, metadataFile + targetExclude moduleInfoFile, constantsFile eclipse('4.27').configFile 'spotless.eclipseformat.xml' formatAnnotations() //noinspection GroovyAccessibility @@ -308,9 +308,9 @@ downloadLicenses { } } -tasks.register('generateMetadata') { +tasks.register('generateConstants') { dependsOn 'downloadLicenses' - description = "Generates the \'$metadataFile\' source file" + description = "Generates the \'$constantsFile\' source file" doLast { def dependencyLicenseHtml = layout.buildDirectory.file('reports/license/dependency-license.html').get().getAsFile().text.replaceFirst('[\\s\\S]*', '').replaceFirst('', '').replaceFirst('

Jar

', '

File

').replaceAll('class\\s*=\\s*\'-?[_a-zA-Z]+[_a-zA-Z0-9-]*\'', '').replaceAll('>\\s*<', '><') def projectLicenseHtml = layout.projectDirectory.file('LICENSE').getAsFile().readLines().collect({ it.trim().codePoints().mapToObj({ it > 127 || '"\'<>&'.indexOf(it) != -1 ? "&#$it;" : new String(Character.toChars(it)) }).collect(Collectors.joining()) }).join '
' @@ -321,9 +321,11 @@ tasks.register('generateMetadata') { licensesHtmlStringBuilder.insert(licensesHtmlStringBuilder.lastIndexOf(''), 'SDL_GameControllerDBgamecontrollerdb.txtzlib LicenseShow license agreement') licensesHtmlStringBuilder.insert(licensesHtmlStringBuilder.lastIndexOf(''), '') - new File(metadataFile).write("""\ - package de.bwravencl.controllerbuddy.metadata;\n - public class Metadata { + def file = new File(constantsFile) + file.getParentFile().mkdirs() + file.write("""\ + package de.bwravencl.controllerbuddy.constants;\n + public class Constants { public static final String APPLICATION_NAME = "$application.applicationName"; @@ -352,8 +354,8 @@ tasks.spotlessOnlyNewline.dependsOn copyGameControllerDB tasks.spotlessXml.dependsOn copyGameControllerDB tasks.withType(JavaCompile).configureEach { - dependsOn generateModuleInfo, generateMetadata - source generateMetadata.outputs.files, sourceSets.main.java + dependsOn generateModuleInfo, generateConstants + source generateConstants.outputs.files, sourceSets.main.java options.encoding = 'UTF-8' gradle.taskGraph.whenReady { if (!it.hasTask(run)) { diff --git a/src/main/java/de/bwravencl/controllerbuddy/gui/Main.java b/src/main/java/de/bwravencl/controllerbuddy/gui/Main.java index c46d76f6..dade025f 100644 --- a/src/main/java/de/bwravencl/controllerbuddy/gui/Main.java +++ b/src/main/java/de/bwravencl/controllerbuddy/gui/Main.java @@ -24,6 +24,7 @@ import com.google.gson.JsonParseException; import com.sun.jna.Platform; import com.sun.jna.platform.unix.X11; +import de.bwravencl.controllerbuddy.constants.Constants; import de.bwravencl.controllerbuddy.gui.GuiUtils.FrameDragListener; import de.bwravencl.controllerbuddy.input.Input; import de.bwravencl.controllerbuddy.input.Input.VirtualAxis; @@ -43,14 +44,13 @@ import de.bwravencl.controllerbuddy.json.LockKeyAdapter; import de.bwravencl.controllerbuddy.json.ModeAwareTypeAdapterFactory; import de.bwravencl.controllerbuddy.json.ScanCodeAdapter; -import de.bwravencl.controllerbuddy.metadata.Metadata; -import de.bwravencl.controllerbuddy.metadata.VersionUtils; import de.bwravencl.controllerbuddy.runmode.ClientRunMode; import de.bwravencl.controllerbuddy.runmode.LocalRunMode; import de.bwravencl.controllerbuddy.runmode.OutputRunMode; import de.bwravencl.controllerbuddy.runmode.RunMode; import de.bwravencl.controllerbuddy.runmode.ServerRunMode; import de.bwravencl.controllerbuddy.util.RunnableWithDefaultExceptionHandler; +import de.bwravencl.controllerbuddy.util.VersionUtils; import java.awt.AWTException; import java.awt.BorderLayout; import java.awt.Color; @@ -351,7 +351,7 @@ public final class Main { options.addOption(OPTION_HELP, false, strings.getString("HELP_OPTION_DESCRIPTION")); SINGLE_INSTANCE_LOCK_FILE = new File( - System.getProperty("java.io.tmpdir") + File.separator + Metadata.APPLICATION_NAME + ".lock"); + System.getProperty("java.io.tmpdir") + File.separator + Constants.APPLICATION_NAME + ".lock"); JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); @@ -963,7 +963,7 @@ public void windowOpened(final WindowEvent e) { if (isWindows || isLinux) { GuiUtils.showMessageDialog(this, frame, MessageFormat.format(strings.getString("COULD_NOT_INITIALIZE_GLFW_DIALOG_TEXT"), - Metadata.APPLICATION_NAME), + Constants.APPLICATION_NAME), strings.getString("ERROR_DIALOG_TITLE"), JOptionPane.ERROR_MESSAGE); } else { GuiUtils.showMessageDialog(this, frame, strings.getString("COULD_NOT_INITIALIZE_GLFW_DIALOG_TEXT_MAC"), @@ -998,7 +998,7 @@ public void windowOpened(final WindowEvent e) { GuiUtils.showMessageDialog(this, frame, MessageFormat.format(strings.getString("ERROR_UPDATING_GAME_CONTROLLER_DB_DIALOG_TEXT"), - Metadata.APPLICATION_NAME), + Constants.APPLICATION_NAME), strings.getString("ERROR_DIALOG_TITLE"), JOptionPane.ERROR_MESSAGE); } @@ -1062,7 +1062,7 @@ public void windowOpened(final WindowEvent e) { if (isWindows || isLinux) { GuiUtils.showMessageDialog(this, frame, MessageFormat.format(strings.getString("NO_CONTROLLER_CONNECTED_DIALOG_TEXT"), - Metadata.APPLICATION_NAME), + Constants.APPLICATION_NAME), strings.getString("INFORMATION_DIALOG_TITLE"), JOptionPane.INFORMATION_MESSAGE); } else { GuiUtils.showMessageDialog(this, frame, strings.getString("NO_CONTROLLER_CONNECTED_DIALOG_TEXT_MAC"), @@ -1207,7 +1207,7 @@ private static boolean isModalDialogShowing() { } public static void main(final String[] args) { - log.log(Level.INFO, "Launching " + Metadata.APPLICATION_NAME + " " + Metadata.VERSION); + log.log(Level.INFO, "Launching " + Constants.APPLICATION_NAME + " " + Constants.VERSION); log.log(Level.INFO, "Operating System: " + System.getProperty("os.name") + " " + System.getProperty("os.version") + " " + System.getProperty("os.arch")); @@ -1222,7 +1222,7 @@ public static void main(final String[] args) { final var panel = new JPanel(); panel.setLayout(new BorderLayout(5, 5)); panel.add(new JLabel(MessageFormat.format(strings.getString("UNCAUGHT_EXCEPTION_DIALOG_TEXT"), - Metadata.APPLICATION_NAME)), BorderLayout.NORTH); + Constants.APPLICATION_NAME)), BorderLayout.NORTH); final var textArea = new JTextArea(sw.toString()); textArea.setEditable(false); final var scrollPane = new JScrollPane(textArea); @@ -1241,7 +1241,7 @@ public static void main(final String[] args) { try { final var commandLine = new DefaultParser().parse(options, args); if (commandLine.hasOption(OPTION_VERSION)) { - printCommandLineMessage(Metadata.APPLICATION_NAME + " " + Metadata.VERSION); + printCommandLineMessage(Constants.APPLICATION_NAME + " " + Constants.VERSION); return; } @@ -1287,7 +1287,7 @@ public static void main(final String[] args) { } if (continueLaunch) { - log.log(Level.WARNING, "Other " + Metadata.APPLICATION_NAME + log.log(Level.WARNING, "Other " + Constants.APPLICATION_NAME + " instance did not acknowledge invocation"); } } @@ -1314,7 +1314,7 @@ public static void main(final String[] args) { taskRunner.enterLoop(); } else { - log.log(Level.INFO, "Another " + Metadata.APPLICATION_NAME + " instance is already running"); + log.log(Level.INFO, "Another " + Constants.APPLICATION_NAME + " instance is already running"); terminate(0); } return; @@ -1326,7 +1326,7 @@ public static void main(final String[] args) { final var stringWriter = new StringWriter(); try (final var printWriter = new PrintWriter(stringWriter)) { final var helpFormatter = new HelpFormatter(); - helpFormatter.printHelp(printWriter, helpFormatter.getWidth(), Metadata.APPLICATION_NAME, null, options, + helpFormatter.printHelp(printWriter, helpFormatter.getWidth(), Constants.APPLICATION_NAME, null, options, helpFormatter.getLeftPadding(), helpFormatter.getDescPadding(), null, true); printWriter.flush(); } @@ -1357,7 +1357,7 @@ private static void printCommandLineMessage(final String message) { textArea.setEditable(false); final var imageIcon = new ImageIcon(getResourceLocation(ICON_RESOURCE_PATHS[2])); - GuiUtils.showMessageDialog(null, null, textArea, Metadata.APPLICATION_NAME, + GuiUtils.showMessageDialog(null, null, textArea, Constants.APPLICATION_NAME, JOptionPane.INFORMATION_MESSAGE, imageIcon); }); } @@ -2035,7 +2035,8 @@ private void loadProfile(final File file, final boolean skipMessageDialogs, if (!skipMessageDialogs) { GuiUtils.showMessageDialog(main, frame, MessageFormat.format(strings.getString("PROFILE_VERSION_MISMATCH_DIALOG_TEXT"), - file.getName(), strings.getString("AN_UNKNOWN"), Metadata.APPLICATION_NAME), + file.getName(), strings.getString("AN_UNKNOWN"), + Constants.APPLICATION_NAME), strings.getString("WARNING_DIALOG_TITLE"), JOptionPane.WARNING_MESSAGE); } } else { @@ -2047,7 +2048,7 @@ private void loadProfile(final File file, final boolean skipMessageDialogs, GuiUtils.showMessageDialog(main, frame, MessageFormat.format(strings.getString("PROFILE_VERSION_MISMATCH_DIALOG_TEXT"), file.getName(), strings.getString("AN_OLDER"), - Metadata.APPLICATION_NAME), + Constants.APPLICATION_NAME), strings.getString("WARNING_DIALOG_TITLE"), JOptionPane.WARNING_MESSAGE); } } else if (v > 0) { @@ -2057,7 +2058,7 @@ private void loadProfile(final File file, final boolean skipMessageDialogs, GuiUtils.showMessageDialog(main, frame, MessageFormat.format(strings.getString("PROFILE_VERSION_MISMATCH_DIALOG_TEXT"), file.getName(), strings.getString("A_NEWER"), - Metadata.APPLICATION_NAME), + Constants.APPLICATION_NAME), strings.getString("WARNING_DIALOG_TITLE"), JOptionPane.WARNING_MESSAGE); } } @@ -2110,7 +2111,7 @@ private void loadProfile(final File file, final boolean skipMessageDialogs, if (!skipMessageDialogs) { GuiUtils.showMessageDialog(main, frame, MessageFormat.format(strings.getString("COULD_NOT_LOAD_PROFILE_DIALOG_TEXT"), - Metadata.APPLICATION_NAME), + Constants.APPLICATION_NAME), strings.getString("ERROR_DIALOG_TITLE"), JOptionPane.ERROR_MESSAGE); } } @@ -2142,7 +2143,7 @@ public void newActivation(final String[] args) { } } else { EventQueue.invokeLater(() -> GuiUtils.showMessageDialog(main, frame, - MessageFormat.format(strings.getString("ALREADY_RUNNING_DIALOG_TEXT"), Metadata.APPLICATION_NAME), + MessageFormat.format(strings.getString("ALREADY_RUNNING_DIALOG_TEXT"), Constants.APPLICATION_NAME), strings.getString("ERROR_DIALOG_TITLE"), JOptionPane.ERROR_MESSAGE)); } } @@ -2615,7 +2616,7 @@ private void showTrayIconHint() { GuiUtils.showMessageDialog(null, frame, new Object[] { MessageFormat.format(strings.getString("TRAY_ICON_HINT_DIALOG_TEXT"), - Metadata.APPLICATION_NAME), imageLabel, doNotShowMessageAgainCheckbox }, + Constants.APPLICATION_NAME), imageLabel, doNotShowMessageAgainCheckbox }, strings.getString("INFORMATION_DIALOG_TITLE"), JOptionPane.INFORMATION_MESSAGE); if (doNotShowMessageAgainCheckbox.isSelected()) { @@ -2849,7 +2850,7 @@ private boolean updateGameControllerMappingsFromFile(final String path) { GuiUtils.showMessageDialog(main, frame, MessageFormat.format(strings.getString("ERROR_UPDATING_GAME_CONTROLLER_DB_DIALOG_TEXT"), - Metadata.APPLICATION_NAME), + Constants.APPLICATION_NAME), strings.getString("ERROR_DIALOG_TITLE"), JOptionPane.ERROR_MESSAGE); } @@ -3365,7 +3366,7 @@ public void updateTitleAndTooltip() { final var profileTitle = (unsavedChanges ? "*" : "") + (loadedProfile != null ? loadedProfile : strings.getString("UNTITLED")); - title = MessageFormat.format(strings.getString("MAIN_FRAME_TITLE"), profileTitle, Metadata.APPLICATION_NAME); + title = MessageFormat.format(strings.getString("MAIN_FRAME_TITLE"), profileTitle, Constants.APPLICATION_NAME); frame.setTitle(title); if (isLinux) { @@ -3629,7 +3630,7 @@ private static final class ProfileFileChooser extends AbstractProfileFileChooser private ProfileFileChooser() { super(new FileNameExtensionFilter( - MessageFormat.format(strings.getString("PROFILE_FILE_DESCRIPTION"), Metadata.APPLICATION_NAME), + MessageFormat.format(strings.getString("PROFILE_FILE_DESCRIPTION"), Constants.APPLICATION_NAME), PROFILE_FILE_EXTENSION)); setSelectedFile(new File(PROFILE_FILE_SUFFIX)); @@ -3644,7 +3645,7 @@ private static final class ShowWebsiteAction extends AbstractAction { private ShowWebsiteAction() { putValue(NAME, strings.getString("SHOW_WEBSITE_ACTION_NAME")); putValue(SHORT_DESCRIPTION, MessageFormat.format(strings.getString("SHOW_WEBSITE_ACTION_DESCRIPTION"), - Metadata.APPLICATION_NAME)); + Constants.APPLICATION_NAME)); } @Override @@ -4033,7 +4034,7 @@ private final class QuitAction extends UnsavedChangesAwareAction { private QuitAction() { putValue(NAME, strings.getString("QUIT_ACTION_NAME")); putValue(SHORT_DESCRIPTION, - MessageFormat.format(strings.getString("QUIT_ACTION_DESCRIPTION"), Metadata.APPLICATION_NAME)); + MessageFormat.format(strings.getString("QUIT_ACTION_DESCRIPTION"), Constants.APPLICATION_NAME)); } @Override @@ -4273,9 +4274,10 @@ private ShowAboutDialogAction() { public void actionPerformed(final ActionEvent e) { final var imageIcon = new ImageIcon(getResourceLocation(ICON_RESOURCE_PATHS[2])); - GuiUtils.showMessageDialog(main, frame, MessageFormat.format(strings.getString("ABOUT_DIALOG_TEXT"), - Metadata.APPLICATION_NAME, Metadata.VERSION), (String) getValue(NAME), - JOptionPane.INFORMATION_MESSAGE, imageIcon); + GuiUtils.showMessageDialog( + main, frame, MessageFormat.format(strings.getString("ABOUT_DIALOG_TEXT"), + Constants.APPLICATION_NAME, Constants.VERSION), + (String) getValue(NAME), JOptionPane.INFORMATION_MESSAGE, imageIcon); } } @@ -4336,7 +4338,7 @@ public void actionPerformed(final ActionEvent actionEvent) { } }); - editorPane.setText(Metadata.LICENSES_HTML); + editorPane.setText(Constants.LICENSES_HTML); editorPane.setCaretPosition(0); GuiUtils.showMessageDialog(main, frame, scrollPane, (String) getValue(NAME), JOptionPane.DEFAULT_OPTION); diff --git a/src/main/java/de/bwravencl/controllerbuddy/runmode/OutputRunMode.java b/src/main/java/de/bwravencl/controllerbuddy/runmode/OutputRunMode.java index f21d6f25..6fef43da 100644 --- a/src/main/java/de/bwravencl/controllerbuddy/runmode/OutputRunMode.java +++ b/src/main/java/de/bwravencl/controllerbuddy/runmode/OutputRunMode.java @@ -35,6 +35,7 @@ import com.sun.jna.platform.win32.WinUser.INPUT; import com.sun.jna.platform.win32.WinUser.KEYBDINPUT; import com.sun.jna.platform.win32.WinUser.MOUSEINPUT; +import de.bwravencl.controllerbuddy.constants.Constants; import de.bwravencl.controllerbuddy.gui.GuiUtils; import de.bwravencl.controllerbuddy.gui.Main; import de.bwravencl.controllerbuddy.input.Input; @@ -42,7 +43,6 @@ import de.bwravencl.controllerbuddy.input.LockKey; import de.bwravencl.controllerbuddy.input.ScanCode; import de.bwravencl.controllerbuddy.input.action.ToButtonAction; -import de.bwravencl.controllerbuddy.metadata.Metadata; import de.bwravencl.controllerbuddy.runmode.dbus.ScreenSaver; import de.bwravencl.controllerbuddy.runmode.dbus.ScreenSaverType; import java.awt.EventQueue; @@ -559,7 +559,7 @@ final boolean init() { } try { - joystickInputDevice = new InputDevice(Metadata.APPLICATION_NAME + " Joystick", UINPUT_VENDOR_CODE, + joystickInputDevice = new InputDevice(Constants.APPLICATION_NAME + " Joystick", UINPUT_VENDOR_CODE, UINPUT_PRODUCT_CODE); joystickInputDevice.addCapability(EventCode.ABS_X, EventCode.ABS_Y, EventCode.ABS_Z, EventCode.ABS_RX, EventCode.ABS_RY, EventCode.ABS_RZ, EventCode.ABS_THROTTLE, EventCode.ABS_RUDDER); @@ -570,14 +570,14 @@ final boolean init() { minAxisValue = Short.MIN_VALUE; maxAxisValue = Short.MAX_VALUE; - mouseInputDevice = new InputDevice(Metadata.APPLICATION_NAME + " Mouse", UINPUT_VENDOR_CODE, + mouseInputDevice = new InputDevice(Constants.APPLICATION_NAME + " Mouse", UINPUT_VENDOR_CODE, UINPUT_PRODUCT_CODE); mouseInputDevice.addCapability(EventCode.BTN_LEFT, EventCode.BTN_RIGHT, EventCode.BTN_MIDDLE, EventCode.REL_X, EventCode.REL_Y, EventCode.REL_WHEEL); mouseInputDevice.open(); log.log(Level.INFO, "Opened UINPUT mouse device: " + mouseInputDevice.toString()); - keyboardInputDevice = new InputDevice(Metadata.APPLICATION_NAME + " Keyboard", UINPUT_VENDOR_CODE, + keyboardInputDevice = new InputDevice(Constants.APPLICATION_NAME + " Keyboard", UINPUT_VENDOR_CODE, UINPUT_PRODUCT_CODE); for (final var eventCode : EventCode.values()) { if (eventCode.isKey()) { @@ -596,7 +596,7 @@ final boolean init() { dBusConnection = DBusConnectionBuilder.forSessionBus().build(); screenSaver = dBusConnection.getRemoteObject(screenSaverType.busname, screenSaverType.objectpath, screenSaverType.clazz); - screenSaverCookie = screenSaver.Inhibit(Metadata.APPLICATION_NAME, "Feeder running"); + screenSaverCookie = screenSaver.Inhibit(Constants.APPLICATION_NAME, "Feeder running"); break; } catch (final DBusException | DBusExecutionException _) { // ignore errors caused by D-Bus diff --git a/src/main/java/de/bwravencl/controllerbuddy/metadata/VersionUtils.java b/src/main/java/de/bwravencl/controllerbuddy/util/VersionUtils.java similarity index 88% rename from src/main/java/de/bwravencl/controllerbuddy/metadata/VersionUtils.java rename to src/main/java/de/bwravencl/controllerbuddy/util/VersionUtils.java index cd9eb754..54e9399d 100644 --- a/src/main/java/de/bwravencl/controllerbuddy/metadata/VersionUtils.java +++ b/src/main/java/de/bwravencl/controllerbuddy/util/VersionUtils.java @@ -14,8 +14,9 @@ * along with this program. If not, see . */ -package de.bwravencl.controllerbuddy.metadata; +package de.bwravencl.controllerbuddy.util; +import de.bwravencl.controllerbuddy.constants.Constants; import java.util.Arrays; import java.util.Optional; @@ -32,7 +33,7 @@ public static Optional compareVersions(final String otherVersion) throw return Optional.empty(); } - final var currentVersionParts = getVersionIntegerParts(Metadata.VERSION); + final var currentVersionParts = getVersionIntegerParts(Constants.VERSION); for (var i = 0; i < 2; i++) { if (otherVersionParts[i] < currentVersionParts[i]) { return Optional.of(-1); @@ -49,7 +50,7 @@ public static Optional compareVersions(final String otherVersion) throw } public static String getMajorAndMinorVersion() { - final var versionWithoutSuffix = stripHashSuffix(Metadata.VERSION); + final var versionWithoutSuffix = stripHashSuffix(Constants.VERSION); return versionWithoutSuffix.substring(0, versionWithoutSuffix.lastIndexOf('.')); }