Search in sources :

Example 6 with ClassCollector

use of fr.xephi.authme.ClassCollector in project AuthMeReloaded by AuthMe.

the class ToolsRunner method main.

/**
     * Entry point of the runner.
     *
     * @param args .
     */
public static void main(String... args) {
    // Note ljacqu 20151212: If the tools folder becomes a lot bigger, it will make sense to restrict the depth
    // of this recursive collector
    ClassCollector collector = new ClassCollector(TestHelper.TEST_SOURCES_FOLDER, "tools");
    Map<String, ToolTask> tasks = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
    for (ToolTask task : collector.getInstancesOfType(ToolTask.class)) {
        tasks.put(task.getTaskName(), task);
    }
    ToolsRunner runner = new ToolsRunner(tasks);
    if (args == null || args.length == 0) {
        runner.promptAndExecuteTask();
    } else {
        runner.executeAutomaticTasks(args);
    }
}
Also used : ToolTask(tools.utils.ToolTask) AutoToolTask(tools.utils.AutoToolTask) ClassCollector(fr.xephi.authme.ClassCollector) TreeMap(java.util.TreeMap)

Example 7 with ClassCollector

use of fr.xephi.authme.ClassCollector in project AuthMeReloaded by AuthMe.

the class CheckTestMocks method executeDefault.

@Override
public void executeDefault() {
    ClassCollector collector = new ClassCollector(TestHelper.TEST_SOURCES_FOLDER, TestHelper.PROJECT_ROOT);
    for (Class<?> clazz : collector.collectClasses(c -> isTestClassWithMocks(c))) {
        checkClass(clazz);
    }
    System.out.println(String.join("\n", errors));
}
Also used : ClassCollector(fr.xephi.authme.ClassCollector)

Example 8 with ClassCollector

use of fr.xephi.authme.ClassCollector in project AuthMeReloaded by AuthMe.

the class SettingsClassConsistencyTest method scanForSettingsClasses.

@BeforeClass
public static void scanForSettingsClasses() {
    ClassCollector collector = new ClassCollector(TestHelper.SOURCES_FOLDER, SETTINGS_FOLDER);
    classes = collector.collectClasses(SettingsHolder.class);
    if (classes.isEmpty()) {
        throw new IllegalStateException("Did not find any SettingsHolder classes. Is the folder correct?");
    }
    System.out.println("Found " + classes.size() + " SettingsHolder implementations");
}
Also used : ClassCollector(fr.xephi.authme.ClassCollector) SettingsHolder(ch.jalu.configme.SettingsHolder) BeforeClass(org.junit.BeforeClass)

Example 9 with ClassCollector

use of fr.xephi.authme.ClassCollector in project AuthMeReloaded by AuthMe.

the class SettingsConsistencyTest method getSectionCommentMethods.

/**
     * Gets all {@link SectionComments} methods from {@link SettingsHolder} implementations.
     */
@SuppressWarnings("unchecked")
private List<Method> getSectionCommentMethods() {
    // Find all SettingsHolder classes
    List<Class<? extends SettingsHolder>> settingsClasses = new ClassCollector(TestHelper.SOURCES_FOLDER, TestHelper.PROJECT_ROOT + "settings/properties/").collectClasses(SettingsHolder.class);
    checkArgument(!settingsClasses.isEmpty(), "Could not find any SettingsHolder classes");
    // Find all @SectionComments methods in these classes
    return settingsClasses.stream().map(Class::getDeclaredMethods).flatMap(Arrays::stream).filter(method -> method.isAnnotationPresent(SectionComments.class)).collect(Collectors.toList());
}
Also used : SecuritySettings(fr.xephi.authme.settings.properties.SecuritySettings) Arrays(java.util.Arrays) ClassCollector(fr.xephi.authme.ClassCollector) BeforeClass(org.junit.BeforeClass) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Map(java.util.Map) SettingsHolder(ch.jalu.configme.SettingsHolder) ConfigurationData(ch.jalu.configme.configurationdata.ConfigurationData) Assert.fail(org.junit.Assert.fail) TestHelper(fr.xephi.authme.TestHelper) Method(java.lang.reflect.Method) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Test(org.junit.Test) EnumProperty(ch.jalu.configme.properties.EnumProperty) Collectors(java.util.stream.Collectors) ReflectionTestUtils(fr.xephi.authme.ReflectionTestUtils) ReflectionTestUtils.getFieldValue(fr.xephi.authme.ReflectionTestUtils.getFieldValue) List(java.util.List) Property(ch.jalu.configme.properties.Property) AuthMeSettingsRetriever(fr.xephi.authme.settings.properties.AuthMeSettingsRetriever) SectionComments(ch.jalu.configme.SectionComments) ClassCollector(fr.xephi.authme.ClassCollector) BeforeClass(org.junit.BeforeClass) Arrays(java.util.Arrays) SettingsHolder(ch.jalu.configme.SettingsHolder)

Aggregations

ClassCollector (fr.xephi.authme.ClassCollector)9 BeforeClass (org.junit.BeforeClass)5 SettingsHolder (ch.jalu.configme.SettingsHolder)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 SectionComments (ch.jalu.configme.SectionComments)1 ConfigurationData (ch.jalu.configme.configurationdata.ConfigurationData)1 EnumProperty (ch.jalu.configme.properties.EnumProperty)1 Property (ch.jalu.configme.properties.Property)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ReflectionTestUtils (fr.xephi.authme.ReflectionTestUtils)1 ReflectionTestUtils.getFieldValue (fr.xephi.authme.ReflectionTestUtils.getFieldValue)1 TestHelper (fr.xephi.authme.TestHelper)1 AuthMeSettingsRetriever (fr.xephi.authme.settings.properties.AuthMeSettingsRetriever)1 SecuritySettings (fr.xephi.authme.settings.properties.SecuritySettings)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1