Send launch properties around as bound constants
Instead of exposing static variable provide launch properties to dependant classes as bound constants in RuneLiteModule. Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -53,7 +53,6 @@ import net.runelite.client.game.ClanManager;
|
|||||||
import net.runelite.client.game.ItemManager;
|
import net.runelite.client.game.ItemManager;
|
||||||
import net.runelite.client.menus.MenuManager;
|
import net.runelite.client.menus.MenuManager;
|
||||||
import net.runelite.client.plugins.PluginManager;
|
import net.runelite.client.plugins.PluginManager;
|
||||||
import net.runelite.client.rs.ClientLoader;
|
|
||||||
import net.runelite.client.rs.ClientUpdateCheckMode;
|
import net.runelite.client.rs.ClientUpdateCheckMode;
|
||||||
import net.runelite.client.ui.ClientUI;
|
import net.runelite.client.ui.ClientUI;
|
||||||
import net.runelite.client.ui.DrawManager;
|
import net.runelite.client.ui.DrawManager;
|
||||||
@@ -80,9 +79,6 @@ public class RuneLite
|
|||||||
@Getter
|
@Getter
|
||||||
private static Injector injector;
|
private static Injector injector;
|
||||||
|
|
||||||
@Getter
|
|
||||||
private static OptionSet options;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private PluginManager pluginManager;
|
private PluginManager pluginManager;
|
||||||
|
|
||||||
@@ -174,15 +170,17 @@ public class RuneLite
|
|||||||
});
|
});
|
||||||
|
|
||||||
parser.accepts("help", "Show this text").forHelp();
|
parser.accepts("help", "Show this text").forHelp();
|
||||||
options = parser.parse(args);
|
OptionSet options = parser.parse(args);
|
||||||
|
|
||||||
if (getOptions().has("help"))
|
if (options.has("help"))
|
||||||
{
|
{
|
||||||
parser.printHelpOn(System.out);
|
parser.printHelpOn(System.out);
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (RuneLite.getOptions().has("developer-mode") && RuneLiteProperties.getLauncherVersion() == null)
|
final boolean developerMode = options.has("developer-mode");
|
||||||
|
|
||||||
|
if (developerMode && RuneLiteProperties.getLauncherVersion() == null)
|
||||||
{
|
{
|
||||||
boolean assertions = false;
|
boolean assertions = false;
|
||||||
assert assertions = true;
|
assert assertions = true;
|
||||||
@@ -212,8 +210,10 @@ public class RuneLite
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
injector = Guice.createInjector(new RuneLiteModule());
|
injector = Guice.createInjector(new RuneLiteModule(
|
||||||
injector.getInstance(ClientLoader.class).setUpdateCheckMode(getOptions().valueOf(updateMode));
|
options.valueOf(updateMode),
|
||||||
|
developerMode));
|
||||||
|
|
||||||
injector.getInstance(RuneLite.class).start();
|
injector.getInstance(RuneLite.class).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,10 +298,4 @@ public class RuneLite
|
|||||||
{
|
{
|
||||||
RuneLite.injector = injector;
|
RuneLite.injector = injector;
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
public static void setOptions(OptionSet options)
|
|
||||||
{
|
|
||||||
RuneLite.options = options;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ import net.runelite.client.config.RuneLiteConfig;
|
|||||||
import net.runelite.client.game.ItemManager;
|
import net.runelite.client.game.ItemManager;
|
||||||
import net.runelite.client.menus.MenuManager;
|
import net.runelite.client.menus.MenuManager;
|
||||||
import net.runelite.client.plugins.PluginManager;
|
import net.runelite.client.plugins.PluginManager;
|
||||||
|
import net.runelite.client.rs.ClientUpdateCheckMode;
|
||||||
import net.runelite.client.rs.ClientLoader;
|
import net.runelite.client.rs.ClientLoader;
|
||||||
import net.runelite.client.task.Scheduler;
|
import net.runelite.client.task.Scheduler;
|
||||||
import net.runelite.client.util.DeferredEventBus;
|
import net.runelite.client.util.DeferredEventBus;
|
||||||
@@ -58,9 +59,20 @@ import okhttp3.OkHttpClient;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class RuneLiteModule extends AbstractModule
|
public class RuneLiteModule extends AbstractModule
|
||||||
{
|
{
|
||||||
|
private final ClientUpdateCheckMode updateCheckMode;
|
||||||
|
private final boolean developerMode;
|
||||||
|
|
||||||
|
public RuneLiteModule(final ClientUpdateCheckMode updateCheckMode, final boolean developerMode)
|
||||||
|
{
|
||||||
|
this.updateCheckMode = updateCheckMode;
|
||||||
|
this.developerMode = developerMode;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure()
|
protected void configure()
|
||||||
{
|
{
|
||||||
|
bindConstant().annotatedWith(Names.named("updateCheckMode")).to(updateCheckMode);
|
||||||
|
bindConstant().annotatedWith(Names.named("developerMode")).to(developerMode);
|
||||||
bind(ScheduledExecutorService.class).toInstance(Executors.newSingleThreadScheduledExecutor());
|
bind(ScheduledExecutorService.class).toInstance(Executors.newSingleThreadScheduledExecutor());
|
||||||
bind(OkHttpClient.class).toInstance(RuneLiteAPI.CLIENT);
|
bind(OkHttpClient.class).toInstance(RuneLiteAPI.CLIENT);
|
||||||
bind(QueryRunner.class);
|
bind(QueryRunner.class);
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins;
|
package net.runelite.client.plugins;
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.eventbus.EventBus;
|
import com.google.common.eventbus.EventBus;
|
||||||
@@ -36,7 +37,6 @@ import com.google.common.reflect.ClassPath;
|
|||||||
import com.google.common.reflect.ClassPath.ClassInfo;
|
import com.google.common.reflect.ClassPath.ClassInfo;
|
||||||
import com.google.inject.Binder;
|
import com.google.inject.Binder;
|
||||||
import com.google.inject.CreationException;
|
import com.google.inject.CreationException;
|
||||||
import com.google.inject.Inject;
|
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Key;
|
import com.google.inject.Key;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
@@ -52,6 +52,8 @@ import java.util.Set;
|
|||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -78,29 +80,38 @@ public class PluginManager
|
|||||||
*/
|
*/
|
||||||
private static final String PLUGIN_PACKAGE = "net.runelite.client.plugins";
|
private static final String PLUGIN_PACKAGE = "net.runelite.client.plugins";
|
||||||
|
|
||||||
@Inject
|
private final boolean developerMode;
|
||||||
EventBus eventBus;
|
private final EventBus eventBus;
|
||||||
|
private final Scheduler scheduler;
|
||||||
@Inject
|
private final ConfigManager configManager;
|
||||||
Scheduler scheduler;
|
private final ScheduledExecutorService executor;
|
||||||
|
private final SceneTileManager sceneTileManager;
|
||||||
@Inject
|
|
||||||
ConfigManager configManager;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
ScheduledExecutorService executor;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
SceneTileManager sceneTileManager;
|
|
||||||
|
|
||||||
@Setter
|
|
||||||
boolean isOutdated;
|
|
||||||
|
|
||||||
private final List<Plugin> plugins = new CopyOnWriteArrayList<>();
|
private final List<Plugin> plugins = new CopyOnWriteArrayList<>();
|
||||||
private final List<Plugin> activePlugins = new CopyOnWriteArrayList<>();
|
private final List<Plugin> activePlugins = new CopyOnWriteArrayList<>();
|
||||||
private final String runeliteGroupName = RuneLiteConfig.class
|
private final String runeliteGroupName = RuneLiteConfig.class
|
||||||
.getAnnotation(ConfigGroup.class).value();
|
.getAnnotation(ConfigGroup.class).value();
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
boolean isOutdated;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@VisibleForTesting
|
||||||
|
PluginManager(
|
||||||
|
@Named("developerMode") final boolean developerMode,
|
||||||
|
final EventBus eventBus,
|
||||||
|
final Scheduler scheduler,
|
||||||
|
final ConfigManager configManager,
|
||||||
|
final ScheduledExecutorService executor,
|
||||||
|
final SceneTileManager sceneTileManager)
|
||||||
|
{
|
||||||
|
this.developerMode = developerMode;
|
||||||
|
this.eventBus = eventBus;
|
||||||
|
this.scheduler = scheduler;
|
||||||
|
this.configManager = configManager;
|
||||||
|
this.executor = executor;
|
||||||
|
this.sceneTileManager = sceneTileManager;
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onSessionOpen(SessionOpen event)
|
public void onSessionOpen(SessionOpen event)
|
||||||
{
|
{
|
||||||
@@ -204,8 +215,6 @@ public class PluginManager
|
|||||||
|
|
||||||
List<Plugin> scanAndInstantiate(ClassLoader classLoader, String packageName) throws IOException
|
List<Plugin> scanAndInstantiate(ClassLoader classLoader, String packageName) throws IOException
|
||||||
{
|
{
|
||||||
boolean developerPlugins = RuneLite.getOptions().has("developer-mode");
|
|
||||||
|
|
||||||
MutableGraph<Class<? extends Plugin>> graph = GraphBuilder
|
MutableGraph<Class<? extends Plugin>> graph = GraphBuilder
|
||||||
.directed()
|
.directed()
|
||||||
.build();
|
.build();
|
||||||
@@ -242,7 +251,7 @@ public class PluginManager
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pluginDescriptor.developerPlugin() && !developerPlugins)
|
if (pluginDescriptor.developerPlugin() && !developerMode)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ import java.io.IOException;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.runelite.http.api.updatecheck.UpdateCheckClient;
|
import net.runelite.http.api.updatecheck.UpdateCheckClient;
|
||||||
|
|
||||||
@@ -41,13 +41,14 @@ public class ClientLoader
|
|||||||
{
|
{
|
||||||
private final UpdateCheckClient updateCheckClient = new UpdateCheckClient();
|
private final UpdateCheckClient updateCheckClient = new UpdateCheckClient();
|
||||||
private final ClientConfigLoader clientConfigLoader;
|
private final ClientConfigLoader clientConfigLoader;
|
||||||
|
private final ClientUpdateCheckMode updateCheckMode;
|
||||||
@Setter
|
|
||||||
private ClientUpdateCheckMode updateCheckMode = ClientUpdateCheckMode.AUTO;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ClientLoader(final ClientConfigLoader clientConfigLoader)
|
private ClientLoader(
|
||||||
|
@Named("updateCheckMode") final ClientUpdateCheckMode updateCheckMode,
|
||||||
|
final ClientConfigLoader clientConfigLoader)
|
||||||
{
|
{
|
||||||
|
this.updateCheckMode = updateCheckMode;
|
||||||
this.clientConfigLoader = clientConfigLoader;
|
this.clientConfigLoader = clientConfigLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
package net.runelite.client;
|
package net.runelite.client;
|
||||||
|
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
|
import net.runelite.client.rs.ClientUpdateCheckMode;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class RuneLiteModuleTest
|
public class RuneLiteModuleTest
|
||||||
@@ -32,8 +33,6 @@ public class RuneLiteModuleTest
|
|||||||
@Test
|
@Test
|
||||||
public void testConfigure()
|
public void testConfigure()
|
||||||
{
|
{
|
||||||
Guice.createInjector(new RuneLiteModule());
|
Guice.createInjector(new RuneLiteModule(ClientUpdateCheckMode.AUTO, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,153 +1,153 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-2017, Adam <Adam@sigterm.info>
|
* Copyright (c) 2016-2017, Adam <Adam@sigterm.info>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
*
|
*
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
* list of conditions and the following disclaimer.
|
* list of conditions and the following disclaimer.
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
* and/or other materials provided with the distribution.
|
* and/or other materials provided with the distribution.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins;
|
package net.runelite.client.plugins;
|
||||||
|
|
||||||
import com.google.common.reflect.ClassPath;
|
import com.google.common.reflect.ClassPath;
|
||||||
import com.google.common.reflect.ClassPath.ClassInfo;
|
import com.google.common.reflect.ClassPath.ClassInfo;
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
import com.google.inject.grapher.graphviz.GraphvizGrapher;
|
import com.google.inject.grapher.graphviz.GraphvizGrapher;
|
||||||
import com.google.inject.grapher.graphviz.GraphvizModule;
|
import com.google.inject.grapher.graphviz.GraphvizModule;
|
||||||
import com.google.inject.testing.fieldbinder.Bind;
|
import com.google.inject.testing.fieldbinder.Bind;
|
||||||
import com.google.inject.testing.fieldbinder.BoundFieldModule;
|
import com.google.inject.testing.fieldbinder.BoundFieldModule;
|
||||||
import java.applet.Applet;
|
import com.google.inject.util.Modules;
|
||||||
import java.io.File;
|
import java.applet.Applet;
|
||||||
import java.io.IOException;
|
import java.io.File;
|
||||||
import java.io.PrintWriter;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.io.PrintWriter;
|
||||||
import java.util.Collection;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.HashSet;
|
||||||
import java.util.Objects;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Objects;
|
||||||
import joptsimple.OptionSet;
|
import java.util.Set;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.client.RuneLite;
|
import net.runelite.client.RuneLite;
|
||||||
import net.runelite.client.RuneLiteModule;
|
import net.runelite.client.RuneLiteModule;
|
||||||
import static org.junit.Assert.assertEquals;
|
import net.runelite.client.rs.ClientUpdateCheckMode;
|
||||||
import org.junit.Before;
|
import static org.junit.Assert.assertEquals;
|
||||||
import org.junit.Rule;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Rule;
|
||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.rules.TemporaryFolder;
|
||||||
import org.mockito.Mock;
|
import org.junit.runner.RunWith;
|
||||||
import static org.mockito.Mockito.mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class PluginManagerTest
|
public class PluginManagerTest
|
||||||
{
|
{
|
||||||
private static final String PLUGIN_PACKAGE = "net.runelite.client.plugins";
|
private static final String PLUGIN_PACKAGE = "net.runelite.client.plugins";
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public TemporaryFolder folder = new TemporaryFolder();
|
public TemporaryFolder folder = new TemporaryFolder();
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
@Bind
|
@Bind
|
||||||
public Applet applet;
|
public Applet applet;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
@Bind
|
@Bind
|
||||||
public Client client;
|
public Client client;
|
||||||
|
|
||||||
private Set<Class> pluginClasses;
|
private Set<Class> pluginClasses;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void before() throws IOException
|
public void before() throws IOException
|
||||||
{
|
{
|
||||||
RuneLite.setOptions(mock(OptionSet.class));
|
Injector injector = Guice.createInjector(Modules
|
||||||
|
.override(new RuneLiteModule(ClientUpdateCheckMode.AUTO, true))
|
||||||
Injector injector = Guice.createInjector(new RuneLiteModule(),
|
.with(BoundFieldModule.of(this)));
|
||||||
BoundFieldModule.of(this));
|
|
||||||
RuneLite.setInjector(injector);
|
RuneLite.setInjector(injector);
|
||||||
|
|
||||||
// Find plugins we expect to have
|
// Find plugins we expect to have
|
||||||
pluginClasses = new HashSet<>();
|
pluginClasses = new HashSet<>();
|
||||||
Set<ClassInfo> classes = ClassPath.from(getClass().getClassLoader()).getTopLevelClassesRecursive(PLUGIN_PACKAGE);
|
Set<ClassInfo> classes = ClassPath.from(getClass().getClassLoader()).getTopLevelClassesRecursive(PLUGIN_PACKAGE);
|
||||||
for (ClassInfo classInfo : classes)
|
for (ClassInfo classInfo : classes)
|
||||||
{
|
{
|
||||||
Class<?> clazz = classInfo.load();
|
Class<?> clazz = classInfo.load();
|
||||||
PluginDescriptor pluginDescriptor = clazz.getAnnotation(PluginDescriptor.class);
|
PluginDescriptor pluginDescriptor = clazz.getAnnotation(PluginDescriptor.class);
|
||||||
if (pluginDescriptor != null)
|
if (pluginDescriptor != null)
|
||||||
{
|
{
|
||||||
pluginClasses.add(clazz);
|
pluginClasses.add(clazz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoadPlugins() throws Exception
|
public void testLoadPlugins() throws Exception
|
||||||
{
|
{
|
||||||
PluginManager pluginManager = new PluginManager();
|
PluginManager pluginManager = new PluginManager(false, null, null, null, null, null);
|
||||||
pluginManager.setOutdated(true);
|
pluginManager.setOutdated(true);
|
||||||
pluginManager.loadCorePlugins();
|
pluginManager.loadCorePlugins();
|
||||||
Collection<Plugin> plugins = pluginManager.getPlugins();
|
Collection<Plugin> plugins = pluginManager.getPlugins();
|
||||||
long expected = pluginClasses.stream()
|
long expected = pluginClasses.stream()
|
||||||
.map(cl -> (PluginDescriptor) cl.getAnnotation(PluginDescriptor.class))
|
.map(cl -> (PluginDescriptor) cl.getAnnotation(PluginDescriptor.class))
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.filter(PluginDescriptor::loadWhenOutdated)
|
.filter(PluginDescriptor::loadWhenOutdated)
|
||||||
.count();
|
.count();
|
||||||
assertEquals(expected, plugins.size());
|
assertEquals(expected, plugins.size());
|
||||||
|
|
||||||
pluginManager = new PluginManager();
|
pluginManager = new PluginManager(false, null, null, null, null, null);
|
||||||
pluginManager.loadCorePlugins();
|
pluginManager.loadCorePlugins();
|
||||||
plugins = pluginManager.getPlugins();
|
plugins = pluginManager.getPlugins();
|
||||||
|
|
||||||
expected = pluginClasses.stream()
|
expected = pluginClasses.stream()
|
||||||
.map(cl -> (PluginDescriptor) cl.getAnnotation(PluginDescriptor.class))
|
.map(cl -> (PluginDescriptor) cl.getAnnotation(PluginDescriptor.class))
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.filter(pd -> !pd.developerPlugin())
|
.filter(pd -> !pd.developerPlugin())
|
||||||
.count();
|
.count();
|
||||||
assertEquals(expected, plugins.size());
|
assertEquals(expected, plugins.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dumpGraph() throws Exception
|
public void dumpGraph() throws Exception
|
||||||
{
|
{
|
||||||
List<Module> modules = new ArrayList<>();
|
List<Module> modules = new ArrayList<>();
|
||||||
modules.add(new GraphvizModule());
|
modules.add(new GraphvizModule());
|
||||||
modules.add(new RuneLiteModule());
|
modules.add(new RuneLiteModule(ClientUpdateCheckMode.AUTO, true));
|
||||||
|
|
||||||
PluginManager pluginManager = new PluginManager();
|
PluginManager pluginManager = new PluginManager(true, null, null, null, null, null);
|
||||||
pluginManager.loadCorePlugins();
|
pluginManager.loadCorePlugins();
|
||||||
for (Plugin p : pluginManager.getPlugins())
|
for (Plugin p : pluginManager.getPlugins())
|
||||||
{
|
{
|
||||||
modules.add(p);
|
modules.add(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
File file = folder.newFile();
|
File file = folder.newFile();
|
||||||
try (PrintWriter out = new PrintWriter(file, "UTF-8"))
|
try (PrintWriter out = new PrintWriter(file, "UTF-8"))
|
||||||
{
|
{
|
||||||
Injector injector = Guice.createInjector(modules);
|
Injector injector = Guice.createInjector(modules);
|
||||||
GraphvizGrapher grapher = injector.getInstance(GraphvizGrapher.class);
|
GraphvizGrapher grapher = injector.getInstance(GraphvizGrapher.class);
|
||||||
grapher.setOut(out);
|
grapher.setOut(out);
|
||||||
grapher.setRankdir("TB");
|
grapher.setRankdir("TB");
|
||||||
grapher.graph(injector);
|
grapher.graph(injector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user