-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Java 9 module path scanning and selection support
This commit includes the service providing interface `ModuleClassFinder` in package `org.junit.platform.commons.util`. Its default implementation will rely on Java 9 features introduced by the Java Platform Module System. The usage of the new module selection options on Java 8 will result in no-op as there is no module system in place. Summary of changes: * Add ModuleSelector to the Platform discovery package. * Add ModuleSelector to the Jupiter discovery package. * Add ModuleSelector to the Vintage discovery package. * Add ModuleUtils to the platform commons utilities toolbox. * Add option `--select-module` to the console launcher. * Add option `--scan-module-path` to the console launcher. Addresses #425
- Loading branch information
Showing
19 changed files
with
536 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
[[release-notes-5.1.0]] | ||
=== 5.1.0 | ||
|
||
*Date of Release:* ? | ||
|
||
*Scope:* ? | ||
|
||
|
||
[[release-notes-5.1.0-junit-platform]] | ||
==== JUnit Platform | ||
|
||
===== Bug Fixes | ||
|
||
? | ||
|
||
===== Deprecations and Breaking Changes | ||
|
||
? | ||
|
||
===== New Features and Improvements | ||
|
||
* Added support of `--scan-module-path` and `--select-module` launcher options. | ||
|
||
|
||
[[release-notes-5.1.0-junit-jupiter]] | ||
==== JUnit Jupiter | ||
|
||
|
||
===== Bug Fixes | ||
|
||
? | ||
|
||
===== Deprecations and Breaking Changes | ||
|
||
? | ||
|
||
===== New Features and Improvements | ||
|
||
* Added support of `--scan-module-path` and `--select-module` launcher options. | ||
|
||
|
||
[[release-notes-5.1.0-junit-vintage]] | ||
==== JUnit Vintage | ||
|
||
===== Bug Fixes | ||
|
||
? | ||
|
||
===== Deprecations and Breaking Changes | ||
|
||
? | ||
===== New Features and Improvements | ||
|
||
* Added support of `--scan-module-path` and `--select-module` launcher options. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
junit-platform-commons/src/main/java/org/junit/platform/commons/util/ModuleClassFinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2015-2017 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 v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.platform.commons.util; | ||
|
||
import static org.apiguardian.api.API.Status.INTERNAL; | ||
|
||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
/** | ||
* Class finder service providing interface. | ||
* | ||
* <h3>DISCLAIMER</h3> | ||
* | ||
* <p>These utilities are intended solely for usage within the JUnit framework | ||
* itself. <strong>Any usage by external parties is not supported.</strong> | ||
* Use at your own risk! | ||
* | ||
* @since 1.1 | ||
*/ | ||
@API(status = INTERNAL, since = "1.1") | ||
public interface ModuleClassFinder { | ||
|
||
/** | ||
* Special name indicating a search for all classes in all modules of the module-path. | ||
*/ | ||
String ALL_MODULE_PATH = "ALL-MODULE-PATH"; | ||
|
||
/** | ||
* Return list of classes of the passed-in module that contains potential testable methods. | ||
* | ||
* @param moduleName name of the module to inspect or {@code ALL-MODULE-PATH} | ||
* @param classTester filter to apply to each class instance | ||
* @param classNameFilter filter to apply to the fully qualified class name | ||
* @return list of classes | ||
* | ||
* @see #ALL_MODULE_PATH | ||
*/ | ||
List<Class<?>> findAllClassesInModule(String moduleName, Predicate<Class<?>> classTester, | ||
Predicate<String> classNameFilter); | ||
} |
84 changes: 84 additions & 0 deletions
84
junit-platform-commons/src/main/java/org/junit/platform/commons/util/ModuleUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright 2015-2017 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 v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.platform.commons.util; | ||
|
||
import static org.apiguardian.api.API.Status.INTERNAL; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.ServiceLoader; | ||
import java.util.function.Predicate; | ||
|
||
import org.apiguardian.api.API; | ||
import org.junit.platform.commons.logging.Logger; | ||
import org.junit.platform.commons.logging.LoggerFactory; | ||
|
||
/** | ||
* Collection of utilities for working with modules. | ||
* | ||
* <h3>DISCLAIMER</h3> | ||
* | ||
* <p>These utilities are intended solely for usage within the JUnit framework | ||
* itself. <strong>Any usage by external parties is not supported.</strong> | ||
* Use at your own risk! | ||
* | ||
* @since 1.1 | ||
*/ | ||
@API(status = INTERNAL, since = "1.1") | ||
public final class ModuleUtils { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(ModuleUtils.class); | ||
|
||
///CLOVER:OFF | ||
private ModuleUtils() { | ||
/* no-op */ | ||
} | ||
///CLOVER:ON | ||
|
||
/** | ||
* Convenient short-cut for finding all classes in all modules that are on the module-path. | ||
*/ | ||
public static List<Class<?>> findAllClassesInModulepath(Predicate<Class<?>> classTester, | ||
Predicate<String> classNameFilter) { | ||
return findAllClassesInModule(ModuleClassFinder.ALL_MODULE_PATH, classTester, classNameFilter); | ||
} | ||
|
||
/** | ||
* Find all classes in the specified module. | ||
* | ||
* @param moduleName name of the module to inspect or {@code ALL-MODULE-PATH} | ||
* @param classTester filter to apply to each class instance | ||
* @param classNameFilter filter to apply to the fully qualified class name | ||
* @return list of classes matching the passed-in criteria | ||
*/ | ||
public static List<Class<?>> findAllClassesInModule(String moduleName, Predicate<Class<?>> classTester, | ||
Predicate<String> classNameFilter) { | ||
Preconditions.notBlank(moduleName, "module name must not be null or blank"); | ||
Preconditions.notNull(classTester, "class tester must not be null"); | ||
Preconditions.notNull(classNameFilter, "class name filter must not be null"); | ||
|
||
ClassLoader classLoader = ClassLoaderUtils.getDefaultClassLoader(); | ||
List<Class<?>> classes = new ArrayList<>(); | ||
|
||
logger.config(() -> "Loading auto-detected class finders..."); | ||
int serviceCounter = 0; | ||
for (ModuleClassFinder classFinder : ServiceLoader.load(ModuleClassFinder.class, classLoader)) { | ||
classes.addAll(classFinder.findAllClassesInModule(moduleName, classTester, classNameFilter)); | ||
serviceCounter++; | ||
} | ||
if (serviceCounter == 0) { | ||
logger.warn(() -> "No module class finder service registered! No test classes found."); | ||
} | ||
return Collections.unmodifiableList(classes); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.