📄 pluginlauncherimpl.java
字号:
File plugin_dir = plugins[i];
if( !plugin_dir.isDirectory()){
continue;
}
try{
ClassLoader classLoader = PluginLauncherImpl.class.getClassLoader();
ClassLoader root_cl = classLoader;
File[] contents = plugin_dir.listFiles();
if ( contents == null || contents.length == 0){
continue;
}
// take only the highest version numbers of jars that look versioned
String[] plugin_version = {null};
String[] plugin_id = {null};
contents = getHighestJarVersions( contents, plugin_version, plugin_id, true );
for( int j = 0 ; j < contents.length ; j++){
classLoader = addFileToClassPath( root_cl, classLoader, contents[j]);
}
Properties props = new Properties();
File properties_file = new File( plugin_dir, "plugin.properties");
// if properties file exists on its own then override any properties file
// potentially held within a jar
if ( properties_file.exists()){
FileInputStream fis = null;
try{
fis = new FileInputStream( properties_file );
props.load( fis );
}finally{
if ( fis != null ){
fis.close();
}
}
}else{
if ( classLoader instanceof URLClassLoader ){
URLClassLoader current = (URLClassLoader)classLoader;
URL url = current.findResource("plugin.properties");
if ( url != null ){
props.load(url.openStream());
}
}
}
String plugin_class = (String)props.get( "plugin.class");
// don't support multiple launchable plugins
if ( plugin_class == null || plugin_class.indexOf(';') != -1 ){
continue;
}
Class c = classLoader.loadClass(plugin_class);
Plugin plugin = (Plugin) c.newInstance();
if ( plugin instanceof LaunchablePlugin ){
preloaded_plugins.put( plugin_class, plugin );
res.add( plugin );
}
}catch( Throwable e ){
listener.messageLogged( "Load of plugin in '" + plugin_dir + "' fails", e );
}
}
LaunchablePlugin[] x = new LaunchablePlugin[res.size()];
res.toArray( x );
return( x );
}
public static Plugin
getPreloadedPlugin(
String cla )
{
return((Plugin)preloaded_plugins.get( cla ));
}
private static File
getApplicationFile(
String filename)
{
String path = SystemProperties.getApplicationPath();
if (Constants.isOSX ){
path = path + "/" + SystemProperties.getApplicationName() + ".app/Contents/";
}
return new File(path, filename);
}
public static File[]
getHighestJarVersions(
File[] files,
String[] version_out ,
String[] id_out, // currently the version of last versioned jar found...
boolean discard_non_versioned_when_versioned_found )
{
// WARNING!!!!
// don't use Debug/lglogger here as we can be called before AZ has been initialised
List res = new ArrayList();
Map version_map = new HashMap();
for (int i=0;i<files.length;i++){
File f = files[i];
String name = f.getName().toLowerCase();
if ( name.endsWith(".jar")){
int cvs_pos = name.lastIndexOf("_cvs");
int sep_pos;
if (cvs_pos <= 0)
sep_pos = name.lastIndexOf("_");
else
sep_pos = name.lastIndexOf("_", cvs_pos - 1);
if ( sep_pos == -1 ||
sep_pos == name.length()-1 ||
!Character.isDigit(name.charAt(sep_pos+1))){
// not a versioned jar
res.add( f );
}else{
String prefix = name.substring(0,sep_pos);
String version = name.substring(sep_pos+1, (cvs_pos <= 0) ? name.length()-4 : cvs_pos);
String prev_version = (String)version_map.get(prefix);
if ( prev_version == null ){
version_map.put( prefix, version );
}else{
if ( PluginUtils.comparePluginVersions( prev_version, version ) < 0 ){
version_map.put( prefix, version );
}
}
}
}
}
// If any of the jars are versioned then the assumption is that all of them are
// For migration purposes (i.e. on the first real introduction of the update versioning
// system) we drop all non-versioned jars from the set
if ( version_map.size() > 0 && discard_non_versioned_when_versioned_found ){
res.clear();
}
// fix a problem we had with the rating plugin. It went out as rating_x.jar when it should
// have been azrating_x.jar. If there are any azrating entries then we remove any rating ones
// to avoid load problems
if ( version_map.containsKey( "azrating" )){
version_map.remove( "rating" );
}
Iterator it = version_map.keySet().iterator();
while(it.hasNext()){
String prefix = (String)it.next();
String version = (String)version_map.get(prefix);
String target = prefix + "_" + version;
version_out[0] = version;
id_out[0] = prefix;
for (int i=0;i<files.length;i++){
File f = files[i];
String lc_name = f.getName().toLowerCase();
if ( lc_name.equals( target + ".jar" ) ||
lc_name.equals( target + "_cvs.jar" )){
res.add( f );
break;
}
}
}
File[] res_array = new File[res.size()];
res.toArray( res_array );
return( res_array );
}
public static ClassLoader
addFileToClassPath(
ClassLoader root,
ClassLoader classLoader,
File f)
{
if ( f.exists() &&
(!f.isDirectory())&&
f.getName().endsWith(".jar")){
try {
// URL classloader doesn't seem to delegate to parent classloader properly
// so if you get a chain of them then it fails to find things. Here we
// make sure that all of our added URLs end up within a single URLClassloader
// with its parent being the one that loaded this class itself
if ( classLoader instanceof URLClassLoader ){
URL[] old = ((URLClassLoader)classLoader).getURLs();
URL[] new_urls = new URL[old.length+1];
System.arraycopy( old, 0, new_urls, 1, old.length );
new_urls[0]= f.toURL();
classLoader = new URLClassLoader(
new_urls,
classLoader==root?
classLoader:
classLoader.getParent());
}else{
classLoader = new URLClassLoader(new URL[]{f.toURL()},classLoader);
}
}catch( Exception e){
// don't use Debug/lglogger here as we can be called before AZ has been initialised
e.printStackTrace();
}
}
return( classLoader );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -