metaborg / spoofax

Spoofax runtime
Apache License 2.0
129 stars 23 forks source link

Dynamic class loading #49

Closed Apanatshka closed 4 years ago

Apanatshka commented 5 years ago

This PR generalises the mechanism through which Stratego dynamic loads classes. These dynamically loaded classes are generated by compiling Stratego to Java in a Spoofax language project. Those classes can be dynamically loaded by Spoofax as part of a LanguageComponent, so they can be accessed during execution of Stratego code from that component.

This generalisation is useful because it allows other parts of Spoofax to use dynamically loaded classes from languages. Therefore meta-languages other than Stratego can now generate Java code and this can be picked up in Spoofax. The eventual goal is to make sure we don't necessarily need Stratego as a glue language for everything else in a Language definition. This PR is intentionally minimal. The java-based-services branch contains an attempt at creating Java APIs for all editor services (defined in ESV).

There is a related PR in metaborg/spoofax-deploy that changes the source directory src-gen/stratego-java -- where Java files generated by the Stratego compiler are put -- into src-gen/java to signify the more general use. In this PR there is a similar change in the SpoofaxCommonPaths class.

Open question: Should I change Dynsem to also generate into src-gen/java instead of src-gen/ds-java? I would like to make the change but I don't know if I should mess with Vlad's code.

See also metaborg/spoofax-deploy#18 and metaborg/stratego#6.

Gohla commented 5 years ago

Have you tested what happens to an existing Spoofax project when the generated source directory is changed from src-gen/stratego-java into src-gen/java? Does the build just work, is a clean required, or are more steps neccessary? I would think that at least a clean + Maven update is required. If so, this need to be documented in a migration guide (probably the one for 2.6.0?).

Apanatshka commented 5 years ago

Have you tested what happens to an existing Spoofax project when the generated source directory is changed from src-gen/stratego-java into src-gen/java? Does the build just work, is a clean required, or are more steps neccessary? I would think that at least a clean + Maven update is required. If so, this need to be documented in a migration guide (probably the one for 2.6.0?).

I just tried running a Spoofax project build in Spoofax 2.5.6 (yes, I remembered to put the compilation to jar instead of ctree). Then I started my local 2.6.0-SNAPSHOT version on the same project, updated Maven (without cleaning), and managed to build the project. So other than updating Maven because of the version number change (which is standard when going to a new Spoofax version), it's actually fine. No need to add any migration instructions :)