1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the GNU General Public License v3+, or later.
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 cc
.squirreljme
.plugin
.util
.ProjectAndSourceSet
;
15 import java
.util
.ArrayList
;
16 import java
.util
.LinkedHashMap
;
18 import java
.util
.concurrent
.Callable
;
19 import org
.gradle
.api
.Project
;
20 import org
.gradle
.api
.Task
;
21 import org
.gradle
.api
.tasks
.SourceSet
;
24 * Dependencies for building the ROM, will depend on every library that exists.
28 public class VMRomDependencies
29 implements Callable
<Iterable
<VMLibraryTask
>>
31 /** The task to execute for. */
32 protected final VMRomTask task
;
34 /** The classifier used. */
35 protected final SourceTargetClassifier classifier
;
38 * Initializes the ROM dependency task.
40 * @param __task The task to use.
41 * @param __classifier The classifier used.
42 * @throws NullPointerException on null arguments.
45 public VMRomDependencies(VMRomTask __task
,
46 SourceTargetClassifier __classifier
)
47 throws NullPointerException
49 if (__task
== null || __classifier
== null)
50 throw new NullPointerException("NARG");
53 this.classifier
= __classifier
;
61 public Iterable
<VMLibraryTask
> call()
63 return VMRomDependencies
.libraries(this.task
, this.classifier
);
67 * Returns all the libraries that should make up the ROM.
69 * @param __task The task to get from.
70 * @param __classifier The classifier used.
71 * @return The libraries that are used as a dependency to build the ROM.
72 * @throws NullPointerException On null arguments.
75 public static Iterable
<VMLibraryTask
> libraries(Task __task
,
76 SourceTargetClassifier __classifier
)
77 throws NullPointerException
79 if (__task
== null || __classifier
== null)
80 throw new NullPointerException("NARG");
82 // Where all the libraries will go
83 Map
<ProjectAndSourceSet
, VMLibraryTask
> result
=
84 new LinkedHashMap
<>();
86 // This could be recursive
87 VMRomDependencies
.__libraries(__task
, __classifier
, result
);
89 return new ArrayList
<>(result
.values());
93 * Returns all the mapped libraries.
95 * @param __task The task to add for.
96 * @param __classifier The classifier used.
97 * @param __result Where all the results are stored.
98 * @throws NullPointerException On null arguments.
101 private static void __libraries(Task __task
,
102 SourceTargetClassifier __classifier
,
103 Map
<ProjectAndSourceSet
, VMLibraryTask
> __result
)
104 throws NullPointerException
106 if (__task
== null || __classifier
== null || __result
== null)
107 throw new NullPointerException("NARG");
109 // If we are not on the main source set, we need to include everything
110 // the main source set has. For tests for example, we need the main
111 // libraries to even test them properly.
112 if (!__classifier
.isMainSourceSet())
113 VMRomDependencies
.__libraries(__task
,
114 __classifier
.withSourceSet(SourceSet
.MAIN_SOURCE_SET_NAME
),
117 // If we are using tests, then we need to include all the test
119 if (__classifier
.isTestSourceSet())
120 VMRomDependencies
.__libraries(__task
, __classifier
.withSourceSet(
121 VMHelpers
.TEST_FIXTURES_SOURCE_SET_NAME
), __result
);
123 // Go through all projects and map dependencies
124 for (Project project
: __task
.getProject().getRootProject()
127 // Only consider SquirrelJME projects
128 SquirrelJMEPluginConfiguration config
=
129 SquirrelJMEPluginConfiguration
.configurationOrNull(project
);
133 // Only consider library tasks of this given type
134 Task task
= project
.getTasks().findByName(TaskInitialization
135 .task("lib", __classifier
));
136 if (!(task
instanceof VMLibraryTask
))
140 __result
.put(new ProjectAndSourceSet(task
.getProject(),
141 __classifier
.getSourceSet()), (VMLibraryTask
)task
);