//parse out the '.jar'
name = info.getFileName().substring(0,info.getFileName().length() - 4);
} else {
//fail
logger.warning("FILE NOT A MODULE!");
return Response.status(Status.INTERNAL_SERVER_ERROR).cacheControl(new CacheControl()).build();
}
File tmpFile = null;
try {
tmpFile = File.createTempFile(name+"_tmp", ".jar");
tmpFile.deleteOnExit();
RunUtil.writeToFile(new FileInputStream(file), tmpFile);
} catch(Exception e) {
logger.warning("ERROR WRITING TO FILE!");
return Response.status(Status.INTERNAL_SERVER_ERROR).cacheControl(new CacheControl()).build();
}
Collection<File> moduleFiles = new LinkedList<File>();
moduleFiles.add(tmpFile);
Collection<Module> result = manager.addToInstall(moduleFiles);
if(result.isEmpty()) {
logger.warning("NOTHING IN MODULE!");
return Response.status(Status.INTERNAL_SERVER_ERROR).cacheControl(new CacheControl()).build();
}
//We won't use this data on the client side, so pass in dummy data for
//file size and URL.
FileMeta metaData = new FileMeta(tmpFile.getName(), 0, "");
List<FileMeta> metas = Lists.newArrayList(metaData);
GenericEntity<List<FileMeta>> entity = new GenericEntity<List<FileMeta>>(metas){};
return Response.ok(entity).cacheControl(new CacheControl()).build();
}