This is an automated email from the ASF dual-hosted git repository.

kbowers pushed a commit to branch main
in repository 
https://gitbox.apache.org/repos/asf/incubator-kie-kogito-benchmarks.git

commit 2df2a7416583a45070e02eece0dcf632de528bcd
Author: Marián Macik <[email protected]>
AuthorDate: Wed Jun 9 13:02:37 2021 +0200

    Replace Paths.get() with Paths.of() and remove path-related code smell
---
 .../kie/kogito/benchmarks/framework/Commands.java   | 13 ++++++++-----
 .../org/kie/kogito/benchmarks/framework/Logs.java   | 21 +++++++++------------
 .../threshold.properties                            |  0
 .../threshold.properties                            |  0
 .../threshold.properties                            |  0
 .../threshold.properties                            |  0
 kogito-benchmarks-tests/pom.xml                     |  4 +++-
 .../kie/kogito/benchmarks/AbstractTemplateTest.java | 10 +++++-----
 8 files changed, 25 insertions(+), 23 deletions(-)

diff --git 
a/kogito-benchmarks-framework/src/main/java/org/kie/kogito/benchmarks/framework/Commands.java
 
b/kogito-benchmarks-framework/src/main/java/org/kie/kogito/benchmarks/framework/Commands.java
index fc6c5dd..333f039 100644
--- 
a/kogito-benchmarks-framework/src/main/java/org/kie/kogito/benchmarks/framework/Commands.java
+++ 
b/kogito-benchmarks-framework/src/main/java/org/kie/kogito/benchmarks/framework/Commands.java
@@ -11,7 +11,6 @@ import java.net.UnknownHostException;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
-import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -41,6 +40,7 @@ public class Commands {
 
     public static final String BASE_DIR = getBaseDir();
     public static final String APPS_DIR = getAppsDir();
+    public static final String ARCHIVED_LOGS_DIR = getArchivedLogsDir();
     public static final String MVNW = Commands.isThisWindows ? "mvnw.cmd" : 
"./mvnw";
     public static final boolean isThisWindows = 
System.getProperty("os.name").matches(".*[Ww]indows.*");
     private static final Pattern numPattern = Pattern.compile("[ \t]*[0-9]+[ 
\t]*");
@@ -130,6 +130,10 @@ public class Commands {
         return getSystemPropertyOrEnvVarValue("appsDir");
     }
 
+    public static String getArchivedLogsDir() {
+        return getSystemPropertyOrEnvVarValue("archivedLogsDir");
+    }
+
     private static String getSystemPropertyOrEnvVarValue(String name) {
         String systemPropertyValue = System.getProperty(name);
         if (StringUtils.isNotBlank(systemPropertyValue)) {
@@ -152,7 +156,7 @@ public class Commands {
 
     public static BuildResult buildApp(App app, String methodName, String 
className, StringBuilder whatIDidReport) throws InterruptedException {
         File appDir = app.getAppDir();
-        File buildLogA = new File(appDir.getAbsolutePath() + File.separator + 
"logs" + File.separator + app.mavenCommands.name().toLowerCase() + 
"-build.log");
+        File buildLogA = Path.of(appDir.getAbsolutePath(), "logs", 
app.mavenCommands.name().toLowerCase() + "-build.log").toFile();
         ExecutorService buildService = Executors.newFixedThreadPool(1);
 
         List<String> baseBuildCmd = new 
ArrayList<>(Arrays.asList(app.mavenCommands.mvnCmds[0]));
@@ -174,7 +178,7 @@ public class Commands {
 
     public static RunInfo startApp(App app, StringBuilder whatIDidReport) 
throws IOException, InterruptedException {
         File appDir = app.getAppDir();
-        File runLogA = new File(appDir.getAbsolutePath() + File.separator + 
"logs" + File.separator + app.mavenCommands.name().toLowerCase() + "-run.log");
+        File runLogA = Path.of(appDir.getAbsolutePath(), "logs", 
app.mavenCommands.name().toLowerCase() + "-run.log").toFile();
         List<String> cmd = getRunCommand(app.mavenCommands.mvnCmds[1]);
         appendln(whatIDidReport, appDir.getAbsolutePath());
         appendlnSection(whatIDidReport, String.join(" ", cmd));
@@ -313,8 +317,7 @@ public class Commands {
             if (isThisWindows) {
                 if (!force) {
                     Process p = Runtime.getRuntime().exec(new String[] {
-                            BASE_DIR + File.separator + "framework" + 
File.separator + "src" + File.separator + "main" + File.separator + "resources" 
+ File.separator +
-                                    "CtrlC.exe ",
+                            Path.of(BASE_DIR, "kogito-benchmarks-framework", 
"src", "main", "resources", "CtrlC.exe ").toString(),
                             Long.toString(pid) });
                     p.waitFor(1, TimeUnit.MINUTES);
                 }
diff --git 
a/kogito-benchmarks-framework/src/main/java/org/kie/kogito/benchmarks/framework/Logs.java
 
b/kogito-benchmarks-framework/src/main/java/org/kie/kogito/benchmarks/framework/Logs.java
index a78c143..22fd7f0 100644
--- 
a/kogito-benchmarks-framework/src/main/java/org/kie/kogito/benchmarks/framework/Logs.java
+++ 
b/kogito-benchmarks-framework/src/main/java/org/kie/kogito/benchmarks/framework/Logs.java
@@ -4,7 +4,6 @@ import java.io.File;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
-import java.nio.file.Paths;
 import java.nio.file.StandardOpenOption;
 import java.util.ArrayList;
 import java.util.HashSet;
@@ -23,7 +22,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
 import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.kie.kogito.benchmarks.framework.Commands.BASE_DIR;
+import static org.kie.kogito.benchmarks.framework.Commands.ARCHIVED_LOGS_DIR;
 import static org.kie.kogito.benchmarks.framework.Commands.isThisWindows;
 
 public class Logs {
@@ -73,8 +72,7 @@ public class Logs {
             }
             assertTrue(offendingLines.isEmpty(),
                     cmd.name() + " log should not contain error or warning 
lines that are not whitelisted. " +
-                            "See testsuite" + File.separator + "target" + 
File.separator + "archived-logs" +
-                            File.separator + testClass + File.separator + 
testMethod + File.separator + log.getName() +
+                            "See " + Path.of(ARCHIVED_LOGS_DIR, testClass, 
testMethod, log.getName()) +
                             " and check these offending lines: \n" + 
String.join("\n", offendingLines));
         }
     }
@@ -100,8 +98,7 @@ public class Logs {
 
         assertFalse(isOffending,
                 cmd.name() + " log should contain expected listening host. " +
-                        "See testsuite" + File.separator + "target" + 
File.separator + "archived-logs" +
-                        File.separator + testClass + File.separator + 
testMethod + File.separator + log.getName() +
+                        "See " + Path.of(ARCHIVED_LOGS_DIR, testClass, 
testMethod, log.getName()) +
                         " and check the listening host.");
     }
 
@@ -161,14 +158,14 @@ public class Logs {
         Path destDir = getLogsDir(testClass, testMethod);
         Files.createDirectories(destDir);
         String filename = log.getName();
-        Files.copy(log.toPath(), Paths.get(destDir.toString(), filename), 
REPLACE_EXISTING);
+        Files.copy(log.toPath(), destDir.resolve(filename), REPLACE_EXISTING);
     }
 
     public static void writeReport(String testClass, String testMethod, String 
text) throws IOException {
         Path destDir = getLogsDir(testClass, testMethod);
         Files.createDirectories(destDir);
-        Files.write(Paths.get(destDir.toString(), "report.md"), 
text.getBytes(UTF_8), StandardOpenOption.CREATE, 
StandardOpenOption.TRUNCATE_EXISTING);
-        Path agregateReport = Paths.get(getLogsDir().toString(), 
"aggregated-report.md");
+        Files.write(destDir.resolve("report.md"), text.getBytes(UTF_8), 
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
+        Path agregateReport = getLogsDir().resolve("aggregated-report.md");
         if (Files.notExists(agregateReport)) {
             Files.write(agregateReport, ("# Aggregated 
Report\n\n").getBytes(UTF_8), StandardOpenOption.CREATE);
         }
@@ -189,19 +186,19 @@ public class Logs {
     }
 
     public static Path getLogsDir(String testClass, String testMethod) throws 
IOException {
-        Path destDir = new File(getLogsDir(testClass).toString() + 
File.separator + testMethod).toPath();
+        Path destDir = getLogsDir(testClass).resolve(testMethod);
         Files.createDirectories(destDir);
         return destDir;
     }
 
     public static Path getLogsDir(String testClass) throws IOException {
-        Path destDir = new File(getLogsDir().toString() + File.separator + 
testClass).toPath();
+        Path destDir = getLogsDir().resolve(testClass);
         Files.createDirectories(destDir);
         return destDir;
     }
 
     public static Path getLogsDir() throws IOException {
-        Path destDir = new File(BASE_DIR + File.separator + "tests" + 
File.separator + "archived-logs").toPath();
+        Path destDir = Path.of(ARCHIVED_LOGS_DIR);
         Files.createDirectories(destDir);
         return destDir;
     }
diff --git 
a/kogito-benchmarks-framework/src/main/resources/smarthouse-02-dm-quarkus/threshold.properties
 
b/kogito-benchmarks-framework/src/main/resources/smarthouse-02-quarkus/threshold.properties
similarity index 100%
rename from 
kogito-benchmarks-framework/src/main/resources/smarthouse-02-dm-quarkus/threshold.properties
rename to 
kogito-benchmarks-framework/src/main/resources/smarthouse-02-quarkus/threshold.properties
diff --git 
a/kogito-benchmarks-framework/src/main/resources/smarthouse-02-dm-springboot/threshold.properties
 
b/kogito-benchmarks-framework/src/main/resources/smarthouse-02-springboot/threshold.properties
similarity index 100%
rename from 
kogito-benchmarks-framework/src/main/resources/smarthouse-02-dm-springboot/threshold.properties
rename to 
kogito-benchmarks-framework/src/main/resources/smarthouse-02-springboot/threshold.properties
diff --git 
a/kogito-benchmarks-framework/src/main/resources/smarthouse-03-dm-quarkus/threshold.properties
 
b/kogito-benchmarks-framework/src/main/resources/smarthouse-03-quarkus/threshold.properties
similarity index 100%
rename from 
kogito-benchmarks-framework/src/main/resources/smarthouse-03-dm-quarkus/threshold.properties
rename to 
kogito-benchmarks-framework/src/main/resources/smarthouse-03-quarkus/threshold.properties
diff --git 
a/kogito-benchmarks-framework/src/main/resources/smarthouse-03-dm-springboot/threshold.properties
 
b/kogito-benchmarks-framework/src/main/resources/smarthouse-03-springboot/threshold.properties
similarity index 100%
rename from 
kogito-benchmarks-framework/src/main/resources/smarthouse-03-dm-springboot/threshold.properties
rename to 
kogito-benchmarks-framework/src/main/resources/smarthouse-03-springboot/threshold.properties
diff --git a/kogito-benchmarks-tests/pom.xml b/kogito-benchmarks-tests/pom.xml
index 0b19972..be0a998 100644
--- a/kogito-benchmarks-tests/pom.xml
+++ b/kogito-benchmarks-tests/pom.xml
@@ -16,7 +16,8 @@
   <description>Benchmarks of sample Kogito apps themselves</description>
 
   <properties>
-    <appsDir>${project.parent.basedir}/</appsDir>
+    <appsDir>apps-dir-needs-to-be-specified</appsDir>
+    <archivedLogsDir>${project.basedir}/archived-logs</archivedLogsDir>
 
     
<version.org.apache.httpcomponents>4.5.13</version.org.apache.httpcomponents>
   </properties>
@@ -55,6 +56,7 @@
         <configuration>
           <systemPropertyVariables>
             <appsDir>${appsDir}</appsDir>
+            <archivedLogsDir>${archivedLogsDir}</archivedLogsDir>
           </systemPropertyVariables>
         </configuration>
       </plugin>
diff --git 
a/kogito-benchmarks-tests/src/test/java/org/kie/kogito/benchmarks/AbstractTemplateTest.java
 
b/kogito-benchmarks-tests/src/test/java/org/kie/kogito/benchmarks/AbstractTemplateTest.java
index 2b88f7f..0d47e70 100644
--- 
a/kogito-benchmarks-tests/src/test/java/org/kie/kogito/benchmarks/AbstractTemplateTest.java
+++ 
b/kogito-benchmarks-tests/src/test/java/org/kie/kogito/benchmarks/AbstractTemplateTest.java
@@ -120,7 +120,7 @@ public abstract class AbstractTemplateTest {
                 long startedInMs = (long) (startedStopped[0] * 1000);
                 long stoppedInMs = (long) (startedStopped[1] * 1000);
 
-                Path measurementsLog = Paths.get(getLogsDir(cn, 
mn).toString(), "measurements.csv");
+                Path measurementsLog = getLogsDir(cn, 
mn).resolve("measurements.csv");
                 LogBuilder.Log log = new LogBuilder()
                         .app(app)
                         .mode(mvnCmds)
@@ -150,7 +150,7 @@ public abstract class AbstractTemplateTest {
             long startedInMsAvgWithoutMinMax = 
getAvgWithoutMinMax(startedInMsValues);
             long stoppedInMsAvgWithoutMinMax = 
getAvgWithoutMinMax(stoppedInMsValues);
 
-            Path measurementsSummary = Paths.get(getLogsDir(cn).toString(), 
"measurementsSummary.csv");
+            Path measurementsSummary = 
getLogsDir(cn).resolve("measurementsSummary.csv");
 
             LogBuilder.Log log = new LogBuilder()
                     .app(app)
@@ -199,7 +199,7 @@ public abstract class AbstractTemplateTest {
         try {
             // Cleanup
             cleanTarget(app);
-            Files.createDirectories(Paths.get(appDir.getAbsolutePath() + 
File.separator + "logs"));
+            Files.createDirectories(Path.of(appDir.getAbsolutePath(), "logs"));
 
             // Build
             BuildResult buildResult = buildApp(app, mn, cn, whatIDidReport);
@@ -320,8 +320,8 @@ public abstract class AbstractTemplateTest {
             long startedInMs = (long) (startedStopped[0] * 1000);
             long stoppedInMs = (long) (startedStopped[1] * 1000);
 
-            Path measurementsLog = Paths.get(getLogsDir(cn, mn).toString(), 
"measurements.csv");
-            Path measurementsSummaryLog = Paths.get(getLogsDir(cn).toString(), 
"measurementsSummary.csv");
+            Path measurementsLog = getLogsDir(cn, 
mn).resolve("measurements.csv");
+            Path measurementsSummaryLog = 
getLogsDir(cn).resolve("measurementsSummary.csv");
             LogBuilder.Log log = new LogBuilder()
                     .app(app)
                     .mode(mvnCmds)


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to