Allow 'softdepends' in plugin description

This commit is contained in:
Keir Nellyer 2014-03-31 15:28:18 +01:00 committed by md_5
parent e025ad8ed7
commit a4dd0dba88
2 changed files with 13 additions and 2 deletions

View File

@ -36,6 +36,10 @@ public class PluginDescription
* Plugin hard dependencies.
*/
private Set<String> depends = new HashSet<>();
/**
* Plugin soft dependencies.
*/
private Set<String> softDepends = new HashSet<>();
/**
* File we were loaded from.
*/

View File

@ -12,10 +12,12 @@ import java.net.URLClassLoader;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Stack;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
@ -219,11 +221,16 @@ public class PluginManager
return pluginStatuses.get( plugin );
}
// combine all dependencies for 'for loop'
Set<String> dependencies = new HashSet<>();
dependencies.addAll( plugin.getDepends() );
dependencies.addAll( plugin.getSoftDepends() );
// success status
boolean status = true;
// try to load dependencies first
for ( String dependName : plugin.getDepends() )
for ( String dependName : dependencies )
{
PluginDescription depend = toLoad.get( dependName );
Boolean dependStatus = ( depend != null ) ? pluginStatuses.get( depend ) : Boolean.FALSE;
@ -248,7 +255,7 @@ public class PluginManager
}
}
if ( dependStatus == Boolean.FALSE )
if ( dependStatus == Boolean.FALSE && plugin.getDepends().contains( dependName ) ) // only fail if this wasn't a soft dependency
{
ProxyServer.getInstance().getLogger().log( Level.WARNING, "{0} (required by {1}) is unavailable", new Object[]
{