You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "julianhyde (via GitHub)" <gi...@apache.org> on 2023/06/08 21:30:18 UTC

[GitHub] [calcite] julianhyde commented on a diff in pull request #3250: [CALCITE-5706] Add class PairList (and other changes)

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


##########
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. "

Review Comment:
   agree; fixed



-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org