private StartupConfiguration newStartupConfigWithModularPath()

in maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java [1828:1919]


    private StartupConfiguration newStartupConfigWithModularPath(
            @Nonnull ClassLoaderConfiguration classLoaderConfiguration,
            @Nonnull ProviderInfo providerInfo,
            @Nonnull ResolvePathResultWrapper moduleDescriptor,
            @Nonnull DefaultScanResult scanResult,
            @Nonnull String javaHome,
            @Nonnull TestClassPath testClasspathWrapper)
            throws MojoExecutionException, IOException {
        boolean isMainDescriptor = moduleDescriptor.isMainModuleDescriptor();
        JavaModuleDescriptor javaModuleDescriptor =
                moduleDescriptor.getResolvePathResult().getModuleDescriptor();
        SortedSet<String> packages = new TreeSet<>();

        Classpath testClasspath = testClasspathWrapper.toClasspath();
        Set<Artifact> providerArtifacts = providerInfo.getProviderClasspath();
        String providerName = providerInfo.getProviderName();
        Classpath providerClasspath = classpathCache.getCachedClassPath(providerName);
        if (providerClasspath == null) {
            providerClasspath = classpathCache.setCachedClasspath(providerName, providerArtifacts);
        }

        final ProviderRequirements providerRequirements;
        final Classpath testModulepath;
        if (isMainDescriptor) {
            providerRequirements = new ProviderRequirements(true, true, false);
            ResolvePathsRequest<String> req = ResolvePathsRequest.ofStrings(testClasspath.getClassPath())
                    .setIncludeAllProviders(true)
                    .setJdkHome(javaHome)
                    .setIncludeStatic(true)
                    .setModuleDescriptor(javaModuleDescriptor);

            ResolvePathsResult<String> result = getLocationManager().resolvePaths(req);
            for (Entry<String, Exception> entry : result.getPathExceptions().entrySet()) {
                // Probably JDK version < 9. Other known causes: passing a non-jar or a corrupted jar.
                getConsoleLogger().warning("Exception for '" + entry.getKey() + "'.", entry.getValue());
            }

            testClasspath = new Classpath(result.getClasspathElements());
            testModulepath = new Classpath(result.getModulepathElements().keySet());

            for (String className : scanResult.getClasses()) {
                packages.add(substringBeforeLast(className, "."));
            }
        } else {
            providerRequirements = new ProviderRequirements(true, false, true);
            testModulepath = testClasspath;
            testClasspath = emptyClasspath();
        }

        getConsoleLogger().debug("main module descriptor name: " + javaModuleDescriptor.name());

        ModularClasspath modularClasspath = new ModularClasspath(
                javaModuleDescriptor.name(),
                testModulepath.getClassPath(),
                packages,
                isMainDescriptor ? getTestClassesDirectory() : null,
                isMainDescriptor);

        Artifact[] additionalInProcArtifacts = {
            getCommonArtifact(),
            getBooterArtifact(),
            getExtensionsArtifact(),
            getApiArtifact(),
            getSpiArtifact(),
            getLoggerApiArtifact(),
            getSurefireSharedUtilsArtifact()
        };
        Set<Artifact> inProcArtifacts = retainInProcArtifactsUnique(providerArtifacts, additionalInProcArtifacts);
        Classpath inProcClasspath = createInProcClasspath(providerClasspath, inProcArtifacts);

        ModularClasspathConfiguration classpathConfiguration = new ModularClasspathConfiguration(
                modularClasspath,
                testClasspath,
                providerClasspath,
                inProcClasspath,
                effectiveIsEnableAssertions(),
                isChildDelegation());

        getConsoleLogger().debug(testClasspath.getLogMessage("test classpath:"));
        getConsoleLogger().debug(testModulepath.getLogMessage("test modulepath:"));
        getConsoleLogger().debug(providerClasspath.getLogMessage("provider classpath:"));
        getConsoleLogger().debug(testClasspath.getCompactLogMessage("test(compact) classpath:"));
        getConsoleLogger().debug(testModulepath.getCompactLogMessage("test(compact) modulepath:"));
        getConsoleLogger().debug(providerClasspath.getCompactLogMessage("provider(compact) classpath:"));
        getConsoleLogger().debug(inProcClasspath.getLogMessage("in-process classpath:"));
        getConsoleLogger().debug(inProcClasspath.getCompactLogMessage("in-process(compact) classpath:"));

        ProcessCheckerType processCheckerType = ProcessCheckerType.toEnum(getEnableProcessChecker());
        List<String[]> jpmsArgs = providerInfo.getJpmsArguments(providerRequirements);
        return new StartupConfiguration(
                providerName, classpathConfiguration, classLoaderConfiguration, processCheckerType, jpmsArgs);
    }