}
}
}
}catch( Throwable e ){
throw( new PluginException( "Failed to read plugin file", e ));
}finally{
if ( zis != null ){
try{
zis.close();
}catch( Throwable e ){
Debug.printStackTrace(e);
}
}
}
pos = prefix.lastIndexOf("_");
String filename_id = null, filename_version = null;
if ( pos != -1 ){
filename_id = prefix.substring(0,pos);
filename_version = prefix.substring(pos+1);
}
if ( properties == null ){
// one valid possibility here, this is a built-in plugin. this doesn't have
// a plugin.properties
if (filename_id != null) {
id = filename_id;
version = filename_version;
PluginInterface pi = installer.getPluginManager().getPluginInterfaceByID( id );
ok = pi != null &&
( pi.getPluginDirectoryName() == null ||
pi.getPluginDirectoryName().length() == 0 );
}
if ( !ok ){
throw( new PluginException( "Mandatory file 'plugin.properties' not found in plugin file" ));
}
}else{ // properties != null
// unfortunately plugin.id isn't mandatory for the properties, and neither is plugin.version
PluginInitializer.checkJDKVersion( "", properties, false );
PluginInitializer.checkAzureusVersion("", properties, false);
id = properties.getProperty( "plugin.id" );
version = properties.getProperty( "plugin.version" );
// Force both versions to be the same if they are both defined.
String prop_version = version;
if (prop_version != null && filename_version != null && !filename_version.equals(prop_version)) {
throw new PluginException("inconsistent versions [file=" + filename_version + ", prop=" + prop_version + "]");
}
}
if ( id == null ){
// see if plugin is already loaded, if so we can get the id from it
String plugin_class = properties.getProperty("plugin.class");
if ( plugin_class == null ){
String plugin_classes = properties.getProperty( "plugin.classes" );
if ( plugin_classes != null ){
int semi_pos = plugin_classes.indexOf(";");
if ( semi_pos == -1 ){
plugin_class = plugin_classes;
}else{
plugin_class = plugin_classes.substring( 0, semi_pos );
}
}
}
if ( plugin_class != null ){
try{
PluginInterface pi = installer.getPluginManager().getPluginInterfaceByClass( plugin_class );
if ( pi != null ){
id = pi.getPluginID();
}
}catch( Throwable ignore ){
}
}
}
pos = prefix.lastIndexOf("_");
if ( pos != -1 ){
id = id==null?prefix.substring(0,pos):id;
// see if we can normalise the ID based on SF values
try{
SFPluginDetailsLoader loader = SFPluginDetailsLoaderFactory.getSingleton();
String[] ids = loader.getPluginIDs();
for (int i=0;i<ids.length;i++){
if ( ids[i].equalsIgnoreCase(id)){
id = ids[i];
break;
}
}
}catch( Throwable e ){
Debug.printStackTrace(e);
}
version = version == null?prefix.substring(pos+1):version;
}
this.name = id;
if ( properties != null ){
String plugin_name = properties.getProperty( "plugin.name" );
if ( plugin_name != null ){
this.name = plugin_name;
}
}
ok = id != null && version != null;
}
}
if ( !ok ){
throw( new PluginException( "Invalid plugin file name: must be of form <pluginid>_<version>.[jar|zip]" ));
}
}