From 87ff19e3066fbb9ce3f38923729410f4d0717276 Mon Sep 17 00:00:00 2001 From: Marc Philipp Date: Sat, 27 Aug 2016 20:48:04 +0200 Subject: [PATCH] Remove CloseablePathProvider --- .../commons/util/ClasspathScanner.java | 3 +- .../platform/commons/util/CloseablePath.java | 30 +++++++++++--- .../commons/util/CloseablePathProvider.java | 41 ------------------- 3 files changed, 25 insertions(+), 49 deletions(-) delete mode 100644 junit-platform-commons/src/main/java/org/junit/platform/commons/util/CloseablePathProvider.java diff --git a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ClasspathScanner.java b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ClasspathScanner.java index 598284bcab6..20a10f87f89 100644 --- a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ClasspathScanner.java +++ b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ClasspathScanner.java @@ -116,8 +116,7 @@ private List> findClassesForUris(List baseUris, String basePackage } private List> findClassesForUri(String basePackageName, URI baseUri, Predicate> classFilter) { - CloseablePathProvider provider = CloseablePathProvider.create(baseUri.getScheme()); - try (CloseablePath closeablePath = provider.toCloseablePath(baseUri)) { + try (CloseablePath closeablePath = CloseablePath.create(baseUri)) { Path baseDir = closeablePath.getPath(); return findClassesForPath(basePackageName, baseDir, classFilter); } diff --git a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/CloseablePath.java b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/CloseablePath.java index 05af4f51b1d..07bee9ca87e 100644 --- a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/CloseablePath.java +++ b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/CloseablePath.java @@ -10,22 +10,40 @@ package org.junit.platform.commons.util; +import static java.util.Collections.emptyMap; + import java.io.Closeable; import java.io.IOException; +import java.net.URI; +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; import java.nio.file.Path; +import java.nio.file.Paths; final class CloseablePath implements Closeable { - static final Closeable NULL_CLOSEABLE = () -> { - }; + private static final String JAR_URI_SCHEME = "jar"; + private static final String JAR_URI_SEPARATOR = "!"; + + private static final Closeable NULL_CLOSEABLE = () -> { + }; private final Path path; private final Closeable delegate; - CloseablePath(Path path, Closeable delegate) { - this.path = path; - this.delegate = delegate; - } + static CloseablePath create(URI uri) throws IOException { + if (JAR_URI_SCHEME.equals(uri.getScheme())) { + String[] parts = uri.toString().split(JAR_URI_SEPARATOR); + FileSystem fileSystem = FileSystems.newFileSystem(URI.create(parts[0]), emptyMap()); + return new CloseablePath(fileSystem.getPath(parts[1]), fileSystem); + } + return new CloseablePath(Paths.get(uri), NULL_CLOSEABLE); + } + + private CloseablePath(Path path, Closeable delegate) { + this.path = path; + this.delegate = delegate; + } public Path getPath() { return path; diff --git a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/CloseablePathProvider.java b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/CloseablePathProvider.java deleted file mode 100644 index 5afb95cfe59..00000000000 --- a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/CloseablePathProvider.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2015-2016 the original author or authors. - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution and is available at - * - * http://www.eclipse.org/legal/epl-v10.html - */ - -package org.junit.platform.commons.util; - -import static java.util.Collections.emptyMap; -import static org.junit.platform.commons.util.CloseablePath.NULL_CLOSEABLE; - -import java.io.IOException; -import java.net.URI; -import java.nio.file.FileSystem; -import java.nio.file.FileSystems; -import java.nio.file.Paths; - -interface CloseablePathProvider { - - String JAR_URI_SCHEME = "jar"; - String JAR_URI_SEPARATOR = "!"; - - CloseablePathProvider JAR_PATH_PROVIDER = uri -> { - String[] parts = uri.toString().split(JAR_URI_SEPARATOR); - FileSystem fileSystem = FileSystems.newFileSystem(URI.create(parts[0]), emptyMap()); - return new CloseablePath(fileSystem.getPath(parts[1]), fileSystem); - }; - - CloseablePathProvider REGULAR_PATH_PROVIDER = uri -> new CloseablePath(Paths.get(uri), NULL_CLOSEABLE); - - static CloseablePathProvider create(String uriScheme) { - return JAR_URI_SCHEME.equals(uriScheme) ? JAR_PATH_PROVIDER : REGULAR_PATH_PROVIDER; - } - - CloseablePath toCloseablePath(URI uri) throws IOException; - -}