All Downloads are FREE. Search and download functionalities are using the official Maven repository.

xapi.dev.util.CurrentGwtPlatform Maven / Gradle / Ivy

Go to download

Everything needed to run a comprehensive dev environment. Just type X_ and pick a service from autocomplete; new dev modules will be added as they are built. The only dev service not included in the uber jar is xapi-dev-maven, as it includes all runtime dependencies of maven, adding ~4 seconds to build time, and 6 megabytes to the final output jar size (without xapi-dev-maven, it's ~1MB).

The newest version!
package xapi.dev.util;

import java.lang.annotation.Annotation;
import java.util.List;

import xapi.collect.impl.AbstractMultiInitMap;
import xapi.except.NotConfiguredCorrectly;
import xapi.platform.Platform;
import xapi.util.X_Util;

import com.google.gwt.core.ext.ConfigurationProperty;
import com.google.gwt.core.ext.GeneratorContext;

public class CurrentGwtPlatform {

  private static final AbstractMultiInitMap
    runtime = new AbstractMultiInitMap(
      AbstractMultiInitMap.PASS_THRU) {

	@SuppressWarnings("unchecked")
  @Override
    protected PlatformSet initialize(String key, GeneratorContext context) {
      PlatformSet all = new PlatformSet();
      boolean isDebug;
      try {
        ConfigurationProperty debugProp = context.getPropertyOracle().getConfigurationProperty("xapi.debug");
        isDebug = debugProp == null ? false : debugProp.getValues().contains("true");
      }catch (Exception e) {
        isDebug = false;
      }

      // Step one: load the platform type we need.
      try {
        Class cls = Class.forName(key);
        assert (Annotation.class.isAssignableFrom(cls)) :
          "You may only use annotation types when selecting a platform type. " +
          "You sent "+key;
        // Once we have the class, let's grab it's Platform annotation.
        Platform platform = cls.getAnnotation(Platform.class);
        if (!isDebug && platform.isDebug()) {
          // debug mismatch.  bail now.
          return all;
        }
        if (platform == null)
          throw new NotConfiguredCorrectly(
            "You have specified a runtime platform of type "+key+", but this " +
            		"annotation is not annotated with @Platform."
          );
        assert !platform.isServer() : "Server platforms should never be used in gwt.  " +
        		"Check your annotation hierarchy for unexpected fallback types.";
        // prefer self first
        all.add((Class)cls);
        //now, throw in any fallback types...
        for (Class fallback : platform.fallback()) {
          // need to check these fallback types for debug level as well.
          Platform anno = fallback.getAnnotation(Platform.class);
          // more helpful error message than NPE if something went wrong.
          assert anno != null : "Fallback annotation "+fallback.getName()+" " +
          		"is specified as a platform type, but is not annotated w/ @Platform";
          if (isDebug || !anno.isDebug()) {
            // only add types if they are non-debug type, or we are in debug mode.
            all.add(fallback);
          }
        }
      } catch (Exception e) {
        // probably don't have the annotation types on classpath...
        e.printStackTrace();
        assert false : e;
      }
      return all;
    };
  };

  public static PlatformSet getPlatforms(GeneratorContext context) {
    final ConfigurationProperty prop;
    try {
      if (context.isProdMode()) {
        prop = context.getPropertyOracle().getConfigurationProperty("xapi.platform.prod");
      } else {
        prop = context.getPropertyOracle().getConfigurationProperty("xapi.platform.dev");
      }
    } catch (Throwable e) {
      throw X_Util.rethrow(e);
    }
    // TODO: filter on isDebug based on whether or not the flag is set...
    PlatformSet platforms = new PlatformSet();
    List vals = prop.getValues();
    for (int i = 0; i < vals.size(); i++) {
      for (Class platform : runtime.get(vals.get(i), context)) {
        platforms.add(platform);
      }
    }
    assert platforms.size() > 0 : "No runtime platform found for gwt.";
    return platforms;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy