
org.junit.gen5.console.tasks.ClasspathEntriesParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of junit-console Show documentation
Show all versions of junit-console Show documentation
Module "junit-console" of JUnit 5.
The newest version!
/*
* 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.gen5.console.tasks;
import static java.util.stream.Collectors.toCollection;
import java.io.File;
import java.net.URL;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import org.junit.gen5.commons.JUnitException;
/**
* @since 5.0
*/
class ClasspathEntriesParser {
private static final String PATH_SEPARATOR_PATTERN = Pattern.quote(File.pathSeparator);
URL[] toURLs(List additionalClasspathEntries) {
return split(additionalClasspathEntries).map(this::toURL).toArray(URL[]::new);
}
Set toDirectories(List additionalClasspathEntries) {
// @formatter:off
return split(additionalClasspathEntries)
.filter(File::isDirectory)
.collect(toCollection(LinkedHashSet::new));
// @formatter:on
}
private Stream split(List additionalClasspathEntries) {
// @formatter:off
return additionalClasspathEntries.stream()
.map(entry -> entry.split(PATH_SEPARATOR_PATTERN))
.flatMap(Arrays::stream)
.map(File::new);
// @formatter:on
}
private URL toURL(File file) {
try {
return file.toURI().toURL();
}
catch (Exception ex) {
throw new JUnitException("Invalid classpath entry: " + file, ex);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy