if (command != null)
{
if (!command.usableWithResource(shell.getCurrentResource().getClass()))
{
// noinspection unchecked
throw new PluginExecutionException(plugin, "command '"
+ command.getName()
+ "' is not usable in current scope ["
+ shell.getCurrentResource().getClass().getSimpleName()
+ "]"
+ " -- usable scopes: "
+ GeneralUtils.elementSetSimpleTypesToString((Set) command.getResourceScopes()));
}
execution.setCommand(command);
// parse parameters and set order / nulls for command invocation
Object[] parameters = parseParameters(command, tokens, pipeIn, pipeOut);
execution.setParameterArray(parameters);
}
else
{
throw new PluginExecutionException(plugin, "Missing command for plugin [" + plugin.getName()
+ "], available commands: " + plugin.getCommands(shell));
}
}
else
{
List<PluginMetadata> pluginMetadata = registry.getPluginMetadata(first);
if ((pluginMetadata != null) && !pluginMetadata.isEmpty())
{
Set<Class<? extends Resource<?>>> aggregate = new HashSet<Class<? extends Resource<?>>>();
for (PluginMetadata meta : pluginMetadata)
{
Set<Class<? extends Resource<?>>> scopes = meta.getResourceScopes();
aggregate.addAll(scopes);
}
throw new PluginExecutionException(pluginMetadata.get(0),
"Plugin is not usable in current scope or project.");
}
}
}