From c93247e5db9e4107d69d35ae3b551e7bc41112b4 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 17 Jan 2018 22:36:04 +0200 Subject: [PATCH] SQL: Make NodeSubClass work on windows (elastic/x-pack-elasticsearch#3603) Original commit: elastic/x-pack-elasticsearch@99a6f3a99bdd0c6231904736832ef29f5d0bd4f4 --- .../xpack/sql/tree/NodeSubclassTests.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/sql/server/src/test/java/org/elasticsearch/xpack/sql/tree/NodeSubclassTests.java b/sql/server/src/test/java/org/elasticsearch/xpack/sql/tree/NodeSubclassTests.java index 3dd1b0bb6da..3e41d2e9f63 100644 --- a/sql/server/src/test/java/org/elasticsearch/xpack/sql/tree/NodeSubclassTests.java +++ b/sql/server/src/test/java/org/elasticsearch/xpack/sql/tree/NodeSubclassTests.java @@ -5,6 +5,8 @@ */ package org.elasticsearch.xpack.sql.tree; +import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; + import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.test.ESTestCase; @@ -21,10 +23,7 @@ import org.elasticsearch.xpack.sql.expression.regex.LikePattern; import org.elasticsearch.xpack.sql.tree.NodeTests.ChildrenAreAProperty; import org.elasticsearch.xpack.sql.tree.NodeTests.Dummy; import org.elasticsearch.xpack.sql.tree.NodeTests.NoChildren; -import org.elasticsearch.xpack.sql.type.DataType; -import org.elasticsearch.xpack.sql.type.DataTypes; import org.mockito.exceptions.base.MockitoException; -import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; import java.io.IOException; import java.lang.reflect.Constructor; @@ -39,7 +38,6 @@ import java.nio.file.Path; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -47,9 +45,9 @@ import java.util.Map; import java.util.Objects; import java.util.function.Supplier; -import static org.mockito.Mockito.mock; import static java.util.Collections.emptyList; import static java.util.stream.Collectors.toList; +import static org.mockito.Mockito.mock; /** * Looks for all subclasses of {@link Node} and verifies that they @@ -534,11 +532,12 @@ public class NodeSubclassTests> extends ESTestCas return lookup; } List> results = new ArrayList<>(); - String[] paths = System.getProperty("java.class.path").split(":"); + String[] paths = System.getProperty("java.class.path").split(System.getProperty("path.separator")); for (String path: paths) { Path root = PathUtils.get(path); int rootLength = root.toString().length() + 1; Files.walkFileTree(root, new SimpleFileVisitor() { + @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (Files.isRegularFile(file) && file.getFileName().toString().endsWith(".class")) { @@ -548,6 +547,12 @@ public class NodeSubclassTests> extends ESTestCas // Go from "path" style to class style className = className.replace(PathUtils.getDefaultFileSystem().getSeparator(), "."); + // filter the class that are not interested + // (and IDE folders like eclipse) + if (!className.startsWith("org.elasticsearch.xpack.sql")) { + return FileVisitResult.CONTINUE; + } + Class c; try { c = Class.forName(className); @@ -562,7 +567,7 @@ public class NodeSubclassTests> extends ESTestCas results.add(s); } } - return super.visitFile(file, attrs); + return FileVisitResult.CONTINUE; } }); }