Search in sources :

Example 1 with InvalidMvp4gConfigurationException

use of com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException in project mvp4g by mvp4g.

the class Mvp4gGenerator method create.

private RebindResult create(TreeLogger logger, GeneratorContext context, String moduleName) throws UnableToCompleteException {
    Date start = new Date();
    String generatedClassQualifiedName;
    try {
        TypeOracle typeOracle = context.getTypeOracle();
        JClassType module = typeOracle.findType(moduleName);
        if (module == null) {
            logger.log(TreeLogger.ERROR, "Unable to find metadata for type '" + moduleName + "'", null);
            throw new UnableToCompleteException();
        }
        @SuppressWarnings("unchecked") Map<Class<? extends Annotation>, List<JClassType>> scanResult = AnnotationScanner.scan(logger, typeOracle, new Class[] { Presenter.class, History.class, Events.class, Service.class, EventHandler.class });
        Mvp4gConfiguration configuration = new Mvp4gConfiguration(logger, context);
        String suffix = "Impl" + configuration.load(module, scanResult);
        generatedClassQualifiedName = module.getParameterizedQualifiedSourceName() + suffix;
        String packageName = module.getPackage().getName();
        String originalClassName = module.getSimpleSourceName();
        String generatedClassName = originalClassName + suffix;
        // check weather there is a usual version or not.
        if (checkAlreadyGenerated(logger, context, configuration)) {
            // Log
            logger.log(TreeLogger.INFO, "Reuse already generated files", null);
            // stop generating
            return new RebindResult(RebindMode.USE_EXISTING, packageName + "." + generatedClassName);
        }
        // Log
        logger.log(TreeLogger.INFO, "Start generate files ... ", null);
        // No, there is non. Create a new one.
        SourceWriter sourceWriter = getSourceWriter(logger, context, module, packageName, generatedClassName);
        if (sourceWriter != null) {
            logger.log(TreeLogger.INFO, "Generating source for " + generatedClassQualifiedName + " ", null);
            Mvp4gConfigurationFileWriter writer = new Mvp4gConfigurationFileWriter(sourceWriter, configuration);
            writer.writeConf();
            sourceWriter.commit(logger);
        } else {
            // don't expect this to occur, but could happen if an instance was
            // recently generated but not yet committed
            new RebindResult(RebindMode.USE_EXISTING, generatedClassQualifiedName);
        }
        Date end = new Date();
        logger.log(TreeLogger.INFO, "Mvp4g Compilation: " + (end.getTime() - start.getTime()) + "ms.");
        return new RebindResult(RebindMode.USE_ALL_NEW_WITH_NO_CACHING, packageName + "." + generatedClassName);
    } catch (InvalidMvp4gConfigurationException e) {
        logger.log(TreeLogger.ERROR, e.getMessage(), e);
        throw new UnableToCompleteException();
    }
}
Also used : Mvp4gConfiguration(com.mvp4g.rebind.config.Mvp4gConfiguration) InvalidMvp4gConfigurationException(com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException) SourceWriter(com.google.gwt.user.rebind.SourceWriter) Date(java.util.Date) Annotation(java.lang.annotation.Annotation) JClassType(com.google.gwt.core.ext.typeinfo.JClassType) TypeOracle(com.google.gwt.core.ext.typeinfo.TypeOracle) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) List(java.util.List) RebindResult(com.google.gwt.core.ext.RebindResult)

Example 2 with InvalidMvp4gConfigurationException

use of com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException in project mvp4g by mvp4g.

the class Mvp4gConfigurationTest method testHistoryWhenParent.

