Run ClassConcept without void main(string[] args)

Hi Community,

i created a concept "Test" which is derived from baselang.ClassConcept. The generator will create a java class with a main() method, so that the class can be executed.


What is the simplest way to execute it directly within mps with a right click - like in the case of classconcepts containing a main().

Best,
Dan
4 comments
Hi, Daniel,

We have a concept IMainClass from a language jetbrains.mps.execution.util designed for that purpose. Execution works automatically for concepts that implement it (but the context menu will appear only after first generation of a node).

IMainClass concept has two behavior methods, which you can override if you wish:
  • getUnitName which returnes a fully qualified name of a class to be executed. By default it returnes the name of the class generated from this node.
  • isNodeRunnable should return true for nodes that can be executed. By default it always returnes true.

--
Julia
1

The robot_Kaja sample has its Script concept as IMainClass. In my regular MPS installation, running a Script node works as expected.

I then set up a build module and built a standalone robot_Kaja MPS build, and when I add a Script to my solution in that, even after building/rebuilding/making the solution and the model, right-clicking on the Script node does not allow me to run it. When I preview the generated text, it does show a main method in the generated class.

Does anyone know what I might be missing, such that the context menu does not give me the option to run the Script?

0

I've made some progress. I realized I needed to include more plugins in my project's build script.

I've tried adding the following plugins, none of which seem to give me the ability to run an IMainClass from within a standalone IDE build:

import mpsStandalone::plugins/svn4idea 
import mpsStandalone::plugins/cvsIntegration
import mpsStandalone::plugins/git4idea
import mpsStandalone::plugins/mps-core
import mpsDebuggerPlugin::mps-debugger-api
import mpsDebuggerPlugin::mps-debugger-java
import mpsDebuggerPlugin::mps-execution-api
import mpsExecutionPlugin::mps-execution-configurations
import mpsExecutionPlugin::mps-execution-languages
import mpsMakePlugin::mps-make

I've included these under the "default layout --> folder plugins" section of the build script, and it runs to completion but the resulting standalone IDE still does not allow me to run IMainClass nodes.

0

Finally figured it out. Lessons learned are: Make sure to understand which plugins your build needs, and make sure to pay attention to the IDE error output when starting the IDE. Those led me to the last plugin dependency I was missing.

Here's a full working build script designed to generate a standalone IDE and allow running the generated code from within the IDE:

build MyCalculator generates build.xml 

base directory: ../../ [JComponent javax.swing.JButton[,475,44,20x20,alignmentX=0.0,alignmentY=0.5,border=com.intellij.ide.ui.laf.darcula.ui.DarculaButtonPainter@635f9a59,flags=424,maximumSize=,minimumSize=,preferredSize=java.awt.Dimension[width=20,height=20],defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin=com.intellij.util.ui.JBInsets$JBInsetsUIResource[top=0,left=2,bottom=0,right=2],paintBorder=true,paintFocus=true,pressedIcon=,rolloverEnabled=false,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=...,defaultCapable=true] ]

use plugins:
java
mps

macros:
var date = date yyyyMMdd
var build.number = MyCalculator-162.SNAPSHOT
folder mps_home = ./../../dev/mps/MPS-Generic-3.4.2

dependencies:
mpsStandalone (artifacts location $mps_home)
mpsMakePlugin (artifacts location $mps_home/plugins)
mpsExecutionPlugin (artifacts location $mps_home/plugins)
mpsDebuggerPlugin (artifacts location $mps_home/plugins)
mpsTesting (artifacts location $mps_home/plugins)

project structure:
idea branding
version
codename MyCalculator
1.0.<no bugfixNr>, eap false
company <no company>
build number ${build.number}, date ${date}
logo splash screen ./icons/splash.png
textcolor 002387
progressColor <no progressColor>
progressX <no progressX>
progressY <no progressY>
progressHeight <no progressHeight>
about screen ./icons/about.png
icons
16x16 ./icons/MPS16.png
32x32 ./icons/MPS32.png
32x32 opaque ./icons/MPS32.png
128x128 <no icon128>
icon <no icon>
icon toolWindow <no iconToolWindow>
@Deprecated (for remove in 3.4)
dialog image ./icons/dialogImage.png
names
name MyCalculator
full name MyCalculator

welcome screen ./icons/logo.png

plugins <no plugins>
<no updateWebsite>

<no help>
documentation <no documentation>
support <no support>
feedback url <no feedbackUrl>
whats new <no whatsnew>
<no keymap>
third-party <no thirdparty>
custom elements
<< ... >>

<no stats>

idea plugin MyCalculator
name MyCalculator
short (folder) name MyCalculator
description <no description>
version 1.0
<< no vendor >>
content:
MyCalculator
dependencies:
jetbrains.mps.core
<< ... >>

mps group MyCalculator
language com.semperos.tutorial.calculator
load from ./languages/com.semperos.tutorial.calculator/com.semperos.tutorial.calculator.mpl


default layout:
import mpsStandalone::languages
import mpsStandalone::license
import mpsStandalone::languages/baseLanguage
folder bin
import files from mpsStandalone::bin
include log.xml
include log4j.dtd
file $mps_home/bin/idea.properties
replace regex "\.MPS(\w+)" /g -> \.${build.number}

folder lib
import files from mpsStandalone::lib
exclude MPS-src.zip
exclude branding.jar
jar branding.jar
files of idea branding MyCalculator

folder plugins
import mpsStandalone::plugins/svn4idea
import mpsStandalone::plugins/cvsIntegration
import mpsStandalone::plugins/git4idea
import mpsStandalone::plugins/mps-core
import mpsDebuggerPlugin::mps-debugger-api
import mpsDebuggerPlugin::mps-debugger-java
import mpsDebuggerPlugin::mps-execution-api
import mpsExecutionPlugin::mps-execution-configurations
import mpsExecutionPlugin::mps-execution-languages
import mpsMakePlugin::mps-make
import mpsTesting::mps-testing
plugin MyCalculator
<empty>

properties file build.number
build.number = ${build.number}
date = ${date}
version = 1.0


<<additional aspects>>

Note in particular the dependencies and the plugins used.

0

Please sign in to leave a comment.