Skip to content

Commit

Permalink
Rename build-generated Metadata class to Constants
Browse files Browse the repository at this point in the history
  • Loading branch information
bwRavencl committed Aug 19, 2024
1 parent dbf3948 commit 066fce0
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -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
Expand Down
28 changes: 15 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -79,17 +79,17 @@ 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') {
description = "Removes the \'gamecontrollerdb.txt\' file from the \'$resourcesDir\' directory."
doLast { delete gamecontrollerdbFile }
}

clean.dependsOn cleanModuleInfo, cleanMetadata, cleanGameControllerDB
clean.dependsOn cleanModuleInfo, cleanConstants, cleanGameControllerDB

dependencies {
errorprone('com.google.errorprone:error_prone_core:2.30.0')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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('<head>[\\s\\S]*</head>', '').replaceFirst('<style>[\\s\\S]*</style>', '').replaceFirst('<h3>Jar</h3>', '<h3>File</h3>').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 '<br>'
Expand All @@ -321,9 +321,11 @@ tasks.register('generateMetadata') {
licensesHtmlStringBuilder.insert(licensesHtmlStringBuilder.lastIndexOf('</table>'), '<tr><td>SDL_GameControllerDB</td><td>gamecontrollerdb.txt</td><td>zlib License</td><td><a href=\'https://raw.githubusercontent.com/mdqinc/SDL_GameControllerDB/master/LICENSE\'>Show license agreement</a></td></tr>')
licensesHtmlStringBuilder.insert(licensesHtmlStringBuilder.lastIndexOf('</body>'), '</center>')

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";
Expand Down Expand Up @@ -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)) {
Expand Down
58 changes: 30 additions & 28 deletions src/main/java/de/bwravencl/controllerbuddy/gui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"));

Expand All @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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");
}
}
Expand All @@ -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;
Expand All @@ -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();
}
Expand Down Expand Up @@ -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);
});
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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));
}
}
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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));
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
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;
import de.bwravencl.controllerbuddy.input.KeyStroke;
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;
Expand Down Expand Up @@ -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);
Expand All @@ -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()) {
Expand All @@ -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
Expand Down
Loading

0 comments on commit 066fce0

Please sign in to comment.