You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ud...@apache.org on 2020/07/02 18:10:42 UTC

[geode] 06/29: GEODE-8285: Change location of generated test file to build dir and fix error message path for sanctioned text file (#5280)

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

udo pushed a commit to branch feature/GEODE-8294
in repository https://gitbox.apache.org/repos/asf/geode.git

commit 4e74098359fb14976c2f73bd2e9907286f4d1d14
Author: luissson <ja...@pdx.edu>
AuthorDate: Wed Jun 24 14:06:53 2020 -0700

    GEODE-8285: Change location of generated test file to build dir and fix error message path for sanctioned text file (#5280)
    
    refactor createEmptyFile and getSrcPathFor for clarity
---
 .../AnalyzeDataSerializablesJUnitTestBase.java     | 31 ++++++++++++++++------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/geode-junit/src/main/java/org/apache/geode/codeAnalysis/AnalyzeDataSerializablesJUnitTestBase.java b/geode-junit/src/main/java/org/apache/geode/codeAnalysis/AnalyzeDataSerializablesJUnitTestBase.java
index 8283725..2257729 100644
--- a/geode-junit/src/main/java/org/apache/geode/codeAnalysis/AnalyzeDataSerializablesJUnitTestBase.java
+++ b/geode-junit/src/main/java/org/apache/geode/codeAnalysis/AnalyzeDataSerializablesJUnitTestBase.java
@@ -25,6 +25,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InvalidClassException;
 import java.io.Serializable;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.LinkedList;
@@ -211,13 +212,12 @@ public abstract class AnalyzeDataSerializablesJUnitTestBase {
   }
 
   protected String getSrcPathFor(File file) {
-    return getSrcPathFor(file, "test");
-  }
-
-  private String getSrcPathFor(File file, String testOrMain) {
-    return file.getAbsolutePath().replace(
-        "build" + File.separator + "resources" + File.separator + "test",
-        "src" + File.separator + testOrMain + File.separator + "resources");
+    final String srcResourcePath = Paths.get("src", "integrationTest", "resources").toString();
+    final String line =
+        "(.*" + File.separator + "geode" + File.separator + ").*(" + File.separator + "org.*)";
+    return file.getAbsolutePath().replaceAll(
+        line,
+        "$1" + getModuleName() + File.separator + srcResourcePath + "$2");
   }
 
   protected List<String> loadExcludedClasses(File exclusionsFile) throws IOException {
@@ -296,7 +296,18 @@ public abstract class AnalyzeDataSerializablesJUnitTestBase {
   }
 
   protected File createEmptyFile(String fileName) throws IOException {
-    File file = new File(fileName);
+    final String workingDir = System.getProperty("user.dir");
+    final String filePath;
+    if (isIntelliJDir(workingDir)) {
+      String buildDir = workingDir.replace(getModuleName(), "");
+      buildDir =
+          Paths.get(buildDir, "out", "production", "geode." + getModuleName() + ".integrationTest")
+              .toString();
+      filePath = buildDir + File.separator + fileName;
+    } else {
+      filePath = fileName;
+    }
+    File file = new File(filePath);
     if (file.exists()) {
       assertThat(file.delete()).isTrue();
     }
@@ -305,6 +316,10 @@ public abstract class AnalyzeDataSerializablesJUnitTestBase {
     return file;
   }
 
+  private boolean isIntelliJDir(final String workingDir) {
+    return !workingDir.contains("build");
+  }
+
   /**
    * Use this method to get a resource stored in the test's resource directory
    */