boolean addCFMLFiles = getBoolV("addCFMLFiles", true);
boolean addNonCFMLFiles=getBoolV("addNonCFMLFiles", true);
// compile
MappingImpl mapping = (MappingImpl) doCompileMapping(mappingType,virtual, true);
// class files
if(mapping==null)throw new ApplicationException("there is no mapping for ["+virtual+"]");
if(!mapping.hasPhysical())throw new ApplicationException("mapping ["+virtual+"] has no physical directory");
Resource classRoot = mapping.getClassRootDirectory();
Resource temp = SystemUtil.getTempDirectory().getRealResource("mani-"+IDGenerator.stringId());
Resource mani = temp.getRealResource("META-INF/MANIFEST.MF");
try {
if(file.exists())file.delete();
if(!file.exists())file.createFile(true);
ResourceFilter filter;
// include everything, no filter needed
if(addCFMLFiles && addNonCFMLFiles)filter=null;
// CFML Files but no other files
else if(addCFMLFiles) {
if(mappingType==MAPPING_CFC)filter=new ExtensionResourceFilter(new String[]{"class","cfc","MF"},true,true);
else filter=new ExtensionResourceFilter(new String[]{"class","cfm","cfml","cfc","MF"},true,true);
}
// No CFML Files, but all other files
else if(addNonCFMLFiles) {
filter=new NotResourceFilter(new ExtensionResourceFilter(new String[]{"cfm","cfml","cfc"},false,true));
}
// no files at all
else {
filter=new ExtensionResourceFilter(new String[]{"class","MF"},true,true);
}
// create manifest
StringBuilder manifest=new StringBuilder();
// id
manifest.append("mapping-id: \"");
manifest.append(MD5.getDigestAsString(mapping.getStrPhysical()));
manifest.append("\"\n");
manifest.append("mapping-type: \"");
if(mappingType==MAPPING_CFC)manifest.append("cfc");
else if(mappingType==MAPPING_CT)manifest.append("ct");
else manifest.append("regular");
manifest.append("\"\n");
manifest.append("mapping-virtual-path: \"");
manifest.append(mapping.getVirtual());
manifest.append("\"\n");
// Hidden
manifest.append("mapping-hidden: ");
manifest.append(mapping.isHidden());
manifest.append("\n");
// Physical First
manifest.append("mapping-physical-first: ");
manifest.append(mapping.isPhysicalFirst());
manifest.append("\n");
// Readonly
manifest.append("mapping-readonly: ");
manifest.append(mapping.isReadonly());
manifest.append("\n");
// Top Level
manifest.append("mapping-top-level: ");
manifest.append(mapping.isTopLevel());
manifest.append("\n");
// Trusted
manifest.append("mapping-inspect: \"");
manifest.append(ConfigWebUtil.inspectTemplate(mapping.getInspectTemplateRaw(), ""));
manifest.append("\"\n");
mani.createFile(true);
IOUtil.write(mani, manifest.toString(), "UTF-8", false);
// source files
Resource[] sources;
if(!addCFMLFiles && !addNonCFMLFiles) sources=new Resource[]{temp,classRoot};
else sources=new Resource[]{temp,mapping.getPhysical(),classRoot};
CompressUtil.compressZip(ResourceUtil.listResources(sources,filter), file, filter);
if(getBoolV("append", false)) {
if(mappingType==MAPPING_CFC) {
admin.updateComponentMapping(
mapping.getVirtual(),
mapping.getStrPhysical(),
strFile,
mapping.isPhysicalFirst()?"physical":"archive",
mapping.getInspectTemplateRaw());
}
else if(mappingType==MAPPING_CT) {
admin.updateCustomTag(
mapping.getVirtual(),
mapping.getStrPhysical(),
strFile,
mapping.isPhysicalFirst()?"physical":"archive",
mapping.getInspectTemplateRaw());
}
else
admin.updateMapping(
mapping.getVirtual(),
mapping.getStrPhysical(),
strFile,
mapping.isPhysicalFirst()?"physical":"archive",
mapping.getInspectTemplateRaw(),
mapping.isTopLevel()
);
store();
}