Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable to exec:java runnables and not only mains with loosely coupled injections #408

Conversation

rmannibucau
Copy link
Contributor

@rmannibucau rmannibucau commented Jan 26, 2024

Goal is to enable to quickly use exec:java as an in place mojo replacement without having to bring all maven stack for simple needs.

Sample:

import java.util.Properties;
import java.util.function.BiConsumer;
import java.util.function.Function;

public final class ComputeLatest implements Runnable {
    private final Function<String, String> versionResolver;
    private final Properties properties;
    private final BiConsumer<String, String> updater;

    public ComputeLatest(final Function<String, String> highestVersionResolver,
                         final Properties systemProperties,
                         final BiConsumer<String, String> systemPropertiesUpdater) {
        this.versionResolver = highestVersionResolver;
        this.properties = systemProperties;
        this.updater = systemPropertiesUpdater;
    }

    public void run() {
        final var project = properties.getProperty("env.DEPLOY_PROJECT");
        final String ga = switch (project) {
            case "foo" -> "com.demo.app1:deploy";
            case "bar" -> "com.demo.app2:deploy";
            default -> "";
        };
        if (ga.isBlank()) { // ignore
            return;
        }

        var lastVersion = versionResolver.apply(ga);
        if (!lastVersion.endsWith("-SNAPSHOT")) { // likely local since m2 repo shouldn't get published snapshots
            final var lastDot = lastVersion.lastIndexOf('.') + 1;
            lastVersion = lastVersion.substring(0, lastDot) + (Integer.parseInt(lastVersion.substring(lastDot)) + 1) + "-snapshot";
        }
        updater.accept(ga.replace('.', '_').replace(':', '_') + ".latest", lastVersion);
    }
}

then use com_demo_app1_deploy.latest in any placeholder friendly downstream plugin.

Copy link
Member

@slawekjaranowski slawekjaranowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also consider to add example page with it in documentation

pom.xml Outdated Show resolved Hide resolved
src/main/java/org/codehaus/mojo/exec/ExecJavaMojo.java Outdated Show resolved Hide resolved
src/main/java/org/codehaus/mojo/exec/ExecJavaMojo.java Outdated Show resolved Hide resolved
src/main/java/org/codehaus/mojo/exec/ExecJavaMojo.java Outdated Show resolved Hide resolved
rmannibucau added a commit to rmannibucau/exec-maven-plugin that referenced this pull request Jan 27, 2024
@rmannibucau rmannibucau force-pushed the rmannibucau/exec-java_runnable-support branch from ead991b to ad436a5 Compare January 27, 2024 14:01
@rmannibucau
Copy link
Contributor Author

adressed comments @slawekjaranowski if you want to have another look, thanks a lot to have spotted some issues, totally missed them yesterday.

rmannibucau added a commit to rmannibucau/exec-maven-plugin that referenced this pull request Jan 27, 2024
@rmannibucau rmannibucau force-pushed the rmannibucau/exec-java_runnable-support branch from ad436a5 to 904866d Compare January 27, 2024 15:24
@slawekjaranowski slawekjaranowski self-requested a review January 27, 2024 19:34
Copy link
Member

@slawekjaranowski slawekjaranowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix copy paste in documentation

rmannibucau added a commit to rmannibucau/exec-maven-plugin that referenced this pull request Jan 27, 2024
@rmannibucau rmannibucau force-pushed the rmannibucau/exec-java_runnable-support branch from 904866d to 4d46190 Compare January 27, 2024 20:33
@rmannibucau rmannibucau force-pushed the rmannibucau/exec-java_runnable-support branch from 4d46190 to e09ac32 Compare January 27, 2024 20:41
@slawekjaranowski slawekjaranowski merged commit a7090d0 into mojohaus:master Jan 28, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants