_log.info("Creating media key folder " + getRelativePath(mediaKeyFolder));
try {
mediaKeyFolder.createFolder();
}
catch (FileSystemException e) {
throw new WGInitialDeployException("Could not create media key folder '" + mediaKeyFolder.getName().getPathDecoded() + "'");
}
}
// Eventually create intermediate directories
List<String> path = WGUtils.deserializeCollection(mod.getName(), ":", true);
String localName = (String) path.get(path.size() - 1);
FileObject currentDir = mediaKeyFolder;
for (int i = 0; i < path.size() - 1; i++) {
currentDir = currentDir.resolveFile((String) path.get(i));
if (!currentDir.exists()) {
_log.info("Creating tml category directory " + getRelativePath(currentDir));
try {
currentDir.createFolder();
}
catch (FileSystemException e) {
throw new WGInitialDeployException("Could not create tml category folder '" + getRelativePath(currentDir) + "'", e);
}
}
else if (!currentDir.getType().equals(FileType.FOLDER)) {
throw new WGInitialDeployException("Cannot deploy " + mod.getDocumentKey() + " to sync folder because the directory name '" + path.get(i) + "' is already used by another file");
}
}
// Create code file
FileObject tmlCodeFile = currentDir.resolveFile(localName + DesignDirectory.SUFFIX_TML);
_log.info("Creating tml module file " + getRelativePath(tmlCodeFile));
try {
tmlCodeFile.createFile();
}
catch (FileSystemException e) {
throw new WGInitialDeployException("Could not create tml code file '" + getRelativePath(tmlCodeFile) + "'");
}
Writer writer = createWriter(tmlCodeFile);
writer.write(mod.getCode());
writer.close();
// Create metadata file
TMLMetadata metaData = new TMLMetadata(mod);
FileObject metadataDir = currentDir.resolveFile(DesignDirectory.NAME_METADATADIR);
if (!metadataDir.exists()) {
_log.info("Creating tml metadata directory " + getRelativePath(metadataDir));
try {
metadataDir.createFolder();
}
catch (FileSystemException e) {
throw new WGInitialDeployException("Could not create metadata folder '" + metadataDir.getName().getPathDecoded() + "'");
}
}
FileObject metadataFile = metadataDir.resolveFile(localName + DesignDirectory.SUFFIX_METADATA);
_log.info("Creating tml metadata file " + getRelativePath(metadataFile));