Indentations break the feed.
[SquirrelJME.git] / buildSrc / src / main / java / cc / squirreljme / plugin / multivm / VMFullSuiteDepends.java
blob8a183f6a5e078dd2e478eb26c366b8a8b362c460
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.SquirrelJMEPluginConfiguration;
13 import cc.squirreljme.plugin.multivm.ident.SourceTargetClassifier;
14 import java.util.Arrays;
15 import java.util.Collection;
16 import java.util.Collections;
17 import java.util.LinkedHashSet;
18 import java.util.List;
19 import java.util.concurrent.Callable;
20 import org.gradle.api.Project;
21 import org.gradle.api.Task;
22 import org.gradle.api.tasks.SourceSet;
24 /**
25 * Dependencies used for the full SquirrelJME suite.
27 * @since 2020/10/17
29 public class VMFullSuiteDepends
30 implements Callable<Iterable<Task>>
32 /** The task to execute for. */
33 protected final Task task;
35 /** The classifier target used. */
36 protected final SourceTargetClassifier classifier;
38 /**
39 * Initializes the dependency grabber.
41 * @param __task The task to run off.
42 * @param __classifier The classifier used.
43 * @throws NullPointerException On null arguments.
44 * @since 2020/10/17
46 public VMFullSuiteDepends(Task __task, SourceTargetClassifier __classifier)
47 throws NullPointerException
49 if (__task == null || __classifier == null)
50 throw new NullPointerException("NARG");
52 this.task = __task;
53 this.classifier = __classifier;
56 /**
57 * {@inheritDoc}
58 * @since 2020/10/17
60 @Override
61 public Iterable<Task> call()
63 Project root = this.task.getProject().getRootProject();
64 Collection<Task> tasks = new LinkedHashSet<>();
66 // We need the emulator to be built and working before we can actually
67 // run our full suite accordingly
68 for (String emulatorProject : this.classifier.getVmType()
69 .emulatorProjects(this.classifier.getBangletVariant()))
71 Task emulJar = root.project(emulatorProject).getTasks()
72 .findByName("jar");
73 if (emulJar != null)
74 tasks.add(emulJar);
77 // Which source sets should be used
78 List<String> sourceSets;
79 if (!this.classifier.isMainSourceSet())
80 sourceSets = Arrays.asList(SourceSet.MAIN_SOURCE_SET_NAME,
81 this.classifier.getSourceSet());
82 else
83 sourceSets = Collections.singletonList(
84 this.classifier.getSourceSet());
86 // Go through every single project, and try to use it as a dependency
87 for (Project project : root.getAllprojects())
89 // Ignore non-SquirrelJME projects
90 SquirrelJMEPluginConfiguration config =
91 SquirrelJMEPluginConfiguration.configurationOrNull(project);
92 if (config == null)
93 continue;
95 // Include whatever libraries are needed for the source set
96 for (String sourceSet : sourceSets)
98 // Find the associated library task
99 Task libTask = project.getTasks().findByName(TaskInitialization
100 .task("lib",
101 this.classifier.withSourceSet(sourceSet)));
102 if (libTask == null)
103 continue;
105 // Use all of their dependencies, if not yet added
106 for (VMLibraryTask subDep : new VMRunDependencies(
107 libTask.getProject(),
108 this.classifier.withSourceSet(sourceSet))
109 .call())
110 tasks.add(subDep);
114 return Collections.unmodifiableCollection(tasks);