moditect / layrry

A Runner and API for Layered Java Applications
Apache License 2.0
328 stars 33 forks source link

When building layers with code existing plugins aren't loaded at startup #184

Open treilhes opened 1 year ago

treilhes commented 1 year ago

Hello,

First of all thanks for your awesome work.

I'm trying to launch the vertx sample without using the launcher jar. The layers configuration is done using java code instead of an external config file. The layers configuration is the same than the one provided in "layrry-examples/vertx-links/staging/layers.yml" The target filesystem is the same than the one generated in "layrry-examples/vertx-links/staging"

Below is the code i launch:

        Path pluginsPath = Path.of("/path/to/layrry-examples/vertx-links/staging/route-plugins1");
        Path pluginsPath2 = Path.of("/path/to/layrry-examples/vertx-links/staging/route-plugins2");

        Layers layers = Layers.builder()
                .resolve(Resolvers.remote().enabled(true))
                .pluginsDirectory("plugins1", pluginsPath, List.of("platform", "log"))
                .pluginsDirectory("plugins2", pluginsPath2, List.of("platform", "log"))
                .layer("vertx")
                    .withModule("io.vertx:vertx-core:3.9.0")
                    .withModule("io.vertx:vertx-web:3.9.0")
                    .withModule("io.vertx:vertx-web-common:3.9.0")
                    .withModule("io.vertx:vertx-bridge-common:3.9.0")
                    .withModule("io.netty:netty-all:4.1.48.Final")
                    .withModule("com.fasterxml.jackson.core:jackson-core:2.10.2")
                    .withModule("com.fasterxml.jackson.core:jackson-databind:2.10.2")
                    .withModule("com.fasterxml.jackson.core:jackson-annotations:2.10.2")

                .layer("log")
                   .withModule("org.apache.logging.log4j:log4j-api:jar:2.13.1")
                   .withModule("org.apache.logging.log4j:log4j-core:jar:2.13.1")
                   .withModule("org.moditect.layrry.examples.links:layrry-links-logconfig:1.0.0")

                .layer("platform")
                    .withParent("log")
                    .withParent("vertx")
                    .withModule("org.moditect.layrry:layrry-platform:1.0.0.Alpha1")
                    .withModule("org.moditect.layrry.examples.links:layrry-links-core:1.0.0")
                .build();

            layers.run("org.moditect.layrry.examples.links.core/org.moditect.layrry.examples.links.core.LayrryLinks", "");

Everything works fine except existing plugins (like "layrry-examples/vertx-links/staging/route-plugins1/layrry-links-membership-1.0.0.jar") which aren't loaded at startup.

Removing and adding "route-plugins1/layrry-links-membership-1.0.0.jar" after startup will detect and load the plugin as expected.

Do you know what can be missing in my use case to prevent loading plugins during startup ?

treilhes commented 1 year ago

A bit of debugging later, it seems an additional layer must be created to handle loading plugins at startup.

.layer("plugins1")
    .withParent("platform")
    .withParent("log")
    .withModulesIn(pluginsPath)

But it feels a bit like breaking the DRY principle as it uses the same parameters than the pluginsDirectory call:

.pluginsDirectory("plugins1", pluginsPath, List.of("platform", "log"))

Can you confirm it is the right solution ?