]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fail build SerializerMapGenerator finds unserializable class (#8711)
authorLeif Åstrand <leif@vaadin.com>
Wed, 25 Jul 2012 08:17:36 +0000 (11:17 +0300)
committerLeif Åstrand <leif@vaadin.com>
Wed, 25 Jul 2012 08:17:36 +0000 (11:17 +0300)
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
src/com/vaadin/terminal/gwt/widgetsetutils/SerializerMapGenerator.java

index 0e6f1b40dde0e288b9e0a38ebf13c3b8f868b298..e01d33db3e78906f4bb9b564ca6b9d7cb3c3c955 100644 (file)
             <arg value="${widgetset-localWorkers}" />
             <arg line="${widgetset-extraParams}" />
             <arg value="${widgetset}" />
+               
+               <sysproperty key="vFailIfNotSerializable" value="true" />
 
             <jvmarg value="-Xss8M"/>
             <jvmarg value="-XX:MaxPermSize=256M"/>  
index 2da2c85d8b95d5307b2317e9b3cca601eaaf990c..ab216693d71d374844ad041a180427861725f27d 100644 (file)
@@ -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<JClassType> typesNeedingSerializers = findTypesNeedingSerializers(
                     typeOracle, logger);
-            warnIfNotJavaSerializable(typesNeedingSerializers, typeOracle,
+            checkForUnserializableTypes(typesNeedingSerializers, typeOracle,
                     logger);
             Set<JClassType> 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<JClassType> 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();
+                }
             }
         }
     }