aboutsummaryrefslogtreecommitdiffstats
path: root/compatibility-server/src/test/java/com/vaadin/tests/server/DeprecatedTest.java
diff options
context:
space:
mode:
authorAleksi Hietanen <aleksi@vaadin.com>2016-10-14 11:41:06 +0300
committerVaadin Code Review <review@vaadin.com>2016-10-24 07:55:31 +0000
commit2cdb3b39329232dcefee2ae61ded92f2c3fe54b0 (patch)
treee1bcdcab7065ae5b5723e8400580d50055aae77f /compatibility-server/src/test/java/com/vaadin/tests/server/DeprecatedTest.java
parent02ed73dc9ea247b13fbef63007af6c3c53ad9423 (diff)
downloadvaadin-framework-2cdb3b39329232dcefee2ae61ded92f2c3fe54b0.tar.gz
vaadin-framework-2cdb3b39329232dcefee2ae61ded92f2c3fe54b0.zip
Add utility for outputting the full declarative syntax of components
Change-Id: I4bc740154ffb5a30892b1859a7550a7aeff94fb3
Diffstat (limited to 'compatibility-server/src/test/java/com/vaadin/tests/server/DeprecatedTest.java')
-rw-r--r--compatibility-server/src/test/java/com/vaadin/tests/server/DeprecatedTest.java107
1 files changed, 17 insertions, 90 deletions
diff --git a/compatibility-server/src/test/java/com/vaadin/tests/server/DeprecatedTest.java b/compatibility-server/src/test/java/com/vaadin/tests/server/DeprecatedTest.java
index e8475b6750..671fc65080 100644
--- a/compatibility-server/src/test/java/com/vaadin/tests/server/DeprecatedTest.java
+++ b/compatibility-server/src/test/java/com/vaadin/tests/server/DeprecatedTest.java
@@ -16,19 +16,8 @@
package com.vaadin.tests.server;
import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Modifier;
-import java.net.URI;
import java.net.URISyntaxException;
-import java.net.URL;
-import java.nio.file.FileSystems;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Locale;
-import java.util.stream.Collectors;
+import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Assert;
import org.junit.Test;
@@ -39,86 +28,24 @@ import org.junit.Test;
*/
public class DeprecatedTest {
- private static String CLASS_SUFFIX = ".class";
-
@Test
public void allTypesAreDeprecated() throws URISyntaxException {
- URL url = DeprecatedTest.class.getResource("/");
- File file = new File(url.toURI());
- List<File> classpath = getRawClasspathEntries().stream()
- .filter(entry -> entry.contains("compatibility-server"))
- .map(File::new).filter(fileEntry -> !fileEntry.equals(file))
- .collect(Collectors.toList());
- Assert.assertFalse(classpath.isEmpty());
- classpath.forEach(this::checkDeprecatedClasses);
- }
-
- private void checkDeprecatedClasses(File classesRoot) {
- try {
- if (classesRoot.isDirectory()) {
- Files.walk(classesRoot.toPath()).filter(Files::isRegularFile)
- .filter(path -> path.toFile().getName()
- .endsWith(CLASS_SUFFIX))
- .forEach(path -> checkDeprecatedClass(path,
- classesRoot.toPath()));
- } else if (classesRoot.getName().toLowerCase(Locale.ENGLISH)
- .endsWith(".jar")) {
- URI uri = URI.create("jar:file:" + classesRoot.getPath());
- Path root = FileSystems
- .newFileSystem(uri, Collections.emptyMap())
- .getPath("/");
- Files.walk(root).filter(Files::isRegularFile)
- .filter(path -> path.toUri().getSchemeSpecificPart()
- .endsWith(CLASS_SUFFIX))
- .forEach(path -> checkDeprecatedClass(path, root));
- }
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- private void checkDeprecatedClass(Path path, Path root) {
- Path relative = root.relativize(path);
- String name = relative.toString();
- name = name.substring(0, name.length() - CLASS_SUFFIX.length());
- name = name.replace('/', '.');
- try {
- Class<?> clazz = Class.forName(name);
- if (clazz.isSynthetic() || clazz.isAnonymousClass()) {
- return;
- }
- if (Modifier.isPrivate(clazz.getModifiers())) {
- return;
- }
- Assert.assertNotNull(
- "Class " + clazz
- + " is in compatability package and it's not deprecated",
- clazz.getAnnotation(Deprecated.class));
- } catch (ClassNotFoundException e) {
- throw new RuntimeException(e);
- }
+ AtomicInteger count = new AtomicInteger(0);
+
+ File testRoot = new File(DeprecatedTest.class.getResource("/").toURI());
+
+ new ClasspathHelper(fqn -> false)
+ .getVaadinClassesFromClasspath(
+ entry -> entry.contains("compatibility-server")
+ && !testRoot.equals(new File(entry)))
+ .forEach(cls -> {
+ count.incrementAndGet();
+ Assert.assertNotNull(
+ "Class " + cls
+ + " is in compatability package and it's not deprecated",
+ cls.getAnnotation(Deprecated.class));
+ });
+ Assert.assertTrue(count.get() > 0);
}
- private final static List<String> getRawClasspathEntries() {
- // try to keep the order of the classpath
- List<String> locations = new ArrayList<>();
-
- String pathSep = System.getProperty("path.separator");
- String classpath = System.getProperty("java.class.path");
-
- if (classpath.startsWith("\"")) {
- classpath = classpath.substring(1);
- }
- if (classpath.endsWith("\"")) {
- classpath = classpath.substring(0, classpath.length() - 1);
- }
-
- String[] split = classpath.split(pathSep);
- for (int i = 0; i < split.length; i++) {
- String classpathEntry = split[i];
- locations.add(classpathEntry);
- }
-
- return locations;
- }
}