@Test
public void testHistoryWhenParent() throws InvalidMvp4gConfigurationException {
    historyConverters.add(new HistoryConverterElement());
    configuration.setModule(oracle.addClass(Modules.ModuleWithParent01.class));
    // configuration.setModule( oracle.addClass( Modules.ModuleWithParent01.class ) );
    setParentEventBus(Modules.ModuleWithParent01.class, EventBusOk.class);
    configuration.loadParentModule();
    configuration.getHistory().setInitEvent("event");
    try {
        configuration.validateHistory();
        fail();
    } catch (InvalidMvp4gConfigurationException e) {
        assertEquals("Module com.mvp4g.rebind.test_tools.Modules.ModuleWithParent01: History configuration (init, not found event and history parameter separator) should be set only for root module (only module with no parent)", e.getMessage());
    }
    HistoryElement history = new HistoryElement();
    configuration.setHistory(history);
    history.setNotFoundEvent("event");
    try {
        configuration.validateHistory();
        fail();
    } catch (InvalidMvp4gConfigurationException e) {
        assertEquals("Module com.mvp4g.rebind.test_tools.Modules.ModuleWithParent01: History configuration (init, not found event and history parameter separator) should be set only for root module (only module with no parent)", e.getMessage());
    }
    history = new HistoryElement();
    configuration.setHistory(history);
    configuration.validateHistory();
    assertNull(configuration.getHistory());
}
Also used : HistoryElement(com.mvp4g.rebind.config.element.HistoryElement) HistoryConverterElement(com.mvp4g.rebind.config.element.HistoryConverterElement) InvalidMvp4gConfigurationException(com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException) Modules(com.mvp4g.rebind.test_tools.Modules) Test(org.junit.Test)

Example 3 with InvalidMvp4gConfigurationException

use of com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException in project mvp4g by mvp4g.

the class Mvp4gConfigurationTest method testGin01.

@Test
public void testGin01() throws InvalidMvp4gConfigurationException {
    GinModuleElement gin = new GinModuleElement();
    configuration.setGinModule(gin);
    try {
        configuration.validateGinModule();
        fail();
    } catch (InvalidMvp4gConfigurationException e) {
        assertEquals(e.getMessage(), "You need to define at least one GIN module. If you don't want to specify a GIN module, don't override the GIN modules option to use the default Mvp4g GIN module.");
    }
    gin = new GinModuleElement();
    oracle.addClass(OneObject.class);
    gin.setModules(new String[] { OneObject.class.getCanonicalName() });
    configuration.setGinModule(gin);
    try {
        configuration.validateGinModule();
        fail();
    } catch (InvalidTypeException e) {
        assertTrue(e.getMessage().contains(GinModule.class.getCanonicalName()));
    }
    String[] propertiesValues;
    gin = new GinModuleElement();
    oracle.addClass(DefaultMvp4gGinModule.class);
    gin.setModules(new String[] { DefaultMvp4gGinModule.class.getCanonicalName() });
    configuration.setGinModule(gin);
    propertiesValues = configuration.validateGinModule();
    assertNull(propertiesValues);
    assertEquals(gin.getModules().size(), 1);
}
Also used : GinModuleElement(com.mvp4g.rebind.config.element.GinModuleElement) InvalidMvp4gConfigurationException(com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException) DefaultMvp4gGinModule(com.mvp4g.client.DefaultMvp4gGinModule) OneGinModule(com.mvp4g.rebind.test_tools.annotation.gin.OneGinModule) DefaultMvp4gGinModule(com.mvp4g.client.DefaultMvp4gGinModule) GinModule(com.google.gwt.inject.client.GinModule) OneObject(com.mvp4g.rebind.test_tools.OneObject) InvalidTypeException(com.mvp4g.rebind.exception.InvalidTypeException) Test(org.junit.Test)

Example 4 with InvalidMvp4gConfigurationException

use of com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException in project mvp4g by mvp4g.

the class Mvp4gConfigurationTest method testEventWithParent.

@Test
public void testEventWithParent() throws InvalidMvp4gConfigurationException {
    EventElement e = newEvent("event");
    e.setForwardToParent("true");
    events.add(e);
    try {
        configuration.validateEvents();
        fail();
    } catch (InvalidMvp4gConfigurationException ex) {
        assertEquals("Event event: Root module has no parent so you can't forward event to parent.", ex.getMessage());
    }
    configuration.setModule(oracle.addClass(Modules.ModuleWithParent01.class));
    setParentEventBus(Modules.ModuleWithParent01.class, EventBusOk.class);
    configuration.loadParentModule();
    configuration.validateEvents();
}
Also used : EventElement(com.mvp4g.rebind.config.element.EventElement) InvalidMvp4gConfigurationException(com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException) Modules(com.mvp4g.rebind.test_tools.Modules) Test(org.junit.Test)

Example 5 with InvalidMvp4gConfigurationException

use of com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException in project mvp4g by mvp4g.

the class Mvp4gConfigurationTest method testGenerateNotMultiple.

@Test
public void testGenerateNotMultiple() throws InvalidMvp4gConfigurationException {
    EventBusElement eventBus = new EventBusElement(EventBusWithLookup.class.getName(), BaseEventBus.class.getName(), false);
    configuration.setEventBus(eventBus);
    EventElement event1 = newEvent("event1");
    event1.setHandlers(new String[] { "generate2" });
    event1.setGenerate(new String[] { "generate1", "generate2" });
    events.add(event1);
    ViewElement view = newView(SimpleView02.class, "view");
    view.setClassName(SimpleView02.class.getCanonicalName());
    views.add(view);
    PresenterElement generate1 = newPresenter(SimplePresenter01.class, "generate1");
    generate1.setView("view");
    EventHandlerElement generate2 = newEventHandler(SimpleEventHandler01.class, "generate2");
    presenters.add(generate1);
    try {
        configuration.validateEventHandlers();
        fail();
    } catch (InvalidMvp4gConfigurationException e) {
        assertTrue(e.getMessage().contains("Event event1: you can generate only multiple handlers. Did you forget to set the attribute multiple to true for generate1?"));
    }
    presenters.clear();
    eventHandlers.clear();
    eventHandlers.add(generate2);
    try {
        configuration.validateEventHandlers();
        fail();
    } catch (InvalidMvp4gConfigurationException e) {
        assertTrue(e.getMessage().contains("Event event1: you can generate only multiple handlers. Did you forget to set the attribute multiple to true for generate2?"));
    }
}
Also used : SimpleView02(com.mvp4g.rebind.test_tools.annotation.views.SimpleView02) EventElement(com.mvp4g.rebind.config.element.EventElement) InvalidMvp4gConfigurationException(com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException) EventBusElement(com.mvp4g.rebind.config.element.EventBusElement) EventBusWithLookup(com.mvp4g.client.event.EventBusWithLookup) BaseEventBus(com.mvp4g.client.event.BaseEventBus) EventHandlerElement(com.mvp4g.rebind.config.element.EventHandlerElement) ViewElement(com.mvp4g.rebind.config.element.ViewElement) PresenterElement(com.mvp4g.rebind.config.element.PresenterElement) Test(org.junit.Test)

Aggregations

InvalidMvp4gConfigurationException (com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException)27 Test (org.junit.Test)26 EventElement (com.mvp4g.rebind.config.element.EventElement)18 OneObject (com.mvp4g.rebind.test_tools.OneObject)11 Modules (com.mvp4g.rebind.test_tools.Modules)9 ChildModuleElement (com.mvp4g.rebind.config.element.ChildModuleElement)5 JClassType (com.google.gwt.core.ext.typeinfo.JClassType)3 GinModule (com.google.gwt.inject.client.GinModule)3 DefaultMvp4gGinModule (com.mvp4g.client.DefaultMvp4gGinModule)3 BaseEventBus (com.mvp4g.client.event.BaseEventBus)3 EventBusElement (com.mvp4g.rebind.config.element.EventBusElement)3 GinModuleElement (com.mvp4g.rebind.config.element.GinModuleElement)3 PresenterElement (com.mvp4g.rebind.config.element.PresenterElement)3 StartElement (com.mvp4g.rebind.config.element.StartElement)3 InvalidTypeException (com.mvp4g.rebind.exception.InvalidTypeException)3 EventBusOk (com.mvp4g.rebind.test_tools.annotation.events.EventBusOk)3 OneGinModule (com.mvp4g.rebind.test_tools.annotation.gin.OneGinModule)3 EventBusWithLookup (com.mvp4g.client.event.EventBusWithLookup)2 HistoryConverterElement (com.mvp4g.rebind.config.element.HistoryConverterElement)2 ViewElement (com.mvp4g.rebind.config.element.ViewElement)2