Skip to content

Commit

Permalink
[java] Really drop the prefix created by Bazel (#12264)
Browse files Browse the repository at this point in the history
Co-authored-by: Diego Molina <diemol@users.noreply.github.com>
  • Loading branch information
joerg1985 and diemol committed Jun 27, 2023
1 parent 7c40c11 commit c3ecc3c
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions java/src/dev/selenium/tools/modules/ModuleGenerator.java
Expand Up @@ -56,6 +56,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -164,11 +165,28 @@ public static void main(String[] args) throws IOException {
// It doesn't matter what we use for writing to the stream: jdeps doesn't use it. *facepalm*
List<String> jdepsArgs = new LinkedList<>(List.of("--api-only", "--multi-release", "9"));
if (!modulePath.isEmpty()) {
Path tmp = Files.createTempDirectory("automatic_module_jars");
jdepsArgs.addAll(
List.of(
"--module-path",
modulePath.stream()
.map(Object::toString)
.map((s) -> {
String file = s.getFileName().toString();

if (file.startsWith("processed_")) {
Path copy = tmp.resolve(file.substring(10));

try {
Files.copy(s, copy, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new UncheckedIOException(e);
}

return copy.toString();
}

return s.toString();
})
.collect(Collectors.joining(File.pathSeparator))));
}
jdepsArgs.addAll(List.of("--generate-module-info", temp.toAbsolutePath().toString()));
Expand Down Expand Up @@ -467,9 +485,9 @@ private static class MyModuleVisitor extends VoidVisitorAdapter<Void> {
@Override
public void visit(ModuleRequiresDirective n, Void arg) {
String name = n.getNameAsString();
if (name.startsWith("processed_")) {
if (name.startsWith("processed.")) {
// When 'Automatic-Module-Name' is not set, we must derive the module name from the jar file
// name. Therefore, the 'processed_' prefix added by bazel must be removed to get the name.
// name. Therefore, the 'processed.' prefix added by bazel must be removed to get the name.
name = name.substring(10);
}
byteBuddyVisitor.visitRequire(name, getByteBuddyModifier(n.getModifiers()), null);
Expand Down

0 comments on commit c3ecc3c

Please sign in to comment.