Limit how often GC can be run.
[SquirrelJME.git] / buildSrc / src / main / java / cc / squirreljme / plugin / multivm / VMRunTask.java
blob7dac3f98b8a4b8141c31a1e78c26feab9b96ae8d
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
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.multivm.ident.SourceTargetClassifier;
13 import cc.squirreljme.plugin.swm.JavaMEMidlet;
14 import java.net.URI;
15 import java.nio.file.Path;
16 import java.nio.file.Paths;
17 import javax.inject.Inject;
18 import lombok.Getter;
19 import org.gradle.api.DefaultTask;
20 import org.gradle.api.tasks.Internal;
22 /**
23 * Used to run the virtual machine.
25 * @since 2020/08/07
27 public class VMRunTask
28 extends DefaultTask
29 implements VMBaseTask, VMExecutableTask
31 /** Not valid for debug server. */
32 public static final URI NO_DEBUG_SERVER =
33 URI.create("none:none");
35 /** JDWP Host. */
36 public static final URI JDWP_HOST =
37 URI.create("jdwp::5005");
39 /** Internal Debugger. */
40 public static final URI INTERNAL =
41 URI.create("internal:internal");
43 /** The classifier used. */
44 @Internal
45 @Getter
46 protected final SourceTargetClassifier classifier;
48 /** The main class to execute. */
49 @Internal
50 @Getter
51 protected final String mainClass;
53 /** The midlet to execute. */
54 @Internal
55 @Getter
56 protected final JavaMEMidlet midlet;
58 /** GDB Server location. */
59 @Internal
60 @Getter
61 protected final URI debugServer;
63 /**
64 * Initializes the task.
66 * @param __classifier The classifier used.
67 * @param __libTask The task used to create libraries, this may be directly
68 * depended upon.
69 * @param __mainClass The main class used.
70 * @param __midlet The midlet used.
71 * @param __debugServer Optional location of where GDB/JDWP is.
72 * @since 2020/08/07
74 @Inject
75 public VMRunTask(SourceTargetClassifier __classifier,
76 VMLibraryTask __libTask, String __mainClass, JavaMEMidlet __midlet,
77 URI __debugServer)
78 throws NullPointerException
80 // Normalize
81 if (__mainClass != null && __mainClass.isEmpty())
82 __mainClass = null;
83 if (__midlet != null && (JavaMEMidlet.NONE == __midlet ||
84 JavaMEMidlet.NONE.equals(__midlet)))
85 __midlet = null;
87 if (__classifier == null || __libTask == null ||
88 (__mainClass == null && __midlet == null))
89 throw new NullPointerException("NARG");
91 if ((__mainClass == null) == (__midlet == null))
92 throw new IllegalArgumentException("Both main and midlet set.");
94 // These are used when running
95 this.classifier = __classifier;
96 this.mainClass = __mainClass;
97 this.midlet = __midlet;
99 // Was this actually specified?
100 if (__debugServer == null ||
101 __debugServer == VMRunTask.NO_DEBUG_SERVER ||
102 VMRunTask.NO_DEBUG_SERVER.equals(__debugServer))
103 this.debugServer = null;
104 else
105 this.debugServer = __debugServer;
107 // Set details of this task
108 this.setGroup("squirreljme");
109 if (__mainClass != null)
110 this.setDescription(String.format(
111 "Runs the standard main class (%s).", __mainClass));
112 else
113 this.setDescription(String.format(
114 "Runs the application %s.", __midlet.title));
116 // This task depends on the various VM libraries of this class
117 // depending on the dependencies along with the emulator being
118 // available as well
119 this.dependsOn(this.getProject().provider(
120 new VMRunDependencies(this.getProject(), __classifier)),
121 new VMEmulatorDependencies(this.getProject(),
122 __classifier.getTargetClassifier()));
124 // If using the internal debugger, it needs to be built first
125 if (__debugServer != null &&
126 "internal".equals(__debugServer.getScheme()))
127 this.dependsOn(this.getProject().provider(
128 new __FindInternalDebugger__(this.getProject())));
130 // Only run if entry points are valid
131 this.onlyIf(new CheckForEntryPoints());
133 // Performs the action of the task
134 this.doLast(new VMRunTaskAction(__classifier));