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();
}
}
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());
}
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);
}
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();
}
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?"));
}
}
Aggregations