julianhyde commented on code in PR #3250:
URL: https://github.com/apache/calcite/pull/3250#discussion_r1223567179


##########
testkit/src/main/java/org/apache/calcite/util/TestUtil.java:
##########
@@ -310,6 +315,38 @@ public static String getJavaVirtualMachineVendor() {
     return System.getProperty("java.vm.vendor");
   }
 
+  /** Returns the root directory of the source tree. */
+  public static File getBaseDir(Class<?> klass) {
+    // Algorithm:
+    // 1) Find location of TestUtil.class
+    // 2) Climb via getParentFile() until we detect pom.xml
+    // 3) It means we've got BASE/testkit/pom.xml, and we need to get BASE
+    final URL resource = klass.getResource(klass.getSimpleName() + ".class");
+    final File testUtilClass =
+        Sources.of(requireNonNull(resource, "resource")).file();
+
+    File file = testUtilClass.getAbsoluteFile();
+    for (int i = 0; i < 42; i++) {
+      if (isProjectDir(file)) {
+        // Ok, file == BASE/testkit/
+        break;
+      }
+      file = file.getParentFile();
+    }
+    if (!isProjectDir(file)) {
+      fail("Could not find either testkit/pom.xml or testkit/build.gradle.kts. 
"
+          + "Started with " + testUtilClass.getAbsolutePath()
+          + ", the current path is " + file.getAbsolutePath());
+    }
+    return file.getParentFile();
+  }
+
+  private static boolean isProjectDir(File dir) {
+    return new File(dir, "pom.xml").isFile()

Review Comment:
   I don't think it can hurt. I have a few old branches that have not been 
upgraded to gradle.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to