Developer Environment
Integrated Development Environments (IDEs) can help you develop your own custom delegates much more easily and error-free than if you were to use a simple text editor and Command Prompt. If you choose to use an IDE, you can configure it however you like, and with whatever build tool you like. To get you started, here are some recommendations for configuring the following IDEs to use Gradle:
You should have already installed Java, Gradle, and your IDE before following these steps.
Project organization
Regardless of what IDE you use, you should set up your project directory first. You can put the directory for your delegate source code anywhere, but it typically makes sense to keep it alongside your No Magic project file, the location you want to deploy your built delegate module to, and any other project-related files like an STK scenario. Figure 1 shows this organization for the completed tutorial sample included in the Behavior Execution Engine installation.
Figure 1: The tutorial sample project directory
Inside your delegate source code directory, you should also follow the pattern used by the samples:
Figure 2: The tutorial sample delegate source code directory
- To set up an environment for development, you can copy the contents of the samples\build directory from the Behavior Execution Engine installation into your delegate source code directory. After you later create a delegate provider for your module, copy its fully qualified name into the \resources\META-INF\services\com.agi.moxie.spi.DelegateProvider file.
- Import your project into your IDE, using the instructions in the next sections, and then return here to finish configuring Gradle.
- In your IDE, open the gradle.properties file.
- Set the
com.agi.moxie.installDir
property to the path to your Behavior Execution Engine installation (e.g., C:/Users/<username>/Documents/Behavior Execution Engine). - Set the
com.agi.moxie.delegateModuleDir
property to the location you want to deploy your delegate module to. This should be a project-relative directory (e.g., ../delegates) or your delegate module home directory (e.g., C:/BehaviorExecutionEngine/DelegateHome). - If you plan to use STK classes in your delegates,
set the
com.agi.moxie.stkInstallDir
property to the path to your STK installation (C:/Program Files/AGI/STK 12 by default); otherwise, you can ignore this property.STK-related features are only available if you acquired Behavior Execution Engine as part of STK Enterprise or otherwise have a valid license for STK. If you acquired Behavior Execution Engine as part of ModelCenter Enterprise but have access to a valid STK license, contact us for access to the STK-related features.
- Set the
com.agi.moxie.noMagicInstallDir
andcom.agi.moxie.noMagicPropFileName
properties to the corresponding values for your No Magic modeling tool. The default values for the tools are already listed in the file for reference. - Save the file, if your IDE does not do that automatically, and close it.
- Open the settings.gradle file.
- Set the
rootProject.name
property to the name of your delegate module project. - Save the file, if your IDE does not do that automatically, and close it.
You should now be ready to start writing delegates. The Gradle build script provides two tasks in particular that you should be aware of:
- You can use the install task to build and deploy your delegate module.
- You can use the launchNoMagicWithDebugging task to open your No Magic modeling tool in a way that enables you to attach your IDE's debugger to examine your delegates during a simulation.
Eclipse
Import your delegate project
- In Eclipse, select File > Import.
- If the Welcome page pops up, you can just click .
- Select Gradle > Existing Gradle Project and then click .
- to your delegate source code directory and click .
- If this is the first time you are importing a Gradle project,
click Configure Workspace Settings....
Figure 3: Importing a Gradle project into Eclipse
Follow these substeps to configure Gradle:- If you are familiar with using a Gradle wrapper then you can select it and configure your Gradle project accordingly. Otherwise, you should just to your Local installation directory of Gradle (the top-level gradle-#.# directory, not the bin directory).
- Leave your Gradle user home empty to use the default (C:\Users\<username>\.gradle).
- Java home
(e.g. C:\Program Files\Java\jdk1.8.0_202).
Figure 4: Recommended Gradle configuration in Eclipse
to your - Click .
- Click .
Configure content assist
If you would like to modify Eclipse's default Java code suggestions, follow these steps:
- Select Window > Preferences.
- In the left sidebar, select Java > Editor > Content Assist > Advanced.
- Select your preferred options. You probably want to select both Java Proposals and Java Type Proposals.
- Click .
Create a debug configuration
If you run the launchNoMagicWithDebugging Gradle task, you can attach the Eclipse debugger by creating a debug configuration.
- Select Run > Debug Configurations....
- In the left sidebar, select Remote Java Application and click the New Configuration button in the upper left.
- Name the configuration and to your delegate module project.
- Leave the
Host
as localhost and set thePort
to 5005. - Click .
After you have created the configuration and attached with it once, you can attach in the future by just clicking the
button again.IntelliJ IDEA
Import your delegate project
- In IntelliJ IDEA, select File > Open or, if IntelliJ IDEA opens to a Welcome page, just click .
- Select your delegate source code directory and click .
- Click and, if given the choice, choose a window to open your project in.
- If IntelliJ IDEA reported a Sync error when opening your project,
follow these substeps to configure Gradle:
- Select File > Settings.
- In the left sidebar, select Build, Execution, Deployment > Build Tools > Gradle.
- Leave your Gradle user home empty to use the default (C:\Users\<username>\.gradle).
- If you are familiar with using a Gradle wrapper, then you can Use Gradle from a 'gradle-wrapper.properties' file, but you will need to configure your Gradle project for that. Otherwise, you should just Use Gradle from the Specified location of your Gradle installation (the top-level gradle-#.# directory, not the bin directory).
- Select your Gradle JVM, adding a new JDK if necessary
(e.g., C:\Program Files\Java\jdk1.8.0_202).
Figure 5: Recommended Gradle configuration in IntelliJ IDEA
- Click .
Configure code completion
If you would like to modify IntelliJ IDEA's default Java code suggestions, follow these steps:
- Select File > Settings.
- In the left sidebar, select Editor > General > Code Completion.
- Select your preferred options. You probably want to select both Basic Completion and Type-Matching Completion.
- Click .
Attach the debugger
In IntelliJ, you do not need to set up any debug configurations. If you run the launchNoMagicWithDebugging Gradle task, you can attach by following these steps:
- Select Run > Attach to Process....
- Select
com.nomagic.launcher.Launcher (5005)
.
VS Code
Install required extensions
- In VS Code, click the Extensions icon on the left.
- Using the search bar, find and install the following extensions:
- Restart VS Code.
Import your delegate project
- In VS Code, select File > Open Folder.
- Select your delegate source code directory and click .
- Click .
- Select View > Command Palatte... (or press ).
- Search for and select Preferences: Open User Settings (JSON).
- Add the following lines to the JSON file, replacing the paths to your Java or Gradle homes if necessary (make sure to use forward
slashes in these paths):
"java.jdt.ls.java.home": "C:/Program Files/Java/jdk1.8.0_202",
"java.import.gradle.home": "C:/Gradle/gradle-7.2",
"java.import.gradle.wrapper.enabled": false, - Restart VS Code.
Create a debug configuration
VS Code requires a separate debug configuration for each project.
- In VS Code, select the Run and Debug icon on the left.
- Click create a launch.json file.
- In the Select Debugger shortcut menu, select Java.
Figure 6: Creating a debug configuration in VS Code
- Select Run > Add Configuration.
- In the list of available configurations, select Java: Attach to Process.
- Delete the
Launch Current File
configuration settings from launch.json.Figure 7: Recommended debug configuration in VS Code
- Save launch.json.
Attach the debugger
If you run the launchNoMagicWithDebugging Gradle task, you can attach the VS Code debugger by following these steps:
- Select Run > Start Debugging.
- Select the process with
debug port: 5005
.