Search in sources :

Example 1 with ClassCollector

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

the class DebugSectionConsistencyTest method collectClasses.

@BeforeClass
public static void collectClasses() {
    // TODO ljacqu 20171021: Improve ClassCollector (pass pkg by class, improve #getInstancesOfType's instantiation)
    ClassCollector classCollector = new ClassCollector(TestHelper.SOURCES_FOLDER, TestHelper.PROJECT_ROOT + "command/executable/authme/debug");
    debugClasses = classCollector.collectClasses();
    debugSections = classCollector.getInstancesOfType(DebugSection.class, clz -> instantiate(clz));
}
Also used : ClassCollector(fr.xephi.authme.ClassCollector) BeforeClass(org.junit.BeforeClass) Matchers.not(org.hamcrest.Matchers.not) Set(java.util.Set) Test(org.junit.Test) HashSet(java.util.HashSet) Assert.assertThat(org.junit.Assert.assertThat) List(java.util.List) Modifier(java.lang.reflect.Modifier) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Assert.fail(org.junit.Assert.fail) TestHelper(fr.xephi.authme.TestHelper) ClassCollector(fr.xephi.authme.ClassCollector) BeforeClass(org.junit.BeforeClass)

Example 2 with ClassCollector

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

the class PermissionConsistencyTest method gatherPermissionNodes.

@BeforeClass
public static void gatherPermissionNodes() {
    permissionClasses = new ClassCollector(TestHelper.SOURCES_FOLDER, TestHelper.PROJECT_ROOT + "permission").collectClasses(PermissionNode.class).stream().filter(clz -> !clz.isInterface()).collect(Collectors.toList());
    permissionNodes = getPermissionsFromClasses();
    pluginYmlPermissions = getPermissionsFromPluginYmlFile();
}
Also used : ClassCollector(fr.xephi.authme.ClassCollector) BeforeClass(org.junit.BeforeClass)

Example 3 with ClassCollector

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

the class PermissionNodesGatherer method getPermissionClasses.

/**
 * Return all enum classes implementing the PermissionNode interface.
 *
 * @return all permission node enums
 */
public List<Class<? extends PermissionNode>> getPermissionClasses() {
    if (permissionClasses == null) {
        ClassCollector classCollector = new ClassCollector(ToolsConstants.MAIN_SOURCE_ROOT, "");
        permissionClasses = classCollector.collectClasses(PermissionNode.class).stream().filter(Class::isEnum).collect(Collectors.toList());
    }
    return permissionClasses;
}
Also used : ClassCollector(fr.xephi.authme.ClassCollector)

Example 4 with ClassCollector

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

the class DrawDependency method execute.

@Override
public void execute(Scanner scanner) {
    System.out.println("Summarize classes to their generic super type where applicable?");
    mapToSupertype = "y".equalsIgnoreCase(scanner.nextLine());
    // Gather all connections
    ClassCollector collector = new ClassCollector(TestHelper.SOURCES_FOLDER, TestHelper.PROJECT_ROOT);
    for (Class<?> clazz : collector.collectClasses()) {
        processClass(clazz);
    }
    // Prompt user for simplification of graph
    System.out.println("Do you want to remove classes that are not used as dependency elsewhere?");
    System.out.println("Specify the number of times to do this: [0=keep all]");
    int stripVerticesCount;
    try {
        stripVerticesCount = Integer.valueOf(scanner.nextLine());
    } catch (NumberFormatException e) {
        stripVerticesCount = 0;
    }
    // Perform simplification as per user's wish
    for (int i = 0; i < stripVerticesCount; ++i) {
        stripNodesWithNoOutgoingEdges();
    }
    // Create dot file content
    final String pattern = "\t\"%s\" -> \"%s\";";
    String dotFile = "";
    for (Map.Entry<Class<?>, String> entry : foundDependencies.entries()) {
        dotFile += "\n" + String.format(pattern, entry.getValue(), entry.getKey().getSimpleName());
    }
    // Write dot file
    try {
        Files.write(Paths.get(DOT_FILE), ("digraph G {\n" + dotFile + "\n}").getBytes());
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    System.out.println("Graph file written");
    System.out.format("Run 'dot -Tpng %s -o graph.png' to generate image (requires GraphViz)%n", DOT_FILE);
}
Also used : ClassCollector(fr.xephi.authme.ClassCollector) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 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)10 BeforeClass (org.junit.BeforeClass)6 SettingsHolder (ch.jalu.configme.SettingsHolder)2 TestHelper (fr.xephi.authme.TestHelper)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Assert.fail (org.junit.Assert.fail)2 Test (org.junit.Test)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 AuthMeSettingsRetriever (fr.xephi.authme.settings.properties.AuthMeSettingsRetriever)1