Skip to content

Commit

Permalink
Apply google-java-format to codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinherron authored Dec 31, 2024
2 parents d19ed6a + 40d9175 commit a6a92fd
Show file tree
Hide file tree
Showing 2,379 changed files with 531,124 additions and 360,458 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# google-java-format
38459f0d42dfc6de2b74de6d784017b5f38fa763
18 changes: 18 additions & 0 deletions .github/workflows/google-java-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: check google-java-format

on:
push:
branches:
- 'dev/1.0'
pull_request:
branches:
- 'dev/1.0'

jobs:
formatting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: axel-op/googlejavaformat-action@v3.6.0
with:
args: "--set-exit-if-changed"
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ You can find all the details in the [Contributing via Git](http://wiki.eclipse.o
* Make sure you include test cases for non-trivial features
* Make sure the test suite passes after your changes
* Make sure checkstyle passes after your changes
* Apply `google-java-format` (see https://github.com/google/google-java-format)
* Commit your changes into that branch
* Use descriptive and meaningful commit messages
* If you have a lot of commits squash them into a single commit
Expand All @@ -68,7 +69,7 @@ Please make sure new source files have license header like this:

````
/*
* Copyright (c) 2019 the Eclipse Milo Authors
* Copyright (c) 2025 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down
450 changes: 450 additions & 0 deletions config/checkstyle/checkstyle.xml

Large diffs are not rendered by default.

123 changes: 62 additions & 61 deletions milo-examples/client-examples/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2022 the Eclipse Milo Authors
~ Copyright (c) 2024 the Eclipse Milo Authors
~
~ This program and the accompanying materials are made
~ available under the terms of the Eclipse Public License 2.0
Expand All @@ -9,71 +9,72 @@
~ SPDX-License-Identifier: EPL-2.0
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.eclipse.milo</groupId>
<artifactId>milo-examples</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<parent>
<groupId>org.eclipse.milo</groupId>
<artifactId>milo-examples</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<artifactId>milo-client-examples</artifactId>
<artifactId>milo-client-examples</artifactId>

<properties>
<javaModuleName>org.eclipse.milo.examples.client</javaModuleName>
</properties>
<properties>
<javaModuleName>org.eclipse.milo.examples.client</javaModuleName>
</properties>

<dependencies>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>milo-sdk-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>milo-codec-json</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>milo-dtd-reader</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>milo-server-examples</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>${jetbrains-annotations.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<dependencies>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>milo-sdk-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>milo-codec-json</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>milo-dtd-reader</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>milo-server-examples</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>${jetbrains-annotations.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
</plugin>
</plugins>
</build>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 the Eclipse Milo Authors
* Copyright (c) 2024 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -10,14 +10,13 @@

package org.eclipse.milo.examples.client;

import com.google.common.base.MoreObjects;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;
import java.util.stream.Stream;

import com.google.common.base.MoreObjects;
import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
import org.eclipse.milo.opcua.sdk.client.nodes.UaNode;
import org.eclipse.milo.opcua.stack.core.NodeIds;
Expand All @@ -26,82 +25,84 @@

public class BrowseAsyncExample implements ClientExample {

public static void main(String[] args) throws Exception {
BrowseAsyncExample example = new BrowseAsyncExample();
public static void main(String[] args) throws Exception {
BrowseAsyncExample example = new BrowseAsyncExample();

new ClientExampleRunner(example).run();
}

private final Logger logger = LoggerFactory.getLogger(getClass());

@Override
public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {
client.connect();
new ClientExampleRunner(example).run();
}

// start browsing at root folder
UaNode rootNode = client.getAddressSpace().getNode(NodeIds.RootFolder);
private final Logger logger = LoggerFactory.getLogger(getClass());

Tree<UaNode> tree = new Tree<>(rootNode);
@Override
public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {
client.connect();

long startTime = System.nanoTime();
browseRecursive(client, tree).get();
long endTime = System.nanoTime();
// start browsing at root folder
UaNode rootNode = client.getAddressSpace().getNode(NodeIds.RootFolder);

traverse(tree, 0, (depth, n) -> logger.info(indent(depth) + n.getBrowseName().getName()));
Tree<UaNode> tree = new Tree<>(rootNode);

logger.info(
"Browse took {}ms",
TimeUnit.MILLISECONDS.convert(endTime - startTime, TimeUnit.NANOSECONDS));
long startTime = System.nanoTime();
browseRecursive(client, tree).get();
long endTime = System.nanoTime();

future.complete(client);
}
traverse(tree, 0, (depth, n) -> logger.info(indent(depth) + n.getBrowseName().getName()));

private CompletableFuture<Void> browseRecursive(OpcUaClient client, Tree<UaNode> tree) {
return client.getAddressSpace().browseNodesAsync(tree.node).thenCompose(nodes -> {
// Add each child node to the tree
nodes.forEach(tree::addChild);
logger.info(
"Browse took {}ms",
TimeUnit.MILLISECONDS.convert(endTime - startTime, TimeUnit.NANOSECONDS));

// For each child node browse for its children
Stream<CompletableFuture<Void>> futures =
tree.children.stream().map(child -> browseRecursive(client, child));
future.complete(client);
}

// Return a CompletableFuture that completes when the child browses complete
return CompletableFuture.allOf(futures.toArray(CompletableFuture[]::new));
});
}
private CompletableFuture<Void> browseRecursive(OpcUaClient client, Tree<UaNode> tree) {
return client
.getAddressSpace()
.browseNodesAsync(tree.node)
.thenCompose(
nodes -> {
// Add each child node to the tree
nodes.forEach(tree::addChild);

private static String indent(int depth) {
return " ".repeat(Math.max(0, depth));
}
// For each child node browse for its children
Stream<CompletableFuture<Void>> futures =
tree.children.stream().map(child -> browseRecursive(client, child));

private static <T> void traverse(Tree<T> tree, int depth, BiConsumer<Integer, T> consumer) {
consumer.accept(depth, tree.node);
// Return a CompletableFuture that completes when the child browses complete
return CompletableFuture.allOf(futures.toArray(CompletableFuture[]::new));
});
}

tree.children.forEach(child -> traverse(child, depth + 1, consumer));
}
private static String indent(int depth) {
return " ".repeat(Math.max(0, depth));
}

private static class Tree<T> {
private static <T> void traverse(Tree<T> tree, int depth, BiConsumer<Integer, T> consumer) {
consumer.accept(depth, tree.node);

final List<Tree<T>> children = new CopyOnWriteArrayList<>();
tree.children.forEach(child -> traverse(child, depth + 1, consumer));
}

final T node;
private static class Tree<T> {

Tree(T node) {
this.node = node;
}
final List<Tree<T>> children = new CopyOnWriteArrayList<>();

void addChild(T child) {
children.add(new Tree<>(child));
}
final T node;

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("node", node)
.add("children", children)
.toString();
}
Tree(T node) {
this.node = node;
}

void addChild(T child) {
children.add(new Tree<>(child));
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("node", node)
.add("children", children)
.toString();
}
}
}
Loading

0 comments on commit a6a92fd

Please sign in to comment.