From a11a905378be05f13c86a155deb1519acb53e4d4 Mon Sep 17 00:00:00 2001
From: rschoene <rene.schoene@tu-dresden.de>
Date: Wed, 26 May 2021 16:05:28 +0200
Subject: [PATCH] fix path to coordinator config

- address some build warnings
---
 .../inf/st/ros3rag/common/SharedMainParts.java        |  5 +++--
 .../java/de/tudresden/inf/st/ros3rag/common/Util.java | 11 ++++++++++-
 ros3rag.coordinator/build.gradle                      |  1 +
 .../tudresden/inf/st/coordinator/MainCoordinator.java |  5 +++--
 4 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/ros3rag.common/src/main/java/de/tudresden/inf/st/ros3rag/common/SharedMainParts.java b/ros3rag.common/src/main/java/de/tudresden/inf/st/ros3rag/common/SharedMainParts.java
index b51ab93..280d089 100644
--- a/ros3rag.common/src/main/java/de/tudresden/inf/st/ros3rag/common/SharedMainParts.java
+++ b/ros3rag.common/src/main/java/de/tudresden/inf/st/ros3rag/common/SharedMainParts.java
@@ -28,8 +28,8 @@ public abstract class SharedMainParts<MqttHandler extends SharedMainParts.MqttHa
   private final String TOPIC_EXIT;
   private final String TOPIC_SCENE_INIT;
 
-  private final String TOPIC_SUFFIX_COORDINATOR_STATUS = "status";
-  private final String TOPIC_SUFFIX_COORDINATOR_COMMAND = "command";
+  private static final String TOPIC_SUFFIX_COORDINATOR_STATUS = "status";
+  private static final String TOPIC_SUFFIX_COORDINATOR_COMMAND = "command";
 
   protected MqttHandler mainHandler;
   protected WorldModel model;
@@ -193,6 +193,7 @@ public abstract class SharedMainParts<MqttHandler extends SharedMainParts.MqttHa
 
     SELF setHost(String host) throws java.io.IOException;
 
+    @SuppressWarnings("UnusedReturnValue")
     boolean waitUntilReady(long value, TimeUnit unit);
   }
 
diff --git a/ros3rag.common/src/main/java/de/tudresden/inf/st/ros3rag/common/Util.java b/ros3rag.common/src/main/java/de/tudresden/inf/st/ros3rag/common/Util.java
index e4ca859..1b8b116 100644
--- a/ros3rag.common/src/main/java/de/tudresden/inf/st/ros3rag/common/Util.java
+++ b/ros3rag.common/src/main/java/de/tudresden/inf/st/ros3rag/common/Util.java
@@ -14,7 +14,9 @@ import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 /**
  * Helper method dealing with config.
@@ -58,11 +60,18 @@ public class Util {
     return pathToModuleDirectory("ros3rag.common");
   }
 
+  private final static Set<String> modules = new HashSet<>() {{
+    add("ros3rag.placeA");
+    add("ros3rag.placeB");
+    add("ros3rag.common");
+    add("ros3rag.coordinator");
+  }};
+
   public static Path pathToModuleDirectory(String moduleName) {
     Path current = Paths.get("").toAbsolutePath();
     String currentFileName = current.getFileName().toString();
     Path repoRoot;
-    if (currentFileName.equals("ros3rag.placeA") || currentFileName.equals("ros3rag.placeB") || currentFileName.equals("ros3rag.common")) {
+    if (modules.contains(currentFileName)) {
       // we are in some module, use parent
       repoRoot = current.getParent();
     } else if (current.resolve(moduleName).toFile().exists()) {
diff --git a/ros3rag.coordinator/build.gradle b/ros3rag.coordinator/build.gradle
index 956ee90..ca9ba4a 100644
--- a/ros3rag.coordinator/build.gradle
+++ b/ros3rag.coordinator/build.gradle
@@ -29,6 +29,7 @@ dependencies {
     jastadd2 fileTree(include: ['jastadd2.jar'], dir: '../libs')
     api group: 'org.fusesource.mqtt-client', name: 'mqtt-client', version: '1.15'
 
+    implementation project(':ros3rag.common')
 }
 
 sourceCompatibility = 11
diff --git a/ros3rag.coordinator/src/main/java/de/tudresden/inf/st/coordinator/MainCoordinator.java b/ros3rag.coordinator/src/main/java/de/tudresden/inf/st/coordinator/MainCoordinator.java
index 51d58a1..0d69891 100644
--- a/ros3rag.coordinator/src/main/java/de/tudresden/inf/st/coordinator/MainCoordinator.java
+++ b/ros3rag.coordinator/src/main/java/de/tudresden/inf/st/coordinator/MainCoordinator.java
@@ -6,12 +6,12 @@ import de.tudresden.inf.st.coordinator.ast.Coordinator;
 import de.tudresden.inf.st.coordinator.ast.MqttHandler;
 import de.tudresden.inf.st.coordinator.parser.CoordinatorParser;
 import de.tudresden.inf.st.coordinator.scanner.CoordinatorScanner;
+import de.tudresden.inf.st.ros3rag.common.Util;
 
 import java.io.IOException;
 import java.io.Reader;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
-import java.nio.file.Paths;
 import java.util.Arrays;
 import java.util.Set;
 import java.util.concurrent.CountDownLatch;
@@ -88,7 +88,8 @@ public class MainCoordinator {
   }
 
   private void parsedBuild() throws IOException, Parser.Exception {
-    Reader in = Files.newBufferedReader(Paths.get("src", "main", "resources", "ros3rag.coordinator"));
+    Reader in = Files.newBufferedReader(Util.pathToModuleDirectory("ros3rag.coordinator")
+        .resolve("src/main/resources/ros3rag.coordinator"));
 
     CoordinatorScanner scanner = new CoordinatorScanner(in);
     CoordinatorParser parser = new CoordinatorParser();
-- 
GitLab