use of com.continuuity.weave.launcher.WeaveLauncher in project weave by continuuity.
the class YarnWeavePreparer method saveLauncher.
/**
* Creates the launcher.jar for launch the main application.
*/
private void saveLauncher(Map<String, LocalFile> localFiles) throws URISyntaxException, IOException {
LOG.debug("Create and copy {}", Constants.Files.LAUNCHER_JAR);
Location location = createTempLocation(Constants.Files.LAUNCHER_JAR);
final String launcherName = WeaveLauncher.class.getName();
// Create a jar file with the WeaveLauncher optionally a json serialized classpath.json in it.
final JarOutputStream jarOut = new JarOutputStream(location.getOutputStream());
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader == null) {
classLoader = getClass().getClassLoader();
}
Dependencies.findClassDependencies(classLoader, new Dependencies.ClassAcceptor() {
@Override
public boolean accept(String className, URL classUrl, URL classPathUrl) {
Preconditions.checkArgument(className.startsWith(launcherName), "Launcher jar should not have dependencies: %s", className);
try {
jarOut.putNextEntry(new JarEntry(className.replace('.', '/') + ".class"));
InputStream is = classUrl.openStream();
try {
ByteStreams.copy(is, jarOut);
} finally {
is.close();
}
} catch (IOException e) {
throw Throwables.propagate(e);
}
return true;
}
}, WeaveLauncher.class.getName());
try {
if (!classPaths.isEmpty()) {
jarOut.putNextEntry(new JarEntry("classpath"));
jarOut.write(Joiner.on(':').join(classPaths).getBytes(Charsets.UTF_8));
}
} finally {
jarOut.close();
}
LOG.debug("Done {}", Constants.Files.LAUNCHER_JAR);
localFiles.put(Constants.Files.LAUNCHER_JAR, createLocalFile(Constants.Files.LAUNCHER_JAR, location));
}
Aggregations