SQL: Make NodeSubClass work on windows (elastic/x-pack-elasticsearch#3603)

Original commit: elastic/x-pack-elasticsearch@99a6f3a99b
This commit is contained in:
Costin Leau 2018-01-17 22:36:04 +02:00 committed by GitHub
parent 41c1c5fdd1
commit c93247e5db
1 changed files with 12 additions and 7 deletions

View File

@ -5,6 +5,8 @@
*/ */
package org.elasticsearch.xpack.sql.tree; package org.elasticsearch.xpack.sql.tree;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.test.ESTestCase; 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.ChildrenAreAProperty;
import org.elasticsearch.xpack.sql.tree.NodeTests.Dummy; import org.elasticsearch.xpack.sql.tree.NodeTests.Dummy;
import org.elasticsearch.xpack.sql.tree.NodeTests.NoChildren; 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 org.mockito.exceptions.base.MockitoException;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
@ -39,7 +38,6 @@ import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor; import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -47,9 +45,9 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.function.Supplier; import java.util.function.Supplier;
import static org.mockito.Mockito.mock;
import static java.util.Collections.emptyList; import static java.util.Collections.emptyList;
import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toList;
import static org.mockito.Mockito.mock;
/** /**
* Looks for all subclasses of {@link Node} and verifies that they * Looks for all subclasses of {@link Node} and verifies that they
@ -534,11 +532,12 @@ public class NodeSubclassTests<T extends B, B extends Node<B>> extends ESTestCas
return lookup; return lookup;
} }
List<Class<? extends T>> results = new ArrayList<>(); List<Class<? extends T>> 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) { for (String path: paths) {
Path root = PathUtils.get(path); Path root = PathUtils.get(path);
int rootLength = root.toString().length() + 1; int rootLength = root.toString().length() + 1;
Files.walkFileTree(root, new SimpleFileVisitor<Path>() { Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
@Override @Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (Files.isRegularFile(file) && file.getFileName().toString().endsWith(".class")) { if (Files.isRegularFile(file) && file.getFileName().toString().endsWith(".class")) {
@ -548,6 +547,12 @@ public class NodeSubclassTests<T extends B, B extends Node<B>> extends ESTestCas
// Go from "path" style to class style // Go from "path" style to class style
className = className.replace(PathUtils.getDefaultFileSystem().getSeparator(), "."); 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; Class<?> c;
try { try {
c = Class.forName(className); c = Class.forName(className);
@ -562,7 +567,7 @@ public class NodeSubclassTests<T extends B, B extends Node<B>> extends ESTestCas
results.add(s); results.add(s);
} }
} }
return super.visitFile(file, attrs); return FileVisitResult.CONTINUE;
} }
}); });
} }