2727import org .checkerframework .checker .nullness .qual .NonNull ;
2828import org .gradle .api .Action ;
2929import org .gradle .api .Named ;
30+ import org .gradle .api .Project ;
3031import org .gradle .api .file .ConfigurableFileCollection ;
3132import org .gradle .api .file .DirectoryProperty ;
3233import org .gradle .api .file .ProjectLayout ;
3839import org .gradle .api .tasks .Nested ;
3940import org .gradle .api .tasks .Optional ;
4041import org .gradle .api .tasks .SourceSet ;
42+ import org .gradle .api .tasks .SourceSetContainer ;
4143import org .gradle .jvm .toolchain .JavaLanguageVersion ;
4244import org .gradle .process .CommandLineArgumentProvider ;
4345import org .spongepowered .gradle .vanilla .internal .Constants ;
4648import java .util .ArrayList ;
4749import java .util .Collection ;
4850import java .util .Collections ;
51+ import java .util .HashMap ;
4952import java .util .List ;
53+ import java .util .Map ;
5054import java .util .Objects ;
5155
5256import javax .inject .Inject ;
@@ -70,10 +74,12 @@ public class RunConfiguration implements Named {
7074 private final MapProperty <String , String > parameterTokens ;
7175 private final Property <Boolean > requiresAssetsAndNatives ;
7276 private final Property <SourceSet > ideaSourceSet ;
77+ private final Property <SourceSet > sourceSet ;
7378 private final Property <JavaLanguageVersion > targetVersion ;
79+ private Map <String , Object > environment = new HashMap <>();
7480
7581 @ Inject
76- public RunConfiguration (final String name , final ProjectLayout layout , final ObjectFactory objects ) {
82+ public RunConfiguration (final String name , final ProjectLayout layout , final ObjectFactory objects , final Project project ) {
7783 this .name = name ;
7884 this .displayName = objects .property (String .class );
7985
@@ -89,8 +95,12 @@ public RunConfiguration(final String name, final ProjectLayout layout, final Obj
8995 this .parameterTokens = objects .mapProperty (String .class , String .class );
9096 this .requiresAssetsAndNatives = objects .property (Boolean .class ).convention (false );
9197 this .ideaSourceSet = objects .property (SourceSet .class );
98+ this .sourceSet = objects .property (SourceSet .class )
99+ .convention (project .getExtensions ().getByType (SourceSetContainer .class ).named (SourceSet .MAIN_SOURCE_SET_NAME ));
92100 this .targetVersion = objects .property (JavaLanguageVersion .class );
93101
102+ this .classpath .from (this .sourceSet .map (SourceSet ::getOutput ), this .sourceSet .map (SourceSet ::getRuntimeClasspath ));
103+
94104 // Apply global environment here
95105 this .parameterTokens .put (ClientRunParameterTokens .LAUNCHER_NAME , Constants .NAME );
96106 this .parameterTokens .put (ClientRunParameterTokens .LAUNCHER_VERSION , Constants .VERSION );
@@ -141,6 +151,52 @@ public Property<Boolean> getRequiresAssetsAndNatives() {
141151 return this .requiresAssetsAndNatives ;
142152 }
143153
154+ public Map <String , String > getActualEnvironment () {
155+ final Map <String , String > actual = new HashMap <>();
156+ for (Map .Entry <String , Object > entry : this .getEnvironment ().entrySet ()) {
157+ actual .put (entry .getKey (), String .valueOf (entry .getValue ()));
158+ }
159+ return actual ;
160+ }
161+
162+ /**
163+ * The environment variables to use for the process.
164+ *
165+ * @return The environment.
166+ */
167+ @ Internal
168+ public Map <String , Object > getEnvironment () {
169+ return this .environment ;
170+ }
171+
172+ /**
173+ * Sets the environment variable to use for the process.
174+ *
175+ * @param environment The environment variables.
176+ */
177+ public void setEnvironment (Map <String , ?> environment ) {
178+ this .environment = new HashMap <>(Objects .requireNonNull (environment , "environment" ));
179+ }
180+
181+ /**
182+ * Adds an environment variable to the environment for this process.
183+ *
184+ * @param name The name of the variable.
185+ * @param value The value for the variable.
186+ */
187+ public void environment (String name , Object value ) {
188+ this .getEnvironment ().put (Objects .requireNonNull (name , "name" ), Objects .requireNonNull (value , "value" ));
189+ }
190+
191+ /**
192+ * Adds some environment variables to the environment for this process.
193+ *
194+ * @param environment The environment variables.
195+ */
196+ public void environment (Map <String , ?> environment ) {
197+ this .getEnvironment ().putAll (Objects .requireNonNull (environment , "environment" ));
198+ }
199+
144200 /**
145201 * Get the classpath used to run this game.
146202 *
@@ -156,13 +212,26 @@ public ConfigurableFileCollection getClasspath() {
156212 *
157213 * @return the source set to use
158214 * @since 0.2
215+ * @deprecated Use {@link #getSourceSet()} instead.
159216 */
217+ @ Deprecated
160218 @ Input
161219 @ Optional
162220 public Property <SourceSet > getIdeaRunSourceSet () {
163221 return this .ideaSourceSet ;
164222 }
165223
224+ /**
225+ * Get the source set to use in the classpath and IDE runs.
226+ *
227+ * @return the source set to use
228+ * @since 0.2.1
229+ */
230+ @ Input
231+ public Property <SourceSet > getSourceSet () {
232+ return this .sourceSet ;
233+ }
234+
166235 @ Nested
167236 public List <CommandLineArgumentProvider > getAllArgumentProviders () {
168237 return this .allArgs ;
0 commit comments