Indentations break the feed.
[SquirrelJME.git] / buildSrc / src / main / java / cc / squirreljme / plugin / multivm / VMTestFrameworkWorkerConfigurationAction.java
blob097c2066f43fe35f2e71ee7a3706dc319824fd0f
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // Multi-Phasic Applications: SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc.squirreljme.plugin.multivm;
12 import java.io.File;
13 import java.net.URL;
14 import java.net.URLClassLoader;
15 import java.nio.file.Paths;
16 import java.util.ArrayList;
17 import java.util.Arrays;
18 import java.util.LinkedHashSet;
19 import java.util.Set;
20 import java.util.regex.Pattern;
21 import org.gradle.api.Action;
22 import org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestFramework;
23 import org.gradle.api.invocation.Gradle;
24 import org.gradle.internal.os.OperatingSystem;
25 import org.gradle.process.internal.worker.WorkerProcessBuilder;
27 /**
28 * Action to create test workers.
30 * @since 2022/09/11
32 public class VMTestFrameworkWorkerConfigurationAction
33 implements Action<WorkerProcessBuilder>
35 /**
36 * {@inheritDoc}
37 * @since 2022/09/11
39 @Override
40 public void execute(WorkerProcessBuilder __builder)
42 // Are we on Windows?
43 boolean isWindows = (OperatingSystem.current() ==
44 OperatingSystem.WINDOWS);
46 // Use the class paths for ourselves and the system class path which
47 // should be Gradle itself... this should make it so that the worker
48 // process is able to actually load our test framework classes
49 Set<URL> classPathUrls = new LinkedHashSet<>();
50 for (ClassLoader classLoader : new ClassLoader[]{
51 this.getClass().getClassLoader(),
52 Gradle.class.getClassLoader(),
53 JUnitPlatformTestFramework.class.getClassLoader(),
54 ClassLoader.getSystemClassLoader()})
55 if (classLoader instanceof URLClassLoader)
56 classPathUrls.addAll(Arrays.asList(
57 ((URLClassLoader)classLoader).getURLs()));
59 // Now we need to load up all of these URLs into the class path if
60 // we can so the classes are actually known to the worker
61 Set<File> classPath = new LinkedHashSet<>();
62 for (URL url : classPathUrls)
63 if ("file".equals(url.getProtocol()))
65 String pathlet = url.getPath();
67 // If we are on Windows and our path starts with a slash
68 // followed by a drive letter we need to remove the slash since
69 // otherwise it is not a valid path
70 // /C:/cutes
71 // 012345678
72 if (isWindows && pathlet.length() >= 3 &&
73 pathlet.charAt(0) == '/' &&
74 Character.isAlphabetic(pathlet.charAt(1)) &&
75 pathlet.charAt(2) == ':' &&
76 pathlet.charAt(3) == '/')
77 pathlet = pathlet.substring(1);
79 classPath.add(Paths.get(pathlet).toFile());
82 // Add our Java given class path as well, just in case
83 for (String splice : System.getProperty("java.class.path")
84 .split(Pattern.quote(File.pathSeparator)))
85 classPath.add(Paths.get(splice).toFile());
87 // Use these both
88 __builder.setImplementationClasspath(
89 new ArrayList<>(classPathUrls));
90 __builder.applicationClasspath(classPath);