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

feat: Added support for script dependencies #1641

Merged
merged 9 commits into from
Jul 8, 2023

Conversation

quintesse
Copy link
Contributor

You can now do:

//DEPS local_file.java http://www.example.com/remote_file.java

And those files will be compiled, if needed, and added as dependencies on the classpath.

@quintesse quintesse requested a review from maxandersen June 28, 2023 18:41
@maxandersen
Copy link
Collaborator

Awesome. Does swizzled urls work too? Ie. For gist and fully qualified catalogs?

@@ -11,17 +11,17 @@

public class JitPackUtil {
private static final Pattern GITHUB_TREE_PATTERN = Pattern.compile(
"^https?://github.com/(.+?)/(.+?)(/tree/(.+?)(/(.+?))?)?/?$");
"^https?://github.com/([^/]+?)/([^/]+?)(/tree/([^/]+?)(/(.+?))?)?/?$");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are these patterns changing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because they are too lenient, they match URLs that are not valid JitPack URLs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For example it will match https://github.com/jbangdev/jbang/blob/main/itests/SankeyPlotTest.java , even though that's obviously neither a "tree" nor a "commit".

@quintesse
Copy link
Contributor Author

quintesse commented Jun 28, 2023

Awesome. Does swizzled urls work too? Ie. For gist and fully qualified catalogs?

Haven't tried yet, this is the first working version 😉

Edit: I don't think aliases will work, though...

@maxandersen
Copy link
Collaborator

first quick test with this beauty:

///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS info.picocli:picocli:4.6.3
//DEPS https://github.com/jbangdev/jbang-catalog/blob/main/httpd.java


import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Parameters;

import java.util.concurrent.Callable;

@Command(name = "hello", mixinStandardHelpOptions = true, version = "hello 0.1",
        description = "hello made with jbang")
class hello implements Callable<Integer> {

    @Parameters(index = "0", description = "The greeting to print", defaultValue = "World!")
    private String greeting;

    public static void main(String... args) {
        int exitCode = new CommandLine(new hello()).execute(args);
        System.exit(exitCode);
    }

    @Override
    public Integer call() throws Exception { // your business logic goes here...
        System.out.println("Hello again " + greeting);

        httpd.main(new String[] { "--port=8080" });
        return 0;
    }
}

at first glance worked - even vscode picked up the new deps.

a few things:

[jbang] Building jar...
[jbang] Resolving dependencies...
[jbang]    info.picocli:picocli:4.6.3
[jbang] Dependencies resolved
[jbang] Building jar...

The Building jar should have some indication of what its building now.

If touch just the hello.java I still get:

jbang hello.java
[jbang] Building jar...
[jbang] Building jar...
Hello again World!

shouldn't there only be one Building Jar in that case ?

@maxandersen
Copy link
Collaborator

//JAVA 21+
//PREVIEW
//DEPS hello.java

void main() {
    System.out.println("Hello, world!");
}

instant stack overflow :)

@maxandersen
Copy link
Collaborator

btw. //DEPS other.jar works. sweet!

@maxandersen
Copy link
Collaborator

maxandersen commented Jun 28, 2023

//DEPS httpd@jbangdev does not work...part of me says it shouldn't but then again....its pretty damn nice if it could work.

quintesse added 2 commits July 6, 2023 18:41
Source dependencies would always be rebuilt whenever the parent script
was built. This was because they were really built a part of (meaning
inside of) the parent's build folder, not as an independent artifact.
This is now no longer the case and building a script as part of a
dependency or standalone will now result in the same artifact.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants