Skip to content

Commit b6bf433

Browse files
Replace paths for containerized bundle execution inplace
1 parent 572e0d1 commit b6bf433

File tree

1 file changed

+24
-20
lines changed
  • substratevm/src/com.oracle.svm.driver.launcher/src/com/oracle/svm/driver/launcher

1 file changed

+24
-20
lines changed

substratevm/src/com.oracle.svm.driver.launcher/src/com/oracle/svm/driver/launcher/BundleLauncher.java

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.util.jar.JarFile;
4848
import java.util.stream.Stream;
4949

50+
import static com.oracle.svm.driver.launcher.ContainerSupport.CONTAINER_GRAAL_VM_HOME;
5051
import static com.oracle.svm.driver.launcher.ContainerSupport.replaceContainerPaths;
5152
import static com.oracle.svm.driver.launcher.ContainerSupport.mountMappingFor;
5253
import static com.oracle.svm.driver.launcher.ContainerSupport.TargetPath;
@@ -85,6 +86,8 @@ public class BundleLauncher {
8586

8687
public static ContainerSupport containerSupport;
8788

89+
public static Map<String, String> launcherEnvironment = new HashMap<>();
90+
8891

8992
public static void main(String[] args) {
9093
bundleFilePath = Paths.get(BundleLauncher.class.getProtectionDomain().getCodeSource().getLocation().getPath());
@@ -98,11 +101,9 @@ public static void main(String[] args) {
98101
System.exit(1);
99102
}
100103

101-
List<String> command = createLaunchCommand(args);
102-
ProcessBuilder pb = new ProcessBuilder(command);
104+
ProcessBuilder pb = new ProcessBuilder();
103105

104106
Path environmentFile = stageDir.resolve("environment.json");
105-
Map<String, String> launcherEnvironment = new HashMap<>();
106107
if (Files.isReadable(environmentFile)) {
107108
try (Reader reader = Files.newBufferedReader(environmentFile)) {
108109
new BundleEnvironmentParser(launcherEnvironment).parseAndRegister(reader);
@@ -111,19 +112,7 @@ public static void main(String[] args) {
111112
throw new Error("Failed to read bundle-file " + environmentFile, e);
112113
}
113114
}
114-
115-
if (useContainer()) {
116-
Path javaHome = getJavaExecutable().getParent().getParent();
117-
replaceContainerPaths(command, javaHome, rootDir);
118-
119-
Map<Path, TargetPath> mountMapping = mountMappingFor(javaHome, inputDir, outputDir);
120-
if (Files.isDirectory(agentOutputDir)) {
121-
mountMapping.put(agentOutputDir, TargetPath.of(agentOutputDir, false));
122-
}
123-
124-
containerSupport.initializeContainerImage();
125-
command.addAll(0, containerSupport.createContainerCommand(launcherEnvironment, mountMapping));
126-
}
115+
pb.command(createLaunchCommand(args));
127116

128117
if (verbose) {
129118
List<String> environmentList = pb.environment()
@@ -134,7 +123,7 @@ public static void main(String[] args) {
134123
.toList();
135124
System.out.println("Executing [");
136125
System.out.println(String.join(" \\\n", environmentList));
137-
System.out.println(String.join(" \\\n", command));
126+
System.out.println(String.join(" \\\n", pb.command()));
138127
System.out.println("]");
139128
}
140129

@@ -166,7 +155,21 @@ private static List<String> createLaunchCommand(String[] args) {
166155
List<String> command = new ArrayList<>();
167156

168157
Path javaExecutable = getJavaExecutable().toAbsolutePath().normalize();
169-
command.add(javaExecutable.toString());
158+
159+
if (useContainer()) {
160+
Path javaHome = javaExecutable.getParent().getParent();
161+
162+
Map<Path, TargetPath> mountMapping = mountMappingFor(javaHome, inputDir, outputDir);
163+
if (Files.isDirectory(agentOutputDir)) {
164+
mountMapping.put(agentOutputDir, TargetPath.of(agentOutputDir, false));
165+
}
166+
167+
containerSupport.initializeContainerImage();
168+
command.addAll(containerSupport.createContainerCommand(launcherEnvironment, mountMapping));
169+
command.add(CONTAINER_GRAAL_VM_HOME.resolve(javaHome.relativize(javaExecutable)).toString());
170+
} else {
171+
command.add(javaExecutable.toString());
172+
}
170173

171174
List<String> applicationArgs = new ArrayList<>();
172175
List<String> launchArgs = parseBundleLauncherArgs(args, applicationArgs);
@@ -176,6 +179,7 @@ private static List<String> createLaunchCommand(String[] args) {
176179
if (Files.isDirectory(classPathDir)) {
177180
try (Stream<Path> walk = Files.walk(classPathDir, 1)) {
178181
walk.filter(path -> path.toString().endsWith(".jar") || Files.isDirectory(path))
182+
.map(path -> useContainer() ? Paths.get("/").resolve(rootDir.relativize(path)) : path)
179183
.map(Path::toString)
180184
.forEach(classpath::add);
181185
} catch (IOException e) {
@@ -190,8 +194,8 @@ private static List<String> createLaunchCommand(String[] args) {
190194
List<String> modulePath = new ArrayList<>();
191195
if (Files.isDirectory(modulePathDir)) {
192196
try (Stream<Path> walk = Files.walk(modulePathDir, 1)) {
193-
walk.filter(Files::isDirectory)
194-
.filter(path -> !path.equals(modulePathDir))
197+
walk.filter(path -> Files.isDirectory(path) && !path.equals(modulePathDir))
198+
.map(path -> useContainer() ? Paths.get("/").resolve(rootDir.relativize(path)) : path)
195199
.map(Path::toString)
196200
.forEach(modulePath::add);
197201
} catch (IOException e) {

0 commit comments

Comments
 (0)