2018-12-23 18:37:09 +00:00
|
|
|
/*
|
|
|
|
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
|
|
|
*
|
2021-07-10 20:50:53 +00:00
|
|
|
* Copyright (c) 2018-2021 FabricMC
|
2018-12-23 18:37:09 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package net.fabricmc.loom.task;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
2019-11-02 20:23:27 +00:00
|
|
|
import org.gradle.api.Project;
|
|
|
|
import org.gradle.api.tasks.JavaExec;
|
|
|
|
|
2020-12-24 20:58:30 +00:00
|
|
|
import net.fabricmc.loom.configuration.ide.RunConfig;
|
2021-07-26 19:08:03 +00:00
|
|
|
import net.fabricmc.loom.util.Constants;
|
2019-11-02 20:23:27 +00:00
|
|
|
|
2019-05-10 11:32:11 +00:00
|
|
|
public abstract class AbstractRunTask extends JavaExec {
|
2021-03-03 21:22:10 +00:00
|
|
|
private final RunConfig config;
|
2019-11-02 20:23:27 +00:00
|
|
|
|
2021-03-03 21:22:10 +00:00
|
|
|
public AbstractRunTask(Function<Project, RunConfig> configProvider) {
|
2019-11-02 20:23:27 +00:00
|
|
|
super();
|
2021-07-26 19:08:03 +00:00
|
|
|
setGroup(Constants.TaskGroup.FABRIC);
|
2021-03-03 21:22:10 +00:00
|
|
|
this.config = configProvider.apply(getProject());
|
2021-01-26 18:08:19 +00:00
|
|
|
|
2021-03-03 21:22:10 +00:00
|
|
|
setClasspath(config.sourceSet.getRuntimeClasspath());
|
2021-10-24 13:11:01 +00:00
|
|
|
args(config.programArgs);
|
2021-12-17 15:37:00 +00:00
|
|
|
getMainClass().set(config.mainClass);
|
2019-11-02 20:23:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void exec() {
|
2021-01-29 18:04:39 +00:00
|
|
|
setWorkingDir(new File(getProject().getRootDir(), config.runDir));
|
2019-11-02 20:23:27 +00:00
|
|
|
|
|
|
|
super.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setWorkingDir(File dir) {
|
|
|
|
if (!dir.exists()) {
|
|
|
|
dir.mkdirs();
|
|
|
|
}
|
|
|
|
|
|
|
|
super.setWorkingDir(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<String> getJvmArgs() {
|
|
|
|
List<String> superArgs = super.getJvmArgs();
|
|
|
|
List<String> args = new ArrayList<>(superArgs != null ? superArgs : Collections.emptyList());
|
2021-10-24 13:11:01 +00:00
|
|
|
args.addAll(config.vmArgs);
|
2019-11-02 20:23:27 +00:00
|
|
|
return args;
|
|
|
|
}
|
2018-12-23 18:37:09 +00:00
|
|
|
}
|