Skip to content

Commit c55469a

Browse files
committed
Updated to include
launchTarget configuration
1 parent fb27366 commit c55469a

3 files changed

Lines changed: 44 additions & 3 deletions

File tree

src/main/java/org/mangorage/mangobotgradle/MangoBotGradlePlugin.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ public void apply(Project project) {
8686
t.setTransitive(false);
8787
});
8888

89+
var launchCfg = project.getConfigurations().create("launchtarget", t -> {
90+
t.setVisible(true);
91+
t.setTransitive(false);
92+
});
93+
8994
var plugin = project.getConfigurations().create("plugin", t -> {
9095
t.setVisible(true);
9196
t.setTransitive(false);
@@ -101,7 +106,7 @@ public void apply(Project project) {
101106
t.setVisible(true);
102107
});
103108

104-
project.getConfigurations().findByName("implementation").extendsFrom(botCfg, plugin, library, embeddedLibrary);
109+
project.getConfigurations().findByName("implementation").extendsFrom(botCfg, launchCfg, plugin, library, embeddedLibrary);
105110

106111
project.afterEvaluate(a -> {
107112
Objects.requireNonNull(config.getJarTask(), "jarTask cannot be null!");

src/main/java/org/mangorage/mangobotgradle/tasks/RunInstallerAndBootTask.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import org.mangorage.mangobotgradle.RunConfig;
77

88
import javax.inject.Inject;
9+
import java.io.File;
10+
import java.nio.file.Path;
911
import java.util.ArrayList;
1012
import java.util.List;
1113

@@ -15,13 +17,33 @@ public RunInstallerAndBootTask(RunConfig runConfig) {
1517
setGroup(runConfig.getGroup());
1618
setDescription("Runs the bot");
1719

18-
ArrayList<Task> deps = new ArrayList<>(getProject().getTasksByName("copyTask", false));
20+
ArrayList<Task> deps = new ArrayList<>();
21+
deps.addAll(getProject().getTasksByName("copyTask", false));
22+
deps.addAll(getProject().getTasksByName("setupPlugins", false));
1923

2024
setDependsOn(deps);
2125
mustRunAfter(deps);
2226

2327
setWorkingDir(getProject().file("build/run/"));
24-
setArgs(runConfig.getArgs());
28+
29+
Path plugins = getProject().getProjectDir().toPath().resolve("build/run/plugins");
30+
StringBuilder builder = new StringBuilder();
31+
32+
for (File file : plugins.toFile().listFiles()) {
33+
System.out.println(file.getName());
34+
if (!file.isDirectory() && file.getName().contains(".jar"))
35+
builder.append(file.toPath().toAbsolutePath()).append(";");
36+
}
37+
38+
String args = builder.substring(0, builder.length() - 1);
39+
var finalArgs = List.of("-manualJar", args);
40+
41+
List<String> argsForProgram = new ArrayList<>();
42+
argsForProgram.addAll(runConfig.getArgs());
43+
argsForProgram.add("-launch");
44+
argsForProgram.add("-manualJar");
45+
argsForProgram.add(args);
46+
setArgs(argsForProgram);
2547

2648
// Create your module path from the config
2749
FileCollection modulePath = getProject().getConfigurations().getByName("installer");

src/main/java/org/mangorage/mangobotgradle/tasks/SetupPluginsTask.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ public void run() {
7676
}
7777

7878
getProject().getConfigurations().getByName("bootstrap").getFiles().forEach(a -> {
79+
System.out.println("Boot Setup!");
80+
7981
try {
8082
if (!Files.exists(getProject().getProjectDir().toPath().resolve("build/run/boot/")))
8183
Files.createDirectories(getProject().getProjectDir().toPath().resolve("build/run/boot/"));
@@ -86,6 +88,18 @@ public void run() {
8688
}
8789
});
8890

91+
getProject().getConfigurations().getByName("launchtarget").getAllArtifacts().getFiles().forEach(a -> {
92+
System.out.println("Launch Target Setup!");
93+
try {
94+
if (!Files.exists(getProject().getProjectDir().toPath().resolve("build/run/launch/")))
95+
Files.createDirectories(getProject().getProjectDir().toPath().resolve("build/run/launch/"));
96+
97+
Files.copy(a.toPath(), getProject().getProjectDir().toPath().resolve("build/run/launch/" + a.getName()), StandardCopyOption.REPLACE_EXISTING);
98+
} catch (IOException e) {
99+
throw new RuntimeException(e);
100+
}
101+
});
102+
89103
getProject().getConfigurations().getByName("plugin").getFiles().forEach(file -> {
90104
try {
91105
Files.copy(file.toPath(), plugins.resolve(file.getName()));

0 commit comments

Comments
 (0)