private static void deployExtension(Config config, Resource ext) {
ConfigImpl ci = (ConfigImpl)config;
boolean isWeb=config instanceof ConfigWeb;
String type=isWeb?"web":"server";
LogAndSource log = ((ConfigImpl)config).getDeployLogger();
// Manifest
Manifest manifest = null;
ZipInputStream zis=null;
try {
zis = new ZipInputStream( IOUtil.toBufferedInputStream(ext.getInputStream()) ) ;
ZipEntry entry;
String name;
while ( ( entry = zis.getNextEntry()) != null ) {
name=entry.getName();
if(!entry.isDirectory() && name.equalsIgnoreCase("META-INF/MANIFEST.MF")) {
manifest = toManifest(config,zis,null);
}
zis.closeEntry() ;
}
}
catch(Throwable t){
log.error("extension", ExceptionUtil.getStacktrace(t, true));
moveToFailedFolder(ext);
return;
}
finally {
IOUtil.closeEL(zis);
}
int minCoreVersion=0;
double minLoaderVersion=0;
String strMinCoreVersion="",strMinLoaderVersion="",version=null,name=null,id=null;
if(manifest!=null) {
Attributes attr = manifest.getMainAttributes();
// version
version=unwrap(attr.getValue("version"));
// id
id=unwrap(attr.getValue("id"));
// name
name=unwrap(attr.getValue("name"));
// core version
strMinCoreVersion=unwrap(attr.getValue("railo-core-version"));
minCoreVersion=Info.toIntVersion(strMinCoreVersion,minCoreVersion);
// loader version
strMinLoaderVersion=unwrap(attr.getValue("railo-loader-version"));
minLoaderVersion=Caster.toDoubleValue(strMinLoaderVersion,minLoaderVersion);
}
if(StringUtil.isEmpty(name,true)) {
name=ext.getName();
int index=name.lastIndexOf('.');
name=name.substring(0,index-1);
}
name=name.trim();
// check core version
if(minCoreVersion>Info.getVersionAsInt()) {
log.error("extension", "cannot deploy Railo Extension ["+ext+"], Railo Version must be at least ["+strMinCoreVersion+"].");
moveToFailedFolder(ext);
return;
}
// check loader version
if(minLoaderVersion>SystemUtil.getLoaderVersion()) {
log.error("extension", "cannot deploy Railo Extension ["+ext+"], Railo Loader Version must be at least ["+strMinLoaderVersion+"], update the railo.jar first.");
moveToFailedFolder(ext);
return;
}
// check id
if(!Decision.isUUId(id)) {
log.error("extension", "cannot deploy Railo Extension ["+ext+"], this Extension has no valid id ["+id+"],id must be a valid UUID.");
moveToFailedFolder(ext);
return;
}
Resource trgFile=null;
try{
ConfigWebAdmin.removeRHExtension(ci,id);
Resource trgDir = config.getConfigDir().getRealResource("extensions").getRealResource(type).getRealResource(name);
trgFile = trgDir.getRealResource(ext.getName());
trgDir.mkdirs();
ResourceUtil.moveTo(ext, trgFile,true);
}
catch(Throwable t){
log.error("extension", ExceptionUtil.getStacktrace(t, true));
moveToFailedFolder(ext);
return;
}
try {
zis = new ZipInputStream( IOUtil.toBufferedInputStream(trgFile.getInputStream()) ) ;
ZipEntry entry;
String path;
String fileName;
List<String> jars=new ArrayList<String>(), flds=new ArrayList<String>(), tlds=new ArrayList<String>(), contexts=new ArrayList<String>(), applications=new ArrayList<String>();
while ( ( entry = zis.getNextEntry()) != null ) {
path=entry.getName();
fileName=fileName(entry);
// jars
if(!entry.isDirectory() && (startsWith(path,type,"jars") || startsWith(path,type,"jar") || startsWith(path,type,"lib") || startsWith(path,type,"libs")) && StringUtil.endsWithIgnoreCase(path, ".jar")) {
log.info("extension","deploy jar "+fileName);
ConfigWebAdmin.updateJar(config,zis,fileName,false);
jars.add(fileName);
}
// flds
if(!entry.isDirectory() && startsWith(path,type,"flds") && StringUtil.endsWithIgnoreCase(path, ".fld")) {
log.info("extension","deploy fld "+fileName);
ConfigWebAdmin.updateFLD(config, zis, fileName,false);
flds.add(fileName);
}
// tlds
if(!entry.isDirectory() && startsWith(path,type,"tlds") && StringUtil.endsWithIgnoreCase(path, ".tld")) {
log.info("extension","deploy tld "+fileName);
ConfigWebAdmin.updateTLD(config, zis, fileName,false);
tlds.add(fileName);
}
// context
String realpath;
if(!entry.isDirectory() && startsWith(path,type,"context") && !StringUtil.startsWith(fileName(entry), '.')) {
realpath=path.substring(8);
//log.info("extension","deploy context "+realpath);
log.info("extension","deploy context "+realpath);
ConfigWebAdmin.updateContext(ci, zis, realpath,false);
contexts.add(realpath);
}
// applications
if(!entry.isDirectory() && startsWith(path,type,"applications") && !StringUtil.startsWith(fileName(entry), '.')) {
realpath=path.substring(13);
//log.info("extension","deploy context "+realpath);
log.info("extension","deploy application "+realpath);
ConfigWebAdmin.updateApplication(ci, zis, realpath,false);
applications.add(realpath);
}
zis.closeEntry() ;
}
//installation successfull
ConfigWebAdmin.updateRHExtension(ci,
new RHExtension(id,name,version,
jars.toArray(new String[jars.size()]),
flds.toArray(new String[flds.size()]),
tlds.toArray(new String[tlds.size()]),
contexts.toArray(new String[contexts.size()]),
applications.toArray(new String[applications.size()])));
}
catch(Throwable t){
// installation failed
log.error("extension",ExceptionUtil.getStacktrace(t, true));
moveToFailedFolder(trgFile);
return;
}
finally {
IOUtil.closeEL(zis);