-
Notifications
You must be signed in to change notification settings - Fork 64
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
JPMS support #1957
Comments
Bump? |
I don't have much experience with JPMS stuff so not sure what to do for this. Can someone contribute what is needed to an existing WebJar? |
Good question :) I've asked for guidance here: https://stackoverflow.com/q/76756387/14731 |
I'm also not a great resource, but in this video at 28:10 the person says there is a loophole for resources in the encapsulation. https://www.youtube.com/watch?v=4fevIDAxQAM So thats why I thought just adding an empty module-info would be enough. |
The loophole is that a module can see its own resources, which isn't our case here. Regardless, I don't think that webjars has a JPMS support.
I'm going to close this issue. Whatever is going on in TestNG sounds like a bug on their end. |
@cowwoc wait, i'm confused. The use case I want to support is having the webjars on the module path and having them play well with |
Basic example, if I have the jquery webjar on the module path then I can do this module mod {
requires jquery;
exports mod;
}
But without an actual module descriptor, jlink won't be happy
Very few people use modules, but it becomes more possible the more "base" libraries do. |
@bowbahdoe Sorry, you're right. @jamesward Does any webjar include Java classes? If not, all you'd need to do is add
and just like that you'd have JPMS support. |
There are not any java classes in WebJars (with the exception of the utilities like |
@jamesward You have to create this file in the root package, compile it, then stick the class file inside the root directory of the JAR. |
I'm happy to take a stab at this. Is there a WebJar any of you use that we could test with? |
@jamesward Not at the moment. Maybe @bowbahdoe ? |
I'll try and get a minimal example |
https://github.com/bowbahdoe/webjar-jpms-example @jamesward Here is a minimal |
@jamesward Any time to get back to this? |
Thanks for the ping. NPM WebJars currently are created by: I also am working on moving all Classic WebJars to this approach as well. So that is where we will need to somehow create the |
@jamesward An easy way is to use a tool provider import java.nio.file.Files;
import java.nio.file.Path;
import java.util.spi.ToolProvider;
public class Main {
public static Path makeOpenModule(String moduleName) throws Exception {
String moduleContents = """
open module %s {}
""".formatted(moduleName);
Path dir = Files.createTempDirectory("module-temp");
Path file = Path.of(dir.toString(), "module-info.java");
Files.writeString(file, moduleContents);
var javac = ToolProvider.findFirst("javac").orElseThrow();
int exitCode = javac.run(System.out, System.err, "--release", "9", file.toString());
if (exitCode != 0) {
throw new Exception("javac exit code: " + exitCode);
}
return Path.of(dir.toString(), "module-info.class");
}
public static void main(String[] args) throws Exception {
System.out.println(makeOpenModule("org.example"));
}
} |
Thank you! I'll give this a try. |
Oh, also - putting the class file in the jar @ |
Thanks! Question... I'm trying this and there seems to be a constraint on the module names that make them incompatible with the artifact names. For example:
Should I just strip the invalid chars or is there a better way? |
I think either stripping them or replacing them with First thought is that |
lord forgive me import java.io.FileOutputStream;
import java.lang.module.ModuleDescriptor;
import java.lang.module.ModuleFinder;
import java.lang.module.ModuleReference;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.zip.ZipOutputStream;
public class Main {
public static String sanitizeModuleName(String moduleName) throws Exception{
Path file = Path.of(
Files.createTempDirectory("sanitize-hack").toString(),
moduleName + ".jar"
);
try (var zos = new ZipOutputStream(new FileOutputStream(file.toFile()))) {}
return ModuleFinder.of(file).findAll()
.stream().map(ModuleReference::descriptor)
.map(ModuleDescriptor::name)
.findFirst()
.orElseThrow();
}
public static void main(String[] args) throws Exception {
System.out.println(sanitizeModuleName("org.example"));
System.out.println(sanitizeModuleName("org.example.react-redux"));
}
} Another issue, besides invalid characters, is things like |
Oh fun. I'm working on: #2072 I wonder how hard it is to get to valid names. I think there could also be an issue if a part starts with a number? I'm assuming these names have to follow Java syntax rules? |
Yeah, especially if we are generating them by running them through the compiler (but thats not a bad thing - to be used they need to work like that anyways). For reserved keywords, adding a |
Might be ugly, but what if we prefix and postfix everything with |
🙉 🙈 🙊 (I am ultimately fine with any heuristic that works) |
Ok, how's this: 7baa60c |
@jamesward Sorry - I keep getting pulled in different directions. Will be back to this soon |
Looking at testng-team/testng#2727 it sounds like you need to include
module-info.java
in all your releases thatopens <package>
. Otherwise, JDK 9+ users will be unable to read the resources directory.You can use multi-release JARs to support both JDK 8 and JDK 9+ users. Feel free to reach out if you have any questions.
The text was updated successfully, but these errors were encountered: