From af40040e0b1126d894487bfc1d701599eb1aaae4 Mon Sep 17 00:00:00 2001 From: David M Date: Fri, 30 Aug 2024 14:53:20 +0200 Subject: [PATCH] Updated maven plugins; Tighten PMD rules; Removed usage of 'var' keyword --- README.md | 3 ++ .../dbus/messages/MessageFactory.java | 2 +- .../ExportObjectWithProperties.java | 2 +- .../signal/PropertiesChangedSignalSample.java | 2 +- .../base/ReceivingServiceTest.java | 2 +- .../dbus/test/DBusConnectionTest.java | 2 +- .../dbus/test/ExportNestedTest.java | 8 +++--- .../dbus/test/MarshallingTest.java | 2 +- .../freedesktop/dbus/test/VariantTest.java | 8 +++--- .../dbus/types/VariantBuilderTest.java | 4 +-- .../test/java/sample/issue/Issue244Test.java | 7 +++-- .../utils/generator/ClassBuilderInfo.java | 4 +-- .../generator/InterfaceCodeGenerator.java | 1 + pom.xml | 28 +++++++++---------- src/main/resources/pmd_rules.xml | 1 + 15 files changed, 41 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 1205b3ef..b5e2cf7b 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,9 @@ The library will remain open source and MIT licensed and can still be used, fork - Fixed printed version information in `InterfaceCodeGenerator` was always `null` - Smaller code cleanup in `InterfaceCodeGenerator` to prevent creating multiple empty lines - Dependency updates + - Added support for `EmitsChangedSignal` ([PR#267](https://github.com/hypfvieh/dbus-java/issues/267)), thanks to [GeVa2072](https://github.com/GeVa2072) + - Tighten PMD rules to disallow usage of `var` keyword + - Updated Maven plugins ##### Changes in 5.1.0 (2024-08-01): - Use Junit BOM thanks to [spannm](https://github.com/spannm) ([PR#248](https://github.com/hypfvieh/dbus-java/issues/248)) diff --git a/dbus-java-core/src/main/java/org/freedesktop/dbus/messages/MessageFactory.java b/dbus-java-core/src/main/java/org/freedesktop/dbus/messages/MessageFactory.java index d6448988..1aa54298 100644 --- a/dbus-java-core/src/main/java/org/freedesktop/dbus/messages/MessageFactory.java +++ b/dbus-java-core/src/main/java/org/freedesktop/dbus/messages/MessageFactory.java @@ -28,7 +28,7 @@ public DBusSignal createSignal(String _source, String _path, String _iface, Stri } public DBusSignal createSignal(String _objectPath, Object... _args) throws DBusException { - var sig = new DBusSignal(_objectPath, _args); + DBusSignal sig = new DBusSignal(_objectPath, _args); sig.updateEndianess(endianess); return sig; } diff --git a/dbus-java-examples/src/main/java/com/github/hypfvieh/dbus/examples/properties/ExportObjectWithProperties.java b/dbus-java-examples/src/main/java/com/github/hypfvieh/dbus/examples/properties/ExportObjectWithProperties.java index 745b5542..16de6b4b 100644 --- a/dbus-java-examples/src/main/java/com/github/hypfvieh/dbus/examples/properties/ExportObjectWithProperties.java +++ b/dbus-java-examples/src/main/java/com/github/hypfvieh/dbus/examples/properties/ExportObjectWithProperties.java @@ -20,7 +20,7 @@ public final class ExportObjectWithProperties { private ExportObjectWithProperties() {} public static void main(String[] _args) throws Exception { - try (var conn = DBusConnectionBuilder.forSessionBus().withShared(false).build()) { + try (DBusConnection conn = DBusConnectionBuilder.forSessionBus().withShared(false).build()) { // create object ObjectWithProperties obj = new ObjectWithProperties(); obj.setMyProperty("My property value"); diff --git a/dbus-java-examples/src/main/java/com/github/hypfvieh/dbus/examples/signal/PropertiesChangedSignalSample.java b/dbus-java-examples/src/main/java/com/github/hypfvieh/dbus/examples/signal/PropertiesChangedSignalSample.java index d83bcd15..1b57071d 100644 --- a/dbus-java-examples/src/main/java/com/github/hypfvieh/dbus/examples/signal/PropertiesChangedSignalSample.java +++ b/dbus-java-examples/src/main/java/com/github/hypfvieh/dbus/examples/signal/PropertiesChangedSignalSample.java @@ -20,7 +20,7 @@ public static void main(String[] _args) throws Exception { // Open connection to the system bus. try (DBusConnection connection = DBusConnectionBuilder.forSystemBus().build()) { // Add a signal handler. - final var token = connection.addSigHandler(PropertiesChanged.class, new PropChangedHandler()); + final AutoCloseable token = connection.addSigHandler(PropertiesChanged.class, new PropChangedHandler()); // Pause to see events written to stdout (your code would differ). System.out.println("sleeping"); diff --git a/dbus-java-tests/src/test/java/org/freedesktop/dbus/connections/base/ReceivingServiceTest.java b/dbus-java-tests/src/test/java/org/freedesktop/dbus/connections/base/ReceivingServiceTest.java index b26ce9f5..3ba51afb 100644 --- a/dbus-java-tests/src/test/java/org/freedesktop/dbus/connections/base/ReceivingServiceTest.java +++ b/dbus-java-tests/src/test/java/org/freedesktop/dbus/connections/base/ReceivingServiceTest.java @@ -182,7 +182,7 @@ ExecutorService getExecutor(ExecutorNames _executor) { @Test void testExecutorShutdownOrTerminated() { ReceivingServiceConfig build = new ReceivingServiceConfigBuilder<>(null).withRetryHandler(null).build(); - var exec = new NoOpExecutorService(); + NoOpExecutorService exec = new NoOpExecutorService(); exec.shutdown = true; ReceivingService service = new ReceivingService("", build) { diff --git a/dbus-java-tests/src/test/java/org/freedesktop/dbus/test/DBusConnectionTest.java b/dbus-java-tests/src/test/java/org/freedesktop/dbus/test/DBusConnectionTest.java index ca0a88b5..4b951329 100644 --- a/dbus-java-tests/src/test/java/org/freedesktop/dbus/test/DBusConnectionTest.java +++ b/dbus-java-tests/src/test/java/org/freedesktop/dbus/test/DBusConnectionTest.java @@ -37,7 +37,7 @@ public void testBusnamesShouldBeAutoReleasedOnCloseOfNonSharedConnection() throw */ @Test public void testExportOnlyAllPublic() throws Exception { - try (var conn = DBusConnectionBuilder.forSessionBus().withShared(false).build()) { + try (DBusConnection conn = DBusConnectionBuilder.forSessionBus().withShared(false).build()) { ExportedObj exportedObj = new ExportedObj(); conn.requestBusName(getClass().getName()); assertThrows(InvalidInterfaceSignature.class, () -> conn.exportObject(exportedObj)); diff --git a/dbus-java-tests/src/test/java/org/freedesktop/dbus/test/ExportNestedTest.java b/dbus-java-tests/src/test/java/org/freedesktop/dbus/test/ExportNestedTest.java index f38c1899..c930ced6 100644 --- a/dbus-java-tests/src/test/java/org/freedesktop/dbus/test/ExportNestedTest.java +++ b/dbus-java-tests/src/test/java/org/freedesktop/dbus/test/ExportNestedTest.java @@ -17,15 +17,15 @@ public class ExportNestedTest extends AbstractDBusDaemonBaseTest { @Test public void testExportNested() throws IOException, DBusException { try (DBusConnection conn = DBusConnectionBuilder.forSessionBus().build()) { - var part1 = new MyObjectPart(); + MyObjectPart part1 = new MyObjectPart(); part1.setVal1("ABC"); part1.setVal2("123"); - var part2 = new MyObjectPart(); + MyObjectPart part2 = new MyObjectPart(); part2.setVal1("DEF"); part2.setVal2("456"); - var myIface = new MyObject(); + MyObject myIface = new MyObject(); myIface.getParts().addAll(Arrays.asList(part1, part2)); conn.requestBusName("com.acme"); @@ -34,7 +34,7 @@ public void testExportNested() throws IOException, DBusException { conn.exportObject(myIface); try (DBusConnection innerConn = DBusConnectionBuilder.forSessionBus().build()) { - var myObject = innerConn.getRemoteObject("com.acme", "/com/acme/MyObject", MyInterface.class); + MyInterface myObject = innerConn.getRemoteObject("com.acme", "/com/acme/MyObject", MyInterface.class); // hello from 'parent' object assertEquals("Hello!", myObject.sayHello()); diff --git a/dbus-java-tests/src/test/java/org/freedesktop/dbus/test/MarshallingTest.java b/dbus-java-tests/src/test/java/org/freedesktop/dbus/test/MarshallingTest.java index 710d9577..eb5a234d 100644 --- a/dbus-java-tests/src/test/java/org/freedesktop/dbus/test/MarshallingTest.java +++ b/dbus-java-tests/src/test/java/org/freedesktop/dbus/test/MarshallingTest.java @@ -133,7 +133,7 @@ void testDeserializeParametersWithTuple() throws Exception { @Test void testDeserializeParametersVariant() throws Exception { - var varList = new Variant<>(List.of(1, 2, 3), "ai"); + Variant> varList = new Variant<>(List.of(1, 2, 3), "ai"); Type[] types = new Type[] {varList.getType()}; Object[] convertParameters = Marshalling.convertParameters(new Object[] {varList}, types, new String[] {"v"}, null); diff --git a/dbus-java-tests/src/test/java/org/freedesktop/dbus/test/VariantTest.java b/dbus-java-tests/src/test/java/org/freedesktop/dbus/test/VariantTest.java index 1d15817f..fe495480 100644 --- a/dbus-java-tests/src/test/java/org/freedesktop/dbus/test/VariantTest.java +++ b/dbus-java-tests/src/test/java/org/freedesktop/dbus/test/VariantTest.java @@ -103,15 +103,15 @@ void testVariantSerializeDeserialize(VariantData _data) throws DBusException, IO Path unixPath = Path.of(System.getProperty("java.io.tmpdir"), getShortTestMethodName()); Files.deleteIfExists(unixPath); - var usx = UnixDomainSocketAddress.of(unixPath); + UnixDomainSocketAddress usx = UnixDomainSocketAddress.of(unixPath); CountDownLatch readWait = new CountDownLatch(1); CountDownLatch writeWait = new CountDownLatch(1); AtomicReference ref = new AtomicReference<>(); Thread thread = new Thread(() -> { - try (var chan = ServerSocketChannel.open(StandardProtocolFamily.UNIX).bind(usx); - var out = new OutputStreamMessageWriter(chan.accept())) { + try (ServerSocketChannel chan = ServerSocketChannel.open(StandardProtocolFamily.UNIX).bind(usx); + OutputStreamMessageWriter out = new OutputStreamMessageWriter(chan.accept())) { logger.debug("Sending --> {}", methodReturn); @@ -126,7 +126,7 @@ void testVariantSerializeDeserialize(VariantData _data) throws DBusException, IO thread.start(); Thread.sleep(300); - try (var chan = SocketChannel.open(usx); var in = new InputStreamMessageReader(chan)) { + try (SocketChannel chan = SocketChannel.open(usx); InputStreamMessageReader in = new InputStreamMessageReader(chan)) { writeWait.await(10, TimeUnit.SECONDS); Message message = in.readMessage(); logger.debug("Receiving <-- {}", message); diff --git a/dbus-java-tests/src/test/java/org/freedesktop/dbus/types/VariantBuilderTest.java b/dbus-java-tests/src/test/java/org/freedesktop/dbus/types/VariantBuilderTest.java index cf0bc9b6..cb7f64c5 100644 --- a/dbus-java-tests/src/test/java/org/freedesktop/dbus/types/VariantBuilderTest.java +++ b/dbus-java-tests/src/test/java/org/freedesktop/dbus/types/VariantBuilderTest.java @@ -40,9 +40,9 @@ void testBuilder() { public static class VbStruct extends Struct { @Position(0) - private String val1; + private final String val1; @Position(1) - private boolean val2; + private final boolean val2; public VbStruct(String _val1, boolean _val2) { super(); diff --git a/dbus-java-tests/src/test/java/sample/issue/Issue244Test.java b/dbus-java-tests/src/test/java/sample/issue/Issue244Test.java index eb5cea0a..f48df4de 100644 --- a/dbus-java-tests/src/test/java/sample/issue/Issue244Test.java +++ b/dbus-java-tests/src/test/java/sample/issue/Issue244Test.java @@ -2,6 +2,7 @@ import org.freedesktop.dbus.bin.EmbeddedDBusDaemon; import org.freedesktop.dbus.connections.BusAddress; +import org.freedesktop.dbus.connections.impl.DBusConnection; import org.freedesktop.dbus.connections.impl.DBusConnectionBuilder; import org.freedesktop.dbus.connections.transports.TransportBuilder; import org.freedesktop.dbus.test.AbstractBaseTest; @@ -24,9 +25,9 @@ public void testSharedConnection() { logger.info("Creating {} based DBus daemon on address {}", busType, serverAddress); - try (var edbus = new EmbeddedDBusDaemon(serverAddress)) { + try (EmbeddedDBusDaemon edbus = new EmbeddedDBusDaemon(serverAddress)) { edbus.startInBackgroundAndWait(MAX_WAIT); - try (var con = DBusConnectionBuilder.forAddress(clientAddress).build()) { + try (DBusConnection con = DBusConnectionBuilder.forAddress(clientAddress).build()) { assertTrue(con.isConnected(), "First connection attempt must work"); edbus.close(); // terminate daemon to enforce disconnect Thread.sleep(1000L); @@ -35,7 +36,7 @@ public void testSharedConnection() { // restart daemon and retry edbus.startInBackgroundAndWait(MAX_WAIT); - try (var con = DBusConnectionBuilder.forAddress(clientAddress).build()) { + try (DBusConnection con = DBusConnectionBuilder.forAddress(clientAddress).build()) { assertTrue(con.isConnected(), "Second connection attempt must work"); edbus.close(); // terminate daemon to enforce disconnect Thread.sleep(1000L); diff --git a/dbus-java-utils/src/main/java/org/freedesktop/dbus/utils/generator/ClassBuilderInfo.java b/dbus-java-utils/src/main/java/org/freedesktop/dbus/utils/generator/ClassBuilderInfo.java index b04c5e02..05b61af1 100644 --- a/dbus-java-utils/src/main/java/org/freedesktop/dbus/utils/generator/ClassBuilderInfo.java +++ b/dbus-java-utils/src/main/java/org/freedesktop/dbus/utils/generator/ClassBuilderInfo.java @@ -459,8 +459,8 @@ public List generateCode(boolean _isInterface, String _argumentPrefix, S } String publicModifier = !_isInterface ? "public " : ""; - String mthReturnType = (getReturnType() == null ? "void" - : TypeConverter.getProperJavaClass(getReturnType(), _allImports)); + String mthReturnType = getReturnType() == null ? "void" + : TypeConverter.getProperJavaClass(getReturnType(), _allImports); String args = ""; if (!getArguments().isEmpty()) { args += getArguments().stream() diff --git a/dbus-java-utils/src/main/java/org/freedesktop/dbus/utils/generator/InterfaceCodeGenerator.java b/dbus-java-utils/src/main/java/org/freedesktop/dbus/utils/generator/InterfaceCodeGenerator.java index 29939aa8..0965f47a 100644 --- a/dbus-java-utils/src/main/java/org/freedesktop/dbus/utils/generator/InterfaceCodeGenerator.java +++ b/dbus-java-utils/src/main/java/org/freedesktop/dbus/utils/generator/InterfaceCodeGenerator.java @@ -687,6 +687,7 @@ private static void version() { rev = properties.getProperty("revision"); } } catch (IOException _ex) { + LoggerFactory.getLogger(InterfaceCodeGenerator.class).debug("Unable to load version information", _ex); } System.out.println("DBus-Java Utils Version: " + version + ", revision: " + rev); diff --git a/pom.xml b/pom.xml index 5e2aacb5..219f96a5 100644 --- a/pom.xml +++ b/pom.xml @@ -24,26 +24,26 @@ 2.10.0 - 8.0.2 + 9.0.1 5.1.9 - 3.4.0 - 3.3.2 + 3.5.0 + 3.4.0 3.13.0 - 3.1.2 + 3.1.3 3.5.0 - 3.2.4 - 3.1.1 - 3.3.0 - 3.7.0 - 3.23.0 - 3.5.0 - 3.0.1 + 3.2.5 + 3.1.3 + 3.4.2 + 3.10.0 + 3.25.0 + 3.7.0 + 3.1.1 3.3.1 - 3.12.1 + 3.20.0 3.3.0 - 3.3.0 + 3.3.1 3.11.0.3922 - 2.17.0 + 2.17.1 false diff --git a/src/main/resources/pmd_rules.xml b/src/main/resources/pmd_rules.xml index f3f4ff5c..470e9bd5 100644 --- a/src/main/resources/pmd_rules.xml +++ b/src/main/resources/pmd_rules.xml @@ -66,6 +66,7 @@ +