*
* @param file the package file to read
*/
private static JahiaTemplatesPackage read(File file) {
JahiaTemplatesPackage templatePackage = new JahiaTemplatesPackage();
// extract data from the META-INF/MANIFEST.MF file
try {
File manifestFile = new File(file, "META-INF/MANIFEST.MF");
if (manifestFile.exists()) {
InputStream manifestStream = new BufferedInputStream(new FileInputStream(manifestFile), 1024);
Manifest manifest = new Manifest(manifestStream);
IOUtils.closeQuietly(manifestStream);
String packageName = (String) manifest.getMainAttributes().get(new Attributes.Name("package-name"));
String rootFolder = (String) manifest.getMainAttributes().get(new Attributes.Name("root-folder"));
if (packageName == null) {
packageName = file.getName();
}
if (rootFolder == null) {
rootFolder = file.getName();
}
String depends = (String) manifest.getMainAttributes().get(new Attributes.Name("depends"));
if (depends != null) {
String[] dependencies = depends.split(",");
for (String dependency : dependencies) {
templatePackage.setDepends(dependency.trim());
}
}
String definitions = (String) manifest.getMainAttributes().get(new Attributes.Name("definitions"));
if (definitions != null) {
String[] defs = definitions.split(",");
for (String defFile : defs) {
templatePackage.getDefinitionsFiles().add(defFile.trim());
}
}
String imports = (String) manifest.getMainAttributes().get(new Attributes.Name("initial-imports"));
if (imports != null) {
String[] importFiles = imports.split(",");
for (String imp : importFiles) {
templatePackage.addInitialImport(imp.trim());
}
}
templatePackage.setName(packageName);
templatePackage.setRootFolder(rootFolder);
String moduleType = (String) manifest.getMainAttributes().get(new Attributes.Name("module-type"));
if (moduleType != null) {
templatePackage.setModuleType(moduleType);
}
}
} catch (IOException ioe) {
logger
.warn(