Limit how often GC can be run.
[SquirrelJME.git] / buildSrc / src / main / java / cc / squirreljme / plugin / multivm / VMEmulatorDependencies.java
blob370d6fc7391d36250c84d6bdc6da76873a00089c
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // 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 cc.squirreljme.plugin.multivm.ident.SourceTargetClassifier;
13 import cc.squirreljme.plugin.multivm.ident.TargetClassifier;
14 import java.util.ArrayList;
15 import java.util.LinkedHashSet;
16 import java.util.Set;
17 import java.util.concurrent.Callable;
18 import org.gradle.api.Project;
19 import org.gradle.api.Task;
20 import org.gradle.api.tasks.SourceSet;
21 import org.gradle.api.tasks.TaskContainer;
23 /**
24 * This class is used to provide the dependency lookup for the emulator
25 * backend, this is so the emulator is built.
27 * @since 2020/08/16
29 public final class VMEmulatorDependencies
30 implements Callable<Iterable<Task>>
32 /** The root project. */
33 protected final Project project;
35 /** The target classifier used. */
36 protected final TargetClassifier targetClassifier;
38 /**
39 * Initializes the dependencies.
41 * @param __project The project to reference.
42 * @param __classifier The classifier used.
43 * @throws NullPointerException On null arguments.
44 * @since 2020/08/16
46 public VMEmulatorDependencies(Project __project,
47 TargetClassifier __classifier)
48 throws NullPointerException
50 if (__project == null || __classifier == null)
51 throw new NullPointerException("NARG");
53 this.project = __project.getRootProject();
54 this.targetClassifier = __classifier;
57 /**
58 * {@inheritDoc}
59 * @since 2020/08/16
60 * @return
62 @Override
63 public Iterable<Task> call()
65 Project root = this.project;
67 // Need tasks for all the source emulators
68 Set<Task> rv = new LinkedHashSet<>();
69 for (String emulatorProject : this.targetClassifier.getVmType()
70 .emulatorProjects(this.targetClassifier.getBangletVariant()))
72 Project emuProject = root.project(emulatorProject);
73 TaskContainer emuTasks = emuProject.getTasks();
74 TaskContainer emuBase =
75 root.project(":emulators:emulator-base").getTasks();
77 // Build projects that are needed to run the emulator
78 for (ProjectAndTaskName task : VMHelpers.runClassTasks(emuProject,
79 new SourceTargetClassifier(SourceSet.MAIN_SOURCE_SET_NAME,
80 this.targetClassifier)))
82 Project taskProject = root.project(task.project);
84 // We need to depend on the classes and JAR for the emulator
85 // projects
86 rv.add(taskProject.getTasks().getByName("classes"));
87 rv.add(taskProject.getTasks().getByName("jar"));
90 // Add base emulator projects and such, so that they are forced
91 rv.add(emuTasks.getByName("jar"));
92 rv.add(emuTasks.getByName("assemble"));
93 rv.add(emuBase.getByName("jar"));
94 rv.add(emuBase.getByName("assemble"));
95 if (null != emuBase.findByName("assembleDebug"))
96 rv.add(emuBase.getByName("assembleDebug"));
97 if (null != emuBase.findByName("assembleRelease"))
98 rv.add(emuBase.getByName("assembleRelease"));
101 return new ArrayList<>(rv);