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
.multivm
.ident
.SourceTargetClassifier
;
13 import cc
.squirreljme
.plugin
.swm
.JavaMEMidlet
;
15 import java
.nio
.file
.Path
;
16 import java
.nio
.file
.Paths
;
17 import javax
.inject
.Inject
;
19 import org
.gradle
.api
.DefaultTask
;
20 import org
.gradle
.api
.tasks
.Internal
;
23 * Used to run the virtual machine.
27 public class VMRunTask
29 implements VMBaseTask
, VMExecutableTask
31 /** Not valid for debug server. */
32 public static final URI NO_DEBUG_SERVER
=
33 URI
.create("none:none");
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. */
46 protected final SourceTargetClassifier classifier
;
48 /** The main class to execute. */
51 protected final String mainClass
;
53 /** The midlet to execute. */
56 protected final JavaMEMidlet midlet
;
58 /** GDB Server location. */
61 protected final URI debugServer
;
64 * Initializes the task.
66 * @param __classifier The classifier used.
67 * @param __libTask The task used to create libraries, this may be directly
69 * @param __mainClass The main class used.
70 * @param __midlet The midlet used.
71 * @param __debugServer Optional location of where GDB/JDWP is.
75 public VMRunTask(SourceTargetClassifier __classifier
,
76 VMLibraryTask __libTask
, String __mainClass
, JavaMEMidlet __midlet
,
78 throws NullPointerException
81 if (__mainClass
!= null && __mainClass
.isEmpty())
83 if (__midlet
!= null && (JavaMEMidlet
.NONE
== __midlet
||
84 JavaMEMidlet
.NONE
.equals(__midlet
)))
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;
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
));
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
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
));