Search in sources :

Example 1 with SystemConfigurationException

use of org.kanonizo.exception.SystemConfigurationException in project kanonizo by kanonizo.

the class Main method getAlgorithm.

private static SearchAlgorithm getAlgorithm(String algorithmChoice) throws InstantiationException, IllegalAccessException {
    Reflections r = Util.getReflections();
    Set<Class<?>> algorithms = r.getTypesAnnotatedWith(Algorithm.class);
    Optional<?> algorithmClass = algorithms.stream().map(cl -> {
        try {
            return cl.newInstance();
        } catch (IllegalAccessException | InstantiationException e) {
            logger.error(e);
        }
        return null;
    }).filter(obj -> ((SearchAlgorithm) obj).readableName().equals(algorithmChoice)).findFirst();
    if (algorithmClass.isPresent()) {
        SearchAlgorithm algorithm = (SearchAlgorithm) algorithmClass.get();
        List<Method> requirements = Framework.getPrerequisites(algorithm);
        boolean anyFail = false;
        for (Method requirement : requirements) {
            try {
                boolean passed = (boolean) requirement.invoke(null, null);
                if (!passed) {
                    anyFail = true;
                    String error = requirement.getAnnotation(Prerequisite.class).failureMessage();
                    logger.error("System is improperly configured: " + error);
                }
            } catch (InvocationTargetException e) {
                logger.error(e);
            }
        }
        if (anyFail) {
            throw new SystemConfigurationException("");
        }
        return algorithm;
    }
    List<String> algorithmNames = Framework.getAvailableAlgorithms().stream().map(alg -> alg.readableName()).collect(Collectors.toList());
    throw new RuntimeException("Algorithm could not be created. The list of available algorithms is given as: " + algorithmNames.stream().reduce((s, s2) -> s + "\n" + s2));
}
Also used : TestSuite(org.kanonizo.framework.objects.TestSuite) ConsoleDisplay(org.kanonizo.display.ConsoleDisplay) Options(org.apache.commons.cli.Options) Reflections(org.reflections.Reflections) Parameter(com.scythe.instrumenter.InstrumentationProperties.Parameter) HelpFormatter(org.apache.commons.cli.HelpFormatter) MutationProperties(com.scythe.instrumenter.mutation.MutationProperties) DefaultParser(org.apache.commons.cli.DefaultParser) TestCase(org.kanonizo.framework.objects.TestCase) Instrumenter(org.kanonizo.framework.instrumentation.Instrumenter) CommandLine(org.apache.commons.cli.CommandLine) Prerequisite(org.kanonizo.annotations.Prerequisite) SystemConfigurationException(org.kanonizo.exception.SystemConfigurationException) Method(java.lang.reflect.Method) SearchAlgorithm(org.kanonizo.algorithms.SearchAlgorithm) InstrumentingClassLoader(com.scythe.instrumenter.instrumentation.InstrumentingClassLoader) Set(java.util.Set) Field(java.lang.reflect.Field) MissingOptionException(org.apache.commons.cli.MissingOptionException) Algorithm(org.kanonizo.annotations.Algorithm) Collectors(java.util.stream.Collectors) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) KanonizoFrame(org.kanonizo.display.fx.KanonizoFrame) Util(org.kanonizo.util.Util) Logger(org.apache.logging.log4j.Logger) SystemUnderTest(org.kanonizo.framework.objects.SystemUnderTest) Optional(java.util.Optional) Display(org.kanonizo.display.Display) LogManager(org.apache.logging.log4j.LogManager) SearchAlgorithm(org.kanonizo.algorithms.SearchAlgorithm) SystemConfigurationException(org.kanonizo.exception.SystemConfigurationException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) Reflections(org.reflections.Reflections) Prerequisite(org.kanonizo.annotations.Prerequisite)

Aggregations

Parameter (com.scythe.instrumenter.InstrumentationProperties.Parameter)1 InstrumentingClassLoader (com.scythe.instrumenter.instrumentation.InstrumentingClassLoader)1 MutationProperties (com.scythe.instrumenter.mutation.MutationProperties)1 File (java.io.File)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 CommandLine (org.apache.commons.cli.CommandLine)1 DefaultParser (org.apache.commons.cli.DefaultParser)1 HelpFormatter (org.apache.commons.cli.HelpFormatter)1 MissingOptionException (org.apache.commons.cli.MissingOptionException)1 Options (org.apache.commons.cli.Options)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 SearchAlgorithm (org.kanonizo.algorithms.SearchAlgorithm)1 Algorithm (org.kanonizo.annotations.Algorithm)1