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 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 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 this is a single source set ROM, then the dependencies act a
111 boolean isSingleSourceSet
= __classifier
.getVmType()
112 .isSingleSourceSetRom(__classifier
.getBangletVariant());
114 // Our ROM is only in our source set, so we do not include the
115 // libraries which are part of the main or other source set at all
116 // The build should go a bit faster for this as it is not waiting
117 // for something to happen
118 if (!isSingleSourceSet
)
120 // If we are not on the main source set, we need to include
121 // everything the main source set has. For tests for example, we
122 // need the main libraries to even test them properly.
123 if (!__classifier
.isMainSourceSet())
124 VMRomDependencies
.__libraries(__task
,
125 __classifier
.withSourceSet(SourceSet
.MAIN_SOURCE_SET_NAME
),
128 // If we are using tests, then we need to include all the test
130 if (__classifier
.isTestSourceSet())
131 VMRomDependencies
.__libraries(__task
,
132 __classifier
.withSourceSet(
133 VMHelpers
.TEST_FIXTURES_SOURCE_SET_NAME
), __result
);
136 // Go through all projects and map dependencies
137 for (Project project
: __task
.getProject().getRootProject()
140 // Only consider SquirrelJME projects
141 SquirrelJMEPluginConfiguration config
=
142 SquirrelJMEPluginConfiguration
.configurationOrNull(project
);
146 // Only consider library tasks of this given type
147 Task task
= project
.getTasks().findByName(TaskInitialization
148 .task("lib", __classifier
));
149 if (!(task
instanceof VMLibraryTask
))
153 __result
.put(new ProjectAndSourceSet(task
.getProject(),
154 __classifier
.getSourceSet()), (VMLibraryTask
)task
);