throws IOException, InstantiationException, IllegalAccessException {
ApplicationBundler bundler = new ApplicationBundler(ImmutableList.of("co.cask.tigon.api",
"org.apache.hadoop",
"org.apache.hbase"));
Location jarLocation = locationFactory.create(clz.getName()).getTempFile(".jar");
bundler.createBundle(jarLocation, clz);
Location deployJar = locationFactory.create(clz.getName()).getTempFile(".jar");
Flow flow = (Flow) clz.newInstance();
FlowSpecification flowSpec = new DefaultFlowSpecification(clz.getClass().getName(), flow.configure());
// Creates Manifest
Manifest manifest = new Manifest();
manifest.getMainAttributes().put(ManifestFields.MANIFEST_VERSION, "1.0");
manifest.getMainAttributes().put(ManifestFields.MAIN_CLASS, clz.getName());
manifest.getMainAttributes().put(ManifestFields.SPEC_FILE, ManifestFields.MANIFEST_SPEC_FILE);
// Create the program jar for deployment. It removes the "classes/" prefix as that's the convention taken
// by the ApplicationBundler inside Twill.
JarOutputStream jarOutput = new JarOutputStream(deployJar.getOutputStream(), manifest);
try {
JarInputStream jarInput = new JarInputStream(jarLocation.getInputStream());
try {
JarEntry jarEntry = jarInput.getNextJarEntry();
Set<String> entriesAdded = Sets.newHashSet();
while (jarEntry != null) {
boolean isDir = jarEntry.isDirectory();
String entryName = jarEntry.getName();
if (!entryName.equals("classes/") && !entryName.endsWith("META-INF/MANIFEST.MF") &&
!entriesAdded.contains(entryName)) {
if (entryName.startsWith("classes/")) {
jarEntry = new JarEntry(entryName.substring("classes/".length()));
} else {
jarEntry = new JarEntry(entryName);
}
jarOutput.putNextEntry(jarEntry);
entriesAdded.add(jarEntry.getName());
if (!isDir) {
ByteStreams.copy(jarInput, jarOutput);
}
}
jarEntry = jarInput.getNextJarEntry();
}
} finally {
jarInput.close();
}
for (File embeddedJar : bundleEmbeddedJars) {
JarEntry jarEntry = new JarEntry("lib/" + embeddedJar.getName());
jarOutput.putNextEntry(jarEntry);
Files.copy(embeddedJar, jarOutput);
}
JarEntry jarEntry = new JarEntry(ManifestFields.MANIFEST_SPEC_FILE);
jarOutput.putNextEntry(jarEntry);
ByteStreams.copy(getInputSupplier(flowSpec), jarOutput);
} finally {
jarOutput.close();
}
return new File(deployJar.toURI());
}