// Load the JAR using the JAR class load and load the manifest file.
File unpackedJarDir = Files.createTempDir();
try {
Application app;
try {
if ("LOCAL".equals(locationFactory)) {
lf = new LocalLocationFactory();
} else if ("DISTRIBUTED".equals(locationFactory)) {
lf = new HDFSLocationFactory(new Configuration());
} else {
LOG.error("Unknown location factory specified");
return -1;
}
Program archive = Programs.createWithUnpack(lf.create(jarFilename), unpackedJarDir);
Object appMain = archive.getMainClass().newInstance();
if (!(appMain instanceof Application)) {
LOG.error(String.format("Application main class is of invalid type: %s",
appMain.getClass().getName()));
return -1;
}
app = (Application) appMain;
} catch (Exception e) {
LOG.error(e.getMessage());
return -1;
}
// Now, we are ready to call configure on application.
// Setup security manager, this setting allows only output file to be written.
// Nothing else can be done from here on other than creating that file.
ApplicationSecurity.builder()
.add(new FilePermission(outputFile.getAbsolutePath(), "write"))
.apply();
// Now, we call configure, which returns application specification.
DefaultAppConfigurer configurer = new DefaultAppConfigurer(app);
app.configure(configurer, new ApplicationContext());
ApplicationSpecification specification = configurer.createApplicationSpec();
// Convert the specification to JSON.
// We write the Application specification to output file in JSON format.
try {