Skip to content

Commit

Permalink
Updated maven plugins; Tighten PMD rules; Removed usage of 'var' keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
hypfvieh committed Aug 30, 2024
1 parent bf6347a commit af40040
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 35 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void testDeserializeParametersWithTuple() throws Exception {

@Test
void testDeserializeParametersVariant() throws Exception {
var varList = new Variant<>(List.of(1, 2, 3), "ai");
Variant<List<Integer>> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Exception> 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);

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 4 additions & 3 deletions dbus-java-tests/src/test/java/sample/issue/Issue244Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,8 @@ public List<String> 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 14 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@
<junixsocket.version>2.10.0</junixsocket.version>

<!-- Plugin versions -->
<mvn.git.commit.id.maven.plugin>8.0.2</mvn.git.commit.id.maven.plugin>
<mvn.git.commit.id.maven.plugin>9.0.1</mvn.git.commit.id.maven.plugin>
<mvn.maven.bundle.plugin.version>5.1.9</mvn.maven.bundle.plugin.version>
<mvn.maven.checkstyle.plugin>3.4.0</mvn.maven.checkstyle.plugin>
<mvn.maven.clean.plugin>3.3.2</mvn.maven.clean.plugin>
<mvn.maven.checkstyle.plugin>3.5.0</mvn.maven.checkstyle.plugin>
<mvn.maven.clean.plugin>3.4.0</mvn.maven.clean.plugin>
<mvn.maven.compiler.plugin>3.13.0</mvn.maven.compiler.plugin>
<mvn.maven.deploy.plugin>3.1.2</mvn.maven.deploy.plugin>
<mvn.maven.deploy.plugin>3.1.3</mvn.maven.deploy.plugin>
<mvn.maven.enforcer.plugin>3.5.0</mvn.maven.enforcer.plugin>
<mvn.maven.gpg.plugin>3.2.4</mvn.maven.gpg.plugin>
<mvn.maven.install.plugin>3.1.1</mvn.maven.install.plugin>
<mvn.maven.jar.plugin>3.3.0</mvn.maven.jar.plugin>
<mvn.maven.javadoc.plugin>3.7.0</mvn.maven.javadoc.plugin>
<mvn.maven.pmd.plugin>3.23.0</mvn.maven.pmd.plugin>
<mvn.maven.project.info.reports.plugin>3.5.0</mvn.maven.project.info.reports.plugin>
<mvn.maven.release.plugin>3.0.1</mvn.maven.release.plugin>
<mvn.maven.gpg.plugin>3.2.5</mvn.maven.gpg.plugin>
<mvn.maven.install.plugin>3.1.3</mvn.maven.install.plugin>
<mvn.maven.jar.plugin>3.4.2</mvn.maven.jar.plugin>
<mvn.maven.javadoc.plugin>3.10.0</mvn.maven.javadoc.plugin>
<mvn.maven.pmd.plugin>3.25.0</mvn.maven.pmd.plugin>
<mvn.maven.project.info.reports.plugin>3.7.0</mvn.maven.project.info.reports.plugin>
<mvn.maven.release.plugin>3.1.1</mvn.maven.release.plugin>
<mvn.maven.resource.plugin>3.3.1</mvn.maven.resource.plugin>
<mvn.maven.site.plugin>3.12.1</mvn.maven.site.plugin>
<mvn.maven.site.plugin>3.20.0</mvn.maven.site.plugin>
<mvn.maven.source.plugin>3.3.0</mvn.maven.source.plugin>
<mvn.maven.surefire.plugin>3.3.0</mvn.maven.surefire.plugin>
<mvn.maven.surefire.plugin>3.3.1</mvn.maven.surefire.plugin>
<mvn.sonar.maven.plugin>3.11.0.3922</mvn.sonar.maven.plugin>
<mvn.versions.maven.plugin>2.17.0</mvn.versions.maven.plugin>
<mvn.versions.maven.plugin>2.17.1</mvn.versions.maven.plugin>

<!-- Code analysis -->
<check.skip-javadoc>false</check.skip-javadoc>
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/pmd_rules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<rule ref="category/java/codestyle.xml/UseDiamondOperator" />
<rule ref="category/java/codestyle.xml/UselessParentheses" />
<rule ref="category/java/codestyle.xml/UselessQualifiedThis" />
<rule ref="category/java/codestyle.xml/UseExplicitTypes" />

<rule ref="category/java/design.xml/AvoidThrowingNewInstanceOfSameException" />
<rule ref="category/java/design.xml/CollapsibleIfStatements" />
Expand Down

0 comments on commit af40040

Please sign in to comment.