Skip to content

Commit 9d1fe9c

Browse files
committed
added sources if possible to a module jar extracted from a JDK
1 parent 75e32cb commit 9d1fe9c

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

mx.py

+49-2
Original file line numberDiff line numberDiff line change
@@ -10059,17 +10059,45 @@ def _get_jdk_module_jar(module, suite, jdk):
1005910059
jdkExplodedModule = join(jdk.home, 'modules', module)
1006010060
jdkModules = join(jdk.home, 'lib', 'modules')
1006110061
if not exists(jarPath) or TimeStampFile(jdkModules if exists(jdkModules) else jdkExplodedModule).isNewerThan(jarPath):
10062+
def _classes_dir(start):
10063+
"""
10064+
Searches for the directory containing the sources of `module` by traversing the
10065+
ancestors of `start` and looking for ``*/src/<module>/share/classes``.
10066+
"""
10067+
d = start
10068+
while d != os.sep:
10069+
for subdir in os.listdir(d):
10070+
classes = join(d, subdir, 'src', module, 'share', 'classes')
10071+
if exists(classes):
10072+
return classes
10073+
d = dirname(d)
10074+
10075+
# Try find the sources for `module` based on the assumption `jdk.home` is in the
10076+
# build/ directory of a JDK9 repo.
10077+
classes = _classes_dir(jdk.home)
10078+
sourcesDirs = []
10079+
if classes:
10080+
if module == 'jdk.vm.ci':
10081+
for subdir in os.listdir(classes):
10082+
src = join(classes, subdir, 'src')
10083+
if exists(src):
10084+
sourcesDirs.append(src)
10085+
else:
10086+
sourcesDirs.append(classes)
10087+
1006210088
className = module.replace('.', '_') + '_ExtractJar'
1006310089
javaSource = join(jdkOutputDir, className + '.java')
1006410090
with open(javaSource, 'w') as fp:
1006510091
print >> fp, """
10092+
import java.io.File;
1006610093
import java.io.FileOutputStream;
1006710094
import java.io.IOException;
1006810095
import java.net.URI;
1006910096
import java.nio.file.FileSystem;
1007010097
import java.nio.file.FileSystems;
1007110098
import java.nio.file.Files;
1007210099
import java.nio.file.Path;
10100+
import java.nio.file.Paths;
1007310101
import java.util.jar.JarEntry;
1007410102
import java.util.jar.JarOutputStream;
1007510103
import java.util.stream.Stream;
@@ -10098,12 +10126,31 @@ def _get_jdk_module_jar(module, suite, jdk):
1009810126
}
1009910127
});
1010010128
}
10129+
for (int i = 1; i < args.length; i++) {
10130+
Path sourceDir = Paths.get(args[i]);
10131+
int sourceDirLength = sourceDir.toString().length();
10132+
try (Stream<Path> stream = Files.walk(sourceDir)) {
10133+
stream.forEach(p -> {
10134+
if (!p.toFile().isDirectory()) {
10135+
String path = p.toString().substring(sourceDirLength + 1);
10136+
JarEntry je = new JarEntry(path.replace(File.separatorChar, '/'));
10137+
try {
10138+
jos.putNextEntry(je);
10139+
jos.write(Files.readAllBytes(p));
10140+
jos.closeEntry();
10141+
} catch (IOException e) {
10142+
e.printStackTrace();
10143+
}
10144+
}
10145+
});
10146+
}
10147+
}
1010110148
}
1010210149
}
1010310150
}
1010410151
""" % {"module" : module, "className" : className}
1010510152
run([jdk.javac, '-d', jdkOutputDir, javaSource])
10106-
run([jdk.java, '-ea', '-cp', jdkOutputDir, className, jarPath])
10153+
run([jdk.java, '-ea', '-cp', jdkOutputDir, className, jarPath] + sourcesDirs)
1010710154
return jarPath
1010810155

1010910156
def _eclipseinit_project(p, files=None, libFiles=None):
@@ -13556,7 +13603,7 @@ def alarm_handler(signum, frame):
1355613603
# no need to show the stack trace when the user presses CTRL-C
1355713604
abort(1)
1355813605

13559-
version = VersionSpec("5.25.0")
13606+
version = VersionSpec("5.26.0")
1356013607

1356113608
currentUmask = None
1356213609

0 commit comments

Comments
 (0)