Reorder plugins to satisfy dependencies.

This uses Topological sort with before, after and phase.

Still gets angry if something is not available.