From df98f12cb627c0272ab3fc4dd7175df5553118a3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Wed, 25 Jul 2012 11:17:36 +0300 Subject: [PATCH] Fail build SerializerMapGenerator finds unserializable class (#8711) This behavior is enabled by setting the system property vFailIfNotSerializable to true. The default is still to just log a warning but still continue compiling. --- build/build.xml | 2 ++ .../SerializerMapGenerator.java | 20 ++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/build/build.xml b/build/build.xml index 0e6f1b40dd..e01d33db3e 100644 --- a/build/build.xml +++ b/build/build.xml @@ -593,6 +593,8 @@ + + diff --git a/src/com/vaadin/terminal/gwt/widgetsetutils/SerializerMapGenerator.java b/src/com/vaadin/terminal/gwt/widgetsetutils/SerializerMapGenerator.java index 2da2c85d8b..ab216693d7 100644 --- a/src/com/vaadin/terminal/gwt/widgetsetutils/SerializerMapGenerator.java +++ b/src/com/vaadin/terminal/gwt/widgetsetutils/SerializerMapGenerator.java @@ -43,6 +43,7 @@ import com.vaadin.terminal.gwt.client.communication.SharedState; */ public class SerializerMapGenerator extends Generator { + private static final String FAIL_IF_NOT_SERIALIZABLE = "vFailIfNotSerializable"; private String packageName; private String className; @@ -54,7 +55,7 @@ public class SerializerMapGenerator extends Generator { TypeOracle typeOracle = context.getTypeOracle(); Set typesNeedingSerializers = findTypesNeedingSerializers( typeOracle, logger); - warnIfNotJavaSerializable(typesNeedingSerializers, typeOracle, + checkForUnserializableTypes(typesNeedingSerializers, typeOracle, logger); Set typesWithExistingSerializers = findTypesWithExistingSerializers( typeOracle, logger); @@ -90,10 +91,11 @@ public class SerializerMapGenerator extends Generator { * @param typesNeedingSerializers * @param typeOracle * @param logger + * @throws UnableToCompleteException */ - private void warnIfNotJavaSerializable( + private void checkForUnserializableTypes( Set typesNeedingSerializers, TypeOracle typeOracle, - TreeLogger logger) { + TreeLogger logger) throws UnableToCompleteException { JClassType javaSerializable = typeOracle.findType(Serializable.class .getName()); for (JClassType type : typesNeedingSerializers) { @@ -103,12 +105,20 @@ public class SerializerMapGenerator extends Generator { } boolean serializable = type.isAssignableTo(javaSerializable); if (!serializable) { + boolean abortCompile = "true".equals(System + .getProperty(FAIL_IF_NOT_SERIALIZABLE)); logger.log( - Type.ERROR, + abortCompile ? Type.ERROR : Type.WARN, type + " is used in RPC or shared state but does not implement " + Serializable.class.getName() - + ". Communication will work but the Application on server side cannot be serialized if it refers to objects of this type."); + + ". Communication will work but the Application on server side cannot be serialized if it refers to objects of this type. " + + "If the system property " + + FAIL_IF_NOT_SERIALIZABLE + + " is set to \"true\", this causes the compilation to fail instead of just emitting a warning."); + if (abortCompile) { + throw new UnableToCompleteException(); + } } } } -- 2.39.